Annotation of OpenXM_contrib2/asir2018/engine/N.c, Revision 1.2
1.2 ! noro 1: #include "gmp.h"
! 2:
! 3: unsigned long mul64(unsigned long a,unsigned long b,unsigned long *c)
! 4: {
! 5: unsigned long u;
! 6: u = (unsigned long)mpn_mul_1((mp_limb_t *)c,(mp_limb_t *)&a,1,(mp_limb_t)b);
! 7: c[1] = u;
! 8: return u;
! 9: }
! 10:
! 11: unsigned long mod64(unsigned long u,unsigned long l,unsigned long b)
! 12: {
! 13: unsigned long q[2],d[2];
! 14: unsigned long r;
! 15:
! 16: d[0] = l; d[1] = u;
! 17: r = (unsigned long)mpn_divmod_1((mp_limb_t *)q,(mp_limb_t *)d,2,(mp_limb_t)b);
! 18: return r;
! 19: }
! 20:
! 21: unsigned long mulmod64(unsigned long a,unsigned long b,unsigned long m)
! 22: {
! 23: unsigned long d[2],q[2];
! 24: unsigned long r;
! 25:
! 26: d[1] = (unsigned long)mpn_mul_1(d,(mp_limb_t *)&a,1,(mp_limb_t)b);
! 27: r = (unsigned long)mpn_divmod_1((mp_limb_t *)q,(mp_limb_t *)d,2,(mp_limb_t)m);
! 28: return r;
! 29: }
! 30:
! 31: unsigned long muladdmod64(unsigned long a,unsigned long b,unsigned long c,unsigned long m)
! 32: {
! 33: unsigned long d[2],q[2];
! 34: unsigned long r;
! 35:
! 36: d[0] = c;
! 37: d[1] = (unsigned long)mpn_addmul_1(d,(mp_limb_t *)&a,1,(mp_limb_t)b);
! 38: r = (unsigned long)mpn_divmod_1((mp_limb_t *)q,(mp_limb_t *)d,2,(mp_limb_t)m);
! 39: return r;
! 40: }
! 41:
! 42: unsigned long invmod64(unsigned long a,unsigned long m)
! 43: {
! 44: mpz_t x,y,z;
! 45:
! 46: mpz_init_set_ui(x,a);
! 47: mpz_init_set_ui(y,m);
! 48: mpz_invert(z,x,y);
! 49: return mpz_get_ui(z);
! 50: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>