简体   繁体   English

__m128i变量是零吗?

[英]Is an __m128i variable zero?

如何测试__m128i变量在SSE-2及更早版本的处理器上是否具有任何非零值?

In SSE2 you can do: 在SSE2中,您可以:

__m128i zero = _mm_setzero_si128();
if(_mm_movemask_epi8(_mm_cmpeq_epi32(x,zero)) == 0xFFFF)
{
    //the code...
}

this will test four int's vs zero then return a mask for each byte, so your bit-offsets of each corresponding int would be at 0, 4, 8 & 12, but the above test will catch if any bit is set, then if you preserve the mask you can work with the finer grained parts directly if need be. 这将测试四个int与零然后为每个字节返回一个掩码,因此每个对应的int位偏移将是0,4,8和12,但上面的测试将捕获是否设置了任何位,然后如果你如果需要,可以直接保留可以使用更细粒度部件的面罩。

For the sake of completeness, with SSE4 one can use _mm_testz_si128 . 为了完整起见,使用SSE4可以使用_mm_testz_si128

const bool isAllZero = _mm_testz_si128(a,a);

Note that this is true when all bits are zero . 注意,当所有位都为零时,这是真的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM