_mm_cmpistrm SSE4.2 内在模式
我试图弄清楚如何为 _mm_cmpistrm SSE4.2 内在函数设置“模式”标志。我有一个常规 C 字符串 (char*),正在使用 _mm_lddqu_si128 将其加载到 __m128i 类型中。我打算使用无符号字节进行常规字符串比较:
_SIDD_UBYTE_OPS | _SIDD_CMP_EQUAL_EACH
但我对为单位和位掩码设置什么感到困惑。以下是 GCC 4.3.2 中 smmintrin.h 中的宏:
/* These macros specify the output selection in _mm_cmpXstrm (). */
#define _SIDD_BIT_MASK 0x00
#define _SIDD_UNIT_MASK 0x40
我想我理解位掩码是什么:如果两个字符串之间该位置的字符不同,我将在位 0..15 中得到 1。但是单位掩码有什么作用呢?
I'm trying to figure out how to set the "mode" flag for the _mm_cmpistrm SSE4.2 intrinsic. I have a regular C string (char*) that I am loading into an __m128i type with _mm_lddqu_si128. I was going to use unsigned bytes with regular string comparison:
_SIDD_UBYTE_OPS | _SIDD_CMP_EQUAL_EACH
But I'm confused about what to set for the unit vs. bit mask. Here are the macros from smmintrin.h in GCC 4.3.2:
/* These macros specify the output selection in _mm_cmpXstrm (). */
#define _SIDD_BIT_MASK 0x00
#define _SIDD_UNIT_MASK 0x40
I think I understand what the bit mask is: I will get a 1 in bits 0..15 if the char in that position differs between the two strings. But what does the unit mask do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于_SIDD_BIT_MASK,如果字符串相等,您将得到一个全为 1 的掩码,如果字符串不相等,则全为 0;如果您执行 _SIDD_UBYTE_OPS,那么您将返回 16 位(字符串中的每个字符对应一个)。
然而,使用 _SIDD_UNIT_MASK,您将获得相同的掩码,但扩展为 16字节。例如,如果字符串中前两个字符的比较为真,则位 0..15 将全部为 1。位 16..31 表示字符二等。
For _SIDD_BIT_MASK you'll get a mask that is all 1 if the strings are equal and all 0 if they are unequal; if you're doing a _SIDD_UBYTE_OPS then you'll get 16 bits returned (one for each character in the string).
With _SIDD_UNIT_MASK however you'll get the same mask but expended to 16 bytes instead. Eg bits 0..15 will all be 1 if the comparison of the first two characters in the string is true. And bits 16..31 for character two etc.