1 // 1 < m < 2^16, standard representation
3 static const _cl_MI fix16_plus (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y)
5 var uint32 zr = FN_to_UL(x.rep) + FN_to_UL(y.rep);
6 if (zr >= FN_to_UL(R->modulus)) { zr = zr - FN_to_UL(R->modulus); }
7 return _cl_MI(R, L_to_FN(zr));
10 static const _cl_MI fix16_minus (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y)
12 var uint32 xr = FN_to_UL(x.rep);
13 var uint32 yr = FN_to_UL(y.rep);
14 var sint32 zr = xr - yr;
15 if (zr < 0) { zr = zr + FN_to_UL(R->modulus); }
16 return _cl_MI(R, L_to_FN(zr));
19 static const _cl_MI fix16_uminus (cl_heap_modint_ring* R, const _cl_MI& x)
21 var uint32 xr = FN_to_UL(x.rep);
22 var uint32 zr = (xr==0 ? 0 : FN_to_UL(R->modulus)-xr);
23 return _cl_MI(R, L_to_FN(zr));
26 static const _cl_MI fix16_mul (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y)
28 var uint32 xr = FN_to_UL(x.rep);
29 var uint32 yr = FN_to_UL(y.rep);
30 var uint32 zr = mulu16(xr,yr);
31 divu_3216_1616(zr,FN_to_UL(R->modulus),,zr=);
32 return _cl_MI(R, L_to_FN(zr));
35 static const _cl_MI fix16_square (cl_heap_modint_ring* R, const _cl_MI& x)
37 var uint32 xr = FN_to_UL(x.rep);
38 var uint32 zr = mulu16(xr,xr);
39 divu_3216_1616(zr,FN_to_UL(R->modulus),,zr=);
40 return _cl_MI(R, L_to_FN(zr));
43 static cl_modint_addops fix16_addops = {
50 static cl_modint_mulops fix16_mulops = {
63 class cl_heap_modint_ring_fix16 : public cl_heap_modint_ring {
64 SUBCLASS_cl_heap_modint_ring()
67 cl_heap_modint_ring_fix16 (const cl_I& m)
68 : cl_heap_modint_ring (m, &std_setops, &fix16_addops, &fix16_mulops) {}
69 // Virtual destructor.
70 ~cl_heap_modint_ring_fix16 () {}