-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBranchCondition.sv
41 lines (40 loc) · 963 Bytes
/
BranchCondition.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
module BranchCondition(input logic [31:0] rs1, rs2, input logic [2:0] br_type, input logic [6:0] opcode,
output logic br_taken);
logic branch, jump;
always_comb begin
if (opcode == 7'b1101111) jump <= 1; else jump <= 0;
end
always_comb begin
if (opcode == 7'b1100011) begin
case (br_type)
3'b000: begin
if (rs1 == rs2) branch <= 1;
else branch <= 0;
end
3'b001: begin
if (rs1 != rs2) branch <= 1;
else branch <= 0;
end
3'b100: begin
if (rs1 < rs2) branch <= 1;
else branch <= 0;
end
3'b101: begin
if (rs1 >= rs2) branch <= 1;
else branch <= 0;
end
3'b110: begin
if ($signed(rs1) < $signed(rs2)) branch <= 1;
else branch <= 0;
end
3'b111: begin
if ($signed(rs1) >= $signed(rs2)) branch <= 1;
else branch <= 0;
end
default: branch <= 0;
endcase
end
else branch <= 0;
end
assign br_taken = (branch | jump);
endmodule