Skip to content

Commit 483bead

Browse files
authored
Merge pull request #493 from AztecProtocol/mw/avm-max-operands
feat(avm)!: Reduce maximum number of AVM operands
2 parents 2d67039 + 30237d7 commit 483bead

43 files changed

Lines changed: 713 additions & 1301 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

barretenberg/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ ts/src/cbind/generated/
1818
**/generated/
1919
# ...but these are committed source dirs, not codegen output:
2020
!cpp/src/barretenberg/flavor/generated/
21+
!cpp/src/barretenberg/vm2/generated/
2122
!cpp/src/barretenberg/honk/execution_trace/generated/

barretenberg/cpp/pil/vm2/bytecode/instr_fetching.pil

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ include "../precomputed.pil";
1010
* For our purposes an instruction can be thought of as:
1111
* - Opcode (exec_opcode, u8): The operation to perform encoded numerically as defined in our
1212
* instruction specification e.g. the SUB operation is mapped to 1.
13-
* - Operands ([op1, ..., op7], MemoryValue[]): The inputs and/or outputs of the operation. The
13+
* - Operands ([op1, ..., op5], MemoryValue[]): The inputs and/or outputs of the operation. The
1414
* number of operands and their types differs per opcode e.g. FDIV has three; two FF inputs
1515
* and one FF output.
1616
* - Addressing Mode (addressing_mode, u16): The indirect and relative contributions of the operands
@@ -21,7 +21,7 @@ include "../precomputed.pil";
2121
* The main work of this trace is to derive the decoded operands of an instruction from raw bytecode
2222
* bytes and our opcode specification:
2323
* - addressing_mode: #[ADDRESSING_MODE_BYTES_DECOMPOSITION]
24-
* - [op1, op2, op3, op4, op5, op6, op7]: #[OPXXX_BYTES_DECOMPOSITION]
24+
* - [op1, op2, op3, op4, op5]: #[OPXXX_BYTES_DECOMPOSITION]
2525
*
2626
* It copies the relevant bytecode portion from bc_decomposition.pil (#[BYTES_FROM_BC_DEC]):
2727
* bd0 = bytecode[pc], bd1 = bytecode[pc+1], ..., bd36 = bytecode[pc+36],
@@ -63,7 +63,7 @@ include "../precomputed.pil";
6363
* instr_fetching.pc, instr_fetching.bytecode_id, instr_fetching.exec_opcode,
6464
* instr_fetching.instr_size, instr_fetching.addressing_mode,
6565
* instr_fetching.op1, instr_fetching.op2, instr_fetching.op3, instr_fetching.op4,
66-
* instr_fetching.op5, instr_fetching.op6, instr_fetching.op7
66+
* instr_fetching.op5
6767
* };
6868
*
6969
* ERROR HANDLING:
@@ -312,7 +312,6 @@ pol commit sel_op_dc_12; // @boolean (by lookup only when sel_pc_in_range == 1)
312312
pol commit sel_op_dc_13; // @boolean (by lookup only when sel_pc_in_range == 1)
313313
pol commit sel_op_dc_14; // @boolean (by lookup only when sel_pc_in_range == 1)
314314
pol commit sel_op_dc_15; // @boolean (by lookup only when sel_pc_in_range == 1)
315-
pol commit sel_op_dc_16; // @boolean (by lookup only when sel_pc_in_range == 1)
316315

317316
#[WIRE_INSTRUCTION_INFO]
318317
sel_pc_in_range {
@@ -325,8 +324,7 @@ sel_pc_in_range {
325324
sel_op_dc_0, sel_op_dc_1, sel_op_dc_2, sel_op_dc_3,
326325
sel_op_dc_4, sel_op_dc_5, sel_op_dc_6, sel_op_dc_7,
327326
sel_op_dc_8, sel_op_dc_9, sel_op_dc_10, sel_op_dc_11,
328-
sel_op_dc_12, sel_op_dc_13, sel_op_dc_14, sel_op_dc_15,
329-
sel_op_dc_16
327+
sel_op_dc_12, sel_op_dc_13, sel_op_dc_14, sel_op_dc_15
330328
} in
331329
precomputed.sel_range_8 {
332330
precomputed.idx,
@@ -338,8 +336,7 @@ precomputed.sel_range_8 {
338336
precomputed.sel_op_dc_0, precomputed.sel_op_dc_1, precomputed.sel_op_dc_2, precomputed.sel_op_dc_3,
339337
precomputed.sel_op_dc_4, precomputed.sel_op_dc_5, precomputed.sel_op_dc_6, precomputed.sel_op_dc_7,
340338
precomputed.sel_op_dc_8, precomputed.sel_op_dc_9, precomputed.sel_op_dc_10, precomputed.sel_op_dc_11,
341-
precomputed.sel_op_dc_12, precomputed.sel_op_dc_13, precomputed.sel_op_dc_14, precomputed.sel_op_dc_15,
342-
precomputed.sel_op_dc_16
339+
precomputed.sel_op_dc_12, precomputed.sel_op_dc_13, precomputed.sel_op_dc_14, precomputed.sel_op_dc_15
343340
};
344341

345342

@@ -350,29 +347,25 @@ precomputed.sel_range_8 {
350347
pol commit addressing_mode;
351348

352349
// Operands.
353-
pol commit op1, op2, op3, op4, op5, op6, op7;
350+
pol commit op1, op2, op3, op4, op5;
354351

355352
// We derive the operands only when no parsing error (except possibly tag out-of-range) occurs. One might remove
356353
// this gating but at a cost of some ugliness in the code (witgen would need a partially parsed instruction when
357354
// the error instr_out_of_range is toggled).
358355
// The following relations decomposing operands (addressing_mode, op1, ...) into bytes were code-generated by
359356
// a cpp test in op_decomposition.test.cpp.
360357
// Remark: Upper-casing the alias needs to be edited manually (not code-generated)!
361-
pol SEL_OP_DC_17 = sel_op_dc_2 + sel_op_dc_6;
358+
pol SEL_OP_DC_16 = sel_op_dc_1 + sel_op_dc_5;
362359

363360
#[ADDRESSING_MODE_BYTES_DECOMPOSITION]
364-
addressing_mode = (1 - PARSING_ERROR_EXCEPT_TAG_ERROR) * (sel_op_dc_0 * (bd1 * 2**8 + bd2 * 2**0) + SEL_OP_DC_17 * (bd1 * 2**0));
361+
addressing_mode = (1 - PARSING_ERROR_EXCEPT_TAG_ERROR) * (sel_op_dc_0 * (bd1 * 2**8 + bd2 * 2**0) + SEL_OP_DC_16 * (bd1 * 2**0));
365362
#[OP1_BYTES_DECOMPOSITION]
366-
op1 = (1 - PARSING_ERROR_EXCEPT_TAG_ERROR) * (sel_op_dc_0 * (bd3 * 2**8 + bd4 * 2**0) + sel_op_dc_2 * (bd2 * 2**8 + bd3 * 2**0) + sel_op_dc_6 * (bd2 * 2**0) + sel_op_dc_15 * (bd1 * 2**24 + bd2 * 2**16 + bd3 * 2**8 + bd4 * 2**0));
363+
op1 = (1 - PARSING_ERROR_EXCEPT_TAG_ERROR) * (sel_op_dc_0 * (bd3 * 2**8 + bd4 * 2**0) + sel_op_dc_1 * (bd2 * 2**8 + bd3 * 2**0) + sel_op_dc_5 * (bd2 * 2**0) + sel_op_dc_14 * (bd1 * 2**24 + bd2 * 2**16 + bd3 * 2**8 + bd4 * 2**0));
367364
#[OP2_BYTES_DECOMPOSITION]
368-
op2 = (1 - PARSING_ERROR_EXCEPT_TAG_ERROR) * (sel_op_dc_0 * (bd5 * 2**8 + bd6 * 2**0) + sel_op_dc_3 * (bd4 * 2**8 + bd5 * 2**0) + sel_op_dc_6 * (bd3 * 2**0) + sel_op_dc_8 * (bd4 * 2**0) + sel_op_dc_16 * (bd4 * 2**24 + bd5 * 2**16 + bd6 * 2**8 + bd7 * 2**0));
365+
op2 = (1 - PARSING_ERROR_EXCEPT_TAG_ERROR) * (sel_op_dc_0 * (bd5 * 2**8 + bd6 * 2**0) + sel_op_dc_2 * (bd4 * 2**8 + bd5 * 2**0) + sel_op_dc_5 * (bd3 * 2**0) + sel_op_dc_7 * (bd4 * 2**0) + sel_op_dc_15 * (bd4 * 2**24 + bd5 * 2**16 + bd6 * 2**8 + bd7 * 2**0));
369366
#[OP3_BYTES_DECOMPOSITION]
370-
op3 = (1 - PARSING_ERROR_EXCEPT_TAG_ERROR) * (sel_op_dc_0 * (bd7 * 2**8 + bd8 * 2**0) + sel_op_dc_4 * (bd6 * 2**8 + bd7 * 2**0) + sel_op_dc_7 * (bd6 * 2**0) + sel_op_dc_9 * (bd5 * 2**248 + bd6 * 2**240 + bd7 * 2**232 + bd8 * 2**224 + bd9 * 2**216 + bd10 * 2**208 + bd11 * 2**200 + bd12 * 2**192 + bd13 * 2**184 + bd14 * 2**176 + bd15 * 2**168 + bd16 * 2**160 + bd17 * 2**152 + bd18 * 2**144 + bd19 * 2**136 + bd20 * 2**128 + bd21 * 2**120 + bd22 * 2**112 + bd23 * 2**104 + bd24 * 2**96 + bd25 * 2**88 + bd26 * 2**80 + bd27 * 2**72 + bd28 * 2**64 + bd29 * 2**56 + bd30 * 2**48 + bd31 * 2**40 + bd32 * 2**32 + bd33 * 2**24 + bd34 * 2**16 + bd35 * 2**8 + bd36 * 2**0) + sel_op_dc_10 * (bd5 * 2**120 + bd6 * 2**112 + bd7 * 2**104 + bd8 * 2**96 + bd9 * 2**88 + bd10 * 2**80 + bd11 * 2**72 + bd12 * 2**64 + bd13 * 2**56 + bd14 * 2**48 + bd15 * 2**40 + bd16 * 2**32 + bd17 * 2**24 + bd18 * 2**16 + bd19 * 2**8 + bd20 * 2**0) + sel_op_dc_11 * (bd5 * 2**56 + bd6 * 2**48 + bd7 * 2**40 + bd8 * 2**32 + bd9 * 2**24 + bd10 * 2**16 + bd11 * 2**8 + bd12 * 2**0) + sel_op_dc_12 * (bd5 * 2**24 + bd6 * 2**16 + bd7 * 2**8 + bd8 * 2**0) + sel_op_dc_13 * (bd5 * 2**8 + bd6 * 2**0) + sel_op_dc_14 * (bd4 * 2**0));
367+
op3 = (1 - PARSING_ERROR_EXCEPT_TAG_ERROR) * (sel_op_dc_0 * (bd7 * 2**8 + bd8 * 2**0) + sel_op_dc_3 * (bd6 * 2**8 + bd7 * 2**0) + sel_op_dc_6 * (bd6 * 2**0) + sel_op_dc_8 * (bd5 * 2**248 + bd6 * 2**240 + bd7 * 2**232 + bd8 * 2**224 + bd9 * 2**216 + bd10 * 2**208 + bd11 * 2**200 + bd12 * 2**192 + bd13 * 2**184 + bd14 * 2**176 + bd15 * 2**168 + bd16 * 2**160 + bd17 * 2**152 + bd18 * 2**144 + bd19 * 2**136 + bd20 * 2**128 + bd21 * 2**120 + bd22 * 2**112 + bd23 * 2**104 + bd24 * 2**96 + bd25 * 2**88 + bd26 * 2**80 + bd27 * 2**72 + bd28 * 2**64 + bd29 * 2**56 + bd30 * 2**48 + bd31 * 2**40 + bd32 * 2**32 + bd33 * 2**24 + bd34 * 2**16 + bd35 * 2**8 + bd36 * 2**0) + sel_op_dc_9 * (bd5 * 2**120 + bd6 * 2**112 + bd7 * 2**104 + bd8 * 2**96 + bd9 * 2**88 + bd10 * 2**80 + bd11 * 2**72 + bd12 * 2**64 + bd13 * 2**56 + bd14 * 2**48 + bd15 * 2**40 + bd16 * 2**32 + bd17 * 2**24 + bd18 * 2**16 + bd19 * 2**8 + bd20 * 2**0) + sel_op_dc_10 * (bd5 * 2**56 + bd6 * 2**48 + bd7 * 2**40 + bd8 * 2**32 + bd9 * 2**24 + bd10 * 2**16 + bd11 * 2**8 + bd12 * 2**0) + sel_op_dc_11 * (bd5 * 2**24 + bd6 * 2**16 + bd7 * 2**8 + bd8 * 2**0) + sel_op_dc_12 * (bd5 * 2**8 + bd6 * 2**0) + sel_op_dc_13 * (bd4 * 2**0));
371368
#[OP4_BYTES_DECOMPOSITION]
372-
op4 = (1 - PARSING_ERROR_EXCEPT_TAG_ERROR) * (sel_op_dc_0 * (bd9 * 2**8 + bd10 * 2**0) + sel_op_dc_5 * (bd8 * 2**8 + bd9 * 2**0));
369+
op4 = (1 - PARSING_ERROR_EXCEPT_TAG_ERROR) * (sel_op_dc_0 * (bd9 * 2**8 + bd10 * 2**0) + sel_op_dc_4 * (bd8 * 2**8 + bd9 * 2**0));
373370
#[OP5_BYTES_DECOMPOSITION]
374-
op5 = (1 - PARSING_ERROR_EXCEPT_TAG_ERROR) * (sel_op_dc_0 * (bd11 * 2**8 + bd12 * 2**0) + sel_op_dc_5 * (bd10 * 2**8 + bd11 * 2**0));
375-
#[OP6_BYTES_DECOMPOSITION]
376-
op6 = (1 - PARSING_ERROR_EXCEPT_TAG_ERROR) * (sel_op_dc_1 * (bd13 * 2**8 + bd14 * 2**0));
377-
#[OP7_BYTES_DECOMPOSITION]
378-
op7 = (1 - PARSING_ERROR_EXCEPT_TAG_ERROR) * (sel_op_dc_1 * (bd15 * 2**8 + bd16 * 2**0));
371+
op5 = (1 - PARSING_ERROR_EXCEPT_TAG_ERROR) * (sel_op_dc_0 * (bd11 * 2**8 + bd12 * 2**0) + sel_op_dc_4 * (bd10 * 2**8 + bd11 * 2**0));

barretenberg/cpp/pil/vm2/execution.pil

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ pol commit sel_instruction_fetching_failure; // @boolean (by definition below)
378378

379379
pol commit exec_opcode;
380380
pol commit addressing_mode;
381-
pol commit op[7]; // operands
381+
pol commit op[5]; // operands
382382

383383
// We now proceed to fetch the instruction.
384384

@@ -419,9 +419,7 @@ sel_instruction_fetching_success {
419419
op[1],
420420
op[2],
421421
op[3],
422-
op[4],
423-
op[5],
424-
op[6]
422+
op[4]
425423
} in instr_fetching.sel {
426424
instr_fetching.pc,
427425
instr_fetching.bytecode_id,
@@ -432,9 +430,7 @@ sel_instruction_fetching_success {
432430
instr_fetching.op2,
433431
instr_fetching.op3,
434432
instr_fetching.op4,
435-
instr_fetching.op5,
436-
instr_fetching.op6,
437-
instr_fetching.op7
433+
instr_fetching.op5
438434
};
439435

440436
/**************************************************************************************************
@@ -457,8 +453,6 @@ sel_instruction_fetching_success {
457453
sel_op_is_address[2],
458454
sel_op_is_address[3],
459455
sel_op_is_address[4],
460-
sel_op_is_address[5],
461-
sel_op_is_address[6],
462456
// decomposed selectors
463457
subtrace_id,
464458
subtrace_operation_id,
@@ -468,7 +462,7 @@ sel_instruction_fetching_success {
468462
sel_mem_op_reg[1],
469463
sel_mem_op_reg[2],
470464
sel_mem_op_reg[3],
471-
sel_mem_op_reg[4],
465+
sel_mem_op_reg[4], // TODO(MW): Remove when reducing max registers
472466
sel_mem_op_reg[5],
473467
// read / write per register
474468
rw_reg[0],
@@ -506,8 +500,6 @@ precomputed.sel_exec_spec {
506500
precomputed.sel_op_is_address[2],
507501
precomputed.sel_op_is_address[3],
508502
precomputed.sel_op_is_address[4],
509-
precomputed.sel_op_is_address[5],
510-
precomputed.sel_op_is_address[6],
511503
// decomposed selectors
512504
precomputed.subtrace_id,
513505
precomputed.subtrace_operation_id,
@@ -549,7 +541,7 @@ precomputed.sel_exec_spec {
549541
pol SEL_RESOLVE_ADDRESS = sel_instruction_fetching_success;
550542

551543
// resolved operands
552-
pol commit rop[7];
544+
pol commit rop[5];
553545

554546
// NOTE: Constraints on the resolved operands are in addressing.pil.
555547
// The "output we want" is sel_addressing_error from addressing.pil.
@@ -565,6 +557,10 @@ sel_read_registers = SEL_RESOLVE_ADDRESS - sel_addressing_error;
565557

566558
// Registers
567559
pol commit register[6];
560+
561+
// TODO(MW): Remove when reducing max registers (below prevents IsolatedCommittedColumn)
562+
sel_read_registers * register[5] = 0;
563+
568564
// Memory Accesses
569565
pol commit sel_mem_op_reg[6]; // @boolean (when `sel_instruction_fetching_success == 1`)
570566
// Read / Write selectors

0 commit comments

Comments
 (0)