1 // 1 < m < 2^32, standard representation
3 static const _cl_MI int32_plus (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y)
5 var uint32 xr = cl_I_to_UL(x.rep);
6 var uint32 yr = cl_I_to_UL(y.rep);
7 var uint32 zr = xr + yr;
8 var uint32 m = cl_I_to_UL(R->modulus);
9 if ((zr < xr) || (zr >= m)) { zr = zr - m; }
10 return _cl_MI(R, UL_to_I(zr));
13 static const _cl_MI int32_minus (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y)
15 var uint32 xr = cl_I_to_UL(x.rep);
16 var uint32 yr = cl_I_to_UL(y.rep);
17 var sint32 zr = (xr >= yr ? xr - yr : xr - yr + cl_I_to_UL(R->modulus));
18 return _cl_MI(R, UL_to_I(zr));
21 static const _cl_MI int32_uminus (cl_heap_modint_ring* R, const _cl_MI& x)
23 var uint32 xr = cl_I_to_UL(x.rep);
24 var uint32 zr = (xr==0 ? 0 : cl_I_to_UL(R->modulus)-xr);
25 return _cl_MI(R, UL_to_I(zr));
28 static const _cl_MI int32_mul (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y)
30 var uint32 xr = cl_I_to_UL(x.rep);
31 var uint32 yr = cl_I_to_UL(y.rep);
34 mulu32(xr,yr,zrhi=,zrlo=);
36 divu_6432_3232(zrhi,zrlo,cl_I_to_UL(R->modulus),,zr=);
37 return _cl_MI(R, UL_to_I(zr));
40 static const _cl_MI int32_square (cl_heap_modint_ring* R, const _cl_MI& x)
42 var uint32 xr = cl_I_to_UL(x.rep);
45 mulu32(xr,xr,zrhi=,zrlo=);
47 divu_6432_3232(zrhi,zrlo,cl_I_to_UL(R->modulus),,zr=);
48 return _cl_MI(R, UL_to_I(zr));
51 static cl_modint_addops int32_addops = {
58 static cl_modint_mulops int32_mulops = {
71 class cl_heap_modint_ring_int32 : public cl_heap_modint_ring {
72 SUBCLASS_cl_heap_modint_ring()
75 cl_heap_modint_ring_int32 (const cl_I& m)
76 : cl_heap_modint_ring (m, &std_setops, &int32_addops, &int32_mulops) {}
77 // Virtual destructor.
78 ~cl_heap_modint_ring_int32 () {}