简体   繁体   English

SSE 16位寄存器的无符号/有符号减法

[英]SSE unsigned/signed subtraction of 16 bit register

I have a __m128i register (Vector A) with 16 bit values with the content: 我有一个带有内容的16位值的__m128i寄存器(向量A):

{100,26,26,26,26,26,26,100} // A Vector

Now I subtract the vector 现在我减去向量

{82,82,82,82,82,82,82,82}

With the instruction 与指示

_mm_sub_epi16(a_vec,_mm_set1_epi16(82)) 

The expected result should be the following vector 预期结果应为以下向量

{18,-56,-56,-56,-56,-56,-56,18}

But I get 但是我明白了

{18,65480,65480,65480,65480,65480,65480,18}

How can I solve that the vector is treated as signed? 如何解决将向量视为带符号的向量?

The A Vector was created by this instruction: A向量是通过以下指令创建的:

__m128i a_vec = _mm_srli_epi16(_mm_unpacklo_epi8(score_vec_8bit, score_vec_8bit), 8)

65480 is the same value as -56 (they are both 0xffc8 at the register level) - you're just displaying it as if it were an unsigned short. 65480-56相同(在寄存器级别上均为0xffc8 )-您只是在显示它,就好像它是无符号的short一样。

Note that for non-saturating addition and subtraction of binary values without carry/borrow flags it really is irrelevant whether the values are signed or unsigned - hence the same instruction can be used for adding both signed and unsigned shorts - the only difference is how you subsequently interpret (or display) the result. 请注意,对于不带进位/借位标志的二进制值进行非饱和加减运算,实际上是无关紧要的,即值是带符号的还是无符号的-因此,同一条指令可用于同时添加带符号的和无符号的短裤-唯一的区别是随后解释(或显示)结果。

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

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