Go to the documentation of this file.
39 #ifndef __CPU_PRED_MULTIPERSPECTIVE_PERCEPTRON_HH__
40 #define __CPU_PRED_MULTIPERSPECTIVE_PERCEPTRON_HH__
46 #include "params/MultiperspectivePerceptron.hh"
51 namespace branch_prediction
63 const unsigned int pc;
65 const unsigned short int pc2;
67 const unsigned short int hpc;
74 static inline unsigned int hash1(
unsigned int a)
76 a = (
a ^ 0xdeadbeef) + (
a<<4);
83 static inline unsigned int hash2(
unsigned int key)
86 key = (key ^ 61) ^ (key >> 16);
87 key = key + (key << 3);
88 key = key ^ (key >> 4);
90 key = key ^ (key >> 15);
94 static inline unsigned int hash(
unsigned int key,
unsigned int i)
139 return last_ghist_bit ^
hpc;
300 ThreadData(
int num_filter,
int n_local_histories,
301 int local_history_length,
int assoc,
346 for (
j =
i;
j >= 1;
j -= 1) {
414 for (
int i = 0;
i <
v.size();
i += 1) {
432 void computeBits(
int num_filter_entries,
int nlocal_histories,
433 int local_history_length,
bool ignore_path_size);
449 const HistorySpec &spec,
int index)
const;
484 void satIncDec(
bool taken,
bool &sign,
int &
c,
int max_weight)
const;
489 specs.push_back(spec);
510 int block_size,
int start_pos,
int end_pos)
517 int am = (((
a/block_size)*block_size)+block_size);
519 int bm = (
b/block_size)*block_size;
527 x += ghist_words[
a / block_size] >> (
a-
am);
529 for (
int i=
am;
i<bm;
i+=block_size) {
530 x += ghist_words[
i / block_size];
534 unsigned int y = ghist_words[bm / block_size] & ((1<<(
b - bm))-1);
535 x += y << (block_size - (
b - bm));
568 for (
int i = 0;
i <
a + 2;
i += 1) {
569 x ^= acyclic_histories[
a][
i] <<
k;
574 for (
int i = 0;
i <
a + 2;
i += 1) {
576 x += acyclic2_histories[
a][
i];
589 for (
int j = 0;
j <
p1 + 2;
j += 1) {
611 unsigned int x = 0,
k = 0;
612 for (
int i = 0;
i <
b;
i += 1) {
613 x ^= mod_histories[
a][
i] <<
k;
660 for (
int i = 0;
i < depth;
i += 1) {
662 x += recency_stack[
i];
666 unsigned int x = 0,
k = 0;
667 for (
int i = 0;
i < depth;
i += 1) {
668 x ^= (!!(recency_stack[
i] & (1 <<
shift))) <<
k;
725 for (
int i = 0;
i < depth;
i += 1) {
727 x += path_history[
i];
735 x ^= (!!(path_history[
i +
j] & (1 <<
shift))) <<
j;
739 for (
int i = bm;
i < depth;
i += 1) {
740 x ^= (!!(path_history[
i] & (1 <<
shift))) <<
k++;
766 x &= ((1 <<
p1) - 1);
792 for (
int i=0;
i<depth;
i += 1) {
831 x += (path_history[
i +
j] << 1) | (
w & 1);
836 for (
int i = bm;
i < depth;
i += 1) {
838 x += (path_history[
i] << 1) | (
w & 1);
849 x ^= (!!(path_history[
i +
j] & (1 <<
shift))) <<
j;
856 for (
int i = bm;
i < depth;
i += 1) {
857 x ^= (!!(path_history[
i] & (1 <<
shift))) <<
k;
897 for (
int i = 0;
i < depth;
i += 1) {
899 x += (modpath_histories[
a][
i] << 1) | mod_histories[
a][
i];
925 if (shiftdelta == -1) shiftdelta = 0;
926 int sdint = shiftdelta >> 2;
927 int sdfrac = shiftdelta & 3;
931 for (
int i = 0;
i < depth;
i += 1) {
935 if (
count == sdfrac) {
951 for (
int j = 0;
j <
p2;
j += 1) {
979 for (
int i = 0;
i <
l;
i += 1) {
980 if (recency_stack[
i] ==
pc) {
1025 x += (path_history[
i+
j] << 1) | (
w & 1);
1030 for (
int i = bm;
i <
b;
i += 1) {
1032 x += (path_history[
i] << 1) | (
w & 1);
1049 void init()
override;
1055 void *bp_history,
bool squashed,
1057 Addr corrTarget)
override;
1064 #endif//__CPU_PRED_MULTIPERSPECTIVE_PERCEPTRON_HH__
BLURRYPATH(int p1, int p2, int p3, double coeff, int size, int width, MultiperspectivePerceptron &mpp)
void updateAcyclic(bool hashed_taken, unsigned int hpc)
std::vector< int > imli_counter_bits
std::vector< std::vector< unsigned int > > blurrypath_histories
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.
std::vector< int > modhist_indices
bool isUnconditional() const
MODPATH(int p1, int p2, int p3, double coeff, int size, int width, MultiperspectivePerceptron &mpp)
const unsigned short int hpc
pc of the branch, hashed
bool alwaysNotTakenSoFar() const
Whether this branch has always been observed as not taken.
bool neverSeen() const
Whether this branch has been observed before.
bool prediction
Result of the prediction (true is taken)
void setBitRequirements() const override
Sets the size requirements of the table, used when initializing to set the proper size of the tables.
const unsigned long long int imli_mask1
const int width
Width of the table in bits
void insertModhistSpec(int p1, int p2)
Auxiliary function for MODHIST and GHISTMODPATH features.
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.
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.
std::vector< int > modpath_lengths
void insertRecency(unsigned int pc, int assoc)
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.
std::vector< unsigned int > imli_counter
const unsigned long long int recencypos_mask
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.
const unsigned long long int imli_mask4
MODHIST(int p1, int p2, double coeff, int size, int width, MultiperspectivePerceptron &mpp)
std::vector< unsigned int > ghist_words
bool lookup(ThreadID tid, Addr instPC, void *&bp_history) override
Looks up a given PC in the BP to see if it is taken or not taken.
MultiperspectivePerceptron(const MultiperspectivePerceptronParams ¶ms)
unsigned int getIndex(ThreadID tid, const MPPBranchInfo &bi, const HistorySpec &spec, int index) const
Get the position index of a predictor table.
ACYCLIC(int p1, int p2, int p3, double coeff, int size, int width, MultiperspectivePerceptron &mpp)
RECENCYPOS(int p1, double coeff, int size, int width, MultiperspectivePerceptron &mpp)
void addSpec(HistorySpec *spec)
Add a table spec to the prefetcher.
MPPBranchInfo(Addr _pc, int pcshift, bool cb)
static unsigned int hash1(unsigned int a)
PC Hash functions.
void setBitRequirements() const override
Sets the size requirements of the table, used when initializing to set the proper size of the tables.
int insert(std::vector< int > &v, int x)
Auxiliary function used by insertModhistSpec and insertModpathSpec.
std::vector< std::vector< int > > blurrypath_bits
static unsigned int hash(unsigned int key, unsigned int i)
unsigned short int getPC2() const
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.
std::vector< unsigned int short > recency_stack
int yout
Score of the perceptron.
bool alwaysTakenSoFar() const
Whether this branch has always been observed as taken.
std::vector< FilterEntry > filterTable
bool filtered
Whether this branch has been filtered by the prefetcher.
void update(Addr pc, bool value)
Adds a history bit to the local history entry of a given branch.
MultiperspectivePerceptron & mpp
Reference to the branch predictor class.
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 insertModpathSpec(int p1, int p2)
Auxiliary function for MODPATH and GHISTMODPATH features.
std::vector< unsigned int > localHistories
The array of histories.
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...
unsigned int operator[](Addr pc) const
Obtains the local history entry of a given branch.
const unsigned int record_mask
const int p1
First parameter.
const Params & params() const
const int size
Pre-assigned size in bits assigned to this feature.
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...
RECENCY(int p1, int p2, int p3, double coeff, int size, int width, MultiperspectivePerceptron &mpp)
PATH(int p1, int p2, int p3, double coeff, int size, int width, MultiperspectivePerceptron &mpp)
std::vector< std::vector< std::array< bool, 2 > > > sign_bits
void setExtraBits(int bits)
Sets the starting number of storage bits to compute the number of table entries.
std::vector< HistorySpec * > specs
Predictor tables.
const int p2
Second parameter.
std::vector< int > modhist_lengths
void setBitRequirements() const override
Sets the size requirements of the table, used when initializing to set the proper size of the tables.
std::vector< std::vector< unsigned short int > > modpath_histories
std::vector< int > modpath_indices
void setBitRequirements() const override
Sets the size requirements of the table, used when initializing to set the proper size of the tables.
int getLocalHistoryLength() const
Returns the number of bits of each local history entry.
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 seenTaken
Has this branch been taken at least once?
ThreadData(int num_filter, int n_local_histories, int local_history_length, int assoc, const std::vector< std::vector< int >> &blurrypath_bits, int path_length, int ghist_length, int block_size, const std::vector< std::vector< std::vector< bool >>> &acyclic_bits, const std::vector< int > &modhist_indices, const std::vector< int > &modhist_lengths, const std::vector< int > &modpath_indices, const std::vector< int > &modpath_lengths, const std::vector< int > &table_sizes, int n_sign_bits)
const double coeff
Coefficient of the feature, models the accuracy of the feature.
bool doing_local
runtime values and data used to count the size in bits
GHISTPATH(int p1, int p2, int p3, double coeff, int size, int width, MultiperspectivePerceptron &mpp)
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 bool condBranch
Whether this is a conditional branch.
static unsigned int hash2(unsigned int key)
unsigned int getHashFilter(bool last_ghist_bit) const
void squash(ThreadID tid, void *bp_history) override
void setBitRequirements() const override
Sets the size requirements of the table, used when initializing to set the proper size of the tables.
const int blockSize
Predictor parameters.
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)
std::vector< int > table_sizes
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.
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.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
bool seenUntaken
Has this branch been not taken at least once?
std::vector< int > mpreds
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.
const unsigned short int pc2
pc of the branch, shifted 2 bits to the right
std::vector< std::vector< std::vector< bool > > > acyclic_bits
const bool speculative_update
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.
const unsigned int pc
pc of the branch
void train(ThreadID tid, MPPBranchInfo &bi, bool taken)
Trains the branch predictor with the given branch and direction.
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 update(ThreadID tid, Addr instPC, bool taken, void *bp_history, bool squashed, const StaticInstPtr &inst, Addr corrTarget) override
Updates the BP with taken/not taken information.
std::vector< std::vector< bool > > acyclic_histories
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.
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.
LocalHistories(int nlocal_histories, int histo_len)
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
std::vector< ThreadData * > threadData
Basically a wrapper class to hold both the branch predictor and the BTB.
static unsigned int hash(const std::vector< unsigned int > &ghist_words, int block_size, int start_pos, int end_pos)
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 unsigned int hashPC(unsigned int pc, int pcshift)
void setBitRequirements() const override
Sets the size requirements of the table, used when initializing to set the proper size of the tables.
void uncondBranch(ThreadID tid, Addr pc, void *&bp_history) override
void btbUpdate(ThreadID tid, Addr branch_addr, void *&bp_history) override
If a branch is not taken, because the BTB address is invalid or missing, this function sets the appro...
std::vector< std::vector< bool > > mod_histories
HistorySpec(int _p1, int _p2, int _p3, double _coeff, int _size, int _width, MultiperspectivePerceptron &_mpp)
const int p3
Third parameter.
std::vector< std::vector< unsigned int > > acyclic2_histories
virtual void createSpecs()=0
Creates the tables of the predictor.
int getSize() const
Size in bits required by all history entries.
const int localHistoryLength
Size in bits of each history entry.
static int xlat4[]
Transfer function for 5-width tables.
static int xlat[]
Transfer function for 6-width tables.
void setBitRequirements() const override
Sets the size requirements of the table, used when initializing to set the proper size of the tables.
SGHISTPATH(int p1, int p2, int p3, double coeff, int size, int width, MultiperspectivePerceptron &mpp)
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
void setBitRequirements() const override
Sets the size requirements of the table, used when initializing to set the proper size of the tables.
std::vector< std::vector< short int > > tables
unsigned int getPC() const
GHIST(int p1, int p2, double coeff, int size, int width, MultiperspectivePerceptron &mpp)
LocalHistories localHistories
History data is kept for each thread.
std::vector< unsigned short int > path_history
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.
Entry of the branch filter.
int16_t ThreadID
Thread index/ID type.
BIAS(double coeff, int size, int width, MultiperspectivePerceptron &mpp)
Base class to implement the predictor tables.
virtual void setBitRequirements() const
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.
unsigned int index(Addr pc) const
Index function given the pc of the branch.
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.
unsigned short int getHPC() const
Generated on Wed May 4 2022 12:13:54 for gem5 by doxygen 1.8.17