-
Notifications
You must be signed in to change notification settings - Fork 2
/
SplitCache.cpp
executable file
·77 lines (57 loc) · 1.9 KB
/
SplitCache.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <cstdlib>
#include <stdio.h>
#include <string.h>
#include "SplitCache.h"
SplitCache::SplitCache(Cache *instr_cache, Cache *data_cache, bool debug)
{
instr_cache_ = instr_cache;
data_cache_ = data_cache;
name_ = "SplitCache";
clearCache();
if (debug)
{
printf("\n-------------------------------------");
printf("\nI, type: %s, RPolicy: %s\n", instr_cache_->getName().c_str(), instr_cache_->getPolicy().c_str());
printf("size: %2.2fMB, lines: %u, ways: %u, slices: %u, linesize: %lu\n", (float)instr_cache_->getCacheSize()/1024/1024, instr_cache_->getLines(), instr_cache_->getWays(), instr_cache_->getSlices(), instr_cache_->getLineSize());
printf("\nD, type: %s, RPolicy: %s\n", data_cache_->getName().c_str(), data_cache_->getPolicy().c_str());
printf("size: %2.2fMB, lines: %u, ways: %u, slices: %u, linesize: %lu\n", (float)data_cache_->getCacheSize()/1024/1024, data_cache_->getLines(), data_cache_->getWays(), data_cache_->getSlices(), data_cache_->getLineSize());
printf("-------------------------------------\n\n");
}
}
void SplitCache::clearCache()
{
instr_cache_->clearCache();
data_cache_->clearCache();
}
CLState SplitCache::isCached(size_t addr, size_t secret)
{
if (instr_cache_->isCached(addr, secret) || data_cache_->isCached(addr, secret))
return HIT;
return MISS;
}
AccessResult SplitCache::access(Access mem_access)
{
AccessResult result = {MISS, false, 0};
if (mem_access.instruction)
result = instr_cache_->access(mem_access);
else
result = data_cache_->access(mem_access);
if (result.hit)
cache_hits_[0]++;
else
cache_misses_[0]++;
return result;
}
void SplitCache::resetUsage(int slice)
{
instr_cache_->resetUsage(slice);
data_cache_->resetUsage(slice);
}
void SplitCache::flush(Access mem_access)
{
instr_cache_->flush(mem_access);
data_cache_->flush(mem_access);
}
SplitCache::~SplitCache()
{
}