1 // 1 < m < 2^(cl_value_len-1), standard representation
2 // Assuming (cl_value_len <= 32).
4 static const _cl_MI fix29_plus (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y)
6 var uint32 zr = FN_to_UL(x.rep) + FN_to_UL(y.rep);
7 if (zr >= FN_to_UL(R->modulus)) { zr = zr - FN_to_UL(R->modulus); }
8 return _cl_MI(R, L_to_FN(zr));
11 static const _cl_MI fix29_minus (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y)
13 var uint32 xr = FN_to_UL(x.rep);
14 var uint32 yr = FN_to_UL(y.rep);
15 var sint32 zr = xr - yr;
16 if (zr < 0) { zr = zr + FN_to_UL(R->modulus); }
17 return _cl_MI(R, L_to_FN(zr));
20 static const _cl_MI fix29_uminus (cl_heap_modint_ring* R, const _cl_MI& x)
22 var uint32 xr = FN_to_UL(x.rep);
23 var uint32 zr = (xr==0 ? 0 : FN_to_UL(R->modulus)-xr);
24 return _cl_MI(R, L_to_FN(zr));
27 static const _cl_MI fix29_mul (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y)
29 var uint32 xr = FN_to_UL(x.rep);
30 var uint32 yr = FN_to_UL(y.rep);
33 mulu32(xr,yr,zrhi=,zrlo=);
35 divu_6432_3232(zrhi,zrlo,FN_to_UL(R->modulus),,zr=);
36 return _cl_MI(R, L_to_FN(zr));
39 static const _cl_MI fix29_square (cl_heap_modint_ring* R, const _cl_MI& x)
41 var uint32 xr = FN_to_UL(x.rep);
44 mulu32(xr,xr,zrhi=,zrlo=);
46 divu_6432_3232(zrhi,zrlo,FN_to_UL(R->modulus),,zr=);
47 return _cl_MI(R, L_to_FN(zr));
50 static cl_modint_addops fix29_addops = {
57 static cl_modint_mulops fix29_mulops = {
70 class cl_heap_modint_ring_fix29 : public cl_heap_modint_ring {
71 SUBCLASS_cl_heap_modint_ring()
74 cl_heap_modint_ring_fix29 (const cl_I& m)
75 : cl_heap_modint_ring (m, &std_setops, &fix29_addops, &fix29_mulops) {}
76 // Virtual destructor.
77 ~cl_heap_modint_ring_fix29 () {}