From: simonmar Date: Mon, 27 Jun 2005 13:56:32 +0000 (+0000) Subject: [project @ 2005-06-27 13:56:32 by simonmar] X-Git-Tag: cmm-merge2~69 X-Git-Url: http://git.megacz.com/?p=ghc-base.git;a=commitdiff_plain;h=b7e861ce34a4d50c777db284cf650f55b58a16a3 [project @ 2005-06-27 13:56:32 by simonmar] Fix performance buglet: small Float literals weren't being simplified enough because the fromInteger method is defined in terms of encodeFloat, which itself is an FFI call. Double was already fixed, this change does the right thing for Float too. --- diff --git a/GHC/Float.lhs b/GHC/Float.lhs index c4003b4..cac8c0a 100644 --- a/GHC/Float.lhs +++ b/GHC/Float.lhs @@ -189,10 +189,13 @@ instance Num Float where | otherwise = negate 1 {-# INLINE fromInteger #-} - fromInteger n = encodeFloat n 0 - -- It's important that encodeFloat inlines here, and that - -- fromInteger in turn inlines, - -- so that if fromInteger is applied to an (S# i) the right thing happens + fromInteger (S# i#) = case (int2Float# i#) of { d# -> F# d# } + fromInteger (J# s# d#) = encodeFloat# s# d# 0 + -- previous code: fromInteger n = encodeFloat n 0 + -- doesn't work too well, because encodeFloat is defined in + -- terms of ccalls which can never be simplified away. We + -- want simple literals like (fromInteger 3 :: Float) to turn + -- into (F# 3.0), hence the special case for S# here. instance Real Float where toRational x = (m%1)*(b%1)^^n