diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2020-03-02 15:55:03 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2020-03-02 15:55:03 +0000 |
commit | 4c7fd1314b55dd614d4a4410e86a025611c66aec (patch) | |
tree | 6a70ab0b51df63f4dfe27689342385a385cce151 /src/cmp2.c | |
parent | 9749ae9b1ff44a9f7bc24b019223775caba91bbf (diff) | |
download | mpfr-4c7fd1314b55dd614d4a4410e86a025611c66aec.tar.gz |
[src/cmp2.c] Updated comments.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@13745 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'src/cmp2.c')
-rw-r--r-- | src/cmp2.c | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/src/cmp2.c b/src/cmp2.c index 46948e97a..47f95e720 100644 --- a/src/cmp2.c +++ b/src/cmp2.c @@ -159,22 +159,21 @@ mpfr_cmp2 (mpfr_srcptr b, mpfr_srcptr c, mpfr_prec_t *cancel) /* Now we have removed the identical upper limbs of b and c (when diff_exp = 0), and after the possible swap, we have |b| > |c|, - where b is represented by (bp,bn) and c is represented by (cp,cn), - with diff_exp = EXP(b) - EXP(c). */ - - /* One needs to accumulate canceled bits for the case - [common part]100000... - [common part]011111... - which can occur for diff_exp == 0 (with a non-empty common part, - partly or entirely removed) or for diff_exp == 1 (with an empty - common part). */ - - /* First, consume the equivalent of GMP_NUMB_BITS bits of c (just - decrease diff_exp if >= GMP_NUMB_BITS). The part aligned with - bp[bn] is put in cc, the remaining part in lastc. */ - + where b is represented by (bp,bn) and c is represented by (cp,cn). + The value diff_exp = EXP(b) - EXP(c) can be regarded as the number + of leading zeros of c, when aligned with b. */ + + /* When a limb of c is read from memory, the part that is not taken + into account for the operation with a limb bp[bn] of b will be put + in lastc, shifted to the leftmost part (for alignment with b): + [-------- bp[bn] --------][------- bp[bn-1] -------] + [-- old_lastc --][-------- cp[cn] --------] + [-- new_lastc --] + */ lastc = 0; + /* Compute the next limb difference, which cannot be 0 (dif >= 1). */ + if (MPFR_LIKELY (diff_exp < GMP_NUMB_BITS)) { cc = cp[cn] >> diff_exp; @@ -186,21 +185,24 @@ mpfr_cmp2 (mpfr_srcptr b, mpfr_srcptr c, mpfr_prec_t *cancel) else { cc = 0; - diff_exp -= GMP_NUMB_BITS; + diff_exp -= GMP_NUMB_BITS; /* remove GMP_NUMB_BITS leading zeros */ } - /* Then consume GMP_NUMB_BITS bits of b. - Since |b| > |c| and the identical upper limbs of b and c have been - removed, we have bp[bn] >= cc + 1 mathematically. */ - MPFR_ASSERTD (bp[bn] >= cc); /* no borrow out in subtraction below */ dif = bp[bn--] - cc; MPFR_ASSERTD (dif >= 1); high_dif = 0; + /* One needs to accumulate canceled bits for the case + [common part]100000... + [common part]011111... + which can occur for diff_exp == 0 (with a non-empty common part, + partly or entirely removed) or for diff_exp == 1 (with an empty + common part). */ + /* If diff_exp > 1, then no limbs have been skipped, so that bp[bn] had its MSB equal to 1 and the most two significant bits of cc are 0, - which implies that dif > 1. This if we enter the loop below, then + which implies that dif > 1. Thus if we enter the loop below, then dif == 1, which implies diff_exp <= 1. */ while (MPFR_UNLIKELY ((cn >= 0 || lastc != 0) |