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

Function exec_fp_op

crates/virtual-machine/src/cpu/pipeline/execute.rs:515–816  ·  view source on GitHub ↗
(
    funct5: u8,
    fmt: u8,
    rm: u8,
    rd: usize,
    rs1: usize,
    rs2: usize,
    regs: &Registers,
    csrs: &CsrFile,
    pc: u64,
)

Source from the content-addressed store, hash-verified

513// --- FP helpers ---
514
515fn exec_fp_op(
516 funct5: u8,
517 fmt: u8,
518 rm: u8,
519 rd: usize,
520 rs1: usize,
521 rs2: usize,
522 regs: &Registers,
523 csrs: &CsrFile,
524 pc: u64,
525) -> Result<ExecResult, VmError> {
526 // Resolve dynamic rounding mode
527 let rm = if rm == RM_DYN {
528 csrs.rounding_mode()
529 } else {
530 rm
531 };
532 let next_pc = pc.wrapping_add(4);
533
534 match funct5 {
535 // FADD
536 0b00000 => {
537 let (bits, fflags) = match fmt {
538 0 => alu::fp_add_s(regs.read_f32(rs1), regs.read_f32(rs2), rm),
539 1 => alu::fp_add_d(regs.read_f64(rs1), regs.read_f64(rs2), rm),
540 _ => return Err(VmError::IllegalInstruction(funct5 as u32)),
541 };
542 Ok(ExecResult::WriteFpFlags {
543 rd,
544 bits,
545 fflags,
546 next_pc,
547 })
548 }
549 // FSUB
550 0b00001 => {
551 let (bits, fflags) = match fmt {
552 0 => alu::fp_sub_s(regs.read_f32(rs1), regs.read_f32(rs2), rm),
553 1 => alu::fp_sub_d(regs.read_f64(rs1), regs.read_f64(rs2), rm),
554 _ => return Err(VmError::IllegalInstruction(funct5 as u32)),
555 };
556 Ok(ExecResult::WriteFpFlags {
557 rd,
558 bits,
559 fflags,
560 next_pc,
561 })
562 }
563 // FMUL
564 0b00010 => {
565 let (bits, fflags) = match fmt {
566 0 => alu::fp_mul_s(regs.read_f32(rs1), regs.read_f32(rs2), rm),
567 1 => alu::fp_mul_d(regs.read_f64(rs1), regs.read_f64(rs2), rm),
568 _ => return Err(VmError::IllegalInstruction(funct5 as u32)),
569 };
570 Ok(ExecResult::WriteFpFlags {
571 rd,
572 bits,

Callers 1

executeFunction · 0.85

Calls 15

fp_add_sFunction · 0.85
fp_add_dFunction · 0.85
fp_sub_sFunction · 0.85
fp_sub_dFunction · 0.85
fp_mul_sFunction · 0.85
fp_mul_dFunction · 0.85
fp_div_sFunction · 0.85
fp_div_dFunction · 0.85
fp_sqrt_sFunction · 0.85
fp_sqrt_dFunction · 0.85
fp_sgnj_sFunction · 0.85
fp_sgnjn_sFunction · 0.85

Tested by

no test coverage detected