-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsum.sv
More file actions
33 lines (29 loc) · 918 Bytes
/
Copy pathsum.sv
File metadata and controls
33 lines (29 loc) · 918 Bytes
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
`default_nettype none
//TODO reg_a_in should consider forward
module SUM #(
parameter PC_ADDR = 32'h8000_0000,
parameter ADDR_WIDTH = 32,
parameter DATA_WIDTH = 32
)(
input wire [ADDR_WIDTH-1:0] PC_reg_in,
input wire [DATA_WIDTH-1:0] reg_a_in,
input wire [DATA_WIDTH-1:0] imm,
input wire [2:0] branch, // 0: branch, 1: eq, 2: jump
output reg [ADDR_WIDTH-1:0] PC_reg_out
);
always_comb begin
if (branch[0]) begin // beq and bne
PC_reg_out = PC_reg_in + imm;
end
else if (branch[2]) begin
// jal
PC_reg_out = PC_reg_in + imm;
end else if (branch[1]) begin
// jalr
PC_reg_out = reg_a_in + imm;
PC_reg_out[0] = 0;
end else begin
PC_reg_out = PC_reg_in + 4;
end
end
endmodule