2
support.h: various support routines for test, profiling and tuning code
4
Copyright (C) 2007, 2008, David Harvey
6
This file is part of the zn_poly library (version 0.8).
8
This program is free software: you can redistribute it and/or modify
9
it under the terms of the GNU General Public License as published by
10
the Free Software Foundation, either version 2 of the License, or
11
(at your option) version 3 of the License.
13
This program is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
GNU General Public License for more details.
18
You should have received a copy of the GNU General Public License
19
along with this program. If not, see <http://www.gnu.org/licenses/>.
29
#include "zn_poly_internal.h"
39
single global random state for test/profile modules
41
extern gmp_randstate_t randstate;
46
An array of modulus bitsizes, used by several test functions.
48
extern unsigned test_bitsizes[];
49
extern unsigned num_test_bitsizes; // how big the array is
53
Exports abs(op) to res, storing exactly len limbs
54
(zero-padded if necessary).
56
Sign of op is ignored.
58
abs(op) must fit into len limbs.
60
void mpz_to_mpn(mp_limb_t* res, size_t len, const mpz_t op);
64
Converts mpn buffer (exactly len limbs) to mpz.
66
Output is always non-negative.
68
void mpn_to_mpz(mpz_t res, const mp_limb_t* op, size_t len);
72
Returns random unsigned long in [0, max).
74
ulong random_ulong(ulong max);
78
Returns random unsigned long in [0, 2^bits).
80
ulong random_ulong_bits(unsigned bits);
84
Returns random modulus with exactly _bits_ bits, i.e. in the range
87
If require_odd is set, the returned modulus will be odd.
89
ulong random_modulus(unsigned bits, int require_odd);
93
Prints array to stdout, in format e.g. "[2 3 7]".
95
void zn_array_print(const ulong* x, size_t len);
99
void ref_zn_array_mul(ulong* res, const ulong* op1, size_t len1,
100
const ulong* op2, size_t len2, const zn_mod_t mod);
102
void ref_zn_array_scalar_mul(ulong* res, const ulong* op, size_t len,
103
ulong x, const zn_mod_t mod);
105
void ref_zn_array_midmul(ulong* res, const ulong* op1, size_t len1,
106
const ulong* op2, size_t len2, const zn_mod_t mod);
108
void ref_zn_array_negamul(ulong* res, const ulong* op1, const ulong* op2,
109
size_t len, const zn_mod_t mod);
115
Prints op to standard output (in normalised form).
117
void zn_pmf_print(const zn_pmf_t op, ulong M, const zn_mod_t mod);
120
Prints op to standard output.
122
void zn_pmf_vec_print(const zn_pmf_vec_t op);
125
Prints first _length_ coefficients of op to standard output.
127
void zn_pmf_vec_print_trunc(const zn_pmf_vec_t op, ulong length);
134
/* ============================================================================
138
============================================================================ */
141
#define tune_mul_KS \
143
void tune_mul_KS(FILE* flog, int squaring, int verbose);
145
#define tune_mul_nussbaumer \
146
ZNP_tune_mul_nussbaumer
147
void tune_nussbaumer(FILE* flog, int squaring, int verbose);
151
void tune_mul(FILE* flog, int squaring, int verbose);
156
/* ============================================================================
158
structs used in profiling routines
160
============================================================================ */
179
struct for passing information to profile_mul
183
size_t len; // length of polynomials to multiply
184
ulong n; // the modulus
185
int algo; // one of the ALGO_MUL_* values
186
int squaring; // whether to profile squaring or multiplication
188
profile_mul_info_struct;
190
typedef profile_mul_info_struct profile_mul_info_t[1];
193
Profiles one of the multiplication routines.
195
_arg_ should point to a profile_mul_info_t describing what to profile.
197
Returns total cycle count for _count_ calls.
199
double profile_mul(void* arg, unsigned long count);
202
As above, but assumes that the algorithm is ALGO_MUL_NTL.
204
double profile_mul_ntl(void* arg, unsigned long count);
210
// fall back on calling zn_array_mul and reducing negacyclically
211
ALGO_NEGAMUL_FALLBACK,
213
// use Nussbaumer convolution
214
ALGO_NEGAMUL_NUSSBAUMER,
218
struct for passing information to profile_negamul
222
unsigned lg_len; // lg2 of polynomial length
223
ulong n; // the modulus
224
int algo; // one of the ALGO_NEGAMUL_* values
225
int squaring; // whether to profile squaring or multiplication
227
profile_negamul_info_struct;
229
typedef profile_negamul_info_struct profile_negamul_info_t[1];
232
Profiles one of the negacyclic multiplication routines.
234
_arg_ should point to a profile_negamul_info_t describing what to profile.
236
Returns total cycle count for _count_ calls.
238
double profile_negamul(void* arg, unsigned long count);
245
ALGO_MIDMUL_FALLBACK,
254
struct for passing information to profile_midmul
258
size_t len; // we're doing a (2*len) x len middle product
259
ulong n; // the modulus
260
int algo; // one of the ALGO_MIDMUL_* values
262
profile_midmul_info_struct;
264
typedef profile_midmul_info_struct profile_midmul_info_t[1];
267
Profiles one of the middle product routines.
269
_arg_ should point to a profile_midmul_info_t describing what to profile.
271
Returns total cycle count for _count_ calls.
273
double profile_midmul(void* arg, unsigned long count);
284
struct for passing information to profile_invert
288
size_t len; // we're doing a length len inversion
289
ulong n; // the modulus
290
int algo; // one of the ALGO_INVERT_* values
292
profile_invert_info_struct;
294
typedef profile_invert_info_struct profile_invert_info_t[1];
297
Profiles one of the series inversion routines.
299
_arg_ should point to a profile_invert_info_t describing what to profile.
301
Returns total cycle count for _count_ calls.
303
double profile_invert(void* arg, unsigned long count);
306
As above, but assumes that the algorithm is ALGO_INVERT_NTL.
308
double profile_invert_ntl(void* arg, unsigned long count);
313
double profile_bfly(void* arg, unsigned long count);
314
double profile_mpn_aors(void* arg, unsigned long count);
315
double profile_scalar_mul(void* arg, unsigned long count);
317
void prof_main(int argc, char* argv[]);
326
// end of file ****************************************************************