我有一个 C 程序只能在我编译代码的 Ivy Bridge CPU 上运行,在 gcc 4.8 上我尝试使用 -march=native
编译以利用所有特定的CPU 的指令。
我也想在 32 位模式下编译它以进行一些研究比较
我已经以这种方式为 x64 编译了程序(注意我在 Linux x64 上)
gcc -march=native -s -O2 mycode.c
反汇编代码,我可以看到使用了AVX指令集
对于 32 位 x86 也是这样
gcc -m32 -march=native -s -O2 mycode.c
如果我尝试反汇编代码,我看不到任何 AVX 指令,指令集是 Pentium Pro,80x87。像 fld
/fadd
/fstp
用于 FP 数学。添加 -mavx
没有帮助,结果相同。
我该如何解决这个问题?
最佳答案
来自GCC 4.8.3 manual :
-m32 -m64 -mx32
Generate code for a 32-bit or 64-bit environment. The -m32 option sets int, long, and pointer types to 32 bits, and generates code that runs on any i386 system. The -m64 option sets int to 32 bits and long and pointer types to 64 bits, and generates code for the x86-64 architecture. For Darwin only the -m64 option also turns off the -fno-pic and -mdynamic-no-pic options.
The -mx32 option sets int, long, and pointer types to 32 bits, and generates code for the x86-64 architecture.
使用 AVX 指令最接近 -m32
的方法是在原处使用 -mx32
,但这可能不是您想要的。
关于c - 让 GCC 在 32 位代码 (-m32) 中使用 AVX?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24041752/