-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbranch.v
48 lines (43 loc) · 1.49 KB
/
branch.v
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
module branch
#(parameter BITS = 32)
(clk, instr, a, b, br);
input clk;
input [BITS-1:0] a;
input [BITS-1:0] b;
input [31:0] instr;
output br;
reg br;
initial
br = 0;
always @(posedge clk) begin
casex ({instr[14:12], instr[6:0]})
10'b0001100011 : begin // BEQ
br <= (a == b) ? 1 : 0;
end
10'b0011100011 : begin // BNE
br <= (a != b) ? 1 : 0;
end
10'b1001100011 : begin // BLT
br <= ($signed(a) < $signed(b)) ? 1 : 0;
end
10'b1011100011 : begin // BGE
br <= ($signed(a) >= $signed(b)) ? 1 : 0;
end
10'b1101100011 : begin // BLTU
br <= (a < b) ? 1 : 0;
end
10'b1111100011 : begin // BGEU
br <= (a >= b) ? 1 : 0;
end
10'bxxx1101111 : begin // JAL
br <= 1;
end
10'b0001100111 : begin // JALR
br <= 1;
end
default : begin
br <= 0;
end
endcase
end
endmodule