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

Subversion Repositories mod_sim_exp

[/] [mod_sim_exp/] [tags/] [start_version/] [bench/] [vhdl/] [tb_multiplier_core.vhd] - Blame information for rev 48

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 JonasDC
--------------------------------------------------------------------------------
2
-- Entity: tb_multiplier_core
3
-- Date:2012-10-02  
4
-- Author: Dinghe     
5
--
6
-- Description ${cursor}
7
--------------------------------------------------------------------------------
8
library ieee;
9
use ieee.std_logic_1164.all;
10
use ieee.std_logic_unsigned.all;
11
use ieee.std_logic_arith.all;
12
 
13
library std;
14
use std.textio.all;
15
 
16
library ieee;
17
use ieee.std_logic_textio.all;
18
 
19
entity tb_multiplier_core is
20
end tb_multiplier_core;
21
 
22
architecture test of tb_multiplier_core is
23
  constant nr_stages  : integer := 96;
24
  constant clk_period : time := 10 ns;
25
  signal clk          : std_logic := '0';
26
  signal reset        : std_logic := '1';
27
  file input          : text open read_mode is "sim_input.txt";
28
  file output         : text open write_mode is "sim_output.txt";
29
 
30
  ------------------------------------------------------------------
31
  -- Signals for multiplier core memory space
32
  ------------------------------------------------------------------
33
  signal core_rw_address   : std_logic_vector (8 downto 0);
34
  signal core_data_in      : std_logic_vector(31 downto 0);
35
  signal core_fifo_din     : std_logic_vector(31 downto 0);
36
  signal core_data_out     : std_logic_vector(31 downto 0);
37
  signal core_write_enable : std_logic;
38
  signal core_fifo_push    : std_logic;
39
  ------------------------------------------------------------------
40
  -- Signals for multiplier core control
41
  ------------------------------------------------------------------
42
  signal core_start          : std_logic;
43
  signal core_run_auto       : std_logic;
44
  signal core_p_sel          : std_logic_vector(1 downto 0);
45
  signal core_dest_op_single : std_logic_vector(1 downto 0);
46
  signal core_x_sel_single   : std_logic_vector(1 downto 0);
47
  signal core_y_sel_single   : std_logic_vector(1 downto 0);
48
  signal calc_time           : std_logic;
49
  ------------------------------------------------------------------
50
  -- Signals for multiplier core interrupt
51
  ------------------------------------------------------------------
52
  signal core_fifo_full   : std_logic;
53
  signal core_fifo_nopush : std_logic;
54
  signal core_ready       : std_logic;
55
  signal core_mem_collision : std_logic;
56
 
57
  component multiplier_core is
58
    port(
59
      clk : in  std_logic;
60
      reset : in  std_logic;
61
          -- operand memory interface (plb shared memory)
62
      write_enable : in  std_logic;
63
      data_in : in  std_logic_vector (31 downto 0);
64
      rw_address : in  std_logic_vector (8 downto 0);
65
      data_out : out std_logic_vector (31 downto 0);
66
      collision : out std_logic;
67
          -- op_sel fifo interface
68
      fifo_din : in  std_logic_vector (31 downto 0);
69
      fifo_push : in  std_logic;
70
      fifo_full : out std_logic;
71
      fifo_nopush : out std_logic;
72
          -- ctrl signals
73
      start : in  std_logic;
74
      run_auto : in  std_logic;
75
      ready : out std_logic;
76
      x_sel_single : in  std_logic_vector (1 downto 0);
77
      y_sel_single : in  std_logic_vector (1 downto 0);
78
      dest_op_single : in  std_logic_vector (1 downto 0);
79
      p_sel : in  std_logic_vector (1 downto 0);
80
      calc_time : out std_logic
81
    );
82
  end component;
83
 
84
 
85
begin
86
 
87
------------------------------------------
88
-- Generate clk
89
------------------------------------------
90
clk_process : process
91
begin
92
  while (true) loop
93
    clk <= '0';
94
    wait for clk_period/2;
95
    clk <= '1';
96
    wait for clk_period/2;
97
  end loop;
98
end process;
99
 
100
------------------------------------------
101
-- Stimulus Process
102
------------------------------------------
103
stim_proc : process
104
  procedure waitclk(n : natural := 1) is
105
  begin
106
    for i in 1 to n loop
107
      wait until rising_edge(clk);
108
    end loop;
109
  end waitclk;
110
 
111
  procedure loadOp(constant op_sel : std_logic_vector(2 downto 0);
112
               variable op_data : std_logic_vector(2047 downto 0)) is
113
  begin
114
    wait until rising_edge(clk);
115
    core_rw_address <= op_sel & "000000";
116
    wait until rising_edge(clk);
117
    core_write_enable <= '1';
118
    for i in 0 to (1536/32)-1 loop
119
      assert (core_mem_collision='0')
120
        report "collision detected while writing operand!!" severity failure;
121
      case (core_p_sel) is
122
        when "11" =>
123
          core_data_in <= op_data(((i+1)*32)-1 downto (i*32));
124
        when "01" =>
125
          if (i < 16) then core_data_in <= op_data(((i+1)*32)-1 downto (i*32));
126
          else core_data_in <= x"00000000"; end if;
127
        when "10" =>
128
          if (i >= 16) then core_data_in <= op_data(((i-15)*32)-1 downto ((i-16)*32));
129
          else core_data_in <= x"00000000"; end if;
130
        when others =>
131
          core_data_in <= x"00000000";
132
      end case;
133
 
134
      wait until rising_edge(clk);
135
      core_rw_address <= core_rw_address+"000000001";
136
    end loop;
137
    core_write_enable <= '0';
138
    wait until rising_edge(clk);
139
  end loadOp;
140
 
141
 
142
  procedure readOp(constant op_sel : std_logic_vector(2 downto 0);
143
                  variable op_data  : out std_logic_vector(2047 downto 0);
144
                  variable op_width : integer) is
145
  begin
146
      wait until rising_edge(clk);
147
      core_dest_op_single <= op_sel(1 downto 0);
148
      if (core_p_sel = "10") then
149
        core_rw_address <= op_sel & "010000";
150
      else
151
        core_rw_address <= op_sel & "000000";
152
      end if;
153
      waitclk(2);
154
 
155
      for i in 0 to (op_width/32)-2 loop
156
          op_data(((i+1)*32)-1 downto (i*32)) := core_data_out;
157
          core_rw_address <= core_rw_address+"000000001";
158
          waitclk(2);
159
      end loop;
160
      op_data(op_width-1 downto op_width-32) := core_data_out;
161
      wait until rising_edge(clk);
162
  end readOp;
163
 
164
  function ToString(constant Timeval : time) return string is
165
    variable StrPtr : line;
166
  begin
167
    write(StrPtr,Timeval);
168
    return StrPtr.all;
169
  end ToString;
170
 
171
  -- variables to read file
172
  variable L : line;
173
  variable Lw : line;
174
  variable base_width : integer;
175
  variable exponent_width : integer;
176
  variable g0 : std_logic_vector(2047 downto 0) := (others=>'0');
177
  variable g1 : std_logic_vector(2047 downto 0) := (others=>'0');
178
  variable e0 : std_logic_vector(2047 downto 0) := (others=>'0');
179
  variable e1 : std_logic_vector(2047 downto 0) := (others=>'0');
180
  variable m : std_logic_vector(2047 downto 0) := (others=>'0');
181
  variable R2 : std_logic_vector(2047 downto 0) := (others=>'0');
182
  variable R : std_logic_vector(2047 downto 0) := (others=>'0');
183
  variable gt0 : std_logic_vector(2047 downto 0) := (others=>'0');
184
  variable gt1 : std_logic_vector(2047 downto 0) := (others=>'0');
185
  variable gt01 : std_logic_vector(2047 downto 0) := (others=>'0');
186
  variable one : std_logic_vector(2047 downto 0) := std_logic_vector(conv_unsigned(1, 2048));
187
  variable result : std_logic_vector(2047 downto 0) := (others=>'0');
188
  variable data_read : std_logic_vector(2047 downto 0) := (others=>'0');
189
  variable good_value : boolean;
190
  variable param_count : integer := 0;
191
 
192
  -- constants for operand selection
193
  constant op_modulus : std_logic_vector(2 downto 0) := "100";
194
  constant op_0 : std_logic_vector(2 downto 0) := "000";
195
  constant op_1 : std_logic_vector(2 downto 0) := "001";
196
  constant op_2 : std_logic_vector(2 downto 0) := "010";
197
  constant op_3 : std_logic_vector(2 downto 0) := "011";
198
 
199
  variable timer : time;
200
begin
201
  -- initialisation
202
  -- memory
203
  core_write_enable <= '0';
204
  core_data_in <= x"00000000";
205
  core_rw_address <= "000000000";
206
  -- fifo
207
  core_fifo_din <= x"00000000";
208
  core_fifo_push <= '0';
209
  -- control
210
  core_start <= '0';
211
  core_run_auto <= '0';
212
  core_x_sel_single <= "00";
213
  core_y_sel_single <= "01";
214
  core_dest_op_single <= "01";
215
  core_p_sel <= "11";
216
 
217
  -- Generate active high reset signal
218
  reset <= '1';
219
  waitclk(100);
220
  reset <= '0';
221
  waitclk(100);
222
 
223
  while not endfile(input) loop
224
    readline(input, L); -- read next line
225
    next when L(1)='-'; -- skip comment lines
226
    -- read input values
227
    case param_count is
228
      when 0 => -- base width
229
        read(L, base_width, good_value);
230
        assert good_value report "Can not read base width" severity failure;
231
        assert false report "Simulating exponentiation" severity note;
232
        write(Lw, string'("----------------------------------------------"));
233
        writeline(output, Lw);
234
        write(Lw, string'("--              EXPONENTIATION              --"));
235
        writeline(output, Lw);
236
        write(Lw, string'("----------------------------------------------"));
237
        writeline(output, Lw);
238
        write(Lw, string'("----- Variables used:"));
239
        writeline(output, Lw);
240
        write(Lw, string'("base width: "));
241
        write(Lw, base_width);
242
        writeline(output, Lw);
243
        case (base_width) is
244
          when 1536 => when 1024 => when 512 =>
245
          when others =>
246
            write(Lw, string'("=> incompatible base width!!!")); writeline(output, Lw);
247
            assert false report "incompatible base width!!!" severity failure;
248
        end case;
249
 
250
      when 1 => -- exponent width
251
        read(L, exponent_width, good_value);
252
        assert good_value report "Can not read exponent width" severity failure;
253
        write(Lw, string'("exponent width: "));
254
        write(Lw, exponent_width);
255
        writeline(output, Lw);
256
 
257
      when 2 => -- g0
258
        hread(L, g0(base_width-1 downto 0), good_value);
259
        assert good_value report "Can not read g0! (wrong lenght?)" severity failure;
260
        write(Lw, string'("g0: "));
261
        hwrite(Lw, g0(base_width-1 downto 0));
262
        writeline(output, Lw);
263
 
264
      when 3 => -- g1
265
        hread(L, g1(base_width-1 downto 0), good_value);
266
        assert good_value report "Can not read g1! (wrong lenght?)" severity failure;
267
        write(Lw, string'("g1: "));
268
        hwrite(Lw, g1(base_width-1 downto 0));
269
        writeline(output, Lw);
270
 
271
      when 4 => -- e0
272
        hread(L, e0(exponent_width-1 downto 0), good_value);
273
        assert good_value report "Can not read e0! (wrong lenght?)" severity failure;
274
        write(Lw, string'("e0: "));
275
        hwrite(Lw, e0(exponent_width-1 downto 0));
276
        writeline(output, Lw);
277
 
278
      when 5 => -- e1
279
        hread(L, e1(exponent_width-1 downto 0), good_value);
280
        assert good_value report "Can not read e1! (wrong lenght?)" severity failure;
281
        write(Lw, string'("e1: "));
282
        hwrite(Lw, e1(exponent_width-1 downto 0));
283
        writeline(output, Lw);
284
 
285
      when 6 => -- m
286
        hread(L, m(base_width-1 downto 0), good_value);
287
        assert good_value report "Can not read m! (wrong lenght?)" severity failure;
288
        write(Lw, string'("m:  "));
289
        hwrite(Lw, m(base_width-1 downto 0));
290
        writeline(output, Lw);
291
 
292
      when 7 => -- R^2
293
        hread(L, R2(base_width-1 downto 0), good_value);
294
        assert good_value report "Can not read R2! (wrong lenght?)" severity failure;
295
        write(Lw, string'("R2: "));
296
        hwrite(Lw, R2(base_width-1 downto 0));
297
        writeline(output, Lw);
298
 
299
      when 8 => -- R
300
        hread(L, R(base_width-1 downto 0), good_value);
301
        assert good_value report "Can not read R! (wrong lenght?)" severity failure;
302
 
303
      when 9 => -- gt0
304
        hread(L, gt0(base_width-1 downto 0), good_value);
305
        assert good_value report "Can not read gt0! (wrong lenght?)" severity failure;
306
 
307
      when 10 => -- gt1
308
        hread(L, gt1(base_width-1 downto 0), good_value);
309
        assert good_value report "Can not read gt1! (wrong lenght?)" severity failure;
310
 
311
      when 11 => -- gt01
312
        hread(L, gt01(base_width-1 downto 0), good_value);
313
        assert good_value report "Can not read gt01! (wrong lenght?)" severity failure;
314
 
315
        -- select pipeline for all computations
316
        ----------------------------------------
317
        writeline(output, Lw);
318
        write(Lw, string'("----- Selecting pipeline: "));
319
        writeline(output, Lw);
320
        case (base_width) is
321
          when 1536 =>  core_p_sel <= "11"; write(Lw, string'("  Full pipeline selected"));
322
          when 1024 =>  core_p_sel <= "10"; write(Lw, string'("  Upper pipeline selected"));
323
          when 512  =>  core_p_sel <= "01"; write(Lw, string'("  Lower pipeline selected"));
324
          when others =>
325
            write(Lw, string'("  Invallid bitwidth for design"));
326
            assert false report "impossible basewidth!" severity failure;
327
        end case;
328
        writeline(output, Lw);
329
 
330
        writeline(output, Lw);
331
        write(Lw, string'("----- Writing operands:"));
332
        writeline(output, Lw);
333
 
334
        -- load the modulus
335
        --------------------
336
        loadOp(op_modulus, m); -- visual check needed
337
        write(Lw, string'("  m written"));
338
        writeline(output, Lw);
339
 
340
        -- load g0
341
        -----------
342
        loadOp(op_0, g0);
343
        -- verify
344
        readOp(op_0, data_read, base_width);
345
        if (g0(base_width-1 downto 0) = data_read(base_width-1 downto 0)) then
346
          write(Lw, string'("  g0 written in operand_0")); writeline(output, Lw);
347
        else
348
          write(Lw, string'("  failed to write g0 to operand_0!")); writeline(output, Lw);
349
          assert false report "Load g0 to op0 data verify failed!!" severity failure;
350
        end if;
351
 
352
        -- load g1
353
        -----------
354
        loadOp(op_1, g1);
355
        -- verify
356
        readOp(op_1, data_read, base_width);
357
        if (g1(base_width-1 downto 0) = data_read(base_width-1 downto 0)) then
358
          write(Lw, string'("  g1 written in operand_1")); writeline(output, Lw);
359
        else
360
          write(Lw, string'("  failed to write g1 to operand_1!")); writeline(output, Lw);
361
          assert false report "Load g1 to op1 data verify failed!!" severity failure;
362
        end if;
363
 
364
        -- load R2
365
        -----------
366
        loadOp(op_2, R2);
367
        -- verify
368
        readOp(op_2, data_read, base_width);
369
        if (R2(base_width-1 downto 0) = data_read(base_width-1 downto 0)) then
370
          write(Lw, string'("  R^2 written in operand_2")); writeline(output, Lw);
371
        else
372
          write(Lw, string'("  failed to write R^2 to operand_2!")); writeline(output, Lw);
373
          assert false report "Load R2 to op2 data verify failed!!" severity failure;
374
        end if;
375
 
376
        -- load a=1
377
        ------------
378
        loadOp(op_3, one);
379
        -- verify
380
        readOp(op_3, data_read, base_width);
381
        if (one(base_width-1 downto 0) = data_read(base_width-1 downto 0)) then
382
          write(Lw, string'("  1 written in operand_3")); writeline(output, Lw);
383
        else
384
          write(Lw, string'("  failed to write 1 to operand_3!")); writeline(output, Lw);
385
          assert false report "Load 1 to op3 data verify failed!!" severity failure;
386
        end if;
387
 
388
        writeline(output, Lw);
389
        write(Lw, string'("----- Pre-computations: "));
390
        writeline(output, Lw);
391
 
392
        -- compute gt0
393
        ---------------
394
        core_x_sel_single <= "00"; -- g0
395
        core_y_sel_single <= "10"; -- R^2
396
        core_dest_op_single <= "00"; -- op_0 = (g0 * R) mod m
397
        wait until rising_edge(clk);
398
        timer := NOW;
399
        core_start <= '1';
400
        wait until rising_edge(clk);
401
        core_start <= '0';
402
        wait until core_ready = '1';
403
        timer := NOW-timer;
404
        waitclk(10);
405
        readOp(op_0, data_read, base_width);
406
        write(Lw, string'("  Computed gt0: "));
407
        hwrite(Lw, data_read(base_width-1 downto 0));
408
        writeline(output, Lw);
409
        write(Lw, string'("  Read gt0:     "));
410
        hwrite(Lw, gt0(base_width-1 downto 0));
411
        writeline(output, Lw);
412
        write(Lw, string'("  => calc time is "));
413
        write(Lw, string'(ToString(timer)));
414
        writeline(output, Lw);
415
        write(Lw, string'("  => expected time is "));
416
        write(Lw, (nr_stages+(2*(base_width-1)))*clk_period);
417
        writeline(output, Lw);
418
        if (gt0(base_width-1 downto 0) = data_read(base_width-1 downto 0)) then
419
          write(Lw, string'("  => gt0 is correct!")); writeline(output, Lw);
420
        else
421
          write(Lw, string'("  => Error: gt0 is incorrect!!!")); writeline(output, Lw);
422
          assert false report "gt0 is incorrect!!!" severity failure;
423
        end if;
424
 
425
        -- compute gt1
426
        ---------------
427
        core_x_sel_single <= "01"; -- g1
428
        core_y_sel_single <= "10"; -- R^2
429
        core_dest_op_single <= "01"; -- op_1 = (g1 * R) mod m
430
        wait until rising_edge(clk);
431
        timer := NOW;
432
        core_start <= '1';
433
        wait until rising_edge(clk);
434
        core_start <= '0';
435
        wait until core_ready = '1';
436
        timer := NOW-timer;
437
        waitclk(10);
438
        readOp(op_1, data_read, base_width);
439
        write(Lw, string'("  Computed gt1: "));
440
        hwrite(Lw, data_read(base_width-1 downto 0));
441
        writeline(output, Lw);
442
        write(Lw, string'("  Read gt1:     "));
443
        hwrite(Lw, gt1(base_width-1 downto 0));
444
        writeline(output, Lw);
445
        write(Lw, string'("  => calc time is "));
446
        write(Lw, string'(ToString(timer)));
447
        writeline(output, Lw);
448
        write(Lw, string'("  => expected time is "));
449
        write(Lw, (nr_stages+(2*(base_width-1)))*clk_period);
450
        writeline(output, Lw);
451
        if (gt1(base_width-1 downto 0) = data_read(base_width-1 downto 0)) then
452
          write(Lw, string'("  => gt1 is correct!")); writeline(output, Lw);
453
        else
454
          write(Lw, string'("  => Error: gt1 is incorrect!!!")); writeline(output, Lw);
455
          assert false report "gt1 is incorrect!!!" severity failure;
456
        end if;
457
 
458
        -- compute a
459
        -------------
460
        core_x_sel_single <= "10"; -- R^2
461
        core_y_sel_single <= "11"; -- 1
462
        core_dest_op_single <= "11"; -- op_3 = (R) mod m
463
        wait until rising_edge(clk);
464
        core_start <= '1';
465
        timer := NOW;
466
        wait until rising_edge(clk);
467
        core_start <= '0';
468
        wait until core_ready = '1';
469
        timer := NOW-timer;
470
        waitclk(10);
471
        readOp(op_3, data_read, base_width);
472
        write(Lw, string'("  Computed a=(R)mod m: "));
473
        hwrite(Lw, data_read(base_width-1 downto 0));
474
        writeline(output, Lw);
475
        write(Lw, string'("  Read (R)mod m:       "));
476
        hwrite(Lw, R(base_width-1 downto 0));
477
        writeline(output, Lw);
478
        write(Lw, string'("  => calc time is "));
479
        write(Lw, string'(ToString(timer)));
480
        writeline(output, Lw);
481
        write(Lw, string'("  => expected time is "));
482
        write(Lw, (nr_stages+(2*(base_width-1)))*clk_period);
483
        writeline(output, Lw);
484
        if (R(base_width-1 downto 0) = data_read(base_width-1 downto 0)) then
485
          write(Lw, string'("  => (R)mod m is correct!")); writeline(output, Lw);
486
        else
487
          write(Lw, string'("  => Error: (R)mod m is incorrect!!!")); writeline(output, Lw);
488
          assert false report "(R)mod m is incorrect!!!" severity failure;
489
        end if;
490
 
491
        -- compute gt01
492
        ---------------
493
        core_x_sel_single <= "00"; -- gt0
494
        core_y_sel_single <= "01"; -- gt1
495
        core_dest_op_single <= "10"; -- op_2 = (gt0 * gt1) mod m
496
        wait until rising_edge(clk);
497
        core_start <= '1';
498
        timer := NOW;
499
        wait until rising_edge(clk);
500
        core_start <= '0';
501
        wait until core_ready = '1';
502
        timer := NOW-timer;
503
        waitclk(10);
504
        readOp(op_2, data_read, base_width);
505
        write(Lw, string'("  Computed gt01: "));
506
        hwrite(Lw, data_read(base_width-1 downto 0));
507
        writeline(output, Lw);
508
        write(Lw, string'("  Read gt01:     "));
509
        hwrite(Lw, gt01(base_width-1 downto 0));
510
        writeline(output, Lw);
511
        write(Lw, string'("  => calc time is "));
512
        write(Lw, string'(ToString(timer)));
513
        writeline(output, Lw);
514
        write(Lw, string'("  => expected time is "));
515
        write(Lw, (nr_stages+(2*(base_width-1)))*clk_period);
516
        writeline(output, Lw);
517
        if (gt01(base_width-1 downto 0) = data_read(base_width-1 downto 0)) then
518
          write(Lw, string'("  => gt01 is correct!")); writeline(output, Lw);
519
        else
520
          write(Lw, string'("  => Error: gt01 is incorrect!!!")); writeline(output, Lw);
521
          assert false report "gt01 is incorrect!!!" severity failure;
522
        end if;
523
 
524
        -- load exponent fifo
525
        ----------------------
526
        writeline(output, Lw);
527
        write(Lw, string'("----- Loading exponent fifo: "));
528
        writeline(output, Lw);
529
        for i in (exponent_width/16)-1 downto 0 loop
530
          core_fifo_din <= e1((i*16)+15 downto (i*16)) & e0((i*16)+15 downto (i*16));
531
          wait until rising_edge(clk);
532
          core_fifo_push <= '1';
533
          wait until rising_edge(clk);
534
          assert (core_fifo_full='0' and core_fifo_nopush='0')
535
            report "Fifo error, full or nopush" severity failure;
536
          core_fifo_push <= '0';
537
          wait until rising_edge(clk);
538
        end loop;
539
        waitclk(10);
540
        write(Lw, string'("  Done"));
541
        writeline(output, Lw);
542
 
543
        -- start exponentiation
544
        ------------------------
545
        writeline(output, Lw);
546
        write(Lw, string'("----- Starting exponentiation: "));
547
        writeline(output, Lw);
548
        core_run_auto <= '1';
549
        wait until rising_edge(clk);
550
        timer := NOW;
551
        core_start <= '1';
552
        wait until rising_edge(clk);
553
        core_start <= '0';
554
        wait until core_ready='1';
555
        timer := NOW-timer;
556
        waitclk(10);
557
        write(Lw, string'("  => calc time is "));
558
        write(Lw, string'(ToString(timer)));
559
        writeline(output, Lw);
560
        write(Lw, string'("  => expected time is "));
561
        write(Lw, ((nr_stages+(2*(base_width-1)))*clk_period*7*exponent_width)/4);
562
        writeline(output, Lw);
563
        write(Lw, string'("  => Done"));
564
        core_run_auto <= '0';
565
        writeline(output, Lw);
566
 
567
        -- post-computations
568
        ---------------------
569
        writeline(output, Lw);
570
        write(Lw, string'("----- Post-computations: "));
571
        writeline(output, Lw);
572
        -- load in 1 to operand 2
573
        loadOp(op_2, one);
574
        -- verify
575
        readOp(op_2, data_read, base_width);
576
        if (one(base_width-1 downto 0) = data_read(base_width-1 downto 0)) then
577
          write(Lw, string'("  1 written in operand_2")); writeline(output, Lw);
578
        else
579
          write(Lw, string'("  failed to write 1 to operand_2!")); writeline(output, Lw);
580
          assert false report "Load 1 to op2 data verify failed!!" severity failure;
581
        end if;
582
        -- compute result
583
        core_x_sel_single <= "11"; -- a
584
        core_y_sel_single <= "10"; -- 1
585
        core_dest_op_single <= "11"; -- op_3 = (a) mod m
586
        wait until rising_edge(clk);
587
        timer := NOW;
588
        core_start <= '1';
589
        wait until rising_edge(clk);
590
        core_start <= '0';
591
        wait until core_ready = '1';
592
        timer := NOW-timer;
593
        waitclk(10);
594
        readOp(op_3, data_read, base_width);
595
        write(Lw, string'("  Computed result: "));
596
        hwrite(Lw, data_read(base_width-1 downto 0));
597
        writeline(output, Lw);
598
        write(Lw, string'("  => calc time is "));
599
        write(Lw, string'(ToString(timer)));
600
        writeline(output, Lw);
601
        write(Lw, string'("  => expected time is "));
602
        write(Lw, (nr_stages+(2*(base_width-1)))*clk_period);
603
        writeline(output, Lw);
604
 
605
      when 12 => -- check with result
606
        hread(L, result(base_width-1 downto 0), good_value);
607
        assert good_value report "Can not read result! (wrong lenght?)" severity failure;
608
        writeline(output, Lw);
609
        write(Lw, string'("----- verifying result: "));
610
        writeline(output, Lw);
611
        write(Lw, string'("  Read result:     "));
612
        hwrite(Lw, result(base_width-1 downto 0));
613
        writeline(output, Lw);
614
        write(Lw, string'("  Computed result: "));
615
        hwrite(Lw, data_read(base_width-1 downto 0));
616
        writeline(output, Lw);
617
        if (result(base_width-1 downto 0) = data_read(base_width-1 downto 0)) then
618
          write(Lw, string'("  => Result is correct!")); writeline(output, Lw);
619
        else
620
          write(Lw, string'("  Error: result is incorrect!!!")); writeline(output, Lw);
621
          assert false report "result is incorrect!!!" severity failure;
622
        end if;
623
        writeline(output, Lw);
624
 
625
      when others =>
626
        assert false report "undefined state!" severity failure;
627
    end case;
628
 
629
    if (param_count = 12) then
630
      param_count := 0;
631
    else
632
      param_count := param_count+1;
633
    end if;
634
  end loop;
635
 
636
  wait for 1 us;
637
  assert false report "End of simulation" severity failure;
638
 
639
end process;
640
 
641
------------------------------------------
642
-- Multiplier core instance
643
------------------------------------------
644
the_multiplier : multiplier_core
645
port map(
646
  clk   => clk,
647
  reset => reset,
648
-- operand memory interface (plb shared memory)
649
  write_enable => core_write_enable,
650
  data_in      => core_data_in,
651
  rw_address   => core_rw_address,
652
  data_out     => core_data_out,
653
  collision    => core_mem_collision,
654
-- op_sel fifo interface
655
  fifo_din    => core_fifo_din,
656
  fifo_push   => core_fifo_push,
657
  fifo_full   => core_fifo_full,
658
  fifo_nopush => core_fifo_nopush,
659
-- ctrl signals
660
  start          => core_start,
661
  run_auto       => core_run_auto,
662
  ready          => core_ready,
663
  x_sel_single   => core_x_sel_single,
664
  y_sel_single   => core_y_sel_single,
665
  dest_op_single => core_dest_op_single,
666
  p_sel          => core_p_sel,
667
  calc_time      => calc_time
668
);
669
 
670
 
671
end test;
672
 

powered by: WebSVN 2.1.0

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