View previous topic :: View next topic |
Author |
Message |
halfgaar l33t
Joined: 22 Feb 2004 Posts: 781 Location: Netherlands
|
Posted: Tue Aug 24, 2004 10:46 am Post subject: GCC -mcpu and -march |
|
|
I was wondering are "-O3 -march=i686 -mcpu=athlon-xp -pipe" valid GCC options? The man-page is a bit unclear. On the one hand, it says -march implies -mpcu, but it also says that -mcpu only optimizes code for the selected CPU, but generates i386 compatible code, unless -march is specified.
What I basicly want to know, is if "-O3 -march=i686 -mcpu=athlon-xp -pipe" generates code that needs at least an i686 but is optimized for an athlon-xp. I'd prefer this over -march=athlon-xp because I don't like to have a non running system if I should fall back to another CPU, in case of problems or whatever, or if I should ever buy an Intel CPU. |
|
Back to top |
|
|
Marctraider Guru
Joined: 24 Dec 2003 Posts: 387
|
Posted: Tue Aug 24, 2004 11:42 am Post subject: |
|
|
Hi, march optimizes for a particular processor, when adding mcpu, it will great code compatible with i386.
Unless you want to run this installation with a lower processor, use -march=athlon-xp.
Otherwise use -mcpu=athlon-xp which will do fine afaik. _________________ MOBO: Maximus II Gene
RAM: DDR2 OCZ 4GB
CPU: E6400 Conroe
GPU: HD2600XT
SATA: 3x 250GB. |
|
Back to top |
|
|
halfgaar l33t
Joined: 22 Feb 2004 Posts: 781 Location: Netherlands
|
Posted: Tue Aug 24, 2004 11:55 am Post subject: |
|
|
Isn't it possible to generate code that utilizes i686 to the maximum extent, but is optimized for an ahtlon-xp?
Look at this (from the man-page):
Quote: |
-mcpu=cpu-type
Tune to cpu-type everything applicable about the generated code, except for the ABI and the set of available instructions.
(snip)
While picking a specific cpu-type will schedule things appropriately for that particular chip, the compiler will not generate
any code that does not run on the i386 without the -march=cpu-type option being used.
-march=cpu-type
Generate instructions for the machine type cpu-type. The choices for cpu-type are the same as for -mcpu. Moreover, specifying
-march=cpu-type implies -mcpu=cpu-type.
|
The two parts in bold are in conflict. The first one suggests you can make code that requires an i686 at least, but is optimized for an athlon-xp. The second part, however, suggests that when you create code specificly for an i686, you can't optimize for another CPU, because -march implies -mcpu.
So, which part is right? |
|
Back to top |
|
|
ursus n00b
Joined: 16 Jul 2004 Posts: 16 Location: 52.2170° N, 4.5330° E
|
Posted: Tue Aug 24, 2004 12:18 pm Post subject: |
|
|
There is no conflict.
-march=cpu-type does everything that -mcpu=cpu-type does, plus it generates code using the cpu-type instruction set, not the i386 set.
What they are trying to say (not very clearly) is that if you specify -march=cpu-type, then you have, by implication, also specified -mcpu=cpu-type. |
|
Back to top |
|
|
Cuardin l33t
Joined: 06 Feb 2003 Posts: 713 Location: vasastaden.stockholm.se
|
Posted: Tue Aug 24, 2004 12:39 pm Post subject: |
|
|
But the question remains if you can specify that you want code that will NOT run on anything less than a PII but is optimized for an XP. _________________ Part of "The adopt an unanswered post initiative" |
|
Back to top |
|
|
halfgaar l33t
Joined: 22 Feb 2004 Posts: 781 Location: Netherlands
|
Posted: Tue Aug 24, 2004 1:26 pm Post subject: |
|
|
Cuardin wrote: | But the question remains if you can specify that you want code that will NOT run on anything less than a PII but is optimized for an XP. |
That is exactly what I mean. |
|
Back to top |
|
|
Genone Retired Dev
Joined: 14 Mar 2003 Posts: 9595 Location: beyond the rim
|
Posted: Tue Aug 24, 2004 2:07 pm Post subject: |
|
|
should work |
|
Back to top |
|
|
halfgaar l33t
Joined: 22 Feb 2004 Posts: 781 Location: Netherlands
|
Posted: Tue Aug 24, 2004 2:24 pm Post subject: |
|
|
I can tell you it compiles, but I can't check if it actually did what I want. Is there a way to check? |
|
Back to top |
|
|
ursus n00b
Joined: 16 Jul 2004 Posts: 16 Location: 52.2170° N, 4.5330° E
|
Posted: Tue Aug 24, 2004 2:25 pm Post subject: |
|
|
-march sets the instruction set to be emitted by the compiler.
-mcpu tells the compiler's instruction scheduler which processor to optimise for.
Optimising for one processor's pipeline set and then emitting another processor's instruction set makes no sense unless that processor is so dumb that the reordering of the instructions in a way that doesn't suit its pipelines doesn't slow it down. That's why -march implies -mcpu. |
|
Back to top |
|
|
halfgaar l33t
Joined: 22 Feb 2004 Posts: 781 Location: Netherlands
|
Posted: Tue Aug 24, 2004 2:51 pm Post subject: |
|
|
But when you use -mcpu, you generate code that uses only the i386 instructions. Isn't it benificial to let GCC generate code that also makes use of the i686 instructions and still optimize for another, like an Athlon-XP?
BTW:
ursus wrote: |
Optimising for one processor's pipeline set and then emitting another processor's instruction set makes no sense
|
That is exactly what you get when only using -mcpu. You optimize for one CPU, for example an Athlon-XP, but emit instructions for another, the i386. So why not optimize for Athlon-XP and emit i686 instructions? |
|
Back to top |
|
|
sapphirecat Guru
Joined: 15 Jan 2003 Posts: 376
|
Posted: Tue Aug 24, 2004 3:34 pm Post subject: |
|
|
halfgaar wrote: | But when you use -mcpu, you generate code that uses only the i386 instructions. |
No, that's not the case, despite the confusion on the issue. Essentially, doing -march=X -mcpu=Y is equivalent to -march=X -mcpu=X -mcpu=Y, and the last option wins in case of duplicates. The only way -mcpu generates 386-compatible code is if there's no -march at all.
As far as the sanity of this goes, it makes perfect sense to use different -march and -mcpu if the -mcpu is higher than the -march. In this case, you're not worried how fast it runs on a pentiumII, only that it does.
halfgaar wrote: | I can tell you it compiles, but I can't check if it actually did what I want. Is there a way to check? |
I'm not sure about reading the generated code, but you can always see what options GCC has actually set by compiling some file (I always use a hello world program for this) with -Q -v, as in 'gcc -Q -v -march=i686 -mcpu=athlon-xp hello.c'. _________________ Former Gentoo user; switched to Kubuntu 7.04 when I got sick of waiting on gcc. Chance of thread necro if you reply now approaching 100%... |
|
Back to top |
|
|
Marctraider Guru
Joined: 24 Dec 2003 Posts: 387
|
Posted: Tue Aug 24, 2004 4:09 pm Post subject: |
|
|
Indeed, then you shouldnt use march if you want i386 optimized code.
Just either use march or mcpu, no?
So you could do -mcpu=athlon-xp which shoudnt break compability with older cpu's, but then i dont understand how it could optimize for a athlonxp? does it detect what cpu you are currently running? _________________ MOBO: Maximus II Gene
RAM: DDR2 OCZ 4GB
CPU: E6400 Conroe
GPU: HD2600XT
SATA: 3x 250GB. |
|
Back to top |
|
|
halfgaar l33t
Joined: 22 Feb 2004 Posts: 781 Location: Netherlands
|
Posted: Tue Aug 24, 2004 5:10 pm Post subject: |
|
|
sapphirecat wrote: | halfgaar wrote: | But when you use -mcpu, you generate code that uses only the i386 instructions. |
No, that's not the case, despite the confusion on the issue. Essentially, doing -march=X -mcpu=Y is equivalent to -march=X -mcpu=X -mcpu=Y, and the last option wins in case of duplicates. The only way -mcpu generates 386-compatible code is if there's no -march at all.
As far as the sanity of this goes, it makes perfect sense to use different -march and -mcpu if the -mcpu is higher than the -march. In this case, you're not worried how fast it runs on a pentiumII, only that it does.
|
OK, I'm confused. Maybe I should rephrase: "But when you use -mcpu and not -march, you generate code that uses only the i386 instructions.". I meant by that, to deny what ursus said, about it being dumb to optimize for one CPU and generate instructions for another. I just meant to say that when using -mcpu and not -march, you do just that, and therefore it should also be possible to generate code for the i686, whilst optimizing it for another.
so, you actually confirm what I'm saying, right?
sapphirecat wrote: | halfgaar wrote: | I can tell you it compiles, but I can't check if it actually did what I want. Is there a way to check? |
I'm not sure about reading the generated code, but you can always see what options GCC has actually set by compiling some file (I always use a hello world program for this) with -Q -v, as in 'gcc -Q -v -march=i686 -mcpu=athlon-xp hello.c'. |
options enabled: {blablabla} -mcpu=athlon-xp -march=i686
So, it does use the options.
OK, it seems that what I wanted, works. I wanted to have my system optimized for my CPU (Athlon-XP), yet compatible with older/other(intel) CPU's, so that I don't have a non-working system should I swap out my CPU/system for another.
Marctraider wrote: |
Indeed, then you shouldnt use march if you want i386 optimized code.
Just either use march or mcpu, no?
So you could do -mcpu=athlon-xp which shoudnt break compability with older cpu's, but then i dont understand how it could optimize for a athlonxp? does it detect what cpu you are currently running?
|
I assume you're questions are answered as well? In short, i386 optimized code can be achieved by -march, by using -march=i386. This also causes -mcpu to be set, so code is also optimzed for the i386, instead of just using it's instructions.
And no, it does not detect anything. You have to manually set -march and -mcpu in /etc/make.conf (or, when using GCC manually, give it them as GCC options). |
|
Back to top |
|
|
sapphirecat Guru
Joined: 15 Jan 2003 Posts: 376
|
Posted: Tue Aug 24, 2004 6:22 pm Post subject: |
|
|
halfgaar wrote: | so, you actually confirm what I'm saying, right? |
Yes.
Marctraider wrote: | So you could do -mcpu=athlon-xp which shoudnt break compability with older cpu's, but then i dont understand how it could optimize for a athlonxp? |
It changes how the compiler chooses and orders the available instructions. For example, Intel couldn't get the loop instruction to play nicely in the 486 pipeline, so on a 486 (and later, IIRC), loop is slower than the equivalent compare and jump instructions. So -mcpu=i486 uses compare and jump, whereas -mcpu=i386 would use loop instead. Both CPUs have all three instructions available, so they can both run whatever way the compiler chose to write it, but each CPU runs one variant faster. There's other parameters like the -falign-* things that -mcpu can set without altering compatibility or instruction set as well. _________________ Former Gentoo user; switched to Kubuntu 7.04 when I got sick of waiting on gcc. Chance of thread necro if you reply now approaching 100%... |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|