FK20 CUDA
frtest_sub.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 
15 __global__ void FrTestSub(testval_t *testval) {
16 
17  printf("=== RUN %s\n", __func__);
18 
19  bool pass = true;
20  size_t count = 0;
21 
22  // x == y-(y-x)
23 
24  for (int i=0; i<TESTVALS; i++) {
25  for (int j=0; j<TESTVALS; j++) {
26  fr_t a, b;
27 
28  fr_cpy(a, testval[j]); // y
29  fr_cpy(b, testval[j]); // y
30 
31  fr_sub(a, testval[i]); // y - x
32  fr_sub(b, a); // y - (y - x)
33 
34  if (fr_neq(b, testval[i])) {
35  pass = false;
36 
37  printf("%d,%d: FAILED: inconsistent result\n", i, j);
38  fr_print("x = ", testval[i]);
39  fr_print("y = ", testval[j]);
40  fr_print("y-x = ", a);
41  fr_print("y-(y-x) = ", b);
42  }
43  ++count;
44  }
45  }
46 
47  // x
48  printf("%ld tests\n", count);
49 
50  PRINTPASS(pass);
51 }
52 
53 // vim: ts=4 et sw=4 si
__managed__ testval_t testval[TESTVALS]
Definition: fptest.cu:8
#define TESTVALS
Definition: fptest.cuh:13
__device__ void fr_print(const char *s, const fr_t &x)
prints the canonical representation of x to STDOUT.
Definition: fr.cu:41
__device__ void fr_sub(fr_t &z, const fr_t &x)
Calculates the difference of two residues modulo p and stores it into z.
Definition: fr_sub.cu:17
__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 FrTestSub(testval_t *testval)
Test of subtraction x == y-(y-x)
Definition: frtest_sub.cu:15
#define PRINTPASS(pass)
Definition: test.h:25