Is there a way to force PMULHRSW to process 0x8000 as 1.0 instead of -1.0?

To process 8-bit pixels, to do things like gamma correction, without losing information, we usually increase the values, work at 16 bits or something else, and then reduce them to 8 bits.

Now this is a slightly new area for me, so please excuse the wrong terminology, etc.

For my needs, I decided to work in the "non-standard" Q15, where I use only the upper half of the range (0.0-1.0), and 0x8000 represents 1.0 instead of -1.0. This makes things much easier to compute in C.

But I had a problem with SSSE3. It has a PMULHRSW instruction that multiplies Q15 numbers, but uses the “standard” range of Q15 [-1.1-2⁻¹⁵], so multplying (my) 0x8000 (1.0) by 0x4000 (0.5) gives 0xC000 (- 0, 5) since it considers 0x8000 to be -1. This is pretty annoying.

What am I doing wrong? Should I keep pixel values ​​in the range 0000-7FFF? Doesn't that mean that the purpose of this is a fixed-point format? Is there any way around this? Maybe some trick?

Is there some final treatise on Q15 that discusses all this?

+5
source share
2 answers

Personally, I would go with the solution of limiting the maximum value to 0x7FFF (~ 0.99something).

  • , , .
  • "" , 0-0x7FFF - Q-format ( ) -1.0 +1.0-one lsb. , 1 lsb 0!

, , , , " 0,01% ", , , .


, , . , , . -1.0 0.0 Q15.

+3

, "", $8000, , $8000 (-1, , 1).

:

pmulhrsw xmm0, xmm1
psignw xmm0, xmm0

, (, !):

pmulhrsw xmm0, xmm1
pabsw xmm0, xmm0

–1 .

+2

All Articles