1+ {-# LANGUAGE CPP #-}
2+ #if MIN_VERSION_base(4,5,0)
3+ -- base-4.5.0 is 7.4, default sigs introduced in 7.2
4+ {-# LANGUAGE DefaultSignatures #-}
5+ #endif
16{-# LANGUAGE MagicHash #-}
27
38-- |
@@ -20,9 +25,13 @@ module Data.Text.Internal.Unsafe.Shift
2025 UnsafeShift (.. )
2126 ) where
2227
23- -- import qualified Data.Bits as Bits
28+ #if MIN_VERSION_base(4,5,0)
29+ import qualified Data.Bits as Bits
30+ import Data.Word
31+ #else
2432import GHC.Base
2533import GHC.Word
34+ #endif
2635
2736-- | This is a workaround for poor optimisation in GHC 6.8.2. It
2837-- fails to notice constant-width shifts, and adds a test and branch
@@ -32,35 +41,54 @@ import GHC.Word
3241-- greater than the size in bits of a machine Int#.
3342class UnsafeShift a where
3443 shiftL :: a -> Int -> a
44+ #if MIN_VERSION_base(4,5,0)
45+ {-# INLINE shiftL #-}
46+ default shiftL :: Bits. Bits a => a -> Int -> a
47+ shiftL = Bits. unsafeShiftL
48+ #endif
49+
3550 shiftR :: a -> Int -> a
51+ #if MIN_VERSION_base(4,5,0)
52+ {-# INLINE shiftR #-}
53+ default shiftR :: Bits. Bits a => a -> Int -> a
54+ shiftR = Bits. unsafeShiftR
55+ #endif
3656
3757instance UnsafeShift Word16 where
58+ #if !MIN_VERSION_base(4,5,0)
3859 {-# INLINE shiftL #-}
3960 shiftL (W16 # x# ) (I # i# ) = W16 # (narrow16Word# (x# `uncheckedShiftL# ` i# ))
4061
4162 {-# INLINE shiftR #-}
4263 shiftR (W16 # x# ) (I # i# ) = W16 # (x# `uncheckedShiftRL# ` i# )
64+ #endif
4365
4466instance UnsafeShift Word32 where
67+ #if !MIN_VERSION_base(4,5,0)
4568 {-# INLINE shiftL #-}
4669 shiftL (W32 # x# ) (I # i# ) = W32 # (narrow32Word# (x# `uncheckedShiftL# ` i# ))
4770
4871 {-# INLINE shiftR #-}
4972 shiftR (W32 # x# ) (I # i# ) = W32 # (x# `uncheckedShiftRL# ` i# )
73+ #endif
5074
5175instance UnsafeShift Word64 where
76+ #if !MIN_VERSION_base(4,5,0)
5277 {-# INLINE shiftL #-}
5378 shiftL (W64 # x# ) (I # i# ) = W64 # (x# `uncheckedShiftL64# ` i# )
5479
5580 {-# INLINE shiftR #-}
5681 shiftR (W64 # x# ) (I # i# ) = W64 # (x# `uncheckedShiftRL64# ` i# )
82+ #endif
5783
5884instance UnsafeShift Int where
85+ #if !MIN_VERSION_base(4,5,0)
5986 {-# INLINE shiftL #-}
6087 shiftL (I # x# ) (I # i# ) = I # (x# `iShiftL# ` i# )
6188
6289 {-# INLINE shiftR #-}
6390 shiftR (I # x# ) (I # i# ) = I # (x# `iShiftRA# ` i# )
91+ #endif
6492
6593{-
6694instance UnsafeShift Integer where
0 commit comments