[llvm-commits] [PATCH] UINT_TO_FP of vectors

Dirk Steinke steinke.dirk.ml at googlemail.com
Wed Mar 16 17:13:41 PDT 2011


On 03/16/2011 11:40 PM, Stephen Canon wrote:
> On Mar 16, 2011, at 3:29 PM, Dirk Steinke wrote:
>
> [snip]
>>   SINT_TO_FP(high 31 bits) * (2) + SINT_TO_FP(low 1 bit)
>
> This actually suffers from the same problem; 0x81000081 rounds to 0x81000000 instead of 0x81000100 as it should.
>
> In order to work properly, an int->float conversion needs to consist of a sum of two values, both of which are guaranteed to have been converted without rounding.  There are tricks (sticky bits) that can be used to simplify this somewhat in more extreme cases (like uint64_t ->  float), but generally you need each of the components to be built from fewer bits than the precision of the floating-point type.
>
> - Steve

The way I see it, you can still simplify, if you know that the rounding 
is correct in the first place. That is, if the msb or lsb of the integer 
is zero, you can use a single SINT_TO_FP. (If the msb is zero, 
UINT_TO_FP is the same as SINT_TO_FP. If the lsb is zero, SRL by 1, 
SINT_TO_FP and FADD to double the number should work. Correct me if I'm 
wrong - again. :)
Unfortunately, for a vector, you have to prove that all msbs or all lsbs 
of the elements are zero. Tricky. If the integers are fed from
memory, the original value range information is probably already lost...
Well, thanks for the enlightening discussion.

Dirk



More information about the llvm-commits mailing list