diff options
author | Johan Tibell <johan.tibell@gmail.com> | 2011-08-14 11:45:27 +0100 |
---|---|---|
committer | Johan Tibell <johan.tibell@gmail.com> | 2011-11-08 15:03:13 -0800 |
commit | f1c593e01d740fde1202f84aa37ad4cc95ec7272 (patch) | |
tree | 903d501f6cc11c9b10ac2e3e123b8dfb1133be0b /libraries/base/GHC/Int.hs | |
parent | c7e5902d023f32b007e2efe01d61852cdd3b23eb (diff) | |
download | haskell-f1c593e01d740fde1202f84aa37ad4cc95ec7272.tar.gz |
Add unsafeShift to Data.Bits
This allows shifting by a non-statically known amount without
introducing a branch (to check for "overflow").
Diffstat (limited to 'libraries/base/GHC/Int.hs')
-rw-r--r-- | libraries/base/GHC/Int.hs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/libraries/base/GHC/Int.hs b/libraries/base/GHC/Int.hs index f1fa3043cf..b11cf26d1d 100644 --- a/libraries/base/GHC/Int.hs +++ b/libraries/base/GHC/Int.hs @@ -138,7 +138,9 @@ instance Bits Int8 where | i# >=# 0# = I8# (narrow8Int# (x# `iShiftL#` i#)) | otherwise = I8# (x# `iShiftRA#` negateInt# i#) (I8# x#) `shiftL` (I# i#) = I8# (narrow8Int# (x# `iShiftL#` i#)) + (I8# x#) `unsafeShiftL` (I# i#) = I8# (narrow8Int# (x# `uncheckedIShiftL#` i#)) (I8# x#) `shiftR` (I# i#) = I8# (x# `iShiftRA#` i#) + (I8# x#) `unsafeShiftR` (I# i#) = I8# (x# `uncheckedIShiftRA#` i#) (I8# x#) `rotate` (I# i#) | i'# ==# 0# = I8# x# @@ -283,7 +285,9 @@ instance Bits Int16 where | i# >=# 0# = I16# (narrow16Int# (x# `iShiftL#` i#)) | otherwise = I16# (x# `iShiftRA#` negateInt# i#) (I16# x#) `shiftL` (I# i#) = I16# (narrow16Int# (x# `iShiftL#` i#)) + (I16# x#) `unsafeShiftL` (I# i#) = I16# (narrow16Int# (x# `uncheckedIShiftL#` i#)) (I16# x#) `shiftR` (I# i#) = I16# (x# `iShiftRA#` i#) + (I16# x#) `unsafeShiftR` (I# i#) = I16# (x# `uncheckedIShiftRA#` i#) (I16# x#) `rotate` (I# i#) | i'# ==# 0# = I16# x# @@ -434,7 +438,10 @@ instance Bits Int32 where | i# >=# 0# = I32# (narrow32Int# (x# `iShiftL#` i#)) | otherwise = I32# (x# `iShiftRA#` negateInt# i#) (I32# x#) `shiftL` (I# i#) = I32# (narrow32Int# (x# `iShiftL#` i#)) + (I32# x#) `unsafeShiftL` (I# i#) = + I32# (narrow32Int# (x# `uncheckedIShiftL#` i#)) (I32# x#) `shiftR` (I# i#) = I32# (x# `iShiftRA#` i#) + (I32# x#) `unsafeShiftR` (I# i#) = I32# (x# `uncheckedIShiftRA#` i#) (I32# x#) `rotate` (I# i#) | i'# ==# 0# = I32# x# @@ -618,7 +625,9 @@ instance Bits Int64 where | i# >=# 0# = I64# (x# `iShiftL64#` i#) | otherwise = I64# (x# `iShiftRA64#` negateInt# i#) (I64# x#) `shiftL` (I# i#) = I64# (x# `iShiftL64#` i#) + (I64# x#) `unsafeShiftL` (I# i#) = I64# (x# `uncheckedIShiftL64#` i#) (I64# x#) `shiftR` (I# i#) = I64# (x# `iShiftRA64#` i#) + (I64# x#) `unsafeShiftR` (I# i#) = I64# (x# `uncheckedIShiftRA64#` i#) (I64# x#) `rotate` (I# i#) | i'# ==# 0# = I64# x# @@ -745,7 +754,9 @@ instance Bits Int64 where | i# >=# 0# = I64# (x# `iShiftL#` i#) | otherwise = I64# (x# `iShiftRA#` negateInt# i#) (I64# x#) `shiftL` (I# i#) = I64# (x# `iShiftL#` i#) + (I64# x#) `unsafeShiftL` (I# i#) = I64# (x# `uncheckedIShiftL#` i#) (I64# x#) `shiftR` (I# i#) = I64# (x# `iShiftRA#` i#) + (I64# x#) `unsafeShiftR` (I# i#) = I64# (x# `uncheckedIShiftRA#` i#) (I64# x#) `rotate` (I# i#) | i'# ==# 0# = I64# x# |