-
Notifications
You must be signed in to change notification settings - Fork 2
/
validation_test.cpp
106 lines (90 loc) · 2.44 KB
/
validation_test.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include "SACache.h"
#include "GenericCache.h"
#include "CacheMemory.h"
#include "time.h"
#include "RP_BIP.h"
#include "RP_RANDOM.h"
#include "RP_LRU.h"
#include "RP_PLRU.h"
#include "RP_QLRU.h"
#include "RAES_NI.h"
#include "RCAT.h"
#include "RSASS_AES_NI.h"
#include "RSHA256.h"
#include "assert.h"
#define NUM_POLICIES 4
#define NUM_MAPPERS 5
RPolicy* getPolicyObject(CacheConfig config, int policy_num);
RMapper* getMapperObject(CacheConfig config, unsigned subsets, int mapper_num);
int main()
{
srand(27);
CacheConfig config = { 7, 4, 2, 6 };
unsigned P = 2;
for (int i = 0; i < NUM_POLICIES; i++)
{
RPolicy* policy = getPolicyObject(config, i);
for (int j = 0; j < NUM_MAPPERS; j++)
{
RMapper* mapper = getMapperObject(config, P, j);
auto* cache = new GenericCache(config, *policy, *mapper, P);
for (int i = 0; i < 1024 * 1024 * 16; i++)
{
uint64_t addr = 64 * (rand() % 1024);
//printf("%ld\n", addr);
cache->access({ addr, 0, false, false });
}
long hits = 0;
long misses = 0;
for (unsigned i = 0; i < config.slices; i++)
{
hits += cache->hits(i);
misses += cache->misses(i);
}
printf("Policy: %8s, Mapper: %12s, Config: %4d, %4d, %4d, %4d, Hits: %8ld, Misses: %8ld, Hitrate: %5f\n",
policy->getPolicyName().c_str(), mapper->getMapperName().c_str(), config.line_bits, config.way_bits, config.slices,
config.line_size_bits, hits, misses, (float)hits / (hits + misses));
delete mapper;
delete cache;
}
printf("\n");
delete policy;
}
return 0;
}
RPolicy* getPolicyObject(CacheConfig config, int policy_num)
{
switch (policy_num)
{
case 0:
return new RP_LRU(config);
case 1:
return new RP_PLRU(config);
case 2:
return new RP_BIP(config);
case 3:
return new RP_RANDOM(config);
default:
assert(false);
return NULL;
}
}
RMapper* getMapperObject(CacheConfig config, unsigned subsets, int mapper_num)
{
switch (mapper_num)
{
case 0:
return new RMapper(config, subsets, 0);
case 1:
return new RAES_NI(config, subsets, 0);
case 2:
return new RCAT(config, subsets, 1);
case 3:
return new RSASS_AES_NI(config, subsets, 0);
case 4:
return new RSHA256(config, subsets, 0);
default:
assert(false);
return NULL;
}
}