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"
56 const unsigned int pc;
58 const unsigned short int pc2;
60 const unsigned short int hpc;
67 static inline unsigned int hash1(
unsigned int a)
69 a = (
a ^ 0xdeadbeef) + (
a<<4);
76 static inline unsigned int hash2(
unsigned int key)
79 key = (key ^ 61) ^ (key >> 16);
80 key = key + (key << 3);
81 key = key ^ (key >> 4);
83 key = key ^ (key >> 15);
87 static inline unsigned int hash(
unsigned int key,
unsigned int i)
132 return last_ghist_bit ^
hpc;
289 ThreadData(
int num_filter,
int n_local_histories,
290 int local_history_length,
int assoc,
335 for (
j =
i;
j >= 1;
j -= 1) {
403 for (
int i = 0;
i <
v.size();
i += 1) {
421 void computeBits(
int num_filter_entries,
int nlocal_histories,
422 int local_history_length,
bool ignore_path_size);
438 const HistorySpec &spec,
int index)
const;
473 void satIncDec(
bool taken,
bool &sign,
int &
c,
int max_weight)
const;
478 specs.push_back(spec);
498 int block_size,
int start_pos,
int end_pos)
505 int am = (((
a/block_size)*block_size)+block_size);
507 int bm = (
b/block_size)*block_size;
515 x += ghist_words[
a / block_size] >> (
a-
am);
517 for (
int i=
am;
i<bm;
i+=block_size) {
518 x += ghist_words[
i / block_size];
522 unsigned int y = ghist_words[bm / block_size] & ((1<<(
b - bm))-1);
523 x += y << (block_size - (
b - bm));
555 for (
int i = 0;
i <
a + 2;
i += 1) {
556 x ^= acyclic_histories[
a][
i] <<
k;
561 for (
int i = 0;
i <
a + 2;
i += 1) {
563 x += acyclic2_histories[
a][
i];
576 for (
int j = 0;
j <
p1 + 2;
j += 1) {
597 unsigned int x = 0,
k = 0;
598 for (
int i = 0;
i <
b;
i += 1) {
599 x ^= mod_histories[
a][
i] <<
k;
644 for (
int i = 0;
i < depth;
i += 1) {
646 x += recency_stack[
i];
650 unsigned int x = 0,
k = 0;
651 for (
int i = 0;
i < depth;
i += 1) {
652 x ^= (!!(recency_stack[
i] & (1 <<
shift))) <<
k;
707 for (
int i = 0;
i < depth;
i += 1) {
709 x += path_history[
i];
717 x ^= (!!(path_history[
i +
j] & (1 <<
shift))) <<
j;
721 for (
int i = bm;
i < depth;
i += 1) {
722 x ^= (!!(path_history[
i] & (1 <<
shift))) <<
k++;
747 x &= ((1 <<
p1) - 1);
772 for (
int i=0;
i<depth;
i += 1) {
810 x += (path_history[
i +
j] << 1) | (
w & 1);
815 for (
int i = bm;
i < depth;
i += 1) {
817 x += (path_history[
i] << 1) | (
w & 1);
828 x ^= (!!(path_history[
i +
j] & (1 <<
shift))) <<
j;
835 for (
int i = bm;
i < depth;
i += 1) {
836 x ^= (!!(path_history[
i] & (1 <<
shift))) <<
k;
875 for (
int i = 0;
i < depth;
i += 1) {
877 x += (modpath_histories[
a][
i] << 1) | mod_histories[
a][
i];
902 if (shiftdelta == -1) shiftdelta = 0;
903 int sdint = shiftdelta >> 2;
904 int sdfrac = shiftdelta & 3;
908 for (
int i = 0;
i < depth;
i += 1) {
912 if (
count == sdfrac) {
928 for (
int j = 0;
j <
p2;
j += 1) {
955 for (
int i = 0;
i <
l;
i += 1) {
956 if (recency_stack[
i] ==
pc) {
1000 x += (path_history[
i+
j] << 1) | (
w & 1);
1005 for (
int i = bm;
i <
b;
i += 1) {
1007 x += (path_history[
i] << 1) | (
w & 1);
1024 void init()
override;
1030 void *bp_history,
bool squashed,
1032 Addr corrTarget)
override;
1035 #endif//__CPU_PRED_MULTIPERSPECTIVE_PERCEPTRON_HH__
LocalHistories(int nlocal_histories, int histo_len)
MultiperspectivePerceptron & mpp
Reference to the branch predictor class.
const int p2
Second parameter.
const unsigned long long int imli_mask1
static int xlat[]
Transfer function for 6-width tables.
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.
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< std::vector< bool > > > acyclic_bits
int getSize() const
Size in bits required by all history entries.
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)
bool neverSeen() const
Whether this branch has been observed before.
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.
const double coeff
Coefficient of the feature, models the accuracy of the feature.
static unsigned int hash(const std::vector< unsigned int > &ghist_words, int block_size, int start_pos, int end_pos)
std::vector< std::vector< unsigned int > > blurrypath_histories
LocalHistories localHistories
MODPATH(int p1, int p2, int p3, double coeff, int size, int width, MultiperspectivePerceptron &mpp)
const int p3
Third parameter.
void addSpec(HistorySpec *spec)
Add a table spec to the prefetcher.
std::vector< unsigned int > imli_counter
int16_t ThreadID
Thread index/ID type.
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.
std::vector< std::vector< unsigned int > > acyclic2_histories
void setBitRequirements() const override
Sets the size requirements of the table, used when initializing to set the proper size of the tables.
const int localHistoryLength
Size in bits of each history entry.
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.
bool doing_local
runtime values and data used to count the size in bits
void setBitRequirements() const override
Sets the size requirements of the table, used when initializing to set the proper size of the tables.
std::vector< int > modpath_indices
std::vector< unsigned int > ghist_words
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.
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...
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 > imli_counter_bits
std::vector< HistorySpec * > specs
Predictor tables.
void insertModpathSpec(int p1, int p2)
Auxiliary function for MODPATH and GHISTMODPATH features.
std::vector< std::vector< bool > > acyclic_histories
const bool speculative_update
std::vector< FilterEntry > filterTable
void update(Addr pc, bool value)
Adds a history bit to the local history entry of a given branch.
bool alwaysTakenSoFar() const
Whether this branch has always been observed as taken.
std::vector< int > modhist_lengths
static unsigned int hash(unsigned int key, unsigned int i)
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
std::vector< unsigned int > localHistories
The array of histories.
unsigned int index(Addr pc) const
Index function given the pc of the branch.
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.
Local history entries, each enty contains the history of directions taken by a given branch.
unsigned int getHashFilter(bool last_ghist_bit) const
bool isUnconditional() const
GHIST(int p1, int p2, double coeff, int size, int width, MultiperspectivePerceptron &mpp)
void insertModhistSpec(int p1, int p2)
Auxiliary function for MODHIST and GHISTMODPATH features.
const int blockSize
Predictor parameters.
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 train(ThreadID tid, MPPBranchInfo &bi, bool taken)
Trains the branch predictor with the given branch and direction.
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.
BIAS(double coeff, int size, int width, MultiperspectivePerceptron &mpp)
void setExtraBits(int bits)
Sets the starting number of storage bits to compute the number of table entries.
std::vector< std::vector< short int > > tables
RECENCYPOS(int p1, double coeff, int size, int width, MultiperspectivePerceptron &mpp)
MODHIST(int p1, int p2, double coeff, int size, int width, MultiperspectivePerceptron &mpp)
virtual void createSpecs()=0
Creates the tables of the predictor.
std::vector< std::vector< bool > > mod_histories
MPPBranchInfo(Addr _pc, int pcshift, bool cb)
static unsigned int hashPC(unsigned int pc, int pcshift)
bool seenTaken
Has this branch been taken at least once?
Basically a wrapper class to hold both the branch predictor and the BTB.
unsigned int operator[](Addr pc) const
Obtains the local history entry of a given branch.
std::vector< int > modhist_indices
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 squash(ThreadID tid, void *bp_history) override
bool filtered
Whether this branch has been filtered by the prefetcher.
unsigned short int getHPC() const
std::vector< std::vector< std::array< bool, 2 > > > sign_bits
std::vector< ThreadData * > threadData
LOCAL(int p1, 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.
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...
std::vector< int > modpath_lengths
Base class to implement the predictor tables.
unsigned short int getPC2() const
bool seenUntaken
Has this branch been not taken at least once?
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.
HistorySpec(int _p1, int _p2, int _p3, double _coeff, int _size, int _width, MultiperspectivePerceptron &_mpp)
const Params * params() const
int yout
Score of the perceptron.
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.
void setBitRequirements() const override
Sets the size requirements of the table, used when initializing to set the proper size of the tables.
const unsigned short int hpc
pc of the branch, hashed
int getLocalHistoryLength() const
Returns the number of bits of each local history entry.
const int size
Pre-assigned size in bits assigned to this feature.
const unsigned short int pc2
pc of the branch, shifted 2 bits to the right
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 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.
IMLI(int p1, double coeff, int size, int width, MultiperspectivePerceptron &mpp)
PATH(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 getIndex(ThreadID tid, const MPPBranchInfo &bi, const HistorySpec &spec, int index) const
Get the position index of a predictor table.
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)
const unsigned int pc
pc of the branch
unsigned int getPC() const
const int p1
First parameter.
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 recencypos_mask
const int width
Width of the table in bits
const unsigned long long int imli_mask4
std::vector< unsigned int short > recency_stack
static int xlat4[]
Transfer function for 5-width tables.
static unsigned int hash2(unsigned int key)
void uncondBranch(ThreadID tid, Addr pc, void *&bp_history) override
SGHISTPATH(int p1, int p2, int p3, double coeff, int size, int width, MultiperspectivePerceptron &mpp)
bool prediction
Result of the prediction (true is taken)
virtual void setBitRequirements() const
Sets the size requirements of the table, used when initializing to set the proper size of the tables.
const unsigned int record_mask
const bool condBranch
Whether this is a conditional branch.
int insert(std::vector< int > &v, int x)
Auxiliary function used by insertModhistSpec and insertModpathSpec.
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.
std::vector< int > table_sizes
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)
std::vector< std::vector< unsigned short int > > modpath_histories
Entry of the branch filter.
std::vector< int > mpreds
static unsigned int hash1(unsigned int a)
PC Hash functions.
std::vector< unsigned short int > path_history
bool alwaysNotTakenSoFar() const
Whether this branch has always been observed as not taken.
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< std::vector< int > > blurrypath_bits
History data is kept for each thread.
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...
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...
void setBitRequirements() const override
Sets the size requirements of the table, used when initializing to set the proper size of the tables.
void updateAcyclic(bool hashed_taken, unsigned int hpc)
MultiperspectivePerceptron(const MultiperspectivePerceptronParams *params)
T bits(T val, int first, int last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it.
Generated on Wed Sep 30 2020 14:02:09 for gem5 by doxygen 1.8.17