1 // 1 < m < 2^32, standard representation
5 static const _cl_MI int32_plus (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y)
7 var uint32 xr = cl_I_to_UL(x.rep);
8 var uint32 yr = cl_I_to_UL(y.rep);
9 var uint32 zr = xr + yr;
10 var uint32 m = cl_I_to_UL(R->modulus);
11 if ((zr < xr) || (zr >= m)) { zr = zr - m; }
12 return _cl_MI(R, UL_to_I(zr));
15 static const _cl_MI int32_minus (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y)
17 var uint32 xr = cl_I_to_UL(x.rep);
18 var uint32 yr = cl_I_to_UL(y.rep);
19 var sint32 zr = (xr >= yr ? xr - yr : xr - yr + cl_I_to_UL(R->modulus));
20 return _cl_MI(R, UL_to_I(zr));
23 static const _cl_MI int32_uminus (cl_heap_modint_ring* R, const _cl_MI& x)
25 var uint32 xr = cl_I_to_UL(x.rep);
26 var uint32 zr = (xr==0 ? 0 : cl_I_to_UL(R->modulus)-xr);
27 return _cl_MI(R, UL_to_I(zr));
30 static const _cl_MI int32_mul (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y)
32 var uint32 xr = cl_I_to_UL(x.rep);
33 var uint32 yr = cl_I_to_UL(y.rep);
36 mulu32(xr,yr,zrhi=,zrlo=);
38 divu_6432_3232(zrhi,zrlo,cl_I_to_UL(R->modulus),,zr=);
39 return _cl_MI(R, UL_to_I(zr));
42 static const _cl_MI int32_square (cl_heap_modint_ring* R, const _cl_MI& x)
44 var uint32 xr = cl_I_to_UL(x.rep);
47 mulu32(xr,xr,zrhi=,zrlo=);
49 divu_6432_3232(zrhi,zrlo,cl_I_to_UL(R->modulus),,zr=);
50 return _cl_MI(R, UL_to_I(zr));
53 static cl_modint_addops int32_addops = {
60 static cl_modint_mulops int32_mulops = {
73 class cl_heap_modint_ring_int32 : public cl_heap_modint_ring {
74 SUBCLASS_cl_heap_modint_ring()
77 cl_heap_modint_ring_int32 (const cl_I& m);
79 ~cl_heap_modint_ring_int32 () {}
82 static void cl_modint_ring_int32_destructor (cl_heap* pointer)
84 (*(cl_heap_modint_ring_int32*)pointer).~cl_heap_modint_ring_int32();
87 cl_class cl_class_modint_ring_int32 = {
88 cl_modint_ring_int32_destructor,
89 cl_class_flags_modint_ring
93 inline cl_heap_modint_ring_int32::cl_heap_modint_ring_int32(const cl_I& m)
94 : cl_heap_modint_ring (m, &std_setops, &int32_addops, &int32_mulops)
96 type = &cl_class_modint_ring_int32;