Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class local_update : public branch_update
- {
- public:
- unsigned int index;
- };
- class local_predictor : public branch_predictor
- {
- public:
- #define HISTORY_LENGTH 15
- #define TABLE_BITS 15
- branch_info bi;
- unsigned int history;
- unsigned char tab[1<<TABLE_BITS];
- local_update u;
- local_predictor (void) : history(0)
- {
- memset (tab, 0, sizeof (tab));
- }
- branch_update *predict (branch_info & b)
- {
- bi = b;
- if (b.br_flags & BR_CONDITIONAL)
- {
- u.index = (history << (TABLE_BITS - HISTORY_LENGTH)) ^ (b.address & ((1<<TABLE_BITS)-1));
- u.direction_prediction (tab[u.index] >> 1);
- }
- else
- {
- u.direction_prediction (true);
- }
- u.target_prediction (0);
- return &u;
- }
- void update (branch_update *u, bool taken, unsigned int target)
- {
- if (bi.br_flags & BR_CONDITIONAL)
- {
- unsigned char *c = &tab[((local_update*)u)->index];
- if (taken)
- {
- if (*c < 3)
- (*c)++;
- }
- else
- {
- if (*c > 0)
- (*c)--;
- }
- history <<= 1; //Bit shift _history_ to the left one to make room for the new result
- history |= taken; //Put the result (1 or 0) in the least significant bit of history (right bit)
- history &= (1<<HISTORY_LENGTH)-1;
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement