Main Page | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

branch.h

Go to the documentation of this file.
00001 /*
00002         Copyright (C) 1997 CFU Corporation
00003 
00004         File: branch.h
00005         Description: branch predictors
00006         Author: Chao-yinig Fu
00007         Date: Oct. 26, 2000
00008 
00009         ^..^
00010         (00)
00011 
00012          $__$
00013         <~00~>
00014          (oo)
00015           ||
00016 
00017         ```````
00018         C ^|^ D
00019          \ O /
00020 */
00021 
00022 #ifndef INCLUDED_BRANCH_H
00023 #define INCLUDED_BRANCH_H
00024 
00025 #include <stdio.h>
00026 #include <assert.h>
00027 
00028 /*
00029 class Virtual_Branch_Predictor
00030 {
00031 public:
00032         Virtual_Branch_Predictor() {}
00033         ~Virtual_Branch_Predictor() {}
00034 
00035         virtual void show(FILE *f);
00036         virtual void predict(int bhr,int ip,int &direction);
00037         virtual void update(int bhr,int ip,int actual_slot_taken);
00038 
00039 private:
00040 };
00041 */
00042 
00043 class Branch_Predictor
00044 {
00045 public:
00046         Branch_Predictor():_tag(NULL),_counter(NULL) {}
00047 
00048         // b => block size
00049         // m => total number of bits to index the prediction table
00050         // s => issue_width
00051         // l => low order bit of branch
00052         Branch_Predictor(int b, int m,int s,int l):_b(b),_m(m),_num_of_slot(s+1),_l(l)
00053         {
00054                 _num_of_entry=1<<_m;
00055 
00056                 _tag=new int[_num_of_entry];
00057                 _counter=new int[_num_of_entry];
00058 
00059                 for(int i=0;i<_num_of_entry;i++)
00060                 {
00061                         _counter[i]=0;  // initial value (weak fallthrough)
00062                 }
00063 
00064                 _low_bhr_mask=(1<<_l)-1;
00065 
00066                 _index_mask=(1<<_m)-1;
00067 
00068                 _num_of_slot_bits;
00069                 int num_of_slot=_num_of_slot;
00070                 for(;num_of_slot!=0;_num_of_slot_bits++)
00071                 {
00072                         num_of_slot=num_of_slot>>1;     
00073                 }
00074                 
00075                 _strong_mask=1<<_num_of_slot_bits;
00076                 _slot_mask=_strong_mask-1;
00077 
00078                 //show(stderr); 
00079                 //exit(0);
00080         }
00081 
00082         void show(FILE *f)
00083         {
00084                 fprintf(f,"_b=%d\n",_b);
00085                 fprintf(f,"_m=%d\n",_m);
00086                 fprintf(f,"_num_of_entry=%d\n",_num_of_entry);
00087                 fprintf(f,"_l=%d\n",_l);
00088                 fprintf(f,"_low_bhr_mask=%d\n",_low_bhr_mask);
00089                 fprintf(f,"_index_mask=%d\n",_index_mask);
00090                 fprintf(f,"_num_of_slot=%d\n",_num_of_slot);
00091                 fprintf(f,"_num_of_slot_bits=%d\n",_num_of_slot_bits);
00092                 fprintf(f,"_strong_mask=%d\n",_strong_mask);
00093                 fprintf(f,"_slot_mask=%d\n",_slot_mask);
00094         }
00095 
00096         void predict(int bhr,int ip,int &direction);
00097         void update(int bhr,int ip,int actual_slot_taken);
00098 
00099         ~Branch_Predictor() 
00100         {
00101                 delete []_tag;
00102                 delete []_counter;
00103         }
00104 
00105 private:
00106         int _b;         // operation size are the 2^_b bytes
00107         int _m;         // number of total bits as the index
00108         int _l;         // number of low-order IP to from the index
00109         int _num_of_entry;      // number of entries in the predictor table
00110         int *_tag;      // store the tag of this op
00111         int *_counter;  // store the value for prediction
00112         int _num_of_slot;       // number of slot in finite state machine
00113                                 // = number of issue width + 1 (fall through)
00114         int _index_mask;        // the mask to get _m bits
00115         int _low_bhr_mask;              // the mask to get _l bits
00116 
00117         int _num_of_slot_bits;  // the bits to represent slots
00118         int _strong_mask;       
00119         int _slot_mask; 
00120         // the first bit of the counter value is strong(1) or weak(0)
00121         // the rest of bit is the slot number
00122         // Ex:
00123         //   000000, predict slot 0 (fall through) is weak taken 
00124         //   100011, predict slot 3 is strong taken 
00125         //   001011, predict slot 11 is weak taken 
00126         //
00127 };
00128 
00129 #endif // INCLUDED_BRANCH_H

Generated on Mon Jul 21 20:24:02 2003 for TINKER LEGO DOC by doxygen 1.3.2