
Optimizing for SIMD Integer Applications
4
4-25
Absolute Value
|
x
|
, where
x
is signed. This example
assumes signed words to be the operands.
movq
MM2, MM0
; make a copy of source1 (A)
pcmpgtw MM0, MM1
; create mask of
; source1>source2 (A>B)
movq
MM4, MM2
; make another copy of A
pxor
MM2, MM1
; create the intermediate value of
; the swap operation - xor(A,B)
pand
MM2, MM0
; create a mask of 0s and xor(A,B)
; elements. Where A>B there will
; be a value xor(A,B) and where
; A<=B there will be 0.
pxor
MM4, MM2
; minima-xor(A, swap mask)
pxor
MM1, MM2
; maxima-xor(B, swap mask)
psubw
MM1, MM4
; absolute difference =
; maxima-minima
Example 4-18
Computing Absolute Value
; Input:
;
MM0 signed
source
operand
; Output:
;
MM1
ABS(MMO)
pxor
MM1, MM1
; set MM1 to all zeros
psubw
MM1, MM0
; make each MM1 word contain the
; negative of each MM0 word
pmaxsw
MM1, MM0
; MM1 will contain only the positive
; (larger) values - the absolute value
Example 4-17 Absolute Difference of Signed Numbers
(continued)
Summary of Contents for ARCHITECTURE IA-32
Page 1: ...IA 32 Intel Architecture Optimization Reference Manual Order Number 248966 013US April 2006...
Page 220: ...IA 32 Intel Architecture Optimization 3 40...
Page 434: ...IA 32 Intel Architecture Optimization 9 20...
Page 514: ...IA 32 Intel Architecture Optimization B 60...
Page 536: ...IA 32 Intel Architecture Optimization C 22...