]> www.ginac.de Git - cln.git/blob - src/modinteger/cl_MI_fix29.h
* All Files have been modified for inclusion of namespace cln;
[cln.git] / src / modinteger / cl_MI_fix29.h
1 // 1 < m < 2^(cl_value_len-1), standard representation
2 // Assuming (cl_value_len <= 32).
3
4 namespace cln {
5
6 static const _cl_MI fix29_plus (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y)
7 {
8         var uint32 zr = FN_to_UL(x.rep) + FN_to_UL(y.rep);
9         if (zr >= FN_to_UL(R->modulus)) { zr = zr - FN_to_UL(R->modulus); }
10         return _cl_MI(R, L_to_FN(zr));
11 }
12
13 static const _cl_MI fix29_minus (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y)
14 {
15         var uint32 xr = FN_to_UL(x.rep);
16         var uint32 yr = FN_to_UL(y.rep);
17         var sint32 zr = xr - yr;
18         if (zr < 0) { zr = zr + FN_to_UL(R->modulus); }
19         return _cl_MI(R, L_to_FN(zr));
20 }
21
22 static const _cl_MI fix29_uminus (cl_heap_modint_ring* R, const _cl_MI& x)
23 {
24         var uint32 xr = FN_to_UL(x.rep);
25         var uint32 zr = (xr==0 ? 0 : FN_to_UL(R->modulus)-xr);
26         return _cl_MI(R, L_to_FN(zr));
27 }
28
29 static const _cl_MI fix29_mul (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y)
30 {
31         var uint32 xr = FN_to_UL(x.rep);
32         var uint32 yr = FN_to_UL(y.rep);
33         var uint32 zrhi;
34         var uint32 zrlo;
35         mulu32(xr,yr,zrhi=,zrlo=);
36         var uint32 zr;
37         divu_6432_3232(zrhi,zrlo,FN_to_UL(R->modulus),,zr=);
38         return _cl_MI(R, L_to_FN(zr));
39 }
40
41 static const _cl_MI fix29_square (cl_heap_modint_ring* R, const _cl_MI& x)
42 {
43         var uint32 xr = FN_to_UL(x.rep);
44         var uint32 zrhi;
45         var uint32 zrlo;
46         mulu32(xr,xr,zrhi=,zrlo=);
47         var uint32 zr;
48         divu_6432_3232(zrhi,zrlo,FN_to_UL(R->modulus),,zr=);
49         return _cl_MI(R, L_to_FN(zr));
50 }
51
52 static cl_modint_addops fix29_addops = {
53         std_zero,
54         std_zerop,
55         fix29_plus,
56         fix29_minus,
57         fix29_uminus
58 };
59 static cl_modint_mulops fix29_mulops = {
60         std_one,
61         std_canonhom,
62         fix29_mul,
63         fix29_square,
64         std_expt_pos,
65         std_recip,
66         std_div,
67         std_expt,
68         std_reduce_modulo,
69         std_retract
70 };
71
72 class cl_heap_modint_ring_fix29 : public cl_heap_modint_ring {
73         SUBCLASS_cl_heap_modint_ring()
74 public:
75         // Constructor.
76         cl_heap_modint_ring_fix29 (const cl_I& m)
77                 : cl_heap_modint_ring (m, &std_setops, &fix29_addops, &fix29_mulops) {}
78         // Virtual destructor.
79         ~cl_heap_modint_ring_fix29 () {}
80 };
81
82 }  // namespace cln