Non-SIMD subtract w/saturation...
Author Message
Non-SIMD subtract w/saturation...

I'm looking for code to subtract 4, 8-bit, numbers in a way such that if
a value wraps around (ie: 100 - 200), it does not interfere with the other
bytes.
If sign matters, then I'm looking for an unsigned solution.

See ya!
Orlando

Mon, 21 Mar 2005 03:56:06 GMT
Non-SIMD subtract w/saturation...

Quote:

>     I'm looking for code to subtract 4, 8-bit, numbers in a way such that if
> a value wraps around (ie: 100 - 200), it does not interfere with the other
> bytes.
>     If sign matters, then I'm looking for an unsigned solution.

I use this code in FBlend:

For a better description, see:
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/fblend/fble...

/* Compute saturation of difference */
/* color1 and color2 are 32-bit RGBA colors */
temp1 = (color2 & 0x80808080) ^ 0x80808080;
temp2 =  color1 & 0x80808080;
color1 = (color2 | 0x80808080) - (color1 & 0x7F7F7F7F);
color2 = temp1;
temp1 = temp1 | temp2;
temp2 = color2 & temp2;
color2 = temp1 & (color1 ^ 0x80808080);
temp2 = (temp2 | color2) >> 7; /* Make sure it's unsigned shift */

temp2 = ((temp2 + 0x7F7F7F7F) ^ 0x80808080);
color1 = temp2 & (temp1 ^ color1);

/* color1 has the saturated difference */

You can put 0x80808080 in memory to save code space. It can also dual as
0x7F7F7F7F if you 'not' it.

Fri, 25 Mar 2005 15:07:32 GMT
Non-SIMD subtract w/saturation...

Quote:

> I use this code in FBlend:
> ...
> 0x7F7F7F7F if you 'not' it.

Thanks! :)

See ya!
Orlando

Tue, 29 Mar 2005 01:23:19 GMT

 Page 1 of 1 [ 3 post ]

Relevant Pages