Skip to content

Commit

Permalink
include all opcodes in rv32im config
Browse files Browse the repository at this point in the history
  • Loading branch information
kunxian-xia committed Oct 29, 2024
1 parent b24c98a commit 9dd45db
Show file tree
Hide file tree
Showing 11 changed files with 245 additions and 91 deletions.
4 changes: 2 additions & 2 deletions ceno_zkvm/examples/fibonacci_elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use ceno_zkvm::{
structs::{ZKVMConstraintSystem, ZKVMFixedTraces, ZKVMWitnesses},
tables::{MemFinalRecord, ProgramTableCircuit, initial_memory, initial_registers},
};
use ff_ext::ff::Field;
use goldilocks::GoldilocksExt2;
use itertools::Itertools;
use mpcs::{Basefold, BasefoldRSParams, PolynomialCommitmentScheme};
Expand All @@ -19,7 +20,6 @@ use std::{panic, time::Instant};
use tracing_flame::FlameLayer;
use tracing_subscriber::{EnvFilter, Registry, fmt, layer::SubscriberExt};
use transcript::Transcript;
use ff_ext::ff::Field;

fn main() {
type E = GoldilocksExt2;
Expand Down Expand Up @@ -153,7 +153,7 @@ fn main() {
.assign_table_circuit::<ExampleProgramTableCircuit<E>>(
&zkvm_cs,
&prog_config,
&vm.program(),
vm.program(),
)
.unwrap();

Expand Down
8 changes: 4 additions & 4 deletions ceno_zkvm/src/instructions/riscv/branch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@ pub struct BltuOp;
impl RIVInstruction for BltuOp {
const INST_KIND: InsnKind = InsnKind::BLTU;
}
pub type BltuInstruction = bltu::BltuCircuit<BltuOp>;
pub type BltuInstruction<E> = bltu::BltuCircuit<E, BltuOp>;

pub struct BgeuOp;
impl RIVInstruction for BgeuOp {
const INST_KIND: InsnKind = InsnKind::BGEU;
}
pub type BgeuInstruction = bltu::BltuCircuit<BgeuOp>;
pub type BgeuInstruction<E> = bltu::BltuCircuit<E, BgeuOp>;

pub struct BltOp;
impl RIVInstruction for BltOp {
const INST_KIND: InsnKind = InsnKind::BLT;
}
pub type BltInstruction = blt::BltCircuit<BltOp>;
pub type BltInstruction<E> = blt::BltCircuit<E, BltOp>;

pub struct BgeOp;
impl RIVInstruction for BgeOp {
const INST_KIND: InsnKind = InsnKind::BGE;
}
pub type BgeInstruction = blt::BltCircuit<BgeOp>;
pub type BgeInstruction<E> = blt::BltCircuit<E, BgeOp>;
4 changes: 2 additions & 2 deletions ceno_zkvm/src/instructions/riscv/branch/blt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{
};
use ceno_emul::{InsnKind, SWord};

pub struct BltCircuit<I>(PhantomData<I>);
pub struct BltCircuit<E, I>(PhantomData<(E, I)>);

pub struct InstructionConfig<E: ExtensionField> {
pub b_insn: BInstructionConfig<E>,
Expand All @@ -25,7 +25,7 @@ pub struct InstructionConfig<E: ExtensionField> {
pub signed_lt: SignedLtConfig,
}

impl<E: ExtensionField, I: RIVInstruction> Instruction<E> for BltCircuit<I> {
impl<E: ExtensionField, I: RIVInstruction> Instruction<E> for BltCircuit<E, I> {
fn name() -> String {
format!("{:?}", I::INST_KIND)
}
Expand Down
4 changes: 2 additions & 2 deletions ceno_zkvm/src/instructions/riscv/branch/bltu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::{
};
use ceno_emul::InsnKind;

pub struct BltuCircuit<I>(PhantomData<I>);
pub struct BltuCircuit<E, I>(PhantomData<(E, I)>);

pub struct InstructionConfig<E: ExtensionField> {
pub b_insn: BInstructionConfig<E>,
Expand All @@ -29,7 +29,7 @@ pub struct InstructionConfig<E: ExtensionField> {
pub is_lt: IsLtConfig,
}

impl<E: ExtensionField, I: RIVInstruction> Instruction<E> for BltuCircuit<I> {
impl<E: ExtensionField, I: RIVInstruction> Instruction<E> for BltuCircuit<E, I> {
fn name() -> String {
format!("{:?}", I::INST_KIND)
}
Expand Down
4 changes: 4 additions & 0 deletions ceno_zkvm/src/instructions/riscv/jump/jalr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ impl<E: ExtensionField> Instruction<E> for JalrInstruction<E> {

let rs1 = step.rs1().unwrap().value;
let imm: i32 = insn.imm_or_funct7() as i32;
if step.rd().is_none() {
tracing::info!("step: {:?}", step.insn().kind());
tracing::info!("step: {:?}", step);
}
let rd = step.rd().unwrap().value.after;

let (sum, overflowing) = rs1.overflowing_add_signed(imm);
Expand Down
3 changes: 0 additions & 3 deletions ceno_zkvm/src/instructions/riscv/memory/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ impl RIVInstruction for SWOp {
const INST_KIND: InsnKind = InsnKind::SW;
}

#[cfg(test)]
pub type SwInstruction<E> = StoreInstruction<E, SWOp, 2>;

pub struct SHOp;
Expand All @@ -47,7 +46,6 @@ impl RIVInstruction for SHOp {
const INST_KIND: InsnKind = InsnKind::SH;
}

#[cfg(test)]
pub type ShInstruction<E> = StoreInstruction<E, SHOp, 1>;

pub struct SBOp;
Expand All @@ -56,7 +54,6 @@ impl RIVInstruction for SBOp {
const INST_KIND: InsnKind = InsnKind::SB;
}

#[cfg(test)]
pub type SbInstruction<E> = StoreInstruction<E, SBOp, 0>;

impl<E: ExtensionField, I: RIVInstruction, const N_ZEROS: usize> Instruction<E>
Expand Down
Loading

0 comments on commit 9dd45db

Please sign in to comment.