I found this question:
Which I used to create the below example:
int main(){
__m128i intrinreg;
intrinreg.m128i_i64[0] = 0;
intrinreg.m128i_i64[1] = 6;
__m128i zero = _mm_setzero_si128();
if (0 == _mm_movemask_epi8(_mm_cmpeq_epi32(intrinreg, zero)))
{
std::cout << "true" << std::endl;
}
else{
std::cout << "false" << std::endl;
}
}
but whether I set the two 64-bit int components to 0 or a non-zero, I always get "false" print out?
Since you have tagged AVX I assume that you have SSE4.1 in which case the instruction you want is
ptest
which you can get from_mm_testz_si128
or_mm_test_all_zeros()
.If you don't have SSE4.1 then use
_mm_movemask_epi8(_mm_cmpeq_epi32(x,_mm_setzero_si128())) == 0xFFFF
. This requirespcmpeqd
,pmovmskb
, andtest
.However,
ptest
sets the zero flag (ZF) so it only needs one instruction. See checking-if-two-sse-registers-are-not-both-zero-without-destroying-them for more details.