1 |
48 |
alirezamon |
// ==================================================================
|
2 |
|
|
// >>>>>>>>>>>>>>>>>>>>>>> COPYRIGHT NOTICE <<<<<<<<<<<<<<<<<<<<<<<<<
|
3 |
|
|
// ------------------------------------------------------------------
|
4 |
|
|
// Copyright (c) 2006-2011 by Lattice Semiconductor Corporation
|
5 |
|
|
// ALL RIGHTS RESERVED
|
6 |
|
|
// ------------------------------------------------------------------
|
7 |
|
|
//
|
8 |
|
|
// IMPORTANT: THIS FILE IS AUTO-GENERATED BY THE LATTICEMICO SYSTEM.
|
9 |
|
|
//
|
10 |
|
|
// Permission:
|
11 |
|
|
//
|
12 |
|
|
// Lattice Semiconductor grants permission to use this code
|
13 |
|
|
// pursuant to the terms of the Lattice Semiconductor Corporation
|
14 |
|
|
// Open Source License Agreement.
|
15 |
|
|
//
|
16 |
|
|
// Disclaimer:
|
17 |
|
|
//
|
18 |
|
|
// Lattice Semiconductor provides no warranty regarding the use or
|
19 |
|
|
// functionality of this code. It is the user's responsibility to
|
20 |
|
|
// verify the user's design for consistency and functionality through
|
21 |
|
|
// the use of formal verification methods.
|
22 |
|
|
//
|
23 |
|
|
// --------------------------------------------------------------------
|
24 |
|
|
//
|
25 |
|
|
// Lattice Semiconductor Corporation
|
26 |
|
|
// 5555 NE Moore Court
|
27 |
|
|
// Hillsboro, OR 97214
|
28 |
|
|
// U.S.A
|
29 |
|
|
//
|
30 |
|
|
// TEL: 1-800-Lattice (USA and Canada)
|
31 |
|
|
// 503-286-8001 (other locations)
|
32 |
|
|
//
|
33 |
|
|
// web: http://www.latticesemi.com/
|
34 |
|
|
// email: techsupport@latticesemi.com
|
35 |
|
|
//
|
36 |
|
|
// --------------------------------------------------------------------
|
37 |
|
|
// FILE DETAILS
|
38 |
|
|
// Project : LatticeMico32
|
39 |
|
|
// File : lm32_decoder.v
|
40 |
|
|
// Title : Instruction decoder
|
41 |
|
|
// Dependencies : lm32_include.v
|
42 |
|
|
// Version : 6.1.17
|
43 |
|
|
// : Initial Release
|
44 |
|
|
// Version : 7.0SP2, 3.0
|
45 |
|
|
// : No Change
|
46 |
|
|
// Version : 3.1
|
47 |
|
|
// : Support for static branch prediction. Information about
|
48 |
|
|
// : branch type is generated and passed on to the predictor.
|
49 |
|
|
// Version : 3.2
|
50 |
|
|
// : No change
|
51 |
|
|
// Version : 3.3
|
52 |
|
|
// : Renamed port names that conflict with keywords reserved
|
53 |
|
|
// : in System-Verilog.
|
54 |
|
|
// =============================================================================
|
55 |
|
|
|
56 |
|
|
`include "lm32_include.v"
|
57 |
|
|
|
58 |
|
|
// Index of opcode field in an instruction
|
59 |
|
|
`define LM32_OPCODE_RNG 31:26
|
60 |
|
|
`define LM32_OP_RNG 30:26
|
61 |
|
|
|
62 |
|
|
// Opcodes - Some are only listed as 5 bits as their MSB is a don't care
|
63 |
|
|
`define LM32_OPCODE_ADD 5'b01101
|
64 |
|
|
`define LM32_OPCODE_AND 5'b01000
|
65 |
|
|
`define LM32_OPCODE_ANDHI 6'b011000
|
66 |
|
|
`define LM32_OPCODE_B 6'b110000
|
67 |
|
|
`define LM32_OPCODE_BI 6'b111000
|
68 |
|
|
`define LM32_OPCODE_BE 6'b010001
|
69 |
|
|
`define LM32_OPCODE_BG 6'b010010
|
70 |
|
|
`define LM32_OPCODE_BGE 6'b010011
|
71 |
|
|
`define LM32_OPCODE_BGEU 6'b010100
|
72 |
|
|
`define LM32_OPCODE_BGU 6'b010101
|
73 |
|
|
`define LM32_OPCODE_BNE 6'b010111
|
74 |
|
|
`define LM32_OPCODE_CALL 6'b110110
|
75 |
|
|
`define LM32_OPCODE_CALLI 6'b111110
|
76 |
|
|
`define LM32_OPCODE_CMPE 5'b11001
|
77 |
|
|
`define LM32_OPCODE_CMPG 5'b11010
|
78 |
|
|
`define LM32_OPCODE_CMPGE 5'b11011
|
79 |
|
|
`define LM32_OPCODE_CMPGEU 5'b11100
|
80 |
|
|
`define LM32_OPCODE_CMPGU 5'b11101
|
81 |
|
|
`define LM32_OPCODE_CMPNE 5'b11111
|
82 |
|
|
`define LM32_OPCODE_DIVU 6'b100011
|
83 |
|
|
`define LM32_OPCODE_LB 6'b000100
|
84 |
|
|
`define LM32_OPCODE_LBU 6'b010000
|
85 |
|
|
`define LM32_OPCODE_LH 6'b000111
|
86 |
|
|
`define LM32_OPCODE_LHU 6'b001011
|
87 |
|
|
`define LM32_OPCODE_LW 6'b001010
|
88 |
|
|
`define LM32_OPCODE_MODU 6'b110001
|
89 |
|
|
`define LM32_OPCODE_MUL 5'b00010
|
90 |
|
|
`define LM32_OPCODE_NOR 5'b00001
|
91 |
|
|
`define LM32_OPCODE_OR 5'b01110
|
92 |
|
|
`define LM32_OPCODE_ORHI 6'b011110
|
93 |
|
|
`define LM32_OPCODE_RAISE 6'b101011
|
94 |
|
|
`define LM32_OPCODE_RCSR 6'b100100
|
95 |
|
|
`define LM32_OPCODE_SB 6'b001100
|
96 |
|
|
`define LM32_OPCODE_SEXTB 6'b101100
|
97 |
|
|
`define LM32_OPCODE_SEXTH 6'b110111
|
98 |
|
|
`define LM32_OPCODE_SH 6'b000011
|
99 |
|
|
`define LM32_OPCODE_SL 5'b01111
|
100 |
|
|
`define LM32_OPCODE_SR 5'b00101
|
101 |
|
|
`define LM32_OPCODE_SRU 5'b00000
|
102 |
|
|
`define LM32_OPCODE_SUB 6'b110010
|
103 |
|
|
`define LM32_OPCODE_SW 6'b010110
|
104 |
|
|
`define LM32_OPCODE_USER 6'b110011
|
105 |
|
|
`define LM32_OPCODE_WCSR 6'b110100
|
106 |
|
|
`define LM32_OPCODE_XNOR 5'b01001
|
107 |
|
|
`define LM32_OPCODE_XOR 5'b00110
|
108 |
|
|
|
109 |
|
|
/////////////////////////////////////////////////////
|
110 |
|
|
// Module interface
|
111 |
|
|
/////////////////////////////////////////////////////
|
112 |
|
|
|
113 |
|
|
module lm32_decoder (
|
114 |
|
|
// ----- Inputs -------
|
115 |
|
|
instruction,
|
116 |
|
|
// ----- Outputs -------
|
117 |
|
|
d_result_sel_0,
|
118 |
|
|
d_result_sel_1,
|
119 |
|
|
x_result_sel_csr,
|
120 |
|
|
`ifdef LM32_MC_ARITHMETIC_ENABLED
|
121 |
|
|
x_result_sel_mc_arith,
|
122 |
|
|
`endif
|
123 |
|
|
`ifdef LM32_NO_BARREL_SHIFT
|
124 |
|
|
x_result_sel_shift,
|
125 |
|
|
`endif
|
126 |
|
|
`ifdef CFG_SIGN_EXTEND_ENABLED
|
127 |
|
|
x_result_sel_sext,
|
128 |
|
|
`endif
|
129 |
|
|
x_result_sel_logic,
|
130 |
|
|
`ifdef CFG_USER_ENABLED
|
131 |
|
|
x_result_sel_user,
|
132 |
|
|
`endif
|
133 |
|
|
x_result_sel_add,
|
134 |
|
|
m_result_sel_compare,
|
135 |
|
|
`ifdef CFG_PL_BARREL_SHIFT_ENABLED
|
136 |
|
|
m_result_sel_shift,
|
137 |
|
|
`endif
|
138 |
|
|
w_result_sel_load,
|
139 |
|
|
`ifdef CFG_PL_MULTIPLY_ENABLED
|
140 |
|
|
w_result_sel_mul,
|
141 |
|
|
`endif
|
142 |
|
|
x_bypass_enable,
|
143 |
|
|
m_bypass_enable,
|
144 |
|
|
read_enable_0,
|
145 |
|
|
read_idx_0,
|
146 |
|
|
read_enable_1,
|
147 |
|
|
read_idx_1,
|
148 |
|
|
write_enable,
|
149 |
|
|
write_idx,
|
150 |
|
|
immediate,
|
151 |
|
|
branch_offset,
|
152 |
|
|
load,
|
153 |
|
|
store,
|
154 |
|
|
size,
|
155 |
|
|
sign_extend,
|
156 |
|
|
adder_op,
|
157 |
|
|
logic_op,
|
158 |
|
|
`ifdef CFG_PL_BARREL_SHIFT_ENABLED
|
159 |
|
|
direction,
|
160 |
|
|
`endif
|
161 |
|
|
`ifdef CFG_MC_BARREL_SHIFT_ENABLED
|
162 |
|
|
shift_left,
|
163 |
|
|
shift_right,
|
164 |
|
|
`endif
|
165 |
|
|
`ifdef CFG_MC_MULTIPLY_ENABLED
|
166 |
|
|
multiply,
|
167 |
|
|
`endif
|
168 |
|
|
`ifdef CFG_MC_DIVIDE_ENABLED
|
169 |
|
|
divide,
|
170 |
|
|
modulus,
|
171 |
|
|
`endif
|
172 |
|
|
branch,
|
173 |
|
|
branch_reg,
|
174 |
|
|
condition,
|
175 |
|
|
bi_conditional,
|
176 |
|
|
bi_unconditional,
|
177 |
|
|
`ifdef CFG_DEBUG_ENABLED
|
178 |
|
|
break_opcode,
|
179 |
|
|
`endif
|
180 |
|
|
scall,
|
181 |
|
|
eret,
|
182 |
|
|
`ifdef CFG_DEBUG_ENABLED
|
183 |
|
|
bret,
|
184 |
|
|
`endif
|
185 |
|
|
`ifdef CFG_USER_ENABLED
|
186 |
|
|
user_opcode,
|
187 |
|
|
`endif
|
188 |
|
|
csr_write_enable
|
189 |
|
|
);
|
190 |
|
|
|
191 |
|
|
/////////////////////////////////////////////////////
|
192 |
|
|
// Inputs
|
193 |
|
|
/////////////////////////////////////////////////////
|
194 |
|
|
|
195 |
|
|
input [`LM32_INSTRUCTION_RNG] instruction; // Instruction to decode
|
196 |
|
|
|
197 |
|
|
/////////////////////////////////////////////////////
|
198 |
|
|
// Outputs
|
199 |
|
|
/////////////////////////////////////////////////////
|
200 |
|
|
|
201 |
|
|
output [`LM32_D_RESULT_SEL_0_RNG] d_result_sel_0;
|
202 |
|
|
reg [`LM32_D_RESULT_SEL_0_RNG] d_result_sel_0;
|
203 |
|
|
output [`LM32_D_RESULT_SEL_1_RNG] d_result_sel_1;
|
204 |
|
|
reg [`LM32_D_RESULT_SEL_1_RNG] d_result_sel_1;
|
205 |
|
|
output x_result_sel_csr;
|
206 |
|
|
reg x_result_sel_csr;
|
207 |
|
|
`ifdef LM32_MC_ARITHMETIC_ENABLED
|
208 |
|
|
output x_result_sel_mc_arith;
|
209 |
|
|
reg x_result_sel_mc_arith;
|
210 |
|
|
`endif
|
211 |
|
|
`ifdef LM32_NO_BARREL_SHIFT
|
212 |
|
|
output x_result_sel_shift;
|
213 |
|
|
reg x_result_sel_shift;
|
214 |
|
|
`endif
|
215 |
|
|
`ifdef CFG_SIGN_EXTEND_ENABLED
|
216 |
|
|
output x_result_sel_sext;
|
217 |
|
|
reg x_result_sel_sext;
|
218 |
|
|
`endif
|
219 |
|
|
output x_result_sel_logic;
|
220 |
|
|
reg x_result_sel_logic;
|
221 |
|
|
`ifdef CFG_USER_ENABLED
|
222 |
|
|
output x_result_sel_user;
|
223 |
|
|
reg x_result_sel_user;
|
224 |
|
|
`endif
|
225 |
|
|
output x_result_sel_add;
|
226 |
|
|
reg x_result_sel_add;
|
227 |
|
|
output m_result_sel_compare;
|
228 |
|
|
reg m_result_sel_compare;
|
229 |
|
|
`ifdef CFG_PL_BARREL_SHIFT_ENABLED
|
230 |
|
|
output m_result_sel_shift;
|
231 |
|
|
reg m_result_sel_shift;
|
232 |
|
|
`endif
|
233 |
|
|
output w_result_sel_load;
|
234 |
|
|
reg w_result_sel_load;
|
235 |
|
|
`ifdef CFG_PL_MULTIPLY_ENABLED
|
236 |
|
|
output w_result_sel_mul;
|
237 |
|
|
reg w_result_sel_mul;
|
238 |
|
|
`endif
|
239 |
|
|
output x_bypass_enable;
|
240 |
|
|
wire x_bypass_enable;
|
241 |
|
|
output m_bypass_enable;
|
242 |
|
|
wire m_bypass_enable;
|
243 |
|
|
output read_enable_0;
|
244 |
|
|
wire read_enable_0;
|
245 |
|
|
output [`LM32_REG_IDX_RNG] read_idx_0;
|
246 |
|
|
wire [`LM32_REG_IDX_RNG] read_idx_0;
|
247 |
|
|
output read_enable_1;
|
248 |
|
|
wire read_enable_1;
|
249 |
|
|
output [`LM32_REG_IDX_RNG] read_idx_1;
|
250 |
|
|
wire [`LM32_REG_IDX_RNG] read_idx_1;
|
251 |
|
|
output write_enable;
|
252 |
|
|
wire write_enable;
|
253 |
|
|
output [`LM32_REG_IDX_RNG] write_idx;
|
254 |
|
|
wire [`LM32_REG_IDX_RNG] write_idx;
|
255 |
|
|
output [`LM32_WORD_RNG] immediate;
|
256 |
|
|
wire [`LM32_WORD_RNG] immediate;
|
257 |
|
|
output [`LM32_PC_RNG] branch_offset;
|
258 |
|
|
wire [`LM32_PC_RNG] branch_offset;
|
259 |
|
|
output load;
|
260 |
|
|
wire load;
|
261 |
|
|
output store;
|
262 |
|
|
wire store;
|
263 |
|
|
output [`LM32_SIZE_RNG] size;
|
264 |
|
|
wire [`LM32_SIZE_RNG] size;
|
265 |
|
|
output sign_extend;
|
266 |
|
|
wire sign_extend;
|
267 |
|
|
output adder_op;
|
268 |
|
|
wire adder_op;
|
269 |
|
|
output [`LM32_LOGIC_OP_RNG] logic_op;
|
270 |
|
|
wire [`LM32_LOGIC_OP_RNG] logic_op;
|
271 |
|
|
`ifdef CFG_PL_BARREL_SHIFT_ENABLED
|
272 |
|
|
output direction;
|
273 |
|
|
wire direction;
|
274 |
|
|
`endif
|
275 |
|
|
`ifdef CFG_MC_BARREL_SHIFT_ENABLED
|
276 |
|
|
output shift_left;
|
277 |
|
|
wire shift_left;
|
278 |
|
|
output shift_right;
|
279 |
|
|
wire shift_right;
|
280 |
|
|
`endif
|
281 |
|
|
`ifdef CFG_MC_MULTIPLY_ENABLED
|
282 |
|
|
output multiply;
|
283 |
|
|
wire multiply;
|
284 |
|
|
`endif
|
285 |
|
|
`ifdef CFG_MC_DIVIDE_ENABLED
|
286 |
|
|
output divide;
|
287 |
|
|
wire divide;
|
288 |
|
|
output modulus;
|
289 |
|
|
wire modulus;
|
290 |
|
|
`endif
|
291 |
|
|
output branch;
|
292 |
|
|
wire branch;
|
293 |
|
|
output branch_reg;
|
294 |
|
|
wire branch_reg;
|
295 |
|
|
output [`LM32_CONDITION_RNG] condition;
|
296 |
|
|
wire [`LM32_CONDITION_RNG] condition;
|
297 |
|
|
output bi_conditional;
|
298 |
|
|
wire bi_conditional;
|
299 |
|
|
output bi_unconditional;
|
300 |
|
|
wire bi_unconditional;
|
301 |
|
|
`ifdef CFG_DEBUG_ENABLED
|
302 |
|
|
output break_opcode;
|
303 |
|
|
wire break_opcode;
|
304 |
|
|
`endif
|
305 |
|
|
output scall;
|
306 |
|
|
wire scall;
|
307 |
|
|
output eret;
|
308 |
|
|
wire eret;
|
309 |
|
|
`ifdef CFG_DEBUG_ENABLED
|
310 |
|
|
output bret;
|
311 |
|
|
wire bret;
|
312 |
|
|
`endif
|
313 |
|
|
`ifdef CFG_USER_ENABLED
|
314 |
|
|
output [`LM32_USER_OPCODE_RNG] user_opcode;
|
315 |
|
|
wire [`LM32_USER_OPCODE_RNG] user_opcode;
|
316 |
|
|
`endif
|
317 |
|
|
output csr_write_enable;
|
318 |
|
|
wire csr_write_enable;
|
319 |
|
|
|
320 |
|
|
/////////////////////////////////////////////////////
|
321 |
|
|
// Internal nets and registers
|
322 |
|
|
/////////////////////////////////////////////////////
|
323 |
|
|
|
324 |
|
|
wire [`LM32_WORD_RNG] extended_immediate; // Zero or sign extended immediate
|
325 |
|
|
wire [`LM32_WORD_RNG] high_immediate; // Immediate as high 16 bits
|
326 |
|
|
wire [`LM32_WORD_RNG] call_immediate; // Call immediate
|
327 |
|
|
wire [`LM32_WORD_RNG] branch_immediate; // Conditional branch immediate
|
328 |
|
|
wire sign_extend_immediate; // Whether the immediate should be sign extended (`TRUE) or zero extended (`FALSE)
|
329 |
|
|
wire select_high_immediate; // Whether to select the high immediate
|
330 |
|
|
wire select_call_immediate; // Whether to select the call immediate
|
331 |
|
|
|
332 |
|
|
/////////////////////////////////////////////////////
|
333 |
|
|
// Functions
|
334 |
|
|
/////////////////////////////////////////////////////
|
335 |
|
|
|
336 |
|
|
/////////////////////////////////////////////////////
|
337 |
|
|
// Combinational logic
|
338 |
|
|
/////////////////////////////////////////////////////
|
339 |
|
|
|
340 |
|
|
// Determine opcode
|
341 |
|
|
assign op_add = instruction[`LM32_OP_RNG] == `LM32_OPCODE_ADD;
|
342 |
|
|
assign op_and = instruction[`LM32_OP_RNG] == `LM32_OPCODE_AND;
|
343 |
|
|
assign op_andhi = instruction[`LM32_OPCODE_RNG] == `LM32_OPCODE_ANDHI;
|
344 |
|
|
assign op_b = instruction[`LM32_OPCODE_RNG] == `LM32_OPCODE_B;
|
345 |
|
|
assign op_bi = instruction[`LM32_OPCODE_RNG] == `LM32_OPCODE_BI;
|
346 |
|
|
assign op_be = instruction[`LM32_OPCODE_RNG] == `LM32_OPCODE_BE;
|
347 |
|
|
assign op_bg = instruction[`LM32_OPCODE_RNG] == `LM32_OPCODE_BG;
|
348 |
|
|
assign op_bge = instruction[`LM32_OPCODE_RNG] == `LM32_OPCODE_BGE;
|
349 |
|
|
assign op_bgeu = instruction[`LM32_OPCODE_RNG] == `LM32_OPCODE_BGEU;
|
350 |
|
|
assign op_bgu = instruction[`LM32_OPCODE_RNG] == `LM32_OPCODE_BGU;
|
351 |
|
|
assign op_bne = instruction[`LM32_OPCODE_RNG] == `LM32_OPCODE_BNE;
|
352 |
|
|
assign op_call = instruction[`LM32_OPCODE_RNG] == `LM32_OPCODE_CALL;
|
353 |
|
|
assign op_calli = instruction[`LM32_OPCODE_RNG] == `LM32_OPCODE_CALLI;
|
354 |
|
|
assign op_cmpe = instruction[`LM32_OP_RNG] == `LM32_OPCODE_CMPE;
|
355 |
|
|
assign op_cmpg = instruction[`LM32_OP_RNG] == `LM32_OPCODE_CMPG;
|
356 |
|
|
assign op_cmpge = instruction[`LM32_OP_RNG] == `LM32_OPCODE_CMPGE;
|
357 |
|
|
assign op_cmpgeu = instruction[`LM32_OP_RNG] == `LM32_OPCODE_CMPGEU;
|
358 |
|
|
assign op_cmpgu = instruction[`LM32_OP_RNG] == `LM32_OPCODE_CMPGU;
|
359 |
|
|
assign op_cmpne = instruction[`LM32_OP_RNG] == `LM32_OPCODE_CMPNE;
|
360 |
|
|
`ifdef CFG_MC_DIVIDE_ENABLED
|
361 |
|
|
assign op_divu = instruction[`LM32_OPCODE_RNG] == `LM32_OPCODE_DIVU;
|
362 |
|
|
`endif
|
363 |
|
|
assign op_lb = instruction[`LM32_OPCODE_RNG] == `LM32_OPCODE_LB;
|
364 |
|
|
assign op_lbu = instruction[`LM32_OPCODE_RNG] == `LM32_OPCODE_LBU;
|
365 |
|
|
assign op_lh = instruction[`LM32_OPCODE_RNG] == `LM32_OPCODE_LH;
|
366 |
|
|
assign op_lhu = instruction[`LM32_OPCODE_RNG] == `LM32_OPCODE_LHU;
|
367 |
|
|
assign op_lw = instruction[`LM32_OPCODE_RNG] == `LM32_OPCODE_LW;
|
368 |
|
|
`ifdef CFG_MC_DIVIDE_ENABLED
|
369 |
|
|
assign op_modu = instruction[`LM32_OPCODE_RNG] == `LM32_OPCODE_MODU;
|
370 |
|
|
`endif
|
371 |
|
|
`ifdef LM32_MULTIPLY_ENABLED
|
372 |
|
|
assign op_mul = instruction[`LM32_OP_RNG] == `LM32_OPCODE_MUL;
|
373 |
|
|
`endif
|
374 |
|
|
assign op_nor = instruction[`LM32_OP_RNG] == `LM32_OPCODE_NOR;
|
375 |
|
|
assign op_or = instruction[`LM32_OP_RNG] == `LM32_OPCODE_OR;
|
376 |
|
|
assign op_orhi = instruction[`LM32_OPCODE_RNG] == `LM32_OPCODE_ORHI;
|
377 |
|
|
assign op_raise = instruction[`LM32_OPCODE_RNG] == `LM32_OPCODE_RAISE;
|
378 |
|
|
assign op_rcsr = instruction[`LM32_OPCODE_RNG] == `LM32_OPCODE_RCSR;
|
379 |
|
|
assign op_sb = instruction[`LM32_OPCODE_RNG] == `LM32_OPCODE_SB;
|
380 |
|
|
`ifdef CFG_SIGN_EXTEND_ENABLED
|
381 |
|
|
assign op_sextb = instruction[`LM32_OPCODE_RNG] == `LM32_OPCODE_SEXTB;
|
382 |
|
|
assign op_sexth = instruction[`LM32_OPCODE_RNG] == `LM32_OPCODE_SEXTH;
|
383 |
|
|
`endif
|
384 |
|
|
assign op_sh = instruction[`LM32_OPCODE_RNG] == `LM32_OPCODE_SH;
|
385 |
|
|
`ifdef LM32_BARREL_SHIFT_ENABLED
|
386 |
|
|
assign op_sl = instruction[`LM32_OP_RNG] == `LM32_OPCODE_SL;
|
387 |
|
|
`endif
|
388 |
|
|
assign op_sr = instruction[`LM32_OP_RNG] == `LM32_OPCODE_SR;
|
389 |
|
|
assign op_sru = instruction[`LM32_OP_RNG] == `LM32_OPCODE_SRU;
|
390 |
|
|
assign op_sub = instruction[`LM32_OPCODE_RNG] == `LM32_OPCODE_SUB;
|
391 |
|
|
assign op_sw = instruction[`LM32_OPCODE_RNG] == `LM32_OPCODE_SW;
|
392 |
|
|
assign op_user = instruction[`LM32_OPCODE_RNG] == `LM32_OPCODE_USER;
|
393 |
|
|
assign op_wcsr = instruction[`LM32_OPCODE_RNG] == `LM32_OPCODE_WCSR;
|
394 |
|
|
assign op_xnor = instruction[`LM32_OP_RNG] == `LM32_OPCODE_XNOR;
|
395 |
|
|
assign op_xor = instruction[`LM32_OP_RNG] == `LM32_OPCODE_XOR;
|
396 |
|
|
|
397 |
|
|
// Group opcodes by function
|
398 |
|
|
assign arith = op_add | op_sub;
|
399 |
|
|
assign logical = op_and | op_andhi | op_nor | op_or | op_orhi | op_xor | op_xnor;
|
400 |
|
|
assign cmp = op_cmpe | op_cmpg | op_cmpge | op_cmpgeu | op_cmpgu | op_cmpne;
|
401 |
|
|
assign bi_conditional = op_be | op_bg | op_bge | op_bgeu | op_bgu | op_bne;
|
402 |
|
|
assign bi_unconditional = op_bi;
|
403 |
|
|
assign bra = op_b | bi_unconditional | bi_conditional;
|
404 |
|
|
assign call = op_call | op_calli;
|
405 |
|
|
`ifdef LM32_BARREL_SHIFT_ENABLED
|
406 |
|
|
assign shift = op_sl | op_sr | op_sru;
|
407 |
|
|
`endif
|
408 |
|
|
`ifdef LM32_NO_BARREL_SHIFT
|
409 |
|
|
assign shift = op_sr | op_sru;
|
410 |
|
|
`endif
|
411 |
|
|
`ifdef CFG_MC_BARREL_SHIFT_ENABLED
|
412 |
|
|
assign shift_left = op_sl;
|
413 |
|
|
assign shift_right = op_sr | op_sru;
|
414 |
|
|
`endif
|
415 |
|
|
`ifdef CFG_SIGN_EXTEND_ENABLED
|
416 |
|
|
assign sext = op_sextb | op_sexth;
|
417 |
|
|
`endif
|
418 |
|
|
`ifdef LM32_MULTIPLY_ENABLED
|
419 |
|
|
assign multiply = op_mul;
|
420 |
|
|
`endif
|
421 |
|
|
`ifdef CFG_MC_DIVIDE_ENABLED
|
422 |
|
|
assign divide = op_divu;
|
423 |
|
|
assign modulus = op_modu;
|
424 |
|
|
`endif
|
425 |
|
|
assign load = op_lb | op_lbu | op_lh | op_lhu | op_lw;
|
426 |
|
|
assign store = op_sb | op_sh | op_sw;
|
427 |
|
|
|
428 |
|
|
// Select pipeline multiplexor controls
|
429 |
|
|
always @(*)
|
430 |
|
|
begin
|
431 |
|
|
// D stage
|
432 |
|
|
if (call)
|
433 |
|
|
d_result_sel_0 = `LM32_D_RESULT_SEL_0_NEXT_PC;
|
434 |
|
|
else
|
435 |
|
|
d_result_sel_0 = `LM32_D_RESULT_SEL_0_REG_0;
|
436 |
|
|
if (call)
|
437 |
|
|
d_result_sel_1 = `LM32_D_RESULT_SEL_1_ZERO;
|
438 |
|
|
else if ((instruction[31] == 1'b0) && !bra)
|
439 |
|
|
d_result_sel_1 = `LM32_D_RESULT_SEL_1_IMMEDIATE;
|
440 |
|
|
else
|
441 |
|
|
d_result_sel_1 = `LM32_D_RESULT_SEL_1_REG_1;
|
442 |
|
|
// X stage
|
443 |
|
|
x_result_sel_csr = `FALSE;
|
444 |
|
|
`ifdef LM32_MC_ARITHMETIC_ENABLED
|
445 |
|
|
x_result_sel_mc_arith = `FALSE;
|
446 |
|
|
`endif
|
447 |
|
|
`ifdef LM32_NO_BARREL_SHIFT
|
448 |
|
|
x_result_sel_shift = `FALSE;
|
449 |
|
|
`endif
|
450 |
|
|
`ifdef CFG_SIGN_EXTEND_ENABLED
|
451 |
|
|
x_result_sel_sext = `FALSE;
|
452 |
|
|
`endif
|
453 |
|
|
x_result_sel_logic = `FALSE;
|
454 |
|
|
`ifdef CFG_USER_ENABLED
|
455 |
|
|
x_result_sel_user = `FALSE;
|
456 |
|
|
`endif
|
457 |
|
|
x_result_sel_add = `FALSE;
|
458 |
|
|
if (op_rcsr)
|
459 |
|
|
x_result_sel_csr = `TRUE;
|
460 |
|
|
`ifdef LM32_MC_ARITHMETIC_ENABLED
|
461 |
|
|
`ifdef CFG_MC_BARREL_SHIFT_ENABLED
|
462 |
|
|
else if (shift_left | shift_right)
|
463 |
|
|
x_result_sel_mc_arith = `TRUE;
|
464 |
|
|
`endif
|
465 |
|
|
`ifdef CFG_MC_DIVIDE_ENABLED
|
466 |
|
|
else if (divide | modulus)
|
467 |
|
|
x_result_sel_mc_arith = `TRUE;
|
468 |
|
|
`endif
|
469 |
|
|
`ifdef CFG_MC_MULTIPLY_ENABLED
|
470 |
|
|
else if (multiply)
|
471 |
|
|
x_result_sel_mc_arith = `TRUE;
|
472 |
|
|
`endif
|
473 |
|
|
`endif
|
474 |
|
|
`ifdef LM32_NO_BARREL_SHIFT
|
475 |
|
|
else if (shift)
|
476 |
|
|
x_result_sel_shift = `TRUE;
|
477 |
|
|
`endif
|
478 |
|
|
`ifdef CFG_SIGN_EXTEND_ENABLED
|
479 |
|
|
else if (sext)
|
480 |
|
|
x_result_sel_sext = `TRUE;
|
481 |
|
|
`endif
|
482 |
|
|
else if (logical)
|
483 |
|
|
x_result_sel_logic = `TRUE;
|
484 |
|
|
`ifdef CFG_USER_ENABLED
|
485 |
|
|
else if (op_user)
|
486 |
|
|
x_result_sel_user = `TRUE;
|
487 |
|
|
`endif
|
488 |
|
|
else
|
489 |
|
|
x_result_sel_add = `TRUE;
|
490 |
|
|
|
491 |
|
|
// M stage
|
492 |
|
|
|
493 |
|
|
m_result_sel_compare = cmp;
|
494 |
|
|
`ifdef CFG_PL_BARREL_SHIFT_ENABLED
|
495 |
|
|
m_result_sel_shift = shift;
|
496 |
|
|
`endif
|
497 |
|
|
|
498 |
|
|
// W stage
|
499 |
|
|
w_result_sel_load = load;
|
500 |
|
|
`ifdef CFG_PL_MULTIPLY_ENABLED
|
501 |
|
|
w_result_sel_mul = op_mul;
|
502 |
|
|
`endif
|
503 |
|
|
end
|
504 |
|
|
|
505 |
|
|
// Set if result is valid at end of X stage
|
506 |
|
|
assign x_bypass_enable = arith
|
507 |
|
|
| logical
|
508 |
|
|
`ifdef CFG_MC_BARREL_SHIFT_ENABLED
|
509 |
|
|
| shift_left
|
510 |
|
|
| shift_right
|
511 |
|
|
`endif
|
512 |
|
|
`ifdef CFG_MC_MULTIPLY_ENABLED
|
513 |
|
|
| multiply
|
514 |
|
|
`endif
|
515 |
|
|
`ifdef CFG_MC_DIVIDE_ENABLED
|
516 |
|
|
| divide
|
517 |
|
|
| modulus
|
518 |
|
|
`endif
|
519 |
|
|
`ifdef LM32_NO_BARREL_SHIFT
|
520 |
|
|
| shift
|
521 |
|
|
`endif
|
522 |
|
|
`ifdef CFG_SIGN_EXTEND_ENABLED
|
523 |
|
|
| sext
|
524 |
|
|
`endif
|
525 |
|
|
`ifdef CFG_USER_ENABLED
|
526 |
|
|
| op_user
|
527 |
|
|
`endif
|
528 |
|
|
| op_rcsr
|
529 |
|
|
;
|
530 |
|
|
// Set if result is valid at end of M stage
|
531 |
|
|
assign m_bypass_enable = x_bypass_enable
|
532 |
|
|
`ifdef CFG_PL_BARREL_SHIFT_ENABLED
|
533 |
|
|
| shift
|
534 |
|
|
`endif
|
535 |
|
|
| cmp
|
536 |
|
|
;
|
537 |
|
|
// Register file read port 0
|
538 |
|
|
assign read_enable_0 = ~(op_bi | op_calli);
|
539 |
|
|
assign read_idx_0 = instruction[25:21];
|
540 |
|
|
// Register file read port 1
|
541 |
|
|
assign read_enable_1 = ~(op_bi | op_calli | load);
|
542 |
|
|
assign read_idx_1 = instruction[20:16];
|
543 |
|
|
// Register file write port
|
544 |
|
|
assign write_enable = ~(bra | op_raise | store | op_wcsr);
|
545 |
|
|
assign write_idx = call
|
546 |
|
|
? 5'd29
|
547 |
|
|
: instruction[31] == 1'b0
|
548 |
|
|
? instruction[20:16]
|
549 |
|
|
: instruction[15:11];
|
550 |
|
|
|
551 |
|
|
// Size of load/stores
|
552 |
|
|
assign size = instruction[27:26];
|
553 |
|
|
// Whether to sign or zero extend
|
554 |
|
|
assign sign_extend = instruction[28];
|
555 |
|
|
// Set adder_op to 1 to perform a subtraction
|
556 |
|
|
assign adder_op = op_sub | op_cmpe | op_cmpg | op_cmpge | op_cmpgeu | op_cmpgu | op_cmpne | bra;
|
557 |
|
|
// Logic operation (and, or, etc)
|
558 |
|
|
assign logic_op = instruction[29:26];
|
559 |
|
|
`ifdef CFG_PL_BARREL_SHIFT_ENABLED
|
560 |
|
|
// Shift direction
|
561 |
|
|
assign direction = instruction[29];
|
562 |
|
|
`endif
|
563 |
|
|
// Control flow microcodes
|
564 |
|
|
assign branch = bra | call;
|
565 |
|
|
assign branch_reg = op_call | op_b;
|
566 |
|
|
assign condition = instruction[28:26];
|
567 |
|
|
`ifdef CFG_DEBUG_ENABLED
|
568 |
|
|
assign break_opcode = op_raise & ~instruction[2];
|
569 |
|
|
`endif
|
570 |
|
|
assign scall = op_raise & instruction[2];
|
571 |
|
|
assign eret = op_b & (instruction[25:21] == 5'd30);
|
572 |
|
|
`ifdef CFG_DEBUG_ENABLED
|
573 |
|
|
assign bret = op_b & (instruction[25:21] == 5'd31);
|
574 |
|
|
`endif
|
575 |
|
|
`ifdef CFG_USER_ENABLED
|
576 |
|
|
// Extract user opcode
|
577 |
|
|
assign user_opcode = instruction[10:0];
|
578 |
|
|
`endif
|
579 |
|
|
// CSR read/write
|
580 |
|
|
assign csr_write_enable = op_wcsr;
|
581 |
|
|
|
582 |
|
|
// Extract immediate from instruction
|
583 |
|
|
|
584 |
|
|
assign sign_extend_immediate = ~(op_and | op_cmpgeu | op_cmpgu | op_nor | op_or | op_xnor | op_xor);
|
585 |
|
|
assign select_high_immediate = op_andhi | op_orhi;
|
586 |
|
|
assign select_call_immediate = instruction[31];
|
587 |
|
|
|
588 |
|
|
assign high_immediate = {instruction[15:0], 16'h0000};
|
589 |
|
|
assign extended_immediate = {{16{sign_extend_immediate & instruction[15]}}, instruction[15:0]};
|
590 |
|
|
assign call_immediate = {{6{instruction[25]}}, instruction[25:0]};
|
591 |
|
|
assign branch_immediate = {{16{instruction[15]}}, instruction[15:0]};
|
592 |
|
|
|
593 |
|
|
assign immediate = select_high_immediate == `TRUE
|
594 |
|
|
? high_immediate
|
595 |
|
|
: extended_immediate;
|
596 |
|
|
|
597 |
|
|
assign branch_offset = select_call_immediate == `TRUE
|
598 |
|
|
? call_immediate
|
599 |
|
|
: branch_immediate;
|
600 |
|
|
|
601 |
|
|
endmodule
|
602 |
|
|
|