User Guide
154 128-Bit Media and Scientific Programming
AMD64 Technology 24592—Rev. 3.15—November 2009
Figure 4-30. PCMPEQB Compare Operation
For the PCMPEQx instructions, if the compared values are equal, the result mask is all 1s. If the values
are not equal, the result mask is all 0s. For the PCMPGTx instructions, if the signed value in the first
operand is greater than the signed value in the second operand, the result mask is all 1s. If the value in
the first operand is less than or equal to the value in the second operand, the result mask is all 0s.
By specifying the same register for both operands, PCMPEQx can be used to set the bits in an XMM
register to all 1s.
Figure 4-10 on page 115 shows an example of a non-branching sequence that implements a two-way
multiplexer—one that is equivalent to the following sequence of ternary operators in C or C++:
r0=a0>b0?a0:b0
r1=a1>b1?a1:b1
r2=a2>b2?a2:b2
r3=a3>b3?a3:b3
r4=a4>b4?a4:b4
r5=a5>b5?a5:b5
r6=a6>b6?a6:b6
r7=a7>b7?a7:b7
Assuming xmm0 contains the vector a, and xmm1 contains the vector b, the above C sequence can be
implemented with the following assembler sequence:
MOVQ xmm3, xmm0
PCMPGTW xmm3, xmm1 ;a>b?0xffff : 0
PAND xmm0, xmm3 ;a>b?a:0
PANDN xmm3, xmm1 ;a>b?0:b
POR xmm0, xmm3 ;r=a>b?a:b
513-168.eps
result
operand 1
127 0
127 0
operand 2
127 0
imm8
compare
all 1s or 0s all 1s or 0s
compare
. . . . . . . . . . . . . .
. . . . . . . . . . . . . .
. . . . . . . . . . . . . .