Skip to content

Commit

Permalink
Try using prim conversions directly
Browse files Browse the repository at this point in the history
  • Loading branch information
la-wu committed Feb 25, 2021
1 parent 70f715d commit 10809d3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 8 additions & 1 deletion Data/ByteString/Builder/RealFloat/D2S.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE BangPatterns, MagicHash, UnboxedTuples #-}
{-# LANGUAGE GHCForeignImportPrim, UnliftedFFITypes #-}

module Data.ByteString.Builder.RealFloat.D2S
( FloatingDecimal(..)
Expand All @@ -14,7 +15,6 @@ import Data.ByteString.Builder.RealFloat.Internal
import Data.ByteString.Builder.RealFloat.TableGenerator
import Data.Maybe (fromMaybe)
import GHC.Exts
import GHC.Float (castDoubleToWord64)
import GHC.Int (Int32(..), Int64(..))
import GHC.ST (ST(..), runST)
import GHC.Word (Word32(..), Word64(..))
Expand Down Expand Up @@ -277,6 +277,13 @@ d2d m e =
!e' = e10 + removed
in FloatingDecimal output e'

{-# INLINE castDoubleToWord64 #-}
castDoubleToWord64 :: Double -> Word64
castDoubleToWord64 (D# d#) = W64# (stgDoubleToWord64 d#)

foreign import prim "stg_doubleToWord64zh"
stgDoubleToWord64 :: Double# -> Word#

breakdown :: Double -> (Bool, Word64, Word64)
breakdown f =
let bits = castDoubleToWord64 f
Expand Down
9 changes: 8 additions & 1 deletion Data/ByteString/Builder/RealFloat/F2S.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE BangPatterns, MagicHash, UnboxedTuples #-}
{-# LANGUAGE GHCForeignImportPrim, UnliftedFFITypes #-}

module Data.ByteString.Builder.RealFloat.F2S
( FloatingDecimal(..)
Expand All @@ -13,7 +14,6 @@ import Data.ByteString.Builder.Prim (primBounded)
import Data.ByteString.Builder.RealFloat.Internal
import Data.ByteString.Builder.RealFloat.TableGenerator
import GHC.Exts
import GHC.Float (castFloatToWord32)
import GHC.Int (Int32(..))
import GHC.ST (ST(..), runST)
import GHC.Word (Word32(..), Word64(..))
Expand Down Expand Up @@ -241,6 +241,13 @@ f2d m e =
!e' = e10 + removed
in FloatingDecimal output e'

{-# INLINE castFloatToWord32 #-}
castFloatToWord32 :: Float -> Word32
castFloatToWord32 (F# f#) = W32# (stgFloatToWord32 f#)

foreign import prim "stg_floatToWord32zh"
stgFloatToWord32 :: Float# -> Word#

breakdown :: Float -> (Bool, Word32, Word32)
breakdown f =
let bits = castFloatToWord32 f
Expand Down

0 comments on commit 10809d3

Please sign in to comment.