SSE4 128bit TEST指令

Test Intrinsics

These Intel® Streaming SIMD Extensions (Intel® SSE4) intrinsics perform packed integer 128-bit comparisons. The prototypes for these instrinsics are in the smmintrin.h file.

Intrinsic Name

Operation

Corresponding 
Intel® SSE4 Instruction

_mm_testz_si128

Check for all zeros in specified bits of a 128-bit value

PTEST

_mm_testc_si128

Check for all ones in specified bits of a 128-bit value

PTEST

_mm_testnzc_si128

Check for at least one zero and at least one one in the specified bits of a 128-bit value

PTEST

int _mm_testz_si128 (__m128i s1, __m128i s2)

Returns 1 if the bitwise AND operation on s1 and s2 results in all zeros, else returns 0. That is,

_mm_testz_si128 := ( (s1 & s2) == 0 ? 1 : 0 )

This intrinsic checks if the ZF flag equals 1 as a result of the instruction PTEST s1, s2. For example, it allows you to check if all set bits in s2 (mask) are zeros in s1.

Corresponding instruction: PTEST

int _mm_testc_si128 (__m128i s1, __m128i s2)

Returns 1 if the bitwise AND operation on s2 and logical NOT s1 results in all zeros, else returns 0. That is,

_mm_testc_si128 := ( (~s1 & s2) == 0 ? 1 : 0 )

This intrinsic checks if the CF flag equals 1 as a result of the instruction PTEST s1, s2. For example it allows you to check if all set bits in s2 (mask) are also set in s1.

Corresponding instruction: PTEST

int _mm_testnzc_si128 (__m128i s1, __m128i s2)

Returns 1 if the following conditions are true: bitwise operation of s1 AND s2 does not equal all zeros and bitwise operation of NOT s1 AND s2 does not equal all zeros, otherwise returns 0. That is,

_mm_testnzc_si128 := ( ( (s1 & s2) != 0 && (~s1 & s2) != 0 ) ? 1 : 0 )

This intrinsic checks if both the CF and ZF flags are not 1 as a result of the instruction PTEST s1, s2. For example, it allows you to check that the result has both zeros and ones in s1 on positions specified as set bits in s2 (mask).

Corresponding instruction: PTEST

http://software.intel.com/sites/products/documentation/studio/composer/en-us/2011Update/compiler_c/index.htm#intref_cls/common/intref_sse41_test.htm

Example1:

http://msdn.microsoft.com/en-us/library/bb513983(v=vs.90).aspx

#include <stdio.h>
#include <smmintrin.h>

int main ()
{
    __m128i a, b;

    a.m128i_u64[0] = 0xAAAA55551111FFFF;
    b.m128i_u64[0] = 0xAAAA55551111FFFF;

    a.m128i_u64[1] = 0xFEDCBA9876543210;
    b.m128i_u64[1] = 0xFEDCBA9876543210;

    int res1 = _mm_testc_si128(a, b);

    a.m128i_u64[0] = 0xAAAA55551011FFFF;

    int res2 = _mm_testc_si128(a, b);

    printf_s("First result should be 1: %d\nSecond result should be 0: %d\n",
                res1, res2);

    return 0;
}

Example2:

static const __m128i zero = {0};

inline bool compare128(__m128i a, __m128i b) {
    __m128i c = _mm_xor_si128(a, b);
    return _mm_testc_si128(zero, c);
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值