-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCompress_methods.v
228 lines (197 loc) · 5.69 KB
/
Compress_methods.v
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
`include "DECOMPRESSIONUNIT.v"
//First method: NOP
module FIRSTMETHOD(
clk,
rst_n,
PC_1,
INSTR,
PC_add,
INSTR_o
);
// === I/O ===
input PC_1; //PC[1] for checking if now using half block
input [31:0] INSTR; //the whole block fetched from cache/memory
output [31:0] PC_add; //addition to PC for next stage
output [31:0] INSTR_o; //Instruction send to ID-stage
// === Wires ===
reg [31:0] INSTR_o;
wire [31:0] INSTR_d;
reg [15:0] INSTR_c;
reg [15:0] INSTR_save_r, INSTR_save_w;
//reg [31:0] PC_r, PC_w;
reg [31:0] PC_add;
reg stall_r, stall_w;
/*
INSTR: original instruction(in little endian)
INSTR_o: output instruction(in common order)
INSTR_c: compressed instruction(in common order)
INSTR_d: decompressed instruction(in common order)
INSTR_save_r, INSTR_save_w: saved instruction for the next 16-bit for a complete 32-bit instruction(in common order)
*/
/* ------ Current Scheme --------
---------
|CURRENT|
| P C |
---------
-------- --------|--------
| | 32-bit | |
-------- --------|--------
32-bit instruction
<------------------|
Above condition will need an NOP
(Because not enough information
for the whole 32-bit instruction)
Might be optimized in some way?
-------------------------------*/
DecompressionUnit DU1(.orig_instr(INSTR_c), .decomp_instr(INSTR_d));
always@(*) begin
PC_add = 0;
INSTR_o = 32'b0;
INSTR_c = 16'b0;
INSTR_save_w = 16'b0;
stall_w = 1'b0;
if ( stall_r ) begin
PC_add = 0; //PC_w = PC_r;
INSTR_o = { INSTR[23:16], INSTR[31:24], INSTR_save_r };
stall_w = 1'b0;
end else begin
if ( PC_1 ) begin
//Half block
if ( &INSTR[25:24] ) begin
//32-bit instruction
PC_add = 4; //PC_w = PC_r + 4;
INSTR_o = { INSTR[7:0], INSTR[15:8], INSTR[23:16], INSTR[31:24] };
end else begin
//16-bit instruction
PC_add = 2; //PC_w = PC_r + 2;
INSTR_c = { INSTR[23:16], INSTR[31:24] }; //16-bit
INSTR_o = INSTR_d;
end
end else begin
//Complete block
if ( &INSTR[9:8] ) begin
//32-bit instruction
PC_add = 4; //PC_w = PC_r + 4;
INSTR_o = 32'h00_00_00_13; //NOP
stall_w = 1'b1;
INSTR_save_w = { INSTR[7:0], INSTR[15:8] }; //Save pre-switched operations
end else begin
//16-bit instruction
PC_add = 2; //PC_w = PC_r + 2;
INSTR_c = { INSTR[7:0], INSTR[15:8] }; //16-bit
INSTR_o = INSTR_d;
end
end
end
end
always @(posedge clk or negedge rst_n) begin
if(~rst_n) begin
INSTR_save_r <= 16'b0;
stall_r <= 1'b0;
end else begin
INSTR_save_r <= INSTR_save_w;
stall_r <= stall_w;
end
end
endmodule
//Second Method: Pre-feed PC to obtain new information
module SECONDMETHOD(
clk,
rst_n,
PCN_1,
INSTR,
PCN_add,
PC_add,
INSTR_o
);
// === I/O ===
input PCN_1; //PC[1] for checking if now using half block
input [31:0] INSTR; //the whole block fetched from cache/memory
output [31:0] PCN_add; //addition to PC for next stage
output [31:0] PC_add; //addition to PC for next cycle
output [31:0] INSTR_o; //Instruction send to ID-stage
// === Wires ===
reg [31:0] INSTR_o;
wire [31:0] INSTR_d;
reg [15:0] INSTR_c;
reg [15:0] INSTR_save_r, INSTR_save_w;
reg [31:0] PCN_add, PC_add;
reg flag_r, flag_w; //to examine if current instruction is a 32-bit starting from a half block
/*
INSTR: original instruction(in little endian)
INSTR_o: output instruction(in common order)
INSTR_c: compressed instruction(in common order)
INSTR_d: decompressed instruction(in common order)
INSTR_save_r, INSTR_save_w: saved instruction for the next 16-bit for a complete 32-bit instruction(in common order)
*/
/* ---------- Current Scheme ----------
Still remain problems with Branch, Jump
-------------------------------------*/
DecompressionUnit DU1(.orig_instr(INSTR_c), .decomp_instr(INSTR_d));
always@(*) begin
PCN_add = 0;
PC_add = 0;
INSTR_o = 32'b0;
INSTR_c = 16'b0;
INSTR_save_w = 16'b0;
flag_w = flag_r;
if ( PCN_1 ) begin
//Complete block
if ( &INSTR[25:24] ) begin
//32-bit instruction
PCN_add = 4;
PC_add = 4;
INSTR_o = { INSTR[7:0], INSTR[15:8], INSTR[23:16], INSTR[31:24] };
flag_w = 1'b0;
end else begin
//16-bit instruction, need to check if next instruction is half block
PCN_add = 2; //original PC
INSTR_c = { INSTR[23:16], INSTR[31:24] };
if ( &INSTR[9:8] ) begin
//The next instruction is 32-bit, need to pre-feed PC to avoid NOP
PC_add = 4; //pre-call PC for new informations
INSTR_save_w = { INSTR[7:0], INSTR[15:8] };
flag_w = 1'b1;
end else begin
//The next instruction is 16-bit, commonly finish the task
PC_add = 2;
flag_w = 1'b0;
end
end
end else begin
//Half block
if ( flag_r ) begin
//32-bit instruction
PCN_add = 4;
INSTR_o = { INSTR[23:16], INSTR[31:24], INSTR_save_r };
if ( INSTR[9:8] ) begin
//The next instruction is still 32-bit, continue pre-feed
PC_add = 4;
INSTR_save_w = { INSTR[7:0], INSTR[15:8] };
flag_w = 1'b1;
end else begin
//The next instruction is 16-bit, back to original
PC_add = 2; //back to original PC-feeding
flag_w = 1'b0;
end
end else begin
//16-bit instruction
PCN_add = 2;
PC_add = 2;
INSTR_c = { INSTR[7:0], INSTR[15:8] };
INSTR_o = INSTR_d;
flag_w = 1'b0;
end
end
end
always @(posedge clk or negedge rst_n) begin
if(~rst_n) begin
INSTR_save_r <= 16'b0;
flag_r <= 1'b0;
end else begin
INSTR_save_r <= INSTR_save_w;
flag_r <= flag_w;
end
end
endmodule
//Third Method: Half-block cache