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

Function exec_alu32

crates/virtual-machine/src/cpu/pipeline/execute.rs:473–511  ·  view source on GitHub ↗
(
    funct3: u8,
    funct7: u8,
    rd: usize,
    rs1: usize,
    rs2: usize,
    regs: &Registers,
    pc: u64,
)

Source from the content-addressed store, hash-verified

471}
472
473fn exec_alu32(
474 funct3: u8,
475 funct7: u8,
476 rd: usize,
477 rs1: usize,
478 rs2: usize,
479 regs: &Registers,
480 pc: u64,
481) -> Result<ExecResult, VmError> {
482 let a = regs.read_x(rs1);
483 let b = regs.read_x(rs2);
484 let result = match funct7 {
485 0x00 => match funct3 {
486 0 => alu::addw(a, b),
487 1 => alu::sllw(a, b),
488 5 => alu::srlw(a, b),
489 _ => return Err(VmError::IllegalInstruction(funct3 as u32)),
490 },
491 0x20 => match funct3 {
492 0 => alu::subw(a, b),
493 5 => alu::sraw(a, b),
494 _ => return Err(VmError::IllegalInstruction(funct3 as u32)),
495 },
496 0x01 => match funct3 {
497 0 => alu::mulw(a, b),
498 4 => alu::divw(a, b),
499 5 => alu::divuw(a, b),
500 6 => alu::remw(a, b),
501 7 => alu::remuw(a, b),
502 _ => return Err(VmError::IllegalInstruction(funct3 as u32)),
503 },
504 _ => return Err(VmError::IllegalInstruction(funct7 as u32)),
505 };
506 Ok(ExecResult::WriteInt {
507 rd,
508 val: result,
509 next_pc: pc.wrapping_add(4),
510 })
511}
512
513// --- FP helpers ---
514

Callers 1

executeFunction · 0.85

Calls 11

addwFunction · 0.85
sllwFunction · 0.85
srlwFunction · 0.85
subwFunction · 0.85
srawFunction · 0.85
mulwFunction · 0.85
divwFunction · 0.85
divuwFunction · 0.85
remwFunction · 0.85
remuwFunction · 0.85
read_xMethod · 0.80

Tested by

no test coverage detected