[llvm-commits] [PATCH] UINT_TO_FP of vectors

Dirk Steinke steinke.dirk.ml at googlemail.com
Wed Mar 16 15:29:55 PDT 2011


On 03/16/2011 10:29 PM, Stephen Canon wrote:
>> thanks for working on this, but your code seems suboptimal to me. If I'm
>> not mistaken, you should be able to turn
>>     UINT_TO_FP(a) into SINT_TO_FP(a&  ~SIGNBIT) - SINT_TO_FP(a&  SIGNBIT)
>> which gets rid of one floating point multiplication, and replaces one
>> shift by an AND, but at the cost of one extra vector constant. In
>> theory, using PANDN on x86, one memory load should be enough, but
>> well... What do you think?
>
> You are mistaken.
>
> You cannot implement uint ->  fp as you describe, as it introduces a double-rounding for certain values.  There are many, but here is one example to illustrate the problem 0x81000081.  It is one greater than an exact halfway case for rounding to single-precision, but the result when using the algorithm you describe is rounded *down* instead of up with default IEEE-754 rounding.
>
> - Steve
>
>
Hi Steve,

thanks. I had just realized myself, that the number of mantissa bits are 
quite smaller than the bits in the equivalent integer, and there will be 
rounding when the high bits of the integer are set. So changing the sign 
bit is a bad idea.
The only other thing I could come up with right now, is changing the 
partitioning from like
   SINT_TO_FP(high 16 bits) * (2^16) + SINT_TO_FP(low 16 bits)
to
   SINT_TO_FP(high 31 bits) * (2) + SINT_TO_FP(low 1 bit)
so that the mul could be turned into an add instead. But with 
fmadd-units around the corner, and separate fmul- and fadd-units at 
least on x86, that would be counter-productive.

Nadav, sorry for the noise.

Dirk



More information about the llvm-commits mailing list