我从以下代码中找到了以下代码:
http://msdn.microsoft.com/en-us/library/bb513993(v=vs.90).aspx
我试图准确地了解代码在做什么,然后修补并满足我的需要。我有兴趣使用 intrincs 在字符串中快速查找空格字符,我认为这些字符串内在函数可以帮助我。
我不太明白 printf 语句中提供的“注释”,为什么预期的结果是作者所说的?
(您应该可以复制并粘贴以下内容并立即运行)
#include <stdio.h>
#include <nmmintrin.h>
#include <iostream>
using namespace std;
int main ()
{
__m128i a, b;
const int mode = _SIDD_UWORD_OPS | _SIDD_CMP_EQUAL_EACH | _SIDD_LEAST_SIGNIFICANT;
// _SIDD_UWORD_OPS a and b contain strings of unsigned 16-bit characters.
// _SIDD_CMP_EQUAL_EACH Find if equal each mode: This implements the string equality algorithm.
// _SIDD_LEAST_SIGNIFICANT sets the same bit as _SIDD_BIT_MASK
a.m128i_u16[7] = 0xFFFF;
a.m128i_u16[6] = 0xFFFF;
a.m128i_u16[5] = 0xFFFF;
a.m128i_u16[4] = 0xFFFF;
a.m128i_u16[3] = 0xFFFF;
a.m128i_u16[2] = 0xFFFF;
a.m128i_u16[1] = 0xFFFF;
a.m128i_u16[0] = 0xFFFF;
b.m128i_u16[7] = 0x0001;
b.m128i_u16[6] = 0x0001;
b.m128i_u16[5] = 0x0001;
b.m128i_u16[4] = 0x0001;
b.m128i_u16[3] = 0x0001;
b.m128i_u16[2] = 0x0001;
b.m128i_u16[1] = 0x0001;
b.m128i_u16[0] = 0x0001;
int returnValue = _mm_cmpistra(a, b, mode);
printf_s("_mm_cmpistra return value should be 1: %i\n", returnValue);
b.m128i_u16[4] = 0x0000;
returnValue = _mm_cmpistra(a, b, mode);
printf_s("_mm_cmpistra return value should be 0: %i\n", returnValue);
b.m128i_u16[5] = 0xFFFF;
returnValue = _mm_cmpistrc(a, b, mode);
printf_s("_mm_cmpistrc return value should be 0: %i\n", returnValue);
b.m128i_u16[4] = 0x0001;
returnValue = _mm_cmpistrc(a, b, mode);
printf_s("_mm_cmpistrc return value should be 1: %i\n", returnValue);
returnValue = _mm_cmpistri(a, b, mode);
printf_s("_mm_cmpistri return value should be 5: %i\n", returnValue);
b.m128i_u16[0] = 0xFFFF;
__m128i fullResult = _mm_cmpistrm(a, b, mode);
printf_s("_mm_cmpistrm return value: 0x%016I64x 0x%016I64x\n",
fullResult.m128i_u64[1], fullResult.m128i_u64[0]);
returnValue = _mm_cmpistro(a, b, mode);
printf_s("_mm_cmpistro return value should be 1: %i\n", returnValue);
returnValue = _mm_cmpistrs(a, b, mode);
printf_s("_mm_cmpistrs return value should be 0: %i\n", returnValue);
a.m128i_u16[7] = 0x0000;
returnValue = _mm_cmpistrs(a, b, mode);
printf_s("_mm_cmpistrs return value should be 1: %i\n", returnValue);
returnValue = _mm_cmpistrz(a, b, mode);
printf_s("_mm_cmpistrz return value should be 0: %i\n", returnValue);
b.m128i_u16[7] = 0x0000;
returnValue = _mm_cmpistrz(a, b, mode);
printf_s("_mm_cmpistrz return value should be 1: %i\n", returnValue);
int bb;
cin >> bb;
return 0;
}