Fir*_*cer 15 c++ gcc cross-platform simd visual-c++
在我的代码库中有几个地方,对于大型数据集,相同的操作重复了很多次.在某些情况下,处理这些需要相当长的时间.
我相信使用SSE来实现这些循环应该会显着提高它们的性能,特别是在对同一组数据执行许多操作的情况下,所以一旦数据最初被读入缓存,就不应该有任何缓存未命中它.但是,我不确定是否会这样做.
是否有编译器和OS独立的方式编写代码以利用SSE指令?我喜欢VC++内在函数,其中包括SSE操作,但我还没有找到任何交叉编译器解决方案.
我仍然需要支持一些没有或有限SSE支持的CPU(例如Intel Celeron).有没有办法避免不得不制作不同版本的程序,比如有一种"运行时链接器"链接在基本或SSE优化代码基于运行进程时运行它的CPU?
那么其他CPU扩展怎么样,看看各种Intel和AMD CPU的指令集,其中有几个?
对于您的第二点,只要您可以将差异分离到不同的功能中,就有几种解决方案:
请注意,因为您依赖于间接函数调用,抽象不同操作的函数通常需要表示更高级别的功能,否则您可能会失去从调用开销中的优化指令获得的任何增益(换句话说,不是'抽象个人SSE操作 - 抽象你正在做的工作.
这是使用函数指针的示例:
typedef int (*scale_func_ptr)( int scalar, int* pData, int count);
int non_sse_scale( int scalar, int* pData, int count)
{
// do whatever work needs done, without SSE so it'll work on older CPUs
return 0;
}
int sse_scale( int scalar, in pData, int count)
{
// equivalent code, but uses SSE
return 0;
}
// at initialization
scale_func_ptr scale_func = non_sse_scale;
if (useSSE) {
scale_func = sse_scale;
}
// now, when you want to do the work:
scale_func( 12, theData_ptr, 512); // this will call the routine that tailored to SSE
// if the CPU supports it, otherwise calls the non-SSE
// version of the function
Run Code Online (Sandbox Code Playgroud)