Exportar (0) Imprimir
Expandir todo
Expandir Minimizar
Este tema aún no ha recibido ninguna valoración - Valorar este tema

_mm_cmpestra

Microsoft Specific

Emits the Streaming SIMD Extensions 4 (SSE4) instruction pcmpestri This instruction compares two parameters.

int _mm_cmpestra (
   __m128i a, 
   int la,
   __m128i b,
   int lb, 
   const int mode
); 

Parameter

Description

[in] a

A string fragment with a maximum size of 16 byte characters or 8 word characters.

[in] la

An integer that specifies the size of the string in a.

[in] b

A string fragment with a maximum size of 16 byte characters or 8 word characters.

[in] lb

An integer that specifies the size of the string in b.

[in] mode

A constant that indicates whether characters are bytes or words, the type of comparison to do, and the format of the returned value.

One if the absolute value of lb is larger than or equal to MaxSize and the resulting mask is equal to zero. Otherwise, zero. The pcmpestri instruction computes the bitmask, where bit0, bit1, bit2… in the mask correspond to the result of the operation on a0, a1, a2… in a.

Intrinsic

Architecture

_mm_cmpestra

x86, x64

Header file <nmmintrin.h>

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 pcmpestri instruction).

Before using this intrinsic, software must ensure that the processor supports the instruction.

#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] = 0xCCCC;
    a.m128i_u16[6] = 0xCCCC;
    a.m128i_u16[5] = 0xCCCC;
    a.m128i_u16[4] = 0xCCCC;
    a.m128i_u16[3] = 0xCCCC;
    a.m128i_u16[2] = 0xCCCC;
    a.m128i_u16[1] = 0xCCCC;
    a.m128i_u16[0] = 0xCCCC;

    b.m128i_u16[7] = 0x3333;
    b.m128i_u16[6] = 0x3333;
    b.m128i_u16[5] = 0x3333;
    b.m128i_u16[4] = 0x3333;
    b.m128i_u16[3] = 0x3333;
    b.m128i_u16[2] = 0x3333;
    b.m128i_u16[1] = 0x3333;
    b.m128i_u16[0] = 0x3333;

    int returnValue = _mm_cmpestra(a, 8, b, -8, mode);
    printf_s("_mm_cmpestra return value should be 1: %i\n", returnValue);

    returnValue = _mm_cmpestrc(a, 8, b, 8, mode);
    printf_s("_mm_cmpestrc return value should be 0: %i\n", returnValue);

    a.m128i_u16[7] = 0x3333;
    a.m128i_u16[5] = 0x3333;
    returnValue = _mm_cmpestri(a, 8, b, 8, mode);
    printf_s("_mm_cmpestri return value should be 5: %i\n", returnValue);

    // NOTE: mode has _SIDD_LEAST_SIGNIFICANT set which equals _SIDD_BIT_MASK
    __m128i fullResult = _mm_cmpestrm(a, 8, b, 8, mode);
    printf_s("_mm_cmpestrm return value: 0x%016I64x 0x%016I64x\n",
                fullResult.m128i_u64[1], fullResult.m128i_u64[0]);

    returnValue = _mm_cmpestro(a, 8, b, 8, mode);
    printf_s("_mm_cmpestro return value should be 0: %i\n", returnValue);
    a.m128i_u16[0] = 0x3333;
    returnValue = _mm_cmpestro(a, 8, b, 8, mode);
    printf_s("_mm_cmpestro return value should be 1: %i\n", returnValue);

    returnValue = _mm_cmpestrs(a, 8, b, 8, mode);
    printf_s("_mm_cmpestrs return value should be 0: %i\n", returnValue);
    returnValue = _mm_cmpestrs(a, 7, b, 8, mode);
    printf_s("_mm_cmpestrs return value should be 1: %i\n", returnValue);

    returnValue = _mm_cmpestrz(a, 8, b, 8, mode);
    printf_s("_mm_cmpestrz return value should be 0: %i\n", returnValue);
    returnValue = _mm_cmpestrz(a, 8, b, 7, mode);
    printf_s("_mm_cmpestrz return value should be 1: %i\n", returnValue);

    return 0;
}
_mm_cmpestra return value should be 1: 1
_mm_cmpestrc return value should be 0: 0
_mm_cmpestri return value should be 5: 5
_mm_cmpestrm return value: 0x0000000000000000 0x00000000000000a0
_mm_cmpestro return value should be 0: 0
_mm_cmpestro return value should be 1: 1
_mm_cmpestrs return value should be 0: 0
_mm_cmpestrs return value should be 1: 1
_mm_cmpestrz return value should be 0: 0
_mm_cmpestrz return value should be 1: 1
¿Te ha resultado útil?
(Caracteres restantes: 1500)
Gracias por sus comentarios

Adiciones de comunidad

AGREGAR
Mostrar:
© 2014 Microsoft. Reservados todos los derechos.