From ddee463e99fcda352f497d5fc925a72a1cf24faa Mon Sep 17 00:00:00 2001 From: Moritz Angermann <moritz.angermann@gmail.com> Date: Sun, 1 Nov 2020 15:17:01 +0800 Subject: [PATCH] [Cmm Sized] Adjust --- binary.cabal | 8 ++++++-- src/Data/Binary/Get.hs | 26 ++++++++++++++++++++------ 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/binary.cabal b/binary.cabal index 288117e..2808714 100644 --- a/binary.cabal +++ b/binary.cabal @@ -39,7 +39,11 @@ source-repository head location: git://github.com/kolmodin/binary.git library - build-depends: base >= 4.5.0.0 && < 5, bytestring >= 0.10.4, containers, array + build-depends: base >= 4.5.0.0 && < 5, + ghc-prim >= 0.5.0 && <0.9, + bytestring >= 0.10.4, + containers, + array hs-source-dirs: src exposed-modules: Data.Binary, Data.Binary.Put, @@ -181,7 +185,7 @@ benchmark generics-bench unordered-containers, zlib, criterion - + other-modules: Cabal24 GenericsBenchCache diff --git a/src/Data/Binary/Get.hs b/src/Data/Binary/Get.hs index 65f7c75..bf8a1df 100644 --- a/src/Data/Binary/Get.hs +++ b/src/Data/Binary/Get.hs @@ -231,14 +231,28 @@ import qualified Data.ByteString.Lazy.Internal as L import Data.Binary.Get.Internal hiding ( Decoder(..), runGetIncremental ) import qualified Data.Binary.Get.Internal as I +-- needed for casting words to float/double +import Data.Binary.FloatCast (wordToFloat, wordToDouble) + #if defined(__GLASGOW_HASKELL__) && !defined(__HADDOCK__) -- needed for (# unboxing #) with magic hash -import GHC.Base +import GHC.Base hiding (extendWord8#, extendWord16#, extendWord32#, narrowWord8#, narrowWord16#, narrowWord32#) import GHC.Word +#if MIN_VERSION_ghc_prim(0,8,0) +import GHC.Base (extendWord8#, extendWord16#, extendWord32#) +import GHC.Base (narrowWord8#, narrowWord16#, narrowWord32#) +#else +import GHC.Prim (Word#) +extendWord8#, extendWord16#, extendWord32# :: Word# -> Word# +narrowWord8#, narrowWord16#, narrowWord32# :: Word# -> Word# +extendWord8# w = w +extendWord16# w = w +extendWord32# w = w +narrowWord8# w = w +narrowWord16# w = w +narrowWord32# w = w +#endif #endif - --- needed for casting words to float/double -import Data.Binary.FloatCast (wordToFloat, wordToDouble) -- $lazyinterface -- The lazy interface consumes a single lazy 'L.ByteString'. It's the easiest @@ -660,8 +674,8 @@ shiftl_w32 :: Word32 -> Int -> Word32 shiftl_w64 :: Word64 -> Int -> Word64 #if defined(__GLASGOW_HASKELL__) && !defined(__HADDOCK__) -shiftl_w16 (W16# w) (I# i) = W16# (w `uncheckedShiftL#` i) -shiftl_w32 (W32# w) (I# i) = W32# (w `uncheckedShiftL#` i) +shiftl_w16 (W16# w) (I# i) = W16# (narrowWord16# ((extendWord16# w) `uncheckedShiftL#` i)) +shiftl_w32 (W32# w) (I# i) = W32# (narrowWord32# ((extendWord32# w) `uncheckedShiftL#` i)) #if WORD_SIZE_IN_BITS < 64 shiftl_w64 (W64# w) (I# i) = W64# (w `uncheckedShiftL64#` i) -- GitLab