Friday 15 April 2011

c - sse - testing equality between two __m128i variables -



c - sse - testing equality between two __m128i variables -

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

although using _mm_movemask_epi8 1 solution, if have processor sse4.1 think improve solution utilize 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 improve 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

c x86 sse simd

No comments:

Post a Comment