Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating Branch Predictors to replace hash-map with Fetch Target Queue #401

Closed
wants to merge 193 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
193 commits
Select commit Hold shift + click to select a range
d365f5a
Adding speculative global history, moving update to ROB, and replacin…
ABenC377 Feb 23, 2024
524c48d
Getting rid of print statements used to track down missing branches
ABenC377 Feb 23, 2024
15fe35d
Changing how globalHistory is updated in the event of a mispredicton
ABenC377 Feb 23, 2024
0411a32
Clang format etc.
ABenC377 Feb 23, 2024
13fec7d
Adding to documentation
ABenC377 Feb 23, 2024
38be41c
Fixing global history bug in generic predictor
ABenC377 Feb 24, 2024
40aabe4
Fixing unit test failures resulting from changes to BP structure
ABenC377 Feb 26, 2024
a30a254
Getting rid of redundant info in the FTQ
ABenC377 Feb 26, 2024
2ba15c4
Clang Format
ABenC377 Feb 26, 2024
162a800
Adding new test for speculative global history updates
ABenC377 Feb 27, 2024
da59fdf
Addressing superficial comments on PR
ABenC377 Mar 5, 2024
11d483f
Adding EXPECT_CALL for branch predictor in reorderBufferTest.cc
ABenC377 Mar 6, 2024
1b2202c
Moving branch statistic collectiong to Reorder buffer and updating te…
ABenC377 Mar 8, 2024
409d627
Removing BP stats from in-order core getstats
ABenC377 Mar 8, 2024
b9bb4f4
Moving branch prediction stat collection to fetch unit to better alig…
ABenC377 Mar 11, 2024
300ea41
Fixing typo
ABenC377 Mar 11, 2024
4377e72
Clang format
ABenC377 Mar 11, 2024
16ec8ac
Adding ftq description in the BP docs
ABenC377 Apr 11, 2024
d7937e4
Attending to Generic Predictor comments
ABenC377 Apr 11, 2024
a0d933a
Docs typo fixed
ABenC377 Apr 11, 2024
4a120ab
Adding buffer check comment
ABenC377 Apr 11, 2024
e673ddc
Fixing typo
ABenC377 Apr 11, 2024
97c50b5
Updating comment re shifting the address to get the hashed index
ABenC377 Apr 30, 2024
97bac68
Adding comment re multiplying global history length by two
ABenC377 Apr 30, 2024
01be4a5
Renaming getBranchExecutedCount to getBranchFetchedCount
ABenC377 Apr 30, 2024
9d8702c
Adding globalHistoryMask_ variable to genericPredictor
ABenC377 Apr 30, 2024
67ff81e
Adding more detail to virtual flush and update functions re order of …
ABenC377 Apr 30, 2024
364f22d
reversing order of purge flush from decodeUnit
ABenC377 Apr 30, 2024
5a4e71c
Moving buffer branch flush functionality from core.cc to PipelineBuff…
ABenC377 Apr 30, 2024
b37e00a
rebase
ABenC377 Jun 5, 2024
f5afa99
Adding comments explaining more basically the nature of the global hi…
ABenC377 Apr 30, 2024
b81f837
replacing top/bottom with front/back in the docs when referring to a …
ABenC377 Apr 30, 2024
84e4ede
Replacing left-most with most-significant
ABenC377 Apr 30, 2024
c5ec7f1
Replacing left-most with most-significant
ABenC377 May 1, 2024
ce3f118
Moving BP files to new directory
ABenC377 May 1, 2024
4b1b50b
Moving AlwaysNotTakenPredictor files to BP directory
ABenC377 May 1, 2024
ad0d58a
clangformat and undoing some unintended taken -> isTaken
ABenC377 May 1, 2024
b2d6ae8
rebase
ABenC377 Jun 5, 2024
5a10cab
rebase
ABenC377 Jun 5, 2024
1e08ca0
Updating BP tests for consistency with new predict() arguments
ABenC377 May 7, 2024
80d3d10
Updating docs
ABenC377 May 7, 2024
0b71bf4
Updating comments
ABenC377 May 7, 2024
dbf5638
rebase
ABenC377 Jun 5, 2024
090e9db
clang format
ABenC377 May 7, 2024
3013198
adding flush asserts
ABenC377 May 7, 2024
594052a
Responding to PR comments
ABenC377 May 10, 2024
38bec68
Responding to PR comments
ABenC377 May 10, 2024
50a378c
Moving words around
ABenC377 May 10, 2024
d66e380
Moving words around
ABenC377 May 10, 2024
a47cae2
Moving words around
ABenC377 May 10, 2024
02f70d8
Correcting definition of 'misprediction', and updating tests accordingly
ABenC377 May 12, 2024
081d12f
undoing last push
ABenC377 May 13, 2024
0f2eaa8
Finessing update logic re target adresses
ABenC377 May 14, 2024
2c00eaf
Updating predict() comment in BranchPredictor.hh
ABenC377 May 24, 2024
1908500
Updating predict() comment in BranchPredictor.hh
ABenC377 May 24, 2024
c2cccb6
Updating haeders and comments
ABenC377 May 24, 2024
22d4bd8
Fixing indentation in CMakeLists.txt
ABenC377 May 24, 2024
3022658
Updating metric language in Core.cc
ABenC377 May 24, 2024
6567c62
Updating variable name in Core class
ABenC377 May 28, 2024
e1c91d4
Adding assert to branch predictors to confirm that they are being upd…
ABenC377 May 28, 2024
7fae8c5
Adding test and clang formatting
ABenC377 May 30, 2024
c25ce4e
rebase
ABenC377 Jun 5, 2024
5f7e5a5
Adding better comments to speculativeGlobalHistory tests in generic a…
ABenC377 Jun 4, 2024
bac3123
Clang format
ABenC377 Jun 4, 2024
d02c095
Changing use of prediction in loopbuffer
ABenC377 Jun 4, 2024
3634a23
replacing = with ==
ABenC377 Jun 4, 2024
e8320ae
Typo fix
ABenC377 Jun 4, 2024
98b2dfe
rebase
ABenC377 Jun 5, 2024
7455be6
Hiding variables that are unused in Release behind ifndef clause
ABenC377 Jun 5, 2024
4b164c7
Adding to branch predictor docs
ABenC377 Jun 12, 2024
9ed27cf
Changing nomenclature
ABenC377 Jun 12, 2024
a1ae600
Adding to branch predictor lastUpdatedInstructionId_ comment
ABenC377 Jun 12, 2024
01628df
Adding comment re unused predict() call in the fetch unit
ABenC377 Jun 12, 2024
92935d3
Moving lasyUpdatedInstructionId_ to BranchPredictor.hh
ABenC377 Jun 12, 2024
beee5e6
clang format
ABenC377 Jun 12, 2024
12bf83c
Adding more detail to idndef comment in BranchPredictor.hh
ABenC377 Jun 13, 2024
b06d894
Updating comments in FetchUnit.cc
ABenC377 Jun 19, 2024
9f39f24
U[dating expected simulated cycles
ABenC377 Jun 19, 2024
cccaeaa
Adding to BP documentation
ABenC377 Jun 19, 2024
16ebda6
Adding to comments to address PR comments
ABenC377 Jun 19, 2024
5665da1
Adjusting comment explaining ifdef in BranchPredictor.hh
ABenC377 Jul 16, 2024
1132605
Updating comment regarding maybe_unused attribute in FetchUnit.cc
ABenC377 Jul 16, 2024
cecb893
Getting rid of superfluous assert in FetchUnit.cc -- the BP works reg…
ABenC377 Jul 16, 2024
16c3f89
Making further changes to comments
ABenC377 Jul 16, 2024
0c50f1f
Shortening comments
ABenC377 Jul 16, 2024
bb38bf7
Adding branches retired statistic, and specifying how it is calculate…
ABenC377 Jul 18, 2024
2c4b739
clang format
ABenC377 Jul 18, 2024
6cc094e
Updating output metrics
ABenC377 Jul 23, 2024
1c394e7
Fixing LoopBuffer bug (#421)
ABenC377 Aug 2, 2024
f86cf1e
Adding speculative global history, moving update to ROB, and replacin…
ABenC377 Feb 23, 2024
d65f400
Getting rid of print statements used to track down missing branches
ABenC377 Feb 23, 2024
4773ceb
Changing how globalHistory is updated in the event of a mispredicton
ABenC377 Feb 23, 2024
74808b7
Clang format etc.
ABenC377 Feb 23, 2024
377b7e8
Adding to documentation
ABenC377 Feb 23, 2024
e9a1140
Fixing global history bug in generic predictor
ABenC377 Feb 24, 2024
131517f
Fixing unit test failures resulting from changes to BP structure
ABenC377 Feb 26, 2024
0a026f8
Getting rid of redundant info in the FTQ
ABenC377 Feb 26, 2024
ec51af0
Clang Format
ABenC377 Feb 26, 2024
e73a153
Adding new test for speculative global history updates
ABenC377 Feb 27, 2024
b611a83
Addressing superficial comments on PR
ABenC377 Mar 5, 2024
268a555
Adding EXPECT_CALL for branch predictor in reorderBufferTest.cc
ABenC377 Mar 6, 2024
a2d471c
Moving branch statistic collectiong to Reorder buffer and updating te…
ABenC377 Mar 8, 2024
fcfc467
Removing BP stats from in-order core getstats
ABenC377 Mar 8, 2024
8391bc9
Moving branch prediction stat collection to fetch unit to better alig…
ABenC377 Mar 11, 2024
b31fa8b
Fixing typo
ABenC377 Mar 11, 2024
18933f8
Clang format
ABenC377 Mar 11, 2024
fa594f4
Adding ftq description in the BP docs
ABenC377 Apr 11, 2024
b10dcbc
Attending to Generic Predictor comments
ABenC377 Apr 11, 2024
c0a79ce
Docs typo fixed
ABenC377 Apr 11, 2024
b7b5550
Adding buffer check comment
ABenC377 Apr 11, 2024
071c484
Fixing typo
ABenC377 Apr 11, 2024
cf19465
Updating comment re shifting the address to get the hashed index
ABenC377 Apr 30, 2024
9f6c6a6
Adding comment re multiplying global history length by two
ABenC377 Apr 30, 2024
daaa2f6
Renaming getBranchExecutedCount to getBranchFetchedCount
ABenC377 Apr 30, 2024
284f3c8
Adding globalHistoryMask_ variable to genericPredictor
ABenC377 Apr 30, 2024
e4df5c5
Adding more detail to virtual flush and update functions re order of …
ABenC377 Apr 30, 2024
6313b6a
reversing order of purge flush from decodeUnit
ABenC377 Apr 30, 2024
882251a
Moving buffer branch flush functionality from core.cc to PipelineBuff…
ABenC377 Apr 30, 2024
abcc64d
Rebasing
ABenC377 Aug 2, 2024
83185ca
Adding comments explaining more basically the nature of the global hi…
ABenC377 Apr 30, 2024
6599dd2
replacing top/bottom with front/back in the docs when referring to a …
ABenC377 Apr 30, 2024
4bb71f4
Replacing left-most with most-significant
ABenC377 Apr 30, 2024
cc773c4
Replacing left-most with most-significant
ABenC377 May 1, 2024
c0b9351
Moving BP files to new directory
ABenC377 May 1, 2024
8a690de
Moving AlwaysNotTakenPredictor files to BP directory
ABenC377 May 1, 2024
23fd3d9
clangformat and undoing some unintended taken -> isTaken
ABenC377 May 1, 2024
fc779bb
rebase
ABenC377 Jun 5, 2024
d2016c6
rebase
ABenC377 Jun 5, 2024
59224ce
Updating BP tests for consistency with new predict() arguments
ABenC377 May 7, 2024
3994c45
Updating docs
ABenC377 May 7, 2024
d4579a0
Updating comments
ABenC377 May 7, 2024
1373773
rebase
ABenC377 Jun 5, 2024
75f4170
clang format
ABenC377 May 7, 2024
c1ba45d
adding flush asserts
ABenC377 May 7, 2024
36a7f1a
Responding to PR comments
ABenC377 May 10, 2024
3298bea
Responding to PR comments
ABenC377 May 10, 2024
305c904
Moving words around
ABenC377 May 10, 2024
15b1037
Moving words around
ABenC377 May 10, 2024
b612c3d
Moving words around
ABenC377 May 10, 2024
9e701bc
Rebasing
ABenC377 Aug 2, 2024
a402dcf
undoing last push
ABenC377 May 13, 2024
7b336ac
Finessing update logic re target adresses
ABenC377 May 14, 2024
6148a4a
Updating predict() comment in BranchPredictor.hh
ABenC377 May 24, 2024
cc19a8d
Updating predict() comment in BranchPredictor.hh
ABenC377 May 24, 2024
e663223
Updating haeders and comments
ABenC377 May 24, 2024
7d6ac3a
Fixing indentation in CMakeLists.txt
ABenC377 May 24, 2024
0067388
Updating metric language in Core.cc
ABenC377 May 24, 2024
b4fab7e
Updating variable name in Core class
ABenC377 May 28, 2024
f9b9f55
Adding assert to branch predictors to confirm that they are being upd…
ABenC377 May 28, 2024
76d7f77
Adding test and clang formatting
ABenC377 May 30, 2024
f6a5b53
rebase
ABenC377 Jun 5, 2024
6c64a48
Adding better comments to speculativeGlobalHistory tests in generic a…
ABenC377 Jun 4, 2024
babb314
Clang format
ABenC377 Jun 4, 2024
7d4f5d7
Changing use of prediction in loopbuffer
ABenC377 Jun 4, 2024
7365e53
replacing = with ==
ABenC377 Jun 4, 2024
1a7ed63
Typo fix
ABenC377 Jun 4, 2024
ada85e4
rebase
ABenC377 Jun 5, 2024
f543387
Hiding variables that are unused in Release behind ifndef clause
ABenC377 Jun 5, 2024
7cb9ce0
Adding to branch predictor docs
ABenC377 Jun 12, 2024
499d66b
Changing nomenclature
ABenC377 Jun 12, 2024
659bdd3
Adding to branch predictor lastUpdatedInstructionId_ comment
ABenC377 Jun 12, 2024
cdccbe8
Adding comment re unused predict() call in the fetch unit
ABenC377 Jun 12, 2024
db4011a
Moving lasyUpdatedInstructionId_ to BranchPredictor.hh
ABenC377 Jun 12, 2024
b14427e
clang format
ABenC377 Jun 12, 2024
307b5f0
Adding more detail to idndef comment in BranchPredictor.hh
ABenC377 Jun 13, 2024
480e703
Updating comments in FetchUnit.cc
ABenC377 Jun 19, 2024
d73ed83
Adding to BP documentation
ABenC377 Jun 19, 2024
f2302ad
Adding to comments to address PR comments
ABenC377 Jun 19, 2024
5c8173a
Adjusting comment explaining ifdef in BranchPredictor.hh
ABenC377 Jul 16, 2024
921aee0
Updating comment regarding maybe_unused attribute in FetchUnit.cc
ABenC377 Jul 16, 2024
36c14cb
Getting rid of superfluous assert in FetchUnit.cc -- the BP works reg…
ABenC377 Jul 16, 2024
5dfbd81
Making further changes to comments
ABenC377 Jul 16, 2024
9284920
Shortening comments
ABenC377 Jul 16, 2024
3d4acc2
Adding branches retired statistic, and specifying how it is calculate…
ABenC377 Jul 18, 2024
a8d2d5d
clang format
ABenC377 Jul 18, 2024
327a720
Rebasing
ABenC377 Aug 2, 2024
f3c721b
Rebasing
ABenC377 Aug 2, 2024
2884451
Merge remote-tracking branch 'origin/BP_update' into BP_update
ABenC377 Aug 2, 2024
28a8e30
Changing CI check test to differentiate instructions retired and bran…
ABenC377 Aug 2, 2024
7a71430
Changing CI check test to differentiate instructions retired and bran…
ABenC377 Aug 2, 2024
0159790
Changing expected number of simulated cycles
ABenC377 Aug 2, 2024
446385b
Updating buffer flush logic
ABenC377 Aug 9, 2024
582da29
Attending to comments on PR
ABenC377 Aug 12, 2024
cf4137f
Making predict a wrapper function
ABenC377 Aug 14, 2024
b50b84d
Getting rid of default argument
ABenC377 Aug 22, 2024
95d384d
Getting rid of default argument
ABenC377 Aug 22, 2024
3a2b1ab
Going to ull when shifting
ABenC377 Aug 22, 2024
abfc2f1
Going to ull when shifting
ABenC377 Aug 22, 2024
94a445d
Merge remote-tracking branch 'origin/BP_update' into BP_update
ABenC377 Aug 22, 2024
d7e0dbb
Adding comments
ABenC377 Aug 22, 2024
e58902b
Updating comments
ABenC377 Aug 22, 2024
98459d3
Addressing Jack's comments
ABenC377 Aug 23, 2024
aec467d
Replacing pointers with references
ABenC377 Aug 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .jenkins/build_test_run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,25 @@ test () {
}

# Run default program with and without specified configuration
# Space needed before 'retired' and 'cycles' to differentiate from other
# subfeilds. E.g., 'branches.retired'
run () {
cd "$SIMENG_INSTALL" || exit

./bin/simeng > run
echo "Simulation without configuration file argument:"
cat run
echo ""
compare_outputs "$(grep "retired:" run | rev | cut -d ' ' -f1 | rev)" "6721" "retired instructions"
compare_outputs "$(grep "cycles:" run | rev | cut -d ' ' -f1 | rev)" "6721" "simulated cycles"
compare_outputs "$(grep " retired:" run | rev | cut -d ' ' -f1 | rev)" "6721" "retired instructions"
compare_outputs "$(grep " cycles:" run | rev | cut -d ' ' -f1 | rev)" "6721" "simulated cycles"
dANW34V3R marked this conversation as resolved.
Show resolved Hide resolved
echo ""

./bin/simeng "$SIMENG_TOP"/configs/tx2.yaml > run
echo "Simulation with configuration file argument:"
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 " retired:" run | rev | cut -d ' ' -f1 | rev)" "6724" "retired instructions"
compare_outputs "$(grep " cycles:" run | rev | cut -d ' ' -f1 | rev)" "7867" "simulated cycles"
echo ""
}

Expand Down
8 changes: 5 additions & 3 deletions docs/sphinx/developer/components/branchPred.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Branch prediction

SimEng's fetch unit is supplied with an instance of the abstract ``BranchPredictor`` class to enable speculative execution.

Access to the ``BranchPredictor`` is supported through the ``predict``, ``update``, and ``flush`` functions. ``predict`` provides a branch prediction, both target and direction, ``update`` updates an instructions' prediction, and ``flush`` provides optional algorithm specific flushing functionality.
Access to the ``BranchPredictor`` is supported through the ``predict``, ``update``, and ``flush`` functions. ``predict`` provides a branch prediction, both target and direction, for a branch instruction. ``update`` updates the branch predictor's prediction mechanism on the actual outcome of a branch. ``flush`` provides algorithm specific flushing functionality.

The ``predict`` function is passed an instruction address, branch type, and a possible known target. The branch type argument currently supports the following types:

Expand All @@ -17,13 +17,15 @@ The usage of these parameters within a branch predictor's ``predict`` function i

The ``update`` function is passed the branch outcome, the instruction address, and the branch type. From this information, any algorithms or branch structures may be updated.

The state of the branch predictor when ``predict`` is called on a branch is stored in the ``ftq`` to be used by the ``update`` function. For instance, the perceptron predictor stores the globalHistory and confidence for each prediction, but future predictors may store alternative state. The ``ftq`` is a queue that has an entry for each in-flight branch. A single entry is added to the back of the ftq on ``predict``, and a single entry is removed from the front of the queue on ``update`` and from the back of the queue on ``flush``.

Generic Predictor
-----------------

The algorithm(s) held within a ``BranchPredictor`` class instance can be model-specific, however, SimEng provides a ``GenericPredictor`` which contains the following logic.

Global History
For indexing relevant prediction structures, a global history can be utilised. The global history value uses n-bits to store the n most recent branch direction outcomes, with the left-most bit being the oldest.
For indexing relevant prediction structures, a global history can be utilised. The global history value stores the n most recent branch direction outcomes in an unsigned integer, with the least-significant bit being the most recent branch direction. The global history is speculatively updated on ``predict``, and is corrected if needed on ``update`` and ``flush``. To facilitate this speculative updating, and rolling-back on correction, for a global history of n the branch predictor keeps track of the 2n most recent branch outcomes. Valid values for Global History are 1-32.

Branch Target Buffer (BTB)
For each entry, the BTB stores the most recent target along with an n-bit saturating counter for an associated direction. The indexing of this structure uses the lower bits of an instruction address XOR'ed with the current global branch history value.
Expand All @@ -41,7 +43,7 @@ Perceptron Predictor
The ``PerceptronPredictor`` has the same overall structure as the ``GenericPredictor`` but replaces the saturating counter as a means for direction prediction with a perceptron. The ``PerceptronPredictor`` contains the following logic.

Global History
For indexing relevant prediction structures and for retrieving a direction from the perceptrons, a global history can be utilised. The global history value uses n-bits to store the n most recent branch direction outcomes, with the left-most bit being the oldest.
For indexing relevant prediction structures, a global history can be utilised. The global history value stores the n most recent branch direction outcomes in an unsigned integer, with the least-significant bit being the most recent branch direction. The global history is speculatively updated on ``predict``, and is corrected if needed on ``update`` and ``flush``. To facilitate this speculative updating, and rolling-back on correction, for a global history of n the branch predictor keeps track of the 2n most recent branch outcomes. Valid values for Global History are 1-32.

Branch Target Buffer (BTB)
For each entry, the BTB stores the most recent target along with a perceptron for an associated direction. The indexing of this structure uses the lower, non-zero bits of an instruction address XOR'ed with the current global branch history value.
Expand Down
3 changes: 2 additions & 1 deletion docs/sphinx/user/running_simeng.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ Exit Clause
The reason why the simulation has halted. Most commonly this is due to the invoking of the ``exit()`` system call by the workload under simulation.

Statistics
A selection of simulation statistics describing the emergent simulated PMU-style hardware events.
A selection of simulation statistics describing the emergent simulated PMU-style hardware events. With respect to branch statistics, the misprediction rate
is calculated as branches mispredicted / branches retired.

dANW34V3R marked this conversation as resolved.
Show resolved Hide resolved
All non-workload outputs from SimEng are prefixed with a tag of the format ``[SimEng:Object]`` (e.g. ``[SimEng:ExceptionHandler]``). If the output came from the root of the framework, the ``Object`` field is omitted.

Expand Down
65 changes: 0 additions & 65 deletions src/include/simeng/BranchPredictor.hh

This file was deleted.

6 changes: 3 additions & 3 deletions src/include/simeng/CoreInstance.hh
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

#include <string>

#include "simeng/AlwaysNotTakenPredictor.hh"
#include "simeng/Core.hh"
#include "simeng/Elf.hh"
#include "simeng/GenericPredictor.hh"
#include "simeng/PerceptronPredictor.hh"
#include "simeng/SpecialFileDirGen.hh"
#include "simeng/arch/Architecture.hh"
#include "simeng/arch/aarch64/Architecture.hh"
#include "simeng/arch/riscv/Architecture.hh"
#include "simeng/branchpredictors/AlwaysNotTakenPredictor.hh"
#include "simeng/branchpredictors/GenericPredictor.hh"
#include "simeng/branchpredictors/PerceptronPredictor.hh"
#include "simeng/config/SimInfo.hh"
#include "simeng/kernel/Linux.hh"
#include "simeng/memory/FixedLatencyMemoryInterface.hh"
Expand Down
10 changes: 5 additions & 5 deletions src/include/simeng/Instruction.hh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
#include <vector>

#include "capstone/capstone.h"
#include "simeng/BranchPredictor.hh"
#include "simeng/Register.hh"
#include "simeng/RegisterValue.hh"
#include "simeng/branchpredictors/BranchPrediction.hh"
#include "simeng/memory/MemoryInterface.hh"
#include "simeng/span.hh"

Expand Down Expand Up @@ -154,9 +154,9 @@ class Instruction {
bool wasBranchMispredicted() const {
assert(executed_ &&
"Branch misprediction check requires instruction to have executed");
// Flag as mispredicted if taken state was wrongly predicted, or taken and
// predicted target is wrong
return (branchTaken_ != prediction_.taken ||
// Flag as mispredicted if taken state was wrongly predicted, or taken
// and predicted target is wrong
return ((branchTaken_ != prediction_.isTaken) ||
(prediction_.target != branchAddress_));
}

Expand All @@ -178,7 +178,7 @@ class Instruction {
* executing it. */
uint16_t getStallCycles() const { return stallCycles_; }

/** Retrieve the number of cycles this instruction will take to be prcoessed
/** Retrieve the number of cycles this instruction will take to be processed
* by the LSQ. */
uint16_t getLSQLatency() const { return lsqExecutionLatency_; }

Expand Down
2 changes: 1 addition & 1 deletion src/include/simeng/arch/Architecture.hh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
#include <tuple>
#include <vector>

#include "simeng/BranchPredictor.hh"
#include "simeng/Core.hh"
#include "simeng/Instruction.hh"
#include "simeng/arch/ProcessStateChange.hh"
#include "simeng/branchpredictors/BranchPredictor.hh"
#include "simeng/kernel/Linux.hh"
#include "simeng/memory/MemoryInterface.hh"

Expand Down
2 changes: 1 addition & 1 deletion src/include/simeng/arch/aarch64/Instruction.hh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
#include <array>
#include <unordered_map>

#include "simeng/BranchPredictor.hh"
#include "simeng/Instruction.hh"
#include "simeng/arch/aarch64/InstructionGroups.hh"
#include "simeng/arch/aarch64/operandContainer.hh"
#include "simeng/branchpredictors/BranchPredictor.hh"

struct cs_arm64_op;

Expand Down
2 changes: 1 addition & 1 deletion src/include/simeng/arch/riscv/Instruction.hh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#include <functional>
#include <unordered_map>

#include "simeng/BranchPredictor.hh"
#include "simeng/Instruction.hh"
#include "simeng/arch/riscv/InstructionGroups.hh"
#include "simeng/branchpredictors/BranchPredictor.hh"

namespace simeng {
namespace arch {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
#pragma once

#include "simeng/BranchPredictor.hh"
#include "simeng/branchpredictors/BranchPredictor.hh"

namespace simeng {

/** An "Always Not Taken" branch predictor; predicts all branches as not taken.
*/
/** An "Always Not Taken" branch predictor; predicts all branches as not
* taken. */
class AlwaysNotTakenPredictor : public BranchPredictor {
public:
/** Generate a branch prediction for the specified instruction address; will
* always predict not taken. */
BranchPrediction predict(uint64_t address, BranchType type,
int64_t knownOffset) override;

/** Provide branch results to update the prediction model for the specified
* instruction address. As this model is static, this does nothing. */
void update(uint64_t address, bool taken, uint64_t targetAddress,
BranchType type) override;
/** Updates appropriate predictor model objects based on the address, type and
* outcome of the branch instruction. Update must be called on
* branches in program order. To check this, instructionId is also passed
* to this function. */
void update(uint64_t address, bool isTaken, uint64_t targetAddress,
BranchType type, uint64_t instructionId) override;

/** Provide flush logic for branch prediction scheme. As there's no flush
* logic for an always taken predictor, this does nothing. */
void flush(uint64_t address) override;

private:
};

} // namespace simeng
37 changes: 37 additions & 0 deletions src/include/simeng/branchpredictors/BranchPrediction.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once

#include <cstdint>

namespace simeng {

/** The types of branches recognised. */
enum class BranchType {
Conditional = 0,
LoopClosing,
Return,
SubroutineCall,
Unconditional,
Unknown
};

/** A branch result prediction for an instruction. */
struct BranchPrediction {
/** Whether the branch will be taken. */
bool isTaken;

/** The branch instruction's target address. If `isTaken == false`, the value
* will be ignored. */
uint64_t target;

/** Check for equality of two branch predictions . */
bool operator==(const BranchPrediction& other) {
return ((isTaken == other.isTaken) && (target == other.target));
}

/** Check for inequality of two branch predictions . */
bool operator!=(const BranchPrediction& other) {
return ((isTaken != other.isTaken) || (target != other.target));
}
};

} // namespace simeng
Loading