Skip to content

Commit

Permalink
fix: do not wipe EX on FP-induced WAW stalls (#649)
Browse files Browse the repository at this point in the history
Fixes #304.

* fix: do not wipe EX on FP-induced WAW stalls

Similar to #305 (which originally fixed #304), add a check on whether
EX is empty before inserting a BUBBLE instruction.

Also add some more verbose logging to help reason about the flow
without having to use a debugger.

* test: add a regression test for issue 304

This test would have exposed the second reoccurrence of issue #304.

Thanks to @hugmanrique for this code.

* fix: fix merge conflict resolution error
  • Loading branch information
lupino3 committed Mar 5, 2022
1 parent 6f1837f commit 799bfd9
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/main/java/org/edumips64/core/CPU.java
Original file line number Diff line number Diff line change
Expand Up @@ -445,32 +445,41 @@ public void step() throws AddressErrorException, HaltException, IrregularWriteOp
pc.writeDoubleWord((pc.getValue()) + 4);

} catch (RAWException ex) {
logger.info("RAW - Read-After-Write");
if (currentPipeStage == Pipeline.Stage.ID && pipe.EX() == null) {
logger.info("Adding a BUBBLE instruction into EX.");
pipe.setEX(bubble);
}
RAWStalls++;

} catch (WAWException ex) {
logger.info("WAW - Write-After-Write");
logger.info(fpPipe.toString());

if (currentPipeStage == Pipeline.Stage.ID) {
if (currentPipeStage == Pipeline.Stage.ID && pipe.EX() == null) {
logger.info("Adding a BUBBLE instruction into EX.");
pipe.setEX(bubble);
}
WAWStalls++;

} catch (FPDividerNotAvailableException ex) {
logger.info("Structural Stall - FP Divider Unavailable");
if (currentPipeStage == Pipeline.Stage.ID) {
logger.info("Adding a BUBBLE instruction into EX.");
pipe.setEX(bubble);
}
dividerStalls++;

} catch (FPFunctionalUnitNotAvailableException ex) {
logger.info("Structural Stall - FP Unavailable");
if (currentPipeStage == Pipeline.Stage.ID) {
logger.info("Adding a BUBBLE instruction into EX.");
pipe.setEX(bubble);
}
funcUnitStalls++;

} catch (EXNotAvailableException ex) {
logger.info("Structural Stall - EX Unavailable");
exStalls++;

} catch (SynchronousException ex) {
Expand Down
7 changes: 7 additions & 0 deletions src/test/java/org/edumips64/EndToEndTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,13 @@ public void testIssue304UI() throws Exception {
runMipsTest("infinite-bug-304.s", false);
}

/* Issue #304: Infinite RAW stall in floating-point due to instruction overwrite in the EX stage.
*/
@Test(timeout=2000)
public void testIssue304EX() throws Exception {
runMipsTest("issue-304-ex.s", false);
}

/* Issue #304: Missing MEM/WB in Cycles UI for some FPU instructions.
*/
@Test(timeout=2000)
Expand Down
40 changes: 40 additions & 0 deletions src/test/resources/issue-304-ex.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
; Thanks to @hugmanrique for this code.

.data
v: .space 256
w: .space 256
x: .double 2.0
y: .double 1.5
z: .double 0.0

.text
daddi R1, R0, v
daddi R2, R0, w
daddi R3, R0, 256

ldc1 F2, x(R0)
ldc1 F4, y(R0)
daddi R4, R0, 0

loop1:
dmtc1 R4, F6
daddi R4, R4, 8
cvt.d.l F6, F6
mul.d F8, F2, F6
mul.d F10, F4, F6
dmtc1 R4, F12
daddi R4, R4, 8
cvt.d.l F12, F12
mul.d F14, F2, F12
daddi R1, R1, 16
mul.d F8, F8, F8
daddi R2, R2, 16

sdc1 F10, -16(R2)
mul.d F14, F14, F14
mul.d F16, F4, F12
sdc1 F8, -16(R1) ; here
sdc1 F14, -8(R1)
sdc1 F16, -8(R2)
bne R4, R3, loop1
syscall 0

0 comments on commit 799bfd9

Please sign in to comment.