MCPcopy Create free account
hub / github.com/LPC4/Full-Stack / decode

Function decode

crates/virtual-machine/src/cpu/decoder.rs:698–803  ·  view source on GitHub ↗
(word: u32)

Source from the content-addressed store, hash-verified

696// --- Public decode entry point ---
697
698pub fn decode(word: u32) -> Result<DecodedInsn, VmError> {
699 let opcode = word & 0x7F;
700 match opcode {
701 0x37 => Ok(DecodedInsn::Lui {
702 rd: rd(word),
703 imm: u_imm(word),
704 }),
705 0x17 => Ok(DecodedInsn::Auipc {
706 rd: rd(word),
707 imm: u_imm(word),
708 }),
709 0x6F => Ok(DecodedInsn::Jal {
710 rd: rd(word),
711 imm: j_imm(word),
712 }),
713 0x67 => Ok(DecodedInsn::Jalr {
714 rd: rd(word),
715 rs1: rs1(word),
716 imm: i_imm(word),
717 }),
718 0x63 => Ok(DecodedInsn::Branch {
719 funct3: funct3(word),
720 rs1: rs1(word),
721 rs2: rs2(word),
722 imm: b_imm(word),
723 }),
724 0x03 => Ok(DecodedInsn::Load {
725 funct3: funct3(word),
726 rd: rd(word),
727 rs1: rs1(word),
728 imm: i_imm(word),
729 }),
730 0x23 => Ok(DecodedInsn::Store {
731 funct3: funct3(word),
732 rs1: rs1(word),
733 rs2: rs2(word),
734 imm: s_imm(word),
735 }),
736 // OP-IMM: pass the full bits[31:25] as funct7 so the execute stage can
737 // disambiguate SRLI vs SRAI using bit 30 (and check for illegal encodings).
738 0x13 => Ok(DecodedInsn::AluImm {
739 funct3: funct3(word),
740 funct7: field(word, 31, 25) as u8,
741 rd: rd(word),
742 rs1: rs1(word),
743 imm: i_imm(word),
744 }),
745 0x1B => Ok(DecodedInsn::AluImm32 {
746 funct3: funct3(word),
747 funct7: field(word, 31, 25) as u8,
748 rd: rd(word),
749 rs1: rs1(word),
750 imm: i_imm(word),
751 }),
752 0x33 => Ok(DecodedInsn::Alu {
753 funct3: funct3(word),
754 funct7: funct7(word),
755 rd: rd(word),

Callers 14

stage_idMethod · 0.70
render_disasmFunction · 0.50
rtype_decodeFunction · 0.50
itype_decodeFunction · 0.50
decode_luiFunction · 0.50
decode_addiFunction · 0.50
decode_addFunction · 0.50
decode_subFunction · 0.50
decode_mulFunction · 0.50
decode_lwFunction · 0.50
decode_swFunction · 0.50
decode_beqFunction · 0.50

Calls 14

rdFunction · 0.85
u_immFunction · 0.85
j_immFunction · 0.85
rs1Function · 0.85
i_immFunction · 0.85
funct3Function · 0.85
rs2Function · 0.85
b_immFunction · 0.85
s_immFunction · 0.85
fieldFunction · 0.85
funct7Function · 0.85
decode_fenceFunction · 0.85

Tested by 12

rtype_decodeFunction · 0.40
itype_decodeFunction · 0.40
decode_luiFunction · 0.40
decode_addiFunction · 0.40
decode_addFunction · 0.40
decode_subFunction · 0.40
decode_mulFunction · 0.40
decode_lwFunction · 0.40
decode_swFunction · 0.40
decode_beqFunction · 0.40
decode_ecallFunction · 0.40
decode_illegalFunction · 0.40