[llvm-commits] [PATCH] UINT_TO_FP of vectors

Stephen Canon scanon at apple.com
Wed Mar 16 14:29:10 PDT 2011


> 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





More information about the llvm-commits mailing list