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 b0a2bde commit aed3b11
Show file tree
Hide file tree
Showing 10 changed files with 243 additions and 84 deletions.
2 changes: 1 addition & 1 deletion 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
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
Loading

0 comments on commit aed3b11

Please sign in to comment.