1 // 1 < m < 2^32, standard representation
2 // Assuming (cl_value_len > 32).
6 static const _cl_MI fix32_plus (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y)
8 var uint32 xr = FN_to_UL(x.rep);
9 var uint32 yr = FN_to_UL(y.rep);
10 var uint32 zr = xr + yr;
11 var uint32 m = FN_to_UL(R->modulus);
12 if ((zr < xr) || (zr >= m)) { zr = zr - m; }
13 return _cl_MI(R, L_to_FN(zr));
16 static const _cl_MI fix32_minus (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y)
18 var uint32 xr = FN_to_UL(x.rep);
19 var uint32 yr = FN_to_UL(y.rep);
20 var sint32 zr = (xr >= yr ? xr - yr : xr - yr + FN_to_UL(R->modulus));
21 return _cl_MI(R, L_to_FN(zr));
24 static const _cl_MI fix32_uminus (cl_heap_modint_ring* R, const _cl_MI& x)
26 var uint32 xr = FN_to_UL(x.rep);
27 var uint32 zr = (xr==0 ? 0 : FN_to_UL(R->modulus)-xr);
28 return _cl_MI(R, L_to_FN(zr));
31 static const _cl_MI fix32_mul (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y)
33 var uint32 xr = FN_to_UL(x.rep);
34 var uint32 yr = FN_to_UL(y.rep);
37 mulu32(xr,yr,zrhi=,zrlo=);
39 divu_6432_3232(zrhi,zrlo,FN_to_UL(R->modulus),,zr=);
40 return _cl_MI(R, L_to_FN(zr));
43 static const _cl_MI fix32_square (cl_heap_modint_ring* R, const _cl_MI& x)
45 var uint32 xr = FN_to_UL(x.rep);
48 mulu32(xr,xr,zrhi=,zrlo=);
50 divu_6432_3232(zrhi,zrlo,FN_to_UL(R->modulus),,zr=);
51 return _cl_MI(R, L_to_FN(zr));
54 static cl_modint_addops fix32_addops = {
61 static cl_modint_mulops fix32_mulops = {
74 class cl_heap_modint_ring_fix32 : public cl_heap_modint_ring {
75 SUBCLASS_cl_heap_modint_ring()
78 cl_heap_modint_ring_fix32 (const cl_I& m)
79 : cl_heap_modint_ring (m, &std_setops, &fix32_addops, &fix32_mulops) {}
80 // Virtual destructor.
81 ~cl_heap_modint_ring_fix32 () {}