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

o1vm/riscv32im: test decoding mulhsu #2837

Open
wants to merge 1 commit into
base: o1vm/riscv32im/test-decoding-mulh
Choose a base branch
from
Open
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
36 changes: 36 additions & 0 deletions o1vm/src/interpreters/riscv32im/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,29 @@ pub fn generate_random_mulh_instruction<RNG: RngCore + CryptoRng>(rng: &mut RNG)
]
}

pub fn generate_random_mulhsu_instruction<RNG: RngCore + CryptoRng>(rng: &mut RNG) -> [u8; 4] {
let opcode = 0b0110011;
let rd = rng.gen_range(0..32);
let funct3 = 0b010;
let rs1 = rng.gen_range(0..32);
let rs2 = rng.gen_range(0..32);
let funct2 = 0b01;
let funct5 = 0b00000;
let instruction = opcode
| (rd << 7)
| (funct3 << 12)
| (rs1 << 15)
| (rs2 << 20)
| (funct2 << 25)
| (funct5 << 27);
[
instruction as u8,
(instruction >> 8) as u8,
(instruction >> 16) as u8,
(instruction >> 24) as u8,
]
}

#[test]
pub fn test_instruction_decoding_add() {
let mut env: Env<Fp> = dummy_env();
Expand Down Expand Up @@ -457,3 +480,16 @@ pub fn test_instruction_decoding_mulh() {
let (opcode, _instruction) = env.decode_instruction();
assert_eq!(opcode, Instruction::MType(MInstruction::Mulh));
}

#[test]
pub fn test_instruction_decoding_mulhsu() {
let mut env: Env<Fp> = dummy_env();
let mut rng = o1_utils::tests::make_test_rng(None);
let instruction = generate_random_mulhsu_instruction(&mut rng);
env.memory[0].1[0] = instruction[0];
env.memory[0].1[1] = instruction[1];
env.memory[0].1[2] = instruction[2];
env.memory[0].1[3] = instruction[3];
let (opcode, _instruction) = env.decode_instruction();
assert_eq!(opcode, Instruction::MType(MInstruction::Mulhsu));
}
Loading