1 // 1 < m < 2^(cl_value_len-1), standard representation
2 // Assuming (cl_value_len <= 32).
6 static const _cl_MI fix29_plus (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y)
8 var uint32 zr = FN_to_UV(x.rep) + FN_to_UV(y.rep);
9 if (zr >= FN_to_UV(R->modulus)) { zr = zr - FN_to_UV(R->modulus); }
10 return _cl_MI(R, L_to_FN(zr));
13 static const _cl_MI fix29_minus (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y)
15 var uint32 xr = FN_to_UV(x.rep);
16 var uint32 yr = FN_to_UV(y.rep);
17 var sint32 zr = xr - yr;
18 if (zr < 0) { zr = zr + FN_to_UV(R->modulus); }
19 return _cl_MI(R, L_to_FN(zr));
22 static const _cl_MI fix29_uminus (cl_heap_modint_ring* R, const _cl_MI& x)
24 var uint32 xr = FN_to_UV(x.rep);
25 var uint32 zr = (xr==0 ? 0 : FN_to_UV(R->modulus)-xr);
26 return _cl_MI(R, L_to_FN(zr));
29 static const _cl_MI fix29_mul (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y)
31 var uint32 xr = FN_to_UV(x.rep);
32 var uint32 yr = FN_to_UV(y.rep);
35 mulu32(xr,yr,zrhi=,zrlo=);
37 divu_6432_3232(zrhi,zrlo,FN_to_UV(R->modulus),,zr=);
38 return _cl_MI(R, L_to_FN(zr));
41 static const _cl_MI fix29_square (cl_heap_modint_ring* R, const _cl_MI& x)
43 var uint32 xr = FN_to_UV(x.rep);
46 mulu32(xr,xr,zrhi=,zrlo=);
48 divu_6432_3232(zrhi,zrlo,FN_to_UV(R->modulus),,zr=);
49 return _cl_MI(R, L_to_FN(zr));
52 static cl_modint_addops fix29_addops = {
59 static cl_modint_mulops fix29_mulops = {
72 class cl_heap_modint_ring_fix29 : public cl_heap_modint_ring {
73 SUBCLASS_cl_heap_modint_ring()
76 cl_heap_modint_ring_fix29 (const cl_I& m);
78 ~cl_heap_modint_ring_fix29 () {}
81 static void cl_modint_ring_fix29_destructor (cl_heap* pointer)
83 (*(cl_heap_modint_ring_fix29*)pointer).~cl_heap_modint_ring_fix29();
86 cl_class cl_class_modint_ring_fix29 = {
87 cl_modint_ring_fix29_destructor,
88 cl_class_flags_modint_ring
92 inline cl_heap_modint_ring_fix29::cl_heap_modint_ring_fix29(const cl_I& m)
93 : cl_heap_modint_ring (m, &std_setops, &fix29_addops, &fix29_mulops)
95 type = &cl_class_modint_ring_fix29;