diff options
author | Kevin Ryde <user42@zip.com.au> | 2002-05-09 02:11:32 +0200 |
---|---|---|
committer | Kevin Ryde <user42@zip.com.au> | 2002-05-09 02:11:32 +0200 |
commit | 60ef39553f40c5e343c55c02ae890214c272514f (patch) | |
tree | ac6345536e025d4d221691b48a1af937b5732001 /mpz/import.c | |
parent | 90ff2c5a63333a7b5b589c2ed38e6fd92c4d5cf2 (diff) | |
download | gmp-60ef39553f40c5e343c55c02ae890214c272514f.tar.gz |
* mpz/import.c: Corrections to size store, special case tests, and
general case ACCUMULATE.
Diffstat (limited to 'mpz/import.c')
-rw-r--r-- | mpz/import.c | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/mpz/import.c b/mpz/import.c index e06afaab5..becb9fd6e 100644 --- a/mpz/import.c +++ b/mpz/import.c @@ -54,7 +54,9 @@ mpz_import (mpz_ptr z, size_t count, int order, if (endian == 0) endian = HOST_ENDIAN; - if (nail == GMP_NAIL_BITS) + /* Can't use these special cases with nails currently, since they don't + mask out the nail bits in the input data. */ + if (nail == 0 && GMP_NAIL_BITS == 0) { unsigned align = (unsigned) data % sizeof (mp_limb_t); @@ -64,7 +66,7 @@ mpz_import (mpz_ptr z, size_t count, int order, && align == 0) { MPN_COPY (zp, (mp_srcptr) data, (mp_size_t) count); - return; + goto done; } if (order == -1 @@ -73,7 +75,7 @@ mpz_import (mpz_ptr z, size_t count, int order, && align == 0) { MPN_BSWAP (zp, (mp_srcptr) data, (mp_size_t) count); - return; + goto done; } if (order == 1 @@ -82,7 +84,7 @@ mpz_import (mpz_ptr z, size_t count, int order, && align == 0) { MPN_REVERSE (zp, (mp_srcptr) data, (mp_size_t) count); - return; + goto done; } } @@ -111,17 +113,20 @@ mpz_import (mpz_ptr z, size_t count, int order, dp = (unsigned char *) data + (order >= 0 ? (count-1)*size : 0) + (endian >= 0 ? size-1 : 0); -#define ACCUMULATE(N) \ - do { \ - limb |= (mp_limb_t) byte << lbits; \ - lbits += (N); \ - if (lbits >= GMP_NUMB_BITS) \ - { \ - *zp++ = limb & GMP_NUMB_MASK; \ - lbits -= GMP_NUMB_BITS; \ - ASSERT (lbits < 8); \ - limb = byte >> (8 - lbits); \ - } \ +#define ACCUMULATE(N) \ + do { \ + ASSERT (lbits < GMP_NUMB_BITS); \ + ASSERT (limb <= (CNST_LIMB(1) << lbits) - 1); \ + \ + limb |= (mp_limb_t) byte << lbits; \ + lbits += (N); \ + if (lbits >= GMP_NUMB_BITS) \ + { \ + *zp++ = limb & GMP_NUMB_MASK; \ + lbits -= GMP_NUMB_BITS; \ + ASSERT (lbits < (N)); \ + limb = byte >> ((N) - lbits); \ + } \ } while (0) limb = 0; @@ -157,8 +162,10 @@ mpz_import (mpz_ptr z, size_t count, int order, + (order < 0 ? count*size : - (mp_size_t) size) + (endian >= 0 ? (mp_size_t) size - 1 : 0)); - zp = PTR(z); - MPN_NORMALIZE (zp, zsize); - SIZ(z) = zsize; } + + done: + zp = PTR(z); + MPN_NORMALIZE (zp, zsize); + SIZ(z) = zsize; } |