errant

Minimal Branch Predictor

Apr 17th, 2012
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. class local_update : public branch_update
  2. {
  3. public:
  4.         unsigned int counter;
  5. };
  6.  
  7. class local_predictor : public branch_predictor
  8. {
  9. public:
  10.         local_update u;
  11.         branch_info binfo;
  12.        
  13.  
  14.         local_predictor (void)
  15.         {
  16.        
  17.         }
  18.  
  19.         branch_update *predict (branch_info & b)
  20.         {
  21.             binfo = b;
  22.             if (b.br_flags & BR_CONDITIONAL)
  23.             {              
  24.                 u.direction_prediction ((u.counter) >> 1);     
  25.             }
  26.             else u.direction_prediction(true);         
  27.             u.target_prediction (0);
  28.             return &u;
  29.         }
  30.  
  31.         void update (branch_update *u, bool taken, unsigned int target)
  32.         {
  33.  
  34.             unsigned int *c = &((local_update*)u)->counter;
  35.             if (binfo.br_flags & BR_CONDITIONAL)
  36.             {
  37.  
  38.                 if (taken)
  39.                 {
  40.                     if (*c < 3)
  41.                         (*c)++;
  42.                 }
  43.                 else
  44.                 {
  45.                     if (*c > 0)
  46.                         (*c)--;
  47.                 }
  48.             }
  49.         }
  50.  
  51. };
Advertisement
Add Comment
Please, Sign In to add comment