FK20 CUDA
fptest_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 "fp.cuh"
6 #include "fptest.cuh"
7 
16 __global__ void FpTestSub(testval_t *testval) {
17 
18  printf("=== RUN %s\n", __func__);
19 
20  bool pass = true;
21  size_t count = 0;
22 
23  fp_t x, l, r;
24 
25  // 2x == 3x - x
26 
27  for (int i=0; pass && i<TESTVALS; i++) {
28  fp_cpy(x, testval[i]);
29 
30  fp_x2(l, x);
31 
32  fp_x3(r, x);
33  fp_sub(r, r, x);
34 
35  if (fp_neq(l, r)) {
36  pass = false;
37 
38  printf("%d: FAILED\n", i);
39  fp_print("x : ", x);
40  fp_print("2x : ", l);
41  fp_print("3x-x : ", r);
42  }
43  ++count;
44  }
45 
46  printf("%ld tests\n", count);
47 
48  PRINTPASS(pass);
49 }
50 
51 // vim: ts=4 et sw=4 si
__device__ void fp_print(const char *s, const fp_t &x)
Prints the canonical representation of x to STDOUT.
Definition: fp.cu:39
__device__ bool fp_neq(const fp_t &x, const fp_t &y)
Compares two fp_t residues.
Definition: fp_neq.cu:14
__device__ void fp_x2(fp_t &z, const fp_t &x)
Multiplies x by 2 and stores the result into z.
Definition: fp_x2.cu:15
uint64_t fp_t[6]
Residue modulo p. Any 384-bit representative of each residue is allowed, and stored as a 6-element li...
Definition: fp.cuh:14
__device__ __host__ void fp_cpy(fp_t &z, const fp_t &x)
Copy from x into z.
Definition: fp_cpy.cu:14
__device__ void fp_x3(fp_t &z, const fp_t &x)
Multiplies x by 3 and stores the result into z.
Definition: fp_x3.cu:15
__device__ void fp_sub(fp_t &z, const fp_t &x, const fp_t &y)
Calculates the difference of two residues modulo p and stores it into z.
Definition: fp_sub.cu:16
__managed__ testval_t testval[TESTVALS]
Definition: fptest.cu:8
#define TESTVALS
Definition: fptest.cuh:13
__global__ void FpTestSub(testval_t *testval)
Test for subtraction in Fp.
Definition: fptest_sub.cu:16
#define PRINTPASS(pass)
Definition: test.h:25