我使用两台电脑.一个没有AVX支持,另一个没有AVX.让我的代码在运行时找到我的CPU支持的指令集并选择适当的代码路径会很方便.我遵循Agner Fog的建议来制作一个CPU调度员(http://www.agner.org/optimize/#vectorclass).但是,在我的机器上进行AVX编译并与visual studio链接时,启用AVX的代码会导致代码在运行时崩溃.
我的意思是例如我有两个源文件,其中一个SSE2指令集定义了一些SSE2指令,另一个源文件定义了AVX指令集和一些AVX指令.在我的主函数中,如果我只引用SSE2函数,代码仍会因启用了AVX和AVX指令的任何源代码而崩溃.我可以解决这个问题的任何线索?
编辑:好的,我想我已经解决了这个问题.我正在使用Agner Fog的矢量类,我已经定义了三个源文件:
//file sse2.cpp - compiled with /arch:SSE2
#include "vectorclass.h"
float func_sse2(const float* a) {
Vec8f v1 = Vec8f().load(a);
float sum = horizontal_add(v1);
return sum;
}
//file avx.cpp - compiled with /arch:AVX
#include "vectorclass.h"
float func_avx(const float* a) {
Vec8f v1 = Vec8f().load(a);
float sum = horizontal_add(v1);
return sum;
}
//file foo.cpp - compiled with /arch:SSE2
#include <stdio.h>
extern float func_sse2(const float* a);
extern float func_avx(const float* a);
int main() {
float (*fp)(const float*a); …Run Code Online (Sandbox Code Playgroud)