From 2a9e20e3aa6fa7870f61c1bf33979bbbca8157c0 Mon Sep 17 00:00:00 2001 From: sewardj Date: Fri, 14 Sep 2001 13:52:21 +0000 Subject: [PATCH] [project @ 2001-09-14 13:52:21 by sewardj] Make rotate fns work properly when rotate count is a multiple of the word size. This fixes sparc failures in ghc-regress/numeric/should_run/arith011. Also fix some copy-and-paste-o-s.Killed by signal 2. MERGE TO STABLE --- ghc/lib/std/PrelInt.lhs | 56 ++++++++++++++++++++++++++++++---------------- ghc/lib/std/PrelWord.lhs | 42 ++++++++++++++++++++++------------ 2 files changed, 65 insertions(+), 33 deletions(-) diff --git a/ghc/lib/std/PrelInt.lhs b/ghc/lib/std/PrelInt.lhs index 42efc75..e282716 100644 --- a/ghc/lib/std/PrelInt.lhs +++ b/ghc/lib/std/PrelInt.lhs @@ -112,9 +112,12 @@ instance Bits Int8 where (I8# x#) `shift` (I# i#) | i# >=# 0# = I8# (narrow8Int# (x# `iShiftL#` i#)) | otherwise = I8# (x# `iShiftRA#` negateInt# i#) - (I8# x#) `rotate` (I# i#) = - I8# (narrow8Int# (word2Int# ((x'# `shiftL#` i'#) `or#` - (x'# `shiftRL#` (8# -# i'#))))) + (I8# x#) `rotate` (I# i#) + | i'# ==# 0# + = I8# x# + | otherwise + = I8# (narrow8Int# (word2Int# ((x'# `shiftL#` i'#) `or#` + (x'# `shiftRL#` (8# -# i'#))))) where x'# = narrow8Word# (int2Word# x#) i'# = word2Int# (int2Word# i# `and#` int2Word# 7#) @@ -217,9 +220,12 @@ instance Bits Int16 where (I16# x#) `shift` (I# i#) | i# >=# 0# = I16# (narrow16Int# (x# `iShiftL#` i#)) | otherwise = I16# (x# `iShiftRA#` negateInt# i#) - (I16# x#) `rotate` (I# i#) = - I16# (narrow16Int# (word2Int# ((x'# `shiftL#` i'#) `or#` - (x'# `shiftRL#` (16# -# i'#))))) + (I16# x#) `rotate` (I# i#) + | i'# ==# 0# + = I16# x# + | otherwise + = I16# (narrow16Int# (word2Int# ((x'# `shiftL#` i'#) `or#` + (x'# `shiftRL#` (16# -# i'#))))) where x'# = narrow16Word# (int2Word# x#) i'# = word2Int# (int2Word# i# `and#` int2Word# 15#) @@ -335,12 +341,15 @@ instance Bits Int32 where (I32# x#) `shift` (I# i#) | i# >=# 0# = I32# (x# `iShiftL32#` i#) | otherwise = I32# (x# `iShiftRA32#` negateInt# i#) - (I32# x#) `rotate` (I# i#) = - I32# (word32ToInt32# ((x'# `shiftL32#` i'#) `or32#` - (x'# `shiftRL32#` (32# -# i'#)))) + (I32# x#) `rotate` (I# i#) + | i'# ==# 0# + = I32# x# + | otherwise + = I32# (word32ToInt32# ((x'# `shiftL32#` i'#) `or32#` + (x'# `shiftRL32#` (32# -# i'#)))) where x'# = int32ToWord32# x# - i'# = word2Int# (int2Word# i# `and#` int2Word# 63#) + i'# = word2Int# (int2Word# i# `and#` int2Word# 31#) bitSize _ = 32 isSigned _ = True @@ -459,9 +468,12 @@ instance Bits Int32 where (I32# x#) `shift` (I# i#) | i# >=# 0# = I32# (narrow32Int# (x# `iShiftL#` i#)) | otherwise = I32# (x# `iShiftRA#` negateInt# i#) - (I32# x#) `rotate` (I# i#) = - I32# (narrow32Int# (word2Int# ((x'# `shiftL#` i'#) `or#` - (x'# `shiftRL#` (32# -# i'#))))) + (I32# x#) `rotate` (I# i#) + | i'# ==# 0# + = I32# x# + | otherwise + = I32# (narrow32Int# (word2Int# ((x'# `shiftL#` i'#) `or#` + (x'# `shiftRL#` (32# -# i'#))))) where x'# = narrow32Word# (int2Word# x#) i'# = word2Int# (int2Word# i# `and#` int2Word# 31#) @@ -598,9 +610,12 @@ instance Bits Int64 where (I64# x#) `shift` (I# i#) | i# >=# 0# = I64# (x# `iShiftL64#` i#) | otherwise = I64# (x# `iShiftRA64#` negateInt# i#) - (I64# x#) `rotate` (I# i#) = - I64# (word64ToInt64# ((x'# `shiftL64#` i'#) `or64#` - (x'# `shiftRL64#` (64# -# i'#)))) + (I64# x#) `rotate` (I# i#) + | i'# ==# 0# + = I64# x# + | otherwise + = I64# (word64ToInt64# ((x'# `shiftL64#` i'#) `or64#` + (x'# `shiftRL64#` (64# -# i'#)))) where x'# = int64ToWord64# x# i'# = word2Int# (int2Word# i# `and#` int2Word# 63#) @@ -711,9 +726,12 @@ instance Bits Int64 where (I64# x#) `shift` (I# i#) | i# >=# 0# = I64# (x# `iShiftL#` i#) | otherwise = I64# (x# `iShiftRA#` negateInt# i#) - (I64# x#) `rotate` (I# i#) = - I64# (word2Int# ((x'# `shiftL#` i'#) `or#` - (x'# `shiftRL#` (64# -# i'#)))) + (I64# x#) `rotate` (I# i#) + | i'# ==# 0# + = I64# x# + | otherwise + = I64# (word2Int# ((x'# `shiftL#` i'#) `or#` + (x'# `shiftRL#` (64# -# i'#)))) where x'# = int2Word# x# i'# = word2Int# (int2Word# i# `and#` int2Word# 63#) diff --git a/ghc/lib/std/PrelWord.lhs b/ghc/lib/std/PrelWord.lhs index 79c79fe..fb12ea1 100644 --- a/ghc/lib/std/PrelWord.lhs +++ b/ghc/lib/std/PrelWord.lhs @@ -156,7 +156,9 @@ instance Bits Word where (W# x#) `shift` (I# i#) | i# >=# 0# = W# (x# `shiftL#` i#) | otherwise = W# (x# `shiftRL#` negateInt# i#) - (W# x#) `rotate` (I# i#) = W# ((x# `shiftL#` i'#) `or#` (x# `shiftRL#` (wsib -# i'#))) + (W# x#) `rotate` (I# i#) + | i'# ==# 0# = W# x# + | otherwise = W# ((x# `shiftL#` i'#) `or#` (x# `shiftRL#` (wsib -# i'#))) where i'# = word2Int# (int2Word# i# `and#` int2Word# (wsib -# 1#)) wsib = WORD_SIZE_IN_BITS# {- work around preprocessor problem (??) -} @@ -255,8 +257,10 @@ instance Bits Word8 where (W8# x#) `shift` (I# i#) | i# >=# 0# = W8# (narrow8Word# (x# `shiftL#` i#)) | otherwise = W8# (x# `shiftRL#` negateInt# i#) - (W8# x#) `rotate` (I# i#) = W8# (narrow8Word# ((x# `shiftL#` i'#) `or#` - (x# `shiftRL#` (8# -# i'#)))) + (W8# x#) `rotate` (I# i#) + | i'# ==# 0# = W8# x# + | otherwise = W8# (narrow8Word# ((x# `shiftL#` i'#) `or#` + (x# `shiftRL#` (8# -# i'#)))) where i'# = word2Int# (int2Word# i# `and#` int2Word# 7#) bitSize _ = 8 @@ -355,8 +359,10 @@ instance Bits Word16 where (W16# x#) `shift` (I# i#) | i# >=# 0# = W16# (narrow16Word# (x# `shiftL#` i#)) | otherwise = W16# (x# `shiftRL#` negateInt# i#) - (W16# x#) `rotate` (I# i#) = W16# (narrow16Word# ((x# `shiftL#` i'#) `or#` - (x# `shiftRL#` (16# -# i'#)))) + (W16# x#) `rotate` (I# i#) + | i'# ==# 0# = W16# x# + | otherwise = W16# (narrow16Word# ((x# `shiftL#` i'#) `or#` + (x# `shiftRL#` (16# -# i'#)))) where i'# = word2Int# (int2Word# i# `and#` int2Word# 15#) bitSize _ = 16 @@ -449,10 +455,12 @@ instance Bits Word32 where (W32# x#) `shift` (I# i#) | i# >=# 0# = W32# (x# `shiftL32#` i#) | otherwise = W32# (x# `shiftRL32#` negateInt# i#) - (W32# x#) `rotate` (I# i#) = W32# ((x# `shiftL32#` i'#) `or32#` - (x# `shiftRL32#` (32# -# i'#))) + (W32# x#) `rotate` (I# i#) + | i'# ==# 0# = W32# x# + | otherwise = W32# ((x# `shiftL32#` i'#) `or32#` + (x# `shiftRL32#` (32# -# i'#))) where - i'# = word2Int# (int2Word# i# `and#` int2Word# 63#) + i'# = word2Int# (int2Word# i# `and#` int2Word# 31#) bitSize _ = 32 isSigned _ = False @@ -575,8 +583,10 @@ instance Bits Word32 where (W32# x#) `shift` (I# i#) | i# >=# 0# = W32# (narrow32Word# (x# `shiftL#` i#)) | otherwise = W32# (x# `shiftRL#` negateInt# i#) - (W32# x#) `rotate` (I# i#) = W32# (narrow32Word# ((x# `shiftL#` i'#) `or#` - (x# `shiftRL#` (32# -# i'#)))) + (W32# x#) `rotate` (I# i#) + | i'# ==# 0# = W32# x# + | otherwise = W32# (narrow32Word# ((x# `shiftL#` i'#) `or#` + (x# `shiftRL#` (32# -# i'#)))) where i'# = word2Int# (int2Word# i# `and#` int2Word# 31#) bitSize _ = 32 @@ -703,8 +713,10 @@ instance Bits Word64 where (W64# x#) `shift` (I# i#) | i# >=# 0# = W64# (x# `shiftL64#` i#) | otherwise = W64# (x# `shiftRL64#` negateInt# i#) - (W64# x#) `rotate` (I# i#) = W64# ((x# `shiftL64#` i'#) `or64#` - (x# `shiftRL64#` (64# -# i'#))) + (W64# x#) `rotate` (I# i#) + | i'# ==# 0# = W64# x# + | otherwise = W64# ((x# `shiftL64#` i'#) `or64#` + (x# `shiftRL64#` (64# -# i'#))) where i'# = word2Int# (int2Word# i# `and#` int2Word# 63#) bitSize _ = 64 @@ -813,8 +825,10 @@ instance Bits Word64 where (W64# x#) `shift` (I# i#) | i# >=# 0# = W64# (x# `shiftL#` i#) | otherwise = W64# (x# `shiftRL#` negateInt# i#) - (W64# x#) `rotate` (I# i#) = W64# ((x# `shiftL#` i'#) `or#` - (x# `shiftRL#` (64# -# i'#))) + (W64# x#) `rotate` (I# i#) + | i'# ==# 0# = W64# x# + | otherwise = W64# ((x# `shiftL#` i'#) `or#` + (x# `shiftRL#` (64# -# i'#))) where i'# = word2Int# (int2Word# i# `and#` int2Word# 63#) bitSize _ = 64 -- 1.7.10.4