Do you know any way to add with saturation 32-bit signed words using MMX/SSE assembler instructions? I can find 8/16 bits versions but no 32-bit ones.
Add 32-bit words with saturation
2.9k Views Asked by LooPer At
2
There are 2 best solutions below
0

Saturated unsigned subtraction is easy, because for `a -= b', we can do
asm (
"pmaxud %1, %0\n\t" // a = max (a,b)
"psubd %1, %0" // a -= b
: "+x" (a)
: "xm" (b)
);
with SSE.
I was looking for unsigned addition, but possibly, the only way is to transform to a saturated unsigned subtraction, perform it, and transform back. Same for signed variants.
EDIT: with unsigned addition, you get min (a, ~b) + b
this way, which of course works. With signed addition and subtraction, you have two saturation boundaries, which makes things complicated.
You can emulate saturated signed adds by performing the following steps:
Unsigned, it's even simpler, see this stackoverflow posting
In SSE2, the above maps to a sequence of parallel compares and AND/ANDN operations. No single operation is available in hardware, unfortunately.