00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef INCLUDED_BTB_H
00023 #define INCLUDED_BTB_H
00024
00025 #include <stdio.h>
00026 #include <assert.h>
00027
00028 class BTB
00029 {
00030 public:
00031 BTB():_tag(NULL) {}
00032
00033
00034
00035
00036 BTB(int b, int e,int s):_b(b),_e(e),_s(s)
00037 {
00038 _num_of_entry=1<<_e;
00039 _num_of_entry_per_set=1<<_s;
00040 _index_mask=(1<<(_e-_s))-1;
00041
00042 _tag=new int[_num_of_entry];
00043 _time=new int[_num_of_entry];
00044 _slot=new int[_num_of_entry];
00045 _target=new int[_num_of_entry];
00046
00047 for(int i=0;i<_num_of_entry;i++)
00048 {
00049 _tag[i]=-1;
00050 _slot[i]=0;
00051 _target[i]=0;
00052 _time[i]=0;
00053 }
00054
00055
00056
00057 }
00058
00059 void show(FILE *f)
00060 {
00061 fprintf(f,"=== BTB ===");
00062 fprintf(f,"_b=%d\n",_b);
00063 fprintf(f,"_e=%d\n",_e);
00064 fprintf(f,"_s=%d\n",_s);
00065 fprintf(f,"_num_of_entry=%d\n",_num_of_entry);
00066 fprintf(f,"_num_of_entry_per_set=%d\n",_num_of_entry_per_set);
00067 fprintf(f,"_index_mask=%d\n",_index_mask);
00068 }
00069
00070 ~BTB()
00071 {
00072 delete []_tag;
00073 delete []_slot;
00074 delete []_target;
00075 delete []_time;
00076 }
00077
00078 void predict(int ip,int slot,bool &find_btb,int &target);
00079 void update(int ip,int slot,int target,int global_cycle);
00080
00081
00082 private:
00083 int _b;
00084 int _e;
00085 int _s;
00086 int _num_of_entry;
00087 int _num_of_entry_per_set;
00088 int _index_mask;
00089
00090 int *_tag;
00091 int *_slot;
00092 int *_target;
00093 int *_time;
00094 };
00095
00096 #endif // INCLUDED_BRANCH_H