[10] | 1 | #ifndef morpheo_behavioural_generic_victim_pseudo_lru_Pseudo_LRU_h |
---|
| 2 | #define morpheo_behavioural_generic_victim_pseudo_lru_Pseudo_LRU_h |
---|
| 3 | |
---|
| 4 | /* |
---|
| 5 | * $Id$ |
---|
| 6 | * |
---|
| 7 | * [ Description ] |
---|
| 8 | * |
---|
| 9 | */ |
---|
| 10 | // Tree of Pseudo-LRU |
---|
| 11 | // |
---|
| 12 | // | 4-5-6-7? | |
---|
| 13 | // | 0_______|_______1 | |
---|
| 14 | // | | | | |
---|
| 15 | // | 2-3? 6-7? | |
---|
| 16 | // | 0___|___1 0___|___1 | |
---|
| 17 | // | | | | | | |
---|
| 18 | // | 1? 3? 5? 7? | |
---|
| 19 | // | 0_|_1 0_|_1 0_|_1 0_|_1 | |
---|
| 20 | // | | | | | | | | | | |
---|
| 21 | // | Way Way Way Way Way Way Way Way | |
---|
| 22 | // | 0 1 2 3 4 5 6 7 | |
---|
| 23 | |
---|
| 24 | |
---|
| 25 | |
---|
| 26 | #ifdef SYSTEMC |
---|
| 27 | #include "systemc.h" |
---|
| 28 | #endif |
---|
| 29 | |
---|
| 30 | #include <iostream> |
---|
| 31 | #include "Include/ToString.h" |
---|
| 32 | #include "Include/Debug.h" |
---|
| 33 | |
---|
| 34 | #include "Behavioural/Generic/Victim/Pseudo_LRU/include/Parameters.h" |
---|
| 35 | #include "Behavioural/Generic/Victim/Pseudo_LRU/include/Types.h" |
---|
| 36 | #ifdef STATISTICS |
---|
| 37 | #include "Behavioural/Generic/Victim/Pseudo_LRU/include/Statistics.h" |
---|
| 38 | #endif |
---|
| 39 | #ifdef VHDL |
---|
| 40 | #include "Behavioural/include/Vhdl.h" |
---|
| 41 | #endif |
---|
| 42 | #ifdef VHDL_TESTBENCH |
---|
| 43 | #include "Behavioural/include/Vhdl_Testbench.h" |
---|
| 44 | #endif |
---|
| 45 | |
---|
| 46 | using namespace std; |
---|
| 47 | |
---|
| 48 | namespace morpheo { |
---|
| 49 | namespace behavioural { |
---|
| 50 | namespace generic { |
---|
| 51 | namespace victim { |
---|
| 52 | namespace pseudo_lru { |
---|
| 53 | |
---|
| 54 | class Pseudo_LRU |
---|
| 55 | #if SYSTEMC |
---|
| 56 | : public sc_module |
---|
| 57 | #endif |
---|
| 58 | { |
---|
| 59 | // -----[ internal class ]-------------------------------------------- |
---|
| 60 | protected : class entry_t |
---|
| 61 | { |
---|
| 62 | // Numerotation of pseudo_LRU's tree |
---|
| 63 | // Tree of Pseudo-LRU |
---|
| 64 | // |
---|
| 65 | // | d2 [3] | |
---|
| 66 | // | 0_______|_______1 | |
---|
| 67 | // | | | | |
---|
| 68 | // | d1 [1] [5] | |
---|
| 69 | // | 0___|___1 0___|___1 | |
---|
| 70 | // | | | | | | |
---|
| 71 | // | d0 [0] [2] [4] [6] | |
---|
| 72 | // | 0_|_1 0_|_1 0_|_1 0_|_1 | |
---|
| 73 | // | | | | | | | | | | |
---|
| 74 | // | Way Way Way Way Way Way Way Way | |
---|
| 75 | // | 0 1 2 3 4 5 6 7 | |
---|
| 76 | // |
---|
| 77 | // Access : Way N with N=2*n -> bit 2*n = 0 |
---|
| 78 | // with N=2*n+1 -> bit 2*n = 1 |
---|
| 79 | // |
---|
| 80 | // if bit = B, depth = D, next_B = B+D if B==1 |
---|
| 81 | // = B-D if B==0 |
---|
| 82 | // |
---|
| 83 | // Update : |
---|
| 84 | |
---|
| 85 | private : bool * _entry; |
---|
| 86 | private : uint32_t _size; |
---|
| 87 | |
---|
| 88 | public : entry_t () |
---|
| 89 | { |
---|
| 90 | }; |
---|
| 91 | public : entry_t (uint32_t size) : _size (size) |
---|
| 92 | { |
---|
| 93 | _entry = new bool [size]; |
---|
| 94 | |
---|
| 95 | // initialisation |
---|
| 96 | for (uint32_t i=0; i<size; i++) |
---|
| 97 | _entry [i] = false; |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | public : ~entry_t () |
---|
| 101 | { |
---|
| 102 | delete _entry; |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | private : uint32_t one_access (uint32_t index, uint32_t offset) |
---|
| 106 | { |
---|
| 107 | bool val = _entry[index]; |
---|
| 108 | |
---|
| 109 | // Compute next slot |
---|
| 110 | if (val == true) |
---|
| 111 | return index + offset; |
---|
| 112 | else |
---|
| 113 | return index - offset; |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | public : uint32_t access () |
---|
| 117 | { |
---|
| 118 | uint32_t index = (_size>>1)-1; // medium |
---|
| 119 | |
---|
| 120 | for (int32_t i=static_cast<uint32_t>(log2(_size)-1); i>= 1; i--) |
---|
| 121 | { |
---|
| 122 | index = one_access (index,(1<<(i-1))); |
---|
| 123 | } |
---|
| 124 | index = one_access (index,0); |
---|
| 125 | |
---|
| 126 | // reverse by one_access make always a reverse |
---|
| 127 | uint32_t offset = (_entry[index]==true)?1:0; |
---|
| 128 | |
---|
| 129 | return index+offset; |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | private : uint32_t one_update (uint32_t index, uint32_t offset, uint32_t value) |
---|
| 133 | { |
---|
| 134 | uint32_t mask = (offset==0)?1:(offset<<1); |
---|
| 135 | bool val = ((value & mask) != 0); |
---|
| 136 | |
---|
| 137 | // reverse |
---|
| 138 | _entry[index] = not val; |
---|
| 139 | |
---|
| 140 | if (val == true) |
---|
| 141 | // Compute next slot |
---|
| 142 | return index + offset; |
---|
| 143 | else |
---|
| 144 | return index - offset; |
---|
| 145 | } |
---|
| 146 | public : void update (uint32_t value) |
---|
| 147 | { |
---|
| 148 | uint32_t index = (_size>>1)-1; // medium |
---|
| 149 | |
---|
| 150 | for (int32_t i=static_cast<uint32_t>(log2(_size)-1); i>=1; i--) |
---|
| 151 | { |
---|
| 152 | index = one_update (index,1<<(i-1),value); |
---|
| 153 | } |
---|
| 154 | index = one_update (index,0,value); |
---|
| 155 | } |
---|
| 156 | |
---|
| 157 | public : string print () |
---|
| 158 | { |
---|
| 159 | string res = ""; |
---|
| 160 | |
---|
| 161 | for (int32_t i=static_cast<int32_t>(_size)-1; i>=0; i--) |
---|
| 162 | res += toString(_entry[i]) + " "; |
---|
| 163 | |
---|
| 164 | return res; |
---|
| 165 | } |
---|
| 166 | |
---|
| 167 | }; |
---|
| 168 | // -----[ fields ]---------------------------------------------------- |
---|
| 169 | // Parameters |
---|
| 170 | protected : const string _name; |
---|
| 171 | |
---|
| 172 | protected : const Parameters _param; |
---|
| 173 | #ifdef STATISTICS |
---|
| 174 | private : Statistics * _stat; |
---|
| 175 | #endif |
---|
| 176 | |
---|
| 177 | #ifdef VHDL_TESTBENCH |
---|
| 178 | private : Vhdl_Testbench * _vhdl_testbench; |
---|
| 179 | #endif |
---|
| 180 | |
---|
| 181 | #ifdef SYSTEMC |
---|
| 182 | // ~~~~~[ Interface ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
| 183 | // Interface |
---|
| 184 | public : SC_CLOCK * in_CLOCK ; |
---|
| 185 | |
---|
| 186 | // Interface access |
---|
| 187 | public : SC_IN (Tcontrol_t) ** in_ACCESS_VAL ; |
---|
| 188 | public : SC_OUT(Tcontrol_t) ** out_ACCESS_ACK ; |
---|
| 189 | public : SC_IN (Taddress_t) ** in_ACCESS_ADDRESS; |
---|
| 190 | public : SC_OUT(Tentity_t ) ** out_ACCESS_ENTITY ; |
---|
| 191 | // Interface update |
---|
| 192 | public : SC_IN (Tcontrol_t) ** in_UPDATE_VAL ; |
---|
| 193 | public : SC_OUT(Tcontrol_t) ** out_UPDATE_ACK ; |
---|
| 194 | public : SC_IN (Taddress_t) ** in_UPDATE_ADDRESS; |
---|
| 195 | public : SC_IN (Tentity_t ) ** in_UPDATE_ENTITY ; |
---|
| 196 | |
---|
| 197 | // Interface update |
---|
| 198 | // ~~~~~[ Register ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
| 199 | private : entry_t ** reg_TABLE; |
---|
| 200 | |
---|
| 201 | // ~~~~~[ Internal ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
| 202 | private : Tentity_t * internal_ACCESS_ENTITY; |
---|
| 203 | #endif |
---|
| 204 | |
---|
| 205 | // -----[ methods ]--------------------------------------------------- |
---|
| 206 | |
---|
| 207 | #ifdef SYSTEMC |
---|
| 208 | SC_HAS_PROCESS (Pseudo_LRU); |
---|
| 209 | #endif |
---|
| 210 | |
---|
| 211 | public : Pseudo_LRU ( |
---|
| 212 | #ifdef SYSTEMC |
---|
| 213 | sc_module_name name, |
---|
| 214 | #else |
---|
| 215 | string name, |
---|
| 216 | #endif |
---|
| 217 | #ifdef STATISTICS |
---|
| 218 | morpheo::behavioural::Parameters_Statistics param_statistics, |
---|
| 219 | #endif |
---|
| 220 | Parameters param ); |
---|
| 221 | |
---|
| 222 | public : Pseudo_LRU (Parameters param ); |
---|
| 223 | public : ~Pseudo_LRU (void); |
---|
| 224 | |
---|
| 225 | #ifdef SYSTEMC |
---|
| 226 | private : void allocation (void); |
---|
| 227 | private : void deallocation (void); |
---|
| 228 | |
---|
| 229 | public : void transition (void); |
---|
| 230 | public : void genMealy_access (void); |
---|
| 231 | #endif |
---|
| 232 | #ifdef STATISTICS |
---|
| 233 | public : string statistics (uint32_t depth); |
---|
| 234 | #endif |
---|
| 235 | |
---|
| 236 | #if VHDL |
---|
| 237 | public : void vhdl (void); |
---|
| 238 | private : void vhdl_port (Vhdl & vhdl); |
---|
| 239 | private : void vhdl_declaration (Vhdl & vhdl); |
---|
| 240 | private : void vhdl_body (Vhdl & vhdl); |
---|
| 241 | #endif |
---|
| 242 | |
---|
| 243 | #ifdef VHDL_TESTBENCH |
---|
| 244 | private : void vhdl_testbench (Vhdl_Testbench & vhdl_testbench); |
---|
| 245 | private : void vhdl_testbench_port (Vhdl_Testbench & vhdl_testbench); |
---|
| 246 | private : void vhdl_testbench_transition (Vhdl_Testbench & vhdl_testbench); |
---|
| 247 | #endif |
---|
| 248 | |
---|
| 249 | }; |
---|
| 250 | |
---|
| 251 | }; // end namespace pseudo_lru |
---|
| 252 | }; // end namespace victim |
---|
| 253 | }; // end namespace generic |
---|
| 254 | |
---|
| 255 | }; // end namespace behavioural |
---|
| 256 | }; // end namespace morpheo |
---|
| 257 | |
---|
| 258 | #endif |
---|