summaryrefslogtreecommitdiff
path: root/libraries/ghc-bignum
diff options
context:
space:
mode:
authorSylvain Henry <sylvain@haskus.fr>2021-10-20 11:39:16 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-11-06 07:53:42 -0400
commit20956e5784fe43781d156dd7ab02f0bff4ab41fb (patch)
treede4776b5223cc3e6c983bd4eec28cbef4f973a8f /libraries/ghc-bignum
parent646c3e21dd30a2eaae46aafb8678d29f8e06054d (diff)
downloadhaskell-20956e5784fe43781d156dd7ab02f0bff4ab41fb.tar.gz
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
Diffstat (limited to 'libraries/ghc-bignum')
-rw-r--r--libraries/ghc-bignum/src/GHC/Num/BigNat.hs10
-rw-r--r--libraries/ghc-bignum/src/GHC/Num/Integer.hs24
2 files changed, 17 insertions, 17 deletions
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
----------------------------------------------------------------------------