From f3c1ce476e8e419e5820ae368e8a5474a26aee87 Mon Sep 17 00:00:00 2001 From: tege Date: Tue, 30 Apr 2002 03:48:13 +0200 Subject: Nailify (and uglify). --- extract-dbl.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 69 insertions(+), 15 deletions(-) (limited to 'extract-dbl.c') diff --git a/extract-dbl.c b/extract-dbl.c index 983b56ef7..ba22af781 100644 --- a/extract-dbl.c +++ b/extract-dbl.c @@ -41,9 +41,9 @@ __gmp_extract_double (mp_ptr rp, double d) unsigned sc; #ifdef _LONG_LONG_LIMB #define BITS_PER_PART 64 /* somewhat bogus */ - unsigned long long int manh, manl; + unsigned long long int manl; #else -#define BITS_PER_PART BITS_PER_MP_LIMB +#define BITS_PER_PART GMP_LIMB_BITS unsigned long int manh, manl; #endif @@ -51,7 +51,7 @@ __gmp_extract_double (mp_ptr rp, double d) 1. Should handle Inf and NaN in IEEE specific code. 2. Handle Inf and NaN also in default code, to avoid hangs. - 3. Generalize to handle all BITS_PER_MP_LIMB >= 32. + 3. Generalize to handle all GMP_LIMB_BITS >= 32. 4. This lits is incomplete and misspelled. */ @@ -158,15 +158,16 @@ __gmp_extract_double (mp_ptr rp, double d) to split manh,,manl into an array of LIMBS_PER_DOUBLE limbs. */ - sc = (unsigned) exp % BITS_PER_MP_LIMB; + sc = (unsigned) (exp + 64 * GMP_NUMB_BITS) % GMP_NUMB_BITS; /* We add something here to get rounding right. */ - exp = (exp + 2048) / BITS_PER_MP_LIMB - 2048 / BITS_PER_MP_LIMB + 1; + exp = (exp + 64 * GMP_NUMB_BITS) / GMP_NUMB_BITS - 64 * GMP_NUMB_BITS / GMP_NUMB_BITS + 1; #if LIMBS_PER_DOUBLE == 2 +#if GMP_NAIL_BITS == 0 if (sc != 0) { - rp[1] = manl >> (BITS_PER_MP_LIMB - sc); + rp[1] = manl >> (GMP_LIMB_BITS - sc); rp[0] = manl << sc; } else @@ -175,12 +176,35 @@ __gmp_extract_double (mp_ptr rp, double d) rp[0] = 0; exp--; } +#else + if (sc > GMP_NAIL_BITS) + { + rp[1] = manl >> (GMP_LIMB_BITS - sc); + rp[0] = (manl << (sc - GMP_NAIL_BITS)) & GMP_NUMB_MASK; + } + else + { + if (sc == 0) + { + rp[1] = manl >> GMP_NAIL_BITS; + rp[0] = (manl << GMP_NUMB_BITS - GMP_NAIL_BITS) & GMP_NUMB_MASK; + exp--; + } + else + { + rp[1] = manl >> (GMP_LIMB_BITS - sc); + rp[0] = (manl >> (GMP_NAIL_BITS - sc)) & GMP_NUMB_MASK; + } + } #endif +#endif + #if LIMBS_PER_DOUBLE == 3 +#if GMP_NAIL_BITS == 0 if (sc != 0) { - rp[2] = manh >> (BITS_PER_MP_LIMB - sc); - rp[1] = (manl >> (BITS_PER_MP_LIMB - sc)) | (manh << sc); + rp[2] = manh >> (GMP_LIMB_BITS - sc); + rp[1] = (manh << sc) | (manl >> (GMP_LIMB_BITS - sc)); rp[0] = manl << sc; } else @@ -190,26 +214,56 @@ __gmp_extract_double (mp_ptr rp, double d) rp[0] = 0; exp--; } +#else + if (sc > GMP_NAIL_BITS) + { + rp[2] = (manh >> (GMP_LIMB_BITS - sc)); + rp[1] = ((manh << (sc - GMP_NAIL_BITS)) | + (manl >> (GMP_LIMB_BITS - sc + GMP_NAIL_BITS))) & GMP_NUMB_MASK; + if (sc >= 2 * GMP_NAIL_BITS) + rp[0] = (manl << sc - 2 * GMP_NAIL_BITS) & GMP_NUMB_MASK; + else + rp[0] = manl >> (2 * GMP_NAIL_BITS - sc) & GMP_NUMB_MASK; + } + else + { + if (sc == 0) + { + rp[2] = manh >> GMP_NAIL_BITS; + rp[1] = ((manh << GMP_NUMB_BITS - GMP_NAIL_BITS) | (manl >> 2 * GMP_NAIL_BITS)) & GMP_NUMB_MASK; + rp[0] = 0; + exp--; + } + else + { + rp[2] = (manh >> (GMP_LIMB_BITS - sc)); + rp[1] = (manh >> (GMP_NAIL_BITS - sc)) & GMP_NUMB_MASK; + rp[0] = ((manh << (GMP_NUMB_BITS - GMP_NAIL_BITS + sc)) + | (manl >> (GMP_LIMB_BITS - (GMP_NUMB_BITS - GMP_NAIL_BITS + sc)))) & GMP_NUMB_MASK; + } + } #endif +#endif + #if LIMBS_PER_DOUBLE > 3 /* Insert code for splitting manh,,manl into LIMBS_PER_DOUBLE mp_limb_t's at rp. */ if (sc != 0) { - /* This is not perfect, and would fail for BITS_PER_MP_LIMB == 16. + /* This is not perfect, and would fail for GMP_LIMB_BITS == 16. The ASSERT_ALWAYS should catch the problematic cases. */ ASSERT_ALWAYS ((manl << sc) == 0); - manl = (manh << sc) | (manl >> (BITS_PER_MP_LIMB - sc)); - manh = manh >> (BITS_PER_MP_LIMB - sc); + manl = (manh << sc) | (manl >> (GMP_LIMB_BITS - sc)); + manh = manh >> (GMP_LIMB_BITS - sc); } { int i; for (i = LIMBS_PER_DOUBLE - 1; i >= 0; i--) { - rp[i] = manh >> (BITS_PER_LONGINT - BITS_PER_MP_LIMB); - manh = ((manh << BITS_PER_MP_LIMB) - | (manl >> (BITS_PER_LONGINT - BITS_PER_MP_LIMB))); - manl = manl << BITS_PER_MP_LIMB; + rp[i] = manh >> (BITS_PER_LONGINT - GMP_LIMB_BITS); + manh = ((manh << GMP_LIMB_BITS) + | (manl >> (BITS_PER_LONGINT - GMP_LIMB_BITS))); + manl = manl << GMP_LIMB_BITS; } } #endif -- cgit v1.2.1