2
mul_fft-profile.c: profiling for mul_fft.c module
4
Copyright (C) 2007, David Harvey
6
This file is part of the zn_poly library (version 0.4.1).
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/>.
25
#include "zn_poly_internal.h"
30
Profiles the main mul_fft() routine.
32
arg points to an array of ulongs.
33
First ulong is poly length.
36
Returns total cycle count for _count_ calls.
38
double profile_mul_fft(void* arg, unsigned long count)
40
size_t len = ((ulong*) arg)[0];
41
ulong n = ((ulong*) arg)[1];
46
ulong* buf1 = (ulong*) malloc(sizeof(ulong) * len);
47
ulong* buf2 = (ulong*) malloc(sizeof(ulong) * len);
48
ulong* buf3 = (ulong*) malloc(sizeof(ulong) * 2 * len);
51
for (i = 0; i < len; i++)
52
buf1[i] = random_ulong(n);
53
for (i = 0; i < len; i++)
54
buf2[i] = random_ulong(n);
58
for (j = 0; j < count; j++)
59
zn_array_mul_fft(buf3, buf1, len, buf2, len, mod);
61
cycle_count_t t0 = get_cycle_counter();
63
for (j = 0; j < count; j++)
64
zn_array_mul_fft(buf3, buf1, len, buf2, len, mod);
66
cycle_count_t t1 = get_cycle_counter();
74
return cycle_diff(t0, t1);
79
void prof_main(int argc, char* argv[])
83
unsigned bitsizes[9] = {4, 8, 16, 24, 32, 40, 48, 56, 64};
89
// loop over bitsizes in above table
90
for (i = 0; i < sizeof(bitsizes) / sizeof(bitsizes[0]); i++)
94
// loop over lengths, spaced out logarithmically
95
for (j = 0; j < 120; j++)
97
size_t new_len = (size_t) floor(pow(1.1, (double) j));
104
// choose an odd modulus exactly _bits_ bits long, and not equal to
105
// a power of two (so that the residues are _bits_ bits long too),
106
ulong n = (1UL << (bits - 1))
107
+ 2 * random_ulong((1UL << (bits - 2))) + 1;
110
result = profile(profile_mul_fft, arg);
112
printf("len = %5lu, bits = %2u, mul_fft = %.2le\n",
115
printf("-------------------------------------------\n");
119
// end of file ****************************************************************