-
Notifications
You must be signed in to change notification settings - Fork 0
/
branch_control.sv
51 lines (51 loc) · 1.19 KB
/
branch_control.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
module branch_control(b_control, r1, r2, branch_sel);
input logic [2:0] b_control;
input logic [31:0] r1;
input logic [31:0] r2;
output logic [0:0] branch_sel;
always_comb
begin
case(b_control)
3'b000: begin // BEQ
if (r1 == r2)
branch_sel = 1'b1;
else
branch_sel = 1'b0;
end
3'b001: begin // BNE
if (r1 != r2)
branch_sel = 1'b1;
else
branch_sel = 1'b0;
end
3'b100: begin // BLT
if ($signed(r1) < $signed(r2))
branch_sel = 1'b1;
else
branch_sel = 1'b0;
end
3'b110: begin // BLTU
if (r1 < r2)
branch_sel = 1'b1;
else
branch_sel = 1'b0;
end
3'b101: begin // BGE
if ($signed(r1) >= $signed(r2))
branch_sel = 1'b1;
else
branch_sel = 1'b0;
end
3'b111: begin // BGEU
if (r1 >= r2)
branch_sel = 1'b1;
else
branch_sel = 1'b0;
end
//3'b011: N/A
default: begin
branch_sel = 1'b0;
end
endcase
end
endmodule