-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcache.h
128 lines (100 loc) · 2.88 KB
/
cache.h
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#ifndef CACHE_H
#define CACHE_H
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <stdbool.h>
#include <string.h>
#define TRUE 1
#define FALSE 0
/* default cache parameters--can be changed */
#define WORD_SIZE 4
#define WORD_SIZE_OFFSET 2
#define DEFAULT_CACHE_SIZE (8 * 1024)
#define DEFAULT_CACHE_BLOCK_SIZE 16
#define DEFAULT_CACHE_ASSOC 1
#define DEFAULT_CACHE_WRITEBACK TRUE
#define DEFAULT_CACHE_WRITEALLOC TRUE
/* constants for settting cache parameters */
#define CACHE_PARAM_BLOCK_SIZE 0
#define CACHE_PARAM_USIZE 1
#define CACHE_PARAM_ISIZE 2
#define CACHE_PARAM_DSIZE 3
#define CACHE_PARAM_ASSOC 4
#define CACHE_PARAM_WRITEBACK 5
#define CACHE_PARAM_WRITETHROUGH 6
#define CACHE_PARAM_WRITEALLOC 7
#define CACHE_PARAM_NOWRITEALLOC 8
int cache_split;
int cache_usize;
int cache_isize;
int cache_dsize;
int cache_block_size[2];
int words_per_block[2];
int cache_assoc[2];
int cache_writeback[2];
int cache_writealloc[2];
/* structure definitions */
typedef struct cache_line_ {
unsigned tag;
int dirty;
struct cache_line_ *LRU_next;
struct cache_line_ *LRU_prev;
} cache_line, *Pcache_line;
typedef struct cache_ {
int size; /* cache size */
int associativity; /* cache associativity */
int n_sets; /* number of cache sets */
unsigned index_mask; /* mask to find cache index */
int index_mask_offset; /* number of zero bits in mask */
Pcache_line *LRU_head; /* head of LRU list for each set */
Pcache_line *LRU_tail; /* tail of LRU list for each set */
int *set_contents; /* number of valid entries in set */
int contents; /* number of valid entries in cache */
} cache, *Pcache;
typedef struct cache_stat_ {
int accesses; /* number of memory references */
int misses; /* number of cache misses */
int replacements; /* number of misses that cause replacments */
int demand_fetches; /* number of fetches */
int copies_back; /* number of write backs */
} cache_stat, *Pcache_stat;
char** c;
int** tag;
bool** v;
bool** dirty;
int** lru;
int tagbits[2],indxbits[2],blockbits[2];//number of bits for tag,index,block offset.
int numsets[2],setsize[2];
int numiref,numdref;
int numimiss,numdmiss;
int mcur[2];
int numireplace,numdreplace;
int demand_fetches[2],copies_back[2];
unsigned t1, indx;
unsigned t2, bo;
unsigned atag;
unsigned end;
/* function prototypes */
void set_default();
void set_cache_param(int param,int value);
void init_vars();
void init_cache();
void perform_access(unsigned addr,unsigned access_type);
void flush(int u);
void delete();
void insert();
void dump_settings();
void print_stats();
void write_to_cache(int u,int idx);
void read_from_cache(int u,int idx);
void write_to_MM(unsigned addr);
void read_from_MM(unsigned addr);
void block_write(int u,int mini);
void block_read(int u,int mini);
char* MMi;
char* MMd;
char read_data,write_data;
/* macros */
#define LOG2(x) ((int) rint((log((double) (x))) / (log(2.0))))
#endif