From 658502d3532830bdaeac536b2e88769514761ace Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Wed, 1 Feb 2023 17:26:34 +0100 Subject: [PATCH] Convert some fp reg from array to struct call --- src/simulator/machine.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/simulator/machine.rs b/src/simulator/machine.rs index 913abda..4d4ee63 100644 --- a/src/simulator/machine.rs +++ b/src/simulator/machine.rs @@ -59,6 +59,7 @@ impl Register { pub struct Machine { pub pc : u64, pub int_reg : Register, + pub fp_reg : Register, pub instructions : [u64 ; 100], pub main_memory : [u8 ; MEM_SIZE], pub shiftmask : [u64 ; 64] @@ -86,6 +87,7 @@ impl Machine { pc : 0, instructions : [0 ; 100], int_reg : Register::::init(), + fp_reg: Register::::init(), main_memory : [0 ; MEM_SIZE], shiftmask } @@ -453,19 +455,19 @@ impl Machine { RISCV_FP => { match inst.funct7 { RISCV_FP_ADD => { - machine.fp_reg[inst.rd as usize] = machine.fp_reg[inst.rs1 as usize] + machine.fp_reg[inst.rs2 as usize]; + machine.fp_reg.set_reg(inst.rd as usize, machine.fp_reg.get_reg(inst.rs1 as usize) + machine.fp_reg.get_reg(inst.rs2 as usize)); }, RISCV_FP_SUB => { - machine.fp_reg[inst.rd as usize] = machine.fp_reg[inst.rs1 as usize] - machine.fp_reg[inst.rs2 as usize]; + machine.fp_reg.set_reg(inst.rd as usize, machine.fp_reg.get_reg(inst.rs1 as usize) - machine.fp_reg.get_reg(inst.rs2 as usize)); }, RISCV_FP_MUL => { - machine.fp_reg[inst.rd as usize] = machine.fp_reg[inst.rs1 as usize] * machine.fp_reg[inst.rs2 as usize]; + machine.fp_reg.set_reg(inst.rd as usize, machine.fp_reg.get_reg(inst.rs1 as usize) * machine.fp_reg.get_reg(inst.rs2 as usize)); }, RISCV_FP_DIV => { - machine.fp_reg[inst.rd as usize] = machine.fp_reg[inst.rs1 as usize] / machine.fp_reg[inst.rs2 as usize]; + machine.fp_reg.set_reg(inst.rd as usize, machine.fp_reg.get_reg(inst.rs1 as usize) / machine.fp_reg.get_reg(inst.rs2 as usize)); }, RISCV_FP_SQRT => { - machine.fp_reg[inst.rd as usize] = machine.fp_reg[inst.rs1 as usize].sqrt(); + machine.fp_reg.set_reg(inst.rd as usize, machine.fp_reg.get_reg(inst.rs1 as usize).sqrt()); }, RISCV_FP_FSGN => { let local_float = machine.fp_reg[inst.rs1 as usize];