[LLVMdev] Complex constant expressions?

Neil Booth neil at daikokuya.co.uk
Wed Jan 23 05:10:52 PST 2008


Talin wrote:-

> Well, I may be using it wrong. But looking at APFloat.h, I see four 
> functions that purport to convert to integer:
> 
>     opStatus convertToInteger(integerPart *, unsigned int, bool,
>                   roundingMode) const;
>     opStatus convertFromSignExtendedInteger(const integerPart *, 
> unsigned int,
>                                             bool, roundingMode);
>     opStatus convertFromZeroExtendedInteger(const integerPart *, 
> unsigned int,
>                                             bool, roundingMode);
>     APInt convertToAPInt() const;
> 
> The first three convert to an array of integer parts, which (as far as I 
> can tell) is not easily convertible into an APInt via any public methods 
> I have been able to discover so far.
> 
> The last function doesn't appear to convert the APFloat into the nearest 
> integer equivalent, since my experiments with it returned completely 
> unexpected values; I'm assuming that what is returned is an APInt 
> containing the bitwise representation of the floating-point value?

Only two convert to integer.  The convertToAPInt is unfortunately
named; I'm not sure what it does but suspect it captures bitpatterns
like you suggest.

convertToInteger is the function I'm responsible for and it does
float->int conversion according to IEEE754.  If you want to place
it in an APInt, create your APInt with the appropriate size and
use its buffer as input.  APInt has made unfortunate sign choices
though, IIRC it is not sign-extended, so you may need to fudge in
the case of a signed target.  This is also why there are two "from"
functions above :(

Neil.



More information about the llvm-dev mailing list