From 441f665d342c2050f915a7b7b60cf0cef4bb4868 Mon Sep 17 00:00:00 2001 From: supersurviveur Date: Sun, 9 Nov 2025 18:23:24 +0100 Subject: [PATCH] Stage 12: passing tests --- bench/tests/op/lb.s | 2 -- bench/tests/op/lbu.s | 2 -- bench/tests/op/lh.s | 4 ---- bench/tests/op/lhu.s | 4 ---- bench/tests/op/lw.s | 2 -- src/main/scala/projet/Rv32i.scala | 25 +++++++++++++++---------- 6 files changed, 15 insertions(+), 24 deletions(-) diff --git a/bench/tests/op/lb.s b/bench/tests/op/lb.s index 6a383aa..8284a0e 100644 --- a/bench/tests/op/lb.s +++ b/bench/tests/op/lb.s @@ -2,11 +2,9 @@ .text _start: addi x1, x0, 0x0FB - nop # Next instruction depends on previous register op sb x1, 100(x0) lb x31, 100(x0) addi x1, x0, 0x0FB - nop # Next instruction depends on previous register op sb x1, 106(x0) lb x31, 106(x0) diff --git a/bench/tests/op/lbu.s b/bench/tests/op/lbu.s index df68222..a8f6624 100644 --- a/bench/tests/op/lbu.s +++ b/bench/tests/op/lbu.s @@ -2,11 +2,9 @@ .text _start: addi x1, x0, 0x0FB - nop # Next instruction depends on previous register op sb x1, 100(x0) lbu x31, 100(x0) addi x1, x0, 0x0FB - nop # Next instruction depends on previous register op sb x1, 106(x0) lbu x31, 106(x0) diff --git a/bench/tests/op/lh.s b/bench/tests/op/lh.s index 98ef006..1ec4c7d 100644 --- a/bench/tests/op/lh.s +++ b/bench/tests/op/lh.s @@ -2,15 +2,11 @@ .text _start: lui x1, 0xF - nop # Next instruction depends on previous register op ori x1, x1, 0x1BC - nop # Next instruction depends on previous register op sh x1, 100(x0) lh x31, 100(x0) lui x1, 0xF - nop # Next instruction depends on previous register op ori x1, x1, 0x1BC - nop # Next instruction depends on previous register op sh x1, 106(x0) lh x31, 106(x0) diff --git a/bench/tests/op/lhu.s b/bench/tests/op/lhu.s index d039a95..c611d1a 100644 --- a/bench/tests/op/lhu.s +++ b/bench/tests/op/lhu.s @@ -2,15 +2,11 @@ .text _start: lui x1, 0xF - nop # Next instruction depends on previous register op ori x1, x1, 0x1BC - nop # Next instruction depends on previous register op sh x1, 100(x0) lhu x31, 100(x0) lui x1, 0xF - nop # Next instruction depends on previous register op ori x1, x1, 0x1BC - nop # Next instruction depends on previous register op sh x1, 106(x0) lhu x31, 106(x0) diff --git a/bench/tests/op/lw.s b/bench/tests/op/lw.s index 3558bdd..2876a82 100644 --- a/bench/tests/op/lw.s +++ b/bench/tests/op/lw.s @@ -2,8 +2,6 @@ .text _start: lui x1, 0x12345 - nop # Next instruction depends on previous register op ori x1, x1, 0x1BC - nop # Next instruction depends on previous register op sw x1, 100(x0) lw x31, 100(x0) diff --git a/src/main/scala/projet/Rv32i.scala b/src/main/scala/projet/Rv32i.scala index ae24aab..0f753f6 100644 --- a/src/main/scala/projet/Rv32i.scala +++ b/src/main/scala/projet/Rv32i.scala @@ -82,43 +82,48 @@ class Rv32i(sim: Boolean = true) extends Module { reg_rd_index := rd_index; reg_file.io.rd_addr := reg_rd_index; + val writeback_line = Mux( + reg_mux_executeout_dout, + reg_execute_out, + dmem.io.data_out + ); + val rs1_data = + Mux(rs1_index === reg_rd_index && rs1_index =/= 0.U, writeback_line, reg_file.io.rs1_data) + val rs2_data = + Mux(rs2_index === reg_rd_index && rs2_index =/= 0.U, writeback_line, reg_file.io.rs2_data) + // EXECUTE val imm = immediate_decoder.io.immediate alu.io.a := Mux( control_unit.io.mux_rega_pc, - reg_file.io.rs1_data, + rs1_data, execute_pc ); - alu.io.b := Mux(control_unit.io.mux_regb_imm, reg_file.io.rs2_data, imm); + alu.io.b := Mux(control_unit.io.mux_regb_imm, rs2_data, imm); // Select what to send on writeback line val execute_out = Mux(control_unit.io.mux_alu_imm, alu.io.out, imm); reg_execute_out := execute_out; reg_mux_executeout_dout := control_unit.io.mux_executeout_dout; - val writeback_line = Mux( - reg_mux_executeout_dout, - reg_execute_out, - dmem.io.data_out - ); reg_file.io.rd_data := Mux( Delay.Delay(control_unit.io.mux_writeback_pc, 1, true.B), writeback_line, - reg_pc + Delay.Delay(reg_pc, 1, 0.U) ); // Writeback pipelining registers reg_pc := Mux( - control_unit.io.mux_pcadder_writeback, + Delay.Delay(control_unit.io.mux_pcadder_writeback, 1, true.B), pc_adder_out, writeback_line ); - dmem.io.data_in := reg_file.io.rs2_data + dmem.io.data_in := rs2_data dmem.io.addr := execute_out io.ibus.wdata := 0.U;