Hi, We need to generate "Floating point constants" in our code. In http://llvm.org/docs/LangRef.html it is explained that FP has to follow special encoding rules to be handled by LLVM later one (hexadecimal coding...) Is there any code available in LLVM to handle this kind of "standard float to LLVM float" conversion? Thanks. Stéphane Letz
On Wed, Jun 2, 2010 at 2:59 AM, Stéphane Letz <letz at free.fr> wrote:> Hi, > > We need to generate "Floating point constants" in our code. In http://llvm.org/docs/LangRef.html it is explained that FP has to follow special encoding rules to be handled by LLVM later one (hexadecimal coding...) > > Is there any code available in LLVM to handle this kind of "standard float to LLVM float" conversion?If you're writing C++ code, just stick your float into an APFloat and doesn't worry about the hexadecimal coding. If you're generating textual IR, and you don't care about the precise hexadecimal representation, AFAIK just printing a decimal float works. If you really want a hexadecimal encoding, just reinterpret the floating-point number as an integer and print in hexadecimal; an "LLVM float" is just an IEEE float printed in hexadecimal. -Eli
Le 2 juin 2010 à 12:21, Eli Friedman a écrit :> On Wed, Jun 2, 2010 at 2:59 AM, Stéphane Letz <letz at free.fr> wrote: >> Hi, >> >> We need to generate "Floating point constants" in our code. In http://llvm.org/docs/LangRef.html it is explained that FP has to follow special encoding rules to be handled by LLVM later one (hexadecimal coding...) >> >> Is there any code available in LLVM to handle this kind of "standard float to LLVM float" conversion? > > If you're writing C++ code, just stick your float into an APFloat and > doesn't worry about the hexadecimal coding. If you're generating > textual IR,Yes we are generating textual IR,> 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")> If you > really want a hexadecimal encoding, just reinterpret the > floating-point number as an integer and print in hexadecimal; an "LLVM > float" is just an IEEE float printed in hexadecimal. >I will try. Thanks Stéphane Letz