Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add/sub -> rtype gadget to build circuit #230

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 3 additions & 1 deletion ceno_emul/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ mod vm_state;
pub use vm_state::VMState;

mod rv32im;
pub use rv32im::{DecodedInstruction, EmuContext, InsnCategory, InsnKind};
pub use rv32im::{
DecodedInstruction, EmuContext, FastDecodeEntry, InsnCategory, InsnKind, RV32IM_ISA,
};

mod elf;
pub use elf::Program;
4 changes: 2 additions & 2 deletions ceno_emul/src/rv32im.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ pub enum InsnKind {
}

#[derive(Clone, Copy, Debug)]
struct FastDecodeEntry {
pub struct FastDecodeEntry {
pub kind: InsnKind,
category: InsnCategory,
pub opcode: u32,
Expand Down Expand Up @@ -282,7 +282,7 @@ const fn insn(
type InstructionTable = [FastDecodeEntry; 48];
type FastInstructionTable = [u8; 1 << 10];

const RV32IM_ISA: InstructionTable = [
pub const RV32IM_ISA: InstructionTable = [
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There could be a pub fn getter and keep details of the table private.

insn(InsnKind::INVALID, InsnCategory::Invalid, 0x00, 0x0, 0x00),
insn(InsnKind::ADD, InsnCategory::Compute, 0x33, 0x0, 0x00),
insn(InsnKind::SUB, InsnCategory::Compute, 0x33, 0x0, 0x20),
Expand Down
6 changes: 4 additions & 2 deletions ceno_zkvm/src/instructions/riscv.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use constants::OpcodeType;
use ceno_emul::{FastDecodeEntry, InsnKind, RV32IM_ISA};
use ff_ext::ExtensionField;

use super::Instruction;
Expand All @@ -7,10 +7,12 @@ pub mod addsub;
pub mod blt;
pub mod config;
pub mod constants;
mod gadgets;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could have a specific name such as r_insn.

#[cfg(test)]
mod test;

pub trait RIVInstruction<E: ExtensionField>: Instruction<E> {
const OPCODE_TYPE: OpcodeType;
const INST_KIND: InsnKind;
const OPCODE_TYPE: FastDecodeEntry = RV32IM_ISA[Self::INST_KIND as usize];
}
Loading
Loading