-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark.c
87 lines (73 loc) · 2.13 KB
/
benchmark.c
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
#include <papi.h>
#include <stdio.h>
#include <arm_neon.h>
#include <sys/random.h>
#include <string.h>
// Include constant file to keep this file short
#include "benchmark_sorting_const.h"
// #define TESTS 1000000
#define BUF_LEN 528
int main()
{
int16_t r_test[256], r_test_half[256], r_gold[256], r_test_mix[256];
uint8_t input[BUF_LEN];
int cnt_gold = 0, cnt_test = 0, cnt_test_half = 0, cnt_test_mix = 0;
int i;
// Quick sampling input, in our implementation genradom is SHAKE128
getrandom(input, sizeof(input), 0);
PAPI_hl_region_begin("rej_uniform");
for (i = 0; i < TESTS; i++)
{
cnt_gold = rej_uniform(r_gold, 256, input, sizeof(input));
}
PAPI_hl_region_end("rej_uniform");
PAPI_hl_region_begin("neon_rej_uniform");
for (i = 0; i < TESTS; i++)
{
cnt_test = neon_rej_uniform(r_test, input);
}
PAPI_hl_region_end("neon_rej_uniform");
PAPI_hl_region_begin("neon_rej_uniform_half");
for (i = 0; i < TESTS; i++)
{
cnt_test_half = neon_rej_uniform_half(r_test_half, input);
}
PAPI_hl_region_end("neon_rej_uniform_half");
PAPI_hl_region_begin("neon_rej_uniform_mix");
for (i = 0; i < TESTS; i++)
{
cnt_test_mix = neon_rej_uniform_mix(r_test_mix, input);
}
PAPI_hl_region_end("neon_rej_uniform_mix");
if (cnt_gold != cnt_test)
{
printf("Error: cnt_gold != cnt_test: %d != %d\n", cnt_gold, cnt_test);
return 1;
}
if (compare(r_gold, r_test, cnt_gold))
{
printf("Error: r_gold != r_test\n");
return 1;
}
if (cnt_gold != cnt_test_half)
{
printf("Error: cnt_gold != cnt_test_half: %d != %d\n", cnt_gold, cnt_test_half);
return 1;
}
if (compare(r_gold, r_test_half, cnt_gold))
{
printf("Error: r_gold != r_test_half \n");
return 1;
}
if (cnt_gold != cnt_test_mix)
{
printf("Error: cnt_gold != cnt_test_mix: %d != %d\n", cnt_gold, cnt_test_mix);
return 1;
}
if (compare(r_gold, r_test_mix, cnt_gold))
{
printf("Error: r_gold != r_test_mix\n");
return 1;
}
return 0;
}