FK20 CUDA
frtest_cmp.cu
Go to the documentation of this file.
1 // bls12_381: Arithmetic for BLS12-381
2 // Copyright 2022-2023 Dag Arne Osvik
3 // Copyright 2022-2023 Luan Cardoso dos Santos
4 
5 #include "fr.cuh"
6 #include "frtest.cuh"
7 
21 __global__ void FrTestCmp(testval_t *testval) {
22 
23  printf("=== RUN %s\n", __func__);
24 
25  bool pass = true;
26  size_t count = 0;
27 
28  for (int i=2; i<514; i++) {
29  fr_t x;
30 
31  fr_cpy(x, testval[i]);
32 
33  for (int j=2; j<514; j++) {
34  fr_t y;
35 
36  fr_cpy(y, testval[j]);
37 
38  uint64_t
39  eq = fr_eq (x, y),
40  neq = fr_neq(x, y);
41 
42  if (eq == neq) {
43  pass = false;
44 
45  printf("%d,%d: FAILED: inconsistent result, eq = %lx, neq = %lx\n", i, j, eq, neq);
46  }
47 
48  if ((i == j) && !eq) {
49  pass = false;
50 
51  printf("%d,%d: FAIL A: fr_eq claims inequality between these values:\n", i, j);
52 
53  printf("\t%016lX%016lX%016lX%016lX/\n",
54  testval[i][3], testval[i][2], testval[i][1], testval[i][0]);
55 
56  printf("\t%016lX%016lX%016lX%016lX\n",
57  x[3], x[2], x[1], x[0]);
58 
59  printf("\t%016lX%016lX%016lX%016lX/\n",
60  testval[j][3], testval[j][2], testval[j][1], testval[j][0]);
61 
62  printf("\t%016lX%016lX%016lX%016lX\n",
63  y[3], y[2], y[1], y[0]);
64 
65  printf("eq = %lx, neq = %lx\n", eq, neq);
66  }
67 
68  if ((i != j) && eq) {
69  pass = false;
70 
71  printf("%d,%d: FAIL B: fr_eq claims equality between these values:\n", i, j);
72 
73  printf("\t%016lX%016lX%016lX%016lX/\n",
74  testval[i][3], testval[i][2], testval[i][1], testval[i][0]);
75 
76  printf("\t%016lX%016lX%016lX%016lX\n",
77  x[3], x[2], x[1], x[0]);
78 
79  printf("\t%016lX%016lX%016lX%016lX/\n",
80  testval[j][3], testval[j][2], testval[j][1], testval[j][0]);
81 
82  printf("\t%016lX%016lX%016lX%016lX\n",
83  y[3], y[2], y[1], y[0]);
84 
85  printf("eq = %lx, neq = %lx\n", eq, neq);
86  }
87 
88  if ((i == j) && neq) {
89  pass = false;
90 
91  printf("%d,%d: FAIL C: fr_neq claims inequality between these values:\n", i, j);
92 
93  printf("\t%016lX%016lX%016lX%016lX/\n",
94  testval[i][3], testval[i][2], testval[i][1], testval[i][0]);
95 
96  printf("\t%016lX%016lX%016lX%016lX\n",
97  x[3], x[2], x[1], x[0]);
98 
99  printf("\t%016lX%016lX%016lX%016lX/\n",
100  testval[j][3], testval[j][2], testval[j][1], testval[j][0]);
101 
102  printf("\t%016lX%016lX%016lX%016lX\n",
103  y[3], y[2], y[1], y[0]);
104 
105  printf("eq = %lx, neq = %lx\n", eq, neq);
106  }
107 
108  if ((i != j) && !neq) {
109  pass = false;
110 
111  printf("%d,%d: FAIL D: fr_neq claims equality between these values:\n", i, j);
112 
113  printf("\t%016lX%016lX%016lX%016lX/\n",
114  testval[i][3], testval[i][2], testval[i][1], testval[i][0]);
115 
116  printf("\t%016lX%016lX%016lX%016lX\n",
117  x[3], x[2], x[1], x[0]);
118 
119  printf("\t%016lX%016lX%016lX%016lX/\n",
120  testval[j][3], testval[j][2], testval[j][1], testval[j][0]);
121 
122  printf("\t%016lX%016lX%016lX%016lX\n",
123  y[3], y[2], y[1], y[0]);
124 
125  printf("eq = %lx, neq = %lx\n", eq, neq);
126  }
127  ++count;
128  }
129  }
130  printf("%ld tests\n", count);
131 
132  PRINTPASS(pass);
133 }
134 
135 // vim: ts=4 et sw=4 si
__managed__ testval_t testval[TESTVALS]
Definition: fptest.cu:8
__device__ bool fr_eq(const fr_t &x, const fr_t &y)
Compares two residues modulo r.
Definition: fr_eq.cu:13
__device__ bool fr_neq(const fr_t &x, const fr_t &y)
Compares two fr_t residues.
Definition: fr_neq.cu:15
uint64_t fr_t[4]
Subgroup element stored as a 256-bit array (a 4-element little-endian array of uint64_t)....
Definition: fr.cuh:24
__device__ __host__ void fr_cpy(fr_t &z, const fr_t &x)
Copy from x into z.
Definition: fr_cpy.cu:14
__global__ void FrTestCmp(testval_t *testval)
Test for the comparison function; checks for inconsistencies in the following properties:
Definition: frtest_cmp.cu:21
#define PRINTPASS(pass)
Definition: test.h:25