1 #ifndef MPFQ_2_64_H_
2 #define MPFQ_2_64_H_
3 
4 /* MPFQ generated file -- do not edit */
5 
6 #include "gf2x.h"
7 #include "gf2x/gf2x-small.h"
8 
9 #include "mpfq.h"
10 #include "mpfq_gf2n_common.h"
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include <assert.h>
15 #include <stdint.h>
16 #include <ctype.h>
17 #include <stddef.h>
18 #include <stdio.h>
19 
20 #include "assert.h"
21 #ifdef	MPFQ_LAST_GENERATED_TAG
22 #undef	MPFQ_LAST_GENERATED_TAG
23 #endif
24 #define MPFQ_LAST_GENERATED_TAG      2_64
25 
26 /* Active handler: Mpfq::defaults */
27 /* Active handler: Mpfq::defaults::vec */
28 /* Active handler: Mpfq::gf2n::field */
29 /* Automatically generated code for GF(2^64) */
30 /* Definition polynomial P = X^64 + X^4 + X^3 + X + 1 */
31 /* Active handler: Mpfq::gf2n::trivialities */
32 /* Active handler: Mpfq::gf2n::io */
33 /* Active handler: Mpfq::gf2n::linearops */
34 /* Active handler: Mpfq::gf2n::inversion */
35 /* Active handler: Mpfq::gf2n::reduction */
36 /* Active handler: Mpfq::gf2n::mul */
37 /* Active handler: Mpfq::defaults::poly */
38 /* Options used:{
39    coeffs=[ 64, 4, 3, 1, 0, ],
40    helper=/tmp/mpfq-cado/gf2n/helper/helper,
41    n=64,
42    no_gmp=1,
43    output_path=x86_64,
44    slice=4,
45    table=/tmp/mpfq-cado/gf2x/wizard.table,
46    tag=2_64,
47    w=64,
48    } */
49 
50 typedef mpfq_2_field mpfq_2_64_field;
51 typedef mpfq_2_dst_field mpfq_2_64_dst_field;
52 typedef mpfq_2_src_field mpfq_2_64_src_field;
53 
54 typedef unsigned long mpfq_2_64_elt[1];
55 typedef unsigned long * mpfq_2_64_dst_elt;
56 typedef const unsigned long * mpfq_2_64_src_elt;
57 
58 typedef unsigned long mpfq_2_64_elt_ur[2];
59 typedef unsigned long * mpfq_2_64_dst_elt_ur;
60 typedef const unsigned long * mpfq_2_64_src_elt_ur;
61 
62 typedef mpfq_2_64_elt * mpfq_2_64_vec;
63 typedef mpfq_2_64_elt * mpfq_2_64_dst_vec;
64 typedef mpfq_2_64_elt * mpfq_2_64_src_vec;
65 
66 typedef struct {
67   mpfq_2_64_vec c;
68   unsigned int alloc;
69   unsigned int size;
70 } mpfq_2_64_poly_struct;
71 typedef mpfq_2_64_poly_struct mpfq_2_64_poly [1];
72 typedef mpfq_2_64_poly_struct * mpfq_2_64_dst_poly;
73 typedef mpfq_2_64_poly_struct * mpfq_2_64_src_poly;
74 /* Extra types defined by implementation: */
75 typedef mpfq_2_64_elt_ur * mpfq_2_64_dst_vec_ur;
76 typedef mpfq_2_64_elt_ur * mpfq_2_64_src_vec_ur;
77 typedef mpfq_2_64_elt_ur * mpfq_2_64_vec_ur;
78 
79 #ifdef  __cplusplus
80 extern "C" {
81 #endif
82 
83 /* Elementary assignment functions */
84 static inline
85 void mpfq_2_64_set(mpfq_2_64_dst_field, mpfq_2_64_dst_elt, mpfq_2_64_src_elt);
86 static inline
87 void mpfq_2_64_set_zero(mpfq_2_64_dst_field, mpfq_2_64_dst_elt);
88 
89 /* Comparison functions */
90 static inline
91 int mpfq_2_64_is_zero(mpfq_2_64_dst_field, mpfq_2_64_src_elt);
92 
93 /* Arithmetic operations on elements */
94 static inline
95 void mpfq_2_64_add(mpfq_2_64_dst_field, mpfq_2_64_dst_elt, mpfq_2_64_src_elt, mpfq_2_64_src_elt);
96 static inline
97 void mpfq_2_64_mul(mpfq_2_64_dst_field, mpfq_2_64_dst_elt, mpfq_2_64_src_elt, mpfq_2_64_src_elt);
98 static inline
99 void mpfq_2_64_sqr(mpfq_2_64_dst_field, mpfq_2_64_dst_elt, mpfq_2_64_src_elt);
100 
101 /* Operations involving unreduced elements */
102 static inline
103 void mpfq_2_64_elt_ur_set(mpfq_2_64_dst_field, mpfq_2_64_dst_elt_ur, mpfq_2_64_src_elt_ur);
104 static inline
105 void mpfq_2_64_elt_ur_set_elt(mpfq_2_64_dst_field, mpfq_2_64_dst_elt_ur, mpfq_2_64_src_elt);
106 static inline
107 void mpfq_2_64_elt_ur_set_zero(mpfq_2_64_dst_field, mpfq_2_64_dst_elt_ur);
108 static inline
109 void mpfq_2_64_elt_ur_add(mpfq_2_64_dst_field, mpfq_2_64_dst_elt_ur, mpfq_2_64_src_elt_ur, mpfq_2_64_src_elt_ur);
110 static inline
111 void mpfq_2_64_mul_ur(mpfq_2_64_dst_field, mpfq_2_64_dst_elt_ur, mpfq_2_64_src_elt, mpfq_2_64_src_elt);
112 static inline
113 void mpfq_2_64_sqr_ur(mpfq_2_64_dst_field, mpfq_2_64_dst_elt_ur, mpfq_2_64_src_elt);
114 static inline
115 void mpfq_2_64_reduce(mpfq_2_64_dst_field, mpfq_2_64_dst_elt, mpfq_2_64_dst_elt_ur);
116 static inline
117 void mpfq_2_64_vec_set_zero(mpfq_2_64_dst_field, mpfq_2_64_dst_vec, unsigned int);
118 #ifdef  __cplusplus
119 }
120 #endif
121 
122 /* Implementations for inlines */
123 /* *Mpfq::defaults::flatdata::code_for_set, Mpfq::gf2n::trivialities */
124 static inline
mpfq_2_64_set(mpfq_2_64_dst_field K MAYBE_UNUSED,mpfq_2_64_dst_elt r,mpfq_2_64_src_elt s)125 void mpfq_2_64_set(mpfq_2_64_dst_field K MAYBE_UNUSED, mpfq_2_64_dst_elt r, mpfq_2_64_src_elt s)
126 {
127     if (r != s) memcpy(r,s,sizeof(mpfq_2_64_elt));
128 }
129 
130 /* *Mpfq::defaults::flatdata::code_for_set_zero, Mpfq::gf2n::trivialities */
131 static inline
mpfq_2_64_set_zero(mpfq_2_64_dst_field K MAYBE_UNUSED,mpfq_2_64_dst_elt r)132 void mpfq_2_64_set_zero(mpfq_2_64_dst_field K MAYBE_UNUSED, mpfq_2_64_dst_elt r)
133 {
134     mpfq_2_64_vec_set_zero(K,(mpfq_2_64_dst_vec)r,1);
135 }
136 
137 /* *Mpfq::defaults::flatdata::code_for_is_zero, Mpfq::gf2n::trivialities */
138 static inline
mpfq_2_64_is_zero(mpfq_2_64_dst_field K MAYBE_UNUSED,mpfq_2_64_src_elt r)139 int mpfq_2_64_is_zero(mpfq_2_64_dst_field K MAYBE_UNUSED, mpfq_2_64_src_elt r)
140 {
141         unsigned int i;
142         for(i = 0 ; i < sizeof(mpfq_2_64_elt)/sizeof(r[0]) ; i++) {
143             if (r[i]) return 0;
144         }
145         return 1;
146 }
147 
148 /* *Mpfq::gf2n::trivialities::code_for_add */
149 static inline
mpfq_2_64_add(mpfq_2_64_dst_field K MAYBE_UNUSED,mpfq_2_64_dst_elt r,mpfq_2_64_src_elt s1,mpfq_2_64_src_elt s2)150 void mpfq_2_64_add(mpfq_2_64_dst_field K MAYBE_UNUSED, mpfq_2_64_dst_elt r, mpfq_2_64_src_elt s1, mpfq_2_64_src_elt s2)
151 {
152     r[0] = s1[0] ^ s2[0];
153 }
154 
155 /* *Mpfq::gf2n::trivialities::code_for_mul */
156 static inline
mpfq_2_64_mul(mpfq_2_64_dst_field K MAYBE_UNUSED,mpfq_2_64_dst_elt r,mpfq_2_64_src_elt s1,mpfq_2_64_src_elt s2)157 void mpfq_2_64_mul(mpfq_2_64_dst_field K MAYBE_UNUSED, mpfq_2_64_dst_elt r, mpfq_2_64_src_elt s1, mpfq_2_64_src_elt s2)
158 {
159     mpfq_2_64_elt_ur t;
160     mpfq_2_64_mul_ur(K, t, s1, s2);
161     mpfq_2_64_reduce(K, r, t);
162 }
163 
164 /* *Mpfq::gf2n::trivialities::code_for_sqr */
165 static inline
mpfq_2_64_sqr(mpfq_2_64_dst_field K MAYBE_UNUSED,mpfq_2_64_dst_elt r,mpfq_2_64_src_elt s)166 void mpfq_2_64_sqr(mpfq_2_64_dst_field K MAYBE_UNUSED, mpfq_2_64_dst_elt r, mpfq_2_64_src_elt s)
167 {
168     mpfq_2_64_elt_ur t;
169     mpfq_2_64_sqr_ur(K, t, s);
170     mpfq_2_64_reduce(K, r, t);
171 }
172 
173 /* *Mpfq::defaults::flatdata::code_for_elt_ur_set, Mpfq::gf2n::trivialities */
174 static inline
mpfq_2_64_elt_ur_set(mpfq_2_64_dst_field K MAYBE_UNUSED,mpfq_2_64_dst_elt_ur r,mpfq_2_64_src_elt_ur s)175 void mpfq_2_64_elt_ur_set(mpfq_2_64_dst_field K MAYBE_UNUSED, mpfq_2_64_dst_elt_ur r, mpfq_2_64_src_elt_ur s)
176 {
177     if (r != s) memcpy(r,s,sizeof(mpfq_2_64_elt_ur));
178 }
179 
180 /* *Mpfq::defaults::flatdata::code_for_elt_ur_set_elt, Mpfq::gf2n::trivialities */
181 static inline
mpfq_2_64_elt_ur_set_elt(mpfq_2_64_dst_field K MAYBE_UNUSED,mpfq_2_64_dst_elt_ur r,mpfq_2_64_src_elt s)182 void mpfq_2_64_elt_ur_set_elt(mpfq_2_64_dst_field K MAYBE_UNUSED, mpfq_2_64_dst_elt_ur r, mpfq_2_64_src_elt s)
183 {
184     memset(r, 0, sizeof(mpfq_2_64_elt_ur)); memcpy(r,s,sizeof(mpfq_2_64_elt));
185 }
186 
187 /* *Mpfq::defaults::flatdata::code_for_elt_ur_set_zero, Mpfq::gf2n::trivialities */
188 static inline
mpfq_2_64_elt_ur_set_zero(mpfq_2_64_dst_field K MAYBE_UNUSED,mpfq_2_64_dst_elt_ur r)189 void mpfq_2_64_elt_ur_set_zero(mpfq_2_64_dst_field K MAYBE_UNUSED, mpfq_2_64_dst_elt_ur r)
190 {
191     memset(r, 0, sizeof(mpfq_2_64_elt_ur));
192 }
193 
194 /* *Mpfq::gf2n::trivialities::code_for_elt_ur_add */
195 static inline
mpfq_2_64_elt_ur_add(mpfq_2_64_dst_field K MAYBE_UNUSED,mpfq_2_64_dst_elt_ur r,mpfq_2_64_src_elt_ur s1,mpfq_2_64_src_elt_ur s2)196 void mpfq_2_64_elt_ur_add(mpfq_2_64_dst_field K MAYBE_UNUSED, mpfq_2_64_dst_elt_ur r, mpfq_2_64_src_elt_ur s1, mpfq_2_64_src_elt_ur s2)
197 {
198     int i;
199     for(i = 0 ; i < 2 ; i++)
200         r[i] = s1[i] ^ s2[i];
201 }
202 
203 /* *Mpfq::gf2n::mul::code_for_mul_ur */
204 static inline
mpfq_2_64_mul_ur(mpfq_2_64_dst_field K MAYBE_UNUSED,mpfq_2_64_dst_elt_ur t,mpfq_2_64_src_elt s1,mpfq_2_64_src_elt s2)205 void mpfq_2_64_mul_ur(mpfq_2_64_dst_field K MAYBE_UNUSED, mpfq_2_64_dst_elt_ur t, mpfq_2_64_src_elt s1, mpfq_2_64_src_elt s2)
206 {
207     gf2x_mul1(t, s1[0], s2[0]);
208 }
209 
210 /* *Mpfq::gf2n::squaring::code_for_sqr_ur */
211 static inline
mpfq_2_64_sqr_ur(mpfq_2_64_dst_field K MAYBE_UNUSED,mpfq_2_64_dst_elt_ur t,mpfq_2_64_src_elt s)212 void mpfq_2_64_sqr_ur(mpfq_2_64_dst_field K MAYBE_UNUSED, mpfq_2_64_dst_elt_ur t, mpfq_2_64_src_elt s)
213 {
214     static const unsigned long g[16] = {
215         0, 1, 4, 5, 16, 17, 20, 21,
216         64, 65, 68, 69, 80, 81, 84, 85,
217     };
218     {
219         unsigned long u;
220         u = g[s[0]       & 15];
221     t[0]  = u;
222         u = g[s[0] >>  4 & 15];
223     t[0] ^= u <<  8;
224         u = g[s[0] >>  8 & 15];
225     t[0] ^= u << 16;
226         u = g[s[0] >> 12 & 15];
227     t[0] ^= u << 24;
228         u = g[s[0] >> 16 & 15];
229     t[0] ^= u << 32;
230         u = g[s[0] >> 20 & 15];
231     t[0] ^= u << 40;
232         u = g[s[0] >> 24 & 15];
233     t[0] ^= u << 48;
234         u = g[s[0] >> 28 & 15];
235     t[0] ^= u << 56;
236         u = g[s[0] >> 32 & 15];
237     t[1]  = u;
238         u = g[s[0] >> 36 & 15];
239     t[1] ^= u <<  8;
240         u = g[s[0] >> 40 & 15];
241     t[1] ^= u << 16;
242         u = g[s[0] >> 44 & 15];
243     t[1] ^= u << 24;
244         u = g[s[0] >> 48 & 15];
245     t[1] ^= u << 32;
246         u = g[s[0] >> 52 & 15];
247     t[1] ^= u << 40;
248         u = g[s[0] >> 56 & 15];
249     t[1] ^= u << 48;
250         u = g[s[0] >> 60 & 15];
251     t[1] ^= u << 56;
252     }
253 }
254 
255 /* *Mpfq::gf2n::reduction::code_for_reduce */
256 static inline
mpfq_2_64_reduce(mpfq_2_64_dst_field K MAYBE_UNUSED,mpfq_2_64_dst_elt r,mpfq_2_64_dst_elt_ur t)257 void mpfq_2_64_reduce(mpfq_2_64_dst_field K MAYBE_UNUSED, mpfq_2_64_dst_elt r, mpfq_2_64_dst_elt_ur t)
258 {
259     {
260         unsigned long s[2];
261         /* 63 excess bits */
262         {
263             unsigned long z;
264             z = t[0];
265             s[0] = z;
266         }
267         memset(s + 1, 0, 1 * sizeof(unsigned long));
268         {
269             unsigned long z;
270             z = t[1];
271             s[0]^= z <<  4;
272             s[0]^= z <<  3;
273             s[0]^= z <<  1;
274             s[0]^= z;
275             z >>= 60;
276             s[1]^= z;
277             z >>= 1;
278             s[1]^= z;
279         }
280         /* 3 excess bits */
281         {
282             unsigned long z;
283             z = s[0];
284             r[0] = z;
285         }
286         {
287             unsigned long z;
288             z = s[1];
289             r[0]^= z <<  4;
290             r[0]^= z <<  3;
291             r[0]^= z <<  1;
292             r[0]^= z;
293         }
294     }
295 }
296 
297 /* *Mpfq::defaults::vec::flatdata::code_for_vec_set_zero, Mpfq::defaults::flatdata, Mpfq::gf2n::trivialities */
298 static inline
mpfq_2_64_vec_set_zero(mpfq_2_64_dst_field K MAYBE_UNUSED,mpfq_2_64_dst_vec r,unsigned int n)299 void mpfq_2_64_vec_set_zero(mpfq_2_64_dst_field K MAYBE_UNUSED, mpfq_2_64_dst_vec r, unsigned int n)
300 {
301     memset(r, 0, n*sizeof(mpfq_2_64_elt));
302 }
303 
304 
305 #endif  /* MPFQ_2_64_H_ */
306 
307 /* vim:set ft=cpp: */
308