Building blocks, Absolute difference of unsigned numbers, Building blocks -23 – Intel ARCHITECTURE IA-32 User Manual

Page 243: Absolute difference of unsigned numbers -23, Example 4-16, Absolute difference of two unsigned numbers -23

Advertising
background image

Optimizing for SIMD Integer Applications

4

4-23

Building Blocks

This section describes instructions and algorithms which implement
common code building blocks efficiently.

Absolute Difference of Unsigned Numbers

Example 4-16 computes the absolute difference of two unsigned
numbers. It assumes an unsigned packed-byte data type. Here, we make
use of the subtract instruction with unsigned saturation. This instruction
receives

UNSIGNED

operands and subtracts them with

UNSIGNED

saturation. This support exists only for packed bytes and packed words,
not for packed doublewords.

This example will not work if the operands are signed.

Note that the

psadbw

instruction may also be used in some situations;

see section “Packed Sum of Absolute Differences” for details.

Example 4-16 Absolute Difference of Two Unsigned Numbers

; Input:

;

MM0 source operand

;

MM1 source operand

; Output:

;

MM0 absolute difference of the unsigned

;

operands

movq

MM2, MM0

; make a copy of MM0

psubusb MM0, MM1

; compute difference one way

psubusb MM1, MM2

; compute difference the other way

por

MM0, MM1

; OR them together

Advertising