summaryrefslogtreecommitdiff
path: root/libraries/ghc-bignum
diff options
context:
space:
mode:
authorSylvain Henry <sylvain@haskus.fr>2020-08-25 17:11:40 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2020-08-31 23:04:04 -0400
commit0a3723876c6c79a0a407d50f4baa2818a13f232e (patch)
tree21b2f424cbb3846cc4146e65444baec630fca759 /libraries/ghc-bignum
parentbcb68a3f7f85b9fdef6f4845e608d086b01e6a58 (diff)
downloadhaskell-0a3723876c6c79a0a407d50f4baa2818a13f232e.tar.gz
Fix documentation and fix "check" bignum backend (#18604)
Diffstat (limited to 'libraries/ghc-bignum')
-rw-r--r--libraries/ghc-bignum/src/GHC/Num/BigNat/Check.hs4
-rw-r--r--libraries/ghc-bignum/src/GHC/Num/BigNat/FFI.hs4
-rw-r--r--libraries/ghc-bignum/src/GHC/Num/BigNat/GMP.hs8
-rw-r--r--libraries/ghc-bignum/src/GHC/Num/BigNat/Native.hs4
-rw-r--r--libraries/ghc-bignum/src/GHC/Num/WordArray.hs18
5 files changed, 19 insertions, 19 deletions
diff --git a/libraries/ghc-bignum/src/GHC/Num/BigNat/Check.hs b/libraries/ghc-bignum/src/GHC/Num/BigNat/Check.hs
index f19eceb3e7..8431a5564d 100644
--- a/libraries/ghc-bignum/src/GHC/Num/BigNat/Check.hs
+++ b/libraries/ghc-bignum/src/GHC/Num/BigNat/Check.hs
@@ -129,8 +129,8 @@ mwaCompareOpBool mwa f g s =
0# -> case unexpectedValue of
!_ -> (# s, ra #)
-- see Note [ghc-bignum exceptions] in GHC.Num.Primitives
- _ -> case (ra ==# 1#) of -- don't compare MWAs if overflow signaled!
- 1# -> (# s, ra #)
+ _ -> case ra of -- don't compare MWAs if underflow signaled!
+ 0# -> (# s, ra #) -- underflow
_ -> case mwaTrimZeroes# mwa s of { s ->
case mwaTrimZeroes# mwb s of { s ->
case mwaCompare mwa mwb s of
diff --git a/libraries/ghc-bignum/src/GHC/Num/BigNat/FFI.hs b/libraries/ghc-bignum/src/GHC/Num/BigNat/FFI.hs
index 3ef2f7046c..cfd96be7a0 100644
--- a/libraries/ghc-bignum/src/GHC/Num/BigNat/FFI.hs
+++ b/libraries/ghc-bignum/src/GHC/Num/BigNat/FFI.hs
@@ -113,7 +113,7 @@ foreign import ccall unsafe ghc_bignat_mul_word
-- The potential 0 most-significant Words will be removed by the caller if it is
-- not already done by the backend.
--
--- Return True to indicate overflow.
+-- Return False# to indicate underflow.
bignat_sub
:: MutableWordArray# RealWorld
-> WordArray#
@@ -136,7 +136,7 @@ foreign import ccall unsafe ghc_bignat_sub
-- The potential 0 most-significant Words will be removed by the caller if it is
-- not already done by the backend.
--
--- Return True to indicate overflow.
+-- Return False# to indicate underflow.
bignat_sub_word
:: MutableWordArray# RealWorld
-> WordArray#
diff --git a/libraries/ghc-bignum/src/GHC/Num/BigNat/GMP.hs b/libraries/ghc-bignum/src/GHC/Num/BigNat/GMP.hs
index d316c65e82..35d3983313 100644
--- a/libraries/ghc-bignum/src/GHC/Num/BigNat/GMP.hs
+++ b/libraries/ghc-bignum/src/GHC/Num/BigNat/GMP.hs
@@ -92,8 +92,8 @@ bignat_sub
{-# INLINE bignat_sub #-}
bignat_sub mwa wa wb s =
case ioWord# (c_mpn_sub mwa wa (wordArraySize# wa) wb (wordArraySize# wb)) s of
- (# s', 1## #) -> (# s', 0# #) -- overflow
- (# s', _ #) -> (# s', 1# #) -- no overflow
+ (# s', 1## #) -> (# s', 0# #) -- underflow
+ (# s', _ #) -> (# s', 1# #) -- no underflow
bignat_sub_word
:: MutableWordArray# RealWorld
@@ -104,8 +104,8 @@ bignat_sub_word
{-# INLINE bignat_sub_word #-}
bignat_sub_word mwa wa b s =
case ioWord# (c_mpn_sub_1 mwa wa (wordArraySize# wa) b) s of
- (# s', 1## #) -> (# s', 0# #) -- overflow
- (# s', _ #) -> (# s', 1# #) -- no overflow
+ (# s', 1## #) -> (# s', 0# #) -- underflow
+ (# s', _ #) -> (# s', 1# #) -- no underflow
bignat_mul
:: MutableWordArray# RealWorld
diff --git a/libraries/ghc-bignum/src/GHC/Num/BigNat/Native.hs b/libraries/ghc-bignum/src/GHC/Num/BigNat/Native.hs
index 592a434337..5c1baa4398 100644
--- a/libraries/ghc-bignum/src/GHC/Num/BigNat/Native.hs
+++ b/libraries/ghc-bignum/src/GHC/Num/BigNat/Native.hs
@@ -131,13 +131,13 @@ bignat_sub_word mwa wa b = go b 0#
| 0## <- carry
= case mwaArrayCopy# mwa i wa i (sz -# i) s of
- s' -> (# s', 1# #) -- no overflow
+ s' -> (# s', 1# #) -- no underflow
| True
= case subWordC# (indexWordArray# wa i) carry of
(# 0##, 0# #)
| isTrue# (i ==# sz) -> case mwaShrink# mwa 1# s of
- s' -> (# s', 1# #) -- no overflow
+ s' -> (# s', 1# #) -- no underflow
(# l , c #) -> case mwaWrite# mwa i l s of
s1 -> go (int2Word# c) (i +# 1#) s1
diff --git a/libraries/ghc-bignum/src/GHC/Num/WordArray.hs b/libraries/ghc-bignum/src/GHC/Num/WordArray.hs
index eded6a83ee..dffb7e5797 100644
--- a/libraries/ghc-bignum/src/GHC/Num/WordArray.hs
+++ b/libraries/ghc-bignum/src/GHC/Num/WordArray.hs
@@ -318,7 +318,7 @@ mwaAddInplaceWord# mwa i y s = case readWordArray# mwa i s of
-- | Sub Word# inplace (at the specified offset) in the mwa with carry
-- propagation.
--
--- Return False# on overflow
+-- Return False# on underflow
mwaSubInplaceWord#
:: MutableWordArray# d
-> Int#
@@ -328,9 +328,9 @@ mwaSubInplaceWord#
mwaSubInplaceWord# mwa ii iw s1 = case mwaSize# mwa s1 of
(# is, sz #) ->
let
- go _ 0## s = (# s, 1# #) -- no overflow
+ go _ 0## s = (# s, 1# #) -- no underflow
go i y s
- | isTrue# (i >=# sz) = (# s, 0# #) -- overflow
+ | isTrue# (i >=# sz) = (# s, 0# #) -- underflow
| True = case readWordArray# mwa i s of
(# s1, x #) -> let !(# l,h #) = subWordC# x y
in case mwaWrite# mwa i l s1 of
@@ -368,16 +368,16 @@ mwaTrimCompare k mwa wb s1
--
-- We don't trim the resulting array!
--
--- Return False# on overflow.
+-- Return False# on underflow.
mwaSubInplaceArray :: MutableWordArray# d -> Int# -> WordArray# -> State# d -> (# State# d, Bool# #)
mwaSubInplaceArray mwa off wb = go (wordArraySize# wb -# 1#)
where
go i s
- | isTrue# (i <# 0#) = (# s, 1# #) -- no overflow
+ | isTrue# (i <# 0#) = (# s, 1# #) -- no underflow
| True
= case mwaSubInplaceWord# mwa (off +# i) (indexWordArray# wb i) s of
(# s2, 1# #) -> go (i -# 1#) s2
- (# s2, _ #) -> (# s2, 0# #) -- overflow
+ (# s2, _ #) -> (# s2, 0# #) -- underflow
-- | Add array inplace (a the specified offset) in the mwa with carry propagation.
--
@@ -398,19 +398,19 @@ mwaAddInplaceArray mwa off wb = go 0# 0##
--
-- We don't trim the resulting array!
--
--- Return False# on overflow.
+-- Return False# on underflow.
mwaSubInplaceMutableArray :: MutableWordArray# d -> Int# -> MutableWordArray# d -> State# d -> (# State# d, Bool# #)
mwaSubInplaceMutableArray mwa off mwb s0 =
case mwaSize# mwb s0 of
(# s1, szB #) -> go (szB -# 1#) s1
where
go i s
- | isTrue# (i <# 0#) = (# s, 1# #) -- no overflow
+ | isTrue# (i <# 0#) = (# s, 1# #) -- no underflow
| True
= case readWordArray# mwb i s of
(# s1, bi #) -> case mwaSubInplaceWord# mwa (off +# i) bi s1 of
(# s2, 1# #) -> go (i -# 1#) s2
- (# s2, _ #) -> (# s2, 0# #) -- overflow
+ (# s2, _ #) -> (# s2, 0# #) -- underflow
-- | Sub an array inplace and then trim zeroes
--