[Git][ghc/ghc][wip/sjakobi/21176-integer-bits] Add explicit setBit/clearBit/complementBit for instance Bits Integer (#21176)
Simon Jakobi pushed to branch wip/sjakobi/21176-integer-bits at Glasgow Haskell Compiler / GHC Commits: cb3065bc by Simon Jakobi at 2026-06-23T00:52:57+02:00 Add explicit setBit/clearBit/complementBit for instance Bits Integer (#21176) The default setBit, clearBit, and complementBit methods allocate intermediate Integers per call. Define them explicitly via the new integerSetBit[#], integerClearBit[#] and integerComplementBit[#], built on the BigNat# primitives, which avoid those allocations. Allocation is not eliminated entirely -- the negative (IN) cases would need in-place mutation, which is left as future work. The default methods constant-folded on literal arguments via the integerOr/integerAnd/integerXor rules, which fold literal Integers of any size. The explicit functions have no such rule, so they (their Word-argument wrappers, and the Bits Integer methods) are marked INLINE to expose the underlying primops to the simplifier; see Note [INLINE for constant folding of bit operations]. This restores folding only on the small-int (IS) path -- large literal Integers (IP/IN) are no longer constant-folded, a minor regression for that case. T8832 covers the IS-path folding. The new golden-output test T21176 checks all three operations against the default implementations across the sign/size boundaries, recording each result plus its integerCheck validity. The base and ghc-bignum interface- stability export goldens gain the new functions. The main changelog entry lives in changelog.d under a new ghc-internal section (renamed from ghc-prim). CLC proposal: https://github.com/haskell/core-libraries-committee/issues/423 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> - - - - - 12 changed files: - + changelog.d/T21176 - changelog.d/config - libraries/base/changelog.md - libraries/ghc-bignum/changelog.md - libraries/ghc-internal/src/GHC/Internal/Bignum/Integer.hs - libraries/ghc-internal/src/GHC/Internal/Bits.hs - testsuite/tests/interface-stability/ghc-bignum-exports.stdout - + testsuite/tests/numeric/should_run/T21176.hs - + testsuite/tests/numeric/should_run/T21176.stdout - testsuite/tests/numeric/should_run/all.T - testsuite/tests/simplCore/should_compile/T8832.hs - testsuite/tests/simplCore/should_compile/T8832.stdout Changes: ===================================== changelog.d/T21176 ===================================== @@ -0,0 +1,4 @@ +section: ghc-internal +synopsis: Give ``setBit``, ``clearBit`` and ``complementBit`` explicit definitions in ``instance Bits Integer``, backed by new ``integerSetBit[#]``, ``integerClearBit[#]`` and ``integerComplementBit[#]`` functions. These avoid the intermediate ``Integer`` allocations of the previous default methods, although allocation is not eliminated entirely — notably the negative (``IN``) cases would require in-place mutation, which is left as future work. As a trade-off, constant folding of these operations now applies only to small (machine-word-sized) literal arguments; the previous default methods folded literal ``Integer`` arguments of any size via the ``integerOr``/``integerAnd``/``integerXor`` rules. +issues: #21176 +mrs: !7772 ===================================== changelog.d/config ===================================== @@ -27,7 +27,7 @@ sections: { cmm Cmm build-tools Build tools base ``base`` library - ghc-prim ``ghc-prim`` library + ghc-internal ``ghc-internal`` library ghc-lib ``ghc`` library ghc-heap ``ghc-heap`` library ghc-experimental ``ghc-experimental`` library ===================================== libraries/base/changelog.md ===================================== @@ -1,6 +1,7 @@ # Changelog for [`base` package](http://hackage.haskell.org/package/base) ## 4.24.0.0 *TBA* + * Give `setBit`, `clearBit` and `complementBit` explicit definitions in `instance Bits Integer`, reducing intermediate allocations. ([CLC proposal #423](https://github.com/haskell/core-libraries-committee/issues/423)) * Add `Bounded` instances for `Double`, `Float`, `CDouble` and `CFloat`. ([CLC proposal #402](https://github.com/haskell/core-libraries-committee/issues/402)) * Ensure that `Data.List.elem` and `notElem` can be specialized even when no list fusion happens. ([CLC proposal #412)(https://github.com/haskell/core-libraries-committee/issues/412)) ===================================== libraries/ghc-bignum/changelog.md ===================================== @@ -1,5 +1,9 @@ # Changelog for `ghc-bignum` package +## UNRELEASED + +- Add `integerSetBit[#]`, `integerClearBit[#]`, `integerComplementBit[#]` (#21176) + ## 1.4 - `ghc-bignum`'s implementation has been merged into `ghc-internal`. ===================================== libraries/ghc-internal/src/GHC/Internal/Bignum/Integer.hs ===================================== @@ -133,6 +133,12 @@ module GHC.Internal.Bignum.Integer , integerBit , integerTestBit# , integerTestBit + , integerSetBit# + , integerSetBit + , integerClearBit# + , integerClearBit + , integerComplementBit# + , integerComplementBit , integerShiftR# , integerShiftR , integerShiftL# @@ -707,6 +713,113 @@ integerTestBit# (IN x) i integerTestBit :: Integer -> Word -> Bool integerTestBit !i (W# n) = isTrue# (integerTestBit# i n) +{- Note [INLINE for constant folding of bit operations] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +While there are no dedicated constant-folding rules for +integerSetBit#/integerClearBit#/integerComplementBit#, we do INLINE them (and +their Word-argument wrappers and the corresponding Bits Integer methods) to make +the underlying primops accessible for constant folding, e.g. so that +`clearBit (bit 0) 0 :: Integer` folds to `IS 0#`. Test T8832 checks the folding +for all three operations. +-} + +-- | Set the /n/-th bit. +-- +-- Fake 2's complement for negative values (might be slow) +-- +-- @since 10.201.0 +integerSetBit# :: Integer -> Word# -> Integer +{-# INLINE integerSetBit# #-} -- See Note [INLINE for constant folding of bit operations] +integerSetBit# n@(IS x) i + | isTrue# (i `ltWord#` (WORD_SIZE_IN_BITS## `minusWord#` 1##)) + = IS (x `orI#` uncheckedIShiftL# 1# (word2Int# i)) + | isTrue# (x >=# 0#) + = IP (bigNatSetBit# (bigNatFromWord# (int2Word# x)) i) + | True + = n +integerSetBit# (IP x) i = IP (bigNatSetBit# x i) +integerSetBit# (IN x) i = integerFromBigNatNeg# + (bigNatAddWord# + (bigNatClearBit# (bigNatSubWordUnsafe# x 1##) i) + 1##) + +-- | Set the /n/-th bit. +-- +-- Fake 2's complement for negative values (might be slow) +-- +-- @since 10.201.0 +integerSetBit :: Integer -> Word -> Integer +{-# INLINE integerSetBit #-} -- See Note [INLINE for constant folding of bit operations] +integerSetBit !i (W# n) = integerSetBit# i n + +-- | Clear the /n/-th bit. +-- +-- Fake 2's complement for negative values (might be slow) +-- +-- @since 10.201.0 +integerClearBit# :: Integer -> Word# -> Integer +{-# INLINE integerClearBit# #-} -- See Note [INLINE for constant folding of bit operations] +integerClearBit# n@(IS x) i + | isTrue# (i `ltWord#` (WORD_SIZE_IN_BITS## `minusWord#` 1##)) + = IS (x `andI#` notI# (uncheckedIShiftL# 1# (word2Int# i))) + | isTrue# (x >=# 0#) + = n + | True + = IN (bigNatAddWord# + (bigNatSetBit# + (bigNatFromWord# + (minusWord# (int2Word# (negateInt# x)) 1##)) + i) + 1##) +integerClearBit# (IP x) i = integerFromBigNat# (bigNatClearBit# x i) +integerClearBit# (IN x) i = IN (bigNatAddWord# + (bigNatSetBit# (bigNatSubWordUnsafe# x 1##) i) + 1##) + +-- | Clear the /n/-th bit. +-- +-- Fake 2's complement for negative values (might be slow) +-- +-- @since 10.201.0 +integerClearBit :: Integer -> Word -> Integer +{-# INLINE integerClearBit #-} -- See Note [INLINE for constant folding of bit operations] +integerClearBit !i (W# n) = integerClearBit# i n + +-- | Reverse the /n/-th bit. +-- +-- Fake 2's complement for negative values (might be slow) +-- +-- @since 10.201.0 +integerComplementBit# :: Integer -> Word# -> Integer +{-# INLINE integerComplementBit# #-} -- See Note [INLINE for constant folding of bit operations] +integerComplementBit# (IS x) i + | isTrue# (i `ltWord#` (WORD_SIZE_IN_BITS## `minusWord#` 1##)) + = IS (x `xorI#` uncheckedIShiftL# 1# (word2Int# i)) + | isTrue# (x >=# 0#) + = IP (bigNatSetBit# (bigNatFromWord# (int2Word# x)) i) + | True + = IN (bigNatAddWord# + (bigNatSetBit# + (bigNatFromWord# (minusWord# (int2Word# (negateInt# x)) 1##)) + i) + 1##) +integerComplementBit# (IP x) i = integerFromBigNat# (bigNatComplementBit# x i) +integerComplementBit# (IN x) i = integerFromBigNatNeg# + (bigNatAddWord# + (bigNatComplementBit# + (bigNatSubWordUnsafe# x 1##) + i) + 1##) + +-- | Reverse the /n/-th bit. +-- +-- Fake 2's complement for negative values (might be slow) +-- +-- @since 10.201.0 +integerComplementBit :: Integer -> Word -> Integer +{-# INLINE integerComplementBit #-} -- See Note [INLINE for constant folding of bit operations] +integerComplementBit !i (W# n) = integerComplementBit# i n + -- | Shift-right operation -- -- Fake 2's complement for negative values (might be slow) ===================================== libraries/ghc-internal/src/GHC/Internal/Bits.hs ===================================== @@ -564,6 +564,15 @@ instance Bits Integer where | otherwise = integerShiftR x (fromIntegral (negate i)) testBit x i = integerTestBit x (fromIntegral i) zeroBits = integerZero + -- INLINE on setBit/clearBit/complementBit preserves constant folding; + -- see Note [INLINE for constant folding of bit operations] in + -- GHC.Internal.Bignum.Integer. + setBit x i = integerSetBit x (fromIntegral i) + {-# INLINE setBit #-} + clearBit x i = integerClearBit x (fromIntegral i) + {-# INLINE clearBit #-} + complementBit x i = integerComplementBit x (fromIntegral i) + {-# INLINE complementBit #-} bit (I# i) = integerBit# (int2Word# i) popCount x = I# (integerPopCount# x) ===================================== testsuite/tests/interface-stability/ghc-bignum-exports.stdout ===================================== @@ -201,8 +201,12 @@ module GHC.Num.Integer where integerBit# :: GHC.Internal.Prim.Word# -> Integer integerCheck :: Integer -> GHC.Internal.Types.Bool integerCheck# :: Integer -> GHC.Internal.Bignum.Primitives.Bool# + integerClearBit :: Integer -> GHC.Internal.Types.Word -> Integer + integerClearBit# :: Integer -> GHC.Internal.Prim.Word# -> Integer integerCompare :: Integer -> Integer -> GHC.Internal.Types.Ordering integerComplement :: Integer -> Integer + integerComplementBit :: Integer -> GHC.Internal.Types.Word -> Integer + integerComplementBit# :: Integer -> GHC.Internal.Prim.Word# -> Integer integerDecodeDouble# :: GHC.Internal.Prim.Double# -> (# Integer, GHC.Internal.Prim.Int# #) integerDiv :: Integer -> Integer -> Integer integerDivMod :: Integer -> Integer -> (Integer, Integer) @@ -266,6 +270,8 @@ module GHC.Num.Integer where integerQuotRem# :: Integer -> Integer -> (# Integer, Integer #) integerRecipMod# :: Integer -> GHC.Internal.Bignum.Natural.Natural -> (# GHC.Internal.Bignum.Natural.Natural | () #) integerRem :: Integer -> Integer -> Integer + integerSetBit :: Integer -> GHC.Internal.Types.Word -> Integer + integerSetBit# :: Integer -> GHC.Internal.Prim.Word# -> Integer integerShiftL :: Integer -> GHC.Internal.Types.Word -> Integer integerShiftL# :: Integer -> GHC.Internal.Prim.Word# -> Integer integerShiftR :: Integer -> GHC.Internal.Types.Word -> Integer ===================================== testsuite/tests/numeric/should_run/T21176.hs ===================================== @@ -0,0 +1,38 @@ +module Main where + +import Data.Bits +import Data.Int (Int32, Int64) +import Data.Foldable (for_) +import GHC.Num.Integer (integerCheck) + +integers :: [Integer] +integers = concatMap neighbours [minInt64, minInt32, 0, maxInt32, maxInt64] + where + neighbours i = [i - 2, i - 1, i, i + 1, i + 2] + minInt64 = toInteger (minBound :: Int64) + minInt32 = toInteger (minBound :: Int32) + maxInt32 = toInteger (maxBound :: Int32) + maxInt64 = toInteger (maxBound :: Int64) + +bits :: [Int] +bits = [0, 1, x - 1, x, x + 1] + where x = finiteBitSize (0 :: Int) - 1 + +testXBit :: String -> (Integer -> Int -> Integer) -> (Integer -> Int -> Integer) -> IO () +testXBit name f model = do + putStrLn name + for_ integers $ \i -> + for_ bits $ \b -> do + let actual = f i b + expected = model i b + valid = if integerCheck actual then "valid" else "invalid" + matches = if actual == expected then "matches" else "differs" + putStrLn $ " " ++ show i ++ " " ++ show b ++ " -> " ++ show actual + ++ " [" ++ valid ++ ", " ++ matches ++ "]" + putStrLn "" + +main :: IO () +main = do + testXBit "setBit" setBit (\i b -> i .|. bit b) + testXBit "clearBit" clearBit (\i b -> i .&. complement (bit b)) + testXBit "complementBit" complementBit (\i b -> i `xor` bit b) ===================================== testsuite/tests/numeric/should_run/T21176.stdout ===================================== @@ -0,0 +1,381 @@ +setBit + -9223372036854775810 0 -> -9223372036854775809 [valid, matches] + -9223372036854775810 1 -> -9223372036854775810 [valid, matches] + -9223372036854775810 62 -> -9223372036854775810 [valid, matches] + -9223372036854775810 63 -> -2 [valid, matches] + -9223372036854775810 64 -> -9223372036854775810 [valid, matches] + -9223372036854775809 0 -> -9223372036854775809 [valid, matches] + -9223372036854775809 1 -> -9223372036854775809 [valid, matches] + -9223372036854775809 62 -> -9223372036854775809 [valid, matches] + -9223372036854775809 63 -> -1 [valid, matches] + -9223372036854775809 64 -> -9223372036854775809 [valid, matches] + -9223372036854775808 0 -> -9223372036854775807 [valid, matches] + -9223372036854775808 1 -> -9223372036854775806 [valid, matches] + -9223372036854775808 62 -> -4611686018427387904 [valid, matches] + -9223372036854775808 63 -> -9223372036854775808 [valid, matches] + -9223372036854775808 64 -> -9223372036854775808 [valid, matches] + -9223372036854775807 0 -> -9223372036854775807 [valid, matches] + -9223372036854775807 1 -> -9223372036854775805 [valid, matches] + -9223372036854775807 62 -> -4611686018427387903 [valid, matches] + -9223372036854775807 63 -> -9223372036854775807 [valid, matches] + -9223372036854775807 64 -> -9223372036854775807 [valid, matches] + -9223372036854775806 0 -> -9223372036854775805 [valid, matches] + -9223372036854775806 1 -> -9223372036854775806 [valid, matches] + -9223372036854775806 62 -> -4611686018427387902 [valid, matches] + -9223372036854775806 63 -> -9223372036854775806 [valid, matches] + -9223372036854775806 64 -> -9223372036854775806 [valid, matches] + -2147483650 0 -> -2147483649 [valid, matches] + -2147483650 1 -> -2147483650 [valid, matches] + -2147483650 62 -> -2147483650 [valid, matches] + -2147483650 63 -> -2147483650 [valid, matches] + -2147483650 64 -> -2147483650 [valid, matches] + -2147483649 0 -> -2147483649 [valid, matches] + -2147483649 1 -> -2147483649 [valid, matches] + -2147483649 62 -> -2147483649 [valid, matches] + -2147483649 63 -> -2147483649 [valid, matches] + -2147483649 64 -> -2147483649 [valid, matches] + -2147483648 0 -> -2147483647 [valid, matches] + -2147483648 1 -> -2147483646 [valid, matches] + -2147483648 62 -> -2147483648 [valid, matches] + -2147483648 63 -> -2147483648 [valid, matches] + -2147483648 64 -> -2147483648 [valid, matches] + -2147483647 0 -> -2147483647 [valid, matches] + -2147483647 1 -> -2147483645 [valid, matches] + -2147483647 62 -> -2147483647 [valid, matches] + -2147483647 63 -> -2147483647 [valid, matches] + -2147483647 64 -> -2147483647 [valid, matches] + -2147483646 0 -> -2147483645 [valid, matches] + -2147483646 1 -> -2147483646 [valid, matches] + -2147483646 62 -> -2147483646 [valid, matches] + -2147483646 63 -> -2147483646 [valid, matches] + -2147483646 64 -> -2147483646 [valid, matches] + -2 0 -> -1 [valid, matches] + -2 1 -> -2 [valid, matches] + -2 62 -> -2 [valid, matches] + -2 63 -> -2 [valid, matches] + -2 64 -> -2 [valid, matches] + -1 0 -> -1 [valid, matches] + -1 1 -> -1 [valid, matches] + -1 62 -> -1 [valid, matches] + -1 63 -> -1 [valid, matches] + -1 64 -> -1 [valid, matches] + 0 0 -> 1 [valid, matches] + 0 1 -> 2 [valid, matches] + 0 62 -> 4611686018427387904 [valid, matches] + 0 63 -> 9223372036854775808 [valid, matches] + 0 64 -> 18446744073709551616 [valid, matches] + 1 0 -> 1 [valid, matches] + 1 1 -> 3 [valid, matches] + 1 62 -> 4611686018427387905 [valid, matches] + 1 63 -> 9223372036854775809 [valid, matches] + 1 64 -> 18446744073709551617 [valid, matches] + 2 0 -> 3 [valid, matches] + 2 1 -> 2 [valid, matches] + 2 62 -> 4611686018427387906 [valid, matches] + 2 63 -> 9223372036854775810 [valid, matches] + 2 64 -> 18446744073709551618 [valid, matches] + 2147483645 0 -> 2147483645 [valid, matches] + 2147483645 1 -> 2147483647 [valid, matches] + 2147483645 62 -> 4611686020574871549 [valid, matches] + 2147483645 63 -> 9223372039002259453 [valid, matches] + 2147483645 64 -> 18446744075857035261 [valid, matches] + 2147483646 0 -> 2147483647 [valid, matches] + 2147483646 1 -> 2147483646 [valid, matches] + 2147483646 62 -> 4611686020574871550 [valid, matches] + 2147483646 63 -> 9223372039002259454 [valid, matches] + 2147483646 64 -> 18446744075857035262 [valid, matches] + 2147483647 0 -> 2147483647 [valid, matches] + 2147483647 1 -> 2147483647 [valid, matches] + 2147483647 62 -> 4611686020574871551 [valid, matches] + 2147483647 63 -> 9223372039002259455 [valid, matches] + 2147483647 64 -> 18446744075857035263 [valid, matches] + 2147483648 0 -> 2147483649 [valid, matches] + 2147483648 1 -> 2147483650 [valid, matches] + 2147483648 62 -> 4611686020574871552 [valid, matches] + 2147483648 63 -> 9223372039002259456 [valid, matches] + 2147483648 64 -> 18446744075857035264 [valid, matches] + 2147483649 0 -> 2147483649 [valid, matches] + 2147483649 1 -> 2147483651 [valid, matches] + 2147483649 62 -> 4611686020574871553 [valid, matches] + 2147483649 63 -> 9223372039002259457 [valid, matches] + 2147483649 64 -> 18446744075857035265 [valid, matches] + 9223372036854775805 0 -> 9223372036854775805 [valid, matches] + 9223372036854775805 1 -> 9223372036854775807 [valid, matches] + 9223372036854775805 62 -> 9223372036854775805 [valid, matches] + 9223372036854775805 63 -> 18446744073709551613 [valid, matches] + 9223372036854775805 64 -> 27670116110564327421 [valid, matches] + 9223372036854775806 0 -> 9223372036854775807 [valid, matches] + 9223372036854775806 1 -> 9223372036854775806 [valid, matches] + 9223372036854775806 62 -> 9223372036854775806 [valid, matches] + 9223372036854775806 63 -> 18446744073709551614 [valid, matches] + 9223372036854775806 64 -> 27670116110564327422 [valid, matches] + 9223372036854775807 0 -> 9223372036854775807 [valid, matches] + 9223372036854775807 1 -> 9223372036854775807 [valid, matches] + 9223372036854775807 62 -> 9223372036854775807 [valid, matches] + 9223372036854775807 63 -> 18446744073709551615 [valid, matches] + 9223372036854775807 64 -> 27670116110564327423 [valid, matches] + 9223372036854775808 0 -> 9223372036854775809 [valid, matches] + 9223372036854775808 1 -> 9223372036854775810 [valid, matches] + 9223372036854775808 62 -> 13835058055282163712 [valid, matches] + 9223372036854775808 63 -> 9223372036854775808 [valid, matches] + 9223372036854775808 64 -> 27670116110564327424 [valid, matches] + 9223372036854775809 0 -> 9223372036854775809 [valid, matches] + 9223372036854775809 1 -> 9223372036854775811 [valid, matches] + 9223372036854775809 62 -> 13835058055282163713 [valid, matches] + 9223372036854775809 63 -> 9223372036854775809 [valid, matches] + 9223372036854775809 64 -> 27670116110564327425 [valid, matches] + +clearBit + -9223372036854775810 0 -> -9223372036854775810 [valid, matches] + -9223372036854775810 1 -> -9223372036854775812 [valid, matches] + -9223372036854775810 62 -> -13835058055282163714 [valid, matches] + -9223372036854775810 63 -> -9223372036854775810 [valid, matches] + -9223372036854775810 64 -> -27670116110564327426 [valid, matches] + -9223372036854775809 0 -> -9223372036854775810 [valid, matches] + -9223372036854775809 1 -> -9223372036854775811 [valid, matches] + -9223372036854775809 62 -> -13835058055282163713 [valid, matches] + -9223372036854775809 63 -> -9223372036854775809 [valid, matches] + -9223372036854775809 64 -> -27670116110564327425 [valid, matches] + -9223372036854775808 0 -> -9223372036854775808 [valid, matches] + -9223372036854775808 1 -> -9223372036854775808 [valid, matches] + -9223372036854775808 62 -> -9223372036854775808 [valid, matches] + -9223372036854775808 63 -> -18446744073709551616 [valid, matches] + -9223372036854775808 64 -> -27670116110564327424 [valid, matches] + -9223372036854775807 0 -> -9223372036854775808 [valid, matches] + -9223372036854775807 1 -> -9223372036854775807 [valid, matches] + -9223372036854775807 62 -> -9223372036854775807 [valid, matches] + -9223372036854775807 63 -> -18446744073709551615 [valid, matches] + -9223372036854775807 64 -> -27670116110564327423 [valid, matches] + -9223372036854775806 0 -> -9223372036854775806 [valid, matches] + -9223372036854775806 1 -> -9223372036854775808 [valid, matches] + -9223372036854775806 62 -> -9223372036854775806 [valid, matches] + -9223372036854775806 63 -> -18446744073709551614 [valid, matches] + -9223372036854775806 64 -> -27670116110564327422 [valid, matches] + -2147483650 0 -> -2147483650 [valid, matches] + -2147483650 1 -> -2147483652 [valid, matches] + -2147483650 62 -> -4611686020574871554 [valid, matches] + -2147483650 63 -> -9223372039002259458 [valid, matches] + -2147483650 64 -> -18446744075857035266 [valid, matches] + -2147483649 0 -> -2147483650 [valid, matches] + -2147483649 1 -> -2147483651 [valid, matches] + -2147483649 62 -> -4611686020574871553 [valid, matches] + -2147483649 63 -> -9223372039002259457 [valid, matches] + -2147483649 64 -> -18446744075857035265 [valid, matches] + -2147483648 0 -> -2147483648 [valid, matches] + -2147483648 1 -> -2147483648 [valid, matches] + -2147483648 62 -> -4611686020574871552 [valid, matches] + -2147483648 63 -> -9223372039002259456 [valid, matches] + -2147483648 64 -> -18446744075857035264 [valid, matches] + -2147483647 0 -> -2147483648 [valid, matches] + -2147483647 1 -> -2147483647 [valid, matches] + -2147483647 62 -> -4611686020574871551 [valid, matches] + -2147483647 63 -> -9223372039002259455 [valid, matches] + -2147483647 64 -> -18446744075857035263 [valid, matches] + -2147483646 0 -> -2147483646 [valid, matches] + -2147483646 1 -> -2147483648 [valid, matches] + -2147483646 62 -> -4611686020574871550 [valid, matches] + -2147483646 63 -> -9223372039002259454 [valid, matches] + -2147483646 64 -> -18446744075857035262 [valid, matches] + -2 0 -> -2 [valid, matches] + -2 1 -> -4 [valid, matches] + -2 62 -> -4611686018427387906 [valid, matches] + -2 63 -> -9223372036854775810 [valid, matches] + -2 64 -> -18446744073709551618 [valid, matches] + -1 0 -> -2 [valid, matches] + -1 1 -> -3 [valid, matches] + -1 62 -> -4611686018427387905 [valid, matches] + -1 63 -> -9223372036854775809 [valid, matches] + -1 64 -> -18446744073709551617 [valid, matches] + 0 0 -> 0 [valid, matches] + 0 1 -> 0 [valid, matches] + 0 62 -> 0 [valid, matches] + 0 63 -> 0 [valid, matches] + 0 64 -> 0 [valid, matches] + 1 0 -> 0 [valid, matches] + 1 1 -> 1 [valid, matches] + 1 62 -> 1 [valid, matches] + 1 63 -> 1 [valid, matches] + 1 64 -> 1 [valid, matches] + 2 0 -> 2 [valid, matches] + 2 1 -> 0 [valid, matches] + 2 62 -> 2 [valid, matches] + 2 63 -> 2 [valid, matches] + 2 64 -> 2 [valid, matches] + 2147483645 0 -> 2147483644 [valid, matches] + 2147483645 1 -> 2147483645 [valid, matches] + 2147483645 62 -> 2147483645 [valid, matches] + 2147483645 63 -> 2147483645 [valid, matches] + 2147483645 64 -> 2147483645 [valid, matches] + 2147483646 0 -> 2147483646 [valid, matches] + 2147483646 1 -> 2147483644 [valid, matches] + 2147483646 62 -> 2147483646 [valid, matches] + 2147483646 63 -> 2147483646 [valid, matches] + 2147483646 64 -> 2147483646 [valid, matches] + 2147483647 0 -> 2147483646 [valid, matches] + 2147483647 1 -> 2147483645 [valid, matches] + 2147483647 62 -> 2147483647 [valid, matches] + 2147483647 63 -> 2147483647 [valid, matches] + 2147483647 64 -> 2147483647 [valid, matches] + 2147483648 0 -> 2147483648 [valid, matches] + 2147483648 1 -> 2147483648 [valid, matches] + 2147483648 62 -> 2147483648 [valid, matches] + 2147483648 63 -> 2147483648 [valid, matches] + 2147483648 64 -> 2147483648 [valid, matches] + 2147483649 0 -> 2147483648 [valid, matches] + 2147483649 1 -> 2147483649 [valid, matches] + 2147483649 62 -> 2147483649 [valid, matches] + 2147483649 63 -> 2147483649 [valid, matches] + 2147483649 64 -> 2147483649 [valid, matches] + 9223372036854775805 0 -> 9223372036854775804 [valid, matches] + 9223372036854775805 1 -> 9223372036854775805 [valid, matches] + 9223372036854775805 62 -> 4611686018427387901 [valid, matches] + 9223372036854775805 63 -> 9223372036854775805 [valid, matches] + 9223372036854775805 64 -> 9223372036854775805 [valid, matches] + 9223372036854775806 0 -> 9223372036854775806 [valid, matches] + 9223372036854775806 1 -> 9223372036854775804 [valid, matches] + 9223372036854775806 62 -> 4611686018427387902 [valid, matches] + 9223372036854775806 63 -> 9223372036854775806 [valid, matches] + 9223372036854775806 64 -> 9223372036854775806 [valid, matches] + 9223372036854775807 0 -> 9223372036854775806 [valid, matches] + 9223372036854775807 1 -> 9223372036854775805 [valid, matches] + 9223372036854775807 62 -> 4611686018427387903 [valid, matches] + 9223372036854775807 63 -> 9223372036854775807 [valid, matches] + 9223372036854775807 64 -> 9223372036854775807 [valid, matches] + 9223372036854775808 0 -> 9223372036854775808 [valid, matches] + 9223372036854775808 1 -> 9223372036854775808 [valid, matches] + 9223372036854775808 62 -> 9223372036854775808 [valid, matches] + 9223372036854775808 63 -> 0 [valid, matches] + 9223372036854775808 64 -> 9223372036854775808 [valid, matches] + 9223372036854775809 0 -> 9223372036854775808 [valid, matches] + 9223372036854775809 1 -> 9223372036854775809 [valid, matches] + 9223372036854775809 62 -> 9223372036854775809 [valid, matches] + 9223372036854775809 63 -> 1 [valid, matches] + 9223372036854775809 64 -> 9223372036854775809 [valid, matches] + +complementBit + -9223372036854775810 0 -> -9223372036854775809 [valid, matches] + -9223372036854775810 1 -> -9223372036854775812 [valid, matches] + -9223372036854775810 62 -> -13835058055282163714 [valid, matches] + -9223372036854775810 63 -> -2 [valid, matches] + -9223372036854775810 64 -> -27670116110564327426 [valid, matches] + -9223372036854775809 0 -> -9223372036854775810 [valid, matches] + -9223372036854775809 1 -> -9223372036854775811 [valid, matches] + -9223372036854775809 62 -> -13835058055282163713 [valid, matches] + -9223372036854775809 63 -> -1 [valid, matches] + -9223372036854775809 64 -> -27670116110564327425 [valid, matches] + -9223372036854775808 0 -> -9223372036854775807 [valid, matches] + -9223372036854775808 1 -> -9223372036854775806 [valid, matches] + -9223372036854775808 62 -> -4611686018427387904 [valid, matches] + -9223372036854775808 63 -> -18446744073709551616 [valid, matches] + -9223372036854775808 64 -> -27670116110564327424 [valid, matches] + -9223372036854775807 0 -> -9223372036854775808 [valid, matches] + -9223372036854775807 1 -> -9223372036854775805 [valid, matches] + -9223372036854775807 62 -> -4611686018427387903 [valid, matches] + -9223372036854775807 63 -> -18446744073709551615 [valid, matches] + -9223372036854775807 64 -> -27670116110564327423 [valid, matches] + -9223372036854775806 0 -> -9223372036854775805 [valid, matches] + -9223372036854775806 1 -> -9223372036854775808 [valid, matches] + -9223372036854775806 62 -> -4611686018427387902 [valid, matches] + -9223372036854775806 63 -> -18446744073709551614 [valid, matches] + -9223372036854775806 64 -> -27670116110564327422 [valid, matches] + -2147483650 0 -> -2147483649 [valid, matches] + -2147483650 1 -> -2147483652 [valid, matches] + -2147483650 62 -> -4611686020574871554 [valid, matches] + -2147483650 63 -> -9223372039002259458 [valid, matches] + -2147483650 64 -> -18446744075857035266 [valid, matches] + -2147483649 0 -> -2147483650 [valid, matches] + -2147483649 1 -> -2147483651 [valid, matches] + -2147483649 62 -> -4611686020574871553 [valid, matches] + -2147483649 63 -> -9223372039002259457 [valid, matches] + -2147483649 64 -> -18446744075857035265 [valid, matches] + -2147483648 0 -> -2147483647 [valid, matches] + -2147483648 1 -> -2147483646 [valid, matches] + -2147483648 62 -> -4611686020574871552 [valid, matches] + -2147483648 63 -> -9223372039002259456 [valid, matches] + -2147483648 64 -> -18446744075857035264 [valid, matches] + -2147483647 0 -> -2147483648 [valid, matches] + -2147483647 1 -> -2147483645 [valid, matches] + -2147483647 62 -> -4611686020574871551 [valid, matches] + -2147483647 63 -> -9223372039002259455 [valid, matches] + -2147483647 64 -> -18446744075857035263 [valid, matches] + -2147483646 0 -> -2147483645 [valid, matches] + -2147483646 1 -> -2147483648 [valid, matches] + -2147483646 62 -> -4611686020574871550 [valid, matches] + -2147483646 63 -> -9223372039002259454 [valid, matches] + -2147483646 64 -> -18446744075857035262 [valid, matches] + -2 0 -> -1 [valid, matches] + -2 1 -> -4 [valid, matches] + -2 62 -> -4611686018427387906 [valid, matches] + -2 63 -> -9223372036854775810 [valid, matches] + -2 64 -> -18446744073709551618 [valid, matches] + -1 0 -> -2 [valid, matches] + -1 1 -> -3 [valid, matches] + -1 62 -> -4611686018427387905 [valid, matches] + -1 63 -> -9223372036854775809 [valid, matches] + -1 64 -> -18446744073709551617 [valid, matches] + 0 0 -> 1 [valid, matches] + 0 1 -> 2 [valid, matches] + 0 62 -> 4611686018427387904 [valid, matches] + 0 63 -> 9223372036854775808 [valid, matches] + 0 64 -> 18446744073709551616 [valid, matches] + 1 0 -> 0 [valid, matches] + 1 1 -> 3 [valid, matches] + 1 62 -> 4611686018427387905 [valid, matches] + 1 63 -> 9223372036854775809 [valid, matches] + 1 64 -> 18446744073709551617 [valid, matches] + 2 0 -> 3 [valid, matches] + 2 1 -> 0 [valid, matches] + 2 62 -> 4611686018427387906 [valid, matches] + 2 63 -> 9223372036854775810 [valid, matches] + 2 64 -> 18446744073709551618 [valid, matches] + 2147483645 0 -> 2147483644 [valid, matches] + 2147483645 1 -> 2147483647 [valid, matches] + 2147483645 62 -> 4611686020574871549 [valid, matches] + 2147483645 63 -> 9223372039002259453 [valid, matches] + 2147483645 64 -> 18446744075857035261 [valid, matches] + 2147483646 0 -> 2147483647 [valid, matches] + 2147483646 1 -> 2147483644 [valid, matches] + 2147483646 62 -> 4611686020574871550 [valid, matches] + 2147483646 63 -> 9223372039002259454 [valid, matches] + 2147483646 64 -> 18446744075857035262 [valid, matches] + 2147483647 0 -> 2147483646 [valid, matches] + 2147483647 1 -> 2147483645 [valid, matches] + 2147483647 62 -> 4611686020574871551 [valid, matches] + 2147483647 63 -> 9223372039002259455 [valid, matches] + 2147483647 64 -> 18446744075857035263 [valid, matches] + 2147483648 0 -> 2147483649 [valid, matches] + 2147483648 1 -> 2147483650 [valid, matches] + 2147483648 62 -> 4611686020574871552 [valid, matches] + 2147483648 63 -> 9223372039002259456 [valid, matches] + 2147483648 64 -> 18446744075857035264 [valid, matches] + 2147483649 0 -> 2147483648 [valid, matches] + 2147483649 1 -> 2147483651 [valid, matches] + 2147483649 62 -> 4611686020574871553 [valid, matches] + 2147483649 63 -> 9223372039002259457 [valid, matches] + 2147483649 64 -> 18446744075857035265 [valid, matches] + 9223372036854775805 0 -> 9223372036854775804 [valid, matches] + 9223372036854775805 1 -> 9223372036854775807 [valid, matches] + 9223372036854775805 62 -> 4611686018427387901 [valid, matches] + 9223372036854775805 63 -> 18446744073709551613 [valid, matches] + 9223372036854775805 64 -> 27670116110564327421 [valid, matches] + 9223372036854775806 0 -> 9223372036854775807 [valid, matches] + 9223372036854775806 1 -> 9223372036854775804 [valid, matches] + 9223372036854775806 62 -> 4611686018427387902 [valid, matches] + 9223372036854775806 63 -> 18446744073709551614 [valid, matches] + 9223372036854775806 64 -> 27670116110564327422 [valid, matches] + 9223372036854775807 0 -> 9223372036854775806 [valid, matches] + 9223372036854775807 1 -> 9223372036854775805 [valid, matches] + 9223372036854775807 62 -> 4611686018427387903 [valid, matches] + 9223372036854775807 63 -> 18446744073709551615 [valid, matches] + 9223372036854775807 64 -> 27670116110564327423 [valid, matches] + 9223372036854775808 0 -> 9223372036854775809 [valid, matches] + 9223372036854775808 1 -> 9223372036854775810 [valid, matches] + 9223372036854775808 62 -> 13835058055282163712 [valid, matches] + 9223372036854775808 63 -> 0 [valid, matches] + 9223372036854775808 64 -> 27670116110564327424 [valid, matches] + 9223372036854775809 0 -> 9223372036854775808 [valid, matches] + 9223372036854775809 1 -> 9223372036854775811 [valid, matches] + 9223372036854775809 62 -> 13835058055282163713 [valid, matches] + 9223372036854775809 63 -> 1 [valid, matches] + 9223372036854775809 64 -> 27670116110564327425 [valid, matches] + ===================================== testsuite/tests/numeric/should_run/all.T ===================================== @@ -101,3 +101,4 @@ test('T24245', normal, compile_and_run, ['']) test('T25653', normal, compile_and_run, ['']) test('T18619', exit_code(1), compile_and_run, ['']) test('T26230', normal, compile_and_run, ['']) +test('T21176', normal, compile_and_run, ['']) ===================================== testsuite/tests/simplCore/should_compile/T8832.hs ===================================== @@ -23,3 +23,9 @@ T(w32,Word32) T(w64,Word64) T(z,Integer) + +zset :: Integer +zset = setBit (bit 0) 0 + +zcompl :: Integer +zcompl = complementBit (bit 0) 0 ===================================== testsuite/tests/simplCore/should_compile/T8832.stdout ===================================== @@ -8,4 +8,6 @@ w8 = GHC.Internal.Word.W8# 0#Word8 w16 = GHC.Internal.Word.W16# 0#Word16 w32 = GHC.Internal.Word.W32# 0#Word32 w64 = GHC.Internal.Word.W64# 0#Word64 -z = GHC.Internal.Bignum.Integer.IS 0# +zcompl = GHC.Internal.Bignum.Integer.IS 0# +zset = GHC.Internal.Bignum.Integer.IS 1# +z = zcompl View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/cb3065bc4cfa8af80dc0279f474efa6c... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/cb3065bc4cfa8af80dc0279f474efa6c... You're receiving this email because of your account on gitlab.haskell.org.
participants (1)
-
Simon Jakobi (@sjakobi2)