-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcache.h
More file actions
68 lines (56 loc) · 1.96 KB
/
cache.h
File metadata and controls
68 lines (56 loc) · 1.96 KB
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
#ifndef __CACHE_H
#define __CACHE_H
#include "trace.h"
// Forward declaration of types:
typedef struct LRUNode LRUNode;
typedef struct Line Line;
typedef struct Set Set;
typedef struct Cache Cache;
typedef struct LRUResult LRUResult;
/*** General Cache Data Structures ***/
// This represents a result of accessing the cache.
// Was it a "hit" or a "miss".
enum AccessResult { HIT, COLD_MISS, CONFLICT_MISS };
typedef enum AccessResult AccessResult;
/*** LRU Data Structures ***/
// Represents a node in the LRU queue/stack linked list.
struct LRUNode {
Line *line;
LRUNode *next;
};
// Represents the result returned from accessing the LRU queue/stack.
struct LRUResult {
Line *line;
AccessResult access;
};
/*** Cache Data Structures ***/
// A Line represents a line in the cache.
struct Line {
char valid; // is the line valid? Treat this as a boolean value,
// something "truth-y" is true, something "false-y" is false
unsigned int tag; // the tag
char *accessed; // the accessed bits
int block_size; // the number of bytes
};
// A Set represents a set in the cache.
struct Set {
Line *lines; // The lines in the set
int line_count; // The number of lines
LRUNode *lru_queue; // The LRU queue/stack associated with the set
};
// A Cache represents the state of the cache.
struct Cache {
Set *sets; // The sets in the cache
int set_count; // The number of sets
int line_count; // The number of lines
int block_size; // The number of bytes per block
int set_bits; // The number of bits used to index a set in the cache
int block_bits; // The number of bits used to index a byte in a block
};
Cache *make_cache(int set_count, int line_count, int block_size);
void delete_cache(Cache *cache);
int get_set(Cache *cache, address_type address);
int get_line(Cache *cache, address_type address);
int get_byte(Cache *cache, address_type address);
AccessResult cache_access(Cache *cache, TraceLine *trace_line);
#endif