diff options
author | Kevin Ryde <user42@zip.com.au> | 2001-01-07 01:19:12 +0100 |
---|---|---|
committer | Kevin Ryde <user42@zip.com.au> | 2001-01-07 01:19:12 +0100 |
commit | ccc0c6f8739e3ce30e252de080bec00367bf8ed6 (patch) | |
tree | aab64756f37f39015d01d8f602ec9fd2529e8690 /mpz/kronzu.c | |
parent | e9545f777eb657335eaae0aabdc639b125f82ffe (diff) | |
download | gmp-ccc0c6f8739e3ce30e252de080bec00367bf8ed6.tar.gz |
* mpz/kronzu.c, mpz/kronzs.c, mpz/kronuz.c, mpz/kronsz.c: Use
mpn_modexact_1_odd and new JACOBI macros, various rearrangements in
support of this.
Diffstat (limited to 'mpz/kronzu.c')
-rw-r--r-- | mpz/kronzu.c | 53 |
1 files changed, 34 insertions, 19 deletions
diff --git a/mpz/kronzu.c b/mpz/kronzu.c index b6681fec8..11e552f91 100644 --- a/mpz/kronzu.c +++ b/mpz/kronzu.c @@ -1,4 +1,4 @@ -/* mpz_kronecker_ui -- Kronecker/Jacobi symbol. */ +/* mpz_kronecker_ui -- mpz+ulong Kronecker/Jacobi symbol. */ /* Copyright 1999, 2000, 2001 Free Software Foundation, Inc. @@ -26,35 +26,50 @@ MA 02111-1307, USA. #include "longlong.h" -/* This function is expected to be often used with b an odd prime, so the - code for odd b is nice and short. */ +/* This implementation depends on BITS_PER_MP_LIMB being even, so that + (a/2)^BITS_PER_MP_LIMB = 1 and so there's no need to pay attention to how + many low zero limbs are stripped. */ +#if BITS_PER_MP_LIMB % 2 != 0 +Error, error, unsupported BITS_PER_MP_LIMB +#endif + int mpz_kronecker_ui (mpz_srcptr a, unsigned long b) { - int twos; + mp_srcptr a_ptr = PTR(a); + int a_size = SIZ(a); + mp_limb_t a_rem; + int result_bit1; if (b & 1) { - if (b != 1) - return mpn_jacobi_base (mpz_fdiv_ui (a, b), b, 0); - else - return 1; /* (a/1)=1 for any a */ + result_bit1 = JACOBI_ASGN_SU_BIT1 (a_size, b); } + else + { + mp_limb_t a_low = a_ptr[0]; + int twos; - if (b == 0) - return JACOBI_Z0 (a); + if (b == 0) + return JACOBI_LS0 (a_low, a_size); /* (a/0) */ - /* (a/2)=0 if a even */ - if (mpz_even_p (a)) - return 0; + if (! (a_low & 1)) + return 0; /* (even/even)=0 */ + + /* (a/2)=(2/a) for a odd */ + count_trailing_zeros (twos, b); + b >>= twos; + result_bit1 = (JACOBI_TWOS_U_BIT1 (twos, a_low) + ^ JACOBI_ASGN_SU_BIT1 (a_size, b)); + } - /* (a/2)=(2/a) when a odd */ - count_trailing_zeros (twos, b); - b >>= twos; if (b == 1) - return JACOBI_TWOS_U (twos, PTR(a)[0]); + return JACOBI_BIT1_TO_PN (result_bit1); /* (a/1)=1 for any a */ + + a_size = ABS(a_size); - return mpn_jacobi_base (mpz_fdiv_ui (a, b), b, - JACOBI_TWOS_U_BIT1(twos, PTR(a)[0])); + /* (a/b) = (a mod b / b) */ + JACOBI_MOD_OR_MODEXACT_1_ODD (result_bit1, a_rem, a_ptr, a_size, b); + return mpn_jacobi_base (a_rem, (mp_limb_t) b, result_bit1); } |