-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmuldiv.v
42 lines (39 loc) · 1009 Bytes
/
muldiv.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
module muldiv (
input wire [31:0] a, b,
output reg [31:0] q,
input wire [2:0] mode
);
reg [63:0] fullq;
always @(*) begin
case (mode)
3'b000: begin
fullq = $signed(a) * $signed(b);
q = fullq[31:0];
end
3'b001: begin
fullq = $signed(a) * $signed(b);
q = fullq[63:32];
end
3'b010: begin
fullq = $signed(a) * $signed({1'b0, b});
q = fullq[63:32];
end
3'b011: begin
fullq = a * b;
q = fullq[63:32];
end
3'b100: begin
q <= $signed(a) / $signed(b);
end
3'b101: begin
q <= a / b;
end
3'b110: begin
q <= $signed(a) % $signed(b);
end
3'b111: begin
q <= a % b;
end
endcase
end
endmodule