From 1fd0b9560f30181af709c784f70017e36a97d4da Mon Sep 17 00:00:00 2001 From: Samuel Bronson Date: Thu, 12 Oct 2006 12:55:53 +0000 Subject: [PATCH] Use unchecked shifts to implement Data.Bits.rotate This should get rid of those cases, maybe lower the size enough that the inliner will like it? --- Data/Bits.hs | 4 ++-- GHC/Int.hs | 16 ++++++++-------- GHC/Word.hs | 18 +++++++++--------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Data/Bits.hs b/Data/Bits.hs index eb8ace1..4564bce 100644 --- a/Data/Bits.hs +++ b/Data/Bits.hs @@ -203,8 +203,8 @@ instance Bits Int where | i# >=# 0# = I# (x# `iShiftL#` i#) | otherwise = I# (x# `iShiftRA#` negateInt# i#) (I# x#) `rotate` (I# i#) = - I# (word2Int# ((x'# `shiftL#` i'#) `or#` - (x'# `shiftRL#` (wsib -# i'#)))) + I# (word2Int# ((x'# `uncheckedShiftL#` i'#) `or#` + (x'# `uncheckedShiftRL#` (wsib -# i'#)))) where x'# = int2Word# x# i'# = word2Int# (int2Word# i# `and#` int2Word# (wsib -# 1#)) diff --git a/GHC/Int.hs b/GHC/Int.hs index 3fff7dd..7ee7b1b 100644 --- a/GHC/Int.hs +++ b/GHC/Int.hs @@ -125,8 +125,8 @@ instance Bits Int8 where | i'# ==# 0# = I8# x# | otherwise - = I8# (narrow8Int# (word2Int# ((x'# `shiftL#` i'#) `or#` - (x'# `shiftRL#` (8# -# i'#))))) + = I8# (narrow8Int# (word2Int# ((x'# `uncheckedShiftL#` i'#) `or#` + (x'# `uncheckedShiftRL#` (8# -# i'#))))) where x'# = narrow8Word# (int2Word# x#) i'# = word2Int# (int2Word# i# `and#` int2Word# 7#) @@ -232,8 +232,8 @@ instance Bits Int16 where | i'# ==# 0# = I16# x# | otherwise - = I16# (narrow16Int# (word2Int# ((x'# `shiftL#` i'#) `or#` - (x'# `shiftRL#` (16# -# i'#))))) + = I16# (narrow16Int# (word2Int# ((x'# `uncheckedShiftL#` i'#) `or#` + (x'# `uncheckedShiftRL#` (16# -# i'#))))) where x'# = narrow16Word# (int2Word# x#) i'# = word2Int# (int2Word# i# `and#` int2Word# 15#) @@ -486,8 +486,8 @@ instance Bits Int32 where | i'# ==# 0# = I32# x# | otherwise - = I32# (narrow32Int# (word2Int# ((x'# `shiftL#` i'#) `or#` - (x'# `shiftRL#` (32# -# i'#))))) + = I32# (narrow32Int# (word2Int# ((x'# `uncheckedShiftL#` i'#) `or#` + (x'# `uncheckedShiftRL#` (32# -# i'#))))) where x'# = narrow32Word# (int2Word# x#) i'# = word2Int# (int2Word# i# `and#` int2Word# 31#) @@ -765,8 +765,8 @@ instance Bits Int64 where | i'# ==# 0# = I64# x# | otherwise - = I64# (word2Int# ((x'# `shiftL#` i'#) `or#` - (x'# `shiftRL#` (64# -# i'#)))) + = I64# (word2Int# ((x'# `uncheckedShiftL#` i'#) `or#` + (x'# `uncheckedShiftRL#` (64# -# i'#)))) where x'# = int2Word# x# i'# = word2Int# (int2Word# i# `and#` int2Word# 63#) diff --git a/GHC/Word.hs b/GHC/Word.hs index 87b6e63..694a9df 100644 --- a/GHC/Word.hs +++ b/GHC/Word.hs @@ -164,7 +164,7 @@ instance Bits Word where | otherwise = W# (x# `shiftRL#` negateInt# i#) (W# x#) `rotate` (I# i#) | i'# ==# 0# = W# x# - | otherwise = W# ((x# `shiftL#` i'#) `or#` (x# `shiftRL#` (wsib -# i'#))) + | otherwise = W# ((x# `uncheckedShiftL#` i'#) `or#` (x# `uncheckedShiftRL#` (wsib -# i'#))) where i'# = word2Int# (int2Word# i# `and#` int2Word# (wsib -# 1#)) wsib = WORD_SIZE_IN_BITS# {- work around preprocessor problem (??) -} @@ -264,8 +264,8 @@ instance Bits Word8 where | otherwise = W8# (x# `shiftRL#` negateInt# i#) (W8# x#) `rotate` (I# i#) | i'# ==# 0# = W8# x# - | otherwise = W8# (narrow8Word# ((x# `shiftL#` i'#) `or#` - (x# `shiftRL#` (8# -# i'#)))) + | otherwise = W8# (narrow8Word# ((x# `uncheckedShiftL#` i'#) `or#` + (x# `uncheckedShiftRL#` (8# -# i'#)))) where i'# = word2Int# (int2Word# i# `and#` int2Word# 7#) bitSize _ = 8 @@ -365,8 +365,8 @@ instance Bits Word16 where | otherwise = W16# (x# `shiftRL#` negateInt# i#) (W16# x#) `rotate` (I# i#) | i'# ==# 0# = W16# x# - | otherwise = W16# (narrow16Word# ((x# `shiftL#` i'#) `or#` - (x# `shiftRL#` (16# -# i'#)))) + | otherwise = W16# (narrow16Word# ((x# `uncheckedShiftL#` i'#) `or#` + (x# `uncheckedShiftRL#` (16# -# i'#)))) where i'# = word2Int# (int2Word# i# `and#` int2Word# 15#) bitSize _ = 16 @@ -595,8 +595,8 @@ instance Bits Word32 where | otherwise = W32# (x# `shiftRL#` negateInt# i#) (W32# x#) `rotate` (I# i#) | i'# ==# 0# = W32# x# - | otherwise = W32# (narrow32Word# ((x# `shiftL#` i'#) `or#` - (x# `shiftRL#` (32# -# i'#)))) + | otherwise = W32# (narrow32Word# ((x# `uncheckedShiftL#` i'#) `or#` + (x# `uncheckedShiftRL#` (32# -# i'#)))) where i'# = word2Int# (int2Word# i# `and#` int2Word# 31#) bitSize _ = 32 @@ -856,8 +856,8 @@ instance Bits Word64 where | otherwise = W64# (x# `shiftRL#` negateInt# i#) (W64# x#) `rotate` (I# i#) | i'# ==# 0# = W64# x# - | otherwise = W64# ((x# `shiftL#` i'#) `or#` - (x# `shiftRL#` (64# -# i'#))) + | otherwise = W64# ((x# `uncheckedShiftL#` i'#) `or#` + (x# `uncheckedShiftRL#` (64# -# i'#))) where i'# = word2Int# (int2Word# i# `and#` int2Word# 63#) bitSize _ = 64 -- 1.7.10.4