1 /*
2 mpn_mulmid-profile.c: routines for profiling mpn middle products
3
4 Copyright (C) 2007, 2008, David Harvey
5
6 This file is part of the zn_poly library (version 0.9).
7
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.
12
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.
17
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/>.
20
21 */
22
23
24 #include <math.h>
25 #include "support.h"
26 #include "profiler.h"
27 #include "zn_poly_internal.h"
28 #include "zn_poly.h"
29
30
31 double
profile_mpn_mul(void * arg,unsigned long count)32 profile_mpn_mul (void* arg, unsigned long count)
33 {
34 profile_info_struct* info = (profile_info_struct*) arg;
35
36 size_t n1 = info->n1;
37 size_t n2 = info->n2;
38
39 mp_ptr buf1 = malloc (sizeof (mp_limb_t) * n1);
40 mp_ptr buf2 = malloc (sizeof (mp_limb_t) * n2);
41 mp_ptr buf3 = malloc (sizeof (mp_limb_t) * (n1 + n2));
42
43 // generate random inputs
44 mpn_random (buf1, n1);
45 mpn_random (buf2, n2);
46
47 // warm up
48 ulong j;
49 for (j = 0; j < count; j++)
50 ZNP_mpn_mul (buf3, buf1, n1, buf2, n2);
51
52 // do the actual profile
53 cycle_count_t t0 = get_cycle_counter ();
54
55 for (j = 0; j < count; j++)
56 ZNP_mpn_mul (buf3, buf1, n1, buf2, n2);
57
58 cycle_count_t t1 = get_cycle_counter ();
59
60 free (buf3);
61 free (buf2);
62 free (buf1);
63
64 return cycle_diff (t0, t1);
65 }
66
67
68 double
profile_mpn_mulmid_fallback(void * arg,unsigned long count)69 profile_mpn_mulmid_fallback (void* arg, unsigned long count)
70 {
71 profile_info_struct* info = (profile_info_struct*) arg;
72
73 size_t n1 = info->n1;
74 size_t n2 = info->n2;
75
76 mp_ptr buf1 = malloc (sizeof (mp_limb_t) * n1);
77 mp_ptr buf2 = malloc (sizeof (mp_limb_t) * n2);
78 mp_ptr buf3 = malloc (sizeof (mp_limb_t) * (n1 - n2 + 3));
79
80 // generate random inputs
81 mpn_random (buf1, n1);
82 mpn_random (buf2, n2);
83
84 // warm up
85 ulong j;
86 for (j = 0; j < count; j++)
87 ZNP_mpn_mulmid_fallback (buf3, buf1, n1, buf2, n2);
88
89 // do the actual profile
90 cycle_count_t t0 = get_cycle_counter ();
91
92 for (j = 0; j < count; j++)
93 ZNP_mpn_mulmid_fallback (buf3, buf1, n1, buf2, n2);
94
95 cycle_count_t t1 = get_cycle_counter ();
96
97 free (buf3);
98 free (buf2);
99 free (buf1);
100
101 return cycle_diff (t0, t1);
102 }
103
104
105 double
profile_mpn_smp(void * arg,unsigned long count)106 profile_mpn_smp (void* arg, unsigned long count)
107 {
108 profile_info_struct* info = (profile_info_struct*) arg;
109
110 size_t n1 = info->n1;
111 size_t n2 = info->n2;
112
113 mp_ptr buf1 = malloc (sizeof (mp_limb_t) * n1);
114 mp_ptr buf2 = malloc (sizeof (mp_limb_t) * n2);
115 mp_ptr buf3 = malloc (sizeof (mp_limb_t) * (n1 - n2 + 3));
116
117 // generate random inputs
118 mpn_random (buf1, n1);
119 mpn_random (buf2, n2);
120
121 // warm up
122 ulong j;
123 for (j = 0; j < count; j++)
124 ZNP_mpn_smp (buf3, buf1, n1, buf2, n2);
125
126 // do the actual profile
127 cycle_count_t t0 = get_cycle_counter ();
128
129 for (j = 0; j < count; j++)
130 ZNP_mpn_smp (buf3, buf1, n1, buf2, n2);
131
132 cycle_count_t t1 = get_cycle_counter ();
133
134 free (buf3);
135 free (buf2);
136 free (buf1);
137
138 return cycle_diff (t0, t1);
139 }
140
141
142 double
profile_mpn_smp_basecase(void * arg,unsigned long count)143 profile_mpn_smp_basecase (void* arg, unsigned long count)
144 {
145 profile_info_struct* info = (profile_info_struct*) arg;
146
147 size_t n1 = info->n1;
148 size_t n2 = info->n2;
149
150 mp_ptr buf1 = malloc (sizeof (mp_limb_t) * n1);
151 mp_ptr buf2 = malloc (sizeof (mp_limb_t) * n2);
152 mp_ptr buf3 = malloc (sizeof (mp_limb_t) * (n1 - n2 + 3));
153
154 // generate random inputs
155 mpn_random (buf1, n1);
156 mpn_random (buf2, n2);
157
158 // warm up
159 ulong j;
160 for (j = 0; j < count; j++)
161 ZNP_mpn_smp_basecase (buf3, buf1, n1, buf2, n2);
162
163 // do the actual profile
164 cycle_count_t t0 = get_cycle_counter ();
165
166 for (j = 0; j < count; j++)
167 ZNP_mpn_smp_basecase (buf3, buf1, n1, buf2, n2);
168
169 cycle_count_t t1 = get_cycle_counter ();
170
171 free (buf3);
172 free (buf2);
173 free (buf1);
174
175 return cycle_diff (t0, t1);
176 }
177
178
179 double
profile_mpn_smp_kara(void * arg,unsigned long count)180 profile_mpn_smp_kara (void* arg, unsigned long count)
181 {
182 profile_info_struct* info = (profile_info_struct*) arg;
183
184 size_t n = info->n;
185
186 mp_ptr buf1 = malloc (sizeof (mp_limb_t) * (2 * n - 1));
187 mp_ptr buf2 = malloc (sizeof (mp_limb_t) * n);
188 mp_ptr buf3 = malloc (sizeof (mp_limb_t) * (n + 2));
189
190 // generate random inputs
191 mpn_random (buf1, 2 * n - 1);
192 mpn_random (buf2, n);
193
194 // warm up
195 ulong j;
196 for (j = 0; j < count; j++)
197 ZNP_mpn_smp_kara (buf3, buf1, buf2, n);
198
199 // do the actual profile
200 cycle_count_t t0 = get_cycle_counter ();
201
202 for (j = 0; j < count; j++)
203 ZNP_mpn_smp_kara (buf3, buf1, buf2, n);
204
205 cycle_count_t t1 = get_cycle_counter ();
206
207 free (buf3);
208 free (buf2);
209 free (buf1);
210
211 return cycle_diff (t0, t1);
212 }
213
214
215
216 // end of file ****************************************************************
217