-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmac_manual.v
55 lines (53 loc) · 1.18 KB
/
mac_manual.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
//`define FIXED_POINT 1
module mac_manual #(parameter N = 16,parameter Q = 12)(
input clk,sclr,ce,
input [N-1:0] a,
input [N-1:0] b,
input [N-1:0] c,
output [N-1:0] p
);
`ifdef FIXED_POINT
wire [N-1:0] mult,add;
reg [N-1:0] tmp;
wire ovr;
qmult #(N,Q) mul (
.clk(clk),
.rst(sclr),
.a(a),
.b(b),
.q_result(mult),
.overflow(ovr)
);
qadd #(N,Q) add1 (
.a(mult),
.b(c),
.c(add)
);
always@(posedge clk,posedge sclr)
begin
if(sclr)
begin
tmp <= 0;
end
else if(ce)
begin
tmp <= add;
end
end
assign p = tmp;
`else
reg [N-1:0] temp;
always@(posedge clk,posedge sclr)
begin
if(sclr)
begin
temp <= 0;
end
else if(ce)
begin
temp <= (a*b+c);
end
end
assign p = temp;
`endif
endmodule