-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfptest_cmp.cu
135 lines (94 loc) · 4.36 KB
/
fptest_cmp.cu
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
// bls12_381: Arithmetic for BLS12-381
// Copyright 2022-2023 Dag Arne Osvik
// Copyright 2022-2023 Luan Cardoso dos Santos
#include "fp.cuh"
#include "fptest.cuh"
/**
* @brief Test for the comparison function in Fp; checks for inconsistencies in the
* following properties:
*
* eq(x,x) != neq(x,x)
* neq(x,x) == false
* neq(x,y) == true
* eq(x,x) == true
* eq(x,y) == false
*
* @param testval
* @return void
*/
__global__ void FpTestCmp(testval_t *testval) {
printf("=== RUN %s\n", __func__);
bool pass = true;
size_t count = 0;
for (int i=3; i<770; i++) {
uint64_t x[6];
fp_cpy(x, testval[i]);
for (int j=3; j<770; j++) {
uint64_t y[6];
fp_cpy(y, testval[j]);
uint64_t
eq = fp_eq (x, y),
neq = fp_neq(x, y);
if (eq == neq) {
pass = false;
printf("%d,%d: FAILED: inconsistent result, eq = %lx, neq = %lx\n", i, j, eq, neq);
}
if ((i == j) && !eq) {
pass = false;
printf("%d,%d: FAIL A: fp_eq claims inequality between these values:\n", i, j);
printf("\t%016lX%016lX%016lX%016lX%016lX%016lX/\n",
testval[i][5], testval[i][4], testval[i][3], testval[i][2], testval[i][1], testval[i][0]);
printf("\t%016lX%016lX%016lX%016lX%016lX%016lX\n",
x[5], x[4], x[3], x[2], x[1], x[0]);
printf("\t%016lX%016lX%016lX%016lX%016lX%016lX/\n",
testval[j][5], testval[j][4], testval[j][3], testval[j][2], testval[j][1], testval[j][0]);
printf("\t%016lX%016lX%016lX%016lX%016lX%016lX\n",
y[5], y[4], y[3], y[2], y[1], y[0]);
printf("eq = %lx, neq = %lx\n", eq, neq);
}
if ((i != j) && eq) {
pass = false;
printf("%d,%d: FAIL B: fp_eq claims equality between these values:\n", i, j);
printf("\t%016lX%016lX%016lX%016lX%016lX%016lX/\n",
testval[i][5], testval[i][4], testval[i][3], testval[i][2], testval[i][1], testval[i][0]);
printf("\t%016lX%016lX%016lX%016lX%016lX%016lX\n",
x[5], x[4], x[3], x[2], x[1], x[0]);
printf("\t%016lX%016lX%016lX%016lX%016lX%016lX/\n",
testval[j][5], testval[j][4], testval[j][3], testval[j][2], testval[j][1], testval[j][0]);
printf("\t%016lX%016lX%016lX%016lX%016lX%016lX\n",
y[5], y[4], y[3], y[2], y[1], y[0]);
printf("eq = %lx, neq = %lx\n", eq, neq);
}
if ((i == j) && neq) {
pass = false;
printf("%d,%d: FAIL C: fp_neq claims inequality between these values:\n", i, j);
printf("\t%016lX%016lX%016lX%016lX%016lX%016lX/\n",
testval[i][5], testval[i][4], testval[i][3], testval[i][2], testval[i][1], testval[i][0]);
printf("\t%016lX%016lX%016lX%016lX%016lX%016lX\n",
x[5], x[4], x[3], x[2], x[1], x[0]);
printf("\t%016lX%016lX%016lX%016lX%016lX%016lX/\n",
testval[j][5], testval[j][4], testval[j][3], testval[j][2], testval[j][1], testval[j][0]);
printf("\t%016lX%016lX%016lX%016lX%016lX%016lX\n",
y[5], y[4], y[3], y[2], y[1], y[0]);
printf("eq = %lx, neq = %lx\n", eq, neq);
}
if ((i != j) && !neq) {
pass = false;
printf("%d,%d: FAIL D: fp_neq claims equality between these values:\n", i, j);
printf("\t%016lX%016lX%016lX%016lX%016lX%016lX/\n",
testval[i][5], testval[i][4], testval[i][3], testval[i][2], testval[i][1], testval[i][0]);
printf("\t%016lX%016lX%016lX%016lX%016lX%016lX\n",
x[5], x[4], x[3], x[2], x[1], x[0]);
printf("\t%016lX%016lX%016lX%016lX%016lX%016lX/\n",
testval[j][5], testval[j][4], testval[j][3], testval[j][2], testval[j][1], testval[j][0]);
printf("\t%016lX%016lX%016lX%016lX%016lX%016lX\n",
y[5], y[4], y[3], y[2], y[1], y[0]);
printf("eq = %lx, neq = %lx\n", eq, neq);
}
++count;
}
}
printf("%ld tests\n", count);
PRINTPASS(pass);
}
// vim: ts=4 et sw=4 si