FK20 CUDA
All Data Structures Namespaces Files Functions Variables Typedefs Macros
fp_neg.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 
16 __device__ void fp_neg(fp_t &z, const fp_t &x) {
17  uint64_t
18  x0 = x[0], z0,
19  x1 = x[1], z1,
20  x2 = x[2], z2,
21  x3 = x[3], z3,
22  x4 = x[4], z4,
23  x5 = x[5], z5;
24 
25  asm volatile (
26  "\n\t{"
27  "\n\t.reg .u32 z6;"
28  "\n\t.reg .pred nz;"
29 
30  // z = pmmu0 - x
31 
32  "\n\tsub.u64.cc %0, 0x89F6FFFFFFFD0003U, %6;"
33  "\n\tsubc.u64.cc %1, 0x140BFFF43BF3FFFDU, %7;"
34  "\n\tsubc.u64.cc %2, 0xA0B767A8AC38A745U, %8;"
35  "\n\tsubc.u64.cc %3, 0x8831A7AC8FADA8BAU, %9;"
36  "\n\tsubc.u64.cc %4, 0xA3F8E5685DA91392U, %10;"
37  "\n\tsubc.u64.cc %5, 0xEA09A13C057F1B6CU, %11;"
38  "\n\tsubc.u32 z6, 0, 0;"
39  "\n\tsetp.ne.u32 nz, z6, 0;"
40 
41  // if nz (borrow) then z += p
42 
43  "\n@nz\tadd.u64.cc %0, %0, 0xB9FEFFFFFFFFAAABU;"
44  "\n@nz\taddc.u64.cc %1, %1, 0x1EABFFFEB153FFFFU;"
45  "\n@nz\taddc.u64.cc %2, %2, 0x6730D2A0F6B0F624U;"
46  "\n@nz\taddc.u64.cc %3, %3, 0x64774B84F38512BFU;"
47  "\n@nz\taddc.u64.cc %4, %4, 0x4B1BA7B6434BACD7U;"
48  "\n@nz\taddc.u64 %5, %5, 0x1A0111EA397FE69AU;"
49 
50  "\n\t}"
51  :
52  "=l"(z0), "=l"(z1), "=l"(z2), "=l"(z3), "=l"(z4), "=l"(z5)
53  :
54  "l"(x0), "l"(x1), "l"(x2), "l"(x3), "l"(x4), "l"(x5)
55  );
56 
57  z[0] = z0, z[1] = z1, z[2] = z2, z[3] = z3, z[4] = z4, z[5] = z5;
58 }
59 
60 // vim: ts=4 et sw=4 si
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__ void fp_neg(fp_t &z, const fp_t &x)
Compute an additive inverse of a residue x modulo p. Stores in z. Subtracts x from the highest multip...
Definition: fp_neg.cu:16