Skip to content

Commit

Permalink
apply to U instrunction
Browse files Browse the repository at this point in the history
  • Loading branch information
KimiWu123 committed Oct 17, 2024
1 parent e04c781 commit d5e1943
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
4 changes: 2 additions & 2 deletions ceno_emul/src/tracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ impl StepRecord {
pub fn new_u_instruction(
cycle: Cycle,
pc: ByteAddr,
insn_code: Word,
insn_code: u32,
rd: Change<Word>,
prev_cycle: Cycle,
) -> StepRecord {
let pc = Change::new(pc, pc + PC_STEP_SIZE);
StepRecord::new_insn(cycle, pc, insn_code, None, None, Some(rd), prev_cycle)
StepRecord::new_insn2(cycle, pc, insn_code, None, None, Some(rd), prev_cycle)
}

pub fn new_j_instruction(
Expand Down
34 changes: 20 additions & 14 deletions ceno_zkvm/src/instructions/riscv/jump/test.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use ceno_emul::{ByteAddr, Change, PC_STEP_SIZE, StepRecord};
use ceno_emul::{ByteAddr, Change, EncodedInstruction, InsnKind, PC_STEP_SIZE, StepRecord};
use goldilocks::GoldilocksExt2;
use itertools::Itertools;
use multilinear_extensions::mle::IntoMLEs;

use crate::{
circuit_builder::{CircuitBuilder, ConstraintSystem},
instructions::Instruction,
scheme::mock_prover::{MOCK_PC_AUIPC, MOCK_PC_JAL, MOCK_PC_LUI, MOCK_PROGRAM, MockProver},
scheme::mock_prover::{MOCK_PC_JAL, MOCK_PC_START, MOCK_PROGRAM, MockProver},
};

use super::{AuipcInstruction, JalInstruction, LuiInstruction};
Expand Down Expand Up @@ -54,6 +54,10 @@ fn test_opcode_jal() {
);
}

fn imm(imm: u32) -> u32 {
// valid imm is imm[12:31] in U-type
imm << 12
}
#[test]
fn test_opcode_lui() {
let mut cs = ConstraintSystem::<GoldilocksExt2>::new(|| "riscv");
Expand All @@ -69,29 +73,30 @@ fn test_opcode_lui() {
.unwrap()
.unwrap();

let lui_insn = MOCK_PROGRAM[22];
let imm = lui_insn & 0xfffff000;
let imm_value = imm(0x90005);
let insn_code = EncodedInstruction::encode(InsnKind::LUI, 0, 0, 4, imm_value);
let (raw_witin, lkm) = LuiInstruction::<GoldilocksExt2>::assign_instances(
&config,
cb.cs.num_witin as usize,
vec![StepRecord::new_u_instruction(
4,
MOCK_PC_LUI,
lui_insn,
Change::new(0, imm),
MOCK_PC_START,
insn_code,
Change::new(0, imm_value),
0,
)],
)
.unwrap();

MockProver::assert_satisfied(
MockProver::assert_satisfied_with_program(
&cb,
&raw_witin
.de_interleaving()
.into_mles()
.into_iter()
.map(|v| v.into())
.collect_vec(),
&[insn_code],
None,
Some(lkm),
);
Expand All @@ -112,29 +117,30 @@ fn test_opcode_auipc() {
.unwrap()
.unwrap();

let auipc_insn = MOCK_PROGRAM[23];
let imm = auipc_insn & 0xfffff000;
let imm_value = imm(0x90005);
let insn_code = EncodedInstruction::encode(InsnKind::AUIPC, 0, 0, 4, imm_value);
let (raw_witin, lkm) = AuipcInstruction::<GoldilocksExt2>::assign_instances(
&config,
cb.cs.num_witin as usize,
vec![StepRecord::new_u_instruction(
4,
MOCK_PC_AUIPC,
auipc_insn,
Change::new(0, MOCK_PC_AUIPC.0.wrapping_add(imm)),
MOCK_PC_START,
insn_code,
Change::new(0, MOCK_PC_START.0.wrapping_add(imm_value)),
0,
)],
)
.unwrap();

MockProver::assert_satisfied(
MockProver::assert_satisfied_with_program(
&cb,
&raw_witin
.de_interleaving()
.into_mles()
.into_iter()
.map(|v| v.into())
.collect_vec(),
&[insn_code],
None,
Some(lkm),
);
Expand Down

0 comments on commit d5e1943

Please sign in to comment.