From 88be32e151a61b2517ee14c3db6ed8e9b7ef240b Mon Sep 17 00:00:00 2001 From: Alex Cockrean <84676155+ABenC377@users.noreply.github.com> Date: Thu, 25 Jul 2024 14:36:06 +0100 Subject: [PATCH 1/7] Updating how a LoopBuffer is begun; and correcting how branch mispredicts are calculated --- src/include/simeng/Instruction.hh | 2 +- src/lib/pipeline/FetchUnit.cc | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/include/simeng/Instruction.hh b/src/include/simeng/Instruction.hh index 9a126460de..0fbaa932d5 100644 --- a/src/include/simeng/Instruction.hh +++ b/src/include/simeng/Instruction.hh @@ -157,7 +157,7 @@ class Instruction { // Flag as mispredicted if taken state was wrongly predicted, or taken and // predicted target is wrong return (branchTaken_ != prediction_.taken || - (prediction_.target != branchAddress_)); + (branchTaken_ && (prediction_.target != branchAddress_))); } /** Check whether an exception has been encountered while processing this diff --git a/src/lib/pipeline/FetchUnit.cc b/src/lib/pipeline/FetchUnit.cc index 553c8198f4..d383e4e32f 100644 --- a/src/lib/pipeline/FetchUnit.cc +++ b/src/lib/pipeline/FetchUnit.cc @@ -176,8 +176,12 @@ void FetchUnit::tick() { } } else if (loopBufferState_ == LoopBufferState::WAITING && pc_ == loopBoundaryAddress_) { - // Once set loopBoundaryAddress_ is fetched, start to fill loop buffer - loopBufferState_ = LoopBufferState::FILLING; + if (macroOp[0]->isBranch() && !macroOp[0]->getBranchPrediction().taken) { + loopBufferState_ = LoopBufferState::IDLE; + } else { + // Once set loopBoundaryAddress_ is fetched, start to fill loop buffer + loopBufferState_ = LoopBufferState::FILLING; + } } assert(bytesRead <= bufferedBytes_ && From 7f6baf198211c5c817677945a9da54efc5aefb97 Mon Sep 17 00:00:00 2001 From: Alex Cockrean <84676155+ABenC377@users.noreply.github.com> Date: Thu, 25 Jul 2024 14:48:11 +0100 Subject: [PATCH 2/7] Adding comments to explain bug fix in FetchUnit.cc --- src/lib/pipeline/FetchUnit.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib/pipeline/FetchUnit.cc b/src/lib/pipeline/FetchUnit.cc index d383e4e32f..a6a0dd8730 100644 --- a/src/lib/pipeline/FetchUnit.cc +++ b/src/lib/pipeline/FetchUnit.cc @@ -176,10 +176,14 @@ void FetchUnit::tick() { } } else if (loopBufferState_ == LoopBufferState::WAITING && pc_ == loopBoundaryAddress_) { + // Now that the loopBoundaryAddress_ has been set, start filling Loop + // Buffer is the branch predictor tells us to reenter the detected loop if (macroOp[0]->isBranch() && !macroOp[0]->getBranchPrediction().taken) { + // If branch is not taken then detected loop is not longer relevant, + // therefore Loop Buffer stays idle loopBufferState_ = LoopBufferState::IDLE; } else { - // Once set loopBoundaryAddress_ is fetched, start to fill loop buffer + // Otherwise, start to fill loop buffer loopBufferState_ = LoopBufferState::FILLING; } } From 2ed54c6741efc6c97033e7077eabeacee2aa7c27 Mon Sep 17 00:00:00 2001 From: Alex Cockrean <84676155+ABenC377@users.noreply.github.com> Date: Thu, 25 Jul 2024 14:50:22 +0100 Subject: [PATCH 3/7] Adding comments to explain bug fix in FetchUnit.cc --- src/lib/pipeline/FetchUnit.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/pipeline/FetchUnit.cc b/src/lib/pipeline/FetchUnit.cc index a6a0dd8730..e90e5fbcf0 100644 --- a/src/lib/pipeline/FetchUnit.cc +++ b/src/lib/pipeline/FetchUnit.cc @@ -179,7 +179,7 @@ void FetchUnit::tick() { // Now that the loopBoundaryAddress_ has been set, start filling Loop // Buffer is the branch predictor tells us to reenter the detected loop if (macroOp[0]->isBranch() && !macroOp[0]->getBranchPrediction().taken) { - // If branch is not taken then detected loop is not longer relevant, + // If branch is not taken then detected loop is no longer relevant, // therefore Loop Buffer stays idle loopBufferState_ = LoopBufferState::IDLE; } else { From 052c4d1a831073b27d65919b89b62e5fcf65dbd2 Mon Sep 17 00:00:00 2001 From: Alex Cockrean <84676155+ABenC377@users.noreply.github.com> Date: Thu, 25 Jul 2024 14:50:42 +0100 Subject: [PATCH 4/7] Adding comments to explain bug fix in FetchUnit.cc --- src/lib/pipeline/FetchUnit.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/pipeline/FetchUnit.cc b/src/lib/pipeline/FetchUnit.cc index e90e5fbcf0..fbfa9968e6 100644 --- a/src/lib/pipeline/FetchUnit.cc +++ b/src/lib/pipeline/FetchUnit.cc @@ -177,7 +177,7 @@ void FetchUnit::tick() { } else if (loopBufferState_ == LoopBufferState::WAITING && pc_ == loopBoundaryAddress_) { // Now that the loopBoundaryAddress_ has been set, start filling Loop - // Buffer is the branch predictor tells us to reenter the detected loop + // Buffer if the branch predictor tells us to reenter the detected loop if (macroOp[0]->isBranch() && !macroOp[0]->getBranchPrediction().taken) { // If branch is not taken then detected loop is no longer relevant, // therefore Loop Buffer stays idle From b520e4571d7042bcb295f1051b5b7c1ac160adce Mon Sep 17 00:00:00 2001 From: Alex Cockrean <84676155+ABenC377@users.noreply.github.com> Date: Thu, 25 Jul 2024 14:52:48 +0100 Subject: [PATCH 5/7] Adding comments to explain bug fix in FetchUnit.cc --- src/lib/pipeline/FetchUnit.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/pipeline/FetchUnit.cc b/src/lib/pipeline/FetchUnit.cc index fbfa9968e6..1b26f0c79d 100644 --- a/src/lib/pipeline/FetchUnit.cc +++ b/src/lib/pipeline/FetchUnit.cc @@ -183,7 +183,7 @@ void FetchUnit::tick() { // therefore Loop Buffer stays idle loopBufferState_ = LoopBufferState::IDLE; } else { - // Otherwise, start to fill loop buffer + // Otherwise, start to fill Loop Buffer loopBufferState_ = LoopBufferState::FILLING; } } From 946c6f04cabb889c73b31804046e65f72b72dc6a Mon Sep 17 00:00:00 2001 From: Alex Cockrean <84676155+ABenC377@users.noreply.github.com> Date: Thu, 25 Jul 2024 15:52:54 +0100 Subject: [PATCH 6/7] Updating simulated cycles --- .jenkins/build_test_run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.jenkins/build_test_run.sh b/.jenkins/build_test_run.sh index 52b3a7bdab..22e48655c9 100644 --- a/.jenkins/build_test_run.sh +++ b/.jenkins/build_test_run.sh @@ -71,7 +71,7 @@ run () { cat run echo "" compare_outputs "$(grep "retired:" run | rev | cut -d ' ' -f1 | rev)" "6724" "retired instructions" - compare_outputs "$(grep "cycles:" run | rev | cut -d ' ' -f1 | rev)" "8677" "simulated cycles" + compare_outputs "$(grep "cycles:" run | rev | cut -d ' ' -f1 | rev)" "8612" "simulated cycles" echo "" } From e93be45d0b5afdffb9fbbb18f8de2e1b720826ab Mon Sep 17 00:00:00 2001 From: Alex Cockrean <84676155+ABenC377@users.noreply.github.com> Date: Thu, 1 Aug 2024 09:54:20 +0100 Subject: [PATCH 7/7] Updating comments --- src/lib/pipeline/FetchUnit.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/lib/pipeline/FetchUnit.cc b/src/lib/pipeline/FetchUnit.cc index 1b26f0c79d..7bc59051e9 100644 --- a/src/lib/pipeline/FetchUnit.cc +++ b/src/lib/pipeline/FetchUnit.cc @@ -176,11 +176,12 @@ void FetchUnit::tick() { } } else if (loopBufferState_ == LoopBufferState::WAITING && pc_ == loopBoundaryAddress_) { - // Now that the loopBoundaryAddress_ has been set, start filling Loop - // Buffer if the branch predictor tells us to reenter the detected loop + // loopBoundaryAddress_ has been fetched whilst loop buffer is waiting, + // start filling Loop Buffer if the branch predictor tells us to + // reenter the detected loop if (macroOp[0]->isBranch() && !macroOp[0]->getBranchPrediction().taken) { - // If branch is not taken then detected loop is no longer relevant, - // therefore Loop Buffer stays idle + // If branch is not taken then we aren't re-entering the detected + // loop, therefore Loop Buffer stays idle loopBufferState_ = LoopBufferState::IDLE; } else { // Otherwise, start to fill Loop Buffer