diff options
author | Reid Barton <rwbarton@gmail.com> | 2015-07-25 23:01:49 -0400 |
---|---|---|
committer | Reid Barton <rwbarton@gmail.com> | 2015-07-25 23:01:49 -0400 |
commit | c55f61ca3f008cc70911d962297fb51f84056661 (patch) | |
tree | e6bfc0a4dbb7d08bd89b703594e1223928cd226e | |
parent | 7e70c063ad88052ca5f2586eb07e5d1571956acd (diff) | |
download | haskell-c55f61ca3f008cc70911d962297fb51f84056661.tar.gz |
Add missing parentheses in eqBigNatWord#
Summary:
I'm pretty sure that parentheses were intended here. But oddly, they
make very little difference.
The presumably intended expression
(sizeofBigNat# bn ==# 1#) `andI#` (bigNatToWord bn `eqWord#` w#)
is 1# exactly when bn consists of a single limb equal to w#, clearly.
In the original expression
sizeofBigNat# bn ==# 1# `andI#` (bigNatToWord bn `eqWord#` w#)
the right-hand side of ==# is always 0# or 1#. So it is 1# when bn
consists of a single limb equal to w#. It is also 1# when bn has
zero limbs and the word past the end of bn does not happen to be
equal to w#. So in practice the difference is that nullBigNat was
eqBigNatWord# to almost everything, but eqBigNatWord# is never
supposed to be called on nullBigNat anyways.
Note that even the corrected version might perform an out-of-bounds
memory access if passed nullBigNat, because `andI#` is not guaranteed
to short-circuit, though in fact GHC does convert isZeroBigNat to a
series of branches in my local build.
Test Plan: validate
Reviewers: hvr, bgamari, goldfire, austin
Reviewed By: hvr, bgamari
Subscribers: thomie
Differential Revision: https://phabricator.haskell.org/D1095
-rw-r--r-- | libraries/integer-gmp/src/GHC/Integer/Type.hs | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/libraries/integer-gmp/src/GHC/Integer/Type.hs b/libraries/integer-gmp/src/GHC/Integer/Type.hs index 88d192306a..d941c4ce85 100644 --- a/libraries/integer-gmp/src/GHC/Integer/Type.hs +++ b/libraries/integer-gmp/src/GHC/Integer/Type.hs @@ -835,7 +835,7 @@ eqBigNatWord bn w# = isTrue# (eqBigNatWord# bn w#) eqBigNatWord# :: BigNat -> GmpLimb# -> Int# eqBigNatWord# bn w# - = sizeofBigNat# bn ==# 1# `andI#` (bigNatToWord bn `eqWord#` w#) + = (sizeofBigNat# bn ==# 1#) `andI#` (bigNatToWord bn `eqWord#` w#) -- | Same as @'indexBigNat#' bn 0\#@ |