-
Notifications
You must be signed in to change notification settings - Fork 2
/
CacheTypes.bsv
executable file
·85 lines (64 loc) · 2.85 KB
/
CacheTypes.bsv
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
import Vector::*; // Vector library distributed as part of the Bluespec compiler
import Common::*;
import MemoryTypes::*;
// Types used in the Cache
////////////////////////////////////////
//// Cache Sizes
typedef 10 LogMaxNumCacheLines;
// We have 64 cache lines. We need the log base 2 of that number to get the
// index size for the cache.
// typedef 6 LogNumCacheLines;
//// Data Types
typedef Bit#(32) Word;
typedef Vector#(16, Word) Line; // 16*32 = 512 bits wide cache lines
//// Address Types
// The cache index is used to index into the cache lines
// the cache index size is sized to maximum cache size
typedef Bit#(LogMaxNumCacheLines) CacheIndex;
// There are 16 words per line, so the word offset is log_2(16) = 4 bits wide
typedef Bit#(4) WordOffset;
// tag size + index size + word offset size + byte offset size = 32,
// so the maximum tag size is
// 32 - 0 (minimum index size) - 4 (word offset size) - 2 (byte offset size) = 26
typedef Bit#(26) CacheTag;
// The line address is just the portion of the byte address used to select lines from main memory.
// The line address is equal to the tag and index concatenated together
// or 32 minus word offset size minus byte offset size
typedef Bit#(26) LineAddr; // 20 + 6 or 32 - 4 - 2
//// Additional Cache types
// Status for each cache line:
// Invalid - the current line is invalid.
// Clean - the current line is valid, and the value hasn't changed since it was read from main memory.
// Dirty - the current line is valid, but has been written to since it was read from main memory.
typedef enum { Invalid = 0, Clean = 1, Dirty = 2 } CacheStatus deriving (Bits, Eq, FShow);
// TaggedLine is a combination of the data, the tag, and the status of the cache line
typedef struct {
Line line;
CacheStatus status;
CacheTag tag;
} TaggedLine deriving (Bits, Eq, FShow);
// Memory Request Types
////////////////////////////////////////
// LineReq is a line-based memory request. Addresses are all line addresses and
// the data is a line.
typedef struct {
MemOp op;
LineAddr lineAddr;
Line data;
} LineReq deriving(Bits, Eq, FShow);
// Address Helper Functions
////////////////////////////////////////
// function CacheIndex getIndex(Word byteAddress) = truncate(byteAddress>>6);
// function CacheTag getTag(Word byteAddress) = truncateLSB(byteAddress);
function WordOffset getWordOffset(Word byteAddress) = truncate(byteAddress >> 2);
interface Cache#(numeric type logNumLines);
// methods for the processor to interact with the cache
method Action req(MemReq req);
method ActionValue#(Word) resp();
// methods for the cache to interact with DRAM
method ActionValue#(LineReq) lineReq;
method Action lineResp(Line r);
// methods for getting the cache hit and miss counts
method Bit#(32) getHitCount;
method Bit#(32) getMissCount;
endinterface