Le 3 juin 2010 à 16:00, Martin Guy a écrit :> [off list] > >> 0.8f get converted in 0x3FE99999A0000000 by LLVM > > single precision > >> http://babbage.cs.qc.edu/IEEE-754/Decimal.html gives: >> >> 0x3FE999999999999A instead and this value cannot be read back by "llc"... > > double precision > > MWell For float 0.8 : http://babbage.cs.qc.edu/IEEE-754/Decimal.html 3F4CCCCD for Single precision (32 bits): 3FE999999999999A for Double precision (64 bits): Still different compared to LLVM... Any idea? Stéphane
On Jun 3, 2010, at 7:05 AMPDT, Stéphane Letz wrote:> Le 3 juin 2010 à 16:00, Martin Guy a écrit : > >> [off list] >> >>> 0.8f get converted in 0x3FE99999A0000000 by LLVM >> >> single precision >> >>> http://babbage.cs.qc.edu/IEEE-754/Decimal.html gives: >>> >>> 0x3FE999999999999A instead and this value cannot be read back by >>> "llc"... >> >> double precisionMartin is right. Floats have only 36 significant bits (sign + 11 exponent + 24 mantissa) and are stored that way. (The exponent is in double format for some reason I've forgotten, probably because it was easier somewhere.) Any resemblance to IEEE-754/Decimal is coincidental. And no, I don't know of anybody else having trouble with this. Why can't you connect to the AsmWriter in your code?
On Jun 3, 2010, at 7:05 AM, Stéphane Letz wrote:> > Le 3 juin 2010 à 16:00, Martin Guy a écrit : > >> [off list] >> >>> 0.8f get converted in 0x3FE99999A0000000 by LLVM >> >> single precision >> >>> http://babbage.cs.qc.edu/IEEE-754/Decimal.html gives: >>> >>> 0x3FE999999999999A instead and this value cannot be read back by "llc"... >> >> double precision >> >> M > > > Well > > For float 0.8 : > > http://babbage.cs.qc.edu/IEEE-754/Decimal.html > > 3F4CCCCD for Single precision (32 bits): > > 3FE999999999999A for Double precision (64 bits): > > Still different compared to LLVM... > > Any idea?LLVM serializes and deserializes float constants in double precision. I don't know why. 0x3F4CCCCD = (sign=0, exp=01111110 (-1), significand=0x99999A) 0x3FE99999A0000000 = (sign = 0, exp=01111111110 (-1), significand=0x99999A0000000) If you try to deserialize 0x3FE999999999999A as a float, it loses a lot of precision, which I presume is why llc complains. John.
Le 3 juin 2010 à 19:41, Dale Johannesen a écrit :> On Jun 3, 2010, at 7:05 AMPDT, Stéphane Letz wrote: >> Le 3 juin 2010 à 16:00, Martin Guy a écrit : >> >>> [off list] >>> >>>> 0.8f get converted in 0x3FE99999A0000000 by LLVM >>> >>> single precision >>> >>>> http://babbage.cs.qc.edu/IEEE-754/Decimal.html gives: >>>> >>>> 0x3FE999999999999A instead and this value cannot be read back by "llc"... >>> >>> double precision > > Martin is right. Floats have only 36 significant bits (sign + 11 exponent + 24 mantissa) and are stored that way. (The exponent is in double format for some reason I've forgotten, probably because it was easier somewhere.) Any resemblance to IEEE-754/Decimal is coincidental. And no, I don't know of anybody else having trouble with this. Why can't you connect to the AsmWriter in your code? >Because this seems like a very big dependency constraint to be able to do something as simple as using "floats" in a textual format. I would have been happy to be able to copy a 10 lines function in my own code to do that conversion. Stéphane Letz