-
Notifications
You must be signed in to change notification settings - Fork 2
/
RMapper.cpp
executable file
·63 lines (53 loc) · 1.39 KB
/
RMapper.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
#include <assert.h>
#include <math.h>
#include "RMapper.h"
RMapper::RMapper(CacheConfig config, unsigned subsets, uint64_t key)
{
line_size_bits_ = config.line_size_bits;
line_size_ = 1 << line_size_bits_;
line_bits_ = config.line_bits;
lines_ = 1 << config.line_bits;
size_ = config.slices * lines_ * line_size_;
way_bits_ = config.way_bits;
ways_ = 1 << config.way_bits;
slices_ = config.slices;
sets_ = lines_ / ways_;
subsets_ = subsets;
subset_bits_ = log2(subsets_);
subset_ways_ = ways_ / subsets_;
key_ = key;
name_ = "static";
assert(!(ways_ % subsets_) && "number of ways can't be evenly split into subsets");
}
CacheSet *RMapper::getIndices(size_t phys_addr, uint64_t secret)
{
uint32_t index = (phys_addr & ((sets_ - 1 ) << line_size_bits_)) >> line_size_bits_;
for (unsigned i = 0; i < subsets_; i++)
set_.index[i] = index;
return &set_;
}
unsigned RMapper::getSlice(size_t phys_addr)
{
//this is Intel's slicing function for 2^x cores
int slice = 0;
if (slices_ >= 2)
{
slice = __builtin_popcountll(phys_addr & SLICE0) % 2;
if (slices_ >= 4)
{
slice |= (__builtin_popcountll(phys_addr & SLICE1) % 2) << 1;
if (slices_ >= 8)
{
slice |= (__builtin_popcountll(phys_addr & SLICE2) % 2) << 2;
}
}
}
return slice;
}
RMapper* RMapper::getCopy()
{
return new RMapper(*this);
}
RMapper::~RMapper()
{
}