riscy_isa/opcode/
op_imm_32_function.rs1#[derive(Copy, Clone, Debug, PartialEq)]
2pub enum OpImm32Function {
3 ADDIW,
4 SLLIW,
5 SRLIW,
6 SRAIW,
7}
8
9impl OpImm32Function {
10 pub fn from_func3_imm(func3: u8, imm11_0: u16) -> Self {
11 match (func3, imm11_0 >> 5) {
12 (0b000, _) => OpImm32Function::ADDIW,
13 (0b001, high) if high == 0b0000000 => OpImm32Function::SLLIW,
14 (0b101, high) if high == 0b0000000 => OpImm32Function::SRLIW,
15 (0b101, high) if high == 0b0100000 => OpImm32Function::SRAIW,
16
17 _ => unimplemented!("OP-IMM with func3={:#03b}, imm11_0={:#08x}", func3, imm11_0),
18 }
19 }
20
21 pub fn to_func3(&self) -> i32 {
22 match self {
23 OpImm32Function::ADDIW => 0b000,
24 OpImm32Function::SLLIW => 0b001,
25 OpImm32Function::SRLIW => 0b101,
26 OpImm32Function::SRAIW => 0b101,
27 }
28 }
29}