-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfptest_fibonacci.cu
168 lines (130 loc) · 3.68 KB
/
fptest_fibonacci.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
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
// 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"
#include "fp_ptx.cuh"
#define ITERATIONS 100000
/**
* @brief Test addition and subtraction in Fp using a fibonacci sequence (chain
* dependency) from 1 to ITERATIONS and back
*
* @return void
*/
__global__ void FpTestFibonacci(testval_t *) {
printf("=== RUN %s\n", __func__);
bool pass = true;
size_t count = 0;
fp_t x, y, t, u, X, Y;
fp_one(X);
fp_one(Y);
for(int ii=0; ii<3; ii++){ //test with different start points for fibonacci
fp_cpy(x, X);
fp_cpy(y, Y);
for (int i=0; i<ITERATIONS; i++) {
fp_cpy(t, x);
fp_add(x, x, y);
fp_cpy(u, x);
fp_sub(u, u, t);
if (fp_neq(u, y)) {
fp_print("x =", x);
fp_print("y =", y);
fp_print("x+y =", t);
fp_print("x+y-x =", u);
pass = false;
break;
}
++count;
fp_cpy(t, y);
fp_add(y, y, x);
fp_cpy(u, y);
fp_sub(u, u, t);
if (fp_neq(u, x)) {
fp_print("x =", x);
fp_print("y =", y);
fp_print("x+y =", t);
fp_print("x+y-y =", u);
pass = false;
break;
}
++count;
}
for (int i=0; i<ITERATIONS; i++) {
fp_sub(y, y, x);
fp_sub(x, x, y);
}
if (fp_neq(x, X) || fp_neq(y, Y)) {
printf("Reverse iteration failed\n");
fp_print("x =", x);
fp_print("y =", y);
pass = false;
}
else
++count;
Y[0]+=3;
}
printf("%ld tests passed\n", count);
PRINTPASS(pass);
}
/**
* @brief Test addition and subtraction in Fp using a fibonacci sequence (chain
* dependency) from 1 to ITERATIONS and back (Using PTX macros)
*
* @return void
*/
__global__ void FpTestFibonacciPTX(testval_t *) {
printf("=== RUN %s\n", __func__);
bool pass = true;
size_t count = 0;
fp_t x, y, t, u, X, Y;
fp_one(X);
fp_one(Y);
for(int ii=0; ii<3; ii++){ //test with different start points for fibonacci
fp_cpy(x, X);
fp_cpy(y, Y);
for (int i=0; i<ITERATIONS; i++) {
fp_cpy(t, x);
fp_add_ptx(x, x, y);
fp_cpy(u, x);
fp_sub_ptx(u, u, t);
if (fp_neq(u, y)) {
fp_print("x =", x);
fp_print("y =", y);
fp_print("x+y =", t);
fp_print("x+y-x =", u);
pass = false;
break;
}
++count;
fp_cpy(t, y);
fp_add_ptx(y, y, x);
fp_cpy(u, y);
fp_sub_ptx(u, u, t);
if (fp_neq(u, x)) {
fp_print("x =", x);
fp_print("y =", y);
fp_print("x+y =", t);
fp_print("x+y-y =", u);
pass = false;
break;
}
++count;
}
for (int i=0; i<ITERATIONS; i++) {
fp_sub_ptx(y, y, x);
fp_sub_ptx(x, x, y);
}
if (fp_neq(x, X) || fp_neq(y, Y)) {
printf("Reverse iteration failed\n");
fp_print("x =", x);
fp_print("y =", y);
pass = false;
}
else
++count;
Y[0]+=3;
}
printf("%ld tests passed\n", count);
PRINTPASS(pass);
}
// vim: ts=4 et sw=4 si