-
Notifications
You must be signed in to change notification settings - Fork 4
/
comp.v
63 lines (57 loc) · 1.22 KB
/
comp.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
module comp(dinA, dinB, ins, compare, branch);
input [31:0] dinA;
input [31:0] dinB;
input [31:0] ins;
input compare;
output reg branch;
wire [5:0] op;
wire [4:0] sel;
assign sel = ins[20:16];
assign op = ins[31:26];
// Operation code.
parameter BEQ = 6'b000100,
BNE = 6'b000101,
BGTZ = 6'b000111,
BLEZ = 6'b000110,
BGEZ_BLTZ = 6'b000001;
// Sel code.
parameter SEL0 = 5'b00000,
SEL1 = 5'b00001;
always @ ( compare or dinA or dinB ) begin
if (compare) begin
case (op)
BEQ: begin
if (dinA == dinB) begin
branch = 1;
end else branch = 0;
end
BNE: begin
if (dinA != dinB) begin
branch = 1;
end else branch = 0;
end
BGTZ: begin
if ($signed(dinA) > 0) begin
branch = 1;
end else branch = 0;
end
BLEZ: begin
if ($signed(dinA) <= 0) begin
branch = 1;
end else branch = 0;
end
BGEZ_BLTZ: begin
case (sel)
SEL0: if ($signed(dinA) < 0) begin// BLTZ
branch = 1;
end else branch = 0;
SEL1: if ($signed(dinA) >= 0) begin// BGEZ
branch = 1;
end else branch = 0;
endcase
end
default: branch = 0;
endcase
end else branch = 0;
end
endmodule // Compare;