-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathset_associative_fifo.cpp
59 lines (48 loc) · 1.71 KB
/
set_associative_fifo.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "cache.hpp"
bool containsTag (deque<cache> qtemp, int atag){
for(int i=0;i<qtemp.size();i++){
if(atag == qtemp[i].tag)
return true;
}
return false;
}
void cache_impl::retrieve_value_from_set_associative_cache_FIFO(int address){
int atag, setBits, offsetBits;
offsetBits = log2(block_size*4);
setBits = log2(num_sets);
int x = offsetBits + setBits;
int temp = block_size;
int whichSet = ((address)>>offsetBits) & (num_sets-1);
atag = (address) >> x;
if(set_associative_cache_FIFO[whichSet][0].validBit == 1){
if(containsTag(set_associative_cache_FIFO[whichSet], atag)){
hit++;
} else{
miss++;
if(set_associative_cache_FIFO[whichSet].size() < (set_ways*block_size)){
while(temp>0){
set_associative_cache_FIFO[whichSet].push_back(cache(1,atag,decimal_to_hex_string(address)));
temp--;
address += word_size;
}
} else{
while(temp > 0){
set_associative_cache_FIFO[whichSet].pop_front();
set_associative_cache_FIFO[whichSet].push_back(cache(1,atag,decimal_to_hex_string(address)));
temp--;
address += word_size;
}
}
}
}
else{
set_associative_cache_FIFO[whichSet].clear();
miss++;
deque<cache> q;
while(temp>0){
q.push_back(cache(1, atag , decimal_to_hex_string(address)));
set_associative_cache_FIFO[whichSet] = q;
temp--;
}
}
}