summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCheng Shao <astrohavoc@gmail.com>2022-03-08 09:53:30 +0000
committerMarge Bot <ben+marge-bot@smart-cactus.org>2022-03-11 20:00:01 -0500
commit27da55407121461695a831aac7cb0ce4845260da (patch)
tree76f75d2627dc0873c39365d00d72bdb232c14478
parent9d8d48378840b856eee47a4ad245537829ce5e5a (diff)
downloadhaskell-27da55407121461695a831aac7cb0ce4845260da.tar.gz
CmmToC: make floatToWord32/doubleToWord64 faster
Use castFloatToWord32/castDoubleToWord64 in base to perform the reinterpret cast.
-rw-r--r--compiler/GHC/CmmToC.hs27
1 files changed, 3 insertions, 24 deletions
diff --git a/compiler/GHC/CmmToC.hs b/compiler/GHC/CmmToC.hs
index 80e4c8fd60..da0b54dd9f 100644
--- a/compiler/GHC/CmmToC.hs
+++ b/compiler/GHC/CmmToC.hs
@@ -53,15 +53,12 @@ import GHC.Utils.Trace
import Data.ByteString (ByteString)
import qualified Data.ByteString as BS
-import Control.Monad.ST
import Data.Char
import Data.List (intersperse)
import Data.Map (Map)
-import Data.Word
import qualified Data.Map as Map
import Control.Monad (ap)
-import qualified Data.Array.Unsafe as U ( castSTUArray )
-import Data.Array.ST
+import GHC.Float
-- --------------------------------------------------------------------------
-- Now do some real work
@@ -1410,28 +1407,10 @@ pprStringInCStyle s = doubleQuotes (text (concatMap charToC (BS.unpack s)))
-- can safely initialise to static locations.
floatToWord32 :: Rational -> CmmLit
-floatToWord32 r
- = runST $ do
- arr <- newArray_ ((0::Int),0)
- writeArray arr 0 (fromRational r)
- arr' <- castFloatToWord32Array arr
- w32 <- readArray arr' 0
- return (CmmInt (toInteger w32) W32)
- where
- castFloatToWord32Array :: STUArray s Int Float -> ST s (STUArray s Int Word32)
- castFloatToWord32Array = U.castSTUArray
+floatToWord32 r = CmmInt (toInteger (castFloatToWord32 (fromRational r))) W32
doubleToWord64 :: Rational -> CmmLit
-doubleToWord64 r
- = runST $ do
- arr <- newArray_ ((0::Int),1)
- writeArray arr 0 (fromRational r)
- arr' <- castDoubleToWord64Array arr
- w64 <- readArray arr' 0
- return $ CmmInt (toInteger w64) W64
- where
- castDoubleToWord64Array :: STUArray s Int Double -> ST s (STUArray s Int Word64)
- castDoubleToWord64Array = U.castSTUArray
+doubleToWord64 r = CmmInt (toInteger (castDoubleToWord64 (fromRational r))) W64
-- ---------------------------------------------------------------------------