FK20 CUDA
fp.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 <stdio.h>
6 
7 #include "fp.cuh"
8 
15 __device__ __host__ void fp_zero(fp_t &z) {
16  for (int i=0; i<6; i++)
17  z[i] = 0;
18 }
19 
26 __device__ __host__ void fp_one(fp_t &z) {
27  z[0] = 1;
28  for (int i=1; i<6; i++)
29  z[i] = 0;
30 }
31 
39 __device__ void fp_print(const char *s, const fp_t &x) {
40  fp_t t;
41  fp_cpy(t, x);
42  fp_reduce6(t);
43  printf("%s", s);
44 // printf("#x%016lx%016lx%016lx%016lx%016lx%016lx\n", // clisp
45  printf("%016lX%016lX%016lX%016lX%016lX%016lX\n", // dc
46 // printf("0x%016lx%016lx%016lx%016lx%016lx%016lx\n", // python
47  t[5], t[4], t[3], t[2], t[1], t[0]);
48 }
49 
58 __device__ __host__ void fp_fromUint64(fp_t &z, const uint64_t *x) {
59  z[0] = x[0];
60  z[1] = x[1];
61  z[2] = x[2];
62  z[3] = x[3];
63  z[4] = x[4];
64  z[5] = x[5];
65 }
66 
75 __device__ void fp_toUint64(uint64_t *z, const fp_t &x) {
76  fp_t t;
77  fp_cpy(t, x);
78  fp_reduce6(t);
79 
80  z[0] = x[0];
81  z[1] = x[1];
82  z[2] = x[2];
83  z[3] = x[3];
84  z[4] = x[4];
85  z[5] = x[5];
86 }
87 
88 // vim: ts=4 et sw=4 si
__device__ void fp_toUint64(uint64_t *z, const fp_t &x)
Converts from residue modulo p (fp_t) to uint64_t[6]. The converted value is in canonical form.
Definition: fp.cu:75
__device__ void fp_print(const char *s, const fp_t &x)
Prints the canonical representation of x to STDOUT.
Definition: fp.cu:39
__device__ __host__ void fp_zero(fp_t &z)
Sets z to zero.
Definition: fp.cu:15
__device__ __host__ void fp_one(fp_t &z)
Sets z to one.
Definition: fp.cu:26
__device__ __host__ void fp_fromUint64(fp_t &z, const uint64_t *x)
Converts uint64_t[6] to fp_t. After this operation, z represents x mod p.
Definition: fp.cu:58
__device__ void fp_reduce6(fp_t &z)
Narrow reduction of a residue modulo p, reducing to the canonical representation.
Definition: fp_reduce6.cu:14
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