-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcache.h
More file actions
28 lines (23 loc) · 789 Bytes
/
cache.h
File metadata and controls
28 lines (23 loc) · 789 Bytes
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
#ifndef CACHE_H
#define CACHE_H
#include <stdbool.h>
typedef struct {
int tag;
int frequency; // For LFU
int accessTime; // For LRU
bool valid;
bool dirty; // For Write-Back
} CacheBlock;
typedef struct {
CacheBlock **sets;
int numSets;
int associativity;
int timeCounter;
char writePolicy[15]; // Write-Through or Write-Back
} Cache;
void initCache(Cache *cache, int cacheSize, int blockSize, int associativity, const char *writePolicy);
bool isHit(Cache *cache, int setIndex, int tag);
void replaceBlock(Cache *cache, int setIndex, int tag, const char *policy);
void accessCache(Cache *l1, Cache *l2, int address, int blockSize, const char *policy, int *l1Hits, int *l1Misses, int *l2Hits, int *l2Misses);
void freeCache(Cache *cache);
#endif