How to force gcc to use march = native by default?

Is there a way to change the specification file so that it passes -march=nativeif nothing is specified on the command line?

Related things in the default specification file:

*cc1:
%(cc1_cpu)

*cc1_cpu:
%{march=native:%>march=native %:local_cpu_detect(arch)   %{!mtune=*:%>mtune=native %:local_cpu_detect(tune)}} %{mtune=native:%>mtune=native %:local_cpu_detect(tune)}

I'm not sure how the specifications work. A simple indication -march=nativebefore or after %(cc1_cpu)does not work. However, this line takes effect, as GCC will report an error if I put in -something_wierdplace -march=native.

Another thing that I noticed is that if I put %{march=i386:-something_wierd}before %(cc1_cpu), gcc reports an error, so it looks like this: -march=i386it is always transmitted if nothing is specified, so is there a way to distinguish anything from the specified one -march=i386in the specification file?

By the way, what is doing %>? This does not appear to be documented .

I am using MinGW gcc-4.6.2.

+5
source share
3 answers

Referring to your last question: gcc 4.6.1 ( gcc/gcc.c) sources contain the following comment in %>:

 %>S    Similar to "%<S", but keep it in the GCC command line.

For completeness, following the comment for %<, create the same file:

 %<S    remove all occurrences of -S from the command line.
        Note - this command is position dependent.  % commands in the
        spec string before this one will see -S, % commands in the
        spec string after this one will not.

To answer the first question in short: yes, but ....

... The only general solution that I found has a significant flaw that will be ignored in the option -march, so each assembly is performed as if it were indicated -march=native. In any case, there is a workaround to this.

1 Solution (no workaround)

specs let say specs.nativealways, :

*cc1_cpu:
%<march=* -march=native %>march=native %:local_cpu_detect(arch) %{!mtune=*:%>mtune=native %:local_cpu_detect(tune)} %{mtune=native:%>mtune=native %:local_cpu_detect(tune)}

specs (, gcc -specs=specs.nativealways) , -march=native ( , -march=<arch> ).

2

, , -myarch , -march ( -myarch=native, , , native ).

specs :

*cc1_cpu:
%<march=* %{myarch=*:%<myarch* -march=%* ; :-march=native %>march=native %:local_cpu_detect(arch) %{!mtune=*:%>mtune=native %:local_cpu_detect(tune)}}  %{mtune=native:%>mtune=native %:local_cpu_detect(tune)}

PS: gcc 4.6.2 Linux, MinGW.

+4

, , CFLAGS CXXFLAGS . 99% Makefile gcc.

+1
*cc1_cpu:
+ %{!march*:-march=native}
+1
source

All Articles