[PATCH][i386] Add -march=native support for VIA nano CPUs
J. Mayer
l_indien@magic.fr
Sun May 29 16:32:00 GMT 2016
When trying to compile using -march=native on a VIA nano CPU, gcc
selects "-march=core2" "-mtune=i386" then is unable to compile, as this
creates a conflicts between 32 bits and 64 bits compilation modes, as
show by the following test:
# echo 'int main(){return 0;}' > test.c && gcc -march=native -O2
-pipe  test.c -o test && rm test.c test
Compilation fails with the following error message and informations:
[...]
test.c:1:0: error: CPU you selected does not support x86-64 instruction
set
 int main(){return 0;}
 ^
Using "-v -Q" option shows the detection problem:
gnu/gcc/../lib/gcc/x86_64-unknown-linux-gnu/4.8.4/
 test.c -march=core2 -mcx16 -msahf -mno-movbe -mno-aes -mno-pclmul
 -mno-popcnt -mno-abm -mno-lwp -mno-fma -mno-fma4 -mno-xop -mno-bmi
 -mno-bmi2 -mno-tbm -mno-avx -mno-avx2 -mno-sse4.2 -mno-sse4.1 -mno-
lzcnt
 -mno-rtm -mno-hle -mno-rdrnd -mno-f16c -mno-fsgsbase -mno-rdseed
 -mno-prfchw -mno-adx -mfxsr -mno-xsave -mno-xsaveopt
 --param l1-cache-size=64 --param l1-cache-line-size=64
 --param l2-cache-size=1024 -mtune=i386 -O2 -fno-use-linker-plugin
The following patch allows gcc to select correct compilation options,
which can be checked using "-v -Q" gcc options. GCC output becomes:
gnu/gcc/../lib/gcc/x86_64-unknown-linux-gnu/4.8.4/
 test.c -march=x86-64 -mcx16 -msahf -mno-movbe -mno-aes -mno-pclmul
 -mno-popcnt -mno-abm -mno-lwp -mno-fma -mno-fma4 -mno-xop -mno-bmi
 -mno-bmi2 -mno-tbm -mno-avx -mno-avx2 -msse3 -mssse3 -mno-sse4.2
 -mno-sse4.1 -mno-lzcnt -mno-rtm -mno-hle -mno-rdrnd -mno-f16c
 -mno-fsgsbase -mno-rdseed -mno-prfchw -mno-adx -mfxsr -mno-xsave
 -mno-xsaveopt --param l1-cache-size=64 --param l1-cache-line-size=64
 --param l2-cache-size=1024 -mtune=generic -O2 -fno-use-linker-plugin
which seems OK.
The same problem appears with gcc 4.9.3 and 5.2, and likely with
current git version.
The following patch applies to gcc >= 4.9; it has been tested by
recompiling the whole system from scratch on a Gentoo distribution
using gcc version 4.9.3 (the current stable gcc version on Gentoo
x86_64) with no issue.
Please consider applying this patch to future releases.
Jocelyn Mayer <l_indien@magic.fr>
PS: please CC me to any answer to this mail, as I didn't subscribe to
the mailing list.
---
--- gcc/config/i386/driver-i386.c.orig  2015-02-02 05:20:49.000000000
+0100
+++ gcc/config/i386/driver-i386.c       2015-08-23 01:11:03.000000000
+0200
@@ -601,15 +601,20 @@
          switch (family)
            {
            case 6:
-Â Â Â Â Â Â Â Â Â Â Â Â Â if (model > 9)
-               /* Use the default detection procedure.  */
+Â Â Â Â Â Â Â Â Â Â Â Â Â if (has_longmode)
                processor = PROCESSOR_GENERIC;
-Â Â Â Â Â Â Â Â Â Â Â Â Â else if (model == 9)
-Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â cpu = "c3-2";
-Â Â Â Â Â Â Â Â Â Â Â Â Â else if (model >= 6)
-Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â cpu = "c3";
              else
-Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â processor = PROCESSOR_GENERIC;
+Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â {
+Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â if (model > 9)
+                   /* Use the default detection procedure.  */
+Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â processor = PROCESSOR_GENERIC;
+Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â else if (model == 9)
+Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â cpu = "c3-2";
+Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â else if (model >= 6)
+Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â cpu = "c3";
+Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â else
+Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â processor = PROCESSOR_GENERIC;
+Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â }
              break;
            case 5:
              if (has_3dnow)
@@ -623,6 +628,8 @@
              /* We have no idea.  */
              processor = PROCESSOR_GENERIC;
            }
+Â Â Â Â Â Â Â } else {
+Â Â Â Â Â Â Â Â Â processor = PROCESSOR_GENERIC;
        }
     }
   else
@@ -840,7 +847,12 @@
       if (arch)
        {Â
          if (has_ssse3)
-Â Â Â Â Â Â Â Â Â Â Â cpu = "core2";
+Â Â Â Â Â Â Â Â Â Â Â {
+Â Â Â Â Â Â Â Â Â Â Â Â Â if (vendor == signature_CENTAUR_ebx)
+Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â cpu = "x86-64";
+Â Â Â Â Â Â Â Â Â Â Â Â Â else
+Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â cpu = "core2";
+Â Â Â Â Â Â Â Â Â Â Â }
          else if (has_sse3)
            {Â
              if (has_longmode)
More information about the Gcc-patches
mailing list