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

Subversion Repositories astron_multiplier

[/] [astron_multiplier/] [trunk/] [tb_common_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
-- Purpose: Verify different architectures of common_complex_mult
21
-- Description:
22
--   p_verify verifies that the instances of common_complex_mult all yield the
23
--   expected results and ASSERTs an ERROR in case they differ.
24
-- Usage:
25
-- > as 10
26
-- > run -all  -- signal tb_end will stop the simulation by stopping the clk
27
 
28
LIBRARY IEEE, common_pkg_lib, common_components_lib, technology_lib, tech_mult_lib; --, ip_stratixiv_mult_lib;
29
USE IEEE.std_logic_1164.ALL;
30
USE IEEE.numeric_std.ALL;
31
USE technology_lib.technology_select_pkg.ALL;
32
USE common_pkg_lib.common_pkg.ALL;
33
USE common_pkg_lib.common_lfsr_sequences_pkg.ALL;
34
USE common_pkg_lib.tb_common_pkg.ALL;
35
 
36
 
37
ENTITY tb_common_complex_mult IS
38
  GENERIC (
39
    g_in_dat_w         : NATURAL := 4;
40
    g_out_dat_w        : NATURAL := 8;       -- g_in_dat_w*2 for multiply and +1 for adder
41
    g_conjugate_b      : BOOLEAN := FALSE;   -- When FALSE p = a * b, else p = a * conj(b)
42
    g_pipeline_input   : NATURAL := 1;
43
    g_pipeline_product : NATURAL := 0;
44
    g_pipeline_adder   : NATURAL := 1;
45
    g_pipeline_output  : NATURAL := 1
46
  );
47
END tb_common_complex_mult;
48
 
49
 
50
ARCHITECTURE tb OF tb_common_complex_mult IS
51
 
52
  CONSTANT clk_period        : TIME := 10 ns;
53
  CONSTANT c_pipeline        : NATURAL := g_pipeline_input + g_pipeline_product + g_pipeline_adder + g_pipeline_output;
54
 
55
  CONSTANT c_max             : INTEGER :=  2**(g_in_dat_w-1)-1;
56
  CONSTANT c_min             : INTEGER := -2**(g_in_dat_w-1);
57
 
58
  CONSTANT c_technology      : NATURAL := c_tech_select_default;
59
 
60
  SIGNAL tb_end              : STD_LOGIC := '0';
61
  SIGNAL rst                 : STD_LOGIC;
62
  SIGNAL clk                 : STD_LOGIC := '0';
63
 
64
  SIGNAL random              : STD_LOGIC_VECTOR(14 DOWNTO 0) := (OTHERS=>'0');  -- use different lengths to have different random sequences
65
 
66
  SIGNAL in_ar               : STD_LOGIC_VECTOR(g_in_dat_w-1 DOWNTO 0);
67
  SIGNAL in_ai               : STD_LOGIC_VECTOR(g_in_dat_w-1 DOWNTO 0);
68
  SIGNAL in_br               : STD_LOGIC_VECTOR(g_in_dat_w-1 DOWNTO 0);
69
  SIGNAL in_bi               : STD_LOGIC_VECTOR(g_in_dat_w-1 DOWNTO 0);
70
 
71
  SIGNAL in_val              : STD_LOGIC;  -- in_val is only passed on to out_val
72
  SIGNAL result_val_expected : STD_LOGIC;
73
  SIGNAL result_val_rtl      : STD_LOGIC;
74
  SIGNAL result_val_ip       : STD_LOGIC;
75
 
76
  SIGNAL out_result_re       : STD_LOGIC_VECTOR(g_out_dat_w-1 DOWNTO 0);  -- combinatorial result
77
  SIGNAL out_result_im       : STD_LOGIC_VECTOR(g_out_dat_w-1 DOWNTO 0);
78
  SIGNAL result_re_expected  : STD_LOGIC_VECTOR(g_out_dat_w-1 DOWNTO 0);  -- pipelined results
79
  SIGNAL result_re_rtl       : STD_LOGIC_VECTOR(g_out_dat_w-1 DOWNTO 0);
80
  SIGNAL result_re_ip        : STD_LOGIC_VECTOR(g_out_dat_w-1 DOWNTO 0);
81
  SIGNAL result_im_expected  : STD_LOGIC_VECTOR(g_out_dat_w-1 DOWNTO 0);
82
  SIGNAL result_im_rtl       : STD_LOGIC_VECTOR(g_out_dat_w-1 DOWNTO 0);
83
  SIGNAL result_im_ip        : STD_LOGIC_VECTOR(g_out_dat_w-1 DOWNTO 0);
84
 
85
 
86
BEGIN
87
 
88
  clk <= (NOT clk) OR tb_end AFTER clk_period/2;
89
 
90
  random <= func_common_random(random) WHEN rising_edge(clk);
91
 
92
  in_val <= random(random'HIGH);
93
 
94
  -- run -all
95
  p_in_stimuli : PROCESS
96
  BEGIN
97
    rst <= '1';
98
    in_ar <= TO_SVEC(0, g_in_dat_w);
99
    in_br <= TO_SVEC(0, g_in_dat_w);
100
    in_ai <= TO_SVEC(0, g_in_dat_w);
101
    in_bi <= TO_SVEC(0, g_in_dat_w);
102
    WAIT UNTIL rising_edge(clk);
103
    FOR I IN 0 TO 9 LOOP
104
      WAIT UNTIL rising_edge(clk);
105
    END LOOP;
106
    rst <= '0';
107
    FOR I IN 0 TO 9 LOOP
108
      WAIT UNTIL rising_edge(clk);
109
    END LOOP;
110
 
111
    -- Some special combinations
112
    in_ar <= TO_SVEC(2, g_in_dat_w);
113
    in_ai <= TO_SVEC(4, g_in_dat_w);
114
    in_br <= TO_SVEC(3, g_in_dat_w);
115
    in_bi <= TO_SVEC(5, g_in_dat_w);
116
    WAIT UNTIL rising_edge(clk);
117
    in_ar <= TO_SVEC( c_max, g_in_dat_w);  -- p*p - p*p + j ( p*p + p*p) = 0 + j 2pp  or  p*p + p*p + j (-p*p + p*p) = 2pp + j 0
118
    in_ai <= TO_SVEC( c_max, g_in_dat_w);
119
    in_br <= TO_SVEC( c_max, g_in_dat_w);
120
    in_bi <= TO_SVEC( c_max, g_in_dat_w);
121
    WAIT UNTIL rising_edge(clk);
122
    in_ar <= TO_SVEC( c_min, g_in_dat_w);
123
    in_ai <= TO_SVEC( c_min, g_in_dat_w);
124
    in_br <= TO_SVEC( c_min, g_in_dat_w);
125
    in_bi <= TO_SVEC( c_min, g_in_dat_w);
126
    WAIT UNTIL rising_edge(clk);
127
    in_ar <= TO_SVEC( c_max, g_in_dat_w);
128
    in_ai <= TO_SVEC( c_max, g_in_dat_w);
129
    in_br <= TO_SVEC( c_min, g_in_dat_w);
130
    in_bi <= TO_SVEC( c_min, g_in_dat_w);
131
    WAIT UNTIL rising_edge(clk);
132
    in_ar <= TO_SVEC( c_max, g_in_dat_w);
133
    in_ai <= TO_SVEC( c_max, g_in_dat_w);
134
    in_br <= TO_SVEC(-c_max, g_in_dat_w);
135
    in_bi <= TO_SVEC(-c_max, g_in_dat_w);
136
    WAIT UNTIL rising_edge(clk);
137
    in_ar <= TO_SVEC( c_min, g_in_dat_w);
138
    in_ai <= TO_SVEC( c_min, g_in_dat_w);
139
    in_br <= TO_SVEC(-c_max, g_in_dat_w);
140
    in_bi <= TO_SVEC(-c_max, g_in_dat_w);
141
    WAIT UNTIL rising_edge(clk);
142
 
143
    FOR I IN 0 TO 49 LOOP
144
      WAIT UNTIL rising_edge(clk);
145
    END LOOP;
146
 
147
    -- All combinations
148
    FOR I IN -c_max TO c_max LOOP
149
      FOR J IN -c_max TO c_max LOOP
150
        FOR K IN -c_max TO c_max LOOP
151
          FOR L IN -c_max TO c_max LOOP
152
            in_ar <= TO_SVEC(I, g_in_dat_w);
153
            in_ai <= TO_SVEC(K, g_in_dat_w);
154
            in_br <= TO_SVEC(J, g_in_dat_w);
155
            in_bi <= TO_SVEC(L, g_in_dat_w);
156
            WAIT UNTIL rising_edge(clk);
157
          END LOOP;
158
        END LOOP;
159
      END LOOP;
160
    END LOOP;
161
 
162
    FOR I IN 0 TO 49 LOOP
163
      WAIT UNTIL rising_edge(clk);
164
    END LOOP;
165
 
166
    tb_end <= '1';
167
    WAIT;
168
  END PROCESS;
169
 
170
  -- Expected combinatorial complex multiply out_result
171
  out_result_re <= func_complex_multiply(in_ar, in_ai, in_br, in_bi, g_conjugate_b, "RE", g_out_dat_w);
172
  out_result_im <= func_complex_multiply(in_ar, in_ai, in_br, in_bi, g_conjugate_b, "IM", g_out_dat_w);
173
 
174
  u_result_re : ENTITY common_components_lib.common_pipeline
175
  GENERIC MAP (
176
    g_representation => "SIGNED",
177
    g_pipeline       => c_pipeline,
178
    g_reset_value    => 0,
179
    g_in_dat_w       => g_out_dat_w,
180
    g_out_dat_w      => g_out_dat_w
181
  )
182
  PORT MAP (
183
    rst     => rst,
184
    clk     => clk,
185
    clken   => '1',
186
    in_dat  => out_result_re,
187
    out_dat => result_re_expected
188
  );
189
 
190
  u_result_im : ENTITY common_components_lib.common_pipeline
191
  GENERIC MAP (
192
    g_representation => "SIGNED",
193
    g_pipeline       => c_pipeline,
194
    g_reset_value    => 0,
195
    g_in_dat_w       => g_out_dat_w,
196
    g_out_dat_w      => g_out_dat_w
197
  )
198
  PORT MAP (
199
    rst     => rst,
200
    clk     => clk,
201
    clken   => '1',
202
    in_dat  => out_result_im,
203
    out_dat => result_im_expected
204
  );
205
 
206
  u_result_val_expected : ENTITY common_components_lib.common_pipeline_sl
207
  GENERIC MAP (
208
    g_pipeline    => c_pipeline,
209
    g_reset_value => 0
210
  )
211
  PORT MAP (
212
    rst     => rst,
213
    clk     => clk,
214
    clken   => '1',
215
    in_dat  => in_val,
216
    out_dat => result_val_expected
217
  );
218
 
219
  u_dut_rtl : ENTITY work.common_complex_mult
220
  GENERIC MAP (
221
    g_technology       => c_technology,
222
    g_variant          => "RTL",
223
    g_in_a_w           => g_in_dat_w,
224
    g_in_b_w           => g_in_dat_w,
225
    g_out_p_w          => g_out_dat_w,
226
    g_conjugate_b      => g_conjugate_b,
227
    g_pipeline_input   => g_pipeline_input,
228
    g_pipeline_product => g_pipeline_product,
229
    g_pipeline_adder   => g_pipeline_adder,
230
    g_pipeline_output  => g_pipeline_output
231
  )
232
  PORT MAP (
233
    rst        => rst,
234
    clk        => clk,
235
    clken      => '1',
236
    in_ar      => in_ar,
237
    in_ai      => in_ai,
238
    in_br      => in_br,
239
    in_bi      => in_bi,
240
    in_val     => in_val,
241
    out_pr     => result_re_rtl,
242
    out_pi     => result_im_rtl,
243
    out_val    => result_val_rtl
244
  );
245
 
246
  u_dut_ip : ENTITY work.common_complex_mult
247
  GENERIC MAP (
248
    g_technology       => c_technology,
249
    g_variant          => "IP",
250
    g_in_a_w           => g_in_dat_w,
251
    g_in_b_w           => g_in_dat_w,
252
    g_out_p_w          => g_out_dat_w,
253
    g_conjugate_b      => g_conjugate_b,
254
    g_pipeline_input   => g_pipeline_input,
255
    g_pipeline_product => g_pipeline_product,
256
    g_pipeline_adder   => g_pipeline_adder,
257
    g_pipeline_output  => g_pipeline_output
258
  )
259
  PORT MAP (
260
    rst        => rst,
261
    clk        => clk,
262
    clken      => '1',
263
    in_ar      => in_ar,
264
    in_ai      => in_ai,
265
    in_br      => in_br,
266
    in_bi      => in_bi,
267
    in_val     => in_val,
268
    out_pr     => result_re_ip,
269
    out_pi     => result_im_ip,
270
    out_val    => result_val_ip
271
  );
272
 
273
  p_verify : PROCESS(rst, clk)
274
  BEGIN
275
    IF rst='0' THEN
276
      IF rising_edge(clk) THEN
277
        ASSERT result_re_rtl  = result_re_expected  REPORT "Error: RE wrong RTL result"  SEVERITY ERROR;
278
        ASSERT result_im_rtl  = result_im_expected  REPORT "Error: IM wrong RTL result"  SEVERITY ERROR;
279
        ASSERT result_val_rtl = result_val_expected REPORT "Error: VAL wrong RTL result" SEVERITY ERROR;
280
 
281
        ASSERT result_re_ip   = result_re_expected  REPORT "Error: RE wrong IP result"  SEVERITY ERROR;
282
        ASSERT result_im_ip   = result_im_expected  REPORT "Error: IM wrong IP result"  SEVERITY ERROR;
283
        ASSERT result_val_ip  = result_val_expected REPORT "Error: VAL wrong IP result" SEVERITY ERROR;
284
 
285
      END IF;
286
    END IF;
287
  END PROCESS;
288
 
289
END tb;

powered by: WebSVN 2.1.0

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