1 |
5 |
danv |
-------------------------------------------------------------------------------
|
2 |
|
|
--
|
3 |
|
|
-- Copyright (C) 2009
|
4 |
|
|
-- ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/>
|
5 |
|
|
-- P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
|
6 |
|
|
--
|
7 |
|
|
-- This program is free software: you can redistribute it and/or modify
|
8 |
|
|
-- it under the terms of the GNU General Public License as published by
|
9 |
|
|
-- the Free Software Foundation, either version 3 of the License, or
|
10 |
|
|
-- (at your option) any later version.
|
11 |
|
|
--
|
12 |
|
|
-- This program is distributed in the hope that it will be useful,
|
13 |
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 |
|
|
-- GNU General Public License for more details.
|
16 |
|
|
--
|
17 |
|
|
-- You should have received a copy of the GNU General Public License
|
18 |
|
|
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
19 |
|
|
--
|
20 |
|
|
-------------------------------------------------------------------------------
|
21 |
|
|
|
22 |
|
|
LIBRARY IEEE, common_pkg_lib;
|
23 |
|
|
USE IEEE.std_logic_1164.ALL;
|
24 |
|
|
USE common_pkg_lib.common_pkg.ALL;
|
25 |
|
|
--USE technology_lib.technology_pkg.ALL;
|
26 |
|
|
--USE technology_lib.technology_select_pkg.ALL;
|
27 |
|
|
USE work.tech_mult_component_pkg.ALL;
|
28 |
|
|
|
29 |
|
|
-- Declare IP libraries to ensure default binding in simulation. The IP library clause is ignored by synthesis.
|
30 |
|
|
--LIBRARY ip_stratixiv_mult_lib;
|
31 |
|
|
--LIBRARY ip_arria10_mult_lib;
|
32 |
|
|
|
33 |
|
|
|
34 |
|
|
ENTITY tech_mult IS
|
35 |
|
|
GENERIC (
|
36 |
|
|
g_technology : NATURAL := 0;
|
37 |
|
|
g_variant : STRING := "IP";
|
38 |
|
|
g_in_a_w : POSITIVE := 18;
|
39 |
|
|
g_in_b_w : POSITIVE := 18;
|
40 |
|
|
g_out_p_w : POSITIVE := 36; -- c_prod_w = g_in_a_w+g_in_b_w, use smaller g_out_p_w to truncate MSbits, or larger g_out_p_w to extend MSbits
|
41 |
|
|
g_nof_mult : POSITIVE := 1; -- using 2 for 18x18, 4 for 9x9 may yield better results when inferring * is used
|
42 |
|
|
g_pipeline_input : NATURAL := 1; -- 0 or 1
|
43 |
|
|
g_pipeline_product : NATURAL := 1; -- 0 or 1
|
44 |
|
|
g_pipeline_output : NATURAL := 1; -- >= 0
|
45 |
|
|
g_representation : STRING := "SIGNED" -- or "UNSIGNED"
|
46 |
|
|
);
|
47 |
|
|
PORT (
|
48 |
|
|
rst : IN STD_LOGIC;
|
49 |
|
|
clk : IN STD_LOGIC;
|
50 |
|
|
clken : IN STD_LOGIC := '1';
|
51 |
|
|
in_a : IN STD_LOGIC_VECTOR(g_nof_mult*g_in_a_w-1 DOWNTO 0);
|
52 |
|
|
in_b : IN STD_LOGIC_VECTOR(g_nof_mult*g_in_b_w-1 DOWNTO 0);
|
53 |
|
|
out_p : OUT STD_LOGIC_VECTOR(g_nof_mult*g_out_p_w-1 DOWNTO 0)
|
54 |
|
|
);
|
55 |
|
|
END tech_mult;
|
56 |
|
|
|
57 |
|
|
ARCHITECTURE str of tech_mult is
|
58 |
|
|
|
59 |
|
|
-- When g_out_p_w < g_in_a_w+g_in_b_w then the LPM_MULT truncates the LSbits of the product. Therefore
|
60 |
|
|
-- define c_prod_w to be able to let common_mult truncate the LSBits of the product.
|
61 |
|
|
CONSTANT c_prod_w : NATURAL := g_in_a_w + g_in_b_w;
|
62 |
|
|
|
63 |
|
|
SIGNAL prod : STD_LOGIC_VECTOR(g_nof_mult*c_prod_w-1 DOWNTO 0);
|
64 |
|
|
|
65 |
|
|
begin
|
66 |
|
|
|
67 |
|
|
gen_ip_stratixiv_ip : IF (g_technology=0 AND g_variant="IP") GENERATE
|
68 |
|
|
u0 : ip_stratixiv_mult
|
69 |
|
|
GENERIC MAP(
|
70 |
|
|
g_in_a_w => g_in_a_w,
|
71 |
|
|
g_in_b_w => g_in_b_w,
|
72 |
|
|
g_out_p_w => g_out_p_w,
|
73 |
|
|
g_nof_mult => g_nof_mult,
|
74 |
|
|
g_pipeline_input => g_pipeline_input,
|
75 |
|
|
g_pipeline_product => g_pipeline_product,
|
76 |
|
|
g_pipeline_output => g_pipeline_output,
|
77 |
|
|
g_representation => g_representation
|
78 |
|
|
)
|
79 |
|
|
PORT MAP(
|
80 |
|
|
clk => clk,
|
81 |
|
|
clken => clken,
|
82 |
|
|
in_a => in_a,
|
83 |
|
|
in_b => in_b,
|
84 |
|
|
out_p => prod
|
85 |
|
|
);
|
86 |
|
|
END GENERATE;
|
87 |
|
|
|
88 |
|
|
gen_ip_stratixiv_rtl : IF (g_technology=0 AND g_variant="RTL") GENERATE
|
89 |
|
|
u0 : ip_stratixiv_mult_rtl
|
90 |
|
|
GENERIC MAP(
|
91 |
|
|
g_in_a_w => g_in_a_w,
|
92 |
|
|
g_in_b_w => g_in_b_w,
|
93 |
|
|
g_out_p_w => g_out_p_w,
|
94 |
|
|
g_nof_mult => g_nof_mult,
|
95 |
|
|
g_pipeline_input => g_pipeline_input,
|
96 |
|
|
g_pipeline_product => g_pipeline_product,
|
97 |
|
|
g_pipeline_output => g_pipeline_output,
|
98 |
|
|
g_representation => g_representation
|
99 |
|
|
)
|
100 |
|
|
PORT MAP(
|
101 |
|
|
rst => rst,
|
102 |
|
|
clk => clk,
|
103 |
|
|
clken => clken,
|
104 |
|
|
in_a => in_a,
|
105 |
|
|
in_b => in_b,
|
106 |
|
|
out_p => prod
|
107 |
|
|
);
|
108 |
|
|
END GENERATE;
|
109 |
|
|
|
110 |
|
|
-- gen_ip_arria10_ip : IF ((g_technology=c_tech_arria10 OR g_technology=c_tech_arria10_e3sge3 OR g_technology=c_tech_arria10_e1sg ) AND g_variant="IP") GENERATE
|
111 |
|
|
-- u0 : ip_arria10_mult
|
112 |
|
|
-- GENERIC MAP(
|
113 |
|
|
-- g_in_a_w => g_in_a_w,
|
114 |
|
|
-- g_in_b_w => g_in_b_w,
|
115 |
|
|
-- g_out_p_w => g_out_p_w,
|
116 |
|
|
-- g_nof_mult => g_nof_mult,
|
117 |
|
|
-- g_pipeline_input => g_pipeline_input,
|
118 |
|
|
-- g_pipeline_product => g_pipeline_product,
|
119 |
|
|
-- g_pipeline_output => g_pipeline_output,
|
120 |
|
|
-- g_representation => g_representation
|
121 |
|
|
-- )
|
122 |
|
|
-- PORT MAP(
|
123 |
|
|
-- clk => clk,
|
124 |
|
|
-- clken => clken,
|
125 |
|
|
-- in_a => in_a,
|
126 |
|
|
-- in_b => in_b,
|
127 |
|
|
-- out_p => prod
|
128 |
|
|
-- );
|
129 |
|
|
-- END GENERATE;
|
130 |
|
|
--
|
131 |
|
|
-- gen_ip_arria10_rtl : IF ((g_technology=c_tech_arria10 OR g_technology=c_tech_arria10_e3sge3 OR g_technology=c_tech_arria10_e1sg ) AND g_variant="RTL") GENERATE
|
132 |
|
|
-- u0 : ip_arria10_mult_rtl
|
133 |
|
|
-- GENERIC MAP(
|
134 |
|
|
-- g_in_a_w => g_in_a_w,
|
135 |
|
|
-- g_in_b_w => g_in_b_w,
|
136 |
|
|
-- g_out_p_w => g_out_p_w,
|
137 |
|
|
-- g_nof_mult => g_nof_mult,
|
138 |
|
|
-- g_pipeline_input => g_pipeline_input,
|
139 |
|
|
-- g_pipeline_product => g_pipeline_product,
|
140 |
|
|
-- g_pipeline_output => g_pipeline_output,
|
141 |
|
|
-- g_representation => g_representation
|
142 |
|
|
-- )
|
143 |
|
|
-- PORT MAP(
|
144 |
|
|
-- rst => rst,
|
145 |
|
|
-- clk => clk,
|
146 |
|
|
-- clken => clken,
|
147 |
|
|
-- in_a => in_a,
|
148 |
|
|
-- in_b => in_b,
|
149 |
|
|
-- out_p => prod
|
150 |
|
|
-- );
|
151 |
|
|
-- END GENERATE;
|
152 |
|
|
|
153 |
|
|
gen_trunk : FOR I IN 0 TO g_nof_mult-1 GENERATE
|
154 |
|
|
-- Truncate MSbits, also for signed (common_pkg.vhd for explanation of RESIZE_SVEC)
|
155 |
|
|
out_p((I+1)*g_out_p_w-1 DOWNTO I*g_out_p_w) <= RESIZE_SVEC(prod((I+1)*c_prod_w-1 DOWNTO I*c_prod_w), g_out_p_w) WHEN g_representation="SIGNED" ELSE
|
156 |
|
|
RESIZE_UVEC(prod((I+1)*c_prod_w-1 DOWNTO I*c_prod_w), g_out_p_w);
|
157 |
|
|
END GENERATE;
|
158 |
|
|
|
159 |
|
|
end str;
|
160 |
|
|
|