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
64
65
66
67
68
69
70
71
72
73
|
`include "gfx/gfx_defs.sv"
module gfx_fixed_fma
(
input logic clk,
input fixed a,
b,
c,
input logic stall,
output fixed q
);
`ifndef VERILATOR
logic[2 * $bits(fixed) - `FIXED_FRAC - 1:0] q_ext;
assign q = q_ext[$bits(fixed) - 1:0];
lpm_mult mult
(
.aclr(0),
.clock(clk),
.clken(!stall),
.sum({c, {`FIXED_FRAC{1'b0}}}),
.dataa(a),
.datab(b),
.result(q_ext)
);
defparam
mult.lpm_widtha = $bits(fixed),
mult.lpm_widthb = $bits(fixed),
mult.lpm_widths = $bits(fixed) + `FIXED_FRAC,
/* Esto es crucial. No está documentado en ningún lado (aparte de un
* comentario en r/fpga). Si lpm_widthp < lpm_widtha + lpm_widthb,
* entonces result contiene los lpm_widthp bits más significativos
* del producto, no los menos significativos como tendría sentido.
*/
mult.lpm_widthp = 2 * $bits(fixed) - `FIXED_FRAC,
mult.lpm_representation = "SIGNED",
mult.lpm_pipeline = `FIXED_FMA_STAGES;
`else
logic[$bits(fixed) + `FIXED_FRAC - 1:0] q_ext;
fixed a_hold, b_hold, c_hold;
assign q = q_ext[$bits(fixed) + `FIXED_FRAC - 1:`FIXED_FRAC] + c_hold;
assign q_ext = a_hold * b_hold;
gfx_pipes #(.WIDTH($bits(a)), .DEPTH(`FIXED_FMA_STAGES)) a_pipes
(
.in(a),
.out(a_hold),
.*
);
gfx_pipes #(.WIDTH($bits(b)), .DEPTH(`FIXED_FMA_STAGES)) b_pipes
(
.in(b),
.out(b_hold),
.*
);
gfx_pipes #(.WIDTH($bits(c)), .DEPTH(`FIXED_FMA_STAGES)) c_pipes
(
.in(c),
.out(c_hold),
.*
);
`endif
endmodule
|