use std::borrow::{Borrow, BorrowMut}; use std::mem::{size_of, transmute}; use std::ops::{Deref, DerefMut}; use crate::util::{indices_arr, transmute_no_compile_time_size_checks}; #[repr(C)] #[derive(Clone, Copy, Eq, PartialEq, Debug)] pub struct OpsColumnsView { // TODO: combine ADD, MUL, SUB, DIV, MOD, ADDFP254, MULFP254, SUBFP254, LT, and GT into one flag pub add: T, pub mul: T, pub sub: T, pub div: T, pub mod_: T, // TODO: combine ADDMOD, MULMOD and SUBMOD into one flag pub addmod: T, pub mulmod: T, pub addfp254: T, pub mulfp254: T, pub subfp254: T, pub submod: T, pub lt: T, pub gt: T, pub eq: T, // Note: This column must be 0 when is_cpu_cycle = 0. pub iszero: T, // Note: This column must be 0 when is_cpu_cycle = 0. pub logic_op: T, // Combines AND, OR and XOR flags. pub not: T, pub byte: T, // TODO: combine SHL and SHR into one flag pub shl: T, pub shr: T, pub keccak_general: T, pub prover_input: T, pub pop: T, // TODO: combine JUMP and JUMPI into one flag pub jump: T, // Note: This column must be 0 when is_cpu_cycle = 0. pub jumpi: T, // Note: This column must be 0 when is_cpu_cycle = 0. pub pc: T, pub jumpdest: T, pub push0: T, pub push: T, pub dup: T, pub swap: T, // TODO: combine GET_CONTEXT and SET_CONTEXT into one flag pub get_context: T, pub set_context: T, pub exit_kernel: T, // Note: This column must be 0 when is_cpu_cycle = 0. // TODO: combine MLOAD_GENERAL and MSTORE_GENERAL into one flag pub mload_general: T, pub mstore_general: T, pub syscall: T, // Note: This column must be 0 when is_cpu_cycle = 0. pub exception: T, // Note: This column must be 0 when is_cpu_cycle = 0. } // `u8` is guaranteed to have a `size_of` of 1. pub const NUM_OPS_COLUMNS: usize = size_of::>(); impl From<[T; NUM_OPS_COLUMNS]> for OpsColumnsView { fn from(value: [T; NUM_OPS_COLUMNS]) -> Self { unsafe { transmute_no_compile_time_size_checks(value) } } } impl From> for [T; NUM_OPS_COLUMNS] { fn from(value: OpsColumnsView) -> Self { unsafe { transmute_no_compile_time_size_checks(value) } } } impl Borrow> for [T; NUM_OPS_COLUMNS] { fn borrow(&self) -> &OpsColumnsView { unsafe { transmute(self) } } } impl BorrowMut> for [T; NUM_OPS_COLUMNS] { fn borrow_mut(&mut self) -> &mut OpsColumnsView { unsafe { transmute(self) } } } impl Deref for OpsColumnsView { type Target = [T; NUM_OPS_COLUMNS]; fn deref(&self) -> &Self::Target { unsafe { transmute(self) } } } impl DerefMut for OpsColumnsView { fn deref_mut(&mut self) -> &mut Self::Target { unsafe { transmute(self) } } } const fn make_col_map() -> OpsColumnsView { let indices_arr = indices_arr::(); unsafe { transmute::<[usize; NUM_OPS_COLUMNS], OpsColumnsView>(indices_arr) } } pub const COL_MAP: OpsColumnsView = make_col_map();