-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDecoder.sv
More file actions
103 lines (89 loc) · 2.31 KB
/
Copy pathDecoder.sv
File metadata and controls
103 lines (89 loc) · 2.31 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
//TODO: adjust data path using x0
module Decoder
import CpuPkg::*;
(
input type_CpuData ins,
output type_RegAddr rs1, rs2, rd,
output type_CpuData imm,
output type_AluOp aluOp,
output type_BranchOp branchOp,
output logic isPcIn,
output logic isImmIn,
output logic isLoad, // mem[alu]->rd
output logic isStore, // rs2->mem[alu]
output logic isBranch, // true ? alu->pc
output logic isJump, // alu->pc, pc+4->rd
output logic badOpcode
);
type_Opcode opcode;
logic nop;
assign opcode = getOpcode(ins);
assign badOpcode = !(opcode inside {OP, OP_IMM, JALR, LOAD, LUI, AUIPC, STORE, BRANCH, JAL});
assign nop = badOpcode;
assign isLoad = nop ? 0 : opcode inside {LOAD};
assign isStore = nop ? 0 : opcode inside {STORE};
assign isBranch = nop ? 0 : opcode inside {BRANCH};
assign isJump = nop ? 0 : opcode inside {JAL, JALR};
assign branchOp = getBranchOp(ins);
/* Reg relevant */
always_comb begin
rs1 = 5'b0; //x0
rs2 = getRs2(ins);
rd = getRd(ins);
if(!nop && opcode != LUI) begin
rs1 = getRs1(ins);
end
end
/* Imm relevant */
always_comb begin
imm = 32'b0;
if(!nop) begin
case(opcode) inside
OP_IMM, JALR, LOAD : begin
if(aluOp inside {ALU_SRL, ALU_SRA, ALU_SLL})
imm = getShAmt_OpImm(ins);
else
imm = getImmI(ins);
end
LUI, AUIPC : imm = getImmU(ins);
STORE : imm = getImmS(ins);
BRANCH : imm = getImmB(ins);
JAL : imm = getImmJ(ins);
endcase
end
end
/* ALU relevant */
always_comb begin
isPcIn = 0;
isImmIn = 1;
aluOp = ALU_ADD;
if(!nop) begin
case(opcode) inside
OP_IMM: begin
aluOp = getAluOp_OpImm(ins);
end
OP: begin
isImmIn = 0;
aluOp = getAluOp_Op(ins);
end
LUI: begin
end
AUIPC: begin
isPcIn = 1;
end
LOAD: begin //TODO: handle width
end
STORE: begin
end
BRANCH: begin
isPcIn = 1;
end
JAL: begin
isPcIn = 1;
end
JALR: begin
end
endcase
end
end
endmodule : Decoder