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

Subversion Repositories mod_sim_exp

[/] [mod_sim_exp/] [trunk/] [bench/] [vhdl/] [multiplier_tb.vhd] - Blame information for rev 41

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

Line No. Rev Author Line
1 26 JonasDC
----------------------------------------------------------------------  
2
----  mod_sim_exp_core_tb                                               ---- 
3
----                                                              ---- 
4
----  This file is part of the                                    ----
5
----    Modular Simultaneous Exponentiation Core project          ---- 
6
----    http://www.opencores.org/cores/mod_sim_exp/               ---- 
7
----                                                              ---- 
8
----  Description                                                 ---- 
9
----    testbench for the modular simultaneous exponentiation     ----
10
----    core. Performs some exponentiations to verify the design  ----
11
----    Takes input parameters from sim_input.txt en writes       ----
12
----    result and output to sim_output.txt                       ----
13
----                                                              ----
14
----  Dependencies:                                               ----
15
----    - multiplier_core                                         ----
16
----                                                              ----
17
----  Authors:                                                    ----
18
----      - Geoffrey Ottoy, DraMCo research group                 ----
19
----      - Jonas De Craene, JonasDC@opencores.org                ---- 
20
----                                                              ---- 
21
---------------------------------------------------------------------- 
22
----                                                              ---- 
23
---- Copyright (C) 2011 DraMCo research group and OPENCORES.ORG   ---- 
24
----                                                              ---- 
25
---- This source file may be used and distributed without         ---- 
26
---- restriction provided that this copyright statement is not    ---- 
27
---- removed from the file and that any derivative work contains  ---- 
28
---- the original copyright notice and the associated disclaimer. ---- 
29
----                                                              ---- 
30
---- This source file is free software; you can redistribute it   ---- 
31
---- and/or modify it under the terms of the GNU Lesser General   ---- 
32
---- Public License as published by the Free Software Foundation; ---- 
33
---- either version 2.1 of the License, or (at your option) any   ---- 
34
---- later version.                                               ---- 
35
----                                                              ---- 
36
---- This source is distributed in the hope that it will be       ---- 
37
---- useful, but WITHOUT ANY WARRANTY; without even the implied   ---- 
38
---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ---- 
39
---- PURPOSE.  See the GNU Lesser General Public License for more ---- 
40
---- details.                                                     ---- 
41
----                                                              ---- 
42
---- You should have received a copy of the GNU Lesser General    ---- 
43
---- Public License along with this source; if not, download it   ---- 
44
---- from http://www.opencores.org/lgpl.shtml                     ---- 
45
----                                                              ---- 
46
----------------------------------------------------------------------
47
 
48
library ieee;
49
use ieee.std_logic_1164.all;
50
use ieee.std_logic_unsigned.all;
51
use ieee.std_logic_arith.all;
52
 
53
library std;
54
use std.textio.all;
55
 
56
library ieee;
57
use ieee.std_logic_textio.all;
58
 
59
library mod_sim_exp;
60
use mod_sim_exp.mod_sim_exp_pkg.all;
61
 
62
entity multiplier_tb is
63
end multiplier_tb;
64
 
65
architecture test of multiplier_tb is
66
  constant nr_stages  : integer := 96;
67
  constant clk_period : time := 10 ns;
68
  signal clk          : std_logic := '0';
69
  signal reset        : std_logic := '1';
70
  file input          : text open read_mode is "src/sim_mult_input.txt";
71
  file output         : text open write_mode is "out/sim_mult_output.txt";
72
 
73
  ------------------------------------------------------------------
74
  -- Signals for multiplier core memory space
75
  ------------------------------------------------------------------
76
  constant n : integer := 1536;
77
  constant t : integer := 96;
78
  constant tl : integer := 0;
79
 
80
  -- data busses
81
  signal xy   : std_logic_vector(n-1 downto 0);  -- x and y operand data bus RAM -> multiplier
82
  signal m    : std_logic_vector(n-1 downto 0);  -- modulus data bus RAM -> multiplier
83
  signal r    : std_logic_vector(n-1 downto 0);  -- result data bus RAM <- multiplier
84
 
85
  -- control signals
86
  signal p_sel           : std_logic_vector(1 downto 0); -- operand selection 
87
  signal result_dest_op   : std_logic_vector(1 downto 0); -- result destination operand
88
  signal ready       : std_logic;
89
  signal start       : std_logic;
90
  signal load_op          : std_logic;
91
  signal load_x         : std_logic;
92
  signal load_m           : std_logic;
93
  signal load_result      : std_logic;
94
 
95
begin
96
 
97
------------------------------------------
98
-- Generate clk
99
------------------------------------------
100
clk_process : process
101
begin
102
  while (true) loop
103
    clk <= '0';
104
    wait for clk_period/2;
105
    clk <= '1';
106
    wait for clk_period/2;
107
  end loop;
108
end process;
109
 
110
------------------------------------------
111
-- Stimulus Process
112
------------------------------------------
113
stim_proc : process
114
  procedure waitclk(n : natural := 1) is
115
  begin
116
    for i in 1 to n loop
117
      wait until rising_edge(clk);
118
    end loop;
119
  end waitclk;
120
 
121
  function ToString(constant Timeval : time) return string is
122
    variable StrPtr : line;
123
  begin
124
    write(StrPtr,Timeval);
125
    return StrPtr.all;
126
  end ToString;
127
 
128
  -- variables to read file
129
  variable L : line;
130
  variable Lw : line;
131
  variable x_op : std_logic_vector((n-1) downto 0) := (others=>'0');
132
  variable y_op : std_logic_vector((n-1) downto 0) := (others=>'0');
133
  variable m_op : std_logic_vector((n-1) downto 0) := (others=>'0');
134
  variable result : std_logic_vector((n-1) downto 0) := (others=>'0');
135
  variable one : std_logic_vector(2047 downto 0) := std_logic_vector(conv_unsigned(1, 2048));
136
  variable data_read : std_logic_vector(2047 downto 0) := (others=>'0');
137
  variable good_value : boolean;
138
  variable param_count : integer := 0;
139
 
140
  variable timer : time;
141
begin
142
  -- initialisation
143
  xy <= (others=>'0');
144
  m <= (others=>'0');
145
  start <='0';
146
  reset <= '0';
147
  p_sel <= "11";
148
  load_x <= '0';
149
 
150
  -- Generate active high reset signal
151
  reset <= '1';
152
  waitclk(10);
153
  reset <= '0';
154
  waitclk(10);
155
 
156
  while not endfile(input) loop
157
    readline(input, L); -- read next line
158
    next when L(1)='-'; -- skip comment lines
159
    -- read input values
160
    case param_count is
161
      when 0 => -- base width
162
        hread(L, x_op, good_value);
163
        assert good_value report "Can not read x operand" severity failure;
164
        assert false report "Simulating multiplication" severity note;
165
        write(Lw, string'("----------------------------------------------"));
166
        writeline(output, Lw);
167
        write(Lw, string'("--              MULTIPLICATION              --"));
168
        writeline(output, Lw);
169
        write(Lw, string'("----------------------------------------------"));
170
        writeline(output, Lw);
171
        write(Lw, string'("----- Variables used:"));
172
        writeline(output, Lw);
173
        write(Lw, string'("x: "));
174
        hwrite(Lw, x_op);
175
        writeline(output, Lw);
176
 
177
      when 1 =>
178
        hread(L, y_op, good_value);
179
        assert good_value report "Can not read y operand" severity failure;
180
        write(Lw, string'("y: "));
181
        hwrite(Lw, y_op);
182
        writeline(output, Lw);
183
 
184
      when 2 =>
185
        hread(L, m_op, good_value);
186
        assert good_value report "Can not read m operand" severity failure;
187
        write(Lw, string'("m: "));
188
        hwrite(Lw, m_op);
189
        writeline(output, Lw);
190
 
191
        -- load in x
192
        xy <= x_op;
193
        wait until rising_edge(clk);
194
        load_x <='1';
195
        wait until rising_edge(clk);
196
        load_x <='0';
197
 
198
        -- put y and m on the bus
199
        xy <= y_op;
200
        m <= m_op;
201
        wait until rising_edge(clk);
202
 
203
        -- start multiplication and wait for result
204
        start <= '1';
205
        wait until rising_edge(clk);
206
        start <= '0';
207
 
208
        wait until ready='1';
209
        wait until rising_edge(clk);
210
        writeline(output, Lw);
211
        write(Lw, string'("  Computed result: "));
212
        hwrite(Lw, r);
213
        writeline(output, Lw);
214
 
215
      when 3 =>
216
        hread(L, result, good_value);
217
        assert good_value report "Can not read result" severity failure;
218
        write(Lw, string'("  Read result:     "));
219
        hwrite(Lw, result);
220
        writeline(output, Lw);
221
 
222
        if (r = result) then
223
          write(Lw, string'("  => result is correct!")); writeline(output, Lw);
224
        else
225
          write(Lw, string'("  => Error: result is incorrect!!!")); writeline(output, Lw);
226
          assert false report "result is incorrect!!!" severity error;
227
        end if;
228
 
229
      when others =>
230
        assert false report "undefined state!" severity failure;
231
    end case;
232
 
233
    if (param_count = 3) then
234
      param_count := 0;
235
    else
236
      param_count := param_count+1;
237
    end if;
238
  end loop;
239
 
240
  wait for 1 us;
241
  assert false report "End of simulation" severity failure;
242
 
243
end process;
244
 
245
------------------------------------------
246
-- Multiplier instance
247
------------------------------------------
248
the_multiplier : mont_multiplier
249
  generic map(
250
    n          => n,
251
    nr_stages  => t,
252
    stages_low => tl
253
  )
254
  port map(
255
    core_clk => clk,
256
    xy       => xy,
257
    m        => m,
258
    r        => r,
259
    start    => start,
260
    reset    => reset,
261
    p_sel    => p_sel,
262
    load_x   => load_x,
263
    ready    => ready
264
  );
265
 
266
end test;

powered by: WebSVN 2.1.0

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