[LLVMdev] Generating Floating point constants

St├ęphane Letz letz at grame.fr
Thu Jun 3 04:43:46 PDT 2010


> ------------------------------
> 
> Message: 4
> Date: Wed, 2 Jun 2010 11:07:39 -0700
> From: Dale Johannesen <dalej at apple.com>
> Subject: Re: [LLVMdev] Generating Floating point constants
> To: St?phane Letz <letz at free.fr>
> Cc: llvmdev at cs.uiuc.edu
> Message-ID: <AEC895CC-E887-4329-8743-FA606BD401F6 at apple.com>
> Content-Type: text/plain; charset=iso-8859-1
> 
> 
> On Jun 2, 2010, at 11:05 AMPDT, St?phane Letz wrote:
>>>> 
>>>>> and you don't care about the precise hexadecimal
>>>>> representation, AFAIK just printing a decimal float works.  
>>>> 
>>>> Seems like some values cannot be assembled later on (for instance with "llc")
>>> 
>>> Yes, there are floating point values (such as NaNs) that cannot be expressed in decimal, and others that would require a prohibitively large number of digits.  You don't want to do that.
>>> 
>>> The code that writes out APFloats is in WriteConstantInt [sic] in VMCore/AsmWriter.cpp.  It's not set up to do conversions separately from writing out, but you should be able to figure it out.
>> 
>> Thanks... but this is linked to the LLVM code base right?
> 
> It's part of LLVM, yes.
> 
>> Is there any self-contained code that can be used to handle floats when writing textual LLVM IR?
> 
> Not that I know of.
> 


I'm becoming crazy with this stuff, for instance

0.8f get converted in 0x3FE99999A0000000 by LLVM (looking at textual generated IR) but  the following tool: 

http://babbage.cs.qc.edu/IEEE-754/Decimal.html  gives:

0x3FE999999999999A  instead and this value cannot be read back by "llc"...

Am I the only one to need to generate constants float in LLVL IR ? 

St├ęphane Letz








More information about the llvm-dev mailing list