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