1 | #include "../include/Cache_OneLevel.h" |
---|
2 | |
---|
3 | namespace environment { |
---|
4 | namespace cache { |
---|
5 | namespace cache_onelevel { |
---|
6 | |
---|
7 | void Cache_OneLevel::transition (void) |
---|
8 | { |
---|
9 | // scan all port - test if have a transaction |
---|
10 | for (int32_t x = param->nb_port-1; x >= 0; x --) |
---|
11 | { |
---|
12 | if (access_port[x].valid == true) |
---|
13 | { |
---|
14 | access_port[x].valid = false; |
---|
15 | |
---|
16 | // Update LRU |
---|
17 | // * hit : now |
---|
18 | // * miss : after the return of next cache |
---|
19 | |
---|
20 | if (access_port[x].hit == HIT_CACHE) |
---|
21 | {// Hit |
---|
22 | update_lru(access_port[x].address.familly,access_port[x].num_associativity); |
---|
23 | } |
---|
24 | |
---|
25 | if (access_port[x].hit == MISS) |
---|
26 | {// Miss |
---|
27 | // Write in write_buffer |
---|
28 | write_buffer->push(access_port[x].latence,Write_Buffer(access_port[x].address,access_port[x].trdid)); |
---|
29 | } |
---|
30 | } |
---|
31 | } |
---|
32 | |
---|
33 | write_buffer->transition(); |
---|
34 | |
---|
35 | // Test if a write_buffer have the result |
---|
36 | while ((write_buffer->empty() == false) and |
---|
37 | (write_buffer->read(0)._delay == 0)) |
---|
38 | { |
---|
39 | // Save in the cache |
---|
40 | Write_Buffer val = write_buffer->pop(); |
---|
41 | |
---|
42 | uint32_t num_tag = val.address.tag; |
---|
43 | uint32_t num_familly = val.address.familly; |
---|
44 | uint32_t num_associativity = index_victim(num_familly); |
---|
45 | |
---|
46 | tag [num_familly][num_associativity].valid = true; |
---|
47 | tag [num_familly][num_associativity].address = num_tag; |
---|
48 | tag [num_familly][num_associativity].trdid = val.trdid; |
---|
49 | |
---|
50 | update_lru(num_familly,num_associativity); |
---|
51 | } |
---|
52 | |
---|
53 | } |
---|
54 | }; |
---|
55 | }; |
---|
56 | }; |
---|