相关疑难解决方法(0)

从SIMD向量中提取设置的字节位置

我使用SIMD指令运行一系列计算。这些指令返回一个16字节的向量,结果为compare,每个字节为0x000xff

             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)

c++ sse simd intrinsics

5
推荐指数
2
解决办法
818
查看次数

标签 统计

c++ ×1

intrinsics ×1

simd ×1

sse ×1