-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfp_x2.ptxh
48 lines (45 loc) · 1.66 KB
/
fp_x2.ptxh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// bls12_381: Arithmetic for BLS12-381
// Copyright 2022-2023 Dag Arne Osvik
// Copyright 2022-2023 Luan Cardoso dos Santos
#ifndef FP_X2
/**
* @brief PTX macro for multiplication by 2. Z ← 2*X
* Z and X may be the same. Modifies T6.
*
* For inclusion directly into ptx code by the C preprocessor.
*/
#define FP_X2(Z, X, T) newline\
/* z = x + x */ newline\
\
add.u64.cc Z##0, X##0, X##0; newline\
addc.u64.cc Z##1, X##1, X##1; newline\
addc.u64.cc Z##2, X##2, X##2; newline\
addc.u64.cc Z##3, X##3, X##3; newline\
addc.u64.cc Z##4, X##4, X##4; newline\
addc.u64.cc Z##5, X##5, X##5; newline\
addc.u32 T##6, 0, 0; newline\
\
/* gt = (z>>320) > (m>>320) */ newline\
/* nz = (z>>384) > 0 */ newline\
\
setp.gt.u64 gt, Z##5, 0x1a0111ea397fe69aU; newline\
setp.ne.u32 nz, T##6, 0; newline\
\
/* If gt then subtract m */ newline\
\
@gt sub.u64.cc Z##0, Z##0, 0xb9feffffffffaaabU; newline\
@gt subc.u64.cc Z##1, Z##1, 0x1eabfffeb153ffffU; newline\
@gt subc.u64.cc Z##2, Z##2, 0x6730d2a0f6b0f624U; newline\
@gt subc.u64.cc Z##3, Z##3, 0x64774b84f38512bfU; newline\
@gt subc.u64.cc Z##4, Z##4, 0x4b1ba7b6434bacd7U; newline\
@gt subc.u64.cc Z##5, Z##5, 0x1a0111ea397fe69aU; newline\
\
/* If nz then subtract mmu0 (= 9m) */ newline\
\
@nz sub.u64.cc Z##0, Z##0, 0x89F6FFFFFFFD0003U; newline\
@nz subc.u64.cc Z##1, Z##1, 0x140BFFF43BF3FFFDU; newline\
@nz subc.u64.cc Z##2, Z##2, 0xA0B767A8AC38A745U; newline\
@nz subc.u64.cc Z##3, Z##3, 0x8831A7AC8FADA8BAU; newline\
@nz subc.u64.cc Z##4, Z##4, 0xA3F8E5685DA91392U; newline\
@nz subc.u64.cc Z##5, Z##5, 0xEA09A13C057F1B6CU
#endif