如果您在第一次遇到 a 时试图跳出循环,\0
那么您需要执行以下操作:
__m128i* pSrc1 = (__m128i *)string; // init pointer to start of string
__m128i m0 = _mm_set1_epi8(0); // vector of 16 `\0` characters
while (1)
{
__m128i v0 = _mm_loadu_si128(pSrc1); // get 16 chars from string
__m128i v1 = _mm_cmpeq_epi8(v0, m0); // compare all 16 chars with '\0'
int vmask = _mm_movemask_epi8(v1); // get 16 comparison result bits
if (vmask != 0) // if any bit is 1
break; // we found a `\0`, break out of loop
pSrc1++; // next 16 characters...
}
如果您只想测试\0
某些位置的字符而忽略任何其他字符,那么您可以将if (vmask != 0)
测试更改为符合您特定要求的内容。