0
我試圖從_mm_cmpistrm
返回一個_m128i位掩碼,它指示128位源中的哪些字節包含空格。但是,我遇到了一些問題,因爲當我將第一個和第三個字節設置爲空格時,得到的結果爲{255,255,0,0,0,0,0,0 ....},而不是{255,0,255 ,0,0,0,...} ....SSE4 _mm_cmpistrm查找字符串中的字符(完整代碼示例)
有人可以幫助/啓發嗎?
#include <stdio.h>
#include <nmmintrin.h>
#include <iostream>
using namespace std;
int main()
{
__m128i a, b;
const int mode = _SIDD_UBYTE_OPS | _SIDD_CMP_EQUAL_ANY | _SIDD_LEAST_SIGNIFICANT;
a.m128i_u8[15] = 't';
a.m128i_u8[14] = 'e';
a.m128i_u8[13] = 's';
a.m128i_u8[12] = 'o';
a.m128i_u8[11] = 'd';
a.m128i_u8[10] = 'i';
a.m128i_u8[9] = 'f';
a.m128i_u8[8] = 'g';
a.m128i_u8[7] = 't';
a.m128i_u8[6] = 'd';
a.m128i_u8[5] = 'b';
a.m128i_u8[4] = 'n';
a.m128i_u8[3] = 'd';
a.m128i_u8[2] = ' ';
a.m128i_u8[1] = 'i';
a.m128i_u8[0] = ' ';
b.m128i_u8[15] = ' ';
b.m128i_u8[14] = ' ';
b.m128i_u8[13] = ' ';
b.m128i_u8[12] = ' ';
b.m128i_u8[11] = ' ';
b.m128i_u8[10] = ' ';
b.m128i_u8[9] = ' ';
b.m128i_u8[8] = ' ';
b.m128i_u8[7] = ' ';
b.m128i_u8[6] = ' ';
b.m128i_u8[5] = ' ';
b.m128i_u8[4] = ' ';
b.m128i_u8[3] = ' ';
b.m128i_u8[2] = ' ';
b.m128i_u8[1] = ' ';
b.m128i_u8[0] = ' ';
__m128i returnValue = _mm_cmpistrm(a, b, mode);
std::cout << int(static_cast<unsigned char>(returnValue.m128i_u8[0])) << endl;
std::cout << int(static_cast<unsigned char>(returnValue.m128i_u8[1])) << endl;
std::cout << int(static_cast<unsigned char>(returnValue.m128i_u8[2])) << endl;
std::cout << int(static_cast<unsigned char>(returnValue.m128i_u8[3])) << endl;
std::cout << int(static_cast<unsigned char>(returnValue.m128i_u8[4])) << endl;
std::cout << int(static_cast<unsigned char>(returnValue.m128i_u8[5])) << endl;
std::cout << int(static_cast<unsigned char>(returnValue.m128i_u8[6])) << endl;
std::cout << int(static_cast<unsigned char>(returnValue.m128i_u8[7])) << endl;
std::cout << int(static_cast<unsigned char>(returnValue.m128i_u8[8])) << endl;
std::cout << int(static_cast<unsigned char>(returnValue.m128i_u8[9])) << endl;
std::cout << int(static_cast<unsigned char>(returnValue.m128i_u8[10])) << endl;
std::cout << int(static_cast<unsigned char>(returnValue.m128i_u8[11])) << endl;
std::cout << int(static_cast<unsigned char>(returnValue.m128i_u8[12])) << endl;
std::cout << int(static_cast<unsigned char>(returnValue.m128i_u8[13])) << endl;
std::cout << int(static_cast<unsigned char>(returnValue.m128i_u8[14])) << endl;
std::cout << int(static_cast<unsigned char>(returnValue.m128i_u8[15])) << endl;
return 0;
}