From 5243e46ffb5c528f22d91af880833aade8a24d14 Mon Sep 17 00:00:00 2001 From: Charles Papon Date: Sun, 9 Jun 2019 20:15:36 +0200 Subject: [PATCH] Fix BranchPlugin when SRC can have hazard in execute stage --- src/main/scala/vexriscv/plugin/BranchPlugin.scala | 8 +++++--- src/main/scala/vexriscv/plugin/HazardSimplePlugin.scala | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/scala/vexriscv/plugin/BranchPlugin.scala b/src/main/scala/vexriscv/plugin/BranchPlugin.scala index 30341d3..281063b 100644 --- a/src/main/scala/vexriscv/plugin/BranchPlugin.scala +++ b/src/main/scala/vexriscv/plugin/BranchPlugin.scala @@ -84,6 +84,8 @@ class BranchPlugin(earlyBranch : Boolean, decodePrediction } + def hasHazardOnBranch = if(earlyBranch) pipeline.service(classOf[HazardService]).hazardOnExecuteRS else False + override def setup(pipeline: VexRiscv): Unit = { import Riscv._ import pipeline.config._ @@ -200,7 +202,7 @@ class BranchPlugin(earlyBranch : Boolean, //Apply branchs (JAL,JALR, Bxx) branchStage plug new Area { import branchStage._ - jumpInterface.valid := arbitration.isValid && input(BRANCH_DO) + jumpInterface.valid := arbitration.isValid && input(BRANCH_DO) && !hasHazardOnBranch jumpInterface.payload := input(BRANCH_CALC) when(jumpInterface.valid && !arbitration.isStuckByOthers) { @@ -282,7 +284,7 @@ class BranchPlugin(earlyBranch : Boolean, val branchStage = if(earlyBranch) execute else memory branchStage plug new Area { import branchStage._ - jumpInterface.valid := arbitration.isValid && input(BRANCH_DO) + jumpInterface.valid := arbitration.isValid && input(BRANCH_DO) && !hasHazardOnBranch jumpInterface.payload := input(BRANCH_CALC) when(jumpInterface.valid && !arbitration.isStuckByOthers) { @@ -361,7 +363,7 @@ class BranchPlugin(earlyBranch : Boolean, input(PC) } - jumpInterface.valid := arbitration.isValid && predictionMissmatch //Probably just isValid instead of isFiring is better + jumpInterface.valid := arbitration.isValid && predictionMissmatch && !hasHazardOnBranch jumpInterface.payload := (input(BRANCH_DO) ? input(BRANCH_CALC) | input(NEXT_PC)) diff --git a/src/main/scala/vexriscv/plugin/HazardSimplePlugin.scala b/src/main/scala/vexriscv/plugin/HazardSimplePlugin.scala index c051aa0..f674ae8 100644 --- a/src/main/scala/vexriscv/plugin/HazardSimplePlugin.scala +++ b/src/main/scala/vexriscv/plugin/HazardSimplePlugin.scala @@ -19,7 +19,7 @@ class HazardSimplePlugin(bypassExecute : Boolean = false, def hazardOnExecuteRS = { - if(pipeline.service(classOf[RegFileService]).readStage() == pipeline.execute) pipeline.execute.arbitration.isStuckByOthers else False + if(pipeline.service(classOf[RegFileService]).readStage() == pipeline.execute) pipeline.execute.arbitration.isStuckByOthers else False //TODO not so nice } override def setup(pipeline: VexRiscv): Unit = {