防止GCC在使用-mavx和-mfma编译时自动使用AVX和FMA指令 [英] Preventing GCC from automatically using AVX and FMA instructions when compiled with -mavx and -mfma

查看:3598
本文介绍了防止GCC在使用-mavx和-mfma编译时自动使用AVX和FMA指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用AVX和FMA指令停用自动矢量化?我仍然喜欢编译器自动使用SSE和SSE2,但不是FMA和AVX。

How can I disable auto-vectorization with AVX and FMA instructions? I would still prefer the compiler to employ SSE and SSE2 automatically, but not FMA and AVX.

我的代码使用AVX检查其可用性,但GCC不做当自动矢量化时。因此,如果我使用 -mfma 编译并在Haswell之前的任何CPU上运行代码,我得到 SIGILL 。如何解决这个问题?

My code that uses AVX checks for its availability, but GCC doesn't do it when auto-vectorizing. So if I compile with -mfma and run the code on any CPU prior to Haswell I get SIGILL. How to solve this issue?

推荐答案

你想要做的是为每个指令集编译不同的目标文件。然后创建一个cpu分派器,它向CPUID请求可用的指令集,然后跳转到相应版本的函数。

What you want to do is compile different object files for each instruction set you are targeting. Then create a cpu dispatcher which asks CPUID for the available instruction set and then jumps to the appropriate version of the function.

我已经在几个不同的问题和答案中描述了这个问题

I already described this in several different questions and answers

do-i-eed-to- -multiple-executableables-for-targetting-different-instruction-set

how-to-check-with-intel-intrinsics-if-avx-extensions-is-supported-by-the-cpu

cpu-dispatcher-for-visual-studio-for-avx-and-sse

create-separate-object-files-from-the-same-source-code-and-link-to-an-executable

这篇关于防止GCC在使用-mavx和-mfma编译时自动使用AVX和FMA指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆