From 20956e5784fe43781d156dd7ab02f0bff4ab41fb Mon Sep 17 00:00:00 2001 From: Sylvain Henry Date: Wed, 20 Oct 2021 11:39:16 +0200 Subject: Remove target dependent CPP for Word64/Int64 (#11470) Primops types were dependent on the target word-size at *compiler* compilation time. It's an issue for multi-target as GHC may not have the correct primops types for the target. This patch fixes some primops types: if they take or return fixed 64-bit values they now always use `Int64#/Word64#`, even on 64-bit architectures (where they used `Int#/Word#` before). Users of these primops may now need to convert from Int64#/Word64# to Int#/Word# (a no-op at runtime). This is a stripped down version of !3658 which goes the all way of changing the underlying primitive types of Word64/Int64. This is left for future work. T12545 allocations increase ~4% on some CI platforms and decrease ~3% on AArch64. Metric Increase: T12545 Metric Decrease: T12545 --- libraries/ghc-bignum/src/GHC/Num/BigNat.hs | 10 ++++++++++ libraries/ghc-bignum/src/GHC/Num/Integer.hs | 24 +++++++----------------- 2 files changed, 17 insertions(+), 17 deletions(-) (limited to 'libraries/ghc-bignum') diff --git a/libraries/ghc-bignum/src/GHC/Num/BigNat.hs b/libraries/ghc-bignum/src/GHC/Num/BigNat.hs index fa8b84eccd..5fa81b7e5b 100644 --- a/libraries/ghc-bignum/src/GHC/Num/BigNat.hs +++ b/libraries/ghc-bignum/src/GHC/Num/BigNat.hs @@ -263,6 +263,16 @@ bigNatToWord64# b in uncheckedShiftL64# wh 32# `or64#` wl else wl +#else + +-- | Convert a Word64# into a BigNat on 64-bit architectures +bigNatFromWord64# :: Word64# -> BigNat# +bigNatFromWord64# w64 = bigNatFromWord# (word64ToWord# w64) + +-- | Convert a BigNat into a Word64# on 64-bit architectures +bigNatToWord64# :: BigNat# -> Word64# +bigNatToWord64# b = wordToWord64# (bigNatToWord# b) + #endif -- | Encode (# BigNat mantissa, Int# exponent #) into a Double# diff --git a/libraries/ghc-bignum/src/GHC/Num/Integer.hs b/libraries/ghc-bignum/src/GHC/Num/Integer.hs index e2a020619e..d85148fc05 100644 --- a/libraries/ghc-bignum/src/GHC/Num/Integer.hs +++ b/libraries/ghc-bignum/src/GHC/Num/Integer.hs @@ -998,14 +998,12 @@ integerIsPowerOf2# (IS i) integerIsPowerOf2# (IN _) = (# (# #) | #) integerIsPowerOf2# (IP w) = bigNatIsPowerOf2# w -#if WORD_SIZE_IN_BITS == 32 - --- | Convert an Int64# into an Integer on 32-bit architectures +-- | Convert an Int64# into an Integer integerFromInt64# :: Int64# -> Integer {-# NOINLINE integerFromInt64# #-} integerFromInt64# !i - | isTrue# ((i `leInt64#` intToInt64# 0x7FFFFFFF#) - &&# (i `geInt64#` intToInt64# -0x80000000#)) + | isTrue# ((i `leInt64#` intToInt64# INT_MAXBOUND#) + &&# (i `geInt64#` intToInt64# INT_MINBOUND#)) = IS (int64ToInt# i) | isTrue# (i `geInt64#` intToInt64# 0#) @@ -1014,37 +1012,29 @@ integerFromInt64# !i | True = IN (bigNatFromWord64# (int64ToWord64# (negateInt64# i))) --- | Convert a Word64# into an Integer on 32-bit architectures +-- | Convert a Word64# into an Integer integerFromWord64# :: Word64# -> Integer {-# NOINLINE integerFromWord64# #-} integerFromWord64# !w - | isTrue# (w `leWord64#` wordToWord64# 0x7FFFFFFF##) + | isTrue# (w `leWord64#` wordToWord64# INT_MAXBOUND##) = IS (int64ToInt# (word64ToInt64# w)) | True = IP (bigNatFromWord64# w) --- | Convert an Integer into an Int64# on 32-bit architectures +-- | Convert an Integer into an Int64# integerToInt64# :: Integer -> Int64# {-# NOINLINE integerToInt64# #-} integerToInt64# (IS i) = intToInt64# i integerToInt64# (IP b) = word64ToInt64# (bigNatToWord64# b) integerToInt64# (IN b) = negateInt64# (word64ToInt64# (bigNatToWord64# b)) --- | Convert an Integer into a Word64# on 32-bit architectures +-- | Convert an Integer into a Word64# integerToWord64# :: Integer -> Word64# {-# NOINLINE integerToWord64# #-} integerToWord64# (IS i) = int64ToWord64# (intToInt64# i) integerToWord64# (IP b) = bigNatToWord64# b integerToWord64# (IN b) = int64ToWord64# (negateInt64# (word64ToInt64# (bigNatToWord64# b))) -#else - --- | Convert an Int64# into an Integer on 64-bit architectures -integerFromInt64# :: Int# -> Integer -integerFromInt64# !x = IS x - -#endif - ---------------------------------------------------------------------------- -- Conversions to/from floating point ---------------------------------------------------------------------------- -- cgit v1.2.1