51#ifndef __CPU_PRED_MULTIPERSPECTIVE_PERCEPTRON_HH__
52#define __CPU_PRED_MULTIPERSPECTIVE_PERCEPTRON_HH__
58#include "params/MultiperspectivePerceptron.hh"
63namespace branch_prediction
75 const unsigned int pc;
77 const unsigned short int pc2;
79 const unsigned short int hpc;
86 static inline unsigned int hash1(
unsigned int a)
88 a = (
a ^ 0xdeadbeef) + (
a<<4);
95 static inline unsigned int hash2(
unsigned int key)
98 key = (key ^ 61) ^ (key >> 16);
99 key = key + (key << 3);
100 key = key ^ (key >> 4);
102 key = key ^ (key >> 15);
106 static inline unsigned int hash(
unsigned int key,
unsigned int i)
151 return last_ghist_bit ^
hpc;
312 ThreadData(
int num_filter,
int n_local_histories,
313 int local_history_length,
int assoc,
358 for (j =
i; j >= 1; j -= 1) {
426 for (
int i = 0;
i <
v.size();
i += 1) {
444 void computeBits(
int num_filter_entries,
int nlocal_histories,
445 int local_history_length,
bool ignore_path_size);
496 void satIncDec(
bool taken,
bool &sign,
int &
c,
int max_weight)
const;
501 specs.push_back(spec);
522 int block_size,
int start_pos,
int end_pos)
529 int am = (((
a/block_size)*block_size)+block_size);
531 int bm = (
b/block_size)*block_size;
539 x += ghist_words[
a / block_size] >> (
a-
am);
541 for (
int i=
am;
i<bm;
i+=block_size) {
542 x += ghist_words[
i / block_size];
546 unsigned int y = ghist_words[bm / block_size] & ((1<<(
b - bm))-1);
547 x += y << (block_size - (
b - bm));
580 for (
int i = 0;
i <
a + 2;
i += 1) {
581 x ^= acyclic_histories[
a][
i] <<
k;
586 for (
int i = 0;
i <
a + 2;
i += 1) {
588 x += acyclic2_histories[
a][
i];
601 for (
int j = 0; j <
p1 + 2; j += 1) {
623 unsigned int x = 0,
k = 0;
624 for (
int i = 0;
i <
b;
i += 1) {
625 x ^= mod_histories[
a][
i] <<
k;
672 for (
int i = 0;
i < depth;
i += 1) {
674 x += recency_stack[
i];
678 unsigned int x = 0,
k = 0;
679 for (
int i = 0;
i < depth;
i += 1) {
680 x ^= (!!(recency_stack[
i] & (1 <<
shift))) <<
k;
737 for (
int i = 0;
i < depth;
i += 1) {
739 x += path_history[
i];
747 x ^= (!!(path_history[
i + j] & (1 <<
shift))) << j;
751 for (
int i = bm;
i < depth;
i += 1) {
752 x ^= (!!(path_history[
i] & (1 <<
shift))) <<
k++;
778 x &= ((1 <<
p1) - 1);
804 for (
int i=0;
i<depth;
i += 1) {
843 x += (path_history[
i + j] << 1) | (
w & 1);
848 for (
int i = bm;
i < depth;
i += 1) {
850 x += (path_history[
i] << 1) | (
w & 1);
861 x ^= (!!(path_history[
i + j] & (1 <<
shift))) << j;
868 for (
int i = bm;
i < depth;
i += 1) {
869 x ^= (!!(path_history[
i] & (1 <<
shift))) <<
k;
909 for (
int i = 0;
i < depth;
i += 1) {
911 x += (modpath_histories[
a][
i] << 1) | mod_histories[
a][
i];
937 if (shiftdelta == -1) shiftdelta = 0;
938 int sdint = shiftdelta >> 2;
939 int sdfrac = shiftdelta & 3;
943 for (
int i = 0;
i < depth;
i += 1) {
947 if (
count == sdfrac) {
963 for (
int j = 0; j <
p2; j += 1) {
991 for (
int i = 0;
i <
l;
i += 1) {
992 if (recency_stack[
i] ==
pc) {
1037 x += (path_history[
i+j] << 1) | (
w & 1);
1042 for (
int i = bm;
i <
b;
i += 1) {
1044 x += (path_history[
i] << 1) | (
w & 1);
1061 void init()
override;
1066 Addr target,
void * &bp_history)
override;
1068 void * &bp_history,
bool squashed,
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
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.
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 - Pranith Kumar Copyright (c) 2020 Inria 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
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)
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