Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
alu_impl.hpp
Go to the documentation of this file.
1// AUTOGENERATED FILE
2#pragma once
3
6
7namespace bb::avm2 {
8
9template <typename FF_>
10template <typename ContainerOverSubrelations, typename AllEntities>
11void aluImpl<FF_>::accumulate(ContainerOverSubrelations& evals,
12 const AllEntities& in,
13 [[maybe_unused]] const RelationParameters<FF_>&,
14 [[maybe_unused]] const FF_& scaling_factor)
15{
16 using C = ColumnAndShifts;
17
18 const auto constants_MEM_TAG_FF = FF(0);
19 const auto constants_MEM_TAG_U1 = FF(1);
20 const auto constants_MEM_TAG_U128 = FF(6);
21 const auto constants_AVM_EXEC_OP_ID_ALU_ADD = FF(1);
22 const auto constants_AVM_EXEC_OP_ID_ALU_SUB = FF(2);
23 const auto constants_AVM_EXEC_OP_ID_ALU_MUL = FF(4);
24 const auto constants_AVM_EXEC_OP_ID_ALU_DIV = FF(8);
25 const auto constants_AVM_EXEC_OP_ID_ALU_FDIV = FF(16);
26 const auto constants_AVM_EXEC_OP_ID_ALU_EQ = FF(32);
27 const auto constants_AVM_EXEC_OP_ID_ALU_LT = FF(64);
28 const auto constants_AVM_EXEC_OP_ID_ALU_LTE = FF(128);
29 const auto constants_AVM_EXEC_OP_ID_ALU_NOT = FF(256);
30 const auto constants_AVM_EXEC_OP_ID_ALU_SHL = FF(512);
31 const auto constants_AVM_EXEC_OP_ID_ALU_SHR = FF(1024);
32 const auto constants_AVM_EXEC_OP_ID_ALU_TRUNCATE = FF(2048);
33 const auto alu_IS_NOT_FF = (FF(1) - in.get(C::alu_sel_is_ff));
34 const auto alu_IS_NOT_U128 = (FF(1) - in.get(C::alu_sel_is_u128));
35 const auto alu_SHIFT_OPS = in.get(C::alu_sel_op_shl) + in.get(C::alu_sel_op_shr);
36 const auto alu_DIV_OPS = in.get(C::alu_sel_op_div) + in.get(C::alu_sel_op_fdiv);
37 const auto alu_TAG_FF_DIFF = (in.get(C::alu_ia_tag) - constants_MEM_TAG_FF);
38 const auto alu_TAG_U128_DIFF = (in.get(C::alu_ia_tag) - constants_MEM_TAG_U128);
39 const auto alu_FF_TAG_ERR =
40 (in.get(C::alu_sel_op_div) + in.get(C::alu_sel_op_not) + alu_SHIFT_OPS) * in.get(C::alu_sel_is_ff) +
41 in.get(C::alu_sel_op_fdiv) * alu_IS_NOT_FF;
42 const auto alu_AB_TAGS_EQ = (FF(1) - in.get(C::alu_sel_ab_tag_mismatch));
43 const auto alu_EXPECTED_C_TAG =
44 (in.get(C::alu_sel_op_add) + in.get(C::alu_sel_op_sub) + in.get(C::alu_sel_op_mul) + in.get(C::alu_sel_op_div) +
45 in.get(C::alu_sel_op_truncate) + alu_SHIFT_OPS) *
46 in.get(C::alu_ia_tag) +
47 (in.get(C::alu_sel_op_eq) + in.get(C::alu_sel_op_lt) + in.get(C::alu_sel_op_lte)) * constants_MEM_TAG_U1 +
48 in.get(C::alu_sel_op_fdiv) * constants_MEM_TAG_FF;
49 const auto alu_SEL_MUL_U128 =
50 in.get(C::alu_sel_op_mul) * in.get(C::alu_sel_is_u128) * (FF(1) - in.get(C::alu_sel_err));
51 const auto alu_SEL_DIV_U128 = in.get(C::alu_sel_div_no_err) * in.get(C::alu_sel_is_u128);
52 const auto alu_TWO_POW_64 = FF(uint256_t{ 0UL, 1UL, 0UL, 0UL });
53 const auto alu_DECOMPOSED_A =
54 (in.get(C::alu_sel_op_mul) * in.get(C::alu_sel_is_u128) + in.get(C::alu_sel_shift_ops_no_overflow)) *
55 in.get(C::alu_ia) +
56 (alu_SHIFT_OPS - in.get(C::alu_sel_shift_ops_no_overflow)) * (in.get(C::alu_ib) - in.get(C::alu_max_bits)) +
57 in.get(C::alu_sel_op_div) * in.get(C::alu_sel_is_u128) * in.get(C::alu_ic);
58 const auto alu_DECOMPOSED_B = in.get(C::alu_ib);
59 const auto alu_LIMB_SIZE =
60 in.get(C::alu_sel_mul_div_u128) * alu_TWO_POW_64 +
61 alu_SHIFT_OPS * in.get(C::alu_sel_shift_ops_no_overflow) * in.get(C::alu_two_pow_shift_lo_bits);
62 const auto alu_DIV_OPS_NON_U128 =
63 (FF(1) - in.get(C::alu_sel_err)) * in.get(C::alu_sel_op_fdiv) + in.get(C::alu_sel_div_no_err) * alu_IS_NOT_U128;
64 const auto alu_DIFF = (in.get(C::alu_ia) - in.get(C::alu_ib));
65 const auto alu_SEL_LT_OPS =
66 (FF(1) - in.get(C::alu_sel_err)) * (in.get(C::alu_sel_op_lt) + in.get(C::alu_sel_op_lte));
67 const auto alu_SHIFT_OVERFLOW = alu_SHIFT_OPS * (FF(1) - in.get(C::alu_sel_shift_ops_no_overflow));
68 const auto alu_SHIFT_HI_BITS =
69 (FF(1) - in.get(C::alu_sel_err)) *
70 (in.get(C::alu_max_bits) - in.get(C::alu_sel_shift_ops_no_overflow) * in.get(C::alu_shift_lo_bits));
71
72 {
73 using View = typename std::tuple_element_t<0, ContainerOverSubrelations>::View;
74 auto tmp = static_cast<View>(in.get(C::alu_sel)) * (FF(1) - static_cast<View>(in.get(C::alu_sel)));
75 std::get<0>(evals) += (tmp * scaling_factor);
76 }
77 {
78 using View = typename std::tuple_element_t<1, ContainerOverSubrelations>::View;
79 auto tmp =
80 static_cast<View>(in.get(C::alu_sel_op_add)) * (FF(1) - static_cast<View>(in.get(C::alu_sel_op_add)));
81 std::get<1>(evals) += (tmp * scaling_factor);
82 }
83 {
84 using View = typename std::tuple_element_t<2, ContainerOverSubrelations>::View;
85 auto tmp =
86 static_cast<View>(in.get(C::alu_sel_op_sub)) * (FF(1) - static_cast<View>(in.get(C::alu_sel_op_sub)));
87 std::get<2>(evals) += (tmp * scaling_factor);
88 }
89 {
90 using View = typename std::tuple_element_t<3, ContainerOverSubrelations>::View;
91 auto tmp =
92 static_cast<View>(in.get(C::alu_sel_op_mul)) * (FF(1) - static_cast<View>(in.get(C::alu_sel_op_mul)));
93 std::get<3>(evals) += (tmp * scaling_factor);
94 }
95 {
96 using View = typename std::tuple_element_t<4, ContainerOverSubrelations>::View;
97 auto tmp =
98 static_cast<View>(in.get(C::alu_sel_op_div)) * (FF(1) - static_cast<View>(in.get(C::alu_sel_op_div)));
99 std::get<4>(evals) += (tmp * scaling_factor);
100 }
101 {
102 using View = typename std::tuple_element_t<5, ContainerOverSubrelations>::View;
103 auto tmp =
104 static_cast<View>(in.get(C::alu_sel_op_fdiv)) * (FF(1) - static_cast<View>(in.get(C::alu_sel_op_fdiv)));
105 std::get<5>(evals) += (tmp * scaling_factor);
106 }
107 {
108 using View = typename std::tuple_element_t<6, ContainerOverSubrelations>::View;
109 auto tmp = static_cast<View>(in.get(C::alu_sel_op_eq)) * (FF(1) - static_cast<View>(in.get(C::alu_sel_op_eq)));
110 std::get<6>(evals) += (tmp * scaling_factor);
111 }
112 {
113 using View = typename std::tuple_element_t<7, ContainerOverSubrelations>::View;
114 auto tmp = static_cast<View>(in.get(C::alu_sel_op_lt)) * (FF(1) - static_cast<View>(in.get(C::alu_sel_op_lt)));
115 std::get<7>(evals) += (tmp * scaling_factor);
116 }
117 {
118 using View = typename std::tuple_element_t<8, ContainerOverSubrelations>::View;
119 auto tmp =
120 static_cast<View>(in.get(C::alu_sel_op_lte)) * (FF(1) - static_cast<View>(in.get(C::alu_sel_op_lte)));
121 std::get<8>(evals) += (tmp * scaling_factor);
122 }
123 {
124 using View = typename std::tuple_element_t<9, ContainerOverSubrelations>::View;
125 auto tmp =
126 static_cast<View>(in.get(C::alu_sel_op_not)) * (FF(1) - static_cast<View>(in.get(C::alu_sel_op_not)));
127 std::get<9>(evals) += (tmp * scaling_factor);
128 }
129 {
130 using View = typename std::tuple_element_t<10, ContainerOverSubrelations>::View;
131 auto tmp =
132 static_cast<View>(in.get(C::alu_sel_op_shl)) * (FF(1) - static_cast<View>(in.get(C::alu_sel_op_shl)));
133 std::get<10>(evals) += (tmp * scaling_factor);
134 }
135 {
136 using View = typename std::tuple_element_t<11, ContainerOverSubrelations>::View;
137 auto tmp =
138 static_cast<View>(in.get(C::alu_sel_op_shr)) * (FF(1) - static_cast<View>(in.get(C::alu_sel_op_shr)));
139 std::get<11>(evals) += (tmp * scaling_factor);
140 }
141 {
142 using View = typename std::tuple_element_t<12, ContainerOverSubrelations>::View;
143 auto tmp = static_cast<View>(in.get(C::alu_sel_op_truncate)) *
144 (FF(1) - static_cast<View>(in.get(C::alu_sel_op_truncate)));
145 std::get<12>(evals) += (tmp * scaling_factor);
146 }
147 { // DISPATCH_OPERATION
148 using View = typename std::tuple_element_t<13, ContainerOverSubrelations>::View;
149 auto tmp = (static_cast<View>(in.get(C::alu_op_id)) -
150 (static_cast<View>(in.get(C::alu_sel_op_add)) * CView(constants_AVM_EXEC_OP_ID_ALU_ADD) +
151 static_cast<View>(in.get(C::alu_sel_op_sub)) * CView(constants_AVM_EXEC_OP_ID_ALU_SUB) +
152 static_cast<View>(in.get(C::alu_sel_op_mul)) * CView(constants_AVM_EXEC_OP_ID_ALU_MUL) +
153 static_cast<View>(in.get(C::alu_sel_op_div)) * CView(constants_AVM_EXEC_OP_ID_ALU_DIV) +
154 static_cast<View>(in.get(C::alu_sel_op_fdiv)) * CView(constants_AVM_EXEC_OP_ID_ALU_FDIV) +
155 static_cast<View>(in.get(C::alu_sel_op_eq)) * CView(constants_AVM_EXEC_OP_ID_ALU_EQ) +
156 static_cast<View>(in.get(C::alu_sel_op_lt)) * CView(constants_AVM_EXEC_OP_ID_ALU_LT) +
157 static_cast<View>(in.get(C::alu_sel_op_lte)) * CView(constants_AVM_EXEC_OP_ID_ALU_LTE) +
158 static_cast<View>(in.get(C::alu_sel_op_not)) * CView(constants_AVM_EXEC_OP_ID_ALU_NOT) +
159 static_cast<View>(in.get(C::alu_sel_op_shl)) * CView(constants_AVM_EXEC_OP_ID_ALU_SHL) +
160 static_cast<View>(in.get(C::alu_sel_op_shr)) * CView(constants_AVM_EXEC_OP_ID_ALU_SHR) +
161 static_cast<View>(in.get(C::alu_sel_op_truncate)) * CView(constants_AVM_EXEC_OP_ID_ALU_TRUNCATE)));
162 std::get<13>(evals) += (tmp * scaling_factor);
163 }
164 {
165 using View = typename std::tuple_element_t<14, ContainerOverSubrelations>::View;
166 auto tmp = static_cast<View>(in.get(C::alu_sel_is_ff)) * (FF(1) - static_cast<View>(in.get(C::alu_sel_is_ff)));
167 std::get<14>(evals) += (tmp * scaling_factor);
168 }
169 {
170 using View = typename std::tuple_element_t<15, ContainerOverSubrelations>::View;
171 auto tmp =
172 static_cast<View>(in.get(C::alu_sel_is_u128)) * (FF(1) - static_cast<View>(in.get(C::alu_sel_is_u128)));
173 std::get<15>(evals) += (tmp * scaling_factor);
174 }
175 { // TAG_IS_FF
176 using View = typename std::tuple_element_t<16, ContainerOverSubrelations>::View;
177 auto tmp = static_cast<View>(in.get(C::alu_sel)) *
178 ((CView(alu_TAG_FF_DIFF) * (static_cast<View>(in.get(C::alu_sel_is_ff)) *
179 (FF(1) - static_cast<View>(in.get(C::alu_tag_ff_diff_inv))) +
180 static_cast<View>(in.get(C::alu_tag_ff_diff_inv))) +
181 static_cast<View>(in.get(C::alu_sel_is_ff))) -
182 FF(1));
183 std::get<16>(evals) += (tmp * scaling_factor);
184 }
185 { // TAG_IS_U128
186 using View = typename std::tuple_element_t<17, ContainerOverSubrelations>::View;
187 auto tmp = static_cast<View>(in.get(C::alu_sel)) *
188 ((CView(alu_TAG_U128_DIFF) * (static_cast<View>(in.get(C::alu_sel_is_u128)) *
189 (FF(1) - static_cast<View>(in.get(C::alu_tag_u128_diff_inv))) +
190 static_cast<View>(in.get(C::alu_tag_u128_diff_inv))) +
191 static_cast<View>(in.get(C::alu_sel_is_u128))) -
192 FF(1));
193 std::get<17>(evals) += (tmp * scaling_factor);
194 }
195 {
196 using View = typename std::tuple_element_t<18, ContainerOverSubrelations>::View;
197 auto tmp = static_cast<View>(in.get(C::alu_sel_ab_tag_mismatch)) *
198 (FF(1) - static_cast<View>(in.get(C::alu_sel_ab_tag_mismatch)));
199 std::get<18>(evals) += (tmp * scaling_factor);
200 }
201 {
202 using View = typename std::tuple_element_t<19, ContainerOverSubrelations>::View;
203 auto tmp =
204 static_cast<View>(in.get(C::alu_sel_div_0_err)) * (FF(1) - static_cast<View>(in.get(C::alu_sel_div_0_err)));
205 std::get<19>(evals) += (tmp * scaling_factor);
206 }
207 { // ERR_CHECK
208 using View = typename std::tuple_element_t<20, ContainerOverSubrelations>::View;
209 auto tmp = (static_cast<View>(in.get(C::alu_sel_err)) -
210 ((static_cast<View>(in.get(C::alu_sel_tag_err)) + static_cast<View>(in.get(C::alu_sel_div_0_err))) -
211 static_cast<View>(in.get(C::alu_sel_tag_err)) * static_cast<View>(in.get(C::alu_sel_div_0_err))));
212 std::get<20>(evals) += (tmp * scaling_factor);
213 }
214 { // TAG_ERR_CHECK
215 using View = typename std::tuple_element_t<21, ContainerOverSubrelations>::View;
216 auto tmp = (static_cast<View>(in.get(C::alu_sel_tag_err)) -
217 ((static_cast<View>(in.get(C::alu_sel_ab_tag_mismatch)) + CView(alu_FF_TAG_ERR)) -
218 static_cast<View>(in.get(C::alu_sel_ab_tag_mismatch)) * CView(alu_FF_TAG_ERR)));
219 std::get<21>(evals) += (tmp * scaling_factor);
220 }
221 { // AB_TAGS_CHECK
222 using View = typename std::tuple_element_t<22, ContainerOverSubrelations>::View;
223 auto tmp = (FF(1) - static_cast<View>(in.get(C::alu_sel_op_truncate))) *
224 (((static_cast<View>(in.get(C::alu_ia_tag)) - static_cast<View>(in.get(C::alu_ib_tag))) *
225 (CView(alu_AB_TAGS_EQ) * (FF(1) - static_cast<View>(in.get(C::alu_ab_tags_diff_inv))) +
226 static_cast<View>(in.get(C::alu_ab_tags_diff_inv))) -
227 FF(1)) +
228 CView(alu_AB_TAGS_EQ));
229 std::get<22>(evals) += (tmp * scaling_factor);
230 }
231 { // ONLY_RELEVANT_CHECK_AB_TAGS_ERROR
232 using View = typename std::tuple_element_t<23, ContainerOverSubrelations>::View;
233 auto tmp = (static_cast<View>(in.get(C::alu_sel_op_not)) + static_cast<View>(in.get(C::alu_sel_op_truncate))) *
234 static_cast<View>(in.get(C::alu_sel_ab_tag_mismatch));
235 std::get<23>(evals) += (tmp * scaling_factor);
236 }
237 { // DIV_0_ERR
238 using View = typename std::tuple_element_t<24, ContainerOverSubrelations>::View;
239 auto tmp = CView(alu_DIV_OPS) *
240 ((static_cast<View>(in.get(C::alu_ib)) * (static_cast<View>(in.get(C::alu_sel_div_0_err)) *
241 (FF(1) - static_cast<View>(in.get(C::alu_b_inv))) +
242 static_cast<View>(in.get(C::alu_b_inv))) +
243 static_cast<View>(in.get(C::alu_sel_div_0_err))) -
244 FF(1));
245 std::get<24>(evals) += (tmp * scaling_factor);
246 }
247 { // ONLY_RELEVANT_CHECK_DIV_0_ERR_ERROR
248 using View = typename std::tuple_element_t<25, ContainerOverSubrelations>::View;
249 auto tmp = (FF(1) - CView(alu_DIV_OPS)) * static_cast<View>(in.get(C::alu_sel_div_0_err));
250 std::get<25>(evals) += (tmp * scaling_factor);
251 }
252 {
253 using View = typename std::tuple_element_t<26, ContainerOverSubrelations>::View;
254 auto tmp = static_cast<View>(in.get(C::alu_cf)) * (FF(1) - static_cast<View>(in.get(C::alu_cf)));
255 std::get<26>(evals) += (tmp * scaling_factor);
256 }
257 { // C_TAG_CHECK
258 using View = typename std::tuple_element_t<27, ContainerOverSubrelations>::View;
259 auto tmp = (FF(1) - static_cast<View>(in.get(C::alu_sel_err))) *
260 (CView(alu_EXPECTED_C_TAG) - static_cast<View>(in.get(C::alu_ic_tag)));
261 std::get<27>(evals) += (tmp * scaling_factor);
262 }
263 {
264 using View = typename std::tuple_element_t<28, ContainerOverSubrelations>::View;
265 auto tmp = (static_cast<View>(in.get(C::alu_sel_decompose_a)) -
266 (FF(1) - static_cast<View>(in.get(C::alu_sel_err))) *
267 (static_cast<View>(in.get(C::alu_sel_mul_div_u128)) + CView(alu_SHIFT_OPS)));
268 std::get<28>(evals) += (tmp * scaling_factor);
269 }
270 { // A_DECOMPOSITION
271 using View = typename std::tuple_element_t<29, ContainerOverSubrelations>::View;
272 auto tmp = static_cast<View>(in.get(C::alu_sel_decompose_a)) *
273 (CView(alu_DECOMPOSED_A) - (static_cast<View>(in.get(C::alu_a_lo)) +
274 CView(alu_LIMB_SIZE) * static_cast<View>(in.get(C::alu_a_hi))));
275 std::get<29>(evals) += (tmp * scaling_factor);
276 }
277 { // B_DECOMPOSITION
278 using View = typename std::tuple_element_t<30, ContainerOverSubrelations>::View;
279 auto tmp = static_cast<View>(in.get(C::alu_sel_mul_div_u128)) *
280 (CView(alu_DECOMPOSED_B) - (static_cast<View>(in.get(C::alu_b_lo)) +
281 CView(alu_LIMB_SIZE) * static_cast<View>(in.get(C::alu_b_hi))));
282 std::get<30>(evals) += (tmp * scaling_factor);
283 }
284 {
285 using View = typename std::tuple_element_t<31, ContainerOverSubrelations>::View;
286 auto tmp = static_cast<View>(in.get(C::alu_sel_mul_div_u128)) *
287 (FF(64) - static_cast<View>(in.get(C::alu_constant_64)));
288 std::get<31>(evals) += (tmp * scaling_factor);
289 }
290 { // A_LO_BITS
291 using View = typename std::tuple_element_t<32, ContainerOverSubrelations>::View;
292 auto tmp = ((static_cast<View>(in.get(C::alu_a_lo_bits)) - static_cast<View>(in.get(C::alu_sel_mul_div_u128)) *
293 static_cast<View>(in.get(C::alu_constant_64))) -
294 CView(alu_SHIFT_OPS) * static_cast<View>(in.get(C::alu_shift_lo_bits)));
295 std::get<32>(evals) += (tmp * scaling_factor);
296 }
297 { // A_HI_BITS
298 using View = typename std::tuple_element_t<33, ContainerOverSubrelations>::View;
299 auto tmp = ((static_cast<View>(in.get(C::alu_a_hi_bits)) - static_cast<View>(in.get(C::alu_sel_mul_div_u128)) *
300 static_cast<View>(in.get(C::alu_constant_64))) -
301 CView(alu_SHIFT_OPS) * CView(alu_SHIFT_HI_BITS));
302 std::get<33>(evals) += (tmp * scaling_factor);
303 }
304 { // ALU_ADD_SUB
305 using View = typename std::tuple_element_t<34, ContainerOverSubrelations>::View;
306 auto tmp = (static_cast<View>(in.get(C::alu_sel_op_add)) + static_cast<View>(in.get(C::alu_sel_op_sub))) *
307 (FF(1) - static_cast<View>(in.get(C::alu_sel_err))) *
308 ((static_cast<View>(in.get(C::alu_ia)) - static_cast<View>(in.get(C::alu_ic))) +
309 (static_cast<View>(in.get(C::alu_sel_op_add)) - static_cast<View>(in.get(C::alu_sel_op_sub))) *
310 (static_cast<View>(in.get(C::alu_ib)) -
311 static_cast<View>(in.get(C::alu_cf)) * (static_cast<View>(in.get(C::alu_max_value)) + FF(1))));
312 std::get<34>(evals) += (tmp * scaling_factor);
313 }
314 { // ALU_MUL_NON_U128
315 using View = typename std::tuple_element_t<35, ContainerOverSubrelations>::View;
316 auto tmp = static_cast<View>(in.get(C::alu_sel_op_mul)) * CView(alu_IS_NOT_U128) *
317 (FF(1) - static_cast<View>(in.get(C::alu_sel_err))) *
318 ((static_cast<View>(in.get(C::alu_ia)) * static_cast<View>(in.get(C::alu_ib)) -
319 static_cast<View>(in.get(C::alu_ic))) -
320 (static_cast<View>(in.get(C::alu_max_value)) + FF(1)) * static_cast<View>(in.get(C::alu_c_hi)));
321 std::get<35>(evals) += (tmp * scaling_factor);
322 }
323 { // ALU_MUL_U128
324 using View = typename std::tuple_element_t<36, ContainerOverSubrelations>::View;
325 auto tmp =
326 CView(alu_SEL_MUL_U128) * (((static_cast<View>(in.get(C::alu_ia)) * static_cast<View>(in.get(C::alu_b_lo)) +
327 static_cast<View>(in.get(C::alu_a_lo)) *
328 static_cast<View>(in.get(C::alu_b_hi)) * CView(alu_TWO_POW_64)) -
329 static_cast<View>(in.get(C::alu_ic))) -
330 (static_cast<View>(in.get(C::alu_max_value)) + FF(1)) *
331 (static_cast<View>(in.get(C::alu_cf)) * CView(alu_TWO_POW_64) +
332 static_cast<View>(in.get(C::alu_c_hi))));
333 std::get<36>(evals) += (tmp * scaling_factor);
334 }
335 {
336 using View = typename std::tuple_element_t<37, ContainerOverSubrelations>::View;
337 auto tmp = (static_cast<View>(in.get(C::alu_sel_mul_no_err_non_ff)) -
338 CView(alu_IS_NOT_FF) * (FF(1) - static_cast<View>(in.get(C::alu_sel_err))) *
339 static_cast<View>(in.get(C::alu_sel_op_mul)));
340 std::get<37>(evals) += (tmp * scaling_factor);
341 }
342 {
343 using View = typename std::tuple_element_t<38, ContainerOverSubrelations>::View;
344 auto tmp = (static_cast<View>(in.get(C::alu_sel_div_no_err)) -
345 static_cast<View>(in.get(C::alu_sel_op_div)) * (FF(1) - static_cast<View>(in.get(C::alu_sel_err))));
346 std::get<38>(evals) += (tmp * scaling_factor);
347 }
348 {
349 using View = typename std::tuple_element_t<39, ContainerOverSubrelations>::View;
350 auto tmp =
351 (static_cast<View>(in.get(C::alu_sel_mul_div_u128)) - (CView(alu_SEL_MUL_U128) + CView(alu_SEL_DIV_U128)));
352 std::get<39>(evals) += (tmp * scaling_factor);
353 }
354 { // ALU_DIV_U128_CHECK
355 using View = typename std::tuple_element_t<40, ContainerOverSubrelations>::View;
356 auto tmp =
357 CView(alu_SEL_DIV_U128) * static_cast<View>(in.get(C::alu_a_hi)) * static_cast<View>(in.get(C::alu_b_hi));
358 std::get<40>(evals) += (tmp * scaling_factor);
359 }
360 { // ALU_DIV_U128
361 using View = typename std::tuple_element_t<41, ContainerOverSubrelations>::View;
362 auto tmp =
363 CView(alu_SEL_DIV_U128) *
364 ((static_cast<View>(in.get(C::alu_ic)) * static_cast<View>(in.get(C::alu_b_lo)) +
365 static_cast<View>(in.get(C::alu_a_lo)) * static_cast<View>(in.get(C::alu_b_hi)) * CView(alu_TWO_POW_64)) -
366 (static_cast<View>(in.get(C::alu_ia)) - static_cast<View>(in.get(C::alu_helper1))));
367 std::get<41>(evals) += (tmp * scaling_factor);
368 }
369 { // ALU_FDIV_DIV_NON_U128
370 using View = typename std::tuple_element_t<42, ContainerOverSubrelations>::View;
371 auto tmp = CView(alu_DIV_OPS_NON_U128) *
372 ((static_cast<View>(in.get(C::alu_ib)) * static_cast<View>(in.get(C::alu_ic)) -
373 static_cast<View>(in.get(C::alu_ia))) +
374 static_cast<View>(in.get(C::alu_sel_op_div)) * static_cast<View>(in.get(C::alu_helper1)));
375 std::get<42>(evals) += (tmp * scaling_factor);
376 }
377 { // EQ_OP_MAIN
378 using View = typename std::tuple_element_t<43, ContainerOverSubrelations>::View;
379 auto tmp = static_cast<View>(in.get(C::alu_sel_op_eq)) * (FF(1) - static_cast<View>(in.get(C::alu_sel_err))) *
380 ((CView(alu_DIFF) * (static_cast<View>(in.get(C::alu_ic)) *
381 (FF(1) - static_cast<View>(in.get(C::alu_ab_diff_inv))) +
382 static_cast<View>(in.get(C::alu_ab_diff_inv))) -
383 FF(1)) +
384 static_cast<View>(in.get(C::alu_ic)));
385 std::get<43>(evals) += (tmp * scaling_factor);
386 }
387 {
388 using View = typename std::tuple_element_t<44, ContainerOverSubrelations>::View;
389 auto tmp = (static_cast<View>(in.get(C::alu_sel_ff_gt)) -
390 static_cast<View>(in.get(C::alu_sel_is_ff)) * CView(alu_SEL_LT_OPS));
391 std::get<44>(evals) += (tmp * scaling_factor);
392 }
393 {
394 using View = typename std::tuple_element_t<45, ContainerOverSubrelations>::View;
395 auto tmp = (static_cast<View>(in.get(C::alu_sel_int_gt)) -
396 (CView(alu_IS_NOT_FF) * CView(alu_SEL_LT_OPS) + static_cast<View>(in.get(C::alu_sel_div_no_err))));
397 std::get<45>(evals) += (tmp * scaling_factor);
398 }
399 { // GT_INPUT_A
400 using View = typename std::tuple_element_t<46, ContainerOverSubrelations>::View;
401 auto tmp = (static_cast<View>(in.get(C::alu_gt_input_a)) -
402 ((static_cast<View>(in.get(C::alu_sel_op_lt)) + static_cast<View>(in.get(C::alu_sel_div_no_err))) *
403 static_cast<View>(in.get(C::alu_ib)) +
404 static_cast<View>(in.get(C::alu_sel_op_lte)) * static_cast<View>(in.get(C::alu_ia))));
405 std::get<46>(evals) += (tmp * scaling_factor);
406 }
407 { // GT_INPUT_B
408 using View = typename std::tuple_element_t<47, ContainerOverSubrelations>::View;
409 auto tmp = (static_cast<View>(in.get(C::alu_gt_input_b)) -
410 (static_cast<View>(in.get(C::alu_sel_op_lt)) * static_cast<View>(in.get(C::alu_ia)) +
411 static_cast<View>(in.get(C::alu_sel_op_lte)) * static_cast<View>(in.get(C::alu_ib)) +
412 static_cast<View>(in.get(C::alu_sel_div_no_err)) * static_cast<View>(in.get(C::alu_helper1))));
413 std::get<47>(evals) += (tmp * scaling_factor);
414 }
415 { // GT_ASSIGN_RESULT_C
416 using View = typename std::tuple_element_t<48, ContainerOverSubrelations>::View;
417 auto tmp = (FF(1) - static_cast<View>(in.get(C::alu_sel_err))) *
418 ((static_cast<View>(in.get(C::alu_sel_div_no_err)) +
419 static_cast<View>(in.get(C::alu_sel_op_lt)) * static_cast<View>(in.get(C::alu_ic)) +
420 static_cast<View>(in.get(C::alu_sel_op_lte)) * (FF(1) - static_cast<View>(in.get(C::alu_ic)))) -
421 static_cast<View>(in.get(C::alu_gt_result_c)));
422 std::get<48>(evals) += (tmp * scaling_factor);
423 }
424 { // NOT_OP_MAIN
425 using View = typename std::tuple_element_t<49, ContainerOverSubrelations>::View;
426 auto tmp = static_cast<View>(in.get(C::alu_sel_op_not)) * (FF(1) - static_cast<View>(in.get(C::alu_sel_err))) *
427 ((static_cast<View>(in.get(C::alu_ia)) + static_cast<View>(in.get(C::alu_ib))) -
428 static_cast<View>(in.get(C::alu_max_value)));
429 std::get<49>(evals) += (tmp * scaling_factor);
430 }
431 { // SHL_TWO_POW_SHIFT
432 using View = typename std::tuple_element_t<50, ContainerOverSubrelations>::View;
433 auto tmp =
434 static_cast<View>(in.get(C::alu_sel_op_shl)) * static_cast<View>(in.get(C::alu_sel_shift_ops_no_overflow)) *
435 (FF(1) - static_cast<View>(in.get(C::alu_sel_err))) *
436 ((static_cast<View>(in.get(C::alu_max_value)) + FF(1)) -
437 static_cast<View>(in.get(C::alu_two_pow_shift_lo_bits)) * static_cast<View>(in.get(C::alu_helper1)));
438 std::get<50>(evals) += (tmp * scaling_factor);
439 }
440 { // ALU_SHL
441 using View = typename std::tuple_element_t<51, ContainerOverSubrelations>::View;
442 auto tmp = static_cast<View>(in.get(C::alu_sel_op_shl)) * (FF(1) - static_cast<View>(in.get(C::alu_sel_err))) *
443 (static_cast<View>(in.get(C::alu_ic)) - static_cast<View>(in.get(C::alu_sel_shift_ops_no_overflow)) *
444 static_cast<View>(in.get(C::alu_a_lo)) *
445 static_cast<View>(in.get(C::alu_helper1)));
446 std::get<51>(evals) += (tmp * scaling_factor);
447 }
448 { // ALU_SHR
449 using View = typename std::tuple_element_t<52, ContainerOverSubrelations>::View;
450 auto tmp = static_cast<View>(in.get(C::alu_sel_op_shr)) * (FF(1) - static_cast<View>(in.get(C::alu_sel_err))) *
451 (static_cast<View>(in.get(C::alu_ic)) - static_cast<View>(in.get(C::alu_sel_shift_ops_no_overflow)) *
452 static_cast<View>(in.get(C::alu_a_hi)));
453 std::get<52>(evals) += (tmp * scaling_factor);
454 }
455 {
456 using View = typename std::tuple_element_t<53, ContainerOverSubrelations>::View;
457 auto tmp = static_cast<View>(in.get(C::alu_sel_shift_ops_no_overflow)) *
458 (FF(1) - static_cast<View>(in.get(C::alu_sel_shift_ops_no_overflow)));
459 std::get<53>(evals) += (tmp * scaling_factor);
460 }
461 {
462 using View = typename std::tuple_element_t<54, ContainerOverSubrelations>::View;
463 auto tmp = static_cast<View>(in.get(C::alu_sel_shift_ops_no_overflow)) * (FF(1) - CView(alu_SHIFT_OPS));
464 std::get<54>(evals) += (tmp * scaling_factor);
465 }
466 { // SHIFTS_LO_BITS
467 using View = typename std::tuple_element_t<55, ContainerOverSubrelations>::View;
468 auto tmp = (static_cast<View>(in.get(C::alu_shift_lo_bits)) -
469 (FF(1) - static_cast<View>(in.get(C::alu_sel_err))) *
470 (static_cast<View>(in.get(C::alu_sel_shift_ops_no_overflow)) *
471 (static_cast<View>(in.get(C::alu_sel_op_shl)) *
472 (static_cast<View>(in.get(C::alu_max_bits)) - static_cast<View>(in.get(C::alu_ib))) +
473 static_cast<View>(in.get(C::alu_sel_op_shr)) * static_cast<View>(in.get(C::alu_ib))) +
474 CView(alu_SHIFT_OVERFLOW) * static_cast<View>(in.get(C::alu_max_bits))));
475 std::get<55>(evals) += (tmp * scaling_factor);
476 }
477 {
478 using View = typename std::tuple_element_t<56, ContainerOverSubrelations>::View;
479 auto tmp = static_cast<View>(in.get(C::alu_sel_trunc_trivial)) *
480 (FF(1) - static_cast<View>(in.get(C::alu_sel_trunc_trivial)));
481 std::get<56>(evals) += (tmp * scaling_factor);
482 }
483 {
484 using View = typename std::tuple_element_t<57, ContainerOverSubrelations>::View;
485 auto tmp = static_cast<View>(in.get(C::alu_sel_trunc_gte_128)) *
486 (FF(1) - static_cast<View>(in.get(C::alu_sel_trunc_gte_128)));
487 std::get<57>(evals) += (tmp * scaling_factor);
488 }
489 {
490 using View = typename std::tuple_element_t<58, ContainerOverSubrelations>::View;
491 auto tmp = static_cast<View>(in.get(C::alu_sel_trunc_lt_128)) *
492 (FF(1) - static_cast<View>(in.get(C::alu_sel_trunc_lt_128)));
493 std::get<58>(evals) += (tmp * scaling_factor);
494 }
495 { // SEL_TRUNC_NON_TRIVIAL
496 using View = typename std::tuple_element_t<59, ContainerOverSubrelations>::View;
497 auto tmp = (static_cast<View>(in.get(C::alu_sel_trunc_non_trivial)) -
498 (static_cast<View>(in.get(C::alu_sel_trunc_gte_128)) +
499 static_cast<View>(in.get(C::alu_sel_trunc_lt_128))));
500 std::get<59>(evals) += (tmp * scaling_factor);
501 }
502 { // SEL_TRUNCATE
503 using View = typename std::tuple_element_t<60, ContainerOverSubrelations>::View;
504 auto tmp = (static_cast<View>(in.get(C::alu_sel_op_truncate)) -
505 (static_cast<View>(in.get(C::alu_sel_trunc_non_trivial)) +
506 static_cast<View>(in.get(C::alu_sel_trunc_trivial))));
507 std::get<60>(evals) += (tmp * scaling_factor);
508 }
509 { // TRUNC_TRIVIAL_CASE
510 using View = typename std::tuple_element_t<61, ContainerOverSubrelations>::View;
511 auto tmp = static_cast<View>(in.get(C::alu_sel_trunc_trivial)) *
512 (static_cast<View>(in.get(C::alu_ia)) - static_cast<View>(in.get(C::alu_ic)));
513 std::get<61>(evals) += (tmp * scaling_factor);
514 }
515 { // SMALL_TRUNC_VAL_IS_LO
516 using View = typename std::tuple_element_t<62, ContainerOverSubrelations>::View;
517 auto tmp = static_cast<View>(in.get(C::alu_sel_trunc_lt_128)) *
518 (static_cast<View>(in.get(C::alu_a_lo)) - static_cast<View>(in.get(C::alu_ia)));
519 std::get<62>(evals) += (tmp * scaling_factor);
520 }
521 { // TRUNC_LO_128_DECOMPOSITION
522 using View = typename std::tuple_element_t<63, ContainerOverSubrelations>::View;
523 auto tmp = static_cast<View>(in.get(C::alu_sel_trunc_non_trivial)) *
524 ((static_cast<View>(in.get(C::alu_ic)) +
525 static_cast<View>(in.get(C::alu_mid)) * (static_cast<View>(in.get(C::alu_max_value)) + FF(1))) -
526 static_cast<View>(in.get(C::alu_a_lo)));
527 std::get<63>(evals) += (tmp * scaling_factor);
528 }
529 { // TRUNC_MID_BITS
530 using View = typename std::tuple_element_t<64, ContainerOverSubrelations>::View;
531 auto tmp =
532 (static_cast<View>(in.get(C::alu_mid_bits)) - static_cast<View>(in.get(C::alu_sel_trunc_non_trivial)) *
533 (FF(128) - static_cast<View>(in.get(C::alu_max_bits))));
534 std::get<64>(evals) += (tmp * scaling_factor);
535 }
536}
537
538} // namespace bb::avm2
static void accumulate(ContainerOverSubrelations &evals, const AllEntities &in, const RelationParameters< FF > &, const FF &scaling_factor)
Definition alu_impl.hpp:11
ColumnAndShifts
Definition columns.hpp:34
AvmFlavorSettings::FF FF
Definition field.hpp:10
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
#define CView(v)
Container for parameters used by the grand product (permutation, lookup) Honk relations.