[10] | 1 | #ifdef VHDL |
---|
| 2 | /* |
---|
| 3 | * $Id: Victim_Pseudo_LRU_vhdl_body.cpp 95 2008-12-16 16:24:26Z rosiere $ |
---|
| 4 | * |
---|
| 5 | * [ Description ] |
---|
| 6 | * |
---|
| 7 | */ |
---|
| 8 | |
---|
[15] | 9 | #include "Behavioural/Generic/Victim/Victim_Pseudo_LRU/include/Victim_Pseudo_LRU.h" |
---|
[10] | 10 | |
---|
| 11 | namespace morpheo { |
---|
| 12 | namespace behavioural { |
---|
| 13 | namespace generic { |
---|
| 14 | namespace victim { |
---|
[15] | 15 | namespace victim_pseudo_lru { |
---|
[10] | 16 | |
---|
[42] | 17 | void Victim_Pseudo_LRU::vhdl_body (Vhdl * & vhdl) |
---|
[10] | 18 | { |
---|
[42] | 19 | vhdl->set_body (""); |
---|
| 20 | vhdl->set_body ("-----------------------------------------------------------------------------"); |
---|
| 21 | vhdl->set_body ("-- Access"); |
---|
| 22 | vhdl->set_body ("-----------------------------------------------------------------------------"); |
---|
| 23 | vhdl->set_body (""); |
---|
| 24 | vhdl->set_body ("-- Tree of Pseudo-LRU - example to 8 entity"); |
---|
| 25 | vhdl->set_body ("--"); |
---|
| 26 | vhdl->set_body ("-- 4-5-6-7? "); |
---|
| 27 | vhdl->set_body ("-- 0_______|_______1 "); |
---|
| 28 | vhdl->set_body ("-- | | "); |
---|
| 29 | vhdl->set_body ("-- 2-3? 6-7? "); |
---|
| 30 | vhdl->set_body ("-- 0___|___1 0___|___1 "); |
---|
| 31 | vhdl->set_body ("-- | | | | "); |
---|
| 32 | vhdl->set_body ("-- 1? 3? 5? 7? "); |
---|
| 33 | vhdl->set_body ("-- 0_|_1 0_|_1 0_|_1 0_|_1 "); |
---|
| 34 | vhdl->set_body ("-- | | | | | | | | "); |
---|
| 35 | vhdl->set_body ("-- Way Way Way Way Way Way Way Way "); |
---|
| 36 | vhdl->set_body ("-- 0 1 2 3 4 5 6 7 "); |
---|
[78] | 37 | for (uint32_t i=0; i<_param->_nb_access; i++) |
---|
[10] | 38 | { |
---|
[42] | 39 | vhdl->set_body (""); |
---|
[10] | 40 | // Read the table |
---|
| 41 | |
---|
[75] | 42 | std::string access_address; |
---|
[10] | 43 | |
---|
[78] | 44 | if (_param->_size_table>1) |
---|
[42] | 45 | access_address = "conv_integer(in_ACCESS_"+toString(i)+"_ADDRESS)"; |
---|
[10] | 46 | else |
---|
| 47 | access_address = "0"; |
---|
| 48 | |
---|
[42] | 49 | vhdl->set_body ("access_entry_"+toString(i)+" <= reg_TABLE ("+access_address+");"); |
---|
| 50 | vhdl->set_body (""); |
---|
[10] | 51 | |
---|
[78] | 52 | for (int32_t j=static_cast<uint32_t>(log2(_param->_nb_entity)-1); j>=0; j--) |
---|
[10] | 53 | { |
---|
[42] | 54 | vhdl->set_body ("access_entity_"+toString(i)+"("+toString(j)+") <= "); |
---|
[10] | 55 | |
---|
| 56 | uint32_t cpt=0; |
---|
| 57 | |
---|
[78] | 58 | for (int32_t k=(1<<j)-1; k<static_cast<int32_t>(_param->_nb_entity-1); k+=(1<<(j+1))) |
---|
[10] | 59 | { |
---|
[75] | 60 | std::string cond = ""; |
---|
[10] | 61 | |
---|
| 62 | // Create the condition |
---|
[78] | 63 | for (uint32_t l=j+1; l<static_cast<uint32_t>(log2(_param->_nb_entity));l++) |
---|
[10] | 64 | { |
---|
| 65 | if (l==static_cast<uint32_t>(j+1)) |
---|
| 66 | cond += "when"; |
---|
| 67 | else |
---|
| 68 | cond += " and"; |
---|
| 69 | cond += " access_entity_"+toString(i)+"("+toString(l)+") = '"+toString((cpt>>(l-(j+1)))&1)+"'"; |
---|
| 70 | } |
---|
| 71 | |
---|
[75] | 72 | std::string print_else = (k==(1<<j)-1)?" ":"else "; |
---|
[10] | 73 | |
---|
[42] | 74 | vhdl->set_body ("\t"+print_else+"access_entry_"+toString(i)+"("+toString(k)+") "+cond); |
---|
[10] | 75 | cpt ++; |
---|
| 76 | } |
---|
[42] | 77 | vhdl->set_body ("\t;"); |
---|
[10] | 78 | } |
---|
| 79 | } |
---|
| 80 | |
---|
[42] | 81 | vhdl->set_body (""); |
---|
| 82 | vhdl->set_body ("-----------------------------------------------------------------------------"); |
---|
| 83 | vhdl->set_body ("-- Update"); |
---|
| 84 | vhdl->set_body ("-----------------------------------------------------------------------------"); |
---|
| 85 | vhdl->set_body (""); |
---|
| 86 | vhdl->set_body ("-- port access"); |
---|
[78] | 87 | for (uint32_t i=0; i<_param->_nb_access; i++) |
---|
| 88 | for (int32_t j=static_cast<uint32_t>(log2(_param->_nb_entity)-1); j>=0; j--) |
---|
[10] | 89 | { |
---|
| 90 | uint32_t cpt=0; |
---|
| 91 | |
---|
[78] | 92 | for (int32_t k=(1<<j)-1; k<static_cast<int32_t>(_param->_nb_entity-1); k+=(1<<(j+1))) |
---|
[10] | 93 | { |
---|
| 94 | bool have_cond = false; |
---|
[75] | 95 | std::string cond = ""; |
---|
[10] | 96 | |
---|
| 97 | // condition to change the bit |
---|
[78] | 98 | for (uint32_t l=j+1; l<static_cast<uint32_t>(log2(_param->_nb_entity));l++) |
---|
[10] | 99 | { |
---|
| 100 | have_cond = true; |
---|
| 101 | |
---|
| 102 | if (l==static_cast<uint32_t>(j+1)) |
---|
| 103 | cond += "when"; |
---|
| 104 | else |
---|
| 105 | cond += " and"; |
---|
| 106 | cond += " access_entity_"+toString(i)+"("+toString(l)+")='"+toString((cpt>>(l-(j+1)))&1)+"'"; |
---|
| 107 | } |
---|
| 108 | |
---|
[42] | 109 | vhdl->set_body ("access_next_entry_"+toString(i)+"("+toString(k)+") <="); |
---|
| 110 | vhdl->set_body ("\tnot access_entity_"+toString(i)+"("+toString(j)+") "+cond); |
---|
[10] | 111 | if (have_cond == true) |
---|
[42] | 112 | vhdl->set_body ("\telse access_entry_"+toString(i)+"("+toString(k)+")"); |
---|
| 113 | vhdl->set_body ("\t;"); |
---|
[10] | 114 | cpt ++; |
---|
| 115 | } |
---|
| 116 | } |
---|
| 117 | |
---|
[95] | 118 | // vhdl->set_body (""); |
---|
| 119 | // vhdl->set_body ("-- port update"); |
---|
| 120 | // for (uint32_t i=0; i<_param->_nb_update; i++) |
---|
| 121 | // for (int32_t j=static_cast<uint32_t>(log2(_param->_nb_entity)-1); j>=0; j--) |
---|
| 122 | // { |
---|
| 123 | // uint32_t cpt=0; |
---|
[10] | 124 | |
---|
[95] | 125 | // for (int32_t k=(1<<j)-1; k<static_cast<int32_t>(_param->_nb_entity-1); k+=(1<<(j+1))) |
---|
| 126 | // { |
---|
| 127 | // bool have_cond = false; |
---|
| 128 | // std::string cond = ""; |
---|
[10] | 129 | |
---|
[95] | 130 | // // condition to change the bit |
---|
| 131 | // for (uint32_t l=j+1; l<static_cast<uint32_t>(log2(_param->_nb_entity));l++) |
---|
| 132 | // { |
---|
| 133 | // have_cond = true; |
---|
[10] | 134 | |
---|
[95] | 135 | // if (l==static_cast<uint32_t>(j+1)) |
---|
| 136 | // cond += "when"; |
---|
| 137 | // else |
---|
| 138 | // cond += " and"; |
---|
| 139 | // cond += " in_UPDATE_"+toString(i)+"_ENTITY("+toString(l)+")='"+toString((cpt>>(l-(j+1)))&1)+"'"; |
---|
| 140 | // } |
---|
[10] | 141 | |
---|
[95] | 142 | // vhdl->set_body ("update_next_entry_"+toString(i)+"("+toString(k)+") <="); |
---|
| 143 | // vhdl->set_body ("\tnot in_UPDATE_"+toString(i)+"_ENTITY("+toString(j)+") "+cond); |
---|
| 144 | // if (have_cond == true) |
---|
| 145 | // { |
---|
| 146 | // std::string update_address; |
---|
[10] | 147 | |
---|
[95] | 148 | // if (_param->_size_table>1) |
---|
| 149 | // update_address = "conv_integer(in_UPDATE_"+toString(i)+"_ADDRESS)"; |
---|
| 150 | // else |
---|
| 151 | // update_address = "0"; |
---|
[10] | 152 | |
---|
[95] | 153 | // vhdl->set_body ("\telse reg_TABLE ("+update_address+")("+toString(k)+")"); |
---|
| 154 | // } |
---|
| 155 | // vhdl->set_body ("\t;"); |
---|
| 156 | // cpt ++; |
---|
| 157 | // } |
---|
| 158 | // } |
---|
[10] | 159 | |
---|
[42] | 160 | vhdl->set_body (""); |
---|
| 161 | vhdl->set_body ("-----------------------------------------------------------------------------"); |
---|
| 162 | vhdl->set_body ("-- Transition"); |
---|
| 163 | vhdl->set_body ("-----------------------------------------------------------------------------"); |
---|
| 164 | vhdl->set_body (""); |
---|
[10] | 165 | |
---|
[42] | 166 | vhdl->set_body ("reg_TABLE_write: process (in_CLOCK)"); |
---|
| 167 | vhdl->set_body ("begin"); |
---|
| 168 | vhdl->set_body ("\tif in_CLOCK'event and in_CLOCK = '1' then"); |
---|
| 169 | vhdl->set_body ("\t\t-- Access port"); |
---|
[78] | 170 | for (uint32_t i=0; i<_param->_nb_access; i++) |
---|
[10] | 171 | { |
---|
[75] | 172 | std::string access_address; |
---|
[10] | 173 | |
---|
[78] | 174 | if (_param->_size_table>1) |
---|
[42] | 175 | access_address = "conv_integer(in_ACCESS_"+toString(i)+"_ADDRESS)"; |
---|
[10] | 176 | else |
---|
| 177 | access_address = "0"; |
---|
| 178 | |
---|
[42] | 179 | vhdl->set_body ("\t\tif (in_ACCESS_"+toString(i)+"_VAL = '1') then"); |
---|
| 180 | vhdl->set_body ("\t\t\treg_TABLE ("+access_address+") <= access_next_entry_"+toString(i)+";"); |
---|
| 181 | vhdl->set_body ("\t\tend if;"); |
---|
[10] | 182 | } |
---|
| 183 | |
---|
[95] | 184 | // vhdl->set_body ("\t\t-- Update port"); |
---|
| 185 | // for (uint32_t i=0; i<_param->_nb_update; i++) |
---|
| 186 | // { |
---|
| 187 | // std::string update_address; |
---|
[10] | 188 | |
---|
[95] | 189 | // if (_param->_size_table>1) |
---|
| 190 | // update_address = "conv_integer(in_UPDATE_"+toString(i)+"_ADDRESS)"; |
---|
| 191 | // else |
---|
| 192 | // update_address = "0"; |
---|
[10] | 193 | |
---|
[95] | 194 | // vhdl->set_body ("\t\tif (in_UPDATE_"+toString(i)+"_VAL = '1') then"); |
---|
| 195 | // vhdl->set_body ("\t\t\treg_TABLE ("+update_address+") <= update_next_entry_"+toString(i)+";"); |
---|
| 196 | // vhdl->set_body ("\t\tend if;"); |
---|
| 197 | // } |
---|
[10] | 198 | |
---|
[42] | 199 | vhdl->set_body ("\tend if;"); |
---|
| 200 | vhdl->set_body ("end process reg_TABLE_write;"); |
---|
[10] | 201 | |
---|
[42] | 202 | vhdl->set_body (""); |
---|
| 203 | vhdl->set_body ("-----------------------------------------------------------------------------"); |
---|
| 204 | vhdl->set_body ("-- Output"); |
---|
| 205 | vhdl->set_body ("-----------------------------------------------------------------------------"); |
---|
| 206 | vhdl->set_body (""); |
---|
| 207 | vhdl->set_body ("-- Ack is always "); |
---|
| 208 | vhdl->set_body (""); |
---|
[78] | 209 | for (uint32_t i=0; i<_param->_nb_access; i++) |
---|
[10] | 210 | { |
---|
[42] | 211 | vhdl->set_body ("out_ACCESS_"+toString(i)+"_ACK <= '1';"); |
---|
[95] | 212 | vhdl->set_body ("out_ACCESS_"+toString(i)+"_VICTIM <= access_entity_"+toString(i)+" when in_ACCESS_"+toString(i)+"_VAL = '1' else (others => '0');"); |
---|
[10] | 213 | } |
---|
[42] | 214 | vhdl->set_body (""); |
---|
[95] | 215 | // for (uint32_t i=0; i<_param->_nb_update; i++) |
---|
| 216 | // { |
---|
| 217 | // vhdl->set_body ("out_UPDATE_"+toString(i)+"_ACK <= '1';"); |
---|
| 218 | // } |
---|
[10] | 219 | }; |
---|
| 220 | |
---|
[15] | 221 | }; // end namespace victim_pseudo_lru |
---|
[10] | 222 | }; // end namespace victim |
---|
| 223 | }; // end namespace generic |
---|
| 224 | |
---|
| 225 | }; // end namespace behavioural |
---|
| 226 | }; // end namespace morpheo |
---|
| 227 | #endif |
---|