diff options
author | Sylvain Henry <sylvain@haskus.fr> | 2020-12-03 18:54:54 +0100 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-03-03 08:12:29 -0500 |
commit | d8dc0f96237fe6fe7081c04727c7c2573477e5cb (patch) | |
tree | dbc4e8d25cf5a085e979df98bacad5999bf78aee /libraries | |
parent | eea96042f1e8682605ae68db10f2bcdd7dab923e (diff) | |
download | haskell-d8dc0f96237fe6fe7081c04727c7c2573477e5cb.tar.gz |
Fix array and cleanup conversion primops (#19026)
The first change makes the array ones use the proper fixed-size types,
which also means that just like before, they can be used without
explicit conversions with the boxed sized types. (Before, it was Int# /
Word# on both sides, now it is fixed sized on both sides).
For the second change, don't use "extend" or "narrow" in some of the
user-facing primops names for conversions.
- Names like `narrowInt32#` are misleading when `Int` is 32-bits.
- Names like `extendInt64#` are flat-out wrong when `Int is
32-bits.
- `narrow{Int,Word}<N>#` however map a type to itself, and so don't
suffer from this problem. They are left as-is.
These changes are batched together because Alex happend to use the array
ops. We can only use released versions of Alex at this time, sadly, and
I don't want to have to have a release thatwon't work for the final GHC
9.2. So by combining these we get all the changes for Alex done at once.
Bump hackage state in a few places, and also make that workflow slightly
easier for the future.
Bump minimum Alex version
Bump Cabal, array, bytestring, containers, text, and binary submodules
Diffstat (limited to 'libraries')
m--------- | libraries/Cabal | 0 | ||||
m--------- | libraries/array | 0 | ||||
-rw-r--r-- | libraries/base/GHC/Float/ConversionUtils.hs | 2 | ||||
-rw-r--r-- | libraries/base/GHC/IO/Encoding/CodePage.hs | 6 | ||||
-rw-r--r-- | libraries/base/GHC/IO/Encoding/UTF16.hs | 4 | ||||
-rw-r--r-- | libraries/base/GHC/IO/Encoding/UTF32.hs | 8 | ||||
-rw-r--r-- | libraries/base/GHC/IO/Encoding/UTF8.hs | 18 | ||||
-rw-r--r-- | libraries/base/GHC/Int.hs | 260 | ||||
-rw-r--r-- | libraries/base/GHC/Storable.hs | 24 | ||||
-rw-r--r-- | libraries/base/GHC/Word.hs | 256 | ||||
m--------- | libraries/binary | 0 | ||||
m--------- | libraries/bytestring | 0 | ||||
m--------- | libraries/containers | 0 | ||||
-rw-r--r-- | libraries/ghc-bignum/src/GHC/Num/Backend/GMP.hs | 10 | ||||
-rw-r--r-- | libraries/ghc-bignum/src/GHC/Num/Primitives.hs | 16 | ||||
-rw-r--r-- | libraries/ghc-boot/GHC/Utils/Encoding.hs | 45 | ||||
-rw-r--r-- | libraries/ghc-heap/tests/tso_and_stack_closures.hs | 2 | ||||
-rw-r--r-- | libraries/ghc-prim/changelog.md | 18 | ||||
-rw-r--r-- | libraries/ghci/GHCi/BreakArray.hs | 26 | ||||
m--------- | libraries/text | 0 |
20 files changed, 370 insertions, 325 deletions
diff --git a/libraries/Cabal b/libraries/Cabal -Subproject d30b8f3ec0b0873b9d2eb245afdd53fabacdb88 +Subproject 23ca3cb318418aaf4aafd3db862278a12a794a2 diff --git a/libraries/array b/libraries/array -Subproject c7a696e3e6d5a6b00d3e00ca694af916f15bcff +Subproject 3e4334a6f39d92090bf3ded86b84d7cd1817ce2 diff --git a/libraries/base/GHC/Float/ConversionUtils.hs b/libraries/base/GHC/Float/ConversionUtils.hs index 5d9de64179..dc35bd09a3 100644 --- a/libraries/base/GHC/Float/ConversionUtils.hs +++ b/libraries/base/GHC/Float/ConversionUtils.hs @@ -64,6 +64,6 @@ elimZerosInt# n e = -- | Number of trailing zero bits in a byte zeroCount :: Int# -> Int# -zeroCount i = indexInt8OffAddr# arr (word2Int# (narrow8Word# (int2Word# i))) -- index must be in [0,255] +zeroCount i = int8ToInt# (indexInt8OffAddr# arr (word2Int# (narrow8Word# (int2Word# i)))) -- index must be in [0,255] where arr = "\8\0\1\0\2\0\1\0\3\0\1\0\2\0\1\0\4\0\1\0\2\0\1\0\3\0\1\0\2\0\1\0\5\0\1\0\2\0\1\0\3\0\1\0\2\0\1\0\4\0\1\0\2\0\1\0\3\0\1\0\2\0\1\0\6\0\1\0\2\0\1\0\3\0\1\0\2\0\1\0\4\0\1\0\2\0\1\0\3\0\1\0\2\0\1\0\5\0\1\0\2\0\1\0\3\0\1\0\2\0\1\0\4\0\1\0\2\0\1\0\3\0\1\0\2\0\1\0\7\0\1\0\2\0\1\0\3\0\1\0\2\0\1\0\4\0\1\0\2\0\1\0\3\0\1\0\2\0\1\0\5\0\1\0\2\0\1\0\3\0\1\0\2\0\1\0\4\0\1\0\2\0\1\0\3\0\1\0\2\0\1\0\6\0\1\0\2\0\1\0\3\0\1\0\2\0\1\0\4\0\1\0\2\0\1\0\3\0\1\0\2\0\1\0\5\0\1\0\2\0\1\0\3\0\1\0\2\0\1\0\4\0\1\0\2\0\1\0\3\0\1\0\2\0\1\0"# diff --git a/libraries/base/GHC/IO/Encoding/CodePage.hs b/libraries/base/GHC/IO/Encoding/CodePage.hs index 6c77e65c41..39430c5ee0 100644 --- a/libraries/base/GHC/IO/Encoding/CodePage.hs +++ b/libraries/base/GHC/IO/Encoding/CodePage.hs @@ -170,15 +170,15 @@ lookupCompact maxVal indexes values x {-# INLINE indexInt #-} indexInt :: ConvArray Int -> Int -> Int -indexInt (ConvArray p) (I# i) = I# (indexInt16OffAddr# p i) +indexInt (ConvArray p) (I# i) = I# (int16ToInt# (indexInt16OffAddr# p i)) {-# INLINE indexWord8 #-} indexWord8 :: ConvArray Word8 -> Int -> Word8 -indexWord8 (ConvArray p) (I# i) = W8# (narrowWord8# (indexWord8OffAddr# p i)) +indexWord8 (ConvArray p) (I# i) = W8# (indexWord8OffAddr# p i) {-# INLINE indexChar #-} indexChar :: ConvArray Char -> Int -> Char -indexChar (ConvArray p) (I# i) = C# (chr# (indexInt16OffAddr# p i)) +indexChar (ConvArray p) (I# i) = C# (chr# (int16ToInt# (indexInt16OffAddr# p i))) #endif diff --git a/libraries/base/GHC/IO/Encoding/UTF16.hs b/libraries/base/GHC/IO/Encoding/UTF16.hs index c77c131eef..a0878d4fce 100644 --- a/libraries/base/GHC/IO/Encoding/UTF16.hs +++ b/libraries/base/GHC/IO/Encoding/UTF16.hs @@ -342,8 +342,8 @@ utf16le_encode chr2 :: Word16 -> Word16 -> Char chr2 (W16# a#) (W16# b#) = C# (chr# (upper# +# lower# +# 0x10000#)) where - !x# = word2Int# (extendWord16# a#) - !y# = word2Int# (extendWord16# b#) + !x# = word2Int# (word16ToWord# a#) + !y# = word2Int# (word16ToWord# b#) !upper# = uncheckedIShiftL# (x# -# 0xD800#) 10# !lower# = y# -# 0xDC00# {-# INLINE chr2 #-} diff --git a/libraries/base/GHC/IO/Encoding/UTF32.hs b/libraries/base/GHC/IO/Encoding/UTF32.hs index c14b365a04..379f76066b 100644 --- a/libraries/base/GHC/IO/Encoding/UTF32.hs +++ b/libraries/base/GHC/IO/Encoding/UTF32.hs @@ -309,10 +309,10 @@ chr4 :: Word8 -> Word8 -> Word8 -> Word8 -> Char chr4 (W8# x1#) (W8# x2#) (W8# x3#) (W8# x4#) = C# (chr# (z1# +# z2# +# z3# +# z4#)) where - !y1# = word2Int# (extendWord8# x1#) - !y2# = word2Int# (extendWord8# x2#) - !y3# = word2Int# (extendWord8# x3#) - !y4# = word2Int# (extendWord8# x4#) + !y1# = word2Int# (word8ToWord# x1#) + !y2# = word2Int# (word8ToWord# x2#) + !y3# = word2Int# (word8ToWord# x3#) + !y4# = word2Int# (word8ToWord# x4#) !z1# = uncheckedIShiftL# y1# 24# !z2# = uncheckedIShiftL# y2# 16# !z3# = uncheckedIShiftL# y3# 8# diff --git a/libraries/base/GHC/IO/Encoding/UTF8.hs b/libraries/base/GHC/IO/Encoding/UTF8.hs index d887a92960..4513ab68b6 100644 --- a/libraries/base/GHC/IO/Encoding/UTF8.hs +++ b/libraries/base/GHC/IO/Encoding/UTF8.hs @@ -283,8 +283,8 @@ ord4 c = assert (n >= 0x10000) (x1,x2,x3,x4) chr2 :: Word8 -> Word8 -> Char chr2 (W8# x1#) (W8# x2#) = C# (chr# (z1# +# z2#)) where - !y1# = word2Int# (extendWord8# x1#) - !y2# = word2Int# (extendWord8# x2#) + !y1# = word2Int# (word8ToWord# x1#) + !y2# = word2Int# (word8ToWord# x2#) !z1# = uncheckedIShiftL# (y1# -# 0xC0#) 6# !z2# = y2# -# 0x80# {-# INLINE chr2 #-} @@ -292,9 +292,9 @@ chr2 (W8# x1#) (W8# x2#) = C# (chr# (z1# +# z2#)) chr3 :: Word8 -> Word8 -> Word8 -> Char chr3 (W8# x1#) (W8# x2#) (W8# x3#) = C# (chr# (z1# +# z2# +# z3#)) where - !y1# = word2Int# (extendWord8# x1#) - !y2# = word2Int# (extendWord8# x2#) - !y3# = word2Int# (extendWord8# x3#) + !y1# = word2Int# (word8ToWord# x1#) + !y2# = word2Int# (word8ToWord# x2#) + !y3# = word2Int# (word8ToWord# x3#) !z1# = uncheckedIShiftL# (y1# -# 0xE0#) 12# !z2# = uncheckedIShiftL# (y2# -# 0x80#) 6# !z3# = y3# -# 0x80# @@ -304,10 +304,10 @@ chr4 :: Word8 -> Word8 -> Word8 -> Word8 -> Char chr4 (W8# x1#) (W8# x2#) (W8# x3#) (W8# x4#) = C# (chr# (z1# +# z2# +# z3# +# z4#)) where - !y1# = word2Int# (extendWord8# x1#) - !y2# = word2Int# (extendWord8# x2#) - !y3# = word2Int# (extendWord8# x3#) - !y4# = word2Int# (extendWord8# x4#) + !y1# = word2Int# (word8ToWord# x1#) + !y2# = word2Int# (word8ToWord# x2#) + !y3# = word2Int# (word8ToWord# x3#) + !y4# = word2Int# (word8ToWord# x4#) !z1# = uncheckedIShiftL# (y1# -# 0xF0#) 18# !z2# = uncheckedIShiftL# (y2# -# 0x80#) 12# !z3# = uncheckedIShiftL# (y3# -# 0x80#) 6# diff --git a/libraries/base/GHC/Int.hs b/libraries/base/GHC/Int.hs index 2af0856bb7..2fe7d6ce8c 100644 --- a/libraries/base/GHC/Int.hs +++ b/libraries/base/GHC/Int.hs @@ -69,8 +69,8 @@ instance Eq Int8 where (/=) = neInt8 eqInt8, neInt8 :: Int8 -> Int8 -> Bool -eqInt8 (I8# x) (I8# y) = isTrue# ((extendInt8# x) ==# (extendInt8# y)) -neInt8 (I8# x) (I8# y) = isTrue# ((extendInt8# x) /=# (extendInt8# y)) +eqInt8 (I8# x) (I8# y) = isTrue# ((int8ToInt# x) ==# (int8ToInt# y)) +neInt8 (I8# x) (I8# y) = isTrue# ((int8ToInt# x) /=# (int8ToInt# y)) {-# INLINE [1] eqInt8 #-} {-# INLINE [1] neInt8 #-} @@ -86,10 +86,10 @@ instance Ord Int8 where {-# INLINE [1] ltInt8 #-} {-# INLINE [1] leInt8 #-} gtInt8, geInt8, ltInt8, leInt8 :: Int8 -> Int8 -> Bool -(I8# x) `gtInt8` (I8# y) = isTrue# ((extendInt8# x) ># (extendInt8# y)) -(I8# x) `geInt8` (I8# y) = isTrue# ((extendInt8# x) >=# (extendInt8# y)) -(I8# x) `ltInt8` (I8# y) = isTrue# ((extendInt8# x) <# (extendInt8# y)) -(I8# x) `leInt8` (I8# y) = isTrue# ((extendInt8# x) <=# (extendInt8# y)) +(I8# x) `gtInt8` (I8# y) = isTrue# ((int8ToInt# x) ># (int8ToInt# y)) +(I8# x) `geInt8` (I8# y) = isTrue# ((int8ToInt# x) >=# (int8ToInt# y)) +(I8# x) `ltInt8` (I8# y) = isTrue# ((int8ToInt# x) <# (int8ToInt# y)) +(I8# x) `leInt8` (I8# y) = isTrue# ((int8ToInt# x) <=# (int8ToInt# y)) -- | @since 2.01 instance Show Int8 where @@ -97,16 +97,16 @@ instance Show Int8 where -- | @since 2.01 instance Num Int8 where - (I8# x#) + (I8# y#) = I8# (narrowInt8# ((extendInt8# x#) +# (extendInt8# y#))) - (I8# x#) - (I8# y#) = I8# (narrowInt8# ((extendInt8# x#) -# (extendInt8# y#))) - (I8# x#) * (I8# y#) = I8# (narrowInt8# ((extendInt8# x#) *# (extendInt8# y#))) - negate (I8# x#) = I8# (narrowInt8# (negateInt# (extendInt8# x#))) + (I8# x#) + (I8# y#) = I8# (intToInt8# ((int8ToInt# x#) +# (int8ToInt# y#))) + (I8# x#) - (I8# y#) = I8# (intToInt8# ((int8ToInt# x#) -# (int8ToInt# y#))) + (I8# x#) * (I8# y#) = I8# (intToInt8# ((int8ToInt# x#) *# (int8ToInt# y#))) + negate (I8# x#) = I8# (intToInt8# (negateInt# (int8ToInt# x#))) abs x | x >= 0 = x | otherwise = negate x signum x | x > 0 = 1 signum 0 = 0 signum _ = -1 - fromInteger i = I8# (narrowInt8# (integerToInt# i)) + fromInteger i = I8# (intToInt8# (integerToInt# i)) -- | @since 2.01 instance Real Int8 where @@ -122,9 +122,9 @@ instance Enum Int8 where | otherwise = predError "Int8" toEnum i@(I# i#) | i >= fromIntegral (minBound::Int8) && i <= fromIntegral (maxBound::Int8) - = I8# (narrowInt8# i#) + = I8# (intToInt8# i#) | otherwise = toEnumError "Int8" i (minBound::Int8, maxBound::Int8) - fromEnum (I8# x#) = I# (extendInt8# x#) + fromEnum (I8# x#) = I# (int8ToInt# x#) enumFrom = boundedEnumFrom enumFromThen = boundedEnumFromThen @@ -133,34 +133,34 @@ instance Integral Int8 where quot x@(I8# x#) y@(I8# y#) | y == 0 = divZeroError | y == (-1) && x == minBound = overflowError -- Note [Order of tests] - | otherwise = I8# (narrowInt8# ((extendInt8# x#) `quotInt#` (extendInt8# y#))) + | otherwise = I8# (intToInt8# ((int8ToInt# x#) `quotInt#` (int8ToInt# y#))) rem (I8# x#) y@(I8# y#) | y == 0 = divZeroError - | otherwise = I8# (narrowInt8# ((extendInt8# x#) `remInt#` (extendInt8# y#))) + | otherwise = I8# (intToInt8# ((int8ToInt# x#) `remInt#` (int8ToInt# y#))) div x@(I8# x#) y@(I8# y#) | y == 0 = divZeroError | y == (-1) && x == minBound = overflowError -- Note [Order of tests] - | otherwise = I8# (narrowInt8# ((extendInt8# x#) `divInt#` (extendInt8# y#))) + | otherwise = I8# (intToInt8# ((int8ToInt# x#) `divInt#` (int8ToInt# y#))) mod (I8# x#) y@(I8# y#) | y == 0 = divZeroError - | otherwise = I8# (narrowInt8# ((extendInt8# x#) `modInt#` (extendInt8# y#))) + | otherwise = I8# (intToInt8# ((int8ToInt# x#) `modInt#` (int8ToInt# y#))) quotRem x@(I8# x#) y@(I8# y#) | y == 0 = divZeroError -- Note [Order of tests] | y == (-1) && x == minBound = (overflowError, 0) - | otherwise = case (extendInt8# x#) `quotRemInt#` (extendInt8# y#) of + | otherwise = case (int8ToInt# x#) `quotRemInt#` (int8ToInt# y#) of (# q, r #) -> - (I8# (narrowInt8# q), - I8# (narrowInt8# r)) + (I8# (intToInt8# q), + I8# (intToInt8# r)) divMod x@(I8# x#) y@(I8# y#) | y == 0 = divZeroError -- Note [Order of tests] | y == (-1) && x == minBound = (overflowError, 0) - | otherwise = case (extendInt8# x#) `divModInt#` (extendInt8# y#) of + | otherwise = case (int8ToInt# x#) `divModInt#` (int8ToInt# y#) of (# d, m #) -> - (I8# (narrowInt8# d), - I8# (narrowInt8# m)) - toInteger (I8# x#) = IS (extendInt8# x#) + (I8# (intToInt8# d), + I8# (intToInt8# m)) + toInteger (I8# x#) = IS (int8ToInt# x#) -- | @since 2.01 instance Bounded Int8 where @@ -184,34 +184,34 @@ instance Bits Int8 where {-# INLINE testBit #-} {-# INLINE popCount #-} - (I8# x#) .&. (I8# y#) = I8# (narrowInt8# ((extendInt8# x#) `andI#` (extendInt8# y#))) - (I8# x#) .|. (I8# y#) = I8# (narrowInt8# ((extendInt8# x#) `orI#` (extendInt8# y#))) - (I8# x#) `xor` (I8# y#) = I8# (narrowInt8# ((extendInt8# x#) `xorI#` (extendInt8# y#))) - complement (I8# x#) = I8# (narrowInt8# (notI# (extendInt8# x#))) + (I8# x#) .&. (I8# y#) = I8# (intToInt8# ((int8ToInt# x#) `andI#` (int8ToInt# y#))) + (I8# x#) .|. (I8# y#) = I8# (intToInt8# ((int8ToInt# x#) `orI#` (int8ToInt# y#))) + (I8# x#) `xor` (I8# y#) = I8# (intToInt8# ((int8ToInt# x#) `xorI#` (int8ToInt# y#))) + complement (I8# x#) = I8# (intToInt8# (notI# (int8ToInt# x#))) (I8# x#) `shift` (I# i#) - | isTrue# (i# >=# 0#) = I8# (narrowInt8# ((extendInt8# x#) `iShiftL#` i#)) - | otherwise = I8# (narrowInt8# ((extendInt8# x#) `iShiftRA#` negateInt# i#)) + | isTrue# (i# >=# 0#) = I8# (intToInt8# ((int8ToInt# x#) `iShiftL#` i#)) + | otherwise = I8# (intToInt8# ((int8ToInt# x#) `iShiftRA#` negateInt# i#)) (I8# x#) `shiftL` (I# i#) - | isTrue# (i# >=# 0#) = I8# (narrowInt8# ((extendInt8# x#) `iShiftL#` i#)) + | isTrue# (i# >=# 0#) = I8# (intToInt8# ((int8ToInt# x#) `iShiftL#` i#)) | otherwise = overflowError - (I8# x#) `unsafeShiftL` (I# i#) = I8# (narrowInt8# ((extendInt8# x#) `uncheckedIShiftL#` i#)) + (I8# x#) `unsafeShiftL` (I# i#) = I8# (intToInt8# ((int8ToInt# x#) `uncheckedIShiftL#` i#)) (I8# x#) `shiftR` (I# i#) - | isTrue# (i# >=# 0#) = I8# (narrowInt8# ((extendInt8# x#) `iShiftRA#` i#)) + | isTrue# (i# >=# 0#) = I8# (intToInt8# ((int8ToInt# x#) `iShiftRA#` i#)) | otherwise = overflowError - (I8# x#) `unsafeShiftR` (I# i#) = I8# (narrowInt8# ((extendInt8# x#) `uncheckedIShiftRA#` i#)) + (I8# x#) `unsafeShiftR` (I# i#) = I8# (intToInt8# ((int8ToInt# x#) `uncheckedIShiftRA#` i#)) (I8# x#) `rotate` (I# i#) | isTrue# (i'# ==# 0#) = I8# x# | otherwise - = I8# (narrowInt8# (word2Int# ((x'# `uncheckedShiftL#` i'#) `or#` + = I8# (intToInt8# (word2Int# ((x'# `uncheckedShiftL#` i'#) `or#` (x'# `uncheckedShiftRL#` (8# -# i'#))))) where - !x'# = narrow8Word# (int2Word# (extendInt8# x#)) + !x'# = narrow8Word# (int2Word# (int8ToInt# x#)) !i'# = word2Int# (int2Word# i# `and#` 7##) bitSizeMaybe i = Just (finiteBitSize i) bitSize i = finiteBitSize i isSigned _ = True - popCount (I8# x#) = I# (word2Int# (popCnt8# (int2Word# (extendInt8# x#)))) + popCount (I8# x#) = I# (word2Int# (popCnt8# (int2Word# (int8ToInt# x#)))) bit = bitDefault testBit = testBitDefault @@ -220,13 +220,13 @@ instance FiniteBits Int8 where {-# INLINE countLeadingZeros #-} {-# INLINE countTrailingZeros #-} finiteBitSize _ = 8 - countLeadingZeros (I8# x#) = I# (word2Int# (clz8# (int2Word# (extendInt8# x#)))) - countTrailingZeros (I8# x#) = I# (word2Int# (ctz8# (int2Word# (extendInt8# x#)))) + countLeadingZeros (I8# x#) = I# (word2Int# (clz8# (int2Word# (int8ToInt# x#)))) + countTrailingZeros (I8# x#) = I# (word2Int# (ctz8# (int2Word# (int8ToInt# x#)))) {-# RULES "fromIntegral/Int8->Int8" fromIntegral = id :: Int8 -> Int8 -"fromIntegral/a->Int8" fromIntegral = \x -> case fromIntegral x of I# x# -> I8# (narrowInt8# x#) -"fromIntegral/Int8->a" fromIntegral = \(I8# x#) -> fromIntegral (I# (extendInt8# x#)) +"fromIntegral/a->Int8" fromIntegral = \x -> case fromIntegral x of I# x# -> I8# (intToInt8# x#) +"fromIntegral/Int8->a" fromIntegral = \(I8# x#) -> fromIntegral (I# (int8ToInt# x#)) #-} {-# RULES @@ -276,8 +276,8 @@ instance Eq Int16 where (/=) = neInt16 eqInt16, neInt16 :: Int16 -> Int16 -> Bool -eqInt16 (I16# x) (I16# y) = isTrue# ((extendInt16# x) ==# (extendInt16# y)) -neInt16 (I16# x) (I16# y) = isTrue# ((extendInt16# x) /=# (extendInt16# y)) +eqInt16 (I16# x) (I16# y) = isTrue# ((int16ToInt# x) ==# (int16ToInt# y)) +neInt16 (I16# x) (I16# y) = isTrue# ((int16ToInt# x) /=# (int16ToInt# y)) {-# INLINE [1] eqInt16 #-} {-# INLINE [1] neInt16 #-} @@ -293,10 +293,10 @@ instance Ord Int16 where {-# INLINE [1] ltInt16 #-} {-# INLINE [1] leInt16 #-} gtInt16, geInt16, ltInt16, leInt16 :: Int16 -> Int16 -> Bool -(I16# x) `gtInt16` (I16# y) = isTrue# ((extendInt16# x) ># (extendInt16# y)) -(I16# x) `geInt16` (I16# y) = isTrue# ((extendInt16# x) >=# (extendInt16# y)) -(I16# x) `ltInt16` (I16# y) = isTrue# ((extendInt16# x) <# (extendInt16# y)) -(I16# x) `leInt16` (I16# y) = isTrue# ((extendInt16# x) <=# (extendInt16# y)) +(I16# x) `gtInt16` (I16# y) = isTrue# ((int16ToInt# x) ># (int16ToInt# y)) +(I16# x) `geInt16` (I16# y) = isTrue# ((int16ToInt# x) >=# (int16ToInt# y)) +(I16# x) `ltInt16` (I16# y) = isTrue# ((int16ToInt# x) <# (int16ToInt# y)) +(I16# x) `leInt16` (I16# y) = isTrue# ((int16ToInt# x) <=# (int16ToInt# y)) -- | @since 2.01 instance Show Int16 where @@ -304,16 +304,16 @@ instance Show Int16 where -- | @since 2.01 instance Num Int16 where - (I16# x#) + (I16# y#) = I16# (narrowInt16# ((extendInt16# x#) +# (extendInt16# y#))) - (I16# x#) - (I16# y#) = I16# (narrowInt16# ((extendInt16# x#) -# (extendInt16# y#))) - (I16# x#) * (I16# y#) = I16# (narrowInt16# ((extendInt16# x#) *# (extendInt16# y#))) - negate (I16# x#) = I16# (narrowInt16# (negateInt# (extendInt16# x#))) + (I16# x#) + (I16# y#) = I16# (intToInt16# ((int16ToInt# x#) +# (int16ToInt# y#))) + (I16# x#) - (I16# y#) = I16# (intToInt16# ((int16ToInt# x#) -# (int16ToInt# y#))) + (I16# x#) * (I16# y#) = I16# (intToInt16# ((int16ToInt# x#) *# (int16ToInt# y#))) + negate (I16# x#) = I16# (intToInt16# (negateInt# (int16ToInt# x#))) abs x | x >= 0 = x | otherwise = negate x signum x | x > 0 = 1 signum 0 = 0 signum _ = -1 - fromInteger i = I16# (narrowInt16# (integerToInt# i)) + fromInteger i = I16# (intToInt16# (integerToInt# i)) -- | @since 2.01 instance Real Int16 where @@ -329,9 +329,9 @@ instance Enum Int16 where | otherwise = predError "Int16" toEnum i@(I# i#) | i >= fromIntegral (minBound::Int16) && i <= fromIntegral (maxBound::Int16) - = I16# (narrowInt16# i#) + = I16# (intToInt16# i#) | otherwise = toEnumError "Int16" i (minBound::Int16, maxBound::Int16) - fromEnum (I16# x#) = I# (extendInt16# x#) + fromEnum (I16# x#) = I# (int16ToInt# x#) enumFrom = boundedEnumFrom enumFromThen = boundedEnumFromThen @@ -340,34 +340,34 @@ instance Integral Int16 where quot x@(I16# x#) y@(I16# y#) | y == 0 = divZeroError | y == (-1) && x == minBound = overflowError -- Note [Order of tests] - | otherwise = I16# (narrowInt16# ((extendInt16# x#) `quotInt#` (extendInt16# y#))) + | otherwise = I16# (intToInt16# ((int16ToInt# x#) `quotInt#` (int16ToInt# y#))) rem (I16# x#) y@(I16# y#) | y == 0 = divZeroError - | otherwise = I16# (narrowInt16# ((extendInt16# x#) `remInt#` (extendInt16# y#))) + | otherwise = I16# (intToInt16# ((int16ToInt# x#) `remInt#` (int16ToInt# y#))) div x@(I16# x#) y@(I16# y#) | y == 0 = divZeroError | y == (-1) && x == minBound = overflowError -- Note [Order of tests] - | otherwise = I16# (narrowInt16# ((extendInt16# x#) `divInt#` (extendInt16# y#))) + | otherwise = I16# (intToInt16# ((int16ToInt# x#) `divInt#` (int16ToInt# y#))) mod (I16# x#) y@(I16# y#) | y == 0 = divZeroError - | otherwise = I16# (narrowInt16# ((extendInt16# x#) `modInt#` (extendInt16# y#))) + | otherwise = I16# (intToInt16# ((int16ToInt# x#) `modInt#` (int16ToInt# y#))) quotRem x@(I16# x#) y@(I16# y#) | y == 0 = divZeroError -- Note [Order of tests] | y == (-1) && x == minBound = (overflowError, 0) - | otherwise = case (extendInt16# x#) `quotRemInt#` (extendInt16# y#) of + | otherwise = case (int16ToInt# x#) `quotRemInt#` (int16ToInt# y#) of (# q, r #) -> - (I16# (narrowInt16# q), - I16# (narrowInt16# r)) + (I16# (intToInt16# q), + I16# (intToInt16# r)) divMod x@(I16# x#) y@(I16# y#) | y == 0 = divZeroError -- Note [Order of tests] | y == (-1) && x == minBound = (overflowError, 0) - | otherwise = case (extendInt16# x#) `divModInt#` (extendInt16# y#) of + | otherwise = case (int16ToInt# x#) `divModInt#` (int16ToInt# y#) of (# d, m #) -> - (I16# (narrowInt16# d), - I16# (narrowInt16# m)) - toInteger (I16# x#) = IS (extendInt16# x#) + (I16# (intToInt16# d), + I16# (intToInt16# m)) + toInteger (I16# x#) = IS (int16ToInt# x#) -- | @since 2.01 instance Bounded Int16 where @@ -391,34 +391,34 @@ instance Bits Int16 where {-# INLINE testBit #-} {-# INLINE popCount #-} - (I16# x#) .&. (I16# y#) = I16# (narrowInt16# ((extendInt16# x#) `andI#` (extendInt16# y#))) - (I16# x#) .|. (I16# y#) = I16# (narrowInt16# ((extendInt16# x#) `orI#` (extendInt16# y#))) - (I16# x#) `xor` (I16# y#) = I16# (narrowInt16# ((extendInt16# x#) `xorI#` (extendInt16# y#))) - complement (I16# x#) = I16# (narrowInt16# (notI# (extendInt16# x#))) + (I16# x#) .&. (I16# y#) = I16# (intToInt16# ((int16ToInt# x#) `andI#` (int16ToInt# y#))) + (I16# x#) .|. (I16# y#) = I16# (intToInt16# ((int16ToInt# x#) `orI#` (int16ToInt# y#))) + (I16# x#) `xor` (I16# y#) = I16# (intToInt16# ((int16ToInt# x#) `xorI#` (int16ToInt# y#))) + complement (I16# x#) = I16# (intToInt16# (notI# (int16ToInt# x#))) (I16# x#) `shift` (I# i#) - | isTrue# (i# >=# 0#) = I16# (narrowInt16# ((extendInt16# x#) `iShiftL#` i#)) - | otherwise = I16# (narrowInt16# ((extendInt16# x#) `iShiftRA#` negateInt# i#)) + | isTrue# (i# >=# 0#) = I16# (intToInt16# ((int16ToInt# x#) `iShiftL#` i#)) + | otherwise = I16# (intToInt16# ((int16ToInt# x#) `iShiftRA#` negateInt# i#)) (I16# x#) `shiftL` (I# i#) - | isTrue# (i# >=# 0#) = I16# (narrowInt16# ((extendInt16# x#) `iShiftL#` i#)) + | isTrue# (i# >=# 0#) = I16# (intToInt16# ((int16ToInt# x#) `iShiftL#` i#)) | otherwise = overflowError - (I16# x#) `unsafeShiftL` (I# i#) = I16# (narrowInt16# ((extendInt16# x#) `uncheckedIShiftL#` i#)) + (I16# x#) `unsafeShiftL` (I# i#) = I16# (intToInt16# ((int16ToInt# x#) `uncheckedIShiftL#` i#)) (I16# x#) `shiftR` (I# i#) - | isTrue# (i# >=# 0#) = I16# (narrowInt16# ((extendInt16# x#) `iShiftRA#` i#)) + | isTrue# (i# >=# 0#) = I16# (intToInt16# ((int16ToInt# x#) `iShiftRA#` i#)) | otherwise = overflowError - (I16# x#) `unsafeShiftR` (I# i#) = I16# (narrowInt16# ((extendInt16# x#) `uncheckedIShiftRA#` i#)) + (I16# x#) `unsafeShiftR` (I# i#) = I16# (intToInt16# ((int16ToInt# x#) `uncheckedIShiftRA#` i#)) (I16# x#) `rotate` (I# i#) | isTrue# (i'# ==# 0#) = I16# x# | otherwise - = I16# (narrowInt16# (word2Int# ((x'# `uncheckedShiftL#` i'#) `or#` + = I16# (intToInt16# (word2Int# ((x'# `uncheckedShiftL#` i'#) `or#` (x'# `uncheckedShiftRL#` (16# -# i'#))))) where - !x'# = narrow16Word# (int2Word# (extendInt16# x#)) + !x'# = narrow16Word# (int2Word# (int16ToInt# x#)) !i'# = word2Int# (int2Word# i# `and#` 15##) bitSizeMaybe i = Just (finiteBitSize i) bitSize i = finiteBitSize i isSigned _ = True - popCount (I16# x#) = I# (word2Int# (popCnt16# (int2Word# (extendInt16# x#)))) + popCount (I16# x#) = I# (word2Int# (popCnt16# (int2Word# (int16ToInt# x#)))) bit = bitDefault testBit = testBitDefault @@ -427,15 +427,15 @@ instance FiniteBits Int16 where {-# INLINE countLeadingZeros #-} {-# INLINE countTrailingZeros #-} finiteBitSize _ = 16 - countLeadingZeros (I16# x#) = I# (word2Int# (clz16# (int2Word# (extendInt16# x#)))) - countTrailingZeros (I16# x#) = I# (word2Int# (ctz16# (int2Word# (extendInt16# x#)))) + countLeadingZeros (I16# x#) = I# (word2Int# (clz16# (int2Word# (int16ToInt# x#)))) + countTrailingZeros (I16# x#) = I# (word2Int# (ctz16# (int2Word# (int16ToInt# x#)))) {-# RULES -"fromIntegral/Word8->Int16" fromIntegral = \(W8# x#) -> I16# (narrowInt16# (word2Int# (extendWord8# x#))) -"fromIntegral/Int8->Int16" fromIntegral = \(I8# x#) -> I16# (narrowInt16# (extendInt8# x#)) +"fromIntegral/Word8->Int16" fromIntegral = \(W8# x#) -> I16# (intToInt16# (word2Int# (word8ToWord# x#))) +"fromIntegral/Int8->Int16" fromIntegral = \(I8# x#) -> I16# (intToInt16# (int8ToInt# x#)) "fromIntegral/Int16->Int16" fromIntegral = id :: Int16 -> Int16 -"fromIntegral/a->Int16" fromIntegral = \x -> case fromIntegral x of I# x# -> I16# (narrowInt16# x#) -"fromIntegral/Int16->a" fromIntegral = \(I16# x#) -> fromIntegral (I# (extendInt16# x#)) +"fromIntegral/a->Int16" fromIntegral = \x -> case fromIntegral x of I# x# -> I16# (intToInt16# x#) +"fromIntegral/Int16->a" fromIntegral = \(I16# x#) -> fromIntegral (I# (int16ToInt# x#)) #-} {-# RULES @@ -488,8 +488,8 @@ instance Eq Int32 where (/=) = neInt32 eqInt32, neInt32 :: Int32 -> Int32 -> Bool -eqInt32 (I32# x) (I32# y) = isTrue# ((extendInt32# x) ==# (extendInt32# y)) -neInt32 (I32# x) (I32# y) = isTrue# ((extendInt32# x) /=# (extendInt32# y)) +eqInt32 (I32# x) (I32# y) = isTrue# ((int32ToInt# x) ==# (int32ToInt# y)) +neInt32 (I32# x) (I32# y) = isTrue# ((int32ToInt# x) /=# (int32ToInt# y)) {-# INLINE [1] eqInt32 #-} {-# INLINE [1] neInt32 #-} @@ -505,10 +505,10 @@ instance Ord Int32 where {-# INLINE [1] ltInt32 #-} {-# INLINE [1] leInt32 #-} gtInt32, geInt32, ltInt32, leInt32 :: Int32 -> Int32 -> Bool -(I32# x) `gtInt32` (I32# y) = isTrue# ((extendInt32# x) ># (extendInt32# y)) -(I32# x) `geInt32` (I32# y) = isTrue# ((extendInt32# x) >=# (extendInt32# y)) -(I32# x) `ltInt32` (I32# y) = isTrue# ((extendInt32# x) <# (extendInt32# y)) -(I32# x) `leInt32` (I32# y) = isTrue# ((extendInt32# x) <=# (extendInt32# y)) +(I32# x) `gtInt32` (I32# y) = isTrue# ((int32ToInt# x) ># (int32ToInt# y)) +(I32# x) `geInt32` (I32# y) = isTrue# ((int32ToInt# x) >=# (int32ToInt# y)) +(I32# x) `ltInt32` (I32# y) = isTrue# ((int32ToInt# x) <# (int32ToInt# y)) +(I32# x) `leInt32` (I32# y) = isTrue# ((int32ToInt# x) <=# (int32ToInt# y)) -- | @since 2.01 instance Show Int32 where @@ -516,16 +516,16 @@ instance Show Int32 where -- | @since 2.01 instance Num Int32 where - (I32# x#) + (I32# y#) = I32# (narrowInt32# ((extendInt32# x#) +# (extendInt32# y#))) - (I32# x#) - (I32# y#) = I32# (narrowInt32# ((extendInt32# x#) -# (extendInt32# y#))) - (I32# x#) * (I32# y#) = I32# (narrowInt32# ((extendInt32# x#) *# (extendInt32# y#))) - negate (I32# x#) = I32# (narrowInt32# (negateInt# (extendInt32# x#))) + (I32# x#) + (I32# y#) = I32# (intToInt32# ((int32ToInt# x#) +# (int32ToInt# y#))) + (I32# x#) - (I32# y#) = I32# (intToInt32# ((int32ToInt# x#) -# (int32ToInt# y#))) + (I32# x#) * (I32# y#) = I32# (intToInt32# ((int32ToInt# x#) *# (int32ToInt# y#))) + negate (I32# x#) = I32# (intToInt32# (negateInt# (int32ToInt# x#))) abs x | x >= 0 = x | otherwise = negate x signum x | x > 0 = 1 signum 0 = 0 signum _ = -1 - fromInteger i = I32# (narrowInt32# (integerToInt# i)) + fromInteger i = I32# (intToInt32# (integerToInt# i)) -- | @since 2.01 instance Enum Int32 where @@ -536,14 +536,14 @@ instance Enum Int32 where | x /= minBound = x - 1 | otherwise = predError "Int32" #if WORD_SIZE_IN_BITS == 32 - toEnum (I# i#) = I32# (narrowInt32# i#) + toEnum (I# i#) = I32# (intToInt32# i#) #else toEnum i@(I# i#) | i >= fromIntegral (minBound::Int32) && i <= fromIntegral (maxBound::Int32) - = I32# (narrowInt32# i#) + = I32# (intToInt32# i#) | otherwise = toEnumError "Int32" i (minBound::Int32, maxBound::Int32) #endif - fromEnum (I32# x#) = I# (extendInt32# x#) + fromEnum (I32# x#) = I# (int32ToInt# x#) enumFrom = boundedEnumFrom enumFromThen = boundedEnumFromThen @@ -552,42 +552,42 @@ instance Integral Int32 where quot x@(I32# x#) y@(I32# y#) | y == 0 = divZeroError | y == (-1) && x == minBound = overflowError -- Note [Order of tests] - | otherwise = I32# (narrowInt32# ((extendInt32# x#) `quotInt#` (extendInt32# y#))) + | otherwise = I32# (intToInt32# ((int32ToInt# x#) `quotInt#` (int32ToInt# y#))) rem (I32# x#) y@(I32# y#) | y == 0 = divZeroError -- The quotRem CPU instruction fails for minBound `quotRem` -1, -- but minBound `rem` -1 is well-defined (0). We therefore -- special-case it. | y == (-1) = 0 - | otherwise = I32# (narrowInt32# ((extendInt32# x#) `remInt#` (extendInt32# y#))) + | otherwise = I32# (intToInt32# ((int32ToInt# x#) `remInt#` (int32ToInt# y#))) div x@(I32# x#) y@(I32# y#) | y == 0 = divZeroError | y == (-1) && x == minBound = overflowError -- Note [Order of tests] - | otherwise = I32# (narrowInt32# ((extendInt32# x#) `divInt#` (extendInt32# y#))) + | otherwise = I32# (intToInt32# ((int32ToInt# x#) `divInt#` (int32ToInt# y#))) mod (I32# x#) y@(I32# y#) | y == 0 = divZeroError -- The divMod CPU instruction fails for minBound `divMod` -1, -- but minBound `mod` -1 is well-defined (0). We therefore -- special-case it. | y == (-1) = 0 - | otherwise = I32# (narrowInt32# ((extendInt32# x#) `modInt#` (extendInt32# y#))) + | otherwise = I32# (intToInt32# ((int32ToInt# x#) `modInt#` (int32ToInt# y#))) quotRem x@(I32# x#) y@(I32# y#) | y == 0 = divZeroError -- Note [Order of tests] | y == (-1) && x == minBound = (overflowError, 0) - | otherwise = case (extendInt32# x#) `quotRemInt#` (extendInt32# y#) of + | otherwise = case (int32ToInt# x#) `quotRemInt#` (int32ToInt# y#) of (# q, r #) -> - (I32# (narrowInt32# q), - I32# (narrowInt32# r)) + (I32# (intToInt32# q), + I32# (intToInt32# r)) divMod x@(I32# x#) y@(I32# y#) | y == 0 = divZeroError -- Note [Order of tests] | y == (-1) && x == minBound = (overflowError, 0) - | otherwise = case (extendInt32# x#) `divModInt#` (extendInt32# y#) of + | otherwise = case (int32ToInt# x#) `divModInt#` (int32ToInt# y#) of (# d, m #) -> - (I32# (narrowInt32# d), - I32# (narrowInt32# m)) - toInteger (I32# x#) = IS (extendInt32# x#) + (I32# (intToInt32# d), + I32# (intToInt32# m)) + toInteger (I32# x#) = IS (int32ToInt# x#) -- | @since 2.01 instance Read Int32 where @@ -600,35 +600,35 @@ instance Bits Int32 where {-# INLINE testBit #-} {-# INLINE popCount #-} - (I32# x#) .&. (I32# y#) = I32# (narrowInt32# ((extendInt32# x#) `andI#` (extendInt32# y#))) - (I32# x#) .|. (I32# y#) = I32# (narrowInt32# ((extendInt32# x#) `orI#` (extendInt32# y#))) - (I32# x#) `xor` (I32# y#) = I32# (narrowInt32# ((extendInt32# x#) `xorI#` (extendInt32# y#))) - complement (I32# x#) = I32# (narrowInt32# (notI# (extendInt32# x#))) + (I32# x#) .&. (I32# y#) = I32# (intToInt32# ((int32ToInt# x#) `andI#` (int32ToInt# y#))) + (I32# x#) .|. (I32# y#) = I32# (intToInt32# ((int32ToInt# x#) `orI#` (int32ToInt# y#))) + (I32# x#) `xor` (I32# y#) = I32# (intToInt32# ((int32ToInt# x#) `xorI#` (int32ToInt# y#))) + complement (I32# x#) = I32# (intToInt32# (notI# (int32ToInt# x#))) (I32# x#) `shift` (I# i#) - | isTrue# (i# >=# 0#) = I32# (narrowInt32# ((extendInt32# x#) `iShiftL#` i#)) - | otherwise = I32# (narrowInt32# ((extendInt32# x#) `iShiftRA#` negateInt# i#)) + | isTrue# (i# >=# 0#) = I32# (intToInt32# ((int32ToInt# x#) `iShiftL#` i#)) + | otherwise = I32# (intToInt32# ((int32ToInt# x#) `iShiftRA#` negateInt# i#)) (I32# x#) `shiftL` (I# i#) - | isTrue# (i# >=# 0#) = I32# (narrowInt32# ((extendInt32# x#) `iShiftL#` i#)) + | isTrue# (i# >=# 0#) = I32# (intToInt32# ((int32ToInt# x#) `iShiftL#` i#)) | otherwise = overflowError (I32# x#) `unsafeShiftL` (I# i#) = - I32# (narrowInt32# ((extendInt32# x#) `uncheckedIShiftL#` i#)) + I32# (intToInt32# ((int32ToInt# x#) `uncheckedIShiftL#` i#)) (I32# x#) `shiftR` (I# i#) - | isTrue# (i# >=# 0#) = I32# (narrowInt32# ((extendInt32# x#) `iShiftRA#` i#)) + | isTrue# (i# >=# 0#) = I32# (intToInt32# ((int32ToInt# x#) `iShiftRA#` i#)) | otherwise = overflowError - (I32# x#) `unsafeShiftR` (I# i#) = I32# (narrowInt32# ((extendInt32# x#) `uncheckedIShiftRA#` i#)) + (I32# x#) `unsafeShiftR` (I# i#) = I32# (intToInt32# ((int32ToInt# x#) `uncheckedIShiftRA#` i#)) (I32# x#) `rotate` (I# i#) | isTrue# (i'# ==# 0#) = I32# x# | otherwise - = I32# (narrowInt32# (word2Int# ((x'# `uncheckedShiftL#` i'#) `or#` + = I32# (intToInt32# (word2Int# ((x'# `uncheckedShiftL#` i'#) `or#` (x'# `uncheckedShiftRL#` (32# -# i'#))))) where - !x'# = narrow32Word# (int2Word# (extendInt32# x#)) + !x'# = narrow32Word# (int2Word# (int32ToInt# x#)) !i'# = word2Int# (int2Word# i# `and#` 31##) bitSizeMaybe i = Just (finiteBitSize i) bitSize i = finiteBitSize i isSigned _ = True - popCount (I32# x#) = I# (word2Int# (popCnt32# (int2Word# (extendInt32# x#)))) + popCount (I32# x#) = I# (word2Int# (popCnt32# (int2Word# (int32ToInt# x#)))) bit = bitDefault testBit = testBitDefault @@ -637,17 +637,17 @@ instance FiniteBits Int32 where {-# INLINE countLeadingZeros #-} {-# INLINE countTrailingZeros #-} finiteBitSize _ = 32 - countLeadingZeros (I32# x#) = I# (word2Int# (clz32# (int2Word# (extendInt32# x#)))) - countTrailingZeros (I32# x#) = I# (word2Int# (ctz32# (int2Word# (extendInt32# x#)))) + countLeadingZeros (I32# x#) = I# (word2Int# (clz32# (int2Word# (int32ToInt# x#)))) + countTrailingZeros (I32# x#) = I# (word2Int# (ctz32# (int2Word# (int32ToInt# x#)))) {-# RULES -"fromIntegral/Word8->Int32" fromIntegral = \(W8# x#) -> I32# (narrowInt32# (word2Int# (extendWord8# x#))) -"fromIntegral/Word16->Int32" fromIntegral = \(W16# x#) -> I32# (narrowInt32# (word2Int# (extendWord16# x#))) -"fromIntegral/Int8->Int32" fromIntegral = \(I8# x#) -> I32# (narrowInt32# (extendInt8# x#)) -"fromIntegral/Int16->Int32" fromIntegral = \(I16# x#) -> I32# (narrowInt32# (extendInt16# x#)) +"fromIntegral/Word8->Int32" fromIntegral = \(W8# x#) -> I32# (intToInt32# (word2Int# (word8ToWord# x#))) +"fromIntegral/Word16->Int32" fromIntegral = \(W16# x#) -> I32# (intToInt32# (word2Int# (word16ToWord# x#))) +"fromIntegral/Int8->Int32" fromIntegral = \(I8# x#) -> I32# (intToInt32# (int8ToInt# x#)) +"fromIntegral/Int16->Int32" fromIntegral = \(I16# x#) -> I32# (intToInt32# (int16ToInt# x#)) "fromIntegral/Int32->Int32" fromIntegral = id :: Int32 -> Int32 -"fromIntegral/a->Int32" fromIntegral = \x -> case fromIntegral x of I# x# -> I32# (narrowInt32# x#) -"fromIntegral/Int32->a" fromIntegral = \(I32# x#) -> fromIntegral (I# (extendInt32# x#)) +"fromIntegral/a->Int32" fromIntegral = \x -> case fromIntegral x of I# x# -> I32# (intToInt32# x#) +"fromIntegral/Int32->a" fromIntegral = \(I32# x#) -> fromIntegral (I# (int32ToInt# x#)) #-} {-# RULES diff --git a/libraries/base/GHC/Storable.hs b/libraries/base/GHC/Storable.hs index 359c136b2b..d9b9382211 100644 --- a/libraries/base/GHC/Storable.hs +++ b/libraries/base/GHC/Storable.hs @@ -91,17 +91,17 @@ readDoubleOffPtr (Ptr a) (I# i) readStablePtrOffPtr (Ptr a) (I# i) = IO $ \s -> case readStablePtrOffAddr# a i s of (# s2, x #) -> (# s2, StablePtr x #) readInt8OffPtr (Ptr a) (I# i) - = IO $ \s -> case readInt8OffAddr# a i s of (# s2, x #) -> (# s2, I8# (narrowInt8# x) #) + = IO $ \s -> case readInt8OffAddr# a i s of (# s2, x #) -> (# s2, I8# x #) readWord8OffPtr (Ptr a) (I# i) - = IO $ \s -> case readWord8OffAddr# a i s of (# s2, x #) -> (# s2, W8# (narrowWord8# x) #) + = IO $ \s -> case readWord8OffAddr# a i s of (# s2, x #) -> (# s2, W8# x #) readInt16OffPtr (Ptr a) (I# i) - = IO $ \s -> case readInt16OffAddr# a i s of (# s2, x #) -> (# s2, I16# (narrowInt16# x) #) + = IO $ \s -> case readInt16OffAddr# a i s of (# s2, x #) -> (# s2, I16# x #) readWord16OffPtr (Ptr a) (I# i) - = IO $ \s -> case readWord16OffAddr# a i s of (# s2, x #) -> (# s2, W16# (narrowWord16# x) #) + = IO $ \s -> case readWord16OffAddr# a i s of (# s2, x #) -> (# s2, W16# x #) readInt32OffPtr (Ptr a) (I# i) - = IO $ \s -> case readInt32OffAddr# a i s of (# s2, x #) -> (# s2, I32# (narrowInt32# x) #) + = IO $ \s -> case readInt32OffAddr# a i s of (# s2, x #) -> (# s2, I32# x #) readWord32OffPtr (Ptr a) (I# i) - = IO $ \s -> case readWord32OffAddr# a i s of (# s2, x #) -> (# s2, W32# (narrowWord32# x) #) + = IO $ \s -> case readWord32OffAddr# a i s of (# s2, x #) -> (# s2, W32# x #) readInt64OffPtr (Ptr a) (I# i) = IO $ \s -> case readInt64OffAddr# a i s of (# s2, x #) -> (# s2, I64# x #) readWord64OffPtr (Ptr a) (I# i) @@ -141,17 +141,17 @@ writeDoubleOffPtr (Ptr a) (I# i) (D# x) writeStablePtrOffPtr (Ptr a) (I# i) (StablePtr x) = IO $ \s -> case writeStablePtrOffAddr# a i x s of s2 -> (# s2 , () #) writeInt8OffPtr (Ptr a) (I# i) (I8# x) - = IO $ \s -> case writeInt8OffAddr# a i (extendInt8# x) s of s2 -> (# s2, () #) + = IO $ \s -> case writeInt8OffAddr# a i x s of s2 -> (# s2, () #) writeWord8OffPtr (Ptr a) (I# i) (W8# x) - = IO $ \s -> case writeWord8OffAddr# a i (extendWord8# x) s of s2 -> (# s2, () #) + = IO $ \s -> case writeWord8OffAddr# a i x s of s2 -> (# s2, () #) writeInt16OffPtr (Ptr a) (I# i) (I16# x) - = IO $ \s -> case writeInt16OffAddr# a i (extendInt16# x) s of s2 -> (# s2, () #) + = IO $ \s -> case writeInt16OffAddr# a i x s of s2 -> (# s2, () #) writeWord16OffPtr (Ptr a) (I# i) (W16# x) - = IO $ \s -> case writeWord16OffAddr# a i (extendWord16# x) s of s2 -> (# s2, () #) + = IO $ \s -> case writeWord16OffAddr# a i x s of s2 -> (# s2, () #) writeInt32OffPtr (Ptr a) (I# i) (I32# x) - = IO $ \s -> case writeInt32OffAddr# a i (extendInt32# x) s of s2 -> (# s2, () #) + = IO $ \s -> case writeInt32OffAddr# a i x s of s2 -> (# s2, () #) writeWord32OffPtr (Ptr a) (I# i) (W32# x) - = IO $ \s -> case writeWord32OffAddr# a i (extendWord32# x) s of s2 -> (# s2, () #) + = IO $ \s -> case writeWord32OffAddr# a i x s of s2 -> (# s2, () #) writeInt64OffPtr (Ptr a) (I# i) (I64# x) = IO $ \s -> case writeInt64OffAddr# a i x s of s2 -> (# s2, () #) writeWord64OffPtr (Ptr a) (I# i) (W64# x) diff --git a/libraries/base/GHC/Word.hs b/libraries/base/GHC/Word.hs index 02dcdfcd1a..77d63cc9d7 100644 --- a/libraries/base/GHC/Word.hs +++ b/libraries/base/GHC/Word.hs @@ -80,8 +80,8 @@ instance Eq Word8 where (/=) = neWord8 eqWord8, neWord8 :: Word8 -> Word8 -> Bool -eqWord8 (W8# x) (W8# y) = isTrue# ((extendWord8# x) `eqWord#` (extendWord8# y)) -neWord8 (W8# x) (W8# y) = isTrue# ((extendWord8# x) `neWord#` (extendWord8# y)) +eqWord8 (W8# x) (W8# y) = isTrue# ((word8ToWord# x) `eqWord#` (word8ToWord# y)) +neWord8 (W8# x) (W8# y) = isTrue# ((word8ToWord# x) `neWord#` (word8ToWord# y)) {-# INLINE [1] eqWord8 #-} {-# INLINE [1] neWord8 #-} @@ -97,10 +97,10 @@ instance Ord Word8 where {-# INLINE [1] ltWord8 #-} {-# INLINE [1] leWord8 #-} gtWord8, geWord8, ltWord8, leWord8 :: Word8 -> Word8 -> Bool -(W8# x) `gtWord8` (W8# y) = isTrue# ((extendWord8# x) `gtWord#` (extendWord8# y)) -(W8# x) `geWord8` (W8# y) = isTrue# ((extendWord8# x) `geWord#` (extendWord8# y)) -(W8# x) `ltWord8` (W8# y) = isTrue# ((extendWord8# x) `ltWord#` (extendWord8# y)) -(W8# x) `leWord8` (W8# y) = isTrue# ((extendWord8# x) `leWord#` (extendWord8# y)) +(W8# x) `gtWord8` (W8# y) = isTrue# ((word8ToWord# x) `gtWord#` (word8ToWord# y)) +(W8# x) `geWord8` (W8# y) = isTrue# ((word8ToWord# x) `geWord#` (word8ToWord# y)) +(W8# x) `ltWord8` (W8# y) = isTrue# ((word8ToWord# x) `ltWord#` (word8ToWord# y)) +(W8# x) `leWord8` (W8# y) = isTrue# ((word8ToWord# x) `leWord#` (word8ToWord# y)) -- | @since 2.01 instance Show Word8 where @@ -108,14 +108,14 @@ instance Show Word8 where -- | @since 2.01 instance Num Word8 where - (W8# x#) + (W8# y#) = W8# (narrowWord8# ((extendWord8# x#) `plusWord#` (extendWord8# y#))) - (W8# x#) - (W8# y#) = W8# (narrowWord8# ((extendWord8# x#) `minusWord#` (extendWord8# y#))) - (W8# x#) * (W8# y#) = W8# (narrowWord8# ((extendWord8# x#) `timesWord#` (extendWord8# y#))) - negate (W8# x#) = W8# (narrowWord8# (int2Word# (negateInt# (word2Int# ((extendWord8# x#)))))) + (W8# x#) + (W8# y#) = W8# (wordToWord8# ((word8ToWord# x#) `plusWord#` (word8ToWord# y#))) + (W8# x#) - (W8# y#) = W8# (wordToWord8# ((word8ToWord# x#) `minusWord#` (word8ToWord# y#))) + (W8# x#) * (W8# y#) = W8# (wordToWord8# ((word8ToWord# x#) `timesWord#` (word8ToWord# y#))) + negate (W8# x#) = W8# (wordToWord8# (int2Word# (negateInt# (word2Int# ((word8ToWord# x#)))))) abs x = x signum 0 = 0 signum _ = 1 - fromInteger i = W8# (narrowWord8# (integerToWord# i)) + fromInteger i = W8# (wordToWord8# (integerToWord# i)) -- | @since 2.01 instance Real Word8 where @@ -131,36 +131,36 @@ instance Enum Word8 where | otherwise = predError "Word8" toEnum i@(I# i#) | i >= 0 && i <= fromIntegral (maxBound::Word8) - = W8# (narrowWord8# (int2Word# i#)) + = W8# (wordToWord8# (int2Word# i#)) | otherwise = toEnumError "Word8" i (minBound::Word8, maxBound::Word8) - fromEnum (W8# x#) = I# (word2Int# (extendWord8# x#)) + fromEnum (W8# x#) = I# (word2Int# (word8ToWord# x#)) enumFrom = boundedEnumFrom enumFromThen = boundedEnumFromThen -- | @since 2.01 instance Integral Word8 where quot (W8# x#) y@(W8# y#) - | y /= 0 = W8# (narrowWord8# ((extendWord8# x#) `quotWord#` (extendWord8# y#))) + | y /= 0 = W8# (wordToWord8# ((word8ToWord# x#) `quotWord#` (word8ToWord# y#))) | otherwise = divZeroError rem (W8# x#) y@(W8# y#) - | y /= 0 = W8# (narrowWord8# ((extendWord8# x#) `remWord#` (extendWord8# y#))) + | y /= 0 = W8# (wordToWord8# ((word8ToWord# x#) `remWord#` (word8ToWord# y#))) | otherwise = divZeroError div (W8# x#) y@(W8# y#) - | y /= 0 = W8# (narrowWord8# ((extendWord8# x#) `quotWord#` (extendWord8# y#))) + | y /= 0 = W8# (wordToWord8# ((word8ToWord# x#) `quotWord#` (word8ToWord# y#))) | otherwise = divZeroError mod (W8# x#) y@(W8# y#) - | y /= 0 = W8# (narrowWord8# ((extendWord8# x#) `remWord#` (extendWord8# y#))) + | y /= 0 = W8# (wordToWord8# ((word8ToWord# x#) `remWord#` (word8ToWord# y#))) | otherwise = divZeroError quotRem (W8# x#) y@(W8# y#) - | y /= 0 = case (extendWord8# x#) `quotRemWord#` (extendWord8# y#) of + | y /= 0 = case (word8ToWord# x#) `quotRemWord#` (word8ToWord# y#) of (# q, r #) -> - (W8# (narrowWord8# q), W8# (narrowWord8# r)) + (W8# (wordToWord8# q), W8# (wordToWord8# r)) | otherwise = divZeroError divMod (W8# x#) y@(W8# y#) - | y /= 0 = (W8# (narrowWord8# ((extendWord8# x#) `quotWord#` (extendWord8# y#))) - ,W8# (narrowWord8# ((extendWord8# x#) `remWord#` (extendWord8# y#)))) + | y /= 0 = (W8# (wordToWord8# ((word8ToWord# x#) `quotWord#` (word8ToWord# y#))) + ,W8# (wordToWord8# ((word8ToWord# x#) `remWord#` (word8ToWord# y#)))) | otherwise = divZeroError - toInteger (W8# x#) = IS (word2Int# (extendWord8# x#)) + toInteger (W8# x#) = IS (word2Int# (word8ToWord# x#)) -- | @since 2.01 instance Bounded Word8 where @@ -180,32 +180,32 @@ instance Bits Word8 where {-# INLINE testBit #-} {-# INLINE popCount #-} - (W8# x#) .&. (W8# y#) = W8# (narrowWord8# ((extendWord8# x#) `and#` (extendWord8# y#))) - (W8# x#) .|. (W8# y#) = W8# (narrowWord8# ((extendWord8# x#) `or#` (extendWord8# y#))) - (W8# x#) `xor` (W8# y#) = W8# (narrowWord8# ((extendWord8# x#) `xor#` (extendWord8# y#))) - complement (W8# x#) = W8# (narrowWord8# (not# (extendWord8# x#))) + (W8# x#) .&. (W8# y#) = W8# (wordToWord8# ((word8ToWord# x#) `and#` (word8ToWord# y#))) + (W8# x#) .|. (W8# y#) = W8# (wordToWord8# ((word8ToWord# x#) `or#` (word8ToWord# y#))) + (W8# x#) `xor` (W8# y#) = W8# (wordToWord8# ((word8ToWord# x#) `xor#` (word8ToWord# y#))) + complement (W8# x#) = W8# (wordToWord8# (not# (word8ToWord# x#))) (W8# x#) `shift` (I# i#) - | isTrue# (i# >=# 0#) = W8# (narrowWord8# ((extendWord8# x#) `shiftL#` i#)) - | otherwise = W8# (narrowWord8# ((extendWord8# x#) `shiftRL#` negateInt# i#)) + | isTrue# (i# >=# 0#) = W8# (wordToWord8# ((word8ToWord# x#) `shiftL#` i#)) + | otherwise = W8# (wordToWord8# ((word8ToWord# x#) `shiftRL#` negateInt# i#)) (W8# x#) `shiftL` (I# i#) - | isTrue# (i# >=# 0#) = W8# (narrowWord8# ((extendWord8# x#) `shiftL#` i#)) + | isTrue# (i# >=# 0#) = W8# (wordToWord8# ((word8ToWord# x#) `shiftL#` i#)) | otherwise = overflowError (W8# x#) `unsafeShiftL` (I# i#) = - W8# (narrowWord8# ((extendWord8# x#) `uncheckedShiftL#` i#)) + W8# (wordToWord8# ((word8ToWord# x#) `uncheckedShiftL#` i#)) (W8# x#) `shiftR` (I# i#) - | isTrue# (i# >=# 0#) = W8# (narrowWord8# ((extendWord8# x#) `shiftRL#` i#)) + | isTrue# (i# >=# 0#) = W8# (wordToWord8# ((word8ToWord# x#) `shiftRL#` i#)) | otherwise = overflowError - (W8# x#) `unsafeShiftR` (I# i#) = W8# (narrowWord8# ((extendWord8# x#) `uncheckedShiftRL#` i#)) + (W8# x#) `unsafeShiftR` (I# i#) = W8# (wordToWord8# ((word8ToWord# x#) `uncheckedShiftRL#` i#)) (W8# x#) `rotate` (I# i#) | isTrue# (i'# ==# 0#) = W8# x# - | otherwise = W8# (narrowWord8# (((extendWord8# x#) `uncheckedShiftL#` i'#) `or#` - ((extendWord8# x#) `uncheckedShiftRL#` (8# -# i'#)))) + | otherwise = W8# (wordToWord8# (((word8ToWord# x#) `uncheckedShiftL#` i'#) `or#` + ((word8ToWord# x#) `uncheckedShiftRL#` (8# -# i'#)))) where !i'# = word2Int# (int2Word# i# `and#` 7##) bitSizeMaybe i = Just (finiteBitSize i) bitSize i = finiteBitSize i isSigned _ = False - popCount (W8# x#) = I# (word2Int# (popCnt8# (extendWord8# x#))) + popCount (W8# x#) = I# (word2Int# (popCnt8# (word8ToWord# x#))) bit = bitDefault testBit = testBitDefault @@ -214,14 +214,14 @@ instance FiniteBits Word8 where {-# INLINE countLeadingZeros #-} {-# INLINE countTrailingZeros #-} finiteBitSize _ = 8 - countLeadingZeros (W8# x#) = I# (word2Int# (clz8# (extendWord8# x#))) - countTrailingZeros (W8# x#) = I# (word2Int# (ctz8# (extendWord8# x#))) + countLeadingZeros (W8# x#) = I# (word2Int# (clz8# (word8ToWord# x#))) + countTrailingZeros (W8# x#) = I# (word2Int# (ctz8# (word8ToWord# x#))) {-# RULES "fromIntegral/Word8->Word8" fromIntegral = id :: Word8 -> Word8 "fromIntegral/Word8->Integer" fromIntegral = toInteger :: Word8 -> Integer -"fromIntegral/a->Word8" fromIntegral = \x -> case fromIntegral x of W# x# -> W8# (narrowWord8# x#) -"fromIntegral/Word8->a" fromIntegral = \(W8# x#) -> fromIntegral (W# (extendWord8# x#)) +"fromIntegral/a->Word8" fromIntegral = \x -> case fromIntegral x of W# x# -> W8# (wordToWord8# x#) +"fromIntegral/Word8->a" fromIntegral = \(W8# x#) -> fromIntegral (W# (word8ToWord# x#)) #-} {-# RULES @@ -271,8 +271,8 @@ instance Eq Word16 where (/=) = neWord16 eqWord16, neWord16 :: Word16 -> Word16 -> Bool -eqWord16 (W16# x) (W16# y) = isTrue# ((extendWord16# x) `eqWord#` (extendWord16# y)) -neWord16 (W16# x) (W16# y) = isTrue# ((extendWord16# x) `neWord#` (extendWord16# y)) +eqWord16 (W16# x) (W16# y) = isTrue# ((word16ToWord# x) `eqWord#` (word16ToWord# y)) +neWord16 (W16# x) (W16# y) = isTrue# ((word16ToWord# x) `neWord#` (word16ToWord# y)) {-# INLINE [1] eqWord16 #-} {-# INLINE [1] neWord16 #-} @@ -288,10 +288,10 @@ instance Ord Word16 where {-# INLINE [1] ltWord16 #-} {-# INLINE [1] leWord16 #-} gtWord16, geWord16, ltWord16, leWord16 :: Word16 -> Word16 -> Bool -(W16# x) `gtWord16` (W16# y) = isTrue# ((extendWord16# x) `gtWord#` (extendWord16# y)) -(W16# x) `geWord16` (W16# y) = isTrue# ((extendWord16# x) `geWord#` (extendWord16# y)) -(W16# x) `ltWord16` (W16# y) = isTrue# ((extendWord16# x) `ltWord#` (extendWord16# y)) -(W16# x) `leWord16` (W16# y) = isTrue# ((extendWord16# x) `leWord#` (extendWord16# y)) +(W16# x) `gtWord16` (W16# y) = isTrue# ((word16ToWord# x) `gtWord#` (word16ToWord# y)) +(W16# x) `geWord16` (W16# y) = isTrue# ((word16ToWord# x) `geWord#` (word16ToWord# y)) +(W16# x) `ltWord16` (W16# y) = isTrue# ((word16ToWord# x) `ltWord#` (word16ToWord# y)) +(W16# x) `leWord16` (W16# y) = isTrue# ((word16ToWord# x) `leWord#` (word16ToWord# y)) -- | @since 2.01 instance Show Word16 where @@ -299,14 +299,14 @@ instance Show Word16 where -- | @since 2.01 instance Num Word16 where - (W16# x#) + (W16# y#) = W16# (narrowWord16# ((extendWord16# x#) `plusWord#` (extendWord16# y#))) - (W16# x#) - (W16# y#) = W16# (narrowWord16# ((extendWord16# x#) `minusWord#` (extendWord16# y#))) - (W16# x#) * (W16# y#) = W16# (narrowWord16# ((extendWord16# x#) `timesWord#` (extendWord16# y#))) - negate (W16# x#) = W16# (narrowWord16# (int2Word# (negateInt# (word2Int# (extendWord16# x#))))) + (W16# x#) + (W16# y#) = W16# (wordToWord16# ((word16ToWord# x#) `plusWord#` (word16ToWord# y#))) + (W16# x#) - (W16# y#) = W16# (wordToWord16# ((word16ToWord# x#) `minusWord#` (word16ToWord# y#))) + (W16# x#) * (W16# y#) = W16# (wordToWord16# ((word16ToWord# x#) `timesWord#` (word16ToWord# y#))) + negate (W16# x#) = W16# (wordToWord16# (int2Word# (negateInt# (word2Int# (word16ToWord# x#))))) abs x = x signum 0 = 0 signum _ = 1 - fromInteger i = W16# (narrowWord16# (integerToWord# i)) + fromInteger i = W16# (wordToWord16# (integerToWord# i)) -- | @since 2.01 instance Real Word16 where @@ -322,36 +322,36 @@ instance Enum Word16 where | otherwise = predError "Word16" toEnum i@(I# i#) | i >= 0 && i <= fromIntegral (maxBound::Word16) - = W16# (narrowWord16# (int2Word# i#)) + = W16# (wordToWord16# (int2Word# i#)) | otherwise = toEnumError "Word16" i (minBound::Word16, maxBound::Word16) - fromEnum (W16# x#) = I# (word2Int# (extendWord16# x#)) + fromEnum (W16# x#) = I# (word2Int# (word16ToWord# x#)) enumFrom = boundedEnumFrom enumFromThen = boundedEnumFromThen -- | @since 2.01 instance Integral Word16 where quot (W16# x#) y@(W16# y#) - | y /= 0 = W16# (narrowWord16# ((extendWord16# x#) `quotWord#` (extendWord16# y#))) + | y /= 0 = W16# (wordToWord16# ((word16ToWord# x#) `quotWord#` (word16ToWord# y#))) | otherwise = divZeroError rem (W16# x#) y@(W16# y#) - | y /= 0 = W16# (narrowWord16# ((extendWord16# x#) `remWord#` (extendWord16# y#))) + | y /= 0 = W16# (wordToWord16# ((word16ToWord# x#) `remWord#` (word16ToWord# y#))) | otherwise = divZeroError div (W16# x#) y@(W16# y#) - | y /= 0 = W16# (narrowWord16# ((extendWord16# x#) `quotWord#` (extendWord16# y#))) + | y /= 0 = W16# (wordToWord16# ((word16ToWord# x#) `quotWord#` (word16ToWord# y#))) | otherwise = divZeroError mod (W16# x#) y@(W16# y#) - | y /= 0 = W16# (narrowWord16# ((extendWord16# x#) `remWord#` (extendWord16# y#))) + | y /= 0 = W16# (wordToWord16# ((word16ToWord# x#) `remWord#` (word16ToWord# y#))) | otherwise = divZeroError quotRem (W16# x#) y@(W16# y#) - | y /= 0 = case (extendWord16# x#) `quotRemWord#` (extendWord16# y#) of + | y /= 0 = case (word16ToWord# x#) `quotRemWord#` (word16ToWord# y#) of (# q, r #) -> - (W16# (narrowWord16# q), W16# (narrowWord16# r)) + (W16# (wordToWord16# q), W16# (wordToWord16# r)) | otherwise = divZeroError divMod (W16# x#) y@(W16# y#) - | y /= 0 = (W16# (narrowWord16# ((extendWord16# x#) `quotWord#` (extendWord16# y#))) - ,W16# (narrowWord16# ((extendWord16# x#) `remWord#` (extendWord16# y#)))) + | y /= 0 = (W16# (wordToWord16# ((word16ToWord# x#) `quotWord#` (word16ToWord# y#))) + ,W16# (wordToWord16# ((word16ToWord# x#) `remWord#` (word16ToWord# y#)))) | otherwise = divZeroError - toInteger (W16# x#) = IS (word2Int# (extendWord16# x#)) + toInteger (W16# x#) = IS (word2Int# (word16ToWord# x#)) -- | @since 2.01 instance Bounded Word16 where @@ -371,32 +371,32 @@ instance Bits Word16 where {-# INLINE testBit #-} {-# INLINE popCount #-} - (W16# x#) .&. (W16# y#) = W16# (narrowWord16# ((extendWord16# x#) `and#` (extendWord16# y#))) - (W16# x#) .|. (W16# y#) = W16# (narrowWord16# ((extendWord16# x#) `or#` (extendWord16# y#))) - (W16# x#) `xor` (W16# y#) = W16# (narrowWord16# ((extendWord16# x#) `xor#` (extendWord16# y#))) - complement (W16# x#) = W16# (narrowWord16# (not# (extendWord16# x#))) + (W16# x#) .&. (W16# y#) = W16# (wordToWord16# ((word16ToWord# x#) `and#` (word16ToWord# y#))) + (W16# x#) .|. (W16# y#) = W16# (wordToWord16# ((word16ToWord# x#) `or#` (word16ToWord# y#))) + (W16# x#) `xor` (W16# y#) = W16# (wordToWord16# ((word16ToWord# x#) `xor#` (word16ToWord# y#))) + complement (W16# x#) = W16# (wordToWord16# (not# (word16ToWord# x#))) (W16# x#) `shift` (I# i#) - | isTrue# (i# >=# 0#) = W16# (narrowWord16# ((extendWord16# x#) `shiftL#` i#)) - | otherwise = W16# (narrowWord16# ((extendWord16# x#) `shiftRL#` negateInt# i#)) + | isTrue# (i# >=# 0#) = W16# (wordToWord16# ((word16ToWord# x#) `shiftL#` i#)) + | otherwise = W16# (wordToWord16# ((word16ToWord# x#) `shiftRL#` negateInt# i#)) (W16# x#) `shiftL` (I# i#) - | isTrue# (i# >=# 0#) = W16# (narrowWord16# ((extendWord16# x#) `shiftL#` i#)) + | isTrue# (i# >=# 0#) = W16# (wordToWord16# ((word16ToWord# x#) `shiftL#` i#)) | otherwise = overflowError (W16# x#) `unsafeShiftL` (I# i#) = - W16# (narrowWord16# ((extendWord16# x#) `uncheckedShiftL#` i#)) + W16# (wordToWord16# ((word16ToWord# x#) `uncheckedShiftL#` i#)) (W16# x#) `shiftR` (I# i#) - | isTrue# (i# >=# 0#) = W16# (narrowWord16# ((extendWord16# x#) `shiftRL#` i#)) + | isTrue# (i# >=# 0#) = W16# (wordToWord16# ((word16ToWord# x#) `shiftRL#` i#)) | otherwise = overflowError - (W16# x#) `unsafeShiftR` (I# i#) = W16# (narrowWord16# ((extendWord16# x#) `uncheckedShiftRL#` i#)) + (W16# x#) `unsafeShiftR` (I# i#) = W16# (wordToWord16# ((word16ToWord# x#) `uncheckedShiftRL#` i#)) (W16# x#) `rotate` (I# i#) | isTrue# (i'# ==# 0#) = W16# x# - | otherwise = W16# (narrowWord16# (((extendWord16# x#) `uncheckedShiftL#` i'#) `or#` - ((extendWord16# x#) `uncheckedShiftRL#` (16# -# i'#)))) + | otherwise = W16# (wordToWord16# (((word16ToWord# x#) `uncheckedShiftL#` i'#) `or#` + ((word16ToWord# x#) `uncheckedShiftRL#` (16# -# i'#)))) where !i'# = word2Int# (int2Word# i# `and#` 15##) bitSizeMaybe i = Just (finiteBitSize i) bitSize i = finiteBitSize i isSigned _ = False - popCount (W16# x#) = I# (word2Int# (popCnt16# (extendWord16# x#))) + popCount (W16# x#) = I# (word2Int# (popCnt16# (word16ToWord# x#))) bit = bitDefault testBit = testBitDefault @@ -405,21 +405,21 @@ instance FiniteBits Word16 where {-# INLINE countLeadingZeros #-} {-# INLINE countTrailingZeros #-} finiteBitSize _ = 16 - countLeadingZeros (W16# x#) = I# (word2Int# (clz16# (extendWord16# x#))) - countTrailingZeros (W16# x#) = I# (word2Int# (ctz16# (extendWord16# x#))) + countLeadingZeros (W16# x#) = I# (word2Int# (clz16# (word16ToWord# x#))) + countTrailingZeros (W16# x#) = I# (word2Int# (ctz16# (word16ToWord# x#))) -- | Reverse order of bytes in 'Word16'. -- -- @since 4.7.0.0 byteSwap16 :: Word16 -> Word16 -byteSwap16 (W16# w#) = W16# (narrowWord16# (byteSwap16# (extendWord16# w#))) +byteSwap16 (W16# w#) = W16# (wordToWord16# (byteSwap16# (word16ToWord# w#))) {-# RULES -"fromIntegral/Word8->Word16" fromIntegral = \(W8# x#) -> W16# (narrowWord16# (extendWord8# x#)) +"fromIntegral/Word8->Word16" fromIntegral = \(W8# x#) -> W16# (wordToWord16# (word8ToWord# x#)) "fromIntegral/Word16->Word16" fromIntegral = id :: Word16 -> Word16 "fromIntegral/Word16->Integer" fromIntegral = toInteger :: Word16 -> Integer -"fromIntegral/a->Word16" fromIntegral = \x -> case fromIntegral x of W# x# -> W16# (narrowWord16# x#) -"fromIntegral/Word16->a" fromIntegral = \(W16# x#) -> fromIntegral (W# (extendWord16# x#)) +"fromIntegral/a->Word16" fromIntegral = \x -> case fromIntegral x of W# x# -> W16# (wordToWord16# x#) +"fromIntegral/Word16->a" fromIntegral = \(W16# x#) -> fromIntegral (W# (word16ToWord# x#)) #-} {-# RULES @@ -505,8 +505,8 @@ instance Eq Word32 where (/=) = neWord32 eqWord32, neWord32 :: Word32 -> Word32 -> Bool -eqWord32 (W32# x) (W32# y) = isTrue# ((extendWord32# x) `eqWord#` (extendWord32# y)) -neWord32 (W32# x) (W32# y) = isTrue# ((extendWord32# x) `neWord#` (extendWord32# y)) +eqWord32 (W32# x) (W32# y) = isTrue# ((word32ToWord# x) `eqWord#` (word32ToWord# y)) +neWord32 (W32# x) (W32# y) = isTrue# ((word32ToWord# x) `neWord#` (word32ToWord# y)) {-# INLINE [1] eqWord32 #-} {-# INLINE [1] neWord32 #-} @@ -522,21 +522,21 @@ instance Ord Word32 where {-# INLINE [1] ltWord32 #-} {-# INLINE [1] leWord32 #-} gtWord32, geWord32, ltWord32, leWord32 :: Word32 -> Word32 -> Bool -(W32# x) `gtWord32` (W32# y) = isTrue# ((extendWord32# x) `gtWord#` (extendWord32# y)) -(W32# x) `geWord32` (W32# y) = isTrue# ((extendWord32# x) `geWord#` (extendWord32# y)) -(W32# x) `ltWord32` (W32# y) = isTrue# ((extendWord32# x) `ltWord#` (extendWord32# y)) -(W32# x) `leWord32` (W32# y) = isTrue# ((extendWord32# x) `leWord#` (extendWord32# y)) +(W32# x) `gtWord32` (W32# y) = isTrue# ((word32ToWord# x) `gtWord#` (word32ToWord# y)) +(W32# x) `geWord32` (W32# y) = isTrue# ((word32ToWord# x) `geWord#` (word32ToWord# y)) +(W32# x) `ltWord32` (W32# y) = isTrue# ((word32ToWord# x) `ltWord#` (word32ToWord# y)) +(W32# x) `leWord32` (W32# y) = isTrue# ((word32ToWord# x) `leWord#` (word32ToWord# y)) -- | @since 2.01 instance Num Word32 where - (W32# x#) + (W32# y#) = W32# (narrowWord32# ((extendWord32# x#) `plusWord#` (extendWord32# y#))) - (W32# x#) - (W32# y#) = W32# (narrowWord32# ((extendWord32# x#) `minusWord#` (extendWord32# y#))) - (W32# x#) * (W32# y#) = W32# (narrowWord32# ((extendWord32# x#) `timesWord#` (extendWord32# y#))) - negate (W32# x#) = W32# (narrowWord32# (int2Word# (negateInt# (word2Int# (extendWord32# x#))))) + (W32# x#) + (W32# y#) = W32# (wordToWord32# ((word32ToWord# x#) `plusWord#` (word32ToWord# y#))) + (W32# x#) - (W32# y#) = W32# (wordToWord32# ((word32ToWord# x#) `minusWord#` (word32ToWord# y#))) + (W32# x#) * (W32# y#) = W32# (wordToWord32# ((word32ToWord# x#) `timesWord#` (word32ToWord# y#))) + negate (W32# x#) = W32# (wordToWord32# (int2Word# (negateInt# (word2Int# (word32ToWord# x#))))) abs x = x signum 0 = 0 signum _ = 1 - fromInteger i = W32# (narrowWord32# (integerToWord# i)) + fromInteger i = W32# (wordToWord32# (integerToWord# i)) -- | @since 2.01 instance Enum Word32 where @@ -551,19 +551,19 @@ instance Enum Word32 where #if WORD_SIZE_IN_BITS > 32 && i <= fromIntegral (maxBound::Word32) #endif - = W32# (narrowWord32# (int2Word# i#)) + = W32# (wordToWord32# (int2Word# i#)) | otherwise = toEnumError "Word32" i (minBound::Word32, maxBound::Word32) #if WORD_SIZE_IN_BITS == 32 fromEnum x@(W32# x#) | x <= fromIntegral (maxBound::Int) - = I# (word2Int# (extendWord32# x#)) + = I# (word2Int# (word32ToWord# x#)) | otherwise = fromEnumError "Word32" x enumFrom = integralEnumFrom enumFromThen = integralEnumFromThen enumFromTo = integralEnumFromTo enumFromThenTo = integralEnumFromThenTo #else - fromEnum (W32# x#) = I# (word2Int# (extendWord32# x#)) + fromEnum (W32# x#) = I# (word2Int# (word32ToWord# x#)) enumFrom = boundedEnumFrom enumFromThen = boundedEnumFromThen #endif @@ -571,34 +571,34 @@ instance Enum Word32 where -- | @since 2.01 instance Integral Word32 where quot (W32# x#) y@(W32# y#) - | y /= 0 = W32# (narrowWord32# ((extendWord32# x#) `quotWord#` (extendWord32# y#))) + | y /= 0 = W32# (wordToWord32# ((word32ToWord# x#) `quotWord#` (word32ToWord# y#))) | otherwise = divZeroError rem (W32# x#) y@(W32# y#) - | y /= 0 = W32# (narrowWord32# ((extendWord32# x#) `remWord#` (extendWord32# y#))) + | y /= 0 = W32# (wordToWord32# ((word32ToWord# x#) `remWord#` (word32ToWord# y#))) | otherwise = divZeroError div (W32# x#) y@(W32# y#) - | y /= 0 = W32# (narrowWord32# ((extendWord32# x#) `quotWord#` (extendWord32# y#))) + | y /= 0 = W32# (wordToWord32# ((word32ToWord# x#) `quotWord#` (word32ToWord# y#))) | otherwise = divZeroError mod (W32# x#) y@(W32# y#) - | y /= 0 = W32# (narrowWord32# ((extendWord32# x#) `remWord#` (extendWord32# y#))) + | y /= 0 = W32# (wordToWord32# ((word32ToWord# x#) `remWord#` (word32ToWord# y#))) | otherwise = divZeroError quotRem (W32# x#) y@(W32# y#) - | y /= 0 = case (extendWord32# x#) `quotRemWord#` (extendWord32# y#) of + | y /= 0 = case (word32ToWord# x#) `quotRemWord#` (word32ToWord# y#) of (# q, r #) -> - (W32# (narrowWord32# q), W32# (narrowWord32# r)) + (W32# (wordToWord32# q), W32# (wordToWord32# r)) | otherwise = divZeroError divMod (W32# x#) y@(W32# y#) - | y /= 0 = (W32# (narrowWord32# ((extendWord32# x#) `quotWord#` (extendWord32# y#))) - ,W32# (narrowWord32# ((extendWord32# x#) `remWord#` (extendWord32# y#)))) + | y /= 0 = (W32# (wordToWord32# ((word32ToWord# x#) `quotWord#` (word32ToWord# y#))) + ,W32# (wordToWord32# ((word32ToWord# x#) `remWord#` (word32ToWord# y#)))) | otherwise = divZeroError toInteger (W32# x#) #if WORD_SIZE_IN_BITS == 32 | isTrue# (i# >=# 0#) = IS i# - | otherwise = integerFromWord# (extendWord32# x#) + | otherwise = integerFromWord# (word32ToWord# x#) where - !i# = word2Int# (extendWord32# x#) + !i# = word2Int# (word32ToWord# x#) #else - = IS (word2Int# (extendWord32# x#)) + = IS (word2Int# (word32ToWord# x#)) #endif -- | @since 2.01 @@ -608,32 +608,32 @@ instance Bits Word32 where {-# INLINE testBit #-} {-# INLINE popCount #-} - (W32# x#) .&. (W32# y#) = W32# (narrowWord32# ((extendWord32# x#) `and#` (extendWord32# y#))) - (W32# x#) .|. (W32# y#) = W32# (narrowWord32# ((extendWord32# x#) `or#` (extendWord32# y#))) - (W32# x#) `xor` (W32# y#) = W32# (narrowWord32# ((extendWord32# x#) `xor#` (extendWord32# y#))) - complement (W32# x#) = W32# (narrowWord32# (not# (extendWord32# x#))) + (W32# x#) .&. (W32# y#) = W32# (wordToWord32# ((word32ToWord# x#) `and#` (word32ToWord# y#))) + (W32# x#) .|. (W32# y#) = W32# (wordToWord32# ((word32ToWord# x#) `or#` (word32ToWord# y#))) + (W32# x#) `xor` (W32# y#) = W32# (wordToWord32# ((word32ToWord# x#) `xor#` (word32ToWord# y#))) + complement (W32# x#) = W32# (wordToWord32# (not# (word32ToWord# x#))) (W32# x#) `shift` (I# i#) - | isTrue# (i# >=# 0#) = W32# (narrowWord32# ((extendWord32# x#) `shiftL#` i#)) - | otherwise = W32# (narrowWord32# ((extendWord32# x#) `shiftRL#` negateInt# i#)) + | isTrue# (i# >=# 0#) = W32# (wordToWord32# ((word32ToWord# x#) `shiftL#` i#)) + | otherwise = W32# (wordToWord32# ((word32ToWord# x#) `shiftRL#` negateInt# i#)) (W32# x#) `shiftL` (I# i#) - | isTrue# (i# >=# 0#) = W32# (narrowWord32# ((extendWord32# x#) `shiftL#` i#)) + | isTrue# (i# >=# 0#) = W32# (wordToWord32# ((word32ToWord# x#) `shiftL#` i#)) | otherwise = overflowError (W32# x#) `unsafeShiftL` (I# i#) = - W32# (narrowWord32# ((extendWord32# x#) `uncheckedShiftL#` i#)) + W32# (wordToWord32# ((word32ToWord# x#) `uncheckedShiftL#` i#)) (W32# x#) `shiftR` (I# i#) - | isTrue# (i# >=# 0#) = W32# (narrowWord32# ((extendWord32# x#) `shiftRL#` i#)) + | isTrue# (i# >=# 0#) = W32# (wordToWord32# ((word32ToWord# x#) `shiftRL#` i#)) | otherwise = overflowError - (W32# x#) `unsafeShiftR` (I# i#) = W32# (narrowWord32# ((extendWord32# x#) `uncheckedShiftRL#` i#)) + (W32# x#) `unsafeShiftR` (I# i#) = W32# (wordToWord32# ((word32ToWord# x#) `uncheckedShiftRL#` i#)) (W32# x#) `rotate` (I# i#) | isTrue# (i'# ==# 0#) = W32# x# - | otherwise = W32# (narrowWord32# (((extendWord32# x#) `uncheckedShiftL#` i'#) `or#` - ((extendWord32# x#) `uncheckedShiftRL#` (32# -# i'#)))) + | otherwise = W32# (wordToWord32# (((word32ToWord# x#) `uncheckedShiftL#` i'#) `or#` + ((word32ToWord# x#) `uncheckedShiftRL#` (32# -# i'#)))) where !i'# = word2Int# (int2Word# i# `and#` 31##) bitSizeMaybe i = Just (finiteBitSize i) bitSize i = finiteBitSize i isSigned _ = False - popCount (W32# x#) = I# (word2Int# (popCnt32# (extendWord32# x#))) + popCount (W32# x#) = I# (word2Int# (popCnt32# (word32ToWord# x#))) bit = bitDefault testBit = testBitDefault @@ -642,16 +642,16 @@ instance FiniteBits Word32 where {-# INLINE countLeadingZeros #-} {-# INLINE countTrailingZeros #-} finiteBitSize _ = 32 - countLeadingZeros (W32# x#) = I# (word2Int# (clz32# (extendWord32# x#))) - countTrailingZeros (W32# x#) = I# (word2Int# (ctz32# (extendWord32# x#))) + countLeadingZeros (W32# x#) = I# (word2Int# (clz32# (word32ToWord# x#))) + countTrailingZeros (W32# x#) = I# (word2Int# (ctz32# (word32ToWord# x#))) {-# RULES -"fromIntegral/Word8->Word32" fromIntegral = \(W8# x#) -> W32# (narrowWord32# (extendWord8# x#)) -"fromIntegral/Word16->Word32" fromIntegral = \(W16# x#) -> W32# (narrowWord32# (extendWord16# x#)) +"fromIntegral/Word8->Word32" fromIntegral = \(W8# x#) -> W32# (wordToWord32# (word8ToWord# x#)) +"fromIntegral/Word16->Word32" fromIntegral = \(W16# x#) -> W32# (wordToWord32# (word16ToWord# x#)) "fromIntegral/Word32->Word32" fromIntegral = id :: Word32 -> Word32 "fromIntegral/Word32->Integer" fromIntegral = toInteger :: Word32 -> Integer -"fromIntegral/a->Word32" fromIntegral = \x -> case fromIntegral x of W# x# -> W32# (narrowWord32# x#) -"fromIntegral/Word32->a" fromIntegral = \(W32# x#) -> fromIntegral (W# (extendWord32# x#)) +"fromIntegral/a->Word32" fromIntegral = \x -> case fromIntegral x of W# x# -> W32# (wordToWord32# x#) +"fromIntegral/Word32->a" fromIntegral = \(W32# x#) -> fromIntegral (W# (word32ToWord# x#)) #-} -- | @since 2.01 @@ -682,7 +682,7 @@ instance Ix Word32 where -- -- @since 4.7.0.0 byteSwap32 :: Word32 -> Word32 -byteSwap32 (W32# w#) = W32# (narrowWord32# (byteSwap32# (extendWord32# w#))) +byteSwap32 (W32# w#) = W32# (wordToWord32# (byteSwap32# (word32ToWord# w#))) ------------------------------------------------------------------------ -- type Word64 @@ -1052,19 +1052,19 @@ byteSwap64 (W64# w#) = W64# (byteSwap# w#) -- -- @since 4.12.0.0 bitReverse8 :: Word8 -> Word8 -bitReverse8 (W8# w#) = W8# (narrowWord8# (bitReverse8# (extendWord8# w#))) +bitReverse8 (W8# w#) = W8# (wordToWord8# (bitReverse8# (word8ToWord# w#))) -- | Reverse the order of the bits in a 'Word16'. -- -- @since 4.12.0.0 bitReverse16 :: Word16 -> Word16 -bitReverse16 (W16# w#) = W16# (narrowWord16# (bitReverse16# (extendWord16# w#))) +bitReverse16 (W16# w#) = W16# (wordToWord16# (bitReverse16# (word16ToWord# w#))) -- | Reverse the order of the bits in a 'Word32'. -- -- @since 4.12.0.0 bitReverse32 :: Word32 -> Word32 -bitReverse32 (W32# w#) = W32# (narrowWord32# (bitReverse32# (extendWord32# w#))) +bitReverse32 (W32# w#) = W32# (wordToWord32# (bitReverse32# (word32ToWord# w#))) -- | Reverse the order of the bits in a 'Word64'. -- diff --git a/libraries/binary b/libraries/binary -Subproject 890fcc606d5c9052bdb016d786289dadc29cd46 +Subproject d0c3f06716be373e4195535a76f94f1bba8ab97 diff --git a/libraries/bytestring b/libraries/bytestring -Subproject 36c2df1feaf10fde8d5848ac47b98d6d62c4e1d +Subproject da9d8d80f3bdb440cf4fbba65c08e289f58535a diff --git a/libraries/containers b/libraries/containers -Subproject 3d05a4ec97fea535593c63a12c188259e641854 +Subproject 7fb91ca53b1aca7c077b36a0c1f8f785d177da3 diff --git a/libraries/ghc-bignum/src/GHC/Num/Backend/GMP.hs b/libraries/ghc-bignum/src/GHC/Num/Backend/GMP.hs index 649a7acc70..3fd4394bcf 100644 --- a/libraries/ghc-bignum/src/GHC/Num/Backend/GMP.hs +++ b/libraries/ghc-bignum/src/GHC/Num/Backend/GMP.hs @@ -435,11 +435,11 @@ integer_gcde a b = case runRW# io of (# _, a #) -> a case readInt32OffAddr# sg_ptr 0# s of { (# s, sg #) -> case touch# szs s of { s -> -- shrink x, y and g to their actual sizes and freeze them - let !sx = absI# ssx in - let !sy = absI# ssy in + let !sx = absI# (int32ToInt# ssx) in + let !sy = absI# (int32ToInt# ssy) in case mwaSetSize# mbx sx s of { s -> case mwaSetSize# mby sy s of { s -> - case mwaSetSize# mbg sg s of { s -> + case mwaSetSize# mbg (int32ToInt# sg) s of { s -> -- return x, y and g as Integer case unsafeFreezeByteArray# mbx s of { (# s, bx #) -> @@ -447,8 +447,8 @@ integer_gcde a b = case runRW# io of (# _, a #) -> a case unsafeFreezeByteArray# mbg s of { (# s, bg #) -> (# s, (# integerFromBigNat# bg - , integerFromBigNatSign# (ssx <# 0#) bx - , integerFromBigNatSign# (ssy <# 0#) by #) #) + , integerFromBigNatSign# (int32ToInt# ssx <# 0#) bx + , integerFromBigNatSign# (int32ToInt# ssy <# 0#) by #) #) }}}}}}}}}}}}}}}} diff --git a/libraries/ghc-bignum/src/GHC/Num/Primitives.hs b/libraries/ghc-bignum/src/GHC/Num/Primitives.hs index 589600e047..d286a8d933 100644 --- a/libraries/ghc-bignum/src/GHC/Num/Primitives.hs +++ b/libraries/ghc-bignum/src/GHC/Num/Primitives.hs @@ -334,7 +334,7 @@ wordToAddrLE# x addr = go x 0# = (# s, int2Word# c #) | True - = case writeWord8OffAddr# addr c (w `and#` 0xFF##) s of + = case writeWord8OffAddr# addr c (wordToWord8# w) s of s' -> go (w `uncheckedShiftRL#` 8#) (c +# 1#) s' -- | Write a Word to @/addr/@ in base-256 big-endian representation and @@ -349,7 +349,7 @@ wordToAddrBE# w addr = go 0# (WORD_SIZE_IN_BITS# -# clz) = (# s, int2Word# c #) | True - , w' <- (w `uncheckedShiftRL#` (sh -# 8#)) `and#` 0xFF## + , w' <- wordToWord8# (w `uncheckedShiftRL#` (sh -# 8#)) = case writeWord8OffAddr# addr c w' s of s' -> go (c +# 1#) (sh -# 8#) s' @@ -386,7 +386,7 @@ wordFromAddrLE# n addr s0 = go 0## 0# s0 | True = case readWord8OffAddr# addr c s of - (# s', b #) -> go (w `or#` (b `uncheckedShiftL#` (c `uncheckedIShiftL#` 3#))) + (# s', b #) -> go (w `or#` (word8ToWord# b `uncheckedShiftL#` (c `uncheckedIShiftL#` 3#))) (c +# 1#) s' @@ -412,7 +412,7 @@ wordFromAddrBE# n addr s0 = go 0## 0# s0 | True = case readWord8OffAddr# addr c s of - (# s', b #) -> go ((w `uncheckedShiftL#` 8#) `or#` b) + (# s', b #) -> go ((w `uncheckedShiftL#` 8#) `or#` word8ToWord# b) (c +# 1#) s' @@ -459,7 +459,7 @@ wordToMutableByteArrayLE# x mba off = go x 0# = (# s, int2Word# c #) | True - = case writeWord8Array# mba (word2Int# off +# c) (w `and#` 0xFF##) s of + = case writeWord8Array# mba (word2Int# off +# c) (wordToWord8# w) s of s' -> go (w `uncheckedShiftRL#` 8#) (c +# 1#) s' -- | Write a Word to @/MutableByteArray/@ in base-256 big-endian representation and @@ -476,7 +476,7 @@ wordToMutableByteArrayBE# w mba off = go 0# (WORD_SIZE_IN_BITS# -# clz) = (# s, int2Word# c #) | True - , w' <- (w `uncheckedShiftRL#` (sh -# 8#)) `and#` 0xFF## + , w' <- wordToWord8# (w `uncheckedShiftRL#` (sh -# 8#)) = case writeWord8Array# mba (word2Int# off +# c) w' s of s' -> go (c +# 1#) (sh -# 8#) s' @@ -531,7 +531,7 @@ wordFromByteArrayLE# n ba off = | True = case indexWord8Array# ba (word2Int# off +# c) of - b -> go (w `or#` (b `uncheckedShiftL#` (c `uncheckedIShiftL#` 3#))) + b -> go (w `or#` (word8ToWord# b `uncheckedShiftL#` (c `uncheckedIShiftL#` 3#))) (c +# 1#) in go 0## 0# @@ -557,7 +557,7 @@ wordFromByteArrayBE# n ba off = go 0## 0# | True = case indexWord8Array# ba (word2Int# off +# c) of - b -> go ((w `uncheckedShiftL#` 8#) `or#` b) (c +# 1#) + b -> go ((w `uncheckedShiftL#` 8#) `or#` word8ToWord# b) (c +# 1#) -- | Read a Word from @/ByteArray/@ in base-256 representation. -- diff --git a/libraries/ghc-boot/GHC/Utils/Encoding.hs b/libraries/ghc-boot/GHC/Utils/Encoding.hs index 0f84be189b..519b607425 100644 --- a/libraries/ghc-boot/GHC/Utils/Encoding.hs +++ b/libraries/ghc-boot/GHC/Utils/Encoding.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE CPP #-} {-# LANGUAGE BangPatterns, MagicHash, UnboxedTuples #-} {-# OPTIONS_GHC -O2 -fno-warn-name-shadowing #-} -- We always optimise this, otherwise performance of a non-optimised @@ -116,11 +117,20 @@ utf8DecodeChar# indexWord8# = utf8DecodeCharAddr# :: Addr# -> Int# -> (# Char#, Int# #) utf8DecodeCharAddr# a# off# = +#if !MIN_VERSION_base(4,16,0) utf8DecodeChar# (\i# -> indexWord8OffAddr# a# (i# +# off#)) +#else + utf8DecodeChar# (\i# -> word8ToWord# (indexWord8OffAddr# a# (i# +# off#))) +#endif utf8DecodeCharByteArray# :: ByteArray# -> Int# -> (# Char#, Int# #) utf8DecodeCharByteArray# ba# off# = +#if !MIN_VERSION_base(4,16,0) utf8DecodeChar# (\i# -> indexWord8Array# ba# (i# +# off#)) +#else + utf8DecodeChar# (\i# -> word8ToWord# (indexWord8Array# ba# (i# +# off#))) +#endif + utf8DecodeChar :: Ptr Word8 -> (Char, Int) utf8DecodeChar !(Ptr a#) = @@ -184,16 +194,29 @@ utf8CompareShortByteString (SBS a1) (SBS a2) = go 0# 0# | isTrue# (off1 >=# sz1) = LT | isTrue# (off2 >=# sz2) = GT | otherwise = +#if !MIN_VERSION_base(4,16,0) let !b1_1 = indexWord8Array# a1 off1 !b2_1 = indexWord8Array# a2 off2 +#else + let !b1_1 = word8ToWord# (indexWord8Array# a1 off1) + !b2_1 = word8ToWord# (indexWord8Array# a2 off2) +#endif in case b1_1 of 0xC0## -> case b2_1 of 0xC0## -> go (off1 +# 1#) (off2 +# 1#) +#if !MIN_VERSION_base(4,16,0) _ -> case indexWord8Array# a1 (off1 +# 1#) of +#else + _ -> case word8ToWord# (indexWord8Array# a1 (off1 +# 1#)) of +#endif 0x80## -> LT _ -> go (off1 +# 1#) (off2 +# 1#) _ -> case b2_1 of +#if !MIN_VERSION_base(4,16,0) 0xC0## -> case indexWord8Array# a2 (off2 +# 1#) of +#else + 0xC0## -> case word8ToWord# (indexWord8Array# a2 (off2 +# 1#)) of +#endif 0x80## -> GT _ -> go (off1 +# 1#) (off2 +# 1#) _ | isTrue# (b1_1 `gtWord#` b2_1) -> GT @@ -218,10 +241,10 @@ countUTF8Chars (SBS ba) = go 0# 0# (# _, nBytes# #) -> go (i# +# nBytes#) (n# +# 1#) {-# INLINE utf8EncodeChar #-} -utf8EncodeChar :: (Int# -> Word# -> State# s -> State# s) +utf8EncodeChar :: (Int# -> Word8# -> State# s -> State# s) -> Char -> ST s Int utf8EncodeChar write# c = - let x = ord c in + let x = fromIntegral (ord c) in case () of _ | x > 0 && x <= 0x007f -> do write 0 x @@ -245,15 +268,24 @@ utf8EncodeChar write# c = return 4 where {-# INLINE write #-} - write (I# off#) (I# c#) = ST $ \s -> - case write# off# (int2Word# c#) s of + write (I# off#) (W# c#) = ST $ \s -> +#if !MIN_VERSION_base(4,16,0) + case write# off# (narrowWord8# c#) s of +#else + case write# off# (wordToWord8# c#) s of +#endif s -> (# s, () #) utf8EncodeString :: Ptr Word8 -> String -> IO () utf8EncodeString (Ptr a#) str = go a# str where go !_ [] = return () go a# (c:cs) = do +#if !MIN_VERSION_base(4,16,0) + -- writeWord8OffAddr# was taking a Word# + I# off# <- stToIO $ utf8EncodeChar (\i w -> writeWord8OffAddr# a# i (extendWord8# w)) c +#else I# off# <- stToIO $ utf8EncodeChar (writeWord8OffAddr# a#) c +#endif go (a# `plusAddr#` off#) cs utf8EncodeShortByteString :: String -> IO ShortByteString @@ -267,7 +299,12 @@ utf8EncodeShortByteString str = IO $ \s -> where go _ _ [] = return () go mba# i# (c:cs) = do +#if !MIN_VERSION_base(4,16,0) + -- writeWord8Array# was taking a Word# + I# off# <- utf8EncodeChar (\j# w -> writeWord8Array# mba# (i# +# j#) (extendWord8# w)) c +#else I# off# <- utf8EncodeChar (\j# -> writeWord8Array# mba# (i# +# j#)) c +#endif go mba# (i# +# off#) cs utf8EncodedLength :: String -> Int diff --git a/libraries/ghc-heap/tests/tso_and_stack_closures.hs b/libraries/ghc-heap/tests/tso_and_stack_closures.hs index 42e871bb1f..313076f890 100644 --- a/libraries/ghc-heap/tests/tso_and_stack_closures.hs +++ b/libraries/ghc-heap/tests/tso_and_stack_closures.hs @@ -133,7 +133,7 @@ createAndUnpackTSOAndSTACKClosure = do in (# s', MBA mba# #) forM_ [0..heapRepSize-1] $ \i@(I# i#) -> do W8# w <- peekElemOff ptrHeapRep i - IO (\s -> (# writeWord8Array# mutHeapRepBA i# (extendWord8# w) s, () #)) + IO (\s -> (# writeWord8Array# mutHeapRepBA i# w s, () #)) BA heapRep <- IO $ \s -> let (# s', ba# #) = unsafeFreezeByteArray# mutHeapRepBA s in (# s', BA ba# #) diff --git a/libraries/ghc-prim/changelog.md b/libraries/ghc-prim/changelog.md index a4465684d6..6c7723068f 100644 --- a/libraries/ghc-prim/changelog.md +++ b/libraries/ghc-prim/changelog.md @@ -1,3 +1,21 @@ +## 0.8.0 (edit as necessary) + +- Change array access primops to use type with size maxing the element size: + + - `index{Int,Word}<N>Array# :: ByteArray# -> Int# -> {Int,Word}<N>#` + - `indexWord8ArrayAs{Int,Word}<N># :: ByteArray# -> Int# -> {Int,Word}<N>#` + - `read{Int,Word}<N>Array# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, {Int,Word}<N># #)` + - `write{Int,Word}<N>Array# :: MutableByteArray# s -> Int# -> {Int,Word}<N># -> State# s -> State# s` + - `readWord8ArrayAs{Int,Word}<N># :: MutableByteArray# s -> Int# -> State# s -> (# State# s, {Int,Word}<N># #)` + - `writeWord8ArrayAs{Int,Word}<N># :: MutableByteArray# s -> Int# -> {Int,Word}<N># -> State# s -> State# s` + + This was already the for the 64-bit access primops, but not the smaller ones. + +- Rename some numeric prim type conversion primops: + + - `extend{Int,Word}<N>#` -> `extend<N>To{Int,Word}#` + - `narrow{Int,Word}<N>#` -> `intTo{Int,Word}<N>#` + ## 0.7.0 (edit as necessary) - Shipped with GHC 9.0.1 diff --git a/libraries/ghci/GHCi/BreakArray.hs b/libraries/ghci/GHCi/BreakArray.hs index 05d13bda67..18c1d96b30 100644 --- a/libraries/ghci/GHCi/BreakArray.hs +++ b/libraries/ghci/GHCi/BreakArray.hs @@ -32,20 +32,10 @@ import Control.Monad import Data.Word import GHC.Word -import GHC.Exts hiding (extendWord8#, narrowWord8#) +import GHC.Exts import GHC.IO ( IO(..) ) import System.IO.Unsafe ( unsafeDupablePerformIO ) -#if MIN_VERSION_base(4,16,0) -import GHC.Base (extendWord8#, narrowWord8#) -#else -narrowWord8#, extendWord8# :: Word# -> Word# -narrowWord8# w = w -extendWord8# w = w -{-# INLINE narrowWord8# #-} -{-# INLINE extendWord8# #-} -#endif - data BreakArray = BA (MutableByteArray# RealWorld) breakOff, breakOn :: Word8 @@ -104,22 +94,22 @@ newBreakArray :: Int -> IO BreakArray newBreakArray entries@(I# sz) = do BA array <- allocBA entries case breakOff of - W8# off -> do + off -> do let loop n | isTrue# (n ==# sz) = return () - | otherwise = do writeBA# array n (extendWord8# off); loop (n +# 1#) + | otherwise = do writeBA# array n off; loop (n +# 1#) loop 0# return $ BA array -writeBA# :: MutableByteArray# RealWorld -> Int# -> Word# -> IO () -writeBA# array i word = IO $ \s -> - case writeWord8Array# array i word s of { s -> (# s, () #) } +writeBA# :: MutableByteArray# RealWorld -> Int# -> Word8 -> IO () +writeBA# array i (W8# w) = IO $ \s -> + case writeWord8Array# array i w s of { s -> (# s, () #) } writeBreakArray :: BreakArray -> Int -> Word8 -> IO () -writeBreakArray (BA array) (I# i) (W8# word) = writeBA# array i (extendWord8# word) +writeBreakArray (BA array) (I# i) word = writeBA# array i word readBA# :: MutableByteArray# RealWorld -> Int# -> IO Word8 readBA# array i = IO $ \s -> - case readWord8Array# array i s of { (# s, c #) -> (# s, W8# (narrowWord8# c) #) } + case readWord8Array# array i s of { (# s, c #) -> (# s, W8# c #) } readBreakArray :: BreakArray -> Int -> IO Word8 readBreakArray (BA array) (I# i) = readBA# array i diff --git a/libraries/text b/libraries/text -Subproject f1a2e141a79ebc0a57ab2d641db00cef3ff60a4 +Subproject 3ed977de30e9fb74af33ce9ea4efa4a284c17bd |