1 // 1 < m < 2^16, standard representation
5 static const _cl_MI fix16_plus (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y)
7 var uint32 zr = FN_to_UL(x.rep) + FN_to_UL(y.rep);
8 if (zr >= FN_to_UL(R->modulus)) { zr = zr - FN_to_UL(R->modulus); }
9 return _cl_MI(R, L_to_FN(zr));
12 static const _cl_MI fix16_minus (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y)
14 var uint32 xr = FN_to_UL(x.rep);
15 var uint32 yr = FN_to_UL(y.rep);
16 var sint32 zr = xr - yr;
17 if (zr < 0) { zr = zr + FN_to_UL(R->modulus); }
18 return _cl_MI(R, L_to_FN(zr));
21 static const _cl_MI fix16_uminus (cl_heap_modint_ring* R, const _cl_MI& x)
23 var uint32 xr = FN_to_UL(x.rep);
24 var uint32 zr = (xr==0 ? 0 : FN_to_UL(R->modulus)-xr);
25 return _cl_MI(R, L_to_FN(zr));
28 static const _cl_MI fix16_mul (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y)
30 var uint32 xr = FN_to_UL(x.rep);
31 var uint32 yr = FN_to_UL(y.rep);
32 var uint32 zr = mulu16(xr,yr);
33 divu_3216_1616(zr,FN_to_UL(R->modulus),,zr=);
34 return _cl_MI(R, L_to_FN(zr));
37 static const _cl_MI fix16_square (cl_heap_modint_ring* R, const _cl_MI& x)
39 var uint32 xr = FN_to_UL(x.rep);
40 var uint32 zr = mulu16(xr,xr);
41 divu_3216_1616(zr,FN_to_UL(R->modulus),,zr=);
42 return _cl_MI(R, L_to_FN(zr));
45 static cl_modint_addops fix16_addops = {
52 static cl_modint_mulops fix16_mulops = {
65 class cl_heap_modint_ring_fix16 : public cl_heap_modint_ring {
66 SUBCLASS_cl_heap_modint_ring()
69 cl_heap_modint_ring_fix16 (const cl_I& m)
70 : cl_heap_modint_ring (m, &std_setops, &fix16_addops, &fix16_mulops) {}
71 // Virtual destructor.
72 ~cl_heap_modint_ring_fix16 () {}