What does UnsignedSaturate mean in an SSE instruction?

I am converting a SIMD code into an equivalent code. I am stuck in one of the SSE instructions.

__m128i _mm_packus_epi16 (__m128i a, __m128i b) 

he returns

 r0 := UnsignedSaturate(a0) r1 := UnsignedSaturate(a1) ... r7 := UnsignedSaturate(a7) r8 := UnsignedSaturate(b0) r9 := UnsignedSaturate(b1) ... r15 := UnsignedSaturate(b7) 

What does UnsignedSaturate mean?

+6
source share
3 answers

In principle, “saturation” means that values ​​outside a certain “max” value are set to “max”, and values ​​below the “min” value are set to “min”. Typically, "min" and "max" are values ​​suitable for some type of data.

Thus, for example, if you take arithmetic for unsigned bytes, "128 + 128" should be "256" (this is hexadecimal 0x100), which does not fit in bytes. Regular integer arithmetic will create an overflow and discard the part that does not fit, which means "128 + 128 → 0". With rich arithmetic "256> 255", so the result is 255.

Another option would be scaling, which basically “compresses” the values ​​to a smaller range. Saturation just turns them off.

You can also use this to put larger types into smaller ones, for example, put 16-bit values ​​in 8-bit values. Your example most likely does just that, although you probably know better than I do what types you deal with.

"UnsignedSaturation" most likely has a minimum of "0" and "max" of any maximum value of the result type. Thus, negative inputs turn into "0".

+14
source

The command converts 16-bit signed integers to 8-bit unsigned integers. The problem is what to do when the value is not appropriate. In other words, it is less than 0 or greater than 255. Unsigned saturation indicates that the value is then clipped to its range. In other words, values ​​less than 0 are converted to 0, from 255 to 255.

+3
source

Saturation simply means that a given variable preserves the maximum possible value instead of overflow.

 unsigned short v1 = 65535; unsigned (saturate) short v2 = 65535; v1++; v2++; printf("v1=%u v2=%u\n", v1, v2); 

prints v1 = 0 v2 = 65535

The concept of saturated does not exist in the C standard and should be provided by extensions.

+1
source

Source: https://habr.com/ru/post/923855/


All Articles