2022-09-28 15:18:56 -07:00
|
|
|
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)]
|
2022-11-28 13:19:40 -08:00
|
|
|
#[derive(Clone, Copy, Eq, PartialEq, Debug)]
|
|
|
|
|
pub struct OpsColumnsView<T: Copy> {
|
2022-11-07 12:29:28 -08:00
|
|
|
// TODO: combine ADD, MUL, SUB, DIV, MOD, ADDFP254, MULFP254, SUBFP254, LT, and GT into one flag
|
2022-09-28 15:18:56 -07:00
|
|
|
pub add: T,
|
|
|
|
|
pub mul: T,
|
|
|
|
|
pub sub: T,
|
|
|
|
|
pub div: T,
|
|
|
|
|
pub mod_: T,
|
2023-02-10 23:07:57 +11:00
|
|
|
// TODO: combine ADDMOD, MULMOD and SUBMOD into one flag
|
2022-09-28 15:18:56 -07:00
|
|
|
pub addmod: T,
|
|
|
|
|
pub mulmod: T,
|
2022-10-13 14:02:19 -07:00
|
|
|
pub addfp254: T,
|
|
|
|
|
pub mulfp254: T,
|
|
|
|
|
pub subfp254: T,
|
2023-02-10 23:07:57 +11:00
|
|
|
pub submod: T,
|
2022-09-28 15:18:56 -07:00
|
|
|
pub lt: T,
|
|
|
|
|
pub gt: T,
|
2023-08-12 11:08:01 -04:00
|
|
|
pub eq_iszero: T, // Combines EQ and ISZERO flags.
|
|
|
|
|
pub logic_op: T, // Combines AND, OR and XOR flags.
|
2022-09-28 15:18:56 -07:00
|
|
|
pub not: T,
|
|
|
|
|
pub byte: T,
|
2022-11-07 12:29:28 -08:00
|
|
|
// TODO: combine SHL and SHR into one flag
|
2022-09-28 15:18:56 -07:00
|
|
|
pub shl: T,
|
|
|
|
|
pub shr: T,
|
2022-10-01 21:55:47 -07:00
|
|
|
pub keccak_general: T,
|
2022-09-28 15:18:56 -07:00
|
|
|
pub prover_input: T,
|
|
|
|
|
pub pop: T,
|
2022-11-07 12:29:28 -08:00
|
|
|
// TODO: combine JUMP and JUMPI into one flag
|
2023-07-20 16:46:31 -04:00
|
|
|
pub jumps: T, // Note: This column must be 0 when is_cpu_cycle = 0.
|
2022-09-28 15:18:56 -07:00
|
|
|
pub pc: T,
|
|
|
|
|
pub jumpdest: T,
|
2023-06-13 13:29:30 -07:00
|
|
|
pub push0: T,
|
2022-09-28 15:18:56 -07:00
|
|
|
pub push: T,
|
|
|
|
|
pub dup: T,
|
|
|
|
|
pub swap: T,
|
2022-11-07 12:29:28 -08:00
|
|
|
// TODO: combine GET_CONTEXT and SET_CONTEXT into one flag
|
2022-09-28 15:18:56 -07:00
|
|
|
pub get_context: T,
|
|
|
|
|
pub set_context: T,
|
2023-06-02 15:51:26 -07:00
|
|
|
pub exit_kernel: T, // Note: This column must be 0 when is_cpu_cycle = 0.
|
2022-11-07 12:29:28 -08:00
|
|
|
// TODO: combine MLOAD_GENERAL and MSTORE_GENERAL into one flag
|
2022-09-28 15:18:56 -07:00
|
|
|
pub mload_general: T,
|
|
|
|
|
pub mstore_general: T,
|
|
|
|
|
|
2023-06-02 15:51:26 -07:00
|
|
|
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.
|
2022-09-28 15:18:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// `u8` is guaranteed to have a `size_of` of 1.
|
|
|
|
|
pub const NUM_OPS_COLUMNS: usize = size_of::<OpsColumnsView<u8>>();
|
|
|
|
|
|
2022-11-28 13:19:40 -08:00
|
|
|
impl<T: Copy> From<[T; NUM_OPS_COLUMNS]> for OpsColumnsView<T> {
|
2022-09-28 15:18:56 -07:00
|
|
|
fn from(value: [T; NUM_OPS_COLUMNS]) -> Self {
|
|
|
|
|
unsafe { transmute_no_compile_time_size_checks(value) }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-28 13:19:40 -08:00
|
|
|
impl<T: Copy> From<OpsColumnsView<T>> for [T; NUM_OPS_COLUMNS] {
|
2022-09-28 15:18:56 -07:00
|
|
|
fn from(value: OpsColumnsView<T>) -> Self {
|
|
|
|
|
unsafe { transmute_no_compile_time_size_checks(value) }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-28 13:19:40 -08:00
|
|
|
impl<T: Copy> Borrow<OpsColumnsView<T>> for [T; NUM_OPS_COLUMNS] {
|
2022-09-28 15:18:56 -07:00
|
|
|
fn borrow(&self) -> &OpsColumnsView<T> {
|
|
|
|
|
unsafe { transmute(self) }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-28 13:19:40 -08:00
|
|
|
impl<T: Copy> BorrowMut<OpsColumnsView<T>> for [T; NUM_OPS_COLUMNS] {
|
2022-09-28 15:18:56 -07:00
|
|
|
fn borrow_mut(&mut self) -> &mut OpsColumnsView<T> {
|
|
|
|
|
unsafe { transmute(self) }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-28 13:19:40 -08:00
|
|
|
impl<T: Copy> Deref for OpsColumnsView<T> {
|
2022-09-28 15:18:56 -07:00
|
|
|
type Target = [T; NUM_OPS_COLUMNS];
|
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
|
unsafe { transmute(self) }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-28 13:19:40 -08:00
|
|
|
impl<T: Copy> DerefMut for OpsColumnsView<T> {
|
2022-09-28 15:18:56 -07:00
|
|
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
|
|
|
|
unsafe { transmute(self) }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const fn make_col_map() -> OpsColumnsView<usize> {
|
|
|
|
|
let indices_arr = indices_arr::<NUM_OPS_COLUMNS>();
|
|
|
|
|
unsafe { transmute::<[usize; NUM_OPS_COLUMNS], OpsColumnsView<usize>>(indices_arr) }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub const COL_MAP: OpsColumnsView<usize> = make_col_map();
|