Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions vm/src/chips/chips/alu/add_sub/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ pub mod columns;
pub mod constraints;
pub mod traces;

#[cfg(test)]
mod tests;

/// A chip that implements addition for the opcode ADD and SUB.
///
/// SUB is basically an ADD with a re-arrangment of the operands and result.
Expand Down
29 changes: 29 additions & 0 deletions vm/src/chips/chips/alu/add_sub/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use super::AddSubChip;
use crate::machine::{chip::ChipBehavior, folder::SymbolicConstraintFolder};
use p3_air::{Air, BaseAir};
use p3_koala_bear::KoalaBear;

#[test]
fn test_add_sub_chip_simple_eval() {
// crate a add-sub chip
let chip: AddSubChip<KoalaBear> = AddSubChip::default();

// get the preprocessed and main trace widths
let preprocessed_width = chip.preprocessed_width();
let width = chip.width();

// create a constraint builder and evaluate with the chip
let mut builder = SymbolicConstraintFolder::new(preprocessed_width, width);
chip.eval(&mut builder);

// check the constraints and public values
assert_eq!(builder.constraints.len(), 17);
assert_eq!(builder.public_values.len(), 231);

// check the looking (sending) and looked (receiving) lookups
let (looking, looked) = builder.lookups();
assert_eq!(looking.len(), 6);
assert_eq!(looked.len(), 2);

// TODO: check the details of evaluated result
}
3 changes: 3 additions & 0 deletions vm/src/chips/chips/alu/bitwise/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ pub mod columns;
pub mod constraints;
pub mod traces;

#[cfg(test)]
mod tests;

/// A chip that implements bitwise operations for the opcodes XOR, OR, and AND.
#[derive(Default)]
pub struct BitwiseChip<F>(PhantomData<F>);
29 changes: 29 additions & 0 deletions vm/src/chips/chips/alu/bitwise/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use super::BitwiseChip;
use crate::machine::{chip::ChipBehavior, folder::SymbolicConstraintFolder};
use p3_air::{Air, BaseAir};
use p3_koala_bear::KoalaBear;

#[test]
fn test_bitwise_chip_simple_eval() {
// crate a bitwise chip
let chip: BitwiseChip<KoalaBear> = BitwiseChip::default();

// get the preprocessed and main trace widths
let preprocessed_width = chip.preprocessed_width();
let width = chip.width();

// create a constraint builder and evaluate with the chip
let mut builder = SymbolicConstraintFolder::new(preprocessed_width, width);
chip.eval(&mut builder);

// check the constraints and public values
assert_eq!(builder.constraints.len(), 4);
assert_eq!(builder.public_values.len(), 231);

// check the looking (sending) and looked (receiving) lookups
let (looking, looked) = builder.lookups();
assert_eq!(looking.len(), 4);
assert_eq!(looked.len(), 1);

// TODO: check the details of evaluated result
}
3 changes: 3 additions & 0 deletions vm/src/chips/chips/alu/divrem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ pub mod constraints;
pub mod traces;
mod utils;

#[cfg(test)]
mod tests;

/// A chip that implements addition for the opcodes DIV/REM.
#[derive(Default)]
pub struct DivRemChip<F>(PhantomData<F>);
29 changes: 29 additions & 0 deletions vm/src/chips/chips/alu/divrem/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use super::DivRemChip;
use crate::machine::{chip::ChipBehavior, folder::SymbolicConstraintFolder};
use p3_air::{Air, BaseAir};
use p3_koala_bear::KoalaBear;

#[test]
fn test_div_rem_chip_simple_eval() {
// crate a divrem chip
let chip: DivRemChip<KoalaBear> = DivRemChip::default();

// get the preprocessed and main trace widths
let preprocessed_width = chip.preprocessed_width();
let width = chip.width();

// create a constraint builder and evaluate with the chip
let mut builder = SymbolicConstraintFolder::new(preprocessed_width, width);
chip.eval(&mut builder);

// check the constraints and public values
assert_eq!(builder.constraints.len(), 131);
assert_eq!(builder.public_values.len(), 231);

// check the looking (sending) and looked (receiving) lookups
let (looking, looked) = builder.lookups();
assert_eq!(looking.len(), 16);
assert_eq!(looked.len(), 1);

// TODO: check the details of evaluated result
}
3 changes: 3 additions & 0 deletions vm/src/chips/chips/alu/lt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@ mod columns;
mod constraints;
mod traces;

#[cfg(test)]
mod tests;

pub use columns::*;
pub use traces::*;
29 changes: 29 additions & 0 deletions vm/src/chips/chips/alu/lt/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use super::LtChip;
use crate::machine::{chip::ChipBehavior, folder::SymbolicConstraintFolder};
use p3_air::{Air, BaseAir};
use p3_koala_bear::KoalaBear;

#[test]
fn test_lt_chip_simple_eval() {
// crate a less-than chip
let chip: LtChip<KoalaBear> = LtChip::default();

// get the preprocessed and main trace widths
let preprocessed_width = chip.preprocessed_width();
let width = chip.width();

// create a constraint builder and evaluate with the chip
let mut builder = SymbolicConstraintFolder::new(preprocessed_width, width);
chip.eval(&mut builder);

// check the constraints and public values
assert_eq!(builder.constraints.len(), 32);
assert_eq!(builder.public_values.len(), 231);

// check the looking (sending) and looked (receiving) lookups
let (looking, looked) = builder.lookups();
assert_eq!(looking.len(), 3);
assert_eq!(looked.len(), 1);

// TODO: check the details of evaluated result
}
3 changes: 3 additions & 0 deletions vm/src/chips/chips/alu/mul/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ pub mod columns;
pub mod constraints;
pub mod traces;

#[cfg(test)]
mod tests;

/// The number of digits in the product is at most the sum of the number of digits in the
/// multiplicands.
const PRODUCT_SIZE: usize = 2 * WORD_SIZE;
Expand Down
29 changes: 29 additions & 0 deletions vm/src/chips/chips/alu/mul/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use super::MulChip;
use crate::machine::{chip::ChipBehavior, folder::SymbolicConstraintFolder};
use p3_air::{Air, BaseAir};
use p3_koala_bear::KoalaBear;

#[test]
fn test_mul_chip_simple_eval() {
// crate a mul chip
let chip: MulChip<KoalaBear> = MulChip::default();

// get the preprocessed and main trace widths
let preprocessed_width = chip.preprocessed_width();
let width = chip.width();

// create a constraint builder and evaluate with the chip
let mut builder = SymbolicConstraintFolder::new(preprocessed_width, width);
chip.eval(&mut builder);

// check the constraints and public values
assert_eq!(builder.constraints.len(), 30);
assert_eq!(builder.public_values.len(), 231);

// check the looking (sending) and looked (receiving) lookups
let (looking, looked) = builder.lookups();
assert_eq!(looking.len(), 14);
assert_eq!(looked.len(), 1);

// TODO: check the details of evaluated result
}
3 changes: 3 additions & 0 deletions vm/src/chips/chips/alu/sll/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@ mod columns;
mod constraints;
mod traces;

#[cfg(test)]
mod tests;

pub use columns::*;
pub use traces::*;
29 changes: 29 additions & 0 deletions vm/src/chips/chips/alu/sll/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use super::SLLChip;
use crate::machine::{chip::ChipBehavior, folder::SymbolicConstraintFolder};
use p3_air::{Air, BaseAir};
use p3_koala_bear::KoalaBear;

#[test]
fn test_shift_left_chip_simple_eval() {
// crate a shift-left chip
let chip: SLLChip<KoalaBear> = SLLChip::default();

// get the preprocessed and main trace widths
let preprocessed_width = chip.preprocessed_width();
let width = chip.width();

// create a constraint builder and evaluate with the chip
let mut builder = SymbolicConstraintFolder::new(preprocessed_width, width);
chip.eval(&mut builder);

// check the constraints and public values
assert_eq!(builder.constraints.len(), 64);
assert_eq!(builder.public_values.len(), 231);

// check the looking (sending) and looked (receiving) lookups
let (looking, looked) = builder.lookups();
assert_eq!(looking.len(), 4);
assert_eq!(looked.len(), 1);

// TODO: check the details of evaluated result
}
3 changes: 3 additions & 0 deletions vm/src/chips/chips/alu/sr/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
pub mod columns;
pub mod constraints;
pub mod traces;

#[cfg(test)]
mod tests;
29 changes: 29 additions & 0 deletions vm/src/chips/chips/alu/sr/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use super::traces::ShiftRightChip;
use crate::machine::{chip::ChipBehavior, folder::SymbolicConstraintFolder};
use p3_air::{Air, BaseAir};
use p3_koala_bear::KoalaBear;

#[test]
fn test_shift_right_chip_simple_eval() {
// crate a shift-right chip
let chip: ShiftRightChip<KoalaBear> = ShiftRightChip::default();

// get the preprocessed and main trace widths
let preprocessed_width = chip.preprocessed_width();
let width = chip.width();

// create a constraint builder and evaluate with the chip
let mut builder = SymbolicConstraintFolder::new(preprocessed_width, width);
chip.eval(&mut builder);

// check the constraints and public values
assert_eq!(builder.constraints.len(), 81);
assert_eq!(builder.public_values.len(), 231);

// check the looking (sending) and looked (receiving) lookups
let (looking, looked) = builder.lookups();
assert_eq!(looking.len(), 25);
assert_eq!(looked.len(), 1);

// TODO: check the details of evaluated result
}
3 changes: 3 additions & 0 deletions vm/src/chips/chips/riscv_cpu/auipc/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
pub mod columns;
pub mod constraints;
pub mod traces;

#[cfg(test)]
mod tests;
36 changes: 36 additions & 0 deletions vm/src/chips/chips/riscv_cpu/auipc/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use crate::{
chips::chips::riscv_cpu::{columns::CpuCols, CpuChip},
machine::{chip::ChipBehavior, folder::SymbolicConstraintFolder},
};
use p3_air::{AirBuilder, BaseAir};
use p3_koala_bear::KoalaBear;
use p3_matrix::Matrix;
use std::borrow::Borrow;

#[test]
fn test_auipc_instruction_simple_eval() {
// crate a riscv-cpu chip
let chip: CpuChip<KoalaBear> = CpuChip::default();

// get the preprocessed and main trace widths
let preprocessed_width = chip.preprocessed_width();
let width = chip.width();

// create a constraint builder and evaluate with the chip
let mut builder = SymbolicConstraintFolder::new(preprocessed_width, width);
let main = builder.main();
let local = main.row_slice(0);
let local: &CpuCols<_> = (*local).borrow();

// evaluate auipc instruction
chip.eval_auipc(&mut builder, local);

// check the constraints and public values
assert_eq!(builder.constraints.len(), 16);
assert_eq!(builder.public_values.len(), 231);

// check the looking (sending) and looked (receiving) lookups
let (looking, looked) = builder.lookups();
assert_eq!(looking.len(), 1);
assert_eq!(looked.len(), 0);
}
3 changes: 3 additions & 0 deletions vm/src/chips/chips/riscv_cpu/branch/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
pub mod columns;
pub mod constraints;
pub mod traces;

#[cfg(test)]
mod tests;
38 changes: 38 additions & 0 deletions vm/src/chips/chips/riscv_cpu/branch/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use crate::{
chips::chips::riscv_cpu::{columns::CpuCols, CpuChip},
machine::{chip::ChipBehavior, folder::SymbolicConstraintFolder},
};
use p3_air::{AirBuilder, BaseAir};
use p3_field::FieldAlgebra;
use p3_koala_bear::KoalaBear;
use p3_matrix::Matrix;
use std::borrow::Borrow;

#[test]
fn test_branch_instruction_simple_eval() {
// crate a riscv-cpu chip
let chip: CpuChip<KoalaBear> = CpuChip::default();

// get the preprocessed and main trace widths
let preprocessed_width = chip.preprocessed_width();
let width = chip.width();

// create a constraint builder and evaluate with the chip
let mut builder = SymbolicConstraintFolder::new(preprocessed_width, width);
let main = builder.main();
let (local, next) = (main.row_slice(0), main.row_slice(1));
let local: &CpuCols<_> = (*local).borrow();
let next: &CpuCols<_> = (*next).borrow();

// evaluate branch instruction
chip.eval_branch_ops(&mut builder, KoalaBear::ONE.into(), local, next);

// check the constraints and public values
assert_eq!(builder.constraints.len(), 52);
assert_eq!(builder.public_values.len(), 231);

// check the looking (sending) and looked (receiving) lookups
let (looking, looked) = builder.lookups();
assert_eq!(looking.len(), 3);
assert_eq!(looked.len(), 0);
}
3 changes: 3 additions & 0 deletions vm/src/chips/chips/riscv_cpu/jump/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
pub mod columns;
pub mod constraints;
pub mod traces;

#[cfg(test)]
mod tests;
Loading
Loading