use crate::*;
pub fn try_decode_q00(i: u32) -> Option<Instruction> {
match i >> 13 {
0b000 if i == 0 => Some(Instruction::Illegal),
0b000 => None, 0b001 => None, 0b010 => Some(Instruction::Lw(IType(
((i & 0x1c00) << 13) | ((i & 0x380) << 8) | ((i & 0x40) << 16) | ((i & 0x20) << 21) | ((i & 0x1c) << 5) | 0b_01000_010_01000_0000011
))),
0b011 => Some(Instruction::Ld(IType( ((i & 0x1c00) << 13) | ((i & 0x380) << 8) | ((i & 0x60) << 21) | ((i & 0x1c) << 5) | 0b_01000_011_01000_0000011
))),
0b100 => None, 0b101 => None, 0b110 => Some(Instruction::Sw(SType( ((i & 0x1000) << 13) | ((i & 0xc00)) | ((i & 0x380) << 8) | ((i & 0x40) << 3) | ((i & 0x20) << 21) | ((i & 0x1c) << 18) | 0b_01000_01000_010_00000_0100011
))),
0b111 => Some(Instruction::Sd(SType( ((i & 0x1000) << 13) | ((i & 0xc00)) | ((i & 0x380) << 8) | ((i & 0x60) << 21) | ((i & 0x1c) << 18) | 0b_01000_01000_011_00000_0100011
))),
_ => None,
}
}
pub fn try_decode_q01(_i: u32) -> Option<Instruction> {
None
}
pub fn try_decode_q10(_i: u32) -> Option<Instruction> {
None
}
#[cfg(test)]
mod tests {
use super::*;
use super::Instruction::*;
#[test]
fn q00() {
assert_eq!(try_decode_q00(0x6188).unwrap(), Ld(IType(0x0005b503))); assert_eq!(try_decode_q00(0x75e0).unwrap(), Ld(IType(0x0e85b403))); assert_eq!(try_decode_q00(0x43b0).unwrap(), Lw(IType(0x0407a603))); assert_eq!(try_decode_q00(0xe188).unwrap(), Sd(SType(0x00a5b023))); assert_eq!(try_decode_q00(0xf5e0).unwrap(), Sd(SType(0x0e85b423))); assert_eq!(try_decode_q00(0xc3b0).unwrap(), Sw(SType(0x04c7a023))); }
}