我使用SIMD指令运行一系列计算。这些指令返回一个16字节的向量,结果为compare,每个字节为0x00或0xff:
0 1 2 3 4 5 6 7 15 16
compare : 0x00 0x00 0x00 0x00 0xff 0x00 0x00 0x00 ... 0xff 0x00
Run Code Online (Sandbox Code Playgroud)
设置为字节的0xff意思是我需要以do_operation(i) i作为字节的位置来运行该函数。
例如,上述compare向量意味着,我需要运行以下操作序列:
do_operation(4);
do_operation(15);
Run Code Online (Sandbox Code Playgroud)
这是到目前为止我想到的最快的解决方案:
for(...) {
//
// SIMD computations
//
__m128i compare = ... // Result of SIMD computations
// Extract high and low quadwords for compare vector
std::uint64_t cmp_low = (_mm_cvtsi128_si64(compare));
std::uint64_t cmp_high = (_mm_extract_epi64(compare, 1));
// Process low quadword …Run Code Online (Sandbox Code Playgroud)