我正在为 x64 和 neon 开发 C++ 内在包装器。我希望我的函数是 constexpr。我的动机类似于Constexpr 和 SSE 内在函数,但是 #pragma omp simd 和内在函数在 constexpr 函数中可能不受编译器 (GCC) 的支持。下面的代码只是一个演示(自动矢量化对于加法来说已经足够了)。
struct FA{
float c[4];
};
inline constexpr FA add(FA a, FA b){
FA result{};
#pragma omp simd // clang error: statement not allowed in constexpr function
for(int i = 0; i < 4; i++){ // GCC error: uninitialized variable 'i' in 'constexpr' function
result.c[i] = b.c[i] + a.c[i];
}
return result;
}
struct FA2{
__m128 c;
};
inline constexpr …Run Code Online (Sandbox Code Playgroud)