2022-06-27 16:03:56 -07:00
|
|
|
//! Memory registers.
|
2022-06-13 14:37:29 -07:00
|
|
|
|
2022-07-07 09:28:17 -07:00
|
|
|
use std::ops::Range;
|
|
|
|
|
|
2022-06-27 16:03:56 -07:00
|
|
|
use crate::memory::{NUM_CHANNELS, VALUE_LIMBS};
|
2022-06-17 16:51:32 -07:00
|
|
|
|
2022-07-11 14:47:16 -07:00
|
|
|
// Columns for the same memory operations, ordered by (addr, timestamp).
|
2022-06-17 16:51:32 -07:00
|
|
|
pub(crate) const TIMESTAMP: usize = 0;
|
|
|
|
|
pub(crate) const IS_READ: usize = TIMESTAMP + 1;
|
|
|
|
|
pub(crate) const ADDR_CONTEXT: usize = IS_READ + 1;
|
|
|
|
|
pub(crate) const ADDR_SEGMENT: usize = ADDR_CONTEXT + 1;
|
|
|
|
|
pub(crate) const ADDR_VIRTUAL: usize = ADDR_SEGMENT + 1;
|
|
|
|
|
|
2022-06-17 11:09:01 -07:00
|
|
|
// Eight limbs to hold up to a 256-bit value.
|
2022-06-17 16:52:42 -07:00
|
|
|
const VALUE_START: usize = ADDR_VIRTUAL + 1;
|
2022-06-17 16:51:32 -07:00
|
|
|
pub(crate) const fn value_limb(i: usize) -> usize {
|
2022-06-27 16:03:56 -07:00
|
|
|
debug_assert!(i < VALUE_LIMBS);
|
2022-06-17 16:51:32 -07:00
|
|
|
VALUE_START + i
|
2022-06-07 14:40:42 -07:00
|
|
|
}
|
|
|
|
|
|
2022-07-11 14:47:16 -07:00
|
|
|
// Flags to indicate whether this part of the address differs from the next row,
|
|
|
|
|
// and the previous parts do not differ.
|
|
|
|
|
// That is, e.g., `SEGMENT_FIRST_CHANGE` is `F::ONE` iff `ADDR_CONTEXT` is the same in this
|
|
|
|
|
// row and the next, but `ADDR_SEGMENT` is not.
|
|
|
|
|
pub(crate) const CONTEXT_FIRST_CHANGE: usize = VALUE_START + VALUE_LIMBS;
|
2022-06-17 16:51:32 -07:00
|
|
|
pub(crate) const SEGMENT_FIRST_CHANGE: usize = CONTEXT_FIRST_CHANGE + 1;
|
|
|
|
|
pub(crate) const VIRTUAL_FIRST_CHANGE: usize = SEGMENT_FIRST_CHANGE + 1;
|
2022-06-07 14:40:42 -07:00
|
|
|
|
2022-07-07 09:28:17 -07:00
|
|
|
// Flags to indicate if this operation came from the `i`th channel of the memory bus.
|
|
|
|
|
const IS_CHANNEL_START: usize = VIRTUAL_FIRST_CHANGE + 1;
|
|
|
|
|
pub(crate) const fn is_channel(channel: usize) -> usize {
|
|
|
|
|
debug_assert!(channel < NUM_CHANNELS);
|
|
|
|
|
IS_CHANNEL_START + channel
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-11 14:47:16 -07:00
|
|
|
// We use a range check to enforce the ordering.
|
2022-07-07 09:28:17 -07:00
|
|
|
pub(crate) const RANGE_CHECK: usize = IS_CHANNEL_START + NUM_CHANNELS;
|
2022-06-17 11:09:01 -07:00
|
|
|
// The counter column (used for the range check) starts from 0 and increments.
|
2022-06-17 16:51:32 -07:00
|
|
|
pub(crate) const COUNTER: usize = RANGE_CHECK + 1;
|
2022-06-17 11:09:01 -07:00
|
|
|
// Helper columns for the permutation argument used to enforce the range check.
|
2022-06-17 16:51:32 -07:00
|
|
|
pub(crate) const RANGE_CHECK_PERMUTED: usize = COUNTER + 1;
|
|
|
|
|
pub(crate) const COUNTER_PERMUTED: usize = RANGE_CHECK_PERMUTED + 1;
|
|
|
|
|
|
2022-07-07 09:28:57 -07:00
|
|
|
// Columns to be padded at the top with zeroes, before the permutation argument takes place.
|
2022-07-07 09:28:17 -07:00
|
|
|
pub(crate) const COLUMNS_TO_PAD: Range<usize> = TIMESTAMP..RANGE_CHECK + 1;
|
2022-06-09 10:39:25 -07:00
|
|
|
|
2022-07-07 09:28:17 -07:00
|
|
|
pub(crate) const NUM_COLUMNS: usize = COUNTER_PERMUTED + 1;
|