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
1
6
{-# LANGUAGE MagicHash #-}
2
7
3
8
-- |
@@ -20,9 +25,13 @@ module Data.Text.Internal.Unsafe.Shift
20
25
UnsafeShift (.. )
21
26
) where
22
27
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
24
32
import GHC.Base
25
33
import GHC.Word
34
+ #endif
26
35
27
36
-- | This is a workaround for poor optimisation in GHC 6.8.2. It
28
37
-- fails to notice constant-width shifts, and adds a test and branch
@@ -32,35 +41,54 @@ import GHC.Word
32
41
-- greater than the size in bits of a machine Int#.
33
42
class UnsafeShift a where
34
43
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
+
35
50
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
36
56
37
57
instance UnsafeShift Word16 where
58
+ #if !MIN_VERSION_base(4,5,0)
38
59
{-# INLINE shiftL #-}
39
60
shiftL (W16 # x# ) (I # i# ) = W16 # (narrow16Word# (x# `uncheckedShiftL# ` i# ))
40
61
41
62
{-# INLINE shiftR #-}
42
63
shiftR (W16 # x# ) (I # i# ) = W16 # (x# `uncheckedShiftRL# ` i# )
64
+ #endif
43
65
44
66
instance UnsafeShift Word32 where
67
+ #if !MIN_VERSION_base(4,5,0)
45
68
{-# INLINE shiftL #-}
46
69
shiftL (W32 # x# ) (I # i# ) = W32 # (narrow32Word# (x# `uncheckedShiftL# ` i# ))
47
70
48
71
{-# INLINE shiftR #-}
49
72
shiftR (W32 # x# ) (I # i# ) = W32 # (x# `uncheckedShiftRL# ` i# )
73
+ #endif
50
74
51
75
instance UnsafeShift Word64 where
76
+ #if !MIN_VERSION_base(4,5,0)
52
77
{-# INLINE shiftL #-}
53
78
shiftL (W64 # x# ) (I # i# ) = W64 # (x# `uncheckedShiftL64# ` i# )
54
79
55
80
{-# INLINE shiftR #-}
56
81
shiftR (W64 # x# ) (I # i# ) = W64 # (x# `uncheckedShiftRL64# ` i# )
82
+ #endif
57
83
58
84
instance UnsafeShift Int where
85
+ #if !MIN_VERSION_base(4,5,0)
59
86
{-# INLINE shiftL #-}
60
87
shiftL (I # x# ) (I # i# ) = I # (x# `iShiftL# ` i# )
61
88
62
89
{-# INLINE shiftR #-}
63
90
shiftR (I # x# ) (I # i# ) = I # (x# `iShiftRA# ` i# )
91
+ #endif
64
92
65
93
{-
66
94
instance UnsafeShift Integer where
0 commit comments