I have a __m128i register (Vector A) with 16 bit values with the content:
{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:
__m128i a_vec = _mm_srli_epi16(_mm_unpacklo_epi8(score_vec_8bit, score_vec_8bit), 8)
65480is the same value as-56(they are both0xffc8at the register level) – you’re just displaying it as if it were an unsigned 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.