SSE - 两个__m128i变量之间的平等测试 [英] sse - testing equality between two __m128i variables
问题描述
如果我想要做的两个 __ m128i
变量之间的按位平等的测试,我是否需要使用SSE指令或者我可以使用 ==
?如果没有,SSE指令我应该使用哪个?
If I want to do a bitwise equality test between two __m128i
variables, am I required to use an SSE instruction or can I use ==
? If not, which SSE instruction should I use?
推荐答案
虽然使用 _mm_movemask_epi8
是一个解决方案,如果你有一个处理器,SSE4.1,我认为一个更好的解决方案是使用它设置为零的指令或进位标志在FLAGS寄存器。 <一href=\"https://stackoverflow.com/questions/26623050/checking-if-two-sse-registers-are-not-both-zero-without-destroying-them/26651301#26651301\">This节省了测试
或 CMP
指令。
Although using _mm_movemask_epi8
is one solution, if you have a processor with SSE4.1 I think a better solution is to use an instruction which sets the zero or carry flag in the FLAGS register. This saves a test
or cmp
instruction.
要做到这一点,你可以这样做:
To do this you could do this:
if(_mm_test_all_ones(_mm_cmpeq_epi8(v1,v2))) {
//v0 == v1
}
编辑:保罗 - [R指出 _mm_test_all_ones
生成两个指令: pcmpeqd
和 PTEST
。随着 _mm_cmpeq_epi8
这三个指令总。这里有一个更好的解决方案只使用了总共两个指令:
as Paul R pointed out _mm_test_all_ones
generates two instructions: pcmpeqd
and ptest
. With _mm_cmpeq_epi8
that's three instructions total. Here's a better solution which only uses two instructions in total:
__m128i neq = _mm_xor_si128(v1,v2);
if(_mm_test_all_zeros(neq,neq)) {
//v0 == v1
}
这会产生
pxor %xmm1, %xmm0
ptest %xmm0, %xmm0
这篇关于SSE - 两个__m128i变量之间的平等测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!