Skip to content

Commit

Permalink
Expand documentation for ctl_data_ternops()
Browse files Browse the repository at this point in the history
  • Loading branch information
Nashtare committed Aug 8, 2023
1 parent d51a512 commit 0f3a11e
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions evm/src/cpu/cpu_stark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,18 @@ fn ctl_data_binops<F: Field>(ops: &[usize]) -> Vec<Column<F>> {
}

/// Create the vector of Columns corresponding to the three inputs and
/// one output of a ternary operation.
/// If `is_shift` is `true`, we offset the memory_channels indices used for the inputs
/// by 1. It will only be valid if the associated filter is one of the two shift flags.
/// one output of a ternary operation. By default, ternary operations use
/// the first three memory channels, and the last one for the result (binary
/// operations do not use the third inputs).
///
/// Shift operations are different, as they are simulated with `MUL` or `DIV`
/// on the arithmetic side. As we first convert the shift into the multiplicand
/// (in case of `SHL`) or the divisor (in case of `SHR`), making the first memory
/// channel not directly usable. We overcome this by adding an offset of 1 in
/// case of shift operation, which will skip the first memory channel and use the
/// next three as ternary inputs. Because both `MUL` and `DIV` are binary operations,
/// the last memory channel used for inputs will be safely ignored. The exact mapping
/// is described in [cpu/shift.rs](super::shift::eval_packed).
fn ctl_data_ternops<F: Field>(ops: &[usize], is_shift: bool) -> Vec<Column<F>> {
let offset = is_shift as usize;
let mut res = Column::singles(ops).collect_vec();
Expand Down

0 comments on commit 0f3a11e

Please sign in to comment.