什么是使用不同版本的上证所内部函数在GCC的正确方法? [英] What's the proper way to use different versions of SSE intrinsics in GCC?
问题描述
我会给予一个例子问我的问题。现在我有一个调用的函数 do_something()
。
I will ask my question by giving an example. Now I have a function called do_something()
.
它有三个版本: do_something()
, do_something_sse3()
和 do_something_sse4 ()
。当我的程序运行时,它会检测CPU的功能(看看它是否支持SSE3 SSE4或),并调用相应的三个版本中的一个。
It has three versions: do_something()
, do_something_sse3()
, and do_something_sse4()
. When my program runs, it will detect the CPU feature (see if it supports SSE3 or SSE4) and call one of the three versions accordingly.
的问题是::当我建立我的程序与海湾合作委员会,我必须设置 -msse4
为 do_something_sse4( )
编译(如头文件< smmintrin.h>
来包括在内)。
The problem is: When I build my program with GCC, I have to set -msse4
for do_something_sse4()
to compile (e.g. for the header file <smmintrin.h>
to be included).
不过,如果我设置 -msse4
,然后GCC被允许使用SSE4指令和一些内部函数在 do_something_sse3()
也被翻译一些SSE4指令。所以,如果我的程序在CPU只具有SSE3(但没有SSE4)支持运行时,它会导致非法指令的时候调用 do_something_sse3()
。
However, if I set -msse4
, then gcc is allowed to use SSE4 instructions, and some intrinsics in do_something_sse3()
is also translated to some SSE4 instructions. So if my program runs on CPU that has only SSE3 (but no SSE4) support, it causes "illegal instruction" when calls do_something_sse3()
.
也许我有一些不好的做法。你能给一些建议吗?谢谢你。
Maybe I have some bad practice. Could you give some suggestions? Thanks.
推荐答案
我认为神秘的技巧是好的,但如果你真的想这样做,在有一个的文件,可以使用适当的编译指示,例如:
I think that the Mystical's tip is fine, but if you really want to do it in the one file, you can use proper pragmas, for instance:
#pragma GCC target("sse4.1")
需要GCC 4.4,AFAIR。
GCC 4.4 is needed, AFAIR.
这篇关于什么是使用不同版本的上证所内部函数在GCC的正确方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!