-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexecute.sv
58 lines (48 loc) · 1002 Bytes
/
execute.sv
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
`include "define.vh"
module execute(
input logic clk,
//input rst,
input logic [31:0] pc,
input logic [5:0] alucode,
input logic [1:0] aluop1_type,
input logic [1:0] aluop2_type,
input logic [31:0] rs1,
input logic [31:0] rs2,
input logic [31:0] imm,
output logic [31:0] pc_next,
output logic [31:0] alu_result
);
logic [31:0] op1;
logic [31:0] op2;
logic br_taken;
logic [31:0] alu_result_rg;
alu alu(
.alucode,
.op1,
.op2,
.alu_result(alu_result_rg),
.br_taken
);
always_latch begin
case(aluop1_type)
`OP_TYPE_REG: op1 = rs1;
`OP_TYPE_IMM: op1 = imm;
`OP_TYPE_PC: op1 = pc;
default: ;
endcase
case(aluop2_type)
`OP_TYPE_REG: op2 = rs2;
`OP_TYPE_IMM: op2 = imm;
`OP_TYPE_PC: op2 = pc;
default: ;
endcase
end
always_ff @(posedge clk) begin
alu_result <= alu_result_rg;
if (br_taken == `ENABLE) begin
pc_next <= alucode != `ALU_JALR ? pc + imm : rs1 + imm;
end else begin
pc_next <= pc + 32'b100;
end
end
endmodule