summaryrefslogtreecommitdiff
path: root/libraries/base/GHC/Word.hs
diff options
context:
space:
mode:
authorSimon Marlow <marlowsd@gmail.com>2008-07-30 10:35:39 +0000
committerSimon Marlow <marlowsd@gmail.com>2008-07-30 10:35:39 +0000
commitf3b135c74fb8ae744254ec11aaeebe16fb814546 (patch)
tree45588540df694b8263e09bd37793a8516f5d0026 /libraries/base/GHC/Word.hs
parentc3965352c25a7c8ed32021f73cbeba1bea6c69a7 (diff)
downloadhaskell-f3b135c74fb8ae744254ec11aaeebe16fb814546.tar.gz
FIX #2376: inline shiftR
Duplicating the default definition for shiftR doesn't seem quite right to me, but it gets the right results when compiling the example program, and I couldn't find a better way to do it.
Diffstat (limited to 'libraries/base/GHC/Word.hs')
-rw-r--r--libraries/base/GHC/Word.hs28
1 files changed, 28 insertions, 0 deletions
diff --git a/libraries/base/GHC/Word.hs b/libraries/base/GHC/Word.hs
index b60cc336f5..99b25ba192 100644
--- a/libraries/base/GHC/Word.hs
+++ b/libraries/base/GHC/Word.hs
@@ -179,6 +179,10 @@ instance Bits Word where
bitSize _ = WORD_SIZE_IN_BITS
isSigned _ = False
+ {-# INLINE shiftR #-}
+ -- same as the default definition, but we want it inlined (#2376)
+ x `shiftR` i = x `shift` (-i)
+
{-# RULES
"fromIntegral/Int->Word" fromIntegral = \(I# x#) -> W# (int2Word# x#)
"fromIntegral/Word->Int" fromIntegral = \(W# x#) -> I# (word2Int# x#)
@@ -278,6 +282,10 @@ instance Bits Word8 where
bitSize _ = 8
isSigned _ = False
+ {-# INLINE shiftR #-}
+ -- same as the default definition, but we want it inlined (#2376)
+ x `shiftR` i = x `shift` (-i)
+
{-# RULES
"fromIntegral/Word8->Word8" fromIntegral = id :: Word8 -> Word8
"fromIntegral/Word8->Integer" fromIntegral = toInteger :: Word8 -> Integer
@@ -378,6 +386,10 @@ instance Bits Word16 where
bitSize _ = 16
isSigned _ = False
+ {-# INLINE shiftR #-}
+ -- same as the default definition, but we want it inlined (#2376)
+ x `shiftR` i = x `shift` (-i)
+
{-# RULES
"fromIntegral/Word8->Word16" fromIntegral = \(W8# x#) -> W16# x#
"fromIntegral/Word16->Word16" fromIntegral = id :: Word16 -> Word16
@@ -477,6 +489,10 @@ instance Bits Word32 where
bitSize _ = 32
isSigned _ = False
+ {-# INLINE shiftR #-}
+ -- same as the default definition, but we want it inlined (#2376)
+ x `shiftR` i = x `shift` (-i)
+
{-# RULES
"fromIntegral/Int->Word32" fromIntegral = \(I# x#) -> W32# (int32ToWord32# (intToInt32# x#))
"fromIntegral/Word->Word32" fromIntegral = \(W# x#) -> W32# (wordToWord32# x#)
@@ -583,6 +599,10 @@ instance Bits Word32 where
bitSize _ = 32
isSigned _ = False
+ {-# INLINE shiftR #-}
+ -- same as the default definition, but we want it inlined (#2376)
+ x `shiftR` i = x `shift` (-i)
+
{-# RULES
"fromIntegral/Word8->Word32" fromIntegral = \(W8# x#) -> W32# x#
"fromIntegral/Word16->Word32" fromIntegral = \(W16# x#) -> W32# x#
@@ -709,6 +729,10 @@ instance Bits Word64 where
bitSize _ = 64
isSigned _ = False
+ {-# INLINE shiftR #-}
+ -- same as the default definition, but we want it inlined (#2376)
+ x `shiftR` i = x `shift` (-i)
+
-- give the 64-bit shift operations the same treatment as the 32-bit
-- ones (see GHC.Base), namely we wrap them in tests to catch the
-- cases when we're shifting more than 64 bits to avoid unspecified
@@ -812,6 +836,10 @@ instance Bits Word64 where
bitSize _ = 64
isSigned _ = False
+ {-# INLINE shiftR #-}
+ -- same as the default definition, but we want it inlined (#2376)
+ x `shiftR` i = x `shift` (-i)
+
{-# RULES
"fromIntegral/a->Word64" fromIntegral = \x -> case fromIntegral x of W# x# -> W64# x#
"fromIntegral/Word64->a" fromIntegral = \(W64# x#) -> fromIntegral (W# x#)