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)."