-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand.hpp
More file actions
153 lines (130 loc) · 2.73 KB
/
command.hpp
File metadata and controls
153 lines (130 loc) · 2.73 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
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#ifndef COMMAND
#define COMMAND
#include <iostream>
#include "enum.hpp"
#include "ultility.hpp"
class _com {
int opcode;
public:
_com(int _opcode) :opcode(_opcode) {}
virtual bool getreg() {
return true;
}
};
class _com_R : public _com {
int funct7, rs2, rs1, funct3, rd;
_R_type type;
public:
_com_R(int cod, _R_type typ) : _com(get(0, 6, cod)), type(typ) {
rd = get(7, 11, cod);
funct3 = get(12, 14, cod);
rs1 = get(15, 19, cod);
rs2 = get(20, 24, cod);
funct7 = get(25, 31, cod);
}
virtual bool getreg() {
if (lock[rs1] || lock[rs2]) return false;
DX.A = x[rs1];
DX.B = x[rs2];
DX.imm = 0;
DX.type = type;
lock[rd]++;
return true;
}
};
class _com_I : public _com {
int imm, rs1, funct3, rd;
_I_type type;
public:
_com_I(int cod, _I_type typ) :_com(get(0, 6, cod)), type(typ) {
rd = get(7, 11, cod);
funct3 = get(12, 14, cod);
rs1 = get(15, 19, cod);
imm = get(20, 31, cod) << 20 >> 20;
}
virtual bool getreg() {
if (lock[rs1]) return false;
DX.A = x[rs1];
DX.B = 0;
DX.imm = imm;
DX.type = type;
lock[rd]++;
return true;
}
};
class _com_S : public _com {
int imm, rs2, rs1, funct3;
_S_type type;
public:
_com_S(int cod, _S_type typ) :_com(get(0, 6, cod)), type(typ) {
funct3 = get(12, 14, cod);
rs1 = get(15, 19, cod);
rs2 = get(20, 24, cod);
imm = link(get(25, 31, cod), 7, get(7, 11, cod), 5);
}
virtual bool getreg() {
if (lock[rs1] || lock[rs2]) return false;
DX.A = x[rs1];
DX.B = x[rs2];
DX.imm = imm;
DX.type = type;
return true;
}
};
class _com_SB : public _com {
int imm, rs2, rs1, funct3;
_SB_type type;
public:
_com_SB(int cod, _SB_type typ) :_com(get(0, 6, cod)), type(typ) {
funct3 = get(12, 14, cod);
rs1 = get(15, 19, cod);
rs2 = get(20, 24, cod);
imm = link(get(31, 31, cod), 1, get(7, 7, cod), 1, get(25, 30, cod), 6, get(8, 11, cod), 4);
imm = imm << 1;
}
virtual bool getreg() {
if (lock[rs1] || lock[rs2]) return false;
DX.A = x[rs1];
DX.B = x[rs2];
DX.imm = imm;
DX.type = type;
return true;
}
};
class _com_U : public _com {
int imm, rd;
_U_type type;
public:
_com_U(int cod, _U_type typ) :_com(get(0, 6, cod)), type(typ) {
rd = get(7, 11, cod);
imm = get(12, 31, cod);
imm = imm << 12;
}
virtual bool getreg() {
DX.A = 0;
DX.B = 0;
DX.imm = imm;
DX.type = type;
lock[rd]++;
return true;
}
};
class _com_UJ : public _com {
int imm, rd;
_UJ_type type;
public:
_com_UJ(int cod, _UJ_type typ) :_com(get(0, 6, cod)), type(typ) {
rd = get(7, 11, cod);
imm = link(get(31, 31, cod), 1, get(12, 19, cod), 8, get(20, 20, cod), 1, get(21, 30, cod), 10);
imm = imm << 1;
}
virtual bool getreg() {
DX.A = 0;
DX.B = 0;
DX.imm = imm;
DX.type = type;
lock[rd]++;
return true;
}
};
#endif // !COMMAND