- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在the Intel Intrinsic site上,我不知道我想要哪种指令组合。我想做的是
result = high_table[i8>>4] & low_table[i8&15]
最佳答案
要将传入索引分为两个半字节 vector ,您需要通常的移位和AND。 SSE没有8位移位,因此您必须模拟更宽的移位和AND,以掩盖移入字节顶部的位。 (不幸的是,对于这种用例,_mm_shuffle_epi8
不会忽略高位。如果设置了最高选择位,则该输出元素将为零。)
您绝对不希望将传入的i8
vector 扩展为16位元素。那将无法与_mm_shuffle_epi8
一起使用。
AVX2具有vpermd
:从8个32位元素的 vector 中选择dword。 (只有3位索引,因此除非您的半字节仅为0..7,否则这对您的用例不利)。 AVX512BW的混洗范围更广,包括vpermi2w
可以索引到两个 vector 的串联表中,或者只是vpermw
可以索引单词。
但是对于只有SSSE3的128位 vector ,是的,pshufb
(_mm_shuffle_epi8
)是可行的方法。对于high_table
,您将需要两个单独的 vector ,一个 vector 用于每个单词条目的高字节,而另一个则用于低字节。还有两个 vector 用于low_table的一半。
使用_mm_unpacklo_epi8
和_mm_unpackhi_epi8
交织两个 vector 的低8个字节,或两个 vector 的高8个字节。这将为您提供所需的16位LUT结果,每个字的上半部分来自上半部 vector 。
也就是说,您正在使用两个交错器从两个8位LUT中构建一个16位LUT。并且您要针对两个不同的LUT重复该过程两次。
该代码看起来像
// UNTESTED, haven't tried even compiling this.
// produces 2 output vectors, you might want to just put this in a loop instead of making a helper function for 1 vector.
// so I'll omit actually returning them.
void foo(__m128i indices)
{
// these optimize away, only used at compile time for the vector initializers
static const uint16_t high_table[16] = {...},
static const uint16_t low_table[16] = {...};
// each LUT needs a separate vector of high-byte and low-byte parts
// don't use SIMD intrinsics to load from the uint16_t tables and deinterleave at runtime, just get the same 16x 2 x 2 bytes of data into vector constants at compile time.
__m128i high_LUT_lobyte = _mm_setr_epi8(high_table[0]&0xff, high_table[1]&0xff, high_table[2]&0xff, ... );
__m128i high_LUT_hibyte = _mm_setr_epi8(high_table[0]>>8, high_table[1]>>8, high_table[2]>>8, ... );
__m128i low_LUT_lobyte = _mm_setr_epi8(low_table[0]&0xff, low_table[1]&0xff, low_table[2]&0xff, ... );
__m128i low_LUT_hibyte = _mm_setr_epi8(low_table[0]>>8, low_table[1]>>8, low_table[2]>>8, ... );
// split the input indexes: emulate byte shift with wider shift + AND
__m128i lo_idx = _mm_and_si128(indices, _mm_set1_epi8(0x0f));
__m128i hi_idx = _mm_and_si128(_mm_srli_epi32(indices, 4), _mm_set1_epi8(0x0f));
__m128i lolo = _mm_shuffle_epi8(low_LUT_lobyte, lo_idx);
__m128i lohi = _mm_shuffle_epi8(low_LUT_hibyte, lo_idx);
__m128i hilo = _mm_shuffle_epi8(high_LUT_lobyte, hi_idx);
__m128i hihi = _mm_shuffle_epi8(high_LUT_hibyte, hi_idx);
// interleave results of LUT lookups into vectors 16-bit elements
__m128i low_result_first = _mm_unpacklo_epi8(lolo, lohi);
__m128i low_result_second = _mm_unpackhi_epi8(lolo, lohi);
__m128i high_result_first = _mm_unpacklo_epi8(hilo, hihi);
__m128i high_result_second = _mm_unpackhi_epi8(hilo, hihi);
// first 8x 16-bit high_table[i8>>4] & low_table[i8&15] results
__m128i and_first = _mm_and_si128(low_result_first, high_result_first);
// second 8x 16-bit high_table[i8>>4] & low_table[i8&15] results
__m128i and_second = _mm_and_si128(low_result_second, high_result_second);
// TOOD: do something with the results.
}
关于c++ - 如何向量化data_i16 [0至15]?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61436326/
我是一名优秀的程序员,十分优秀!