sp1_recursion_core/air/
opcode.rs

1use std::borrow::BorrowMut;
2
3use sp1_derive::AlignedBorrow;
4
5pub(crate) const OPCODE_COUNT: usize = core::mem::size_of::<OpcodeSelectorCols<u8>>();
6
7/// Selectors for the opcode.
8///
9/// This contains selectors for the different opcodes corresponding to variants of the [`Opcode`]
10/// enum.
11#[derive(AlignedBorrow, Clone, Copy, Default, Debug)]
12#[repr(C)]
13pub struct OpcodeSelectorCols<T> {
14    // Arithmetic field instructions.
15    pub is_add: T,
16    pub is_sub: T,
17    pub is_mul: T,
18    pub is_div: T,
19    pub is_ext: T,
20
21    // Memory instructions.
22    pub is_load: T,
23    pub is_store: T,
24
25    // Branch instructions.
26    pub is_beq: T,
27    pub is_bne: T,
28    pub is_bneinc: T,
29
30    // Jump instructions.
31    pub is_jal: T,
32    pub is_jalr: T,
33
34    // System instructions.
35    pub is_trap: T,
36    pub is_noop: T,
37    pub is_halt: T,
38
39    pub is_poseidon: T,
40    pub is_fri_fold: T,
41    pub is_commit: T,
42    pub is_ext_to_felt: T,
43    pub is_exp_reverse_bits_len: T,
44    pub is_heap_expand: T,
45}
46
47impl<T: Copy> IntoIterator for &OpcodeSelectorCols<T> {
48    type Item = T;
49
50    type IntoIter = std::array::IntoIter<T, OPCODE_COUNT>;
51
52    fn into_iter(self) -> Self::IntoIter {
53        let mut array = [self.is_add; OPCODE_COUNT];
54        let mut_ref: &mut OpcodeSelectorCols<T> = array.as_mut_slice().borrow_mut();
55
56        *mut_ref = *self;
57        array.into_iter()
58    }
59}