Branch: Tag:

2003-05-19

2003-05-19 19:23:41 by Martin Stjernholm <mast@lysator.liu.se>

Moved PIKE_MPZ_SET_SI to my_gmp.h. Fixes to use the MPZ_GETLIMBN macro.

Rev: src/modules/Gmp/mpz_glue.c:1.149
Rev: src/modules/Gmp/my_gmp.h:1.21

2:   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: mpz_glue.c,v 1.148 2003/05/19 19:02:17 mast Exp $ + || $Id: mpz_glue.c,v 1.149 2003/05/19 19:23:41 mast Exp $   */      #include "global.h" - RCSID("$Id: mpz_glue.c,v 1.148 2003/05/19 19:02:17 mast Exp $"); + RCSID("$Id: mpz_glue.c,v 1.149 2003/05/19 19:23:41 mast Exp $");   #include "gmp_machine.h"   #include "module.h"   
66:   struct program *bignum_program;   #endif    - #if !defined(HAVE_MPZ_IMPORT) && !defined(NO_MPZ_SET_SI_KLUDGE) - /* Old gmp libraries have a broken implementation of mpz_set_si(), -  * which handles -0x80000000 incorrectly -  * (it results in -0xffffffff80000000)... -  * -  * FIXME: Should have a configure test for this. -  * /grubba 2003-05-17 -  */ - #define PIKE_MPZ_SET_SI(MPZ_VAL, VALUE) do { \ -  long val_ = (VALUE); \ -  if (val_ < 0) { \ -  mpz_set_ui((MPZ_VAL), (unsigned long) -val_); \ -  mpz_neg((MPZ_VAL), (MPZ_VAL)); \ -  } else { \ -  mpz_set_ui((MPZ_VAL), (unsigned long) val_); \ -  } \ -  } while(0) - #else /* HAVE_MPZ_IMPORT || NO_MPZ_SET_SI_KLUDGE */ - #define PIKE_MPZ_SET_SI(MPZ_VAL, VALUE) mpz_set_si((MPZ_VAL), (VALUE)) - #endif /* !HAVE_MPZ_IMPORT || !NO_MPZ_SET_SI_KLUDGE */ -  +    #ifdef AUTO_BIGNUM   static mpz_t mpz_int_type_min;   
96: Inside #if defined(AUTO_BIGNUM)
   int neg = mpz_sgn (mpz) < 0;    INT_TYPE res = 0;    +  /* Note: Similar code in gmp_int64_from_bignum. */ +     /* Get the index of the highest limb that has bits within the range    * of the INT_TYPE. */    size_t pos = (INT_TYPE_BITS + GMP_NUMB_BITS - 1) / GMP_NUMB_BITS - 1;
106: Inside #if defined(AUTO_BIGNUM) and #if INT_TYPE_BITS == GMP_NUMB_BITS
   */   #if INT_TYPE_BITS == GMP_NUMB_BITS    /* NOTE: Overflow is not possible. */ -  res = mpz_getlimbn (mpz, 0) & GMP_NUMB_MASK; +  res = MPZ_GETLIMBN (mpz, 0) & GMP_NUMB_MASK;   #elif INT_TYPE_BITS < GMP_NUMB_BITS -  mp_limb_t val = mpz_getlimbn (mpz, 0) & GMP_NUMB_MASK; +  mp_limb_t val = MPZ_GETLIMBN (mpz, 0) & GMP_NUMB_MASK;    if (val >= (mp_limb_t) 1 << INT_TYPE_BITS) goto overflow;    res = val;   #else    for (;; pos--) { -  res |= mpz_getlimbn (mpz, pos) & GMP_NUMB_MASK; +  res |= MPZ_GETLIMBN (mpz, pos) & GMP_NUMB_MASK;    if (pos == 0) break;    if (res >= (INT_TYPE) 1 << (INT_TYPE_BITS - GMP_NUMB_BITS)) goto overflow;    res <<= GMP_NUMB_BITS;
197:    int neg = mpz_sgn (mpz) < 0;    INT64 res = 0;    +  /* Note: Similar code in mpzmod_reduce. */ +     /* Get the index of the highest limb that have bits within the range    * of the INT64. */    size_t pos = (INT64_BITS + GMP_NUMB_BITS - 1) / GMP_NUMB_BITS - 1;
207:       if (mpz_size (mpz) <= pos + 1) {   #if INT64_BITS == GMP_NUMB_BITS -  res = mpz_getlimbn (mpz, 0) & GMP_NUMB_MASK; +  res = MPZ_GETLIMBN (mpz, 0) & GMP_NUMB_MASK;   #elif INT64_BITS < GMP_NUMB_BITS -  mp_limb_t val = mpz_getlimbn (mpz, 0) & GMP_NUMB_MASK; +  mp_limb_t val = MPZ_GETLIMBN (mpz, 0) & GMP_NUMB_MASK;    if (val >= (mp_limb_t) 1 << INT64_BITS) goto overflow;    res = val;   #else    for (;; pos--) { -  res |= mpz_getlimbn (mpz, pos) & GMP_NUMB_MASK; +  res |= MPZ_GETLIMBN (mpz, pos) & GMP_NUMB_MASK;    if (pos == 0) break;    if (res >= (INT64) 1 << (INT64_BITS - GMP_NUMB_BITS)) goto overflow;    res <<= GMP_NUMB_BITS;
566:       while (len > 0)    { -  mp_limb_t x = mpz_getlimbn (mpz, pos++); +  mp_limb_t x = MPZ_GETLIMBN (mpz, pos++);    for (i=0; i<sizeof(mp_limb_t); i++)    {    *(--dst) = DO_NOT_WARN((unsigned char)(x & 0xff));
775:   #error Cannot cope with GMP using nail bits.   #endif    -  mp_limb_t x = (length-->0? mpz_getlimbn(n, pos++) : 0); +  mp_limb_t x = (length-->0? MPZ_GETLIMBN(n, pos++) : 0);       if (!flag_left)    for(i = 0; i < (INT_TYPE)sizeof(mp_limb_t); i++)