Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
vector_field_mont_mul_body.inl.hpp
Go to the documentation of this file.
1// Body of VectorField<Params>::operator* under WASM SIMD. Included inside
2// per-Params explicit specializations in vector_field_wasm.cpp so each one
3// stamps a fresh kernel resolving R_INV_WASM / P_WASM / R_INV_MOD_2_29
4// against the surrounding class's static constexpr Params constants.
5//
6// The macros it expands (BB_VF_LOAD_LIMBS, BB_VF_KARATSUBA_STAGES_1_4,
7// BB_VF_RUN_STAGES_6_THROUGH_10) are Params-agnostic — they use unqualified
8// names that resolve in the enclosing scope. Stage 5 (the temp_*/tlo_*/thi_*
9// combine between the two macros) is pure arithmetic over the previous
10// stage's locals and is likewise Params-agnostic.
11//
12// Including this file inside `{ ... }` of a `VectorField<Foo>::operator*`
13// specialization is the supported use; do not include it at namespace scope.
14VectorField result;
15
16BB_VF_LOAD_LIMBS(*this, other);
18
19// ============================================================
20// Stage 5: Combine into temp_0..temp_16.
21// temp[k] = pl[k] for k in 0..4
22// temp[k] = pl[k] + (pc[k-5] - pl[k-5] - ph[k-5]) for k in 5..8
23// temp[9] = pc[4] - pl[4] - ph[4]
24// temp[k] = (pc[k-5] - pl[k-5]) - ph[k-5] + ph[k-10] for k in 10..13
25// (ph[k-5] only defined for k-5 <= 6 i.e. k <= 11; k=12,13 omit)
26// temp[k] = ph[k-10] for k in 14..16
27// Scalar math uses uint64_t subtraction (wrap); quad math uses i64x2 sub.
28// ============================================================
29uint64_t temp_0 = pl0;
30v128_t tlo_0 = pl0_lo;
31v128_t thi_0 = pl0_hi;
32uint64_t temp_1 = pl1;
33v128_t tlo_1 = pl1_lo;
34v128_t thi_1 = pl1_hi;
35uint64_t temp_2 = pl2;
36v128_t tlo_2 = pl2_lo;
37v128_t thi_2 = pl2_hi;
38uint64_t temp_3 = pl3;
39v128_t tlo_3 = pl3_lo;
40v128_t thi_3 = pl3_hi;
41uint64_t temp_4 = pl4;
42v128_t tlo_4 = pl4_lo;
43v128_t thi_4 = pl4_hi;
44
45uint64_t temp_5 = pl5 + (pc0 - pl0 - ph0);
46v128_t tlo_5 = wasm_i64x2_add(pl5_lo, wasm_i64x2_sub(wasm_i64x2_sub(pc0_lo, pl0_lo), ph0_lo));
47v128_t thi_5 = wasm_i64x2_add(pl5_hi, wasm_i64x2_sub(wasm_i64x2_sub(pc0_hi, pl0_hi), ph0_hi));
48uint64_t temp_6 = pl6 + (pc1 - pl1 - ph1);
49v128_t tlo_6 = wasm_i64x2_add(pl6_lo, wasm_i64x2_sub(wasm_i64x2_sub(pc1_lo, pl1_lo), ph1_lo));
50v128_t thi_6 = wasm_i64x2_add(pl6_hi, wasm_i64x2_sub(wasm_i64x2_sub(pc1_hi, pl1_hi), ph1_hi));
51uint64_t temp_7 = pl7 + (pc2 - pl2 - ph2);
52v128_t tlo_7 = wasm_i64x2_add(pl7_lo, wasm_i64x2_sub(wasm_i64x2_sub(pc2_lo, pl2_lo), ph2_lo));
53v128_t thi_7 = wasm_i64x2_add(pl7_hi, wasm_i64x2_sub(wasm_i64x2_sub(pc2_hi, pl2_hi), ph2_hi));
54uint64_t temp_8 = pl8 + (pc3 - pl3 - ph3);
55v128_t tlo_8 = wasm_i64x2_add(pl8_lo, wasm_i64x2_sub(wasm_i64x2_sub(pc3_lo, pl3_lo), ph3_lo));
56v128_t thi_8 = wasm_i64x2_add(pl8_hi, wasm_i64x2_sub(wasm_i64x2_sub(pc3_hi, pl3_hi), ph3_hi));
57
58uint64_t temp_9 = pc4 - pl4 - ph4;
59v128_t tlo_9 = wasm_i64x2_sub(wasm_i64x2_sub(pc4_lo, pl4_lo), ph4_lo);
60v128_t thi_9 = wasm_i64x2_sub(wasm_i64x2_sub(pc4_hi, pl4_hi), ph4_hi);
61
62uint64_t temp_10 = (pc5 - pl5 - ph5) + ph0;
63v128_t tlo_10 = wasm_i64x2_add(wasm_i64x2_sub(wasm_i64x2_sub(pc5_lo, pl5_lo), ph5_lo), ph0_lo);
64v128_t thi_10 = wasm_i64x2_add(wasm_i64x2_sub(wasm_i64x2_sub(pc5_hi, pl5_hi), ph5_hi), ph0_hi);
65uint64_t temp_11 = (pc6 - pl6 - ph6) + ph1;
66v128_t tlo_11 = wasm_i64x2_add(wasm_i64x2_sub(wasm_i64x2_sub(pc6_lo, pl6_lo), ph6_lo), ph1_lo);
67v128_t thi_11 = wasm_i64x2_add(wasm_i64x2_sub(wasm_i64x2_sub(pc6_hi, pl6_hi), ph6_hi), ph1_hi);
68uint64_t temp_12 = (pc7 - pl7) + ph2;
69v128_t tlo_12 = wasm_i64x2_add(wasm_i64x2_sub(pc7_lo, pl7_lo), ph2_lo);
70v128_t thi_12 = wasm_i64x2_add(wasm_i64x2_sub(pc7_hi, pl7_hi), ph2_hi);
71uint64_t temp_13 = (pc8 - pl8) + ph3;
72v128_t tlo_13 = wasm_i64x2_add(wasm_i64x2_sub(pc8_lo, pl8_lo), ph3_lo);
73v128_t thi_13 = wasm_i64x2_add(wasm_i64x2_sub(pc8_hi, pl8_hi), ph3_hi);
74
75uint64_t temp_14 = ph4;
76v128_t tlo_14 = ph4_lo;
77v128_t thi_14 = ph4_hi;
78uint64_t temp_15 = ph5;
79v128_t tlo_15 = ph5_lo;
80v128_t thi_15 = ph5_hi;
81uint64_t temp_16 = ph6;
82v128_t tlo_16 = ph6_lo;
83v128_t thi_16 = ph6_hi;
84
85// ============================================================
86// Stage 6: 8 x Yuval reductions.
87// Stage 7: 1 x wasm_reduce on (temp_8..temp_16).
88// Stage 8: Carry propagation temp_9..temp_16, out to temp_17.
89// Stage 9/10: Store output (no conditional subtract needed — Karatsuba+Yuval
90// result is already in [0, p]; scalar/quad AND with mask29 strips deferred
91// Stage 8 carry bits. See field_impl_generic.hpp line 863 and Stage 8/9
92// comments in BB_VF_RUN_STAGES_6_THROUGH_10 below.
93// ============================================================
95return result;
BB_VF_KARATSUBA_STAGES_1_4()
VectorField result
BB_VF_RUN_STAGES_6_THROUGH_10()