use std::borrow::{Borrow, BorrowMut}; use std::mem::{size_of, transmute}; use std::ops::{Deref, DerefMut}; use crate::util::transmute_no_compile_time_size_checks; #[repr(C)] #[derive(Clone, Copy, Eq, PartialEq, Debug)] pub struct OpsColumnsView { pub binary_op: T, // Combines ADD, MUL, SUB, DIV, MOD, LT, GT and BYTE flags. pub ternary_op: T, // Combines ADDMOD, MULMOD and SUBMOD flags. pub fp254_op: T, // Combines ADD_FP254, MUL_FP254 and SUB_FP254 flags. pub eq_iszero: T, // Combines EQ and ISZERO flags. pub logic_op: T, // Combines AND, OR and XOR flags. pub not: T, pub shift: T, // Combines SHL and SHR flags. pub keccak_general: T, pub prover_input: T, pub pop: T, pub jumps: T, // Combines JUMP and JUMPI flags. pub pc: T, pub jumpdest: T, pub push0: T, pub push: T, pub dup_swap: T, pub get_context: T, pub set_context: T, pub mstore_32bytes: T, pub mload_32bytes: T, pub exit_kernel: T, pub m_op_general: T, pub syscall: T, pub exception: T, } // `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) } } }