Skip to content
Merged
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
23 changes: 5 additions & 18 deletions src/decode/a_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,40 +170,27 @@ mod test_a {
#[test]
#[allow(overflowing_literals)]
fn a_decode_test() {
use crate::decode::inst_32::test_32_in_rv64;
use crate::instruction::a_extension::AOpcode;
use crate::{Decode, Isa, OpcodeKind};
use crate::OpcodeKind;

let test_32 = |inst_32: u32,
op: OpcodeKind,
rd: Option<usize>,
rs1: Option<usize>,
rs2: Option<usize>,
imm: Option<i32>| {
let op_32 = inst_32.parse_opcode(Isa::Rv64).unwrap();
assert!(matches!(&op_32, op));
assert_eq!(inst_32.parse_rd(&op_32).unwrap(), rd);
assert_eq!(inst_32.parse_rs1(&op_32).unwrap(), rs1);
assert_eq!(inst_32.parse_rs2(&op_32).unwrap(), rs2);
assert_eq!(inst_32.parse_imm(&op_32, Isa::Rv64).unwrap(), imm);
};

test_32(
test_32_in_rv64(
0x04d7_27af,
OpcodeKind::A(AOpcode::AMOADD_W),
Some(15),
Some(14),
Some(13),
Some(2),
);
test_32(
test_32_in_rv64(
0x1007b62f,
OpcodeKind::A(AOpcode::LR_D),
Some(12),
Some(15),
None,
Some(0),
);
test_32(
test_32_in_rv64(
0x60f6302f,
OpcodeKind::A(AOpcode::AMOAND_D),
Some(0),
Expand Down
45 changes: 16 additions & 29 deletions src/decode/base_i.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,128 +343,115 @@ mod test_basei {
#[test]
#[allow(overflowing_literals)]
fn basei_decode_test() {
use crate::decode::inst_32::test_32_in_rv64;
use crate::instruction::base_i::BaseIOpcode;
use crate::{Decode, Isa, OpcodeKind};
use crate::OpcodeKind;

let test_32 = |inst_32: u32,
op: OpcodeKind,
rd: Option<usize>,
rs1: Option<usize>,
rs2: Option<usize>,
imm: Option<i32>| {
let op_32 = inst_32.parse_opcode(Isa::Rv64).unwrap();
assert!(matches!(&op_32, op));
assert_eq!(inst_32.parse_rd(&op_32).unwrap(), rd);
assert_eq!(inst_32.parse_rs1(&op_32).unwrap(), rs1);
assert_eq!(inst_32.parse_rs2(&op_32).unwrap(), rs2);
assert_eq!(inst_32.parse_imm(&op_32, Isa::Rv64).unwrap(), imm);
};

test_32(
test_32_in_rv64(
0b1000_0000_0000_0000_0000_0000_1011_0111,
OpcodeKind::BaseI(BaseIOpcode::LUI),
Some(1),
None,
None,
Some(0x8000_0000),
);
test_32(
test_32_in_rv64(
0b0000_0000_0000_0000_0000_0010_1001_0111,
OpcodeKind::BaseI(BaseIOpcode::AUIPC),
Some(5),
None,
None,
Some(0),
);
test_32(
test_32_in_rv64(
0b1111_1111_1001_1111_1111_0000_0110_1111,
OpcodeKind::BaseI(BaseIOpcode::JAL),
Some(0),
None,
None,
Some(-8),
);
test_32(
test_32_in_rv64(
0b1111_1110_0010_0000_1000_1110_1010_0011,
OpcodeKind::BaseI(BaseIOpcode::SB),
None,
Some(1),
Some(2),
Some(-3),
);
test_32(
test_32_in_rv64(
0b1110_1110_1100_0010_1000_0010_1001_0011,
OpcodeKind::BaseI(BaseIOpcode::ADDI),
Some(5),
Some(5),
None,
Some(-276),
);
test_32(
test_32_in_rv64(
0b0000_0000_0000_0000_0000_0000_0111_0011,
OpcodeKind::BaseI(BaseIOpcode::ECALL),
None,
None,
None,
None,
);
test_32(
test_32_in_rv64(
0b0000_0000_0000_0101_0100_1100_0110_0011,
OpcodeKind::BaseI(BaseIOpcode::BLT),
None,
Some(10),
Some(0),
Some(24),
);
test_32(
test_32_in_rv64(
0x0010_0513,
OpcodeKind::BaseI(BaseIOpcode::ADDI),
Some(10),
Some(0),
None,
Some(1),
);
test_32(
test_32_in_rv64(
0x4170_04b3,
OpcodeKind::BaseI(BaseIOpcode::SUB),
Some(9),
Some(0),
Some(23),
None,
);
test_32(
test_32_in_rv64(
0x3307_3983,
OpcodeKind::BaseI(BaseIOpcode::LD),
Some(19),
Some(14),
None,
Some(816),
);
test_32(
test_32_in_rv64(
0x10ec_eb63,
OpcodeKind::BaseI(BaseIOpcode::BLTU),
None,
Some(25),
Some(14),
Some(278),
);
test_32(
test_32_in_rv64(
0x31e1_60ef,
OpcodeKind::BaseI(BaseIOpcode::JAL),
Some(1),
None,
None,
Some(90910),
);
test_32(
test_32_in_rv64(
0x0019_4913,
OpcodeKind::BaseI(BaseIOpcode::XORI),
Some(18),
Some(18),
None,
Some(1),
);
test_32(
test_32_in_rv64(
0x00a9_3933,
OpcodeKind::BaseI(BaseIOpcode::SLTU),
Some(18),
Expand Down
40 changes: 14 additions & 26 deletions src/decode/c_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,111 +268,99 @@ pub mod bit_16 {
mod test_c {
#[test]
fn c_decode_test() {
use crate::decode::inst_16::test_16_in_rv64;
use crate::instruction::c_extension::COpcode;
use crate::{Decode, Isa, OpcodeKind};
let test_16 = |inst_16: u16,
op: OpcodeKind,
rd: Option<usize>,
rs1: Option<usize>,
rs2: Option<usize>,
imm: Option<i32>| {
let op_16 = inst_16.parse_opcode(Isa::Rv64).unwrap();
assert!(matches!(&op_16, op));
assert_eq!(inst_16.parse_rd(&op_16).unwrap(), rd);
assert_eq!(inst_16.parse_rs1(&op_16).unwrap(), rs1);
assert_eq!(inst_16.parse_rs2(&op_16).unwrap(), rs2);
assert_eq!(inst_16.parse_imm(&op_16, Isa::Rv64).unwrap(), imm);
};
use crate::OpcodeKind;

test_16(
test_16_in_rv64(
0b0000_0000_0000_0001,
OpcodeKind::C(COpcode::NOP),
None,
None,
None,
Some(0),
);
test_16(
test_16_in_rv64(
0b0110_0011_1000_0001,
OpcodeKind::C(COpcode::LUI),
Some(7),
None,
None,
Some(0),
);
test_16(
test_16_in_rv64(
0b1000_0010_1100_0001,
OpcodeKind::C(COpcode::SRAI),
Some(13),
Some(13),
None,
Some(16),
);
test_16(
test_16_in_rv64(
0x4521,
OpcodeKind::C(COpcode::LI),
Some(10),
None,
None,
Some(8),
);
test_16(
test_16_in_rv64(
0xb5e5,
OpcodeKind::C(COpcode::J),
None,
None,
None,
Some(-280),
);
test_16(
test_16_in_rv64(
0x6105,
OpcodeKind::C(COpcode::ADDI),
Some(2),
Some(2),
None,
Some(32),
);
test_16(
test_16_in_rv64(
0x8082,
OpcodeKind::C(COpcode::JR),
None,
Some(1),
Some(0),
None,
);
test_16(
test_16_in_rv64(
0xe29d,
OpcodeKind::C(COpcode::BNEZ),
None,
Some(13),
None,
Some(38),
);
test_16(
test_16_in_rv64(
0xc05c,
OpcodeKind::C(COpcode::SW),
None,
Some(8),
Some(15),
Some(4),
);
test_16(
test_16_in_rv64(
0x9002,
OpcodeKind::C(COpcode::EBREAK),
None,
None,
None,
None,
);
test_16(
test_16_in_rv64(
0x880a,
OpcodeKind::C(COpcode::MV),
Some(16),
None,
Some(2),
None,
);
test_16(
test_16_in_rv64(
0x8585,
OpcodeKind::C(COpcode::SRAI),
Some(11),
Expand Down
Loading
Loading