diff --git a/.hlint.yaml b/.hlint.yaml index cd5991d8e..d9f6bad97 100644 --- a/.hlint.yaml +++ b/.hlint.yaml @@ -2,7 +2,6 @@ name: Use camelCase within: - Data.ByteString.Builder.Internal - - Data.ByteString.Builder.Prim.Internal.UncheckedShifts - Data.ByteString.Short.Internal - ignore: name: Use fewer imports diff --git a/Data/ByteString/Builder/ASCII.hs b/Data/ByteString/Builder/ASCII.hs index 31f6e36dd..3643bdade 100644 --- a/Data/ByteString/Builder/ASCII.hs +++ b/Data/ByteString/Builder/ASCII.hs @@ -104,17 +104,11 @@ import Data.Monoid (mappend) import GHC.Num (quotRemInteger) # endif -# if __GLASGOW_HASKELL__ < 611 -import GHC.Integer.Internals -# else import GHC.Integer.GMP.Internals -# endif #endif #if HAS_INTEGER_CONSTR import qualified Data.ByteString.Builder.Prim.Internal as P -import Data.ByteString.Builder.Prim.Internal.UncheckedShifts - ( caseWordSize_32_64 ) import Foreign.C.Types import GHC.Types (Int(..)) #endif @@ -329,7 +323,7 @@ lazyByteStringHex = P.primMapLazyByteStringFixed P.word8HexFixed -- FIXME: Think about also using the MSB. For 64 bit 'Int's this makes a -- difference. maxPow10 :: Integer -maxPow10 = toInteger $ (10 :: Int) ^ caseWordSize_32_64 (9 :: Int) 18 +maxPow10 = toInteger $ (10 :: Int) ^ P.caseWordSize_32_64 (9 :: Int) 18 -- | Decimal encoding of an 'Integer' using the ASCII digits. integerDec :: Integer -> Builder @@ -386,7 +380,7 @@ foreign import ccall unsafe "static _hs_bytestring_long_long_int_dec_padded18" {-# INLINE intDecPadded #-} intDecPadded :: P.BoundedPrim Int -intDecPadded = P.liftFixedToBounded $ caseWordSize_32_64 +intDecPadded = P.liftFixedToBounded $ P.caseWordSize_32_64 (P.fixedPrim 9 $ c_int_dec_padded9 . fromIntegral) (P.fixedPrim 18 $ c_long_long_int_dec_padded18 . fromIntegral) diff --git a/Data/ByteString/Builder/Internal.hs b/Data/ByteString/Builder/Internal.hs index 8209c398f..2b40860b4 100644 --- a/Data/ByteString/Builder/Internal.hs +++ b/Data/ByteString/Builder/Internal.hs @@ -608,7 +608,6 @@ putLiftIO io = put $ \k br -> io >>= (`k` br) -- buffer is too small to execute one step of the 'Put' action, then -- it is replaced with a large enough buffer. hPut :: forall a. Handle -> Put a -> IO a -#if __GLASGOW_HASKELL__ >= 611 hPut h p = do fillHandle 1 (runPut p) where @@ -655,12 +654,7 @@ hPut h p = do | freeSpace buf < minFree = flushWriteBuffer h_ | otherwise = -#if __GLASGOW_HASKELL__ >= 613 return () -#else - -- required for ghc-6.12 - flushWriteBuffer h_ -#endif fillBuffer buf | freeSpace buf < minFree = @@ -709,15 +703,6 @@ hPut h p = do return $ do S.hPut h bs fillHandle 1 nextStep -#else -hPut h p = - go =<< buildStepToCIOS strategy (runPut p) - where - strategy = untrimmedStrategy L.smallChunkSize L.defaultChunkSize - - go (Finished buf x) = S.hPut h (byteStringFromBuffer buf) >> return x - go (Yield1 bs io) = S.hPut h bs >> io >>= go -#endif -- | Execute a 'Put' and return the computed result and the bytes -- written during the computation as a lazy 'L.ByteString'. diff --git a/Data/ByteString/Builder/Prim/ASCII.hs b/Data/ByteString/Builder/Prim/ASCII.hs index 821136f1d..81d1140e1 100644 --- a/Data/ByteString/Builder/Prim/ASCII.hs +++ b/Data/ByteString/Builder/Prim/ASCII.hs @@ -84,7 +84,6 @@ import Data.ByteString.Builder.Prim.Binary import Data.ByteString.Builder.Prim.Internal import Data.ByteString.Builder.Prim.Internal.Floating import Data.ByteString.Builder.Prim.Internal.Base16 -import Data.ByteString.Builder.Prim.Internal.UncheckedShifts import Data.Char (ord) @@ -242,20 +241,20 @@ word8HexFixed = fixedPrim 2 $ {-# INLINE word16HexFixed #-} word16HexFixed :: FixedPrim Word16 word16HexFixed = - (\x -> (fromIntegral $ x `shiftr_w16` 8, fromIntegral x)) + (\x -> (fromIntegral $ x `shiftR` 8, fromIntegral x)) >$< pairF word8HexFixed word8HexFixed -- | Encode a 'Word32' using 8 nibbles. {-# INLINE word32HexFixed #-} word32HexFixed :: FixedPrim Word32 word32HexFixed = - (\x -> (fromIntegral $ x `shiftr_w32` 16, fromIntegral x)) + (\x -> (fromIntegral $ x `shiftR` 16, fromIntegral x)) >$< pairF word16HexFixed word16HexFixed -- | Encode a 'Word64' using 16 nibbles. {-# INLINE word64HexFixed #-} word64HexFixed :: FixedPrim Word64 word64HexFixed = - (\x -> (fromIntegral $ x `shiftr_w64` 32, fromIntegral x)) + (\x -> (fromIntegral $ x `shiftR` 32, fromIntegral x)) >$< pairF word32HexFixed word32HexFixed -- | Encode a 'Int8' using 2 nibbles (hexadecimal digits). diff --git a/Data/ByteString/Builder/Prim/Binary.hs b/Data/ByteString/Builder/Prim/Binary.hs index 8af381f52..24e67d1a4 100644 --- a/Data/ByteString/Builder/Prim/Binary.hs +++ b/Data/ByteString/Builder/Prim/Binary.hs @@ -55,7 +55,6 @@ module Data.ByteString.Builder.Prim.Binary ( ) where import Data.ByteString.Builder.Prim.Internal -import Data.ByteString.Builder.Prim.Internal.UncheckedShifts import Data.ByteString.Builder.Prim.Internal.Floating import Foreign @@ -87,7 +86,7 @@ word16BE :: FixedPrim Word16 word16BE = word16Host #else word16BE = fixedPrim 2 $ \w p -> do - poke p (fromIntegral (shiftr_w16 w 8) :: Word8) + poke p (fromIntegral (shiftR w 8) :: Word8) poke (p `plusPtr` 1) (fromIntegral w :: Word8) #endif @@ -97,7 +96,7 @@ word16LE :: FixedPrim Word16 #ifdef WORDS_BIGENDIAN word16LE = fixedPrim 2 $ \w p -> do poke p (fromIntegral w :: Word8) - poke (p `plusPtr` 1) (fromIntegral (shiftr_w16 w 8) :: Word8) + poke (p `plusPtr` 1) (fromIntegral (shiftR w 8) :: Word8) #else word16LE = word16Host #endif @@ -109,9 +108,9 @@ word32BE :: FixedPrim Word32 word32BE = word32Host #else word32BE = fixedPrim 4 $ \w p -> do - poke p (fromIntegral (shiftr_w32 w 24) :: Word8) - poke (p `plusPtr` 1) (fromIntegral (shiftr_w32 w 16) :: Word8) - poke (p `plusPtr` 2) (fromIntegral (shiftr_w32 w 8) :: Word8) + poke p (fromIntegral (shiftR w 24) :: Word8) + poke (p `plusPtr` 1) (fromIntegral (shiftR w 16) :: Word8) + poke (p `plusPtr` 2) (fromIntegral (shiftR w 8) :: Word8) poke (p `plusPtr` 3) (fromIntegral w :: Word8) #endif @@ -121,9 +120,9 @@ word32LE :: FixedPrim Word32 #ifdef WORDS_BIGENDIAN word32LE = fixedPrim 4 $ \w p -> do poke p (fromIntegral w :: Word8) - poke (p `plusPtr` 1) (fromIntegral (shiftr_w32 w 8) :: Word8) - poke (p `plusPtr` 2) (fromIntegral (shiftr_w32 w 16) :: Word8) - poke (p `plusPtr` 3) (fromIntegral (shiftr_w32 w 24) :: Word8) + poke (p `plusPtr` 1) (fromIntegral (shiftR w 8) :: Word8) + poke (p `plusPtr` 2) (fromIntegral (shiftR w 16) :: Word8) + poke (p `plusPtr` 3) (fromIntegral (shiftR w 24) :: Word8) #else word32LE = word32Host #endif @@ -144,25 +143,25 @@ word64BE = word64Host -- word64BE = fixedPrim 8 $ \w p -> do - let a = fromIntegral (shiftr_w64 w 32) :: Word32 + let a = fromIntegral (shiftR w 32) :: Word32 b = fromIntegral w :: Word32 - poke p (fromIntegral (shiftr_w32 a 24) :: Word8) - poke (p `plusPtr` 1) (fromIntegral (shiftr_w32 a 16) :: Word8) - poke (p `plusPtr` 2) (fromIntegral (shiftr_w32 a 8) :: Word8) + poke p (fromIntegral (shiftR a 24) :: Word8) + poke (p `plusPtr` 1) (fromIntegral (shiftR a 16) :: Word8) + poke (p `plusPtr` 2) (fromIntegral (shiftR a 8) :: Word8) poke (p `plusPtr` 3) (fromIntegral a :: Word8) - poke (p `plusPtr` 4) (fromIntegral (shiftr_w32 b 24) :: Word8) - poke (p `plusPtr` 5) (fromIntegral (shiftr_w32 b 16) :: Word8) - poke (p `plusPtr` 6) (fromIntegral (shiftr_w32 b 8) :: Word8) + poke (p `plusPtr` 4) (fromIntegral (shiftR b 24) :: Word8) + poke (p `plusPtr` 5) (fromIntegral (shiftR b 16) :: Word8) + poke (p `plusPtr` 6) (fromIntegral (shiftR b 8) :: Word8) poke (p `plusPtr` 7) (fromIntegral b :: Word8) #else word64BE = fixedPrim 8 $ \w p -> do - poke p (fromIntegral (shiftr_w64 w 56) :: Word8) - poke (p `plusPtr` 1) (fromIntegral (shiftr_w64 w 48) :: Word8) - poke (p `plusPtr` 2) (fromIntegral (shiftr_w64 w 40) :: Word8) - poke (p `plusPtr` 3) (fromIntegral (shiftr_w64 w 32) :: Word8) - poke (p `plusPtr` 4) (fromIntegral (shiftr_w64 w 24) :: Word8) - poke (p `plusPtr` 5) (fromIntegral (shiftr_w64 w 16) :: Word8) - poke (p `plusPtr` 6) (fromIntegral (shiftr_w64 w 8) :: Word8) + poke p (fromIntegral (shiftR w 56) :: Word8) + poke (p `plusPtr` 1) (fromIntegral (shiftR w 48) :: Word8) + poke (p `plusPtr` 2) (fromIntegral (shiftR w 40) :: Word8) + poke (p `plusPtr` 3) (fromIntegral (shiftR w 32) :: Word8) + poke (p `plusPtr` 4) (fromIntegral (shiftR w 24) :: Word8) + poke (p `plusPtr` 5) (fromIntegral (shiftR w 16) :: Word8) + poke (p `plusPtr` 6) (fromIntegral (shiftR w 8) :: Word8) poke (p `plusPtr` 7) (fromIntegral w :: Word8) #endif #endif @@ -174,26 +173,26 @@ word64LE :: FixedPrim Word64 #if WORD_SIZE_IN_BITS < 64 word64LE = fixedPrim 8 $ \w p -> do - let b = fromIntegral (shiftr_w64 w 32) :: Word32 + let b = fromIntegral (shiftR w 32) :: Word32 a = fromIntegral w :: Word32 poke (p) (fromIntegral a :: Word8) - poke (p `plusPtr` 1) (fromIntegral (shiftr_w32 a 8) :: Word8) - poke (p `plusPtr` 2) (fromIntegral (shiftr_w32 a 16) :: Word8) - poke (p `plusPtr` 3) (fromIntegral (shiftr_w32 a 24) :: Word8) + poke (p `plusPtr` 1) (fromIntegral (shiftR a 8) :: Word8) + poke (p `plusPtr` 2) (fromIntegral (shiftR a 16) :: Word8) + poke (p `plusPtr` 3) (fromIntegral (shiftR a 24) :: Word8) poke (p `plusPtr` 4) (fromIntegral b :: Word8) - poke (p `plusPtr` 5) (fromIntegral (shiftr_w32 b 8) :: Word8) - poke (p `plusPtr` 6) (fromIntegral (shiftr_w32 b 16) :: Word8) - poke (p `plusPtr` 7) (fromIntegral (shiftr_w32 b 24) :: Word8) + poke (p `plusPtr` 5) (fromIntegral (shiftR b 8) :: Word8) + poke (p `plusPtr` 6) (fromIntegral (shiftR b 16) :: Word8) + poke (p `plusPtr` 7) (fromIntegral (shiftR b 24) :: Word8) #else word64LE = fixedPrim 8 $ \w p -> do poke p (fromIntegral w :: Word8) - poke (p `plusPtr` 1) (fromIntegral (shiftr_w64 w 8) :: Word8) - poke (p `plusPtr` 2) (fromIntegral (shiftr_w64 w 16) :: Word8) - poke (p `plusPtr` 3) (fromIntegral (shiftr_w64 w 24) :: Word8) - poke (p `plusPtr` 4) (fromIntegral (shiftr_w64 w 32) :: Word8) - poke (p `plusPtr` 5) (fromIntegral (shiftr_w64 w 40) :: Word8) - poke (p `plusPtr` 6) (fromIntegral (shiftr_w64 w 48) :: Word8) - poke (p `plusPtr` 7) (fromIntegral (shiftr_w64 w 56) :: Word8) + poke (p `plusPtr` 1) (fromIntegral (shiftR w 8) :: Word8) + poke (p `plusPtr` 2) (fromIntegral (shiftR w 16) :: Word8) + poke (p `plusPtr` 3) (fromIntegral (shiftR w 24) :: Word8) + poke (p `plusPtr` 4) (fromIntegral (shiftR w 32) :: Word8) + poke (p `plusPtr` 5) (fromIntegral (shiftR w 40) :: Word8) + poke (p `plusPtr` 6) (fromIntegral (shiftR w 48) :: Word8) + poke (p `plusPtr` 7) (fromIntegral (shiftR w 56) :: Word8) #endif #else word64LE = word64Host diff --git a/Data/ByteString/Builder/Prim/Internal.hs b/Data/ByteString/Builder/Prim/Internal.hs index d4d944167..9df2c796a 100644 --- a/Data/ByteString/Builder/Prim/Internal.hs +++ b/Data/ByteString/Builder/Prim/Internal.hs @@ -64,6 +64,9 @@ module Data.ByteString.Builder.Prim.Internal ( , (>$<) , (>*<) + -- * Helpers + , caseWordSize_32_64 + -- * Deprecated , boudedPrim ) where @@ -71,10 +74,7 @@ module Data.ByteString.Builder.Prim.Internal ( import Foreign import Prelude hiding (maxBound) -#if !(__GLASGOW_HASKELL__ >= 612) --- ghc-6.10 and older do not support {-# INLINE CONLIKE #-} -#define CONLIKE -#endif +#include "MachDeps.h" ------------------------------------------------------------------------------ -- Supporting infrastructure @@ -298,3 +298,17 @@ eitherB (BP b1 io1) (BP b2 io2) = condB :: (a -> Bool) -> BoundedPrim a -> BoundedPrim a -> BoundedPrim a condB p be1 be2 = contramapB (\x -> if p x then Left x else Right x) (eitherB be1 be2) + +-- | Select an implementation depending on bitness. +-- Throw a compile time error if bitness is neither 32 nor 64. +{-# INLINE caseWordSize_32_64 #-} +caseWordSize_32_64 + :: a -- Value for 32-bit architecture + -> a -- Value for 64-bit architecture + -> a +#if WORD_SIZE_IN_BITS == 32 +caseWordSize_32_64 = const +#endif +#if WORD_SIZE_IN_BITS == 64 +caseWordSize_32_64 = const id +#endif diff --git a/Data/ByteString/Builder/Prim/Internal/UncheckedShifts.hs b/Data/ByteString/Builder/Prim/Internal/UncheckedShifts.hs deleted file mode 100644 index 4cad1d664..000000000 --- a/Data/ByteString/Builder/Prim/Internal/UncheckedShifts.hs +++ /dev/null @@ -1,107 +0,0 @@ -{-# LANGUAGE CPP, MagicHash #-} -#if __GLASGOW_HASKELL__ >= 703 -{-# LANGUAGE Unsafe #-} -#endif --- | --- Copyright : (c) 2010 Simon Meier --- --- Original serialization code from 'Data.Binary.Builder': --- (c) Lennart Kolmodin, Ross Patterson --- --- License : BSD3-style (see LICENSE) --- --- Maintainer : Simon Meier --- Portability : GHC --- --- Utilty module defining unchecked shifts. --- --- These functions are undefined when the amount being shifted by is --- greater than the size in bits of a machine Int#.- --- -#if !defined(__HADDOCK__) -#include "MachDeps.h" -#endif - -module Data.ByteString.Builder.Prim.Internal.UncheckedShifts ( - shiftr_w16 - , shiftr_w32 - , shiftr_w64 - , shiftr_w - - , caseWordSize_32_64 - ) where - - -#if !defined(__HADDOCK__) -import GHC.Base -import GHC.Word (Word32(..),Word16(..),Word64(..)) - -#if WORD_SIZE_IN_BITS < 64 && __GLASGOW_HASKELL__ >= 608 -import GHC.Word (uncheckedShiftRL64#) -#endif -#else -import Data.Word -#endif - -import Foreign - - ------------------------------------------------------------------------- --- Unchecked shifts - --- | Right-shift of a 'Word16'. -{-# INLINE shiftr_w16 #-} -shiftr_w16 :: Word16 -> Int -> Word16 - --- | Right-shift of a 'Word32'. -{-# INLINE shiftr_w32 #-} -shiftr_w32 :: Word32 -> Int -> Word32 - --- | Right-shift of a 'Word64'. -{-# INLINE shiftr_w64 #-} -shiftr_w64 :: Word64 -> Int -> Word64 - --- | Right-shift of a 'Word'. -{-# INLINE shiftr_w #-} -shiftr_w :: Word -> Int -> Word -#if WORD_SIZE_IN_BITS < 64 -shiftr_w w s = fromIntegral $ (`shiftr_w32` s) $ fromIntegral w -#else -shiftr_w w s = fromIntegral $ (`shiftr_w64` s) $ fromIntegral w -#endif - -#if !defined(__HADDOCK__) -shiftr_w16 (W16# w) (I# i) = W16# (w `uncheckedShiftRL#` i) -shiftr_w32 (W32# w) (I# i) = W32# (w `uncheckedShiftRL#` i) - -#if WORD_SIZE_IN_BITS < 64 -shiftr_w64 (W64# w) (I# i) = W64# (w `uncheckedShiftRL64#` i) -#else -shiftr_w64 (W64# w) (I# i) = W64# (w `uncheckedShiftRL#` i) -#endif - -#else -shiftr_w16 = shiftR -shiftr_w32 = shiftR -shiftr_w64 = shiftR -#endif - - --- | Select an implementation depending on the bit-size of 'Word's. --- Currently, it produces a runtime failure if the bitsize is different. --- This is detected by the testsuite. -{-# INLINE caseWordSize_32_64 #-} -caseWordSize_32_64 :: a -- Value to use for 32-bit 'Word's - -> a -- Value to use for 64-bit 'Word's - -> a -caseWordSize_32_64 f32 f64 = -#if MIN_VERSION_base(4,7,0) - case finiteBitSize (undefined :: Word) of -#else - case bitSize (undefined :: Word) of -#endif - 32 -> f32 - 64 -> f64 - s -> error $ "caseWordSize_32_64: unsupported Word bit-size " ++ show s - - diff --git a/bench/bench-bytestring.cabal b/bench/bench-bytestring.cabal index 83ad60976..3d68c7075 100644 --- a/bench/bench-bytestring.cabal +++ b/bench/bench-bytestring.cabal @@ -46,7 +46,6 @@ common bench-stanza Data.ByteString.Builder.Prim.Internal Data.ByteString.Builder.Prim.Internal.Base16 Data.ByteString.Builder.Prim.Internal.Floating - Data.ByteString.Builder.Prim.Internal.UncheckedShifts Data.ByteString.Char8 Data.ByteString.Internal Data.ByteString.Lazy diff --git a/bytestring.cabal b/bytestring.cabal index 625e272f3..036bda260 100644 --- a/bytestring.cabal +++ b/bytestring.cabal @@ -94,7 +94,6 @@ library Data.ByteString.Builder.Prim.Binary Data.ByteString.Builder.Prim.ASCII Data.ByteString.Builder.Prim.Internal.Floating - Data.ByteString.Builder.Prim.Internal.UncheckedShifts Data.ByteString.Builder.Prim.Internal.Base16 default-language: Haskell98 diff --git a/tests/bytestring-tests.cabal b/tests/bytestring-tests.cabal index 48b53122f..84bc24be3 100644 --- a/tests/bytestring-tests.cabal +++ b/tests/bytestring-tests.cabal @@ -97,7 +97,6 @@ test-suite test-builder Data.ByteString.Builder.Prim.Internal Data.ByteString.Builder.Prim.Internal.Base16 Data.ByteString.Builder.Prim.Internal.Floating - Data.ByteString.Builder.Prim.Internal.UncheckedShifts Data.ByteString.Internal Data.ByteString.Lazy Data.ByteString.Lazy.Char8