* Which -march option to use for a generic 64-bit cpu?
@ 2012-01-21 16:53 Erik Leunissen
2012-01-21 17:22 ` Jonathan Wakely
0 siblings, 1 reply; 7+ messages in thread
From: Erik Leunissen @ 2012-01-21 16:53 UTC (permalink / raw)
To: gcc-help
L.S.
I'd like to generate code that runs on a selection of common 64-bit
cpu's, both Intel and AMD[*].
[*] Aside: I'm not yet entirely sure yet about the final selection
of architectures, but in any case I would like to support core2, atom,
athlon64 (not yet sure about opteron and AMD multicore cpu's).
To that end, I've been looking in the list of "-march" options to gcc
for a specific option that indicates such a common set of architectures
(much like "-march=i686" for 32-bit architectures).
I remain confused about how to do this for 64-bit cpu's. I found several
options indicating specific cpu's that I'd like to run my code on.
However, I guess that I'm clueless about "backward compatibility" of
(closely) related 64-bit cpu types (like i386 code being supported by
i686 with 32-bit cpu's). Also, I'm unsure about the differences between
AMD and Intel in this regard.
- Do options indicating such a generic 64-bit cpu exist?, or
- Can I specifiy multiple -march options in one compile command?, or
- Do I need to compile separately for each 64-bit architecture?, or
- ... ?
I'd appreciate very much any directions about how to proceed.
Thanks for any insight,
Erik Leunissen.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Which -march option to use for a generic 64-bit cpu?
2012-01-21 16:53 Which -march option to use for a generic 64-bit cpu? Erik Leunissen
@ 2012-01-21 17:22 ` Jonathan Wakely
2012-01-21 17:26 ` Jonathan Wakely
2012-01-21 17:31 ` Erik Leunissen
0 siblings, 2 replies; 7+ messages in thread
From: Jonathan Wakely @ 2012-01-21 17:22 UTC (permalink / raw)
To: Erik Leunissen; +Cc: gcc-help
On 21/01/2012, Erik Leunissen wrote:
> L.S.
>
> I'd like to generate code that runs on a selection of common 64-bit
> cpu's, both Intel and AMD[*].
>
> [*] Aside: I'm not yet entirely sure yet about the final selection
> of architectures, but in any case I would like to support core2, atom,
> athlon64 (not yet sure about opteron and AMD multicore cpu's).
>
> To that end, I've been looking in the list of "-march" options to gcc
> for a specific option that indicates such a common set of architectures
> (much like "-march=i686" for 32-bit architectures).
>
> I remain confused about how to do this for 64-bit cpu's. I found several
> options indicating specific cpu's that I'd like to run my code on.
> However, I guess that I'm clueless about "backward compatibility" of
> (closely) related 64-bit cpu types (like i386 code being supported by
> i686 with 32-bit cpu's). Also, I'm unsure about the differences between
> AMD and Intel in this regard.
>
> - Do options indicating such a generic 64-bit cpu exist?, or
Why do you think you need to use any -march option?
If do don't use one you'll get code that runs on any x86_64 machine.
> - Can I specifiy multiple -march options in one compile command?, or
No.
> - Do I need to compile separately for each 64-bit architecture?, or
> - ... ?
>
> I'd appreciate very much any directions about how to proceed.
Just compile without any -march, unless you're sure your code will
always run on chips that support more specific features. Each -march
option lists the features it enables, so you should be able to work
out what options will work for all the machines you want to use. e.g.
don't use -march=core2 if you want to support chips without SSSE3.
You can always use -mtune=generic to generate code that is tuned for
common chips, but still runs on older ones.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Which -march option to use for a generic 64-bit cpu?
2012-01-21 17:22 ` Jonathan Wakely
@ 2012-01-21 17:26 ` Jonathan Wakely
2012-01-21 17:31 ` Erik Leunissen
1 sibling, 0 replies; 7+ messages in thread
From: Jonathan Wakely @ 2012-01-21 17:26 UTC (permalink / raw)
To: Erik Leunissen; +Cc: gcc-help
On 21 January 2012 15:33, Jonathan Wakely wrote:
>> - Do options indicating such a generic 64-bit cpu exist?, or
>
> Why do you think you need to use any -march option?
> If do don't use one you'll get code that runs on any x86_64 machine.
That was meant to say "if you don't use..."
>> - Can I specifiy multiple -march options in one compile command?, or
>
> No.
Technically you can, but only the last one will have any effect.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Which -march option to use for a generic 64-bit cpu?
2012-01-21 17:22 ` Jonathan Wakely
2012-01-21 17:26 ` Jonathan Wakely
@ 2012-01-21 17:31 ` Erik Leunissen
2012-01-21 17:48 ` Tim Prince
2012-01-21 22:20 ` Jonathan Wakely
1 sibling, 2 replies; 7+ messages in thread
From: Erik Leunissen @ 2012-01-21 17:31 UTC (permalink / raw)
To: gcc-help
On 21/01/12 16:33, Jonathan Wakely wrote:
> On 21/01/2012, Erik Leunissen wrote:
>> L.S.
>>
>> I'd like to generate code that runs on a selection of common 64-bit
>> cpu's, both Intel and AMD[*].
>>
>> [*] Aside: I'm not yet entirely sure yet about the final selection
>> of architectures, but in any case I would like to support core2, atom,
>> athlon64 (not yet sure about opteron and AMD multicore cpu's).
>>
>> To that end, I've been looking in the list of "-march" options to gcc
>> for a specific option that indicates such a common set of architectures
>> (much like "-march=i686" for 32-bit architectures).
>>
>> I remain confused about how to do this for 64-bit cpu's. I found several
>> options indicating specific cpu's that I'd like to run my code on.
>> However, I guess that I'm clueless about "backward compatibility" of
>> (closely) related 64-bit cpu types (like i386 code being supported by
>> i686 with 32-bit cpu's). Also, I'm unsure about the differences between
>> AMD and Intel in this regard.
>>
>> - Do options indicating such a generic 64-bit cpu exist?, or
>
> Why do you think you need to use any -march option?
Well, for all I knew, absence of any option could mean that gcc
generates code for the machine where I run the compile command, and not
for others.
Following that logic, I expected to need a -march option.
Apparently this is just one part where I was confused/ignorant, as
predicted.
> If do don't use one you'll get code that runs on any x86_64 machine.
>
I simply didn't know this. It's just what I need.
>> - Can I specifiy multiple -march options in one compile command?, or
>
> No.
>
>> - Do I need to compile separately for each 64-bit architecture?, or
>> - ... ?
>>
>> I'd appreciate very much any directions about how to proceed.
>
> Just compile without any -march, unless you're sure your code will
> always run on chips that support more specific features. Each -march
> option lists the features it enables, so you should be able to work
> out what options will work for all the machines you want to use. e.g.
> don't use -march=core2 if you want to support chips without SSSE3.
>
OK
> You can always use -mtune=generic to generate code that is tuned for
> common chips, but still runs on older ones.
>
OK, thanks for clearing up my confusion/ignorance.
Erik.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Which -march option to use for a generic 64-bit cpu?
2012-01-21 17:31 ` Erik Leunissen
@ 2012-01-21 17:48 ` Tim Prince
2012-01-21 22:20 ` Jonathan Wakely
1 sibling, 0 replies; 7+ messages in thread
From: Tim Prince @ 2012-01-21 17:48 UTC (permalink / raw)
To: gcc-help
On 1/21/2012 12:22 PM, Erik Leunissen wrote:
> On 21/01/12 16:33, Jonathan Wakely wrote:
>>
>> Why do you think you need to use any -march option?
>
> Well, for all I knew, absence of any option could mean that gcc
> generates code for the machine where I run the compile command, and not
> for others.
>
> Following that logic, I expected to need a -march option.
You're thinking of -march=native. It's not set by default, but you
might find it set in a makefile.
--
Tim Prince
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Which -march option to use for a generic 64-bit cpu?
2012-01-21 17:31 ` Erik Leunissen
2012-01-21 17:48 ` Tim Prince
@ 2012-01-21 22:20 ` Jonathan Wakely
2012-01-21 22:35 ` Erik Leunissen
1 sibling, 1 reply; 7+ messages in thread
From: Jonathan Wakely @ 2012-01-21 22:20 UTC (permalink / raw)
To: Erik Leunissen; +Cc: gcc-help
On 21 January 2012 17:22, Erik Leunissen wrote:
> On 21/01/12 16:33, Jonathan Wakely wrote:
>>
>> Why do you think you need to use any -march option?
>
>
> Well, for all I knew, absence of any option could mean that gcc generates
> code for the machine where I run the compile command, and not for others.
No, the docs say:
"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."
That applies to x86_64 too, if you don't use -march you will get code
that runs on any x86_64 processor, i.e. using just the basic x86_64
instruction set.
I've updated that text for the GCC 4.7 manual to say:
"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 default machine type without the -march=cpu-type
option being used. For example, if GCC is configured for
i686-pc-linux-gnu then -mtune=pentium4 will generate code that is
tuned for Pentium4 but will still run on i686 machines."
i.e. if your compiler is configured for amdfam10-unknown-linux-gnu
then it will behave as though -march=amdfam10 is given, unless you
override it with an explicit -march option. But if it's configured
for x86_64-unknown-linux-gnu (the default in most cases) then it
generates code that will run on any x86_64.
As Tim pointed out, the behaviour you describe is enabled by
-march-native, documented like so
"Using -march=native will enable all instruction subsets supported by
the local machine (hence the result might not run on different
machines)."
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Which -march option to use for a generic 64-bit cpu?
2012-01-21 22:20 ` Jonathan Wakely
@ 2012-01-21 22:35 ` Erik Leunissen
0 siblings, 0 replies; 7+ messages in thread
From: Erik Leunissen @ 2012-01-21 22:35 UTC (permalink / raw)
To: gcc-help
On 21/01/12 19:37, Jonathan Wakely wrote:
> On 21 January 2012 17:22, Erik Leunissen wrote:
>> On 21/01/12 16:33, Jonathan Wakely wrote:
>>>
>>> Why do you think you need to use any -march option?
>>
>>
>> Well, for all I knew, absence of any option could mean that gcc generates
>> code for the machine where I run the compile command, and not for others.
>
> No, the docs say:
>
I now understand completely. Central to that understanding is your
explanation of the meaning of "the default machine type". The example
helps a great deal too, to be able to check my understanding.
I agree that that can be read in the docs.
Recognizing the value of your explanation leads me to suggest a small
addition to the current text in the manual. Not under the option -mtune,
but under the option -march. Maybe something like:
-march=cpu-type
Without any -march option, gcc generates code for the default machine
type, i.e. the target-cpu for which your specific gcc program has been
configured during build time. You may retrieve the default machine type
with "gcc -dumpmachine". Adding an option -march makes gcc generate
instructions for the machine type cpu-type. The choices for cpu-type are
the same as for -mtune. Moreover, specifying -march=cpu-type implies
-mtune=cpu-type.
Greetings,
Erik.
> "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."
>
> That applies to x86_64 too, if you don't use -march you will get code
> that runs on any x86_64 processor, i.e. using just the basic x86_64
> instruction set.
>
> I've updated that text for the GCC 4.7 manual to say:
> "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 default machine type without the -march=cpu-type
> option being used. For example, if GCC is configured for
> i686-pc-linux-gnu then -mtune=pentium4 will generate code that is
> tuned for Pentium4 but will still run on i686 machines."
>
> i.e. if your compiler is configured for amdfam10-unknown-linux-gnu
> then it will behave as though -march=amdfam10 is given, unless you
> override it with an explicit -march option. But if it's configured
> for x86_64-unknown-linux-gnu (the default in most cases) then it
> generates code that will run on any x86_64.
>
> As Tim pointed out, the behaviour you describe is enabled by
> -march-native, documented like so
>
> "Using -march=native will enable all instruction subsets supported by
> the local machine (hence the result might not run on different
> machines)."
>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2012-01-21 22:20 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-21 16:53 Which -march option to use for a generic 64-bit cpu? Erik Leunissen
2012-01-21 17:22 ` Jonathan Wakely
2012-01-21 17:26 ` Jonathan Wakely
2012-01-21 17:31 ` Erik Leunissen
2012-01-21 17:48 ` Tim Prince
2012-01-21 22:20 ` Jonathan Wakely
2012-01-21 22:35 ` Erik Leunissen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).