-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmesi.h
102 lines (96 loc) · 2.97 KB
/
mesi.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
// MESI_H_
#ifndef _MESI_H_
#define _MESI_H_
#include "protocol.h"
using namespace std;
class mesi: public Protocol{
public:
mesi(){
cerr<<"MESI constructor"<<endl;
write_back_based_protocol = true;
}
~mesi(){
cerr<<"MESI destructor"<<endl;
}
tuple<char, bool, bool> next_state(int operation, char curr_state, bool exclusive){
char output;
bool write_back = false;
bool respond = false;
switch(curr_state){
case 'm' :{
switch (operation){
case PROC_READ_FROM_CACHE: output = 'm'; break;
// case PROC_READ_FROM_MEM: output = 'm'; break; /* impossible state */
case PROC_WRITE: output = 'm'; break;
case BUS_READ: output = 's'; write_back = true; respond = true; break;
case BUS_WRITE: output = 'i'; write_back = false; respond = false; break;
default: cerr<<"invalid operation"<<endl; break;
}
break;
}
case 'e' :{
switch (operation){
case PROC_READ_FROM_CACHE: output = 'e'; break;
// case PROC_READ_FROM_MEM: output = 's'; break; /* impossible state */
case PROC_WRITE: output = 'm'; break;
case BUS_READ: output = 's'; write_back = false; respond = true; break;
case BUS_WRITE: output = 'i'; write_back = false; respond = false; break;
default: cerr<<"invalid operation"<<endl; break;
}
break;
}
case 's' :{
switch (operation){
case PROC_READ_FROM_CACHE: output = 's'; break;
// case PROC_READ_FROM_MEM: output = 's'; break; /* impossible state */
case PROC_WRITE: output = 'm'; break;
case BUS_READ: output = 's'; write_back = false; respond = true; break;
case BUS_WRITE: output = 'i'; write_back = false; respond = false; break;
default: cerr<<"invalid operation"<<endl; break;
}
break;
}
case 'i' :{
switch (operation){
case PROC_READ_FROM_CACHE: output = 's'; break;
case PROC_READ_FROM_MEM: output = 'e'; break;
case PROC_WRITE: output = 'm'; break;
case BUS_READ: output = 'i'; write_back = false; respond = false; break;
case BUS_WRITE: output = 'i'; write_back = false; respond = false; break;
default: cerr<<"invalid operation"<<endl; break;
}
break;
}
default: cerr<<"invalid curr state"<<endl; break;
}
return tuple<char, bool, bool>(output, write_back, respond);
}
bool hit(int operation, char curr_state){
bool hit;
switch (curr_state){
case 'm':{
hit = true;
break;
}
case 'e':{
hit = true;
break;
}
case 's':{
hit = (operation == READ);
break;
}
case 'i':{
hit = false;
break;
}
default: cerr<<"invalid curr state"<<endl; break;
}
return hit;
}
bool dirty(char state){
return state == 'm';
}
private:
};
#endif // _MESI_H_