-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple_types_loop_invariant.cpp
478 lines (337 loc) · 32.4 KB
/
simple_types_loop_invariant.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
/*
Copyright 2007-2008 Adobe Systems Incorporated
Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
or a copy at http://stlab.adobe.com/licenses.html )
Goal: Test compiler optimizations related to simple language defined types
Assumptions:
1) the compiler will move loop invariant calculations on simple types out of a loop
aka: loop invariant code motion
for (i = 0; i < N; ++i) temp = A + B + C + D;
result = input[i] + A+B+C+D; ==> for (i = 0; i < N; ++i)
result = input[i] + temp;
*/
/******************************************************************************/
#include "benchmark_stdint.hpp"
#include <cstddef>
#include <cstdio>
#include <ctime>
#include <cstdlib>
#include <cmath>
#include "benchmark_results.h"
#include "benchmark_timer.h"
/******************************************************************************/
// this constant may need to be adjusted to give reasonable minimum times
// For best results, times should be about 1.0 seconds for the minimum test run
int iterations = 200000;
// 8000 items, or between 8k and 64k of data
// this is intended to remain within the L2 cache of most common CPUs
const int SIZE = 8000;
// initial value for filling our arrays, may be changed from the command line
double init_value = 1.0;
/******************************************************************************/
// our global arrays of numbers to be operated upon
double dataDouble[SIZE];
float dataFloat[SIZE];
uint64_t data64unsigned[SIZE];
int64_t data64[SIZE];
uint32_t data32unsigned[SIZE];
int32_t data32[SIZE];
uint16_t data16unsigned[SIZE];
int16_t data16[SIZE];
uint8_t data8unsigned[SIZE];
int8_t data8[SIZE];
/******************************************************************************/
#include "benchmark_shared_tests.h"
/******************************************************************************/
// v1 is constant in the function, so we can move the addition or subtraction of it outside the loop entirely
// converting it to a multiply and a summation of the input array
// Note that this is always legal for integers
// it can only be applied to floating point if using inexact math (relaxed IEEE rules)
template <typename T, typename Shifter>
void test_hoisted_variable1(T* first, int count, T v1, const char *label) {
int i;
start_timer();
for(i = 0; i < iterations; ++i) {
T result = 0;
for (int n = 0; n < count; ++n) {
result += first[n];
}
result += count * v1;
check_shifted_variable_sum<T, Shifter>(result, v1);
}
record_result( timer(), label );
}
/******************************************************************************/
int main(int argc, char** argv) {
double temp = 1.0;
// output command for documentation:
int i;
for (i = 0; i < argc; ++i)
printf("%s ", argv[i] );
printf("\n");
if (argc > 1) iterations = atoi(argv[1]);
if (argc > 2) init_value = (double) atof(argv[2]);
if (argc > 3) temp = (double)atof(argv[3]);
// int8_t
::fill(data8, data8+SIZE, int8_t(init_value));
int8_t var1int8_1, var1int8_2, var1int8_3, var1int8_4;
var1int8_1 = int8_t(temp);
var1int8_2 = var1int8_1 * int8_t(2);
var1int8_3 = var1int8_1 + int8_t(2);
var1int8_4 = var1int8_1 + var1int8_2 / var1int8_3;
// test moving redundant calcs out of loop
test_variable1< int8_t, custom_add_variable<int8_t> > (data8, SIZE, var1int8_1, "int8_t variable add");
test_hoisted_variable1< int8_t, custom_add_variable<int8_t> > (data8, SIZE, var1int8_1, "int8_t variable add hoisted");
test_variable4< int8_t, custom_add_multiple_variable<int8_t> > (data8, SIZE, var1int8_1, var1int8_2, var1int8_3, var1int8_4, "int8_t multiple variable adds");
test_variable1< int8_t, custom_sub_variable<int8_t> > (data8, SIZE, var1int8_1, "int8_t variable subtract");
test_variable4< int8_t, custom_sub_multiple_variable<int8_t> > (data8, SIZE, var1int8_1, var1int8_2, var1int8_3, var1int8_4, "int8_t multiple variable subtracts");
test_variable1< int8_t, custom_multiply_variable<int8_t> > (data8, SIZE, var1int8_1, "int8_t variable multiply");
test_variable4< int8_t, custom_multiply_multiple_variable<int8_t> > (data8, SIZE, var1int8_1, var1int8_2, var1int8_3, var1int8_4, "int8_t multiple variable multiplies");
test_variable4< int8_t, custom_multiply_multiple_variable2<int8_t> > (data8, SIZE, var1int8_1, var1int8_2, var1int8_3, var1int8_4, "int8_t multiple variable multiplies2");
test_variable1< int8_t, custom_divide_variable<int8_t> > (data8, SIZE, var1int8_1, "int8_t variable divide");
test_variable4< int8_t, custom_divide_multiple_variable<int8_t> > (data8, SIZE, var1int8_1, var1int8_2, var1int8_3, var1int8_4, "int8_t multiple variable divides");
test_variable4< int8_t, custom_divide_multiple_variable2<int8_t> > (data8, SIZE, var1int8_1, var1int8_2, var1int8_3, var1int8_4, "int8_t multiple variable divides2");
test_variable4< int8_t, custom_mixed_multiple_variable<int8_t> > (data8, SIZE, var1int8_1, var1int8_2, var1int8_3, var1int8_4, "int8_t multiple variable mixed");
test_variable1< int8_t, custom_variable_and<int8_t> > (data8, SIZE, var1int8_1, "int8_t variable and");
test_variable4< int8_t, custom_multiple_variable_and<int8_t> > (data8, SIZE, var1int8_1, var1int8_2, var1int8_3, var1int8_4, "int8_t multiple variable and");
test_variable1< int8_t, custom_variable_or<int8_t> > (data8, SIZE, var1int8_1, "int8_t variable or");
test_variable4< int8_t, custom_multiple_variable_or<int8_t> > (data8, SIZE, var1int8_1, var1int8_2, var1int8_3, var1int8_4, "int8_t multiple variable or");
test_variable1< int8_t, custom_variable_xor<int8_t> > (data8, SIZE, var1int8_1, "int8_t variable xor");
test_variable4< int8_t, custom_multiple_variable_xor<int8_t> > (data8, SIZE, var1int8_1, var1int8_2, var1int8_3, var1int8_4, "int8_t multiple variable xor");
summarize("int8_t loop invariant", SIZE, iterations, kDontShowGMeans, kDontShowPenalty );
// unsigned8
::fill(data8unsigned, data8unsigned+SIZE, uint8_t(init_value));
uint8_t var1uint8_1, var1uint8_2, var1uint8_3, var1uint8_4;
var1uint8_1 = uint8_t(temp);
var1uint8_2 = var1uint8_1 * uint8_t(2);
var1uint8_3 = var1uint8_1 + uint8_t(2);
var1uint8_4 = var1uint8_1 + var1uint8_2 / var1uint8_3;
// test moving redundant calcs out of loop
test_variable1< uint8_t, custom_add_variable<uint8_t> > (data8unsigned, SIZE, var1uint8_1, "uint8_t variable add");
test_hoisted_variable1< uint8_t, custom_add_variable<uint8_t> > (data8unsigned, SIZE, var1uint8_1, "uint8_t variable add hoisted");
test_variable4< uint8_t, custom_add_multiple_variable<uint8_t> > (data8unsigned, SIZE, var1uint8_1, var1uint8_2, var1uint8_3, var1uint8_4, "uint8_t multiple variable adds");
test_variable1< uint8_t, custom_sub_variable<uint8_t> > (data8unsigned, SIZE, var1uint8_1, "uint8_t variable subtract");
test_variable4< uint8_t, custom_sub_multiple_variable<uint8_t> > (data8unsigned, SIZE, var1uint8_1, var1uint8_2, var1uint8_3, var1uint8_4, "uint8_t multiple variable subtracts");
test_variable1< uint8_t, custom_multiply_variable<uint8_t> > (data8unsigned, SIZE, var1uint8_1, "uint8_t variable multiply");
test_variable4< uint8_t, custom_multiply_multiple_variable<uint8_t> > (data8unsigned, SIZE, var1uint8_1, var1uint8_2, var1uint8_3, var1uint8_4, "uint8_t multiple variable multiplies");
test_variable4< uint8_t, custom_multiply_multiple_variable2<uint8_t> > (data8unsigned, SIZE, var1uint8_1, var1uint8_2, var1uint8_3, var1uint8_4, "uint8_t multiple variable multiplies2");
test_variable1< uint8_t, custom_divide_variable<uint8_t> > (data8unsigned, SIZE, var1uint8_1, "uint8_t variable divide");
test_variable4< uint8_t, custom_divide_multiple_variable<uint8_t> > (data8unsigned, SIZE, var1uint8_1, var1uint8_2, var1uint8_3, var1uint8_4, "uint8_t multiple variable divides");
test_variable4< uint8_t, custom_divide_multiple_variable2<uint8_t> > (data8unsigned, SIZE, var1uint8_1, var1uint8_2, var1uint8_3, var1uint8_4, "uint8_t multiple variable divides2");
test_variable4< uint8_t, custom_mixed_multiple_variable<uint8_t> > (data8unsigned, SIZE, var1uint8_1, var1uint8_2, var1uint8_3, var1uint8_4, "uint8_t multiple variable mixed");
test_variable1< uint8_t, custom_variable_and<uint8_t> > (data8unsigned, SIZE, var1uint8_1, "uint8_t variable and");
test_variable4< uint8_t, custom_multiple_variable_and<uint8_t> > (data8unsigned, SIZE, var1uint8_1, var1uint8_2, var1uint8_3, var1uint8_4, "uint8_t multiple variable and");
test_variable1< uint8_t, custom_variable_or<uint8_t> > (data8unsigned, SIZE, var1uint8_1, "uint8_t variable or");
test_variable4< uint8_t, custom_multiple_variable_or<uint8_t> > (data8unsigned, SIZE, var1uint8_1, var1uint8_2, var1uint8_3, var1uint8_4, "uint8_t multiple variable or");
test_variable1< uint8_t, custom_variable_xor<uint8_t> > (data8unsigned, SIZE, var1uint8_1, "uint8_t variable xor");
test_variable4< uint8_t, custom_multiple_variable_xor<uint8_t> > (data8unsigned, SIZE, var1uint8_1, var1uint8_2, var1uint8_3, var1uint8_4, "uint8_t multiple variable xor");
summarize("uint8_t loop invariant", SIZE, iterations, kDontShowGMeans, kDontShowPenalty );
// int16_t
::fill(data16, data16+SIZE, int16_t(init_value));
int16_t var1int16_1, var1int16_2, var1int16_3, var1int16_4;
var1int16_1 = int16_t(temp);
var1int16_2 = var1int16_1 * int16_t(2);
var1int16_3 = var1int16_1 + int16_t(2);
var1int16_4 = var1int16_1 + var1int16_2 / var1int16_3;
// test moving redundant calcs out of loop
test_variable1< int16_t, custom_add_variable<int16_t> > (data16, SIZE, var1int16_1, "int16_t variable add");
test_hoisted_variable1< int16_t, custom_add_variable<int16_t> > (data16, SIZE, var1int16_1, "int16_t variable add hoisted");
test_variable4< int16_t, custom_add_multiple_variable<int16_t> > (data16, SIZE, var1int16_1, var1int16_2, var1int16_3, var1int16_4, "int16_t multiple variable adds");
test_variable1< int16_t, custom_sub_variable<int16_t> > (data16, SIZE, var1int16_1, "int16_t variable subtract");
test_variable4< int16_t, custom_sub_multiple_variable<int16_t> > (data16, SIZE, var1int16_1, var1int16_2, var1int16_3, var1int16_4, "int16_t multiple variable subtracts");
test_variable1< int16_t, custom_multiply_variable<int16_t> > (data16, SIZE, var1int16_1, "int16_t variable multiply");
test_variable4< int16_t, custom_multiply_multiple_variable<int16_t> > (data16, SIZE, var1int16_1, var1int16_2, var1int16_3, var1int16_4, "int16_t multiple variable multiplies");
test_variable4< int16_t, custom_multiply_multiple_variable2<int16_t> > (data16, SIZE, var1int16_1, var1int16_2, var1int16_3, var1int16_4, "int16_t multiple variable multiplies2");
test_variable1< int16_t, custom_divide_variable<int16_t> > (data16, SIZE, var1int16_1, "int16_t variable divide");
test_variable4< int16_t, custom_divide_multiple_variable<int16_t> > (data16, SIZE, var1int16_1, var1int16_2, var1int16_3, var1int16_4, "int16_t multiple variable divides");
test_variable4< int16_t, custom_divide_multiple_variable2<int16_t> > (data16, SIZE, var1int16_1, var1int16_2, var1int16_3, var1int16_4, "int16_t multiple variable divides2");
test_variable4< int16_t, custom_mixed_multiple_variable<int16_t> > (data16, SIZE, var1int16_1, var1int16_2, var1int16_3, var1int16_4, "int16_t multiple variable mixed");
test_variable1< int16_t, custom_variable_and<int16_t> > (data16, SIZE, var1int16_1, "int16_t variable and");
test_variable4< int16_t, custom_multiple_variable_and<int16_t> > (data16, SIZE, var1int16_1, var1int16_2, var1int16_3, var1int16_4, "int16_t multiple variable and");
test_variable1< int16_t, custom_variable_or<int16_t> > (data16, SIZE, var1int16_1, "int16_t variable or");
test_variable4< int16_t, custom_multiple_variable_or<int16_t> > (data16, SIZE, var1int16_1, var1int16_2, var1int16_3, var1int16_4, "int16_t multiple variable or");
test_variable1< int16_t, custom_variable_xor<int16_t> > (data16, SIZE, var1int16_1, "int16_t variable xor");
test_variable4< int16_t, custom_multiple_variable_xor<int16_t> > (data16, SIZE, var1int16_1, var1int16_2, var1int16_3, var1int16_4, "int16_t multiple variable xor");
summarize("int16_t loop invariant", SIZE, iterations, kDontShowGMeans, kDontShowPenalty );
// unsigned16
::fill(data16unsigned, data16unsigned+SIZE, uint16_t(init_value));
uint16_t var1uint16_1, var1uint16_2, var1uint16_3, var1uint16_4;
var1uint16_1 = uint16_t(temp);
var1uint16_2 = var1uint16_1 * uint16_t(2);
var1uint16_3 = var1uint16_1 + uint16_t(2);
var1uint16_4 = var1uint16_1 + var1uint16_2 / var1uint16_3;
// test moving redundant calcs out of loop
test_variable1< uint16_t, custom_add_variable<uint16_t> > (data16unsigned, SIZE, var1uint16_1, "uint16_t variable add");
test_hoisted_variable1< uint16_t, custom_add_variable<uint16_t> > (data16unsigned, SIZE, var1uint16_1, "uint16_t variable add hoisted");
test_variable4< uint16_t, custom_add_multiple_variable<uint16_t> > (data16unsigned, SIZE, var1uint16_1, var1uint16_2, var1uint16_3, var1uint16_4, "uint16_t multiple variable adds");
test_variable1< uint16_t, custom_sub_variable<uint16_t> > (data16unsigned, SIZE, var1uint16_1, "uint16_t variable subtract");
test_variable4< uint16_t, custom_sub_multiple_variable<uint16_t> > (data16unsigned, SIZE, var1uint16_1, var1uint16_2, var1uint16_3, var1uint16_4, "uint16_t multiple variable subtracts");
test_variable1< uint16_t, custom_multiply_variable<uint16_t> > (data16unsigned, SIZE, var1uint16_1, "uint16_t variable multiply");
test_variable4< uint16_t, custom_multiply_multiple_variable<uint16_t> > (data16unsigned, SIZE, var1uint16_1, var1uint16_2, var1uint16_3, var1uint16_4, "uint16_t multiple variable multiplies");
test_variable4< uint16_t, custom_multiply_multiple_variable2<uint16_t> > (data16unsigned, SIZE, var1uint16_1, var1uint16_2, var1uint16_3, var1uint16_4, "uint16_t multiple variable multiplies2");
test_variable1< uint16_t, custom_divide_variable<uint16_t> > (data16unsigned, SIZE, var1uint16_1, "uint16_t variable divide");
test_variable4< uint16_t, custom_divide_multiple_variable<uint16_t> > (data16unsigned, SIZE, var1uint16_1, var1uint16_2, var1uint16_3, var1uint16_4, "uint16_t multiple variable divides");
test_variable4< uint16_t, custom_divide_multiple_variable2<uint16_t> > (data16unsigned, SIZE, var1uint16_1, var1uint16_2, var1uint16_3, var1uint16_4, "uint16_t multiple variable divides2");
test_variable4< uint16_t, custom_mixed_multiple_variable<uint16_t> > (data16unsigned, SIZE, var1uint16_1, var1uint16_2, var1uint16_3, var1uint16_4, "uint16_t multiple variable mixed");
test_variable1< uint16_t, custom_variable_and<uint16_t> > (data16unsigned, SIZE, var1uint16_1, "uint16_t variable and");
test_variable4< uint16_t, custom_multiple_variable_and<uint16_t> > (data16unsigned, SIZE, var1uint16_1, var1uint16_2, var1uint16_3, var1uint16_4, "uint16_t multiple variable and");
test_variable1< uint16_t, custom_variable_or<uint16_t> > (data16unsigned, SIZE, var1uint16_1, "uint16_t variable or");
test_variable4< uint16_t, custom_multiple_variable_or<uint16_t> > (data16unsigned, SIZE, var1uint16_1, var1uint16_2, var1uint16_3, var1uint16_4, "uint16_t multiple variable or");
test_variable1< uint16_t, custom_variable_xor<uint16_t> > (data16unsigned, SIZE, var1uint16_1, "uint16_t variable xor");
test_variable4< uint16_t, custom_multiple_variable_xor<uint16_t> > (data16unsigned, SIZE, var1uint16_1, var1uint16_2, var1uint16_3, var1uint16_4, "uint16_t multiple variable xor");
summarize("uint16_t loop invariant", SIZE, iterations, kDontShowGMeans, kDontShowPenalty );
// int32_t
::fill(data32, data32+SIZE, int32_t(init_value));
int32_t var1int32_1, var1int32_2, var1int32_3, var1int32_4;
var1int32_1 = int32_t(temp);
var1int32_2 = var1int32_1 * int32_t(2);
var1int32_3 = var1int32_1 + int32_t(2);
var1int32_4 = var1int32_1 + var1int32_2 / var1int32_3;
// test moving redundant calcs out of loop
test_variable1< int32_t, custom_add_variable<int32_t> > (data32, SIZE, var1int32_1, "int32_t variable add");
test_hoisted_variable1< int32_t, custom_add_variable<int32_t> > (data32, SIZE, var1int32_1, "int32_t variable add hoisted");
test_variable4< int32_t, custom_add_multiple_variable<int32_t> > (data32, SIZE, var1int32_1, var1int32_2, var1int32_3, var1int32_4, "int32_t multiple variable adds");
test_variable1< int32_t, custom_sub_variable<int32_t> > (data32, SIZE, var1int32_1, "int32_t variable subtract");
test_variable4< int32_t, custom_sub_multiple_variable<int32_t> > (data32, SIZE, var1int32_1, var1int32_2, var1int32_3, var1int32_4, "int32_t multiple variable subtracts");
test_variable1< int32_t, custom_multiply_variable<int32_t> > (data32, SIZE, var1int32_1, "int32_t variable multiply");
test_variable4< int32_t, custom_multiply_multiple_variable<int32_t> > (data32, SIZE, var1int32_1, var1int32_2, var1int32_3, var1int32_4, "int32_t multiple variable multiplies");
test_variable4< int32_t, custom_multiply_multiple_variable2<int32_t> > (data32, SIZE, var1int32_1, var1int32_2, var1int32_3, var1int32_4, "int32_t multiple variable multiplies2");
test_variable1< int32_t, custom_divide_variable<int32_t> > (data32, SIZE, var1int32_1, "int32_t variable divide");
test_variable4< int32_t, custom_divide_multiple_variable<int32_t> > (data32, SIZE, var1int32_1, var1int32_2, var1int32_3, var1int32_4, "int32_t multiple variable divides");
test_variable4< int32_t, custom_divide_multiple_variable2<int32_t> > (data32, SIZE, var1int32_1, var1int32_2, var1int32_3, var1int32_4, "int32_t multiple variable divides2");
test_variable4< int32_t, custom_mixed_multiple_variable<int32_t> > (data32, SIZE, var1int32_1, var1int32_2, var1int32_3, var1int32_4, "int32_t multiple variable mixed");
test_variable1< int32_t, custom_variable_and<int32_t> > (data32, SIZE, var1int32_1, "int32_t variable and");
test_variable4< int32_t, custom_multiple_variable_and<int32_t> > (data32, SIZE, var1int32_1, var1int32_2, var1int32_3, var1int32_4, "int32_t multiple variable and");
test_variable1< int32_t, custom_variable_or<int32_t> > (data32, SIZE, var1int32_1, "int32_t variable or");
test_variable4< int32_t, custom_multiple_variable_or<int32_t> > (data32, SIZE, var1int32_1, var1int32_2, var1int32_3, var1int32_4, "int32_t multiple variable or");
test_variable1< int32_t, custom_variable_xor<int32_t> > (data32, SIZE, var1int32_1, "int32_t variable xor");
test_variable4< int32_t, custom_multiple_variable_xor<int32_t> > (data32, SIZE, var1int32_1, var1int32_2, var1int32_3, var1int32_4, "int32_t multiple variable xor");
summarize("int32_t loop invariant", SIZE, iterations, kDontShowGMeans, kDontShowPenalty );
// unsigned32
::fill(data32unsigned, data32unsigned+SIZE, uint32_t(init_value));
uint32_t var1uint32_1, var1uint32_2, var1uint32_3, var1uint32_4;
var1uint32_1 = uint32_t(temp);
var1uint32_2 = var1uint32_1 * uint32_t(2);
var1uint32_3 = var1uint32_1 + uint32_t(2);
var1uint32_4 = var1uint32_1 + var1uint32_2 / var1uint32_3;
// test moving redundant calcs out of loop
test_variable1< uint32_t, custom_add_variable<uint32_t> > (data32unsigned, SIZE, var1uint32_1, "uint32_t variable add");
test_hoisted_variable1< uint32_t, custom_add_variable<uint32_t> > (data32unsigned, SIZE, var1uint32_1, "uint32_t variable add hoisted");
test_variable4< uint32_t, custom_add_multiple_variable<uint32_t> > (data32unsigned, SIZE, var1uint32_1, var1uint32_2, var1uint32_3, var1uint32_4, "uint32_t multiple variable adds");
test_variable1< uint32_t, custom_sub_variable<uint32_t> > (data32unsigned, SIZE, var1uint32_1, "uint32_t variable subtract");
test_variable4< uint32_t, custom_sub_multiple_variable<uint32_t> > (data32unsigned, SIZE, var1uint32_1, var1uint32_2, var1uint32_3, var1uint32_4, "uint32_t multiple variable subtracts");
test_variable1< uint32_t, custom_multiply_variable<uint32_t> > (data32unsigned, SIZE, var1uint32_1, "uint32_t variable multiply");
test_variable4< uint32_t, custom_multiply_multiple_variable<uint32_t> > (data32unsigned, SIZE, var1uint32_1, var1uint32_2, var1uint32_3, var1uint32_4, "uint32_t multiple variable multiplies");
test_variable4< uint32_t, custom_multiply_multiple_variable2<uint32_t> > (data32unsigned, SIZE, var1uint32_1, var1uint32_2, var1uint32_3, var1uint32_4, "uint32_t multiple variable multiplies2");
test_variable1< uint32_t, custom_divide_variable<uint32_t> > (data32unsigned, SIZE, var1uint32_1, "uint32_t variable divide");
test_variable4< uint32_t, custom_divide_multiple_variable<uint32_t> > (data32unsigned, SIZE, var1uint32_1, var1uint32_2, var1uint32_3, var1uint32_4, "uint32_t multiple variable divides");
test_variable4< uint32_t, custom_divide_multiple_variable2<uint32_t> > (data32unsigned, SIZE, var1uint32_1, var1uint32_2, var1uint32_3, var1uint32_4, "uint32_t multiple variable divides2");
test_variable4< uint32_t, custom_mixed_multiple_variable<uint32_t> > (data32unsigned, SIZE, var1uint32_1, var1uint32_2, var1uint32_3, var1uint32_4, "uint32_t multiple variable mixed");
test_variable1< uint32_t, custom_variable_and<uint32_t> > (data32unsigned, SIZE, var1uint32_1, "uint32_t variable and");
test_variable4< uint32_t, custom_multiple_variable_and<uint32_t> > (data32unsigned, SIZE, var1uint32_1, var1uint32_2, var1uint32_3, var1uint32_4, "uint32_t multiple variable and");
test_variable1< uint32_t, custom_variable_or<uint32_t> > (data32unsigned, SIZE, var1uint32_1, "uint32_t variable or");
test_variable4< uint32_t, custom_multiple_variable_or<uint32_t> > (data32unsigned, SIZE, var1uint32_1, var1uint32_2, var1uint32_3, var1uint32_4, "uint32_t multiple variable or");
test_variable1< uint32_t, custom_variable_xor<uint32_t> > (data32unsigned, SIZE, var1uint32_1, "uint32_t variable xor");
test_variable4< uint32_t, custom_multiple_variable_xor<uint32_t> > (data32unsigned, SIZE, var1uint32_1, var1uint32_2, var1uint32_3, var1uint32_4, "uint32_t multiple variable xor");
summarize("uint32_t loop invariant", SIZE, iterations, kDontShowGMeans, kDontShowPenalty );
// int64_t
::fill(data64, data64+SIZE, int64_t(init_value));
int64_t var1int64_1, var1int64_2, var1int64_3, var1int64_4;
var1int64_1 = int64_t(temp);
var1int64_2 = var1int64_1 * int64_t(2);
var1int64_3 = var1int64_1 + int64_t(2);
var1int64_4 = var1int64_1 + var1int64_2 / var1int64_3;
// test moving redundant calcs out of loop
test_variable1< int64_t, custom_add_variable<int64_t> > (data64, SIZE, var1int64_1, "int64_t variable add");
test_hoisted_variable1< int64_t, custom_add_variable<int64_t> > (data64, SIZE, var1int64_1, "int64_t variable add hoisted");
test_variable4< int64_t, custom_add_multiple_variable<int64_t> > (data64, SIZE, var1int64_1, var1int64_2, var1int64_3, var1int64_4, "int64_t multiple variable adds");
test_variable1< int64_t, custom_sub_variable<int64_t> > (data64, SIZE, var1int64_1, "int64_t variable subtract");
test_variable4< int64_t, custom_sub_multiple_variable<int64_t> > (data64, SIZE, var1int64_1, var1int64_2, var1int64_3, var1int64_4, "int64_t multiple variable subtracts");
test_variable1< int64_t, custom_multiply_variable<int64_t> > (data64, SIZE, var1int64_1, "int64_t variable multiply");
test_variable4< int64_t, custom_multiply_multiple_variable<int64_t> > (data64, SIZE, var1int64_1, var1int64_2, var1int64_3, var1int64_4, "int64_t multiple variable multiplies");
test_variable4< int64_t, custom_multiply_multiple_variable2<int64_t> > (data64, SIZE, var1int64_1, var1int64_2, var1int64_3, var1int64_4, "int64_t multiple variable multiplies2");
test_variable1< int64_t, custom_divide_variable<int64_t> > (data64, SIZE, var1int64_1, "int64_t variable divide");
test_variable4< int64_t, custom_divide_multiple_variable<int64_t> > (data64, SIZE, var1int64_1, var1int64_2, var1int64_3, var1int64_4, "int64_t multiple variable divides");
test_variable4< int64_t, custom_divide_multiple_variable2<int64_t> > (data64, SIZE, var1int64_1, var1int64_2, var1int64_3, var1int64_4, "int64_t multiple variable divides2");
test_variable4< int64_t, custom_mixed_multiple_variable<int64_t> > (data64, SIZE, var1int64_1, var1int64_2, var1int64_3, var1int64_4, "int64_t multiple variable mixed");
test_variable1< int64_t, custom_variable_and<int64_t> > (data64, SIZE, var1int64_1, "int64_t variable and");
test_variable4< int64_t, custom_multiple_variable_and<int64_t> > (data64, SIZE, var1int64_1, var1int64_2, var1int64_3, var1int64_4, "int64_t multiple variable and");
test_variable1< int64_t, custom_variable_or<int64_t> > (data64, SIZE, var1int64_1, "int64_t variable or");
test_variable4< int64_t, custom_multiple_variable_or<int64_t> > (data64, SIZE, var1int64_1, var1int64_2, var1int64_3, var1int64_4, "int64_t multiple variable or");
test_variable1< int64_t, custom_variable_xor<int64_t> > (data64, SIZE, var1int64_1, "int64_t variable xor");
test_variable4< int64_t, custom_multiple_variable_xor<int64_t> > (data64, SIZE, var1int64_1, var1int64_2, var1int64_3, var1int64_4, "int64_t multiple variable xor");
summarize("int64_t loop invariant", SIZE, iterations, kDontShowGMeans, kDontShowPenalty );
// unsigned64
::fill(data64unsigned, data64unsigned+SIZE, uint64_t(init_value));
uint64_t var1uint64_1, var1uint64_2, var1uint64_3, var1uint64_4;
var1uint64_1 = uint64_t(temp);
var1uint64_2 = var1uint64_1 * uint64_t(2);
var1uint64_3 = var1uint64_1 + uint64_t(2);
var1uint64_4 = var1uint64_1 + var1uint64_2 / var1uint64_3;
// test moving redundant calcs out of loop
test_variable1< uint64_t, custom_add_variable<uint64_t> > (data64unsigned, SIZE, var1uint64_1, "uint64_t variable add");
test_hoisted_variable1< uint64_t, custom_add_variable<uint64_t> > (data64unsigned, SIZE, var1uint64_1, "uint64_t variable add hoisted");
test_variable4< uint64_t, custom_add_multiple_variable<uint64_t> > (data64unsigned, SIZE, var1uint64_1, var1uint64_2, var1uint64_3, var1uint64_4, "uint64_t multiple variable adds");
test_variable1< uint64_t, custom_sub_variable<uint64_t> > (data64unsigned, SIZE, var1uint64_1, "uint64_t variable subtract");
test_variable4< uint64_t, custom_sub_multiple_variable<uint64_t> > (data64unsigned, SIZE, var1uint64_1, var1uint64_2, var1uint64_3, var1uint64_4, "uint64_t multiple variable subtracts");
test_variable1< uint64_t, custom_multiply_variable<uint64_t> > (data64unsigned, SIZE, var1uint64_1, "uint64_t variable multiply");
test_variable4< uint64_t, custom_multiply_multiple_variable<uint64_t> > (data64unsigned, SIZE, var1uint64_1, var1uint64_2, var1uint64_3, var1uint64_4, "uint64_t multiple variable multiplies");
test_variable4< uint64_t, custom_multiply_multiple_variable2<uint64_t> > (data64unsigned, SIZE, var1uint64_1, var1uint64_2, var1uint64_3, var1uint64_4, "uint64_t multiple variable multiplies2");
test_variable1< uint64_t, custom_divide_variable<uint64_t> > (data64unsigned, SIZE, var1uint64_1, "uint64_t variable divide");
test_variable4< uint64_t, custom_divide_multiple_variable<uint64_t> > (data64unsigned, SIZE, var1uint64_1, var1uint64_2, var1uint64_3, var1uint64_4, "uint64_t multiple variable divides");
test_variable4< uint64_t, custom_divide_multiple_variable2<uint64_t> > (data64unsigned, SIZE, var1uint64_1, var1uint64_2, var1uint64_3, var1uint64_4, "uint64_t multiple variable divides2");
test_variable4< uint64_t, custom_mixed_multiple_variable<uint64_t> > (data64unsigned, SIZE, var1uint64_1, var1uint64_2, var1uint64_3, var1uint64_4, "uint64_t multiple variable mixed");
test_variable1< uint64_t, custom_variable_and<uint64_t> > (data64unsigned, SIZE, var1uint64_1, "uint64_t variable and");
test_variable4< uint64_t, custom_multiple_variable_and<uint64_t> > (data64unsigned, SIZE, var1uint64_1, var1uint64_2, var1uint64_3, var1uint64_4, "uint64_t multiple variable and");
test_variable1< uint64_t, custom_variable_or<uint64_t> > (data64unsigned, SIZE, var1uint64_1, "uint64_t variable or");
test_variable4< uint64_t, custom_multiple_variable_or<uint64_t> > (data64unsigned, SIZE, var1uint64_1, var1uint64_2, var1uint64_3, var1uint64_4, "uint64_t multiple variable or");
test_variable1< uint64_t, custom_variable_xor<uint64_t> > (data64unsigned, SIZE, var1uint64_1, "uint64_t variable xor");
test_variable4< uint64_t, custom_multiple_variable_xor<uint64_t> > (data64unsigned, SIZE, var1uint64_1, var1uint64_2, var1uint64_3, var1uint64_4, "uint64_t multiple variable xor");
summarize("uint64_t loop invariant", SIZE, iterations, kDontShowGMeans, kDontShowPenalty );
// float
::fill(dataFloat, dataFloat+SIZE, float(init_value));
float var1Float_1, var1Float_2, var1Float_3, var1Float_4;
var1Float_1 = float(temp);
var1Float_2 = var1Float_1 * float(2.0);
var1Float_3 = var1Float_1 + float(2.0);
var1Float_4 = var1Float_1 + var1Float_2 / var1Float_3;
// test moving redundant calcs out of loop
test_variable1< float, custom_add_variable<float> > (dataFloat, SIZE, var1Float_1, "float variable add");
test_hoisted_variable1< float, custom_add_variable<float> > (dataFloat, SIZE, var1Float_1, "float variable add hoisted");
test_variable4< float, custom_add_multiple_variable<float> > (dataFloat, SIZE, var1Float_1, var1Float_2, var1Float_3, var1Float_4, "float multiple variable adds");
test_variable1< float, custom_sub_variable<float> > (dataFloat, SIZE, var1Float_1, "float variable subtract");
test_variable4< float, custom_sub_multiple_variable<float> > (dataFloat, SIZE, var1Float_1, var1Float_2, var1Float_3, var1Float_4, "float multiple variable subtracts");
test_variable1< float, custom_multiply_variable<float> > (dataFloat, SIZE, var1Float_1, "float variable multiply");
test_variable4< float, custom_multiply_multiple_variable<float> > (dataFloat, SIZE, var1Float_1, var1Float_2, var1Float_3, var1Float_4, "float multiple variable multiplies");
test_variable4< float, custom_multiply_multiple_variable2<float> > (dataFloat, SIZE, var1Float_1, var1Float_2, var1Float_3, var1Float_4, "float multiple variable multiplies2");
test_variable1< float, custom_divide_variable<float> > (dataFloat, SIZE, var1Float_1, "float variable divide");
test_variable4< float, custom_divide_multiple_variable<float> > (dataFloat, SIZE, var1Float_1, var1Float_2, var1Float_3, var1Float_4, "float multiple variable divides");
test_variable4< float, custom_divide_multiple_variable2<float> > (dataFloat, SIZE, var1Float_1, var1Float_2, var1Float_3, var1Float_4, "float multiple variable divides2");
test_variable4< float, custom_mixed_multiple_variable<float> > (dataFloat, SIZE, var1Float_1, var1Float_2, var1Float_3, var1Float_4, "float multiple variable mixed");
summarize("float loop invariant", SIZE, iterations, kDontShowGMeans, kDontShowPenalty );
// double
::fill(dataDouble, dataDouble+SIZE, double(init_value));
double var1Double_1, var1Double_2, var1Double_3, var1Double_4;
var1Double_1 = double(temp);
var1Double_2 = var1Double_1 * double(2.0);
var1Double_3 = var1Double_1 + double(2.0);
var1Double_4 = var1Double_1 + var1Double_2 / var1Double_3;
// test moving redundant calcs out of loop
test_variable1< double, custom_add_variable<double> > (dataDouble, SIZE, var1Double_1, "double variable add");
test_hoisted_variable1< double, custom_add_variable<double> > (dataDouble, SIZE, var1Double_1, "double variable add hoisted");
test_variable4< double, custom_add_multiple_variable<double> > (dataDouble, SIZE, var1Double_1, var1Double_2, var1Double_3, var1Double_4, "double multiple variable adds");
test_variable1< double, custom_sub_variable<double> > (dataDouble, SIZE, var1Double_1, "double variable subtract");
test_variable4< double, custom_sub_multiple_variable<double> > (dataDouble, SIZE, var1Double_1, var1Double_2, var1Double_3, var1Double_4, "double multiple variable subtracts");
test_variable1< double, custom_multiply_variable<double> > (dataDouble, SIZE, var1Double_1, "double variable multiply");
test_variable4< double, custom_multiply_multiple_variable<double> > (dataDouble, SIZE, var1Double_1, var1Double_2, var1Double_3, var1Double_4, "double multiple variable multiplies");
test_variable4< double, custom_multiply_multiple_variable2<double> > (dataDouble, SIZE, var1Double_1, var1Double_2, var1Double_3, var1Double_4, "double multiple variable multiplies2");
test_variable1< double, custom_divide_variable<double> > (dataDouble, SIZE, var1Double_1, "double variable divide");
test_variable4< double, custom_divide_multiple_variable<double> > (dataDouble, SIZE, var1Double_1, var1Double_2, var1Double_3, var1Double_4, "double multiple variable divides");
test_variable4< double, custom_divide_multiple_variable2<double> > (dataDouble, SIZE, var1Double_1, var1Double_2, var1Double_3, var1Double_4, "double multiple variable divides2");
test_variable4< double, custom_mixed_multiple_variable<double> > (dataDouble, SIZE, var1Double_1, var1Double_2, var1Double_3, var1Double_4, "double multiple variable mixed");
summarize("double loop invariant", SIZE, iterations, kDontShowGMeans, kDontShowPenalty );
return 0;
}
// the end
/******************************************************************************/
/******************************************************************************/