]> www.ginac.de Git - cln.git/blob - src/modinteger/cl_MI_int32.h
Avoid some "suggest explicit braces to avoid ambiguous ‘else’" warnings.
[cln.git] / src / modinteger / cl_MI_int32.h
1 // 1 < m < 2^32, standard representation
2
3 namespace cln {
4
5 static const _cl_MI int32_plus (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y)
6 {
7         var uint32 xr = cl_I_to_UL(x.rep);
8         var uint32 yr = cl_I_to_UL(y.rep);
9         var uint32 zr = xr + yr;
10         var uint32 m = cl_I_to_UL(R->modulus);
11         if ((zr < xr) || (zr >= m)) { zr = zr - m; }
12         return _cl_MI(R, UL_to_I(zr));
13 }
14
15 static const _cl_MI int32_minus (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y)
16 {
17         var uint32 xr = cl_I_to_UL(x.rep);
18         var uint32 yr = cl_I_to_UL(y.rep);
19         var sint32 zr = (xr >= yr ? xr - yr : xr - yr + cl_I_to_UL(R->modulus));
20         return _cl_MI(R, UL_to_I(zr));
21 }
22
23 static const _cl_MI int32_uminus (cl_heap_modint_ring* R, const _cl_MI& x)
24 {
25         var uint32 xr = cl_I_to_UL(x.rep);
26         var uint32 zr = (xr==0 ? 0 : cl_I_to_UL(R->modulus)-xr);
27         return _cl_MI(R, UL_to_I(zr));
28 }
29
30 static const _cl_MI int32_mul (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y)
31 {
32         var uint32 xr = cl_I_to_UL(x.rep);
33         var uint32 yr = cl_I_to_UL(y.rep);
34         var uint32 zrhi;
35         var uint32 zrlo;
36         mulu32(xr,yr,zrhi=,zrlo=);
37         var uint32 zr;
38         divu_6432_3232(zrhi,zrlo,cl_I_to_UL(R->modulus),,zr=);
39         return _cl_MI(R, UL_to_I(zr));
40 }
41
42 static const _cl_MI int32_square (cl_heap_modint_ring* R, const _cl_MI& x)
43 {
44         var uint32 xr = cl_I_to_UL(x.rep);
45         var uint32 zrhi;
46         var uint32 zrlo;
47         mulu32(xr,xr,zrhi=,zrlo=);
48         var uint32 zr;
49         divu_6432_3232(zrhi,zrlo,cl_I_to_UL(R->modulus),,zr=);
50         return _cl_MI(R, UL_to_I(zr));
51 }
52
53 static cl_modint_addops int32_addops = {
54         std_zero,
55         std_zerop,
56         int32_plus,
57         int32_minus,
58         int32_uminus
59 };
60 static cl_modint_mulops int32_mulops = {
61         std_one,
62         std_canonhom,
63         int32_mul,
64         int32_square,
65         std_expt_pos,
66         std_recip,
67         std_div,
68         std_expt,
69         std_reduce_modulo,
70         std_retract
71 };
72
73 class cl_heap_modint_ring_int32 : public cl_heap_modint_ring {
74         SUBCLASS_cl_heap_modint_ring()
75 public:
76         // Constructor.
77         cl_heap_modint_ring_int32 (const cl_I& m);
78         // Destructor.
79         ~cl_heap_modint_ring_int32 () {}
80 };
81
82 static void cl_modint_ring_int32_destructor (cl_heap* pointer)
83 {
84         (*(cl_heap_modint_ring_int32*)pointer).~cl_heap_modint_ring_int32();
85 }
86
87 cl_class cl_class_modint_ring_int32 = {
88         cl_modint_ring_int32_destructor,
89         cl_class_flags_modint_ring
90 };
91
92 // Constructor.
93 inline cl_heap_modint_ring_int32::cl_heap_modint_ring_int32(const cl_I& m)
94         : cl_heap_modint_ring (m, &std_setops, &int32_addops, &int32_mulops)
95 {
96         type = &cl_class_modint_ring_int32;
97 }
98
99 }  // namespace cln