[Git][ghc/ghc][wip/int64-everywhere] ghc-bignum: add support for Word64#/Int64# on 64-bit arch
Sylvain Henry
gitlab at gitlab.haskell.org
Mon Jul 20 12:39:24 UTC 2020
Sylvain Henry pushed to branch wip/int64-everywhere at Glasgow Haskell Compiler / GHC
Commits:
280b3843 by Sylvain Henry at 2020-07-20T14:38:08+02:00
ghc-bignum: add support for Word64#/Int64# on 64-bit arch
- - - - -
2 changed files:
- libraries/ghc-bignum/src/GHC/Num/BigNat.hs
- libraries/ghc-bignum/src/GHC/Num/Integer.hs
Changes:
=====================================
libraries/ghc-bignum/src/GHC/Num/BigNat.hs
=====================================
@@ -254,23 +254,31 @@ bigNatToInt# a
bigNatToInt :: BigNat# -> Int
bigNatToInt bn = I# (bigNatToInt# bn)
--- | Convert a Word64# into a BigNat on 32-bit architectures
+-- | Convert a Word64# into a BigNat
bigNatFromWord64# :: Word64# -> BigNat#
+#if WORD_SIZE_IN_BITS == 32
bigNatFromWord64# w64 = bigNatFromWord2# wh# wl#
where
wh# = word64ToWord# (uncheckedShiftRL64# w64 32#)
wl# = word64ToWord# w64
+#else
+bigNatFromWord64# w64 = bigNatFromWord# (word64ToWord# w64)
+#endif
--- | Convert a BigNat into a Word64# on 32-bit architectures
+-- | Convert a BigNat into a Word64#
bigNatToWord64# :: BigNat# -> Word64#
bigNatToWord64# b
| bigNatIsZero b = wordToWord64# 0##
+#if WORD_SIZE_IN_BITS == 32
| wl <- wordToWord64# (bigNatToWord# b)
= if isTrue# (bigNatSize# b ># 1#)
then
let wh = wordToWord64# (bigNatIndex# b 1#)
in uncheckedShiftL64# wh 32# `or64#` wl
else wl
+#else
+ | True = wordToWord64# (bigNatToWord# b)
+#endif
-- | Encode (# BigNat mantissa, Int# exponent #) into a Double#
bigNatEncodeDouble# :: BigNat# -> Int# -> Double#
=====================================
libraries/ghc-bignum/src/GHC/Num/Integer.hs
=====================================
@@ -970,12 +970,12 @@ integerIsPowerOf2# (IS i)
integerIsPowerOf2# (IN _) = (# () | #)
integerIsPowerOf2# (IP w) = bigNatIsPowerOf2# w
--- | 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#)
@@ -984,23 +984,23 @@ 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)
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/280b3843169580261f3816cf182d204476d20b0c
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/280b3843169580261f3816cf182d204476d20b0c
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20200720/5b991c59/attachment-0001.html>
More information about the ghc-commits
mailing list