Skip to content

Commit

Permalink
Renames
Browse files Browse the repository at this point in the history
  • Loading branch information
dlubarov committed Jan 24, 2024
1 parent deccf90 commit 27bf713
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
18 changes: 9 additions & 9 deletions cpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,31 +259,31 @@ impl CpuChip {
fn compute_word_diffs<F: PrimeField>(rows: &mut Vec<[F; NUM_CPU_COLS]>) {
// Compute `diff`
let mut diff = vec![F::zero(); rows.len()];
for n in 0..rows.len() {
for i in 0..rows.len() {
let word_1 = CPU_COL_MAP.mem_channels[0]
.value
.into_iter()
.map(|i| rows[n][i])
.map(|i| rows[i][i])
.collect::<Vec<_>>();
let word_2 = CPU_COL_MAP.mem_channels[1]
.value
.into_iter()
.map(|i| rows[n][i])
.map(|i| rows[i][i])
.collect::<Vec<_>>();
for (a, b) in word_1.into_iter().zip(word_2) {
diff[n] += (a - b).square();
diff[i] += (a - b).square();
}
}

// Compute `diff_inv`
let diff_inv = batch_multiplicative_inverse_allowing_zero(diff.clone());

// Set trace values
for n in 0..rows.len() {
rows[n][CPU_COL_MAP.diff] = diff[n];
rows[n][CPU_COL_MAP.diff_inv] = diff_inv[n];
if diff[n] != F::zero() {
rows[n][CPU_COL_MAP.not_equal] = F::one();
for i in 0..rows.len() {
rows[i][CPU_COL_MAP.diff] = diff[i];
rows[i][CPU_COL_MAP.diff_inv] = diff_inv[i];
if diff[i] != F::zero() {
rows[i][CPU_COL_MAP.not_equal] = F::one();
}
}
}
Expand Down
26 changes: 13 additions & 13 deletions memory/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,33 +290,33 @@ impl MemoryChip {
// Compute `diff` and `counter_mult`
let mut diff = vec![F::zero(); rows.len()];
let mut mult = vec![F::zero(); rows.len()];
for n in 0..(rows.len() - 1) {
let addr = ops[n].1.get_address();
let addr_next = ops[n + 1].1.get_address();
for i in 0..(rows.len() - 1) {
let addr = ops[i].1.get_address();
let addr_next = ops[i + 1].1.get_address();
let value = if addr_next != addr {
addr_next - addr
} else {
let clk = ops[n].0;
let clk_next = ops[n + 1].0;
let clk = ops[i].0;
let clk_next = ops[i + 1].0;
clk_next - clk
};
diff[n] = F::from_canonical_u32(value);
diff[i] = F::from_canonical_u32(value);
mult[value as usize] += F::one();
}

// Compute `diff_inv`
let diff_inv = batch_multiplicative_inverse_allowing_zero(diff.clone());

// Set trace values
for n in 0..(rows.len() - 1) {
rows[n][MEM_COL_MAP.diff] = diff[n];
rows[n][MEM_COL_MAP.diff_inv] = diff_inv[n];
rows[n][MEM_COL_MAP.counter_mult] = mult[n];
for i in 0..(rows.len() - 1) {
rows[i][MEM_COL_MAP.diff] = diff[i];
rows[i][MEM_COL_MAP.diff_inv] = diff_inv[i];
rows[i][MEM_COL_MAP.counter_mult] = mult[i];

let addr = ops[n].1.get_address();
let addr_next = ops[n + 1].1.get_address();
let addr = ops[i].1.get_address();
let addr_next = ops[i + 1].1.get_address();
if addr_next - addr != 0 {
rows[n][MEM_COL_MAP.addr_not_equal] = F::one();
rows[i][MEM_COL_MAP.addr_not_equal] = F::one();
}
}

Expand Down
6 changes: 3 additions & 3 deletions output/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ where
let clk_diff = clk_2 - clk_1;
let num_rows = (clk_diff / table_len) as usize + 1;
let mut rows = Vec::with_capacity(num_rows);
for n in 0..num_rows {
for i in 0..num_rows {
let mut row = [SC::Val::zero(); NUM_OUTPUT_COLS];
let cols: &mut OutputCols<SC::Val> = unsafe { transmute(&mut row) };
if n == 0 {
if i == 0 {
cols.is_real = SC::Val::one();
cols.clk = SC::Val::from_canonical_u32(clk_1);
cols.value = SC::Val::from_canonical_u8(val_1);
} else {
// Dummy output to satisfy range check
cols.clk = SC::Val::from_canonical_u32(clk_1 + table_len * (n + 1) as u32);
cols.clk = SC::Val::from_canonical_u32(clk_1 + table_len * (i + 1) as u32);
}
rows.push(row);
}
Expand Down

0 comments on commit 27bf713

Please sign in to comment.