OpenCores
URL https://opencores.org/ocsvn/astron_multiplier/astron_multiplier/trunk

Subversion Repositories astron_multiplier

[/] [astron_multiplier/] [trunk/] [tech_complex_mult.vhd] - Blame information for rev 3

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 danv
-------------------------------------------------------------------------------
2
--
3 3 danv
-- Copyright 2020
4 2 danv
-- ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/>
5
-- P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
6 3 danv
-- 
7
-- Licensed under the Apache License, Version 2.0 (the "License");
8
-- you may not use this file except in compliance with the License.
9
-- You may obtain a copy of the License at
10
-- 
11
--     http://www.apache.org/licenses/LICENSE-2.0
12
-- 
13
-- Unless required by applicable law or agreed to in writing, software
14
-- distributed under the License is distributed on an "AS IS" BASIS,
15
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
-- See the License for the specific language governing permissions and
17
-- limitations under the License.
18 2 danv
--
19
-------------------------------------------------------------------------------
20
 
21
LIBRARY IEEE, common_pkg_lib, common_components_lib, technology_lib;
22
USE IEEE.std_logic_1164.ALL;
23
USE common_pkg_lib.common_pkg.ALL;
24
USE technology_lib.technology_pkg.ALL;
25
USE technology_lib.technology_select_pkg.ALL;
26
USE work.tech_mult_component_pkg.ALL;
27
 
28
-- Declare IP libraries to ensure default binding in simulation. The IP library clause is ignored by synthesis.
29
LIBRARY ip_stratixiv_mult_lib;
30
--LIBRARY ip_arria10_mult_lib;
31
--LIBRARY ip_arria10_mult_rtl_lib;
32
--LIBRARY ip_arria10_complex_mult_altmult_complex_150;
33
--LIBRARY ip_arria10_e1sg_complex_mult_altmult_complex_170;
34
--LIBRARY ip_arria10_complex_mult_rtl_lib;
35
--LIBRARY ip_arria10_complex_mult_rtl_canonical_lib;
36
 
37
ENTITY tech_complex_mult IS
38
  GENERIC (
39
    g_sim              : BOOLEAN := TRUE;
40
    g_sim_level        : NATURAL := 0; -- 0: Simulate variant passed via g_variant for given g_technology
41
    g_technology       : NATURAL  := c_tech_select_default;
42
    g_variant          : STRING := "IP";
43
    g_in_a_w           : POSITIVE;
44
    g_in_b_w           : POSITIVE;
45
    g_out_p_w          : POSITIVE;          -- default use g_out_p_w = g_in_a_w+g_in_b_w = c_prod_w
46
    g_conjugate_b      : BOOLEAN := FALSE;
47
    g_pipeline_input   : NATURAL := 1;      -- 0 or 1
48
    g_pipeline_product : NATURAL := 0;      -- 0 or 1
49
    g_pipeline_adder   : NATURAL := 1;      -- 0 or 1
50
    g_pipeline_output  : NATURAL := 1       -- >= 0
51
  );
52
  PORT (
53
    rst        : IN   STD_LOGIC := '0';
54
    clk        : IN   STD_LOGIC;
55
    clken      : IN   STD_LOGIC := '1';
56
    in_ar      : IN   STD_LOGIC_VECTOR(g_in_a_w-1 DOWNTO 0);
57
    in_ai      : IN   STD_LOGIC_VECTOR(g_in_a_w-1 DOWNTO 0);
58
    in_br      : IN   STD_LOGIC_VECTOR(g_in_b_w-1 DOWNTO 0);
59
    in_bi      : IN   STD_LOGIC_VECTOR(g_in_b_w-1 DOWNTO 0);
60
    result_re  : OUT  STD_LOGIC_VECTOR(g_out_p_w-1 DOWNTO 0);
61
    result_im  : OUT  STD_LOGIC_VECTOR(g_out_p_w-1 DOWNTO 0)
62
  );
63
END tech_complex_mult;
64
 
65
ARCHITECTURE str of tech_complex_mult is
66
 
67
  -- Force to maximum 18 bit width, because:
68
  -- . the ip_stratixiv_complex_mult is generated for 18b inputs and 36b output and then uses 4 real multipliers and no additional registers
69
  -- . if one input   > 18b then another IP needs to be regenerated and that will use  8 real multipliers and some extra LUTs and registers
70
  -- . if both inputs > 18b then another IP needs to be regenerated and that will use 16 real multipliers and some extra LUTs and registers
71
  -- . if the output is set to 18b+18b + 1b =37b to account for the sum then another IP needs to be regenerated and that will use some extra registers
72
  -- ==> for inputs <= 18b this ip_stratixiv_complex_mult is appropriate and it can not be made parametrisable to fit also inputs > 18b.
73
  CONSTANT c_dsp_dat_w    : NATURAL  := 18;
74
  CONSTANT c_dsp_prod_w   : NATURAL  := 2*c_dsp_dat_w;
75
 
76
  SIGNAL ar        : STD_LOGIC_VECTOR(c_dsp_dat_w-1 DOWNTO 0);
77
  SIGNAL ai        : STD_LOGIC_VECTOR(c_dsp_dat_w-1 DOWNTO 0);
78
  SIGNAL br        : STD_LOGIC_VECTOR(c_dsp_dat_w-1 DOWNTO 0);
79
  SIGNAL bi        : STD_LOGIC_VECTOR(c_dsp_dat_w-1 DOWNTO 0);
80
  SIGNAL mult_re   : STD_LOGIC_VECTOR(c_dsp_prod_w-1 DOWNTO 0);
81
  SIGNAL mult_im   : STD_LOGIC_VECTOR(c_dsp_prod_w-1 DOWNTO 0);
82
 
83
  -- sim_model=1
84
  SIGNAL result_re_undelayed : STD_LOGIC_VECTOR(g_in_b_w+g_in_a_w-1 DOWNTO 0);
85
  SIGNAL result_im_undelayed : STD_LOGIC_VECTOR(g_in_b_w+g_in_a_w-1 DOWNTO 0);
86
 
87
begin
88
 
89
  gen_ip_stratixiv_ip : IF (g_sim=FALSE OR (g_sim=TRUE AND g_sim_level=0)) AND (g_technology=c_tech_stratixiv AND g_variant="IP") GENERATE
90
 
91
    -- Adapt DSP input widths
92
    ar <= RESIZE_SVEC(in_ar, c_dsp_dat_w);
93
    ai <= RESIZE_SVEC(in_ai, c_dsp_dat_w);
94
    br <= RESIZE_SVEC(in_br, c_dsp_dat_w);
95
    bi <= RESIZE_SVEC(in_bi, c_dsp_dat_w) WHEN g_conjugate_b=FALSE ELSE TO_SVEC(-TO_SINT(in_bi), c_dsp_dat_w);
96
 
97
    u0 : ip_stratixiv_complex_mult
98
    PORT MAP (
99
         aclr        => rst,
100
         clock       => clk,
101
         dataa_imag  => ai,
102
         dataa_real  => ar,
103
         datab_imag  => bi,
104
         datab_real  => br,
105
         ena         => clken,
106
         result_imag => mult_im,
107
         result_real => mult_re
108
         );
109
 
110
    -- Back to true input widths and then resize for output width
111
    result_re <= RESIZE_SVEC(mult_re, g_out_p_w);
112
    result_im <= RESIZE_SVEC(mult_im, g_out_p_w);
113
 
114
  END GENERATE;
115
 
116
  gen_ip_stratixiv_rtl : IF (g_sim=FALSE OR (g_sim=TRUE AND g_sim_level=0)) AND (g_technology=c_tech_stratixiv AND g_variant="RTL") GENERATE
117
    u0 : ip_stratixiv_complex_mult_rtl
118
  GENERIC MAP(
119
    g_in_a_w           => g_in_a_w,
120
    g_in_b_w           => g_in_b_w,
121
    g_out_p_w          => g_out_p_w,
122
    g_conjugate_b      => g_conjugate_b,
123
    g_pipeline_input   => g_pipeline_input,
124
    g_pipeline_product => g_pipeline_product,
125
    g_pipeline_adder   => g_pipeline_adder,
126
    g_pipeline_output  => g_pipeline_output
127
  )
128
  PORT MAP(
129
    rst        => rst,
130
    clk        => clk,
131
    clken      => clken,
132
    in_ar      => in_ar,
133
    in_ai      => in_ai,
134
    in_br      => in_br,
135
    in_bi      => in_bi,
136
    result_re  => result_re,
137
    result_im  => result_im
138
    );
139
  END GENERATE;
140
 
141
--  gen_ip_arria10_ip : IF (g_sim=FALSE OR (g_sim=TRUE AND g_sim_level=0)) AND (g_technology=c_tech_arria10 AND g_variant="IP") GENERATE
142
--
143
--    -- Adapt DSP input widths
144
--    ar <= RESIZE_SVEC(in_ar, c_dsp_dat_w);
145
--    ai <= RESIZE_SVEC(in_ai, c_dsp_dat_w);
146
--    br <= RESIZE_SVEC(in_br, c_dsp_dat_w);
147
--    bi <= RESIZE_SVEC(in_bi, c_dsp_dat_w) WHEN g_conjugate_b=FALSE ELSE TO_SVEC(-TO_SINT(in_bi), c_dsp_dat_w);
148
--
149
--    u0 : ip_arria10_complex_mult
150
--    PORT MAP (
151
--         aclr        => rst,
152
--         clock       => clk,
153
--         dataa_imag  => ai,
154
--         dataa_real  => ar,
155
--         datab_imag  => bi,
156
--         datab_real  => br,
157
--         ena         => clken,
158
--         result_imag => mult_im,
159
--         result_real => mult_re
160
--         );
161
--
162
--    -- Back to true input widths and then resize for output width
163
--    result_re <= RESIZE_SVEC(mult_re, g_out_p_w);
164
--    result_im <= RESIZE_SVEC(mult_im, g_out_p_w);
165
--
166
--  END GENERATE;
167
--
168
--  -- RTL variant is the same for unb2, unb2a and unb2b
169
--  gen_ip_arria10_rtl : IF (g_sim=FALSE OR (g_sim=TRUE AND g_sim_level=0)) AND 
170
--      ((g_technology=c_tech_arria10 OR g_technology=c_tech_arria10_e3sge3 OR g_technology=c_tech_arria10_e1sg ) AND g_variant="RTL") GENERATE
171
--    u0 : ip_arria10_complex_mult_rtl
172
--  GENERIC MAP(
173
--    g_in_a_w           => g_in_a_w,
174
--    g_in_b_w           => g_in_b_w,
175
--    g_out_p_w          => g_out_p_w,
176
--    g_conjugate_b      => g_conjugate_b,
177
--    g_pipeline_input   => g_pipeline_input,
178
--    g_pipeline_product => g_pipeline_product,
179
--    g_pipeline_adder   => g_pipeline_adder,
180
--    g_pipeline_output  => g_pipeline_output
181
--  )
182
--  PORT MAP(
183
--    rst        => rst,
184
--    clk        => clk,
185
--    clken      => clken,
186
--    in_ar      => in_ar,
187
--    in_ai      => in_ai,
188
--    in_br      => in_br,
189
--    in_bi      => in_bi,
190
--    result_re  => result_re,
191
--    result_im  => result_im
192
--    );
193
--  END GENERATE;
194
--
195
--  gen_ip_arria10_rtl_canonical : IF (g_sim=FALSE OR (g_sim=TRUE AND g_sim_level=0)) AND 
196
--      ((g_technology=c_tech_arria10 OR g_technology=c_tech_arria10_e3sge3 OR g_technology=c_tech_arria10_e1sg ) AND g_variant="RTL_C") GENERATE
197
--    u0 : ip_arria10_complex_mult_rtl_canonical
198
--  GENERIC MAP(
199
--    g_in_a_w           => g_in_a_w,
200
--    g_in_b_w           => g_in_b_w,
201
--    g_out_p_w          => g_out_p_w,
202
----    g_conjugate_b      => g_conjugate_b, -- NOT SUPPORTED
203
--    g_pipeline_input   => g_pipeline_input,
204
--    g_pipeline_product => g_pipeline_product,
205
--    g_pipeline_adder   => g_pipeline_adder,
206
--    g_pipeline_output  => g_pipeline_output
207
--  )
208
--  PORT MAP(
209
--    rst        => rst,
210
--    clk        => clk,
211
--    clken      => clken,
212
--    in_ar      => in_ar,
213
--    in_ai      => in_ai,
214
--    in_br      => in_br,
215
--    in_bi      => in_bi,
216
--    result_re  => result_re,
217
--    result_im  => result_im
218
--    );
219
--  END GENERATE;
220
--
221
--
222
--  gen_ip_arria10_e1sg_ip : IF (g_sim=FALSE OR (g_sim=TRUE AND g_sim_level=0)) AND (g_technology=c_tech_arria10_e1sg AND g_variant="IP") GENERATE
223
--
224
--    -- Adapt DSP input widths
225
--    ar <= RESIZE_SVEC(in_ar, c_dsp_dat_w);
226
--    ai <= RESIZE_SVEC(in_ai, c_dsp_dat_w);
227
--    br <= RESIZE_SVEC(in_br, c_dsp_dat_w);
228
--    bi <= RESIZE_SVEC(in_bi, c_dsp_dat_w) WHEN g_conjugate_b=FALSE ELSE TO_SVEC(-TO_SINT(in_bi), c_dsp_dat_w);
229
--
230
--
231
--    u0 : ip_arria10_e1sg_complex_mult
232
--    PORT MAP (
233
--         aclr        => rst,
234
--         clock       => clk,
235
--         dataa_imag  => ai,
236
--         dataa_real  => ar,
237
--         datab_imag  => bi,
238
--         datab_real  => br,
239
--         ena         => clken,
240
--         result_imag => mult_im,
241
--         result_real => mult_re
242
--         );
243
--
244
--    -- Back to true input widths and then resize for output width
245
--    result_re <= RESIZE_SVEC(mult_re, g_out_p_w);
246
--    result_im <= RESIZE_SVEC(mult_im, g_out_p_w);
247
--
248
--  END GENERATE;
249
 
250
  -------------------------------------------------------------------------------
251
  -- Model: forward concatenated inputs to the 'result' output
252
  -- 
253
  -- Example:
254
  --                                    ______ 
255
  -- Input B.real (in_br) = 0x1111 --> |      |
256
  --        .imag (in_bi) = 0xBBBB --> |      |
257
  --                                   | mult | --> Output result.real = 0x00000000
258
  -- Input A.real (in_ar) = 0x0000 --> |      |                  .imag = 0xBBBBAAAA
259
  --        .imag (in_ai) = 0xAAAA --> |______|
260
  -- 
261
  -- Note: this model is synthsizable as well.
262
  -- 
263
  -------------------------------------------------------------------------------
264
  gen_sim_level_1 : IF g_sim=TRUE AND g_sim_level=1 GENERATE --FIXME: g_sim required? This is synthesizable.
265
 
266
    result_re_undelayed <= in_br & in_ar;
267
    result_im_undelayed <= in_bi & in_ai;
268
 
269
    u_common_pipeline_re : entity common_components_lib.common_pipeline
270
    generic map (
271
      g_pipeline  => 3,
272
      g_in_dat_w  => g_in_b_w+g_in_a_w,
273
      g_out_dat_w => g_out_p_w
274
    )
275
    port map (
276
      clk     => clk,
277
      in_dat  => result_re_undelayed,
278
      out_dat => result_re
279
    );
280
 
281
    u_common_pipeline_im : entity common_components_lib.common_pipeline
282
    generic map (
283
      g_pipeline  => 3,
284
      g_in_dat_w  => g_in_b_w+g_in_a_w,
285
      g_out_dat_w => g_out_p_w
286
    )
287
    port map (
288
      clk     => clk,
289
      in_dat  => result_im_undelayed,
290
      out_dat => result_im
291
    );
292
 
293
  END GENERATE;
294
 
295
end str;
296
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.