[2] | 1 | #ifndef UPDATE_TAB_H_ |
---|
| 2 | #define UPDATE_TAB_H_ |
---|
| 3 | |
---|
| 4 | #include <inttypes.h> |
---|
| 5 | #include <systemc> |
---|
| 6 | #include <cassert> |
---|
| 7 | #include "arithmetics.h" |
---|
| 8 | |
---|
| 9 | //////////////////////////////////////////////////////////////////////// |
---|
| 10 | // An update tab entry |
---|
| 11 | //////////////////////////////////////////////////////////////////////// |
---|
| 12 | class UpdateTabEntry { |
---|
| 13 | typedef uint32_t size_t; |
---|
| 14 | |
---|
| 15 | public: |
---|
| 16 | bool valid; // It is a valid pending transaction |
---|
| 17 | bool update; // It is an update transaction |
---|
| 18 | size_t srcid; // The srcid of the initiator which wrote the data |
---|
| 19 | size_t trdid; // The trdid of the initiator which wrote the data |
---|
| 20 | size_t pktid; // The pktid of the initiator which wrote the data |
---|
| 21 | size_t count; // The number of acknowledge responses to receive |
---|
| 22 | |
---|
| 23 | UpdateTabEntry(){ |
---|
| 24 | valid = false; |
---|
| 25 | update = false; |
---|
| 26 | srcid = 0; |
---|
| 27 | trdid = 0; |
---|
| 28 | pktid = 0; |
---|
| 29 | count = 0; |
---|
| 30 | } |
---|
| 31 | |
---|
| 32 | UpdateTabEntry(bool i_valid, |
---|
| 33 | bool i_update, |
---|
| 34 | size_t i_srcid, |
---|
| 35 | size_t i_trdid, |
---|
| 36 | size_t i_pktid, |
---|
| 37 | size_t i_count) |
---|
| 38 | { |
---|
| 39 | valid = i_valid; |
---|
| 40 | update = i_update; |
---|
| 41 | srcid = i_srcid; |
---|
| 42 | trdid = i_trdid; |
---|
| 43 | pktid = i_pktid; |
---|
| 44 | count = i_count; |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | UpdateTabEntry(const UpdateTabEntry &source) |
---|
| 48 | { |
---|
| 49 | valid = source.valid; |
---|
| 50 | update = source.update; |
---|
| 51 | srcid = source.srcid; |
---|
| 52 | trdid = source.trdid; |
---|
| 53 | pktid = source.pktid; |
---|
| 54 | count = source.count; |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | //////////////////////////////////////////////////// |
---|
| 58 | // The init() function initializes the entry |
---|
| 59 | /////////////////////////////////////////////////// |
---|
| 60 | void init() |
---|
| 61 | { |
---|
| 62 | valid=false; |
---|
| 63 | update=false; |
---|
| 64 | srcid=0; |
---|
| 65 | trdid=0; |
---|
| 66 | pktid=0; |
---|
| 67 | count=0; |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | //////////////////////////////////////////////////////////////////// |
---|
| 71 | // The copy() function copies an existing entry |
---|
| 72 | // Its arguments are : |
---|
| 73 | // - source : the update tab entry to copy |
---|
| 74 | //////////////////////////////////////////////////////////////////// |
---|
| 75 | void copy(const UpdateTabEntry &source) |
---|
| 76 | { |
---|
| 77 | valid=source.valid; |
---|
| 78 | update=source.update; |
---|
| 79 | srcid=source.srcid; |
---|
| 80 | trdid=source.trdid; |
---|
| 81 | pktid=source.pktid; |
---|
| 82 | count=source.count; |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | //////////////////////////////////////////////////////////////////// |
---|
| 86 | // The print() function prints the entry |
---|
| 87 | //////////////////////////////////////////////////////////////////// |
---|
| 88 | void print(){ |
---|
| 89 | std::cout << "valid = " << valid << std::endl; |
---|
| 90 | std::cout << "update = " << update << std::endl; |
---|
| 91 | std::cout << "srcid = " << srcid << std::endl; |
---|
| 92 | std::cout << "trdid = " << trdid << std::endl; |
---|
| 93 | std::cout << "pktid = " << pktid << std::endl; |
---|
| 94 | std::cout << "count = " << count << std::endl; |
---|
| 95 | } |
---|
| 96 | }; |
---|
| 97 | |
---|
| 98 | //////////////////////////////////////////////////////////////////////// |
---|
| 99 | // The update tab |
---|
| 100 | //////////////////////////////////////////////////////////////////////// |
---|
| 101 | class UpdateTab{ |
---|
| 102 | |
---|
| 103 | typedef uint32_t size_t; |
---|
| 104 | |
---|
| 105 | private: |
---|
| 106 | size_t size_tab; |
---|
| 107 | std::vector<UpdateTabEntry> tab; |
---|
| 108 | |
---|
| 109 | public: |
---|
| 110 | |
---|
| 111 | UpdateTab() |
---|
| 112 | : tab(0) |
---|
| 113 | { |
---|
| 114 | size_tab=0; |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | UpdateTab(size_t size_tab_i) |
---|
| 118 | : tab(size_tab_i) |
---|
| 119 | { |
---|
| 120 | size_tab=size_tab_i; |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | //////////////////////////////////////////////////////////////////// |
---|
| 124 | // The size() function returns the size of the tab |
---|
| 125 | //////////////////////////////////////////////////////////////////// |
---|
| 126 | const size_t size(){ |
---|
| 127 | return size_tab; |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | |
---|
| 131 | ///////////////////////////////////////////////////////////////////// |
---|
| 132 | // The init() function initializes the tab |
---|
| 133 | ///////////////////////////////////////////////////////////////////// |
---|
| 134 | void init(){ |
---|
| 135 | for ( size_t i=0; i<size_tab; i++) { |
---|
| 136 | tab[i].init(); |
---|
| 137 | } |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | |
---|
| 141 | ///////////////////////////////////////////////////////////////////// |
---|
| 142 | // The reads() function reads an entry |
---|
| 143 | // Arguments : |
---|
| 144 | // - entry : the entry to read |
---|
| 145 | // This function returns a copy of the entry. |
---|
| 146 | ///////////////////////////////////////////////////////////////////// |
---|
| 147 | UpdateTabEntry read (size_t entry) |
---|
| 148 | { |
---|
| 149 | assert(entry<size_tab && "Bad Update Tab Entry"); |
---|
| 150 | return UpdateTabEntry(tab[entry]); |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | /////////////////////////////////////////////////////////////////////////// |
---|
| 154 | // The set() function writes an entry in the Update Table |
---|
| 155 | // Arguments : |
---|
| 156 | // - update : transaction type (bool) |
---|
| 157 | // - srcid : srcid of the initiator |
---|
| 158 | // - trdid : trdid of the initiator |
---|
| 159 | // - pktid : pktid of the initiator |
---|
| 160 | // - count : number of expected responses |
---|
| 161 | // - index : (return argument) index of the selected entry |
---|
| 162 | // This function returns true if the write successed (an entry was empty). |
---|
| 163 | /////////////////////////////////////////////////////////////////////////// |
---|
| 164 | bool set(const bool update, |
---|
| 165 | const size_t srcid, |
---|
| 166 | const size_t trdid, |
---|
| 167 | const size_t pktid, |
---|
| 168 | const size_t count, |
---|
| 169 | size_t &index) |
---|
| 170 | { |
---|
| 171 | for ( size_t i=0 ; i<size_tab ; i++ ) { |
---|
| 172 | if( !tab[i].valid ) { |
---|
| 173 | tab[i].valid = true; |
---|
| 174 | tab[i].update = update; |
---|
| 175 | tab[i].srcid = (size_t) srcid; |
---|
| 176 | tab[i].trdid = (size_t) trdid; |
---|
| 177 | tab[i].pktid = (size_t) pktid; |
---|
| 178 | tab[i].count = (size_t) count; |
---|
| 179 | index = i; |
---|
| 180 | return true; |
---|
| 181 | } |
---|
| 182 | } |
---|
| 183 | return false; |
---|
| 184 | } // end set() |
---|
| 185 | |
---|
| 186 | ///////////////////////////////////////////////////////////////////// |
---|
| 187 | // The decrement() function decrements the counter for a given entry. |
---|
| 188 | // Arguments : |
---|
| 189 | // - index : the index of the entry |
---|
| 190 | // - counter : (return argument) value of the counter after decrement |
---|
| 191 | // This function returns true if the entry is valid. |
---|
| 192 | ///////////////////////////////////////////////////////////////////// |
---|
| 193 | bool decrement( const size_t index, |
---|
| 194 | size_t &counter ) |
---|
| 195 | { |
---|
| 196 | assert((index<size_tab) && "Bad Update Tab Entry"); |
---|
| 197 | if ( tab[index].valid ) { |
---|
| 198 | tab[index].count--; |
---|
| 199 | counter = tab[index].count; |
---|
| 200 | return true; |
---|
| 201 | } else { |
---|
| 202 | return false; |
---|
| 203 | } |
---|
| 204 | } |
---|
| 205 | |
---|
| 206 | ///////////////////////////////////////////////////////////////////// |
---|
| 207 | // The is_update() function returns the transaction type |
---|
| 208 | // Arguments : |
---|
| 209 | // - index : the index of the entry |
---|
| 210 | ///////////////////////////////////////////////////////////////////// |
---|
| 211 | bool is_update(const size_t index) |
---|
| 212 | { |
---|
| 213 | assert(index<size_tab && "Bad Update Tab Entry"); |
---|
| 214 | return tab[index].update; |
---|
| 215 | } |
---|
| 216 | |
---|
| 217 | ///////////////////////////////////////////////////////////////////// |
---|
| 218 | // The srcid() function returns the srcid value |
---|
| 219 | // Arguments : |
---|
| 220 | // - index : the index of the entry |
---|
| 221 | ///////////////////////////////////////////////////////////////////// |
---|
| 222 | size_t srcid(const size_t index) |
---|
| 223 | { |
---|
| 224 | assert(index<size_tab && "Bad Update Tab Entry"); |
---|
| 225 | return tab[index].srcid; |
---|
| 226 | } |
---|
| 227 | |
---|
| 228 | ///////////////////////////////////////////////////////////////////// |
---|
| 229 | // The trdid() function returns the trdid value |
---|
| 230 | // Arguments : |
---|
| 231 | // - index : the index of the entry |
---|
| 232 | ///////////////////////////////////////////////////////////////////// |
---|
| 233 | size_t trdid(const size_t index) |
---|
| 234 | { |
---|
| 235 | assert(index<size_tab && "Bad Update Tab Entry"); |
---|
| 236 | return tab[index].trdid; |
---|
| 237 | } |
---|
| 238 | |
---|
| 239 | ///////////////////////////////////////////////////////////////////// |
---|
| 240 | // The pktid() function returns the pktid value |
---|
| 241 | // Arguments : |
---|
| 242 | // - index : the index of the entry |
---|
| 243 | ///////////////////////////////////////////////////////////////////// |
---|
| 244 | size_t pktid(const size_t index) |
---|
| 245 | { |
---|
| 246 | assert(index<size_tab && "Bad Update Tab Entry"); |
---|
| 247 | return tab[index].pktid; |
---|
| 248 | } |
---|
| 249 | |
---|
| 250 | ///////////////////////////////////////////////////////////////////// |
---|
| 251 | // The clear() function erases an entry of the tab |
---|
| 252 | // Arguments : |
---|
| 253 | // - index : the index of the entry |
---|
| 254 | ///////////////////////////////////////////////////////////////////// |
---|
| 255 | void clear(const size_t index) |
---|
| 256 | { |
---|
| 257 | assert(index<size_tab && "Bad Update Tab Entry"); |
---|
| 258 | tab[index].valid=false; |
---|
| 259 | return; |
---|
| 260 | } |
---|
| 261 | |
---|
| 262 | }; |
---|
| 263 | |
---|
| 264 | #endif |
---|