简体   繁体   English

SSE指令中的UnsignedSaturate是什么意思?

[英]What does UnsignedSaturate in SSE instruction mean?

I am converting SIMD code into equivalent c code. 我正在将SIMD代码转换为等效的c代码。 I am stuck at one of SSE instructions 我被困在SSE指令之一

__m128i _mm_packus_epi16 (__m128i a, __m128i b)

it returns 它返回

r0 := UnsignedSaturate(a0)
r1 := UnsignedSaturate(a1)

...
r7 := UnsignedSaturate(a7)
r8 := UnsignedSaturate(b0)
r9 := UnsignedSaturate(b1)
...
r15 := UnsignedSaturate(b7)

What does UnsignedSaturate mean? UnsignedSaturate是什么意思?

Basically, "saturation" means that values beyond some "max" value get set to "max", and values below a "min" value get set to "min". 基本上,“饱和度”意味着超出某个“最大”值的值被设置为“最大”,而低于“最小值”的值被设置为“最小”。 Usually, "min" and "max" are the values appropiate for some data type. 通常,“min”和“max”是适合某些数据类型的值。

Thus, for example, if you take arithmetic on unsigned bytes, "128+128" would have to be "256" (which is hex 0x100), which doesn't fit into a byte. 因此,例如,如果对无符号字节进行算术运算,则“128 + 128”必须为“256”(十六进制0x100),这不适合一个字节。 Normal integer arithmetic would create an overflow and discard the part that doesn't fit, which means "128+128 -> 0". 正常整数运算会产生溢出并丢弃不适合的部分,这意味着“128 + 128 - > 0”。 With saturated arithmetic, "256 > 255" so the result is 255. 使用饱和算术,“256> 255”,结果为255。

Another option would be scaling, which basically "compresses" the values to a smaller range. 另一种选择是缩放,它基本上将值“压缩”到较小的范围。 Saturation just cuts them off. 饱和只会削减它们。

You can also use this to put larger types into smaller ones, like putting 16 bit values into 8 bit values. 您也可以使用它将较大的类型放入较小的类型中,例如将16位值放入8位值。 Your example most likely does exactly that, although you'll probably know better than I do what kind of types you are dealing with there. 你的例子最有可能就是这样,虽然你可能比我知道的更好,你在那里处理的是哪种类型。

"UnsignedSaturation" most likely has a min of "0" and a "max" of whatever the max of the result type is. “UnsignedSaturation”最有可能具有“0”的最小值和结果类型的最大值的“最大值”。 Thus, negative inputs get turned into "0". 因此,负输入变为“0”。

The instruction converts 16-bit signed integers to 8-bit unsigned integers. 该指令将16位有符号整数转换为8位无符号整数。 The problem is what to do when the value doesn't fit. 问题是当值不适合时该怎么做。 In other words is less than 0 or larger than 255. Unsigned saturation specifies that the value is then clipped to its range. 换句话说,小于0或大于255.无符号饱和度指定该值被剪切到其范围。 In other words, values less than 0 are converted to 0, more than 255 to 255. 换句话说,小于0的值将转换为0,大于255到255。

Saturate simply means that the given variable keeps the maximum possible value instead of overflowing. 饱和只是意味着给定变量保持最大可能值而不是溢出。

unsigned short v1 = 65535;
unsigned (saturate) short v2 = 65535;

v1++;
v2++;
printf("v1=%u v2=%u\n", v1, v2);

prints v1=0 v2=65535 print v1 = 0 v2 = 65535

The concept of saturates does not exist in standard C and must be provided by extensions. 饱和度的概念在标准C中不存在,必须由扩展提供。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM