_mm_cmpistra
Microsoft Specific
Emits the Streaming SIMD Extensions 4 (SSE4) instruction pcmpistri. This instruction compares two parameters.
int _mm_cmpistra (
__m128i a,
__m128i b,
const int mode
);
Parameters
Parameter |
Description |
[in] a |
A string fragment with a maximum size of 16 byte characters or 8 word characters. |
[in] b |
A string fragment with a maximum size of 16 byte characters or 8 word characters. |
[in] mode |
A constant that indicates if characters are bytes or words, the type of comparison to do, and the format of the returned value. |
Return value
One if b is does not contain the null character and the resulting mask is equal to zero. Otherwise, zero. The pcmpistri instruction computes the bitmask, where bit0, bit1, bit2… in the mask correspond to the result of the operation on a0, a1, a2… in a.
Requirements
Intrinsic |
Architecture |
_mm_cmpistra |
x86, x64 |
Header file <nmmintrin.h>
Remarks
b0, b1, b2… indicate the first, second, third… characters in b. b0 is stored in the least significant bits of b. The same notation applies to a. MaxSize is either 16 for byte characters or 8 for word characters. This is the maximum number of characters that fit into a __m128i data type. The lower 7 bits in mode determine the type of the input characters, which comparison to run, and the format of the return value. They are described in the following table:
mode in binary |
Defined constant |
Description |
xxxxxx00 |
SIDD_UBYTE_OPS |
a and b contain strings of unsigned 8-bit characters. |
xxxxxx01 |
SIDD_UWORD_OPS |
a and b contain strings of unsigned 16-bit characters. |
xxxxxx10 |
SIDD_SBYTE_OPS |
a and b contain strings of signed 8-bit characters. |
xxxxxx11 |
SIDD_SWORD_OPS |
a and b contain strings of signed 16-bit characters. |
xxxx00xx |
SIDD_CMP_EQUAL_ANY |
Find if equal any mode: For each character c in a, determine whether any character in b is equal to c. |
xxxx01xx |
SIDD_CMP_RANGES |
Find in ranges mode: For each character c in a, determine whether b0 <= c <= b1or b2 <= c <= b3… |
xxxx10xx |
SIDD_CMP_EQUAL_EACH |
Find if equal each mode: This implements the string equality algorithm. |
xxxx11xx |
SIDD_CMP_EQUAL_ORDERED |
Find if equal ordered mode: This implements the substring search algorithm. |
xx01xxxx |
SIDD_NEGATIVE_POLARITY |
Negation of resulting bitmask. |
xx11xxxx |
SIDD_MASKED_NEGATIVE_POLARITY |
Negation of resulting bitmask except for bits that have an index larger than the size of a or b (see details of pcmpstri instruction). |
Before using this intrinsic, software must ensure that the processor supports the instruction.
Example
#include <stdio.h>
#include <nmmintrin.h>
int main ()
{
__m128i a, b;
// Note: SIDD_LEAST_SIGNIFICANT sets the same bit as SIDD_BIT_MASK
const int mode = SIDD_UWORD_OPS | SIDD_CMP_EQUAL_EACH | SIDD_LEAST_SIGNIFICANT;
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);
return 0;
}
_mm_cmpistra return value should be 1: 1
_mm_cmpistra return value should be 0: 0
_mm_cmpistrc return value should be 0: 0
_mm_cmpistrc return value should be 1: 1
_mm_cmpistri return value should be 5: 5
_mm_cmpistrm return value: 0x0000000000000000 0x0000000000000021
_mm_cmpistro return value should be 1: 1
_mm_cmpistrs return value should be 0: 0
_mm_cmpistrs return value should be 1: 1
_mm_cmpistrz return value should be 0: 0
_mm_cmpistrz return value should be 1: 1