[Haskell-cafe] Optimizations and constant unboxed values

Pierre-Etienne Meunier pierreetienne.meunier at gmail.com
Thu May 27 20:22:30 EDT 2010


Hi Cafe,

Profiling a function that I thought ultra simple revealed that it consumed more than half the execution time of my code. After noticing that GHC did not unbox all I thought it did, I rewrote it with primitive types, and it did a little better, but not much. Then, examining the core (with of course -O3 on) revealed things like :

 (GHC.Prim.*##
                  (GHC.Prim.-## 1.0 (GHC.Prim.**## 2.0 -53.0))
                  (GHC.Prim.**## 2.0 1024.0))

or

 case GHC.Prim.<## x_aB9 (GHC.Prim.**## 2.0 -1021.0) of _  {...

Then I wondered if this was really the last stage of GHC's optimizations, as constants are not yet propagated. Or maybe GHC does not propagate constants, in which case I'd really like to write my 1-2^53 and 2^-1021 once and for all in my program. But since unsafeCoerce# does not work between doubles and words ( there is a trac ticket about it : http://hackage.haskell.org/trac/ghc/ticket/4092 ), I do not even think this is possible (and of course, specifying a double in decimal notation with ## is not precise enough for this program).

Any clue about how to do it ?

Thanks,
PE



More information about the Haskell-Cafe mailing list