c - Testing equality between two __m128i variables -


if want bitwise equality test between 2 __m128i variables, required use sse instruction or can use ==? if not, sse instruction should use?

although using _mm_movemask_epi8 1 solution, if have processor sse4.1 think better solution use instruction sets 0 or carry flag in flags register. this saves test or cmp instruction.

to this:

if(_mm_test_all_ones(_mm_cmpeq_epi8(v1,v2))) {     //v0 == v1 } 

edit: paul r pointed out _mm_test_all_ones generates 2 instructions: pcmpeqd , ptest. _mm_cmpeq_epi8 that's 3 instructions total. here's better solution uses 2 instructions in total:

__m128i neq = _mm_xor_si128(v1,v2); if(_mm_test_all_zeros(neq,neq)) {     //v0 == v1 } 

this generates

pxor    %xmm1, %xmm0 ptest   %xmm0, %xmm0 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -