-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprefetcher.h
78 lines (63 loc) · 2.02 KB
/
prefetcher.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
#ifndef PREFETCHER_H
#define PREFETCHER_H
#define MAX_STATE_COUNT 256
#define MAX_REQUEST_COUNT 32
#define NULL_STATE 0xFFFF
#define L1_PREFETCH_DEGREE 1
#define L2_PREFETCH_DEGREE 4
#define L1_CACHE_BLOCK 32
#define L2_CACHE_BLOCK 64
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
#include <sys/types.h>
#include <stdio.h>
struct Request;
struct State {
u_int32_t pc; // PC of the state
u_int32_t addr; // Last access address
u_int16_t count; // Access counter
int16_t offset; // Access offset
u_int16_t ahead; // Accesses prefetched ahead
u_int16_t next; // Next state for LRU
};
class Prefetcher {
private:
// History state table - Size: sizeof(State) * MAX_STATE_COUNT
u_int32_t stateCount;
u_int32_t stateHead;
State historyState[MAX_STATE_COUNT];
// Local request queue
u_int32_t frontRequest;
u_int32_t rearRequest;
u_int32_t localRequest[MAX_REQUEST_COUNT];
// History state table operations
void initHistoryState();
bool ifEmptyHistoryState();
bool ifFullHistoryState();
void insertHistoryState(u_int32_t, u_int32_t, u_int16_t, int16_t, u_int16_t);
u_int16_t queryHistoryState(u_int32_t);
u_int16_t getSecondLRUState();
// Local request queue operations
void initLocalRequest();
bool ifEmptyLocalRequest();
bool ifFullLocalRequest();
bool enLocalRequest(u_int32_t);
u_int32_t deLocalRequest();
u_int32_t getFrontLocalRequest();
bool ifAlreadyInQueue(u_int32_t);
public:
// Construction function
Prefetcher();
// should return true if a request is ready for this cycle
bool hasRequest(u_int32_t cycle);
// request a desired address be brought in
Request getRequest(u_int32_t cycle);
// this function is called whenever the last prefetcher request was successfully sent to the L2
void completeRequest(u_int32_t cycle);
/*
* This function is called whenever the CPU references memory.
* Note that only the addr, pc, load, issuedAt, and HitL1 should be considered valid data
*/
void cpuRequest(Request req);
};
#endif