51#ifndef __CPU_PRED_MULTIPERSPECTIVE_PERCEPTRON_HH__
52#define __CPU_PRED_MULTIPERSPECTIVE_PERCEPTRON_HH__
59#include "params/MultiperspectivePerceptron.hh"
64namespace branch_prediction
76 const unsigned int pc;
78 const unsigned short int pc2;
80 const unsigned short int hpc;
87 static inline unsigned int hash1(
unsigned int a)
89 a = (
a ^ 0xdeadbeef) + (
a<<4);
87 static inline unsigned int hash1(
unsigned int a) {
…}
96 static inline unsigned int hash2(
unsigned int key)
99 key = (key ^ 61) ^ (key >> 16);
100 key = key + (key << 3);
101 key = key ^ (key >> 4);
103 key = key ^ (key >> 15);
96 static inline unsigned int hash2(
unsigned int key) {
…}
107 static inline unsigned int hash(
unsigned int key,
unsigned int i)
107 static inline unsigned int hash(
unsigned int key,
unsigned int i) {
…}
152 return last_ghist_bit ^
hpc;
315 ThreadData(
int num_filter,
int n_local_histories,
316 int local_history_length,
int assoc,
361 for (j =
i; j >= 1; j -= 1) {
429 for (
int i = 0;
i <
v.size();
i += 1) {
447 void computeBits(
int num_filter_entries,
int nlocal_histories,
448 int local_history_length,
bool ignore_path_size);
499 void satIncDec(
bool taken,
bool &sign,
int &
c,
int max_weight)
const;
504 specs.push_back(spec);
525 int block_size,
int start_pos,
int end_pos)
532 int am = (((
a/block_size)*block_size)+block_size);
534 int bm = (
b/block_size)*block_size;
542 x += ghist_words[
a / block_size] >> (
a-
am);
544 for (
int i=
am;
i<bm;
i+=block_size) {
545 x += ghist_words[
i / block_size];
549 unsigned int y = ghist_words[bm / block_size] & ((1<<(
b - bm))-1);
550 x += y << (block_size - (
b - bm));
583 for (
int i = 0;
i <
a + 2;
i += 1) {
584 x ^= acyclic_histories[
a][
i] <<
k;
589 for (
int i = 0;
i <
a + 2;
i += 1) {
591 x += acyclic2_histories[
a][
i];
604 for (
int j = 0; j <
p1 + 2; j += 1) {
626 unsigned int x = 0,
k = 0;
627 for (
int i = 0;
i <
b;
i += 1) {
628 x ^= mod_histories[
a][
i] <<
k;
675 for (
int i = 0;
i < depth;
i += 1) {
677 x += recency_stack[
i];
681 unsigned int x = 0,
k = 0;
682 for (
int i = 0;
i < depth;
i += 1) {
683 x ^= (!!(recency_stack[
i] & (1 <<
shift))) <<
k;
740 for (
int i = 0;
i < depth;
i += 1) {
742 x += path_history[
i];
750 x ^= (!!(path_history[
i + j] & (1 <<
shift))) << j;
754 for (
int i = bm;
i < depth;
i += 1) {
755 x ^= (!!(path_history[
i] & (1 <<
shift))) <<
k++;
781 x &= ((1 <<
p1) - 1);
807 for (
int i=0;
i<depth;
i += 1) {
846 x += (path_history[
i + j] << 1) | (
w & 1);
851 for (
int i = bm;
i < depth;
i += 1) {
853 x += (path_history[
i] << 1) | (
w & 1);
864 x ^= (!!(path_history[
i + j] & (1 <<
shift))) << j;
871 for (
int i = bm;
i < depth;
i += 1) {
872 x ^= (!!(path_history[
i] & (1 <<
shift))) <<
k;
912 for (
int i = 0;
i < depth;
i += 1) {
914 x += (modpath_histories[
a][
i] << 1) | mod_histories[
a][
i];
940 if (shiftdelta == -1) shiftdelta = 0;
941 int sdint = shiftdelta >> 2;
942 int sdfrac = shiftdelta & 3;
946 for (
int i = 0;
i < depth;
i += 1) {
950 if (
count == sdfrac) {
966 for (
int j = 0; j <
p2; j += 1) {
994 for (
int i = 0;
i <
l;
i += 1) {
995 if (recency_stack[
i] ==
pc) {
1040 x += (path_history[
i+j] << 1) | (
w & 1);
1045 for (
int i = bm;
i <
b;
i += 1) {
1047 x += (path_history[
i] << 1) | (
w & 1);
1064 void init()
override;
1069 Addr target,
void * &bp_history)
override;
1071 void * &bp_history,
bool squashed,
std::shared_ptr< Random > RandomPtr
static RandomPtr genRandom()
Basically a wrapper class to hold both the branch predictor and the BTB.
void setBitRequirements() const override
Sets the size requirements of the table, used when initializing to set the proper size of the tables.
ACYCLIC(int p1, int p2, int p3, double coeff, int size, int width, MultiperspectivePerceptron &mpp)
unsigned int getHash(ThreadID tid, Addr pc, Addr pc2, int t) const override
Gets the hash to index the table, using the pc of the branch, and the index of the table.
unsigned int getHash(ThreadID tid, Addr pc, Addr pc2, int t) const override
Gets the hash to index the table, using the pc of the branch, and the index of the table.
BIAS(double coeff, int size, int width, MultiperspectivePerceptron &mpp)
BLURRYPATH(int p1, int p2, int p3, double coeff, int size, int width, MultiperspectivePerceptron &mpp)
void setBitRequirements() const override
Sets the size requirements of the table, used when initializing to set the proper size of the tables.
unsigned int getHash(ThreadID tid, Addr pc, Addr pc2, int t) const override
Gets the hash to index the table, using the pc of the branch, and the index of the table.
void setBitRequirements() const override
Sets the size requirements of the table, used when initializing to set the proper size of the tables.
unsigned int getHash(ThreadID tid, Addr pc, Addr pc2, int t) const override
Gets the hash to index the table, using the pc of the branch, and the index of the table.
GHISTMODPATH(int p1, int p2, int p3, double coeff, int size, int width, MultiperspectivePerceptron &mpp)
unsigned int getHash(ThreadID tid, Addr pc, Addr pc2, int t) const override
Gets the hash to index the table, using the pc of the branch, and the index of the table.
void setBitRequirements() const override
Sets the size requirements of the table, used when initializing to set the proper size of the tables.
GHISTPATH(int p1, int p2, int p3, double coeff, int size, int width, MultiperspectivePerceptron &mpp)
void setBitRequirements() const override
Sets the size requirements of the table, used when initializing to set the proper size of the tables.
unsigned int getHash(ThreadID tid, Addr pc, Addr pc2, int t) const override
Gets the hash to index the table, using the pc of the branch, and the index of the table.
static unsigned int hash(const std::vector< unsigned int > &ghist_words, int block_size, int start_pos, int end_pos)
GHIST(int p1, int p2, double coeff, int size, int width, MultiperspectivePerceptron &mpp)
void setBitRequirements() const override
Sets the size requirements of the table, used when initializing to set the proper size of the tables.
IMLI(int p1, double coeff, int size, int width, MultiperspectivePerceptron &mpp)
unsigned int getHash(ThreadID tid, Addr pc, Addr pc2, int t) const override
Gets the hash to index the table, using the pc of the branch, and the index of the table.
LOCAL(int p1, double coeff, int size, int width, MultiperspectivePerceptron &mpp)
unsigned int getHash(ThreadID tid, Addr pc, Addr pc2, int t) const override
Gets the hash to index the table, using the pc of the branch, and the index of the table.
void setBitRequirements() const override
Sets the size requirements of the table, used when initializing to set the proper size of the tables.
Local history entries, each enty contains the history of directions taken by a given branch.
std::vector< unsigned int > localHistories
The array of histories.
int getSize() const
Size in bits required by all history entries.
unsigned int operator[](Addr pc) const
Obtains the local history entry of a given branch.
void update(Addr pc, bool value)
Adds a history bit to the local history entry of a given branch.
int getLocalHistoryLength() const
Returns the number of bits of each local history entry.
const int localHistoryLength
Size in bits of each history entry.
unsigned int index(Addr pc) const
Index function given the pc of the branch.
LocalHistories(int nlocal_histories, int histo_len)
MODHIST(int p1, int p2, double coeff, int size, int width, MultiperspectivePerceptron &mpp)
void setBitRequirements() const override
Sets the size requirements of the table, used when initializing to set the proper size of the tables.
unsigned int getHash(ThreadID tid, Addr pc, Addr pc2, int t) const override
Gets the hash to index the table, using the pc of the branch, and the index of the table.
MODPATH(int p1, int p2, int p3, double coeff, int size, int width, MultiperspectivePerceptron &mpp)
void setBitRequirements() const override
Sets the size requirements of the table, used when initializing to set the proper size of the tables.
unsigned int getHash(ThreadID tid, Addr pc, Addr pc2, int t) const override
Gets the hash to index the table, using the pc of the branch, and the index of the table.
bool isUnconditional() const
unsigned int getPC() const
bool prediction
Result of the prediction (true is taken)
MPPBranchInfo(Addr _pc, int pcshift, bool cb)
unsigned short int getPC2() const
const bool condBranch
Whether this is a conditional branch.
static unsigned int hash2(unsigned int key)
unsigned short int getHPC() const
int yout
Score of the perceptron.
bool filtered
Whether this branch has been filtered by the prefetcher.
static unsigned int hash1(unsigned int a)
PC Hash functions.
static unsigned int hashPC(unsigned int pc, int pcshift)
unsigned int getHashFilter(bool last_ghist_bit) const
const unsigned short int pc2
pc of the branch, shifted 2 bits to the right
const unsigned int pc
pc of the branch
const unsigned short int hpc
pc of the branch, hashed
static unsigned int hash(unsigned int key, unsigned int i)
unsigned int getHash(ThreadID tid, Addr pc, Addr pc2, int t) const override
Gets the hash to index the table, using the pc of the branch, and the index of the table.
PATH(int p1, int p2, int p3, double coeff, int size, int width, MultiperspectivePerceptron &mpp)
void setBitRequirements() const override
Sets the size requirements of the table, used when initializing to set the proper size of the tables.
void setBitRequirements() const override
Sets the size requirements of the table, used when initializing to set the proper size of the tables.
static unsigned int hash(const std::vector< unsigned int short > &recency_stack, const std::vector< int > &table_sizes, unsigned short int pc, int l, int t)
unsigned int getHash(ThreadID tid, Addr pc, Addr pc2, int t) const override
Gets the hash to index the table, using the pc of the branch, and the index of the table.
RECENCYPOS(int p1, double coeff, int size, int width, MultiperspectivePerceptron &mpp)
unsigned int getHash(ThreadID tid, Addr pc, Addr pc2, int t) const override
Gets the hash to index the table, using the pc of the branch, and the index of the table.
void setBitRequirements() const override
Sets the size requirements of the table, used when initializing to set the proper size of the tables.
RECENCY(int p1, int p2, int p3, double coeff, int size, int width, MultiperspectivePerceptron &mpp)
SGHISTPATH(int p1, int p2, int p3, double coeff, int size, int width, MultiperspectivePerceptron &mpp)
unsigned int getHash(ThreadID tid, Addr pc, Addr pc2, int t) const override
Gets the hash to index the table, using the pc of the branch, and the index of the table.
void insertModhistSpec(int p1, int p2)
Auxiliary function for MODHIST and GHISTMODPATH features.
std::vector< ThreadData * > threadData
std::vector< int > imli_counter_bits
void insertModpathSpec(int p1, int p2)
Auxiliary function for MODPATH and GHISTMODPATH features.
const unsigned long long int imli_mask4
std::vector< std::vector< std::vector< bool > > > acyclic_bits
int computeOutput(ThreadID tid, MPPBranchInfo &bi)
Computes the output of the predictor for a given branch and the resulting best value in case the pred...
const unsigned int record_mask
void addSpec(HistorySpec *spec)
Add a table spec to the prefetcher.
std::vector< int > modpath_lengths
std::vector< std::vector< int > > blurrypath_bits
int insert(std::vector< int > &v, int x)
Auxiliary function used by insertModhistSpec and insertModpathSpec.
const bool speculative_update
void findBest(ThreadID tid, std::vector< int > &best_preds) const
Finds the best subset of features to use in case of a low-confidence branch, returns the result as an...
const int blockSize
Predictor parameters.
static int xlat[]
Transfer function for 6-width tables.
bool doing_local
runtime values and data used to count the size in bits
unsigned int getIndex(ThreadID tid, const MPPBranchInfo &bi, const HistorySpec &spec, int index) const
Get the position index of a predictor table.
std::vector< int > modhist_indices
virtual void createSpecs()=0
Creates the tables of the predictor.
void satIncDec(bool taken, bool &sign, int &c, int max_weight) const
Auxiliary function to increase a table counter depending on the direction of the branch.
bool lookup(ThreadID tid, Addr branch_addr, void *&bp_history) override
Looks up a given conditional branch PC of in the BP to see if it is taken or not taken.
std::vector< int > modhist_lengths
void computeBits(int num_filter_entries, int nlocal_histories, int local_history_length, bool ignore_path_size)
Computes the size in bits of the structures needed to keep track of the history and the predictor tab...
static int xlat4[]
Transfer function for 5-width tables.
std::vector< int > table_sizes
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
void update(ThreadID tid, Addr pc, bool taken, void *&bp_history, bool squashed, const StaticInstPtr &inst, Addr target) override
Updates the BP with taken/not taken information.
void train(ThreadID tid, MPPBranchInfo &bi, bool taken)
Trains the branch predictor with the given branch and direction.
void setExtraBits(int bits)
Sets the starting number of storage bits to compute the number of table entries.
std::vector< HistorySpec * > specs
Predictor tables.
std::vector< int > modpath_indices
const unsigned long long int recencypos_mask
void updateHistories(ThreadID tid, Addr pc, bool uncond, bool taken, Addr target, void *&bp_history) override
Ones done with the prediction this function updates the path and global history.
const unsigned long long int imli_mask1
void squash(ThreadID tid, void *&bp_history) override
constexpr T bits(T val, unsigned first, unsigned last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it.
const Params & params() const
Copyright (c) 2024 Arm Limited All rights reserved.
int16_t ThreadID
Thread index/ID type.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Entry of the branch filter.
bool seenTaken
Has this branch been taken at least once?
bool alwaysTakenSoFar() const
Whether this branch has always been observed as taken.
bool neverSeen() const
Whether this branch has been observed before.
bool seenUntaken
Has this branch been not taken at least once?
bool alwaysNotTakenSoFar() const
Whether this branch has always been observed as not taken.
Base class to implement the predictor tables.
const int size
Pre-assigned size in bits assigned to this feature.
virtual unsigned int getHash(ThreadID tid, Addr pc, Addr pc2, int t) const =0
Gets the hash to index the table, using the pc of the branch, and the index of the table.
const int p1
First parameter.
const int p2
Second parameter.
MultiperspectivePerceptron & mpp
Reference to the branch predictor class.
const int width
Width of the table in bits
const int p3
Third parameter.
virtual void setBitRequirements() const
Sets the size requirements of the table, used when initializing to set the proper size of the tables.
HistorySpec(int _p1, int _p2, int _p3, double _coeff, int _size, int _width, MultiperspectivePerceptron &_mpp)
const double coeff
Coefficient of the feature, models the accuracy of the feature.
History data is kept for each thread.
std::vector< unsigned int > ghist_words
std::vector< std::vector< unsigned int > > acyclic2_histories
std::vector< std::vector< short int > > tables
std::vector< std::vector< unsigned int > > blurrypath_histories
void insertRecency(unsigned int pc, int assoc)
std::vector< unsigned int > imli_counter
std::vector< FilterEntry > filterTable
std::vector< std::vector< std::array< bool, 2 > > > sign_bits
std::vector< std::vector< bool > > mod_histories
void updateAcyclic(bool hashed_taken, unsigned int hpc)
std::vector< std::vector< bool > > acyclic_histories
std::vector< int > mpreds
std::vector< unsigned short int > path_history
LocalHistories localHistories
std::vector< std::vector< unsigned short int > > modpath_histories
std::vector< unsigned int short > recency_stack