diff options
author | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2018-09-11 20:59:57 +0000 |
---|---|---|
committer | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2018-09-11 20:59:57 +0000 |
commit | e8e558f8a700718bc45c93dcc2f750846afb48d0 (patch) | |
tree | 4274ee2be69702edd006d0607360a99b025a54c4 | |
parent | b55e59e1d750efa6ed336f3f191c7bedac90a7ba (diff) | |
download | mpfr-e8e558f8a700718bc45c93dcc2f750846afb48d0.tar.gz |
[src/rec_sqrt.c] fixed for 8-bit limb
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@13172 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r-- | src/rec_sqrt.c | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/src/rec_sqrt.c b/src/rec_sqrt.c index 0e5a435ee..a6b106a3e 100644 --- a/src/rec_sqrt.c +++ b/src/rec_sqrt.c @@ -179,7 +179,7 @@ mpfr_mpn_rec_sqrt (mpfr_limb_ptr x, mpfr_prec_t p, if (p == 11) /* should happen only from recursive calls */ { unsigned long i, ab, ac; - mp_limb_t t; + int t; /* take the 12+as most significant bits of A */ #if GMP_NUMB_BITS >= 16 @@ -196,8 +196,16 @@ mpfr_mpn_rec_sqrt (mpfr_limb_ptr x, mpfr_prec_t p, /* if one wants faithful rounding for p=11, replace #if 0 by #if 1 */ ab = i >> 4; ac = (ab & 0x3F0) | (i & 0x0F); - t = (mp_limb_t) T1[ab - 0x80] + (mp_limb_t) T2[ac - 0x80]; - x[0] = t << (GMP_NUMB_BITS - p); + t = (int) T1[ab - 0x80] + (int) T2[ac - 0x80]; + if (GMP_NUMB_BITS >= 16) /* x has only one limb */ + x[0] = t << (GMP_NUMB_BITS - p); + else + { + MPFR_ASSERTD(GMP_NUMB_BITS == 8); + /* 1024 <= t <= 2047 */ + x[1] = t >> 3; /* 128 <= x[1] <= 255 */ + x[0] = MPFR_LIMB_LSHIFT(t, 5); + } } else /* p >= 12 */ { @@ -235,7 +243,7 @@ mpfr_mpn_rec_sqrt (mpfr_limb_ptr x, mpfr_prec_t p, /* we need h+1+as bits of a */ ahn = LIMB_SIZE(h + 1 + as); /* number of high limbs of A - needed for the recursive call*/ + needed for the recursive call */ if (MPFR_UNLIKELY(ahn > an)) ahn = an; mpfr_mpn_rec_sqrt (x + ln, h, a + an - ahn, ahn * GMP_NUMB_BITS, as); @@ -383,9 +391,10 @@ mpfr_mpn_rec_sqrt (mpfr_limb_ptr x, mpfr_prec_t p, thus we round u to nearest at bit pl-1 of u[0] */ if (pl > 0) { - cu = mpn_add_1 (u, u, un, u[0] & (MPFR_LIMB_ONE << (pl - 1))); + cu = mpn_add_1 (u, u, un, + u[0] & MPFR_LIMB_LSHIFT(MPFR_LIMB_ONE, pl - 1)); /* mask bits 0..pl-1 of u[0] */ - u[0] &= ~MPFR_LIMB_MASK(pl); + u[0] &= MPFR_LIMB(~MPFR_LIMB_MASK(pl)); } else /* round bit is in u[-1] */ cu = mpn_add_1 (u, u, un, u[-1] >> (GMP_NUMB_BITS - 1)); |