IA-32 Intel® Architecture Optimization
4-26
Clipping to an Arbitrary Range [high, low]
This section explains how to clip a values to a range [
high, low
].
Specifically, if the value is less than
low
or greater than
high
, then clip
to
low
or
high,
respectively. This technique uses the packed-add and
packed-subtract instructions with saturation (signed or unsigned), which
means that this technique can only be used on packed-byte and
packed-word data types.
The examples in this section use the constants
packed_max
and
packed_min
and show operations on word values. For simplicity we use
the following constants (corresponding constants are used in case the
operation is done on byte values):
•
packed_max
equals
0x7fff7fff7fff7fff
•
packed_min
equals
0x8000800080008000
•
packed_low
contains the value
low
in all four words of the
packed-words data type
•
packed_high
contains the value
high
in all four words of the
packed-words data type
•
packed_usmax
all values equal
1
•
high_us
adds the
high
value to all data elements (4 words) of
packed_min
•
low_us
adds the
low
value to all data elements (4 words) of
packed_min
CAUTION.
The absolute value of the most negative
number (that is, 8000 hex for 16-bit) cannot be
represented using positive numbers. This algorithm
will return the original value for the absolute value
(8000 hex).
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...