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

Subversion Repositories mod_sim_exp

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /mod_sim_exp/tags/Release_1.5/bench/vhdl
    from Rev 94 to Rev 104
    Reverse comparison

Rev 94 → Rev 104

/mod_sim_exp_core_tb.vhd
0,0 → 1,723
----------------------------------------------------------------------
---- mod_sim_exp_core_tb ----
---- ----
---- This file is part of the ----
---- Modular Simultaneous Exponentiation Core project ----
---- http://www.opencores.org/cores/mod_sim_exp/ ----
---- ----
---- Description ----
---- testbench for the modular simultaneous exponentiation ----
---- core. Performs some exponentiations to verify the design ----
---- Takes input parameters from sim_input.txt en writes ----
---- result and output to sim_output.txt ----
---- ----
---- Dependencies: ----
---- - multiplier_core ----
---- ----
---- Authors: ----
---- - Geoffrey Ottoy, DraMCo research group ----
---- - Jonas De Craene, JonasDC@opencores.org ----
---- ----
----------------------------------------------------------------------
---- ----
---- Copyright (C) 2011 DraMCo research group and OPENCORES.ORG ----
---- ----
---- This source file may be used and distributed without ----
---- restriction provided that this copyright statement is not ----
---- removed from the file and that any derivative work contains ----
---- the original copyright notice and the associated disclaimer. ----
---- ----
---- This source file is free software; you can redistribute it ----
---- and/or modify it under the terms of the GNU Lesser General ----
---- Public License as published by the Free Software Foundation; ----
---- either version 2.1 of the License, or (at your option) any ----
---- later version. ----
---- ----
---- This source is distributed in the hope that it will be ----
---- useful, but WITHOUT ANY WARRANTY; without even the implied ----
---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ----
---- PURPOSE. See the GNU Lesser General Public License for more ----
---- details. ----
---- ----
---- You should have received a copy of the GNU Lesser General ----
---- Public License along with this source; if not, download it ----
---- from http://www.opencores.org/lgpl.shtml ----
---- ----
----------------------------------------------------------------------
 
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
 
library std;
use std.textio.all;
 
library ieee;
use ieee.std_logic_textio.all;
 
library mod_sim_exp;
use mod_sim_exp.mod_sim_exp_pkg.all;
 
entity mod_sim_exp_core_tb is
end mod_sim_exp_core_tb;
 
architecture test of mod_sim_exp_core_tb is
constant CLK_PERIOD : time := 10 ns;
signal clk : std_logic := '0';
constant CORE_CLK_PERIOD : time := 4 ns;
signal core_clk : std_logic := '0';
signal reset : std_logic := '1';
file input : text open read_mode is "src/sim_input.txt";
file output : text open write_mode is "out/sim_output.txt";
------------------------------------------------------------------
-- Core parameters
------------------------------------------------------------------
constant C_NR_BITS_TOTAL : integer := 1536;
constant C_NR_STAGES_TOTAL : integer := 96;
constant C_NR_STAGES_LOW : integer := 32;
constant C_SPLIT_PIPELINE : boolean := true;
constant C_FIFO_AW : integer := 7; -- set to log2( (maximum exponent width)/16 )
constant C_MEM_STYLE : string := "asym"; -- xil_prim, generic, asym are valid options
constant C_FPGA_MAN : string := "xilinx"; -- xilinx, altera are valid options
-- extra calculated constants
constant NR_BITS_LOW : integer := (C_NR_BITS_TOTAL/C_NR_STAGES_TOTAL)*C_NR_STAGES_LOW;
constant NR_BITS_HIGH : integer := C_NR_BITS_TOTAL-NR_BITS_LOW;
------------------------------------------------------------------
-- Signals for multiplier core memory space
------------------------------------------------------------------
signal core_rw_address : std_logic_vector (8 downto 0);
signal core_data_in : std_logic_vector(31 downto 0);
signal core_fifo_din : std_logic_vector(31 downto 0);
signal core_data_out : std_logic_vector(31 downto 0);
signal core_write_enable : std_logic;
signal core_fifo_push : std_logic;
------------------------------------------------------------------
-- Signals for multiplier core control
------------------------------------------------------------------
signal core_start : std_logic;
signal core_exp_m : std_logic;
signal core_p_sel : std_logic_vector(1 downto 0);
signal core_dest_op_single : std_logic_vector(1 downto 0);
signal core_x_sel_single : std_logic_vector(1 downto 0);
signal core_y_sel_single : std_logic_vector(1 downto 0);
signal calc_time : std_logic;
------------------------------------------------------------------
-- Signals for multiplier core interrupt
------------------------------------------------------------------
signal core_fifo_full : std_logic;
signal core_fifo_nopush : std_logic;
signal core_ready : std_logic;
signal core_mem_collision : std_logic;
 
begin
 
------------------------------------------
-- Generate clk
------------------------------------------
clk_process : process
begin
while (true) loop
clk <= '0';
wait for CLK_PERIOD/2;
clk <= '1';
wait for CLK_PERIOD/2;
end loop;
end process;
 
core_clk_process : process
begin
while (true) loop
core_clk <= '0';
wait for CORE_CLK_PERIOD/2;
core_clk <= '1';
wait for CORE_CLK_PERIOD/2;
end loop;
end process;
 
------------------------------------------
-- Stimulus Process
------------------------------------------
stim_proc : process
procedure waitclk(n : natural := 1) is
begin
for i in 1 to n loop
wait until rising_edge(clk);
end loop;
end waitclk;
procedure loadOp(constant op_sel : std_logic_vector(2 downto 0);
variable op_data : std_logic_vector(2047 downto 0)) is
begin
wait until rising_edge(clk);
core_rw_address <= op_sel & "000000";
wait until rising_edge(clk);
core_write_enable <= '1';
for i in 0 to (1536/32)-1 loop
assert (core_mem_collision='0')
report "collision detected while writing operand!!" severity failure;
case (core_p_sel) is
when "11" =>
core_data_in <= op_data(((i+1)*32)-1 downto (i*32));
when "01" =>
if (i < 16) then core_data_in <= op_data(((i+1)*32)-1 downto (i*32));
else core_data_in <= x"00000000"; end if;
when "10" =>
if (i >= 16) then core_data_in <= op_data(((i-15)*32)-1 downto ((i-16)*32));
else core_data_in <= x"00000000"; end if;
when others =>
core_data_in <= x"00000000";
end case;
wait until rising_edge(clk);
core_rw_address <= core_rw_address+"000000001";
end loop;
core_write_enable <= '0';
wait until rising_edge(clk);
end loadOp;
procedure readOp(constant op_sel : std_logic_vector(2 downto 0);
variable op_data : out std_logic_vector(2047 downto 0);
variable op_width : integer) is
begin
wait until rising_edge(clk);
core_dest_op_single <= op_sel(1 downto 0);
if (core_p_sel = "10") then
core_rw_address <= op_sel & "010000";
else
core_rw_address <= op_sel & "000000";
end if;
waitclk(2);
for i in 0 to (op_width/32)-2 loop
op_data(((i+1)*32)-1 downto (i*32)) := core_data_out;
core_rw_address <= core_rw_address+"000000001";
waitclk(2);
end loop;
op_data(op_width-1 downto op_width-32) := core_data_out;
wait until rising_edge(clk);
end readOp;
 
function ToString(constant Timeval : time) return string is
variable StrPtr : line;
begin
write(StrPtr,Timeval);
return StrPtr.all;
end ToString;
 
-- variables to read file
variable L : line;
variable Lw : line;
variable base_width : integer;
variable exponent_width : integer;
variable g0 : std_logic_vector(2047 downto 0) := (others=>'0');
variable g1 : std_logic_vector(2047 downto 0) := (others=>'0');
variable e0 : std_logic_vector(2047 downto 0) := (others=>'0');
variable e1 : std_logic_vector(2047 downto 0) := (others=>'0');
variable m : std_logic_vector(2047 downto 0) := (others=>'0');
variable R2 : std_logic_vector(2047 downto 0) := (others=>'0');
variable R : std_logic_vector(2047 downto 0) := (others=>'0');
variable gt0 : std_logic_vector(2047 downto 0) := (others=>'0');
variable gt1 : std_logic_vector(2047 downto 0) := (others=>'0');
variable gt01 : std_logic_vector(2047 downto 0) := (others=>'0');
variable one : std_logic_vector(2047 downto 0) := std_logic_vector(conv_unsigned(1, 2048));
variable result : std_logic_vector(2047 downto 0) := (others=>'0');
variable data_read : std_logic_vector(2047 downto 0) := (others=>'0');
variable good_value : boolean;
variable param_count : integer := 0;
-- constants for operand selection
constant op_modulus : std_logic_vector(2 downto 0) := "100";
constant op_0 : std_logic_vector(2 downto 0) := "000";
constant op_1 : std_logic_vector(2 downto 0) := "001";
constant op_2 : std_logic_vector(2 downto 0) := "010";
constant op_3 : std_logic_vector(2 downto 0) := "011";
variable timer : time;
begin
-- initialisation
-- memory
core_write_enable <= '0';
core_data_in <= x"00000000";
core_rw_address <= "000000000";
-- fifo
core_fifo_din <= x"00000000";
core_fifo_push <= '0';
-- control
core_start <= '0';
core_exp_m <= '0';
core_x_sel_single <= "00";
core_y_sel_single <= "01";
core_dest_op_single <= "01";
core_p_sel <= "11";
-- Generate active high reset signal
reset <= '1';
waitclk(100);
reset <= '0';
waitclk(100);
while not endfile(input) loop
readline(input, L); -- read next line
next when L(1)='-'; -- skip comment lines
-- read input values
case param_count is
when 0 => -- base width
read(L, base_width, good_value);
assert good_value report "Can not read base width" severity failure;
assert false report "Simulating exponentiation" severity note;
write(Lw, string'("----------------------------------------------"));
writeline(output, Lw);
write(Lw, string'("-- EXPONENTIATION --"));
writeline(output, Lw);
write(Lw, string'("----------------------------------------------"));
writeline(output, Lw);
write(Lw, string'("----- Variables used:"));
writeline(output, Lw);
write(Lw, string'("base width: "));
write(Lw, base_width);
writeline(output, Lw);
case (base_width) is
when C_NR_BITS_TOTAL => when NR_BITS_HIGH => when NR_BITS_LOW =>
when others =>
write(Lw, string'("=> incompatible base width!!!")); writeline(output, Lw);
assert false report "incompatible base width!!!" severity failure;
end case;
when 1 => -- exponent width
read(L, exponent_width, good_value);
assert good_value report "Can not read exponent width" severity failure;
write(Lw, string'("exponent width: "));
write(Lw, exponent_width);
writeline(output, Lw);
when 2 => -- g0
hread(L, g0(base_width-1 downto 0), good_value);
assert good_value report "Can not read g0! (wrong lenght?)" severity failure;
write(Lw, string'("g0: "));
hwrite(Lw, g0(base_width-1 downto 0));
writeline(output, Lw);
when 3 => -- g1
hread(L, g1(base_width-1 downto 0), good_value);
assert good_value report "Can not read g1! (wrong lenght?)" severity failure;
write(Lw, string'("g1: "));
hwrite(Lw, g1(base_width-1 downto 0));
writeline(output, Lw);
when 4 => -- e0
hread(L, e0(exponent_width-1 downto 0), good_value);
assert good_value report "Can not read e0! (wrong lenght?)" severity failure;
write(Lw, string'("e0: "));
hwrite(Lw, e0(exponent_width-1 downto 0));
writeline(output, Lw);
when 5 => -- e1
hread(L, e1(exponent_width-1 downto 0), good_value);
assert good_value report "Can not read e1! (wrong lenght?)" severity failure;
write(Lw, string'("e1: "));
hwrite(Lw, e1(exponent_width-1 downto 0));
writeline(output, Lw);
when 6 => -- m
hread(L, m(base_width-1 downto 0), good_value);
assert good_value report "Can not read m! (wrong lenght?)" severity failure;
write(Lw, string'("m: "));
hwrite(Lw, m(base_width-1 downto 0));
writeline(output, Lw);
when 7 => -- R^2
hread(L, R2(base_width-1 downto 0), good_value);
assert good_value report "Can not read R2! (wrong lenght?)" severity failure;
write(Lw, string'("R2: "));
hwrite(Lw, R2(base_width-1 downto 0));
writeline(output, Lw);
when 8 => -- R
hread(L, R(base_width-1 downto 0), good_value);
assert good_value report "Can not read R! (wrong lenght?)" severity failure;
when 9 => -- gt0
hread(L, gt0(base_width-1 downto 0), good_value);
assert good_value report "Can not read gt0! (wrong lenght?)" severity failure;
when 10 => -- gt1
hread(L, gt1(base_width-1 downto 0), good_value);
assert good_value report "Can not read gt1! (wrong lenght?)" severity failure;
when 11 => -- gt01
hread(L, gt01(base_width-1 downto 0), good_value);
assert good_value report "Can not read gt01! (wrong lenght?)" severity failure;
-- select pipeline for all computations
----------------------------------------
writeline(output, Lw);
write(Lw, string'("----- Selecting pipeline: "));
writeline(output, Lw);
case (base_width) is
when C_NR_BITS_TOTAL => core_p_sel <= "11"; write(Lw, string'(" Full pipeline selected"));
when NR_BITS_HIGH => core_p_sel <= "10"; write(Lw, string'(" Upper pipeline selected"));
when NR_BITS_LOW => core_p_sel <= "01"; write(Lw, string'(" Lower pipeline selected"));
when others =>
write(Lw, string'(" Invallid bitwidth for design"));
assert false report "impossible basewidth!" severity failure;
end case;
writeline(output, Lw);
writeline(output, Lw);
write(Lw, string'("----- Writing operands:"));
writeline(output, Lw);
-- load the modulus
--------------------
loadOp(op_modulus, m); -- visual check needed
write(Lw, string'(" m written"));
writeline(output, Lw);
-- load g0
-----------
loadOp(op_0, g0);
-- verify
readOp(op_0, data_read, base_width);
if (g0(base_width-1 downto 0) = data_read(base_width-1 downto 0)) then
write(Lw, string'(" g0 written in operand_0")); writeline(output, Lw);
else
write(Lw, string'(" failed to write g0 to operand_0!")); writeline(output, Lw);
assert false report "Load g0 to op0 data verify failed!!" severity failure;
end if;
-- load g1
-----------
loadOp(op_1, g1);
-- verify
readOp(op_1, data_read, base_width);
if (g1(base_width-1 downto 0) = data_read(base_width-1 downto 0)) then
write(Lw, string'(" g1 written in operand_1")); writeline(output, Lw);
else
write(Lw, string'(" failed to write g1 to operand_1!")); writeline(output, Lw);
assert false report "Load g1 to op1 data verify failed!!" severity failure;
end if;
-- load R2
-----------
loadOp(op_2, R2);
-- verify
readOp(op_2, data_read, base_width);
if (R2(base_width-1 downto 0) = data_read(base_width-1 downto 0)) then
write(Lw, string'(" R^2 written in operand_2")); writeline(output, Lw);
else
write(Lw, string'(" failed to write R^2 to operand_2!")); writeline(output, Lw);
assert false report "Load R2 to op2 data verify failed!!" severity failure;
end if;
-- load a=1
------------
loadOp(op_3, one);
-- verify
readOp(op_3, data_read, base_width);
if (one(base_width-1 downto 0) = data_read(base_width-1 downto 0)) then
write(Lw, string'(" 1 written in operand_3")); writeline(output, Lw);
else
write(Lw, string'(" failed to write 1 to operand_3!")); writeline(output, Lw);
assert false report "Load 1 to op3 data verify failed!!" severity failure;
end if;
writeline(output, Lw);
write(Lw, string'("----- Pre-computations: "));
writeline(output, Lw);
-- compute gt0
---------------
core_x_sel_single <= "00"; -- g0
core_y_sel_single <= "10"; -- R^2
core_dest_op_single <= "00"; -- op_0 = (g0 * R) mod m
wait until rising_edge(clk);
timer := NOW;
core_start <= '1';
wait until rising_edge(clk);
core_start <= '0';
wait until core_ready = '1';
timer := NOW-timer;
waitclk(10);
readOp(op_0, data_read, base_width);
write(Lw, string'(" Computed gt0: "));
hwrite(Lw, data_read(base_width-1 downto 0));
writeline(output, Lw);
write(Lw, string'(" Read gt0: "));
hwrite(Lw, gt0(base_width-1 downto 0));
writeline(output, Lw);
write(Lw, string'(" => calc time is "));
write(Lw, string'(ToString(timer)));
writeline(output, Lw);
write(Lw, string'(" => expected time is "));
write(Lw, (C_NR_STAGES_TOTAL+(2*(base_width-1)))*CLK_PERIOD);
writeline(output, Lw);
if (gt0(base_width-1 downto 0) = data_read(base_width-1 downto 0)) then
write(Lw, string'(" => gt0 is correct!")); writeline(output, Lw);
else
write(Lw, string'(" => Error: gt0 is incorrect!!!")); writeline(output, Lw);
assert false report "gt0 is incorrect!!!" severity failure;
end if;
-- compute gt1
---------------
core_x_sel_single <= "01"; -- g1
core_y_sel_single <= "10"; -- R^2
core_dest_op_single <= "01"; -- op_1 = (g1 * R) mod m
wait until rising_edge(clk);
timer := NOW;
core_start <= '1';
wait until rising_edge(clk);
core_start <= '0';
wait until core_ready = '1';
timer := NOW-timer;
waitclk(10);
readOp(op_1, data_read, base_width);
write(Lw, string'(" Computed gt1: "));
hwrite(Lw, data_read(base_width-1 downto 0));
writeline(output, Lw);
write(Lw, string'(" Read gt1: "));
hwrite(Lw, gt1(base_width-1 downto 0));
writeline(output, Lw);
write(Lw, string'(" => calc time is "));
write(Lw, string'(ToString(timer)));
writeline(output, Lw);
write(Lw, string'(" => expected time is "));
write(Lw, (C_NR_STAGES_TOTAL+(2*(base_width-1)))*CLK_PERIOD);
writeline(output, Lw);
if (gt1(base_width-1 downto 0) = data_read(base_width-1 downto 0)) then
write(Lw, string'(" => gt1 is correct!")); writeline(output, Lw);
else
write(Lw, string'(" => Error: gt1 is incorrect!!!")); writeline(output, Lw);
assert false report "gt1 is incorrect!!!" severity failure;
end if;
-- compute a
-------------
core_x_sel_single <= "10"; -- R^2
core_y_sel_single <= "11"; -- 1
core_dest_op_single <= "11"; -- op_3 = (R) mod m
wait until rising_edge(clk);
core_start <= '1';
timer := NOW;
wait until rising_edge(clk);
core_start <= '0';
wait until core_ready = '1';
timer := NOW-timer;
waitclk(10);
readOp(op_3, data_read, base_width);
write(Lw, string'(" Computed a=(R)mod m: "));
hwrite(Lw, data_read(base_width-1 downto 0));
writeline(output, Lw);
write(Lw, string'(" Read (R)mod m: "));
hwrite(Lw, R(base_width-1 downto 0));
writeline(output, Lw);
write(Lw, string'(" => calc time is "));
write(Lw, string'(ToString(timer)));
writeline(output, Lw);
write(Lw, string'(" => expected time is "));
write(Lw, (C_NR_STAGES_TOTAL+(2*(base_width-1)))*CLK_PERIOD);
writeline(output, Lw);
if (R(base_width-1 downto 0) = data_read(base_width-1 downto 0)) then
write(Lw, string'(" => (R)mod m is correct!")); writeline(output, Lw);
else
write(Lw, string'(" => Error: (R)mod m is incorrect!!!")); writeline(output, Lw);
assert false report "(R)mod m is incorrect!!!" severity failure;
end if;
-- compute gt01
---------------
core_x_sel_single <= "00"; -- gt0
core_y_sel_single <= "01"; -- gt1
core_dest_op_single <= "10"; -- op_2 = (gt0 * gt1) mod m
wait until rising_edge(clk);
core_start <= '1';
timer := NOW;
wait until rising_edge(clk);
core_start <= '0';
wait until core_ready = '1';
timer := NOW-timer;
waitclk(10);
readOp(op_2, data_read, base_width);
write(Lw, string'(" Computed gt01: "));
hwrite(Lw, data_read(base_width-1 downto 0));
writeline(output, Lw);
write(Lw, string'(" Read gt01: "));
hwrite(Lw, gt01(base_width-1 downto 0));
writeline(output, Lw);
write(Lw, string'(" => calc time is "));
write(Lw, string'(ToString(timer)));
writeline(output, Lw);
write(Lw, string'(" => expected time is "));
write(Lw, (C_NR_STAGES_TOTAL+(2*(base_width-1)))*CLK_PERIOD);
writeline(output, Lw);
if (gt01(base_width-1 downto 0) = data_read(base_width-1 downto 0)) then
write(Lw, string'(" => gt01 is correct!")); writeline(output, Lw);
else
write(Lw, string'(" => Error: gt01 is incorrect!!!")); writeline(output, Lw);
assert false report "gt01 is incorrect!!!" severity failure;
end if;
-- load exponent fifo
----------------------
writeline(output, Lw);
write(Lw, string'("----- Loading exponent fifo: "));
writeline(output, Lw);
for i in (exponent_width/16)-1 downto 0 loop
core_fifo_din <= e1((i*16)+15 downto (i*16)) & e0((i*16)+15 downto (i*16));
wait until rising_edge(clk);
assert (core_fifo_full='0')
report "Fifo error, fifo full" severity failure;
core_fifo_push <= '1';
wait until rising_edge(clk);
assert (core_fifo_full='0' and core_fifo_nopush='0')
report "Fifo error, fifo nopush" severity failure;
core_fifo_push <= '0';
wait until rising_edge(clk);
end loop;
waitclk(10);
write(Lw, string'(" => Done"));
writeline(output, Lw);
-- start exponentiation
------------------------
writeline(output, Lw);
write(Lw, string'("----- Starting exponentiation: "));
writeline(output, Lw);
core_exp_m <= '1';
wait until rising_edge(clk);
timer := NOW;
core_start <= '1';
wait until rising_edge(clk);
core_start <= '0';
wait until core_ready='1';
timer := NOW-timer;
waitclk(10);
write(Lw, string'(" => calc time is "));
write(Lw, string'(ToString(timer)));
writeline(output, Lw);
write(Lw, string'(" => expected time is "));
write(Lw, ((C_NR_STAGES_TOTAL+(2*(base_width-1)))*CLK_PERIOD*7*exponent_width)/4);
writeline(output, Lw);
write(Lw, string'(" => Done"));
core_exp_m <= '0';
writeline(output, Lw);
-- post-computations
---------------------
writeline(output, Lw);
write(Lw, string'("----- Post-computations: "));
writeline(output, Lw);
-- load in 1 to operand 2
loadOp(op_2, one);
-- verify
readOp(op_2, data_read, base_width);
if (one(base_width-1 downto 0) = data_read(base_width-1 downto 0)) then
write(Lw, string'(" 1 written in operand_2")); writeline(output, Lw);
else
write(Lw, string'(" failed to write 1 to operand_2!")); writeline(output, Lw);
assert false report "Load 1 to op2 data verify failed!!" severity failure;
end if;
-- compute result
core_x_sel_single <= "11"; -- a
core_y_sel_single <= "10"; -- 1
core_dest_op_single <= "11"; -- op_3 = (a) mod m
wait until rising_edge(clk);
timer := NOW;
core_start <= '1';
wait until rising_edge(clk);
core_start <= '0';
wait until core_ready = '1';
timer := NOW-timer;
waitclk(10);
readOp(op_3, data_read, base_width);
write(Lw, string'(" Computed result: "));
hwrite(Lw, data_read(base_width-1 downto 0));
writeline(output, Lw);
write(Lw, string'(" => calc time is "));
write(Lw, string'(ToString(timer)));
writeline(output, Lw);
write(Lw, string'(" => expected time is "));
write(Lw, (C_NR_STAGES_TOTAL+(2*(base_width-1)))*CLK_PERIOD);
writeline(output, Lw);
when 12 => -- check with result
hread(L, result(base_width-1 downto 0), good_value);
assert good_value report "Can not read result! (wrong lenght?)" severity failure;
writeline(output, Lw);
write(Lw, string'("----- verifying result: "));
writeline(output, Lw);
write(Lw, string'(" Read result: "));
hwrite(Lw, result(base_width-1 downto 0));
writeline(output, Lw);
write(Lw, string'(" Computed result: "));
hwrite(Lw, data_read(base_width-1 downto 0));
writeline(output, Lw);
if (result(base_width-1 downto 0) = data_read(base_width-1 downto 0)) then
write(Lw, string'(" => Result is correct!")); writeline(output, Lw);
else
write(Lw, string'(" Error: result is incorrect!!!")); writeline(output, Lw);
assert false report "result is incorrect!!!" severity failure;
end if;
writeline(output, Lw);
 
when others =>
assert false report "undefined state!" severity failure;
end case;
if (param_count = 12) then
param_count := 0;
else
param_count := param_count+1;
end if;
end loop;
wait for 1 us;
assert false report "End of simulation" severity failure;
 
end process;
 
------------------------------------------
-- Multiplier core instance
------------------------------------------
the_multiplier : mod_sim_exp.mod_sim_exp_pkg.mod_sim_exp_core
generic map(
C_NR_BITS_TOTAL => C_NR_BITS_TOTAL,
C_NR_STAGES_TOTAL => C_NR_STAGES_TOTAL,
C_NR_STAGES_LOW => C_NR_STAGES_LOW,
C_SPLIT_PIPELINE => C_SPLIT_PIPELINE,
C_FIFO_AW => C_FIFO_AW,
C_MEM_STYLE => C_MEM_STYLE, -- xil_prim, generic, asym are valid options
C_FPGA_MAN => C_FPGA_MAN -- xilinx, altera are valid options
)
port map(
bus_clk => clk,
core_clk => core_clk,
reset => reset,
-- operand memory interface (plb shared memory)
write_enable => core_write_enable,
data_in => core_data_in,
rw_address => core_rw_address,
data_out => core_data_out,
collision => core_mem_collision,
-- op_sel fifo interface
fifo_din => core_fifo_din,
fifo_push => core_fifo_push,
fifo_full => core_fifo_full,
fifo_nopush => core_fifo_nopush,
-- ctrl signals
start => core_start,
exp_m => core_exp_m,
ready => core_ready,
x_sel_single => core_x_sel_single,
y_sel_single => core_y_sel_single,
dest_op_single => core_dest_op_single,
p_sel => core_p_sel,
calc_time => calc_time,
modulus_sel => '0'
);
 
end test;
/axi_tb.vhd
0,0 → 1,322
----------------------------------------------------------------------
---- axi_tb ----
---- ----
---- This file is part of the ----
---- Modular Simultaneous Exponentiation Core project ----
---- http://www.opencores.org/cores/mod_sim_exp/ ----
---- ----
---- Description ----
---- testbench for the AXI-Lite interface, functions are ----
---- provided to read and write data ----
---- writes bus transfers to out/axi_output ----
---- ----
---- Dependencies: ----
---- - mod_sim_exp_core ----
---- ----
---- Authors: ----
---- - Geoffrey Ottoy, DraMCo research group ----
---- - Jonas De Craene, JonasDC@opencores.org ----
---- ----
----------------------------------------------------------------------
---- ----
---- Copyright (C) 2011 DraMCo research group and OPENCORES.ORG ----
---- ----
---- This source file may be used and distributed without ----
---- restriction provided that this copyright statement is not ----
---- removed from the file and that any derivative work contains ----
---- the original copyright notice and the associated disclaimer. ----
---- ----
---- This source file is free software; you can redistribute it ----
---- and/or modify it under the terms of the GNU Lesser General ----
---- Public License as published by the Free Software Foundation; ----
---- either version 2.1 of the License, or (at your option) any ----
---- later version. ----
---- ----
---- This source is distributed in the hope that it will be ----
---- useful, but WITHOUT ANY WARRANTY; without even the implied ----
---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ----
---- PURPOSE. See the GNU Lesser General Public License for more ----
---- details. ----
---- ----
---- You should have received a copy of the GNU Lesser General ----
---- Public License along with this source; if not, download it ----
---- from http://www.opencores.org/lgpl.shtml ----
---- ----
----------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
 
library std;
use std.textio.all;
 
library ieee;
use ieee.std_logic_textio.all;
 
entity axi_tb is
end axi_tb;
 
architecture arch of axi_tb is
-- constants
constant CLK_PERIOD : time := 10 ns;
constant CORE_CLK_PERIOD : time := 4 ns;
constant C_S_AXI_DATA_WIDTH : integer := 32;
constant C_S_AXI_ADDR_WIDTH : integer := 32;
file output : text open write_mode is "out/axi_output.txt";
------------------------------------------------------------------
-- Core parameters
------------------------------------------------------------------
constant C_NR_BITS_TOTAL : integer := 1536;
constant C_NR_STAGES_TOTAL : integer := 96;
constant C_NR_STAGES_LOW : integer := 32;
constant C_SPLIT_PIPELINE : boolean := true;
constant C_FIFO_AW : integer := 7; -- set to log2( (maximum exponent width)/16 )
constant C_MEM_STYLE : string := "generic"; -- xil_prim, generic, asym are valid options
constant C_FPGA_MAN : string := "xilinx"; -- xilinx, altera are valid options
constant C_BASEADDR : std_logic_vector(0 to 31) := x"A0000000";
constant C_HIGHADDR : std_logic_vector(0 to 31) := x"A0007FFF";
signal core_clk : std_logic := '0';
-------------------------
-- AXI4lite interface
-------------------------
--- Global signals
signal S_AXI_ACLK : std_logic;
signal S_AXI_ARESETN : std_logic;
--- Write address channel
signal S_AXI_AWADDR : std_logic_vector(C_S_AXI_ADDR_WIDTH-1 downto 0);
signal S_AXI_AWVALID : std_logic;
signal S_AXI_AWREADY : std_logic;
--- Write data channel
signal S_AXI_WDATA : std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
signal S_AXI_WVALID : std_logic;
signal S_AXI_WREADY : std_logic;
signal S_AXI_WSTRB : std_logic_vector((C_S_AXI_DATA_WIDTH/8)-1 downto 0);
--- Write response channel
signal S_AXI_BVALID : std_logic;
signal S_AXI_BREADY : std_logic;
signal S_AXI_BRESP : std_logic_vector(1 downto 0);
--- Read address channel
signal S_AXI_ARADDR : std_logic_vector(C_S_AXI_ADDR_WIDTH-1 downto 0);
signal S_AXI_ARVALID : std_logic;
signal S_AXI_ARREADY : std_logic;
--- Read data channel
signal S_AXI_RDATA : std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
signal S_AXI_RVALID : std_logic;
signal S_AXI_RREADY : std_logic;
signal S_AXI_RRESP : std_logic_vector(1 downto 0);
 
begin
 
------------------------------------------
-- Generate clk
------------------------------------------
clk_process : process
begin
while (true) loop
S_AXI_ACLK <= '0';
wait for CLK_PERIOD/2;
S_AXI_ACLK <= '1';
wait for CLK_PERIOD/2;
end loop;
end process;
core_clk_process : process
begin
while (true) loop
core_clk <= '0';
wait for CORE_CLK_PERIOD/2;
core_clk <= '1';
wait for CORE_CLK_PERIOD/2;
end loop;
end process;
 
stim_proc : process
variable Lw : line;
procedure waitclk(n : natural := 1) is
begin
for i in 1 to n loop
wait until rising_edge(S_AXI_ACLK);
end loop;
end waitclk;
procedure axi_write( address : std_logic_vector(31 downto 0);
data : std_logic_vector(31 downto 0) ) is
variable counter : integer := 0;
begin
-- place address on the bus
wait until rising_edge(S_AXI_ACLK);
S_AXI_AWADDR <= address;
S_AXI_AWVALID <= '1';
S_AXI_WDATA <= data;
S_AXI_WVALID <= '1';
S_AXI_WSTRB <= "1111";
while (counter /= 2) loop -- wait for slave response
wait until rising_edge(S_AXI_ACLK);
if (S_AXI_AWREADY='1') then
S_AXI_AWVALID <= '0';
counter := counter+1;
end if;
if (S_AXI_WREADY='1') then
S_AXI_WVALID <= '0';
counter := counter+1;
end if;
end loop;
S_AXI_BREADY <= '1';
if S_AXI_BVALID/='1' then
wait until S_AXI_BVALID='1';
end if;
write(Lw, string'("Wrote "));
hwrite(Lw, data);
write(Lw, string'(" to "));
hwrite(Lw, address);
if (S_AXI_BRESP /= "00") then
write(Lw, string'(" --> Error! Status: "));
write(Lw, S_AXI_BRESP);
end if;
writeline(output, Lw);
wait until rising_edge(S_AXI_ACLK);
S_AXI_BREADY <= '0';
end axi_write;
procedure axi_read( address : std_logic_vector(31 downto 0) ) is
begin
-- place address on the bus
wait until rising_edge(S_AXI_ACLK);
S_AXI_ARADDR <= address;
S_AXI_ARVALID <= '1';
wait until S_AXI_ARREADY='1';
wait until rising_edge(S_AXI_ACLK);
S_AXI_ARVALID <= '0';
-- wait for read data
S_AXI_RREADY <= '1';
wait until S_AXI_RVALID='1';
wait until rising_edge(S_AXI_ACLK);
write(Lw, string'("Read "));
hwrite(Lw, S_AXI_RDATA);
write(Lw, string'(" from "));
hwrite(Lw, address);
if (S_AXI_RRESP /= "00") then
write(Lw, string'(" --> Error! Status: "));
write(Lw, S_AXI_RRESP);
end if;
writeline(output, Lw);
S_AXI_RREADY <= '0';
--assert false report "Wrote " & " to " & " Status=" & to_string(S_AXI_BRESP) severity note;
end axi_read;
begin
write(Lw, string'("----------------------------------------------"));
writeline(output, Lw);
write(Lw, string'("-- AXI BUS SIMULATION --"));
writeline(output, Lw);
write(Lw, string'("----------------------------------------------"));
writeline(output, Lw);
S_AXI_AWADDR <= (others=>'0');
S_AXI_AWVALID <= '0';
S_AXI_WDATA <= (others=>'0');
S_AXI_WVALID <= '0';
S_AXI_WSTRB <= (others=>'0');
S_AXI_BREADY <= '0';
S_AXI_ARADDR <= (others=>'0');
S_AXI_ARVALID <= '0';
S_AXI_RREADY <= '0';
S_AXI_ARESETN <= '0';
waitclk(10);
S_AXI_ARESETN <= '1';
waitclk(20);
axi_write(x"A0000000", x"11111111");
axi_read(x"A0000000");
axi_write(x"A0001000", x"01234567");
axi_read(x"A0001000");
axi_write(x"A0002000", x"AAAAAAAA");
axi_read(x"A0002000");
axi_write(x"A0003000", x"BBBBBBBB");
axi_read(x"A0003000");
axi_write(x"A0004000", x"CCCCCCCC");
axi_read(x"A0004000");
axi_write(x"A0005000", x"DDDDDDDD");
axi_read(x"A0005000");
axi_write(x"A0006000", x"EEEEEEEE");
axi_read(x"A0006000");
axi_write(x"A0007000", x"FFFFFFFF");
axi_read(x"A0007000");
axi_write(x"A0008000", x"22222222");
axi_read(x"A0008000");
axi_write(x"A0009000", x"33333333");
axi_read(x"A0009000");
axi_write(x"A000A000", x"44444444");
axi_read(x"A000A000");
waitclk(100);
assert false report "End of simulation" severity failure;
end process;
 
 
-------------------------
-- Unit Under Test
-------------------------
uut : entity work.msec_ipcore_axilite
generic map(
C_NR_BITS_TOTAL => C_NR_BITS_TOTAL,
C_NR_STAGES_TOTAL => C_NR_STAGES_TOTAL,
C_NR_STAGES_LOW => C_NR_STAGES_LOW,
C_SPLIT_PIPELINE => C_SPLIT_PIPELINE,
C_FIFO_AW => C_FIFO_AW,
C_MEM_STYLE => C_MEM_STYLE, -- xil_prim, generic, asym are valid options
C_FPGA_MAN => C_FPGA_MAN, -- xilinx, altera are valid options
C_BASEADDR => C_BASEADDR,
C_HIGHADDR => C_HIGHADDR
)
port map(
--USER ports
core_clk => core_clk,
-------------------------
-- AXI4lite interface
-------------------------
--- Global signals
S_AXI_ACLK => S_AXI_ACLK,
S_AXI_ARESETN => S_AXI_ARESETN,
--- Write address channel
S_AXI_AWADDR => S_AXI_AWADDR,
S_AXI_AWVALID => S_AXI_AWVALID,
S_AXI_AWREADY => S_AXI_AWREADY,
--- Write data channel
S_AXI_WDATA => S_AXI_WDATA,
S_AXI_WVALID => S_AXI_WVALID,
S_AXI_WREADY => S_AXI_WREADY,
S_AXI_WSTRB => S_AXI_WSTRB,
--- Write response channel
S_AXI_BVALID => S_AXI_BVALID,
S_AXI_BREADY => S_AXI_BREADY,
S_AXI_BRESP => S_AXI_BRESP,
--- Read address channel
S_AXI_ARADDR => S_AXI_ARADDR,
S_AXI_ARVALID => S_AXI_ARVALID,
S_AXI_ARREADY => S_AXI_ARREADY,
--- Read data channel
S_AXI_RDATA => S_AXI_RDATA,
S_AXI_RVALID => S_AXI_RVALID,
S_AXI_RREADY => S_AXI_RREADY,
S_AXI_RRESP => S_AXI_RRESP
);
 
end arch;
 
/msec_axi_tb.vhd
0,0 → 1,866
----------------------------------------------------------------------
---- msec_axi_tb ----
---- ----
---- This file is part of the ----
---- Modular Simultaneous Exponentiation Core project ----
---- http://www.opencores.org/cores/mod_sim_exp/ ----
---- ----
---- Description ----
---- testbench for the AXI-Lite interface of the modular ----
---- simultaneous exponentiation core. Performs some ----
---- exponentiations to verify the design ----
---- Takes input parameters from in/sim_input.txt en writes ----
---- result and output to out/axi_sim_output.txt. The AXI bus ----
---- transfers ar written to out/axi_bus_output ----
---- ----
---- Dependencies: ----
---- - msec_ipcore_axilite ----
---- ----
---- Authors: ----
---- - Geoffrey Ottoy, DraMCo research group ----
---- - Jonas De Craene, JonasDC@opencores.org ----
---- ----
----------------------------------------------------------------------
---- ----
---- Copyright (C) 2011 DraMCo research group and OPENCORES.ORG ----
---- ----
---- This source file may be used and distributed without ----
---- restriction provided that this copyright statement is not ----
---- removed from the file and that any derivative work contains ----
---- the original copyright notice and the associated disclaimer. ----
---- ----
---- This source file is free software; you can redistribute it ----
---- and/or modify it under the terms of the GNU Lesser General ----
---- Public License as published by the Free Software Foundation; ----
---- either version 2.1 of the License, or (at your option) any ----
---- later version. ----
---- ----
---- This source is distributed in the hope that it will be ----
---- useful, but WITHOUT ANY WARRANTY; without even the implied ----
---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ----
---- PURPOSE. See the GNU Lesser General Public License for more ----
---- details. ----
---- ----
---- You should have received a copy of the GNU Lesser General ----
---- Public License along with this source; if not, download it ----
---- from http://www.opencores.org/lgpl.shtml ----
---- ----
----------------------------------------------------------------------
 
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
 
library std;
use std.textio.all;
 
library ieee;
use ieee.std_logic_textio.all;
 
entity msec_axi_tb is
end msec_axi_tb;
 
architecture arch of msec_axi_tb is
-- constants
constant CLK_PERIOD : time := 10 ns;
constant CORE_CLK_PERIOD : time := 4 ns;
constant C_S_AXI_DATA_WIDTH : integer := 32;
constant C_S_AXI_ADDR_WIDTH : integer := 32;
file output : text open write_mode is "out/axi_sim_output.txt";
file axi_dbg : text open write_mode is "out/axi_bus_output.txt";
file input : text open read_mode is "src/sim_input.txt";
 
------------------------------------------------------------------
-- Core parameters
------------------------------------------------------------------
constant C_NR_BITS_TOTAL : integer := 1536;
constant C_NR_STAGES_TOTAL : integer := 96;
constant C_NR_STAGES_LOW : integer := 32;
constant C_SPLIT_PIPELINE : boolean := true;
constant C_FIFO_AW : integer := 7; -- set to log2( (maximum exponent width)/16 )
constant C_MEM_STYLE : string := "xil_prim"; -- xil_prim, generic, asym are valid options
constant C_FPGA_MAN : string := "xilinx"; -- xilinx, altera are valid options
constant C_BASEADDR : std_logic_vector(0 to 31) := x"A0000000";
constant C_HIGHADDR : std_logic_vector(0 to 31) := x"A0007FFF";
-- extra calculated constants
constant NR_BITS_LOW : integer := (C_NR_BITS_TOTAL/C_NR_STAGES_TOTAL)*C_NR_STAGES_LOW;
constant NR_BITS_HIGH : integer := C_NR_BITS_TOTAL-NR_BITS_LOW;
 
signal core_clk : std_logic := '0';
-------------------------
-- AXI4lite interface
-------------------------
--- Global signals
signal S_AXI_ACLK : std_logic;
signal S_AXI_ARESETN : std_logic;
--- Write address channel
signal S_AXI_AWADDR : std_logic_vector(C_S_AXI_ADDR_WIDTH-1 downto 0);
signal S_AXI_AWVALID : std_logic;
signal S_AXI_AWREADY : std_logic;
--- Write data channel
signal S_AXI_WDATA : std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
signal S_AXI_WVALID : std_logic;
signal S_AXI_WREADY : std_logic;
signal S_AXI_WSTRB : std_logic_vector((C_S_AXI_DATA_WIDTH/8)-1 downto 0);
--- Write response channel
signal S_AXI_BVALID : std_logic;
signal S_AXI_BREADY : std_logic;
signal S_AXI_BRESP : std_logic_vector(1 downto 0);
--- Read address channel
signal S_AXI_ARADDR : std_logic_vector(C_S_AXI_ADDR_WIDTH-1 downto 0);
signal S_AXI_ARVALID : std_logic;
signal S_AXI_ARREADY : std_logic;
--- Read data channel
signal S_AXI_RDATA : std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
signal S_AXI_RVALID : std_logic;
signal S_AXI_RREADY : std_logic;
signal S_AXI_RRESP : std_logic_vector(1 downto 0);
-- CORE control reg bits
signal core_control_reg : std_logic_vector(31 downto 0) := (others=>'0');
signal core_start : std_logic;
signal core_exp_m : std_logic;
signal core_p_sel : std_logic_vector(1 downto 0);
signal core_dest_op_single : std_logic_vector(1 downto 0);
signal core_x_sel_single : std_logic_vector(1 downto 0);
signal core_y_sel_single : std_logic_vector(1 downto 0);
signal core_modulus_sel : std_logic;
signal calc_time : std_logic;
signal IntrEvent : std_logic;
begin
 
-- map the core control bits to the core control register
core_control_reg(31 downto 30) <= core_p_sel;
core_control_reg(29 downto 28) <= core_dest_op_single;
core_control_reg(27 downto 26) <= core_x_sel_single;
core_control_reg(25 downto 24) <= core_y_sel_single;
core_control_reg(23) <= core_start;
core_control_reg(22) <= core_exp_m;
core_control_reg(21) <= core_modulus_sel;
 
------------------------------------------
-- Generate S_AXI_ACLK
------------------------------------------
clk_process : process
begin
while (true) loop
S_AXI_ACLK <= '0';
wait for CLK_PERIOD/2;
S_AXI_ACLK <= '1';
wait for CLK_PERIOD/2;
end loop;
end process;
core_clk_process : process
begin
while (true) loop
core_clk <= '0';
wait for CORE_CLK_PERIOD/2;
core_clk <= '1';
wait for CORE_CLK_PERIOD/2;
end loop;
end process;
 
stim_proc : process
-- variables to read file
variable L : line;
variable Lw : line;
variable La : line;
-- constants for memory space selection
constant op_modulus : std_logic_vector(2 downto 0) := "000";
constant op_0 : std_logic_vector(2 downto 0) := "001";
constant op_1 : std_logic_vector(2 downto 0) := "010";
constant op_2 : std_logic_vector(2 downto 0) := "011";
constant op_3 : std_logic_vector(2 downto 0) := "100";
constant fifo : std_logic_vector(2 downto 0) := "101";
constant control_reg : std_logic_vector(2 downto 0) := "110";
procedure waitclk(n : natural := 1) is
begin
for i in 1 to n loop
wait until rising_edge(S_AXI_ACLK);
end loop;
end waitclk;
procedure axi_write( variable address : std_logic_vector(31 downto 0);
variable data : std_logic_vector(31 downto 0) ) is
variable counter : integer := 0;
begin
-- place address on the bus
wait until rising_edge(S_AXI_ACLK);
S_AXI_AWADDR <= address;
S_AXI_AWVALID <= '1';
S_AXI_WDATA <= data;
S_AXI_WVALID <= '1';
S_AXI_WSTRB <= "1111";
while (counter /= 2) loop -- wait for slave response
wait until rising_edge(S_AXI_ACLK);
if (S_AXI_AWREADY='1') then
S_AXI_AWVALID <= '0';
counter := counter+1;
end if;
if (S_AXI_WREADY='1') then
S_AXI_WVALID <= '0';
counter := counter+1;
end if;
end loop;
S_AXI_BREADY <= '1';
if S_AXI_BVALID/='1' then
wait until S_AXI_BVALID='1';
end if;
write(La, string'("Wrote "));
hwrite(La, data);
write(La, string'(" to "));
hwrite(La, address);
if (S_AXI_BRESP /= "00") then
write(La, string'(" --> Error! Status: "));
write(La, S_AXI_BRESP);
end if;
writeline(axi_dbg, La);
wait until rising_edge(S_AXI_ACLK);
S_AXI_BREADY <= '0';
end axi_write;
procedure axi_read( variable address : std_logic_vector(31 downto 0);
variable data : out std_logic_vector(31 downto 0) ) is
begin
-- place address on the bus
wait until rising_edge(S_AXI_ACLK);
S_AXI_ARADDR <= address;
S_AXI_ARVALID <= '1';
wait until S_AXI_ARREADY='1';
wait until rising_edge(S_AXI_ACLK);
S_AXI_ARVALID <= '0';
-- wait for read data
S_AXI_RREADY <= '1';
wait until S_AXI_RVALID='1';
wait until rising_edge(S_AXI_ACLK);
data := S_AXI_RDATA;
write(La, string'("Read "));
hwrite(La, S_AXI_RDATA);
write(La, string'(" from "));
hwrite(La, address);
if (S_AXI_RRESP /= "00") then
write(La, string'(" --> Error! Status: "));
write(La, S_AXI_RRESP);
end if;
writeline(axi_dbg, La);
S_AXI_RREADY <= '0';
--assert false report "Wrote " & " to " & " Status=" & to_string(S_AXI_BRESP) severity note;
end axi_read;
procedure axi_write_control_reg is
variable address : std_logic_vector(31 downto 0);
variable data : std_logic_vector(31 downto 0);
begin
wait until rising_edge(S_AXI_ACLK);
address := C_BASEADDR+x"00006000";
data := core_control_reg;
axi_write(address, data);
end axi_write_control_reg;
procedure loadOp(constant op_sel : std_logic_vector(2 downto 0);
variable op_data : std_logic_vector(2047 downto 0)) is
variable address : std_logic_vector(31 downto 0);
variable zero : std_logic_vector(31 downto 0) := (others=>'0');
begin
-- set the start address
address := C_BASEADDR(0 to 15) & '0' & op_sel & "0000" & "000000" & "00";
-- write operand per 32 bits
for i in 0 to (C_NR_BITS_TOTAL/32)-1 loop
case (core_p_sel) is
when "11" =>
axi_write(address, op_data(((i+1)*32)-1 downto (i*32)));
when "01" =>
if (i < 16) then axi_write(address, op_data(((i+1)*32)-1 downto (i*32)));
else axi_write(address, zero); end if;
when "10" =>
if (i >= 16) then axi_write(address, op_data(((i-15)*32)-1 downto ((i-16)*32)));
else axi_write(address, zero); end if;
when others =>
axi_write(address, zero);
end case;
-- next address is 32 further
address := address + "100";
end loop;
end loadOp;
procedure readOp(constant op_sel : std_logic_vector(2 downto 0);
variable op_data : out std_logic_vector(2047 downto 0);
variable op_width : integer) is
variable address : std_logic_vector(31 downto 0);
variable data : std_logic_vector(31 downto 0);
begin
-- set destination operand, cause only can readfrom destination operand
case op_sel is
when "001" => core_dest_op_single <= "00";
when "010" => core_dest_op_single <= "01";
when "011" => core_dest_op_single <= "10";
when "100" => core_dest_op_single <= "11";
when others => core_dest_op_single <= "00";
end case;
axi_write_control_reg;
-- set the start address
if (core_p_sel = "10") then
address := C_BASEADDR(0 to 15) & '0' & op_sel & "0000" & "010000" & "00";
else
address := C_BASEADDR(0 to 15) & '0' & op_sel & "0000" & "000000" & "00";
end if;
-- read the data
for i in 0 to (op_width/32)-1 loop
axi_read(address, data);
op_data(((i+1)*32)-1 downto (i*32)) := data;
-- next address is 32 further
address := address + "100";
end loop;
end readOp;
procedure loadFifo(variable data : std_logic_vector(31 downto 0)) is
variable address : std_logic_vector(31 downto 0);
begin
-- set the start address
address := C_BASEADDR(0 to 15) & '0' & fifo & "0000" & "000000" & "00";
axi_write(address, data);
end loadFifo;
function ToString(constant Timeval : time) return string is
variable StrPtr : line;
begin
write(StrPtr,Timeval);
return StrPtr.all;
end ToString;
variable base_width : integer;
variable exponent_width : integer;
variable g0 : std_logic_vector(2047 downto 0) := (others=>'0');
variable g1 : std_logic_vector(2047 downto 0) := (others=>'0');
variable e0 : std_logic_vector(2047 downto 0) := (others=>'0');
variable e1 : std_logic_vector(2047 downto 0) := (others=>'0');
variable m : std_logic_vector(2047 downto 0) := (others=>'0');
variable R2 : std_logic_vector(2047 downto 0) := (others=>'0');
variable R : std_logic_vector(2047 downto 0) := (others=>'0');
variable gt0 : std_logic_vector(2047 downto 0) := (others=>'0');
variable gt1 : std_logic_vector(2047 downto 0) := (others=>'0');
variable gt01 : std_logic_vector(2047 downto 0) := (others=>'0');
variable one : std_logic_vector(2047 downto 0) := std_logic_vector(conv_unsigned(1, 2048));
variable result : std_logic_vector(2047 downto 0) := (others=>'0');
variable data_read : std_logic_vector(2047 downto 0) := (others=>'0');
variable good_value : boolean;
variable param_count : integer := 0;
variable temp_data : std_logic_vector(31 downto 0);
variable timer : time;
begin
write(Lw, string'("----------------------------------------------"));
writeline(output, Lw);
write(Lw, string'("-- AXI BUS SIMULATION --"));
writeline(output, Lw);
write(Lw, string'("----------------------------------------------"));
writeline(output, Lw);
-- axi bus initialisation
S_AXI_AWADDR <= (others=>'0');
S_AXI_AWVALID <= '0';
S_AXI_WDATA <= (others=>'0');
S_AXI_WVALID <= '0';
S_AXI_WSTRB <= (others=>'0');
S_AXI_BREADY <= '0';
S_AXI_ARADDR <= (others=>'0');
S_AXI_ARVALID <= '0';
S_AXI_RREADY <= '0';
-- control signals initialisation
core_start <= '0';
core_exp_m <= '0';
core_x_sel_single <= "00";
core_y_sel_single <= "01";
core_dest_op_single <= "01";
core_p_sel <= "11";
core_modulus_sel <= '0';
-- reset
S_AXI_ARESETN <= '0';
waitclk(10);
S_AXI_ARESETN <= '1';
waitclk(20);
while not endfile(input) loop
readline(input, L); -- read next line
next when L(1)='-'; -- skip comment lines
-- read input values
case param_count is
when 0 => -- base width
read(L, base_width, good_value);
assert good_value report "Can not read base width" severity failure;
assert false report "Simulating exponentiation" severity note;
write(Lw, string'("----------------------------------------------"));
writeline(output, Lw);
write(Lw, string'("-- EXPONENTIATION --"));
writeline(output, Lw);
write(Lw, string'("----------------------------------------------"));
writeline(output, Lw);
write(Lw, string'("----- Variables used:"));
writeline(output, Lw);
write(Lw, string'("base width: "));
write(Lw, base_width);
writeline(output, Lw);
case (base_width) is
when C_NR_BITS_TOTAL => when NR_BITS_HIGH => when NR_BITS_LOW =>
when others =>
write(Lw, string'("=> incompatible base width!!!")); writeline(output, Lw);
assert false report "incompatible base width!!!" severity failure;
end case;
when 1 => -- exponent width
read(L, exponent_width, good_value);
assert good_value report "Can not read exponent width" severity failure;
write(Lw, string'("exponent width: "));
write(Lw, exponent_width);
writeline(output, Lw);
when 2 => -- g0
hread(L, g0(base_width-1 downto 0), good_value);
assert good_value report "Can not read g0! (wrong lenght?)" severity failure;
write(Lw, string'("g0: "));
hwrite(Lw, g0(base_width-1 downto 0));
writeline(output, Lw);
when 3 => -- g1
hread(L, g1(base_width-1 downto 0), good_value);
assert good_value report "Can not read g1! (wrong lenght?)" severity failure;
write(Lw, string'("g1: "));
hwrite(Lw, g1(base_width-1 downto 0));
writeline(output, Lw);
when 4 => -- e0
hread(L, e0(exponent_width-1 downto 0), good_value);
assert good_value report "Can not read e0! (wrong lenght?)" severity failure;
write(Lw, string'("e0: "));
hwrite(Lw, e0(exponent_width-1 downto 0));
writeline(output, Lw);
when 5 => -- e1
hread(L, e1(exponent_width-1 downto 0), good_value);
assert good_value report "Can not read e1! (wrong lenght?)" severity failure;
write(Lw, string'("e1: "));
hwrite(Lw, e1(exponent_width-1 downto 0));
writeline(output, Lw);
when 6 => -- m
hread(L, m(base_width-1 downto 0), good_value);
assert good_value report "Can not read m! (wrong lenght?)" severity failure;
write(Lw, string'("m: "));
hwrite(Lw, m(base_width-1 downto 0));
writeline(output, Lw);
when 7 => -- R^2
hread(L, R2(base_width-1 downto 0), good_value);
assert good_value report "Can not read R2! (wrong lenght?)" severity failure;
write(Lw, string'("R2: "));
hwrite(Lw, R2(base_width-1 downto 0));
writeline(output, Lw);
when 8 => -- R
hread(L, R(base_width-1 downto 0), good_value);
assert good_value report "Can not read R! (wrong lenght?)" severity failure;
when 9 => -- gt0
hread(L, gt0(base_width-1 downto 0), good_value);
assert good_value report "Can not read gt0! (wrong lenght?)" severity failure;
when 10 => -- gt1
hread(L, gt1(base_width-1 downto 0), good_value);
assert good_value report "Can not read gt1! (wrong lenght?)" severity failure;
when 11 => -- gt01
hread(L, gt01(base_width-1 downto 0), good_value);
assert good_value report "Can not read gt01! (wrong lenght?)" severity failure;
-- select pipeline for all computations
----------------------------------------
writeline(output, Lw);
write(Lw, string'("----- Selecting pipeline: "));
writeline(output, Lw);
case (base_width) is
when C_NR_BITS_TOTAL => core_p_sel <= "11"; write(Lw, string'(" Full pipeline selected"));
when NR_BITS_HIGH => core_p_sel <= "10"; write(Lw, string'(" Upper pipeline selected"));
when NR_BITS_LOW => core_p_sel <= "01"; write(Lw, string'(" Lower pipeline selected"));
when others =>
write(Lw, string'(" Invallid bitwidth for design"));
assert false report "impossible basewidth!" severity failure;
end case;
axi_write_control_reg;
writeline(output, Lw);
writeline(output, Lw);
write(Lw, string'("----- Writing operands:"));
writeline(output, Lw);
-- load the modulus
--------------------
loadOp(op_modulus, m); -- visual check needed
write(Lw, string'(" m written"));
writeline(output, Lw);
-- load g0
-----------
loadOp(op_0, g0);
-- verify
readOp(op_0, data_read, base_width);
if (g0(base_width-1 downto 0) = data_read(base_width-1 downto 0)) then
write(Lw, string'(" g0 written in operand_0")); writeline(output, Lw);
else
write(Lw, string'(" failed to write g0 to operand_0!")); writeline(output, Lw);
assert false report "Load g0 to op0 data verify failed!!" severity failure;
end if;
-- load g1
-----------
loadOp(op_1, g1);
-- verify
readOp(op_1, data_read, base_width);
if (g1(base_width-1 downto 0) = data_read(base_width-1 downto 0)) then
write(Lw, string'(" g1 written in operand_1")); writeline(output, Lw);
else
write(Lw, string'(" failed to write g1 to operand_1!")); writeline(output, Lw);
assert false report "Load g1 to op1 data verify failed!!" severity failure;
end if;
-- load R2
-----------
loadOp(op_2, R2);
-- verify
readOp(op_2, data_read, base_width);
if (R2(base_width-1 downto 0) = data_read(base_width-1 downto 0)) then
write(Lw, string'(" R^2 written in operand_2")); writeline(output, Lw);
else
write(Lw, string'(" failed to write R^2 to operand_2!")); writeline(output, Lw);
assert false report "Load R2 to op2 data verify failed!!" severity failure;
end if;
-- load a=1
------------
loadOp(op_3, one);
-- verify
readOp(op_3, data_read, base_width);
if (one(base_width-1 downto 0) = data_read(base_width-1 downto 0)) then
write(Lw, string'(" 1 written in operand_3")); writeline(output, Lw);
else
write(Lw, string'(" failed to write 1 to operand_3!")); writeline(output, Lw);
assert false report "Load 1 to op3 data verify failed!!" severity failure;
end if;
writeline(output, Lw);
write(Lw, string'("----- Pre-computations: "));
writeline(output, Lw);
-- compute gt0
---------------
core_x_sel_single <= "00"; -- g0
core_y_sel_single <= "10"; -- R^2
core_dest_op_single <= "00"; -- op_0 = (g0 * R) mod m
axi_write_control_reg;
timer := NOW;
core_start <= '1';
axi_write_control_reg;
core_start <= '0';
axi_write_control_reg;
wait until IntrEvent = '1';
timer := NOW-timer;
waitclk(10);
readOp(op_0, data_read, base_width);
write(Lw, string'(" Computed gt0: "));
hwrite(Lw, data_read(base_width-1 downto 0));
writeline(output, Lw);
write(Lw, string'(" Read gt0: "));
hwrite(Lw, gt0(base_width-1 downto 0));
writeline(output, Lw);
write(Lw, string'(" => calc time is "));
write(Lw, string'(ToString(timer)));
writeline(output, Lw);
write(Lw, string'(" => expected time is "));
write(Lw, (C_NR_STAGES_TOTAL+(2*(base_width-1)))*CLK_PERIOD);
writeline(output, Lw);
if (gt0(base_width-1 downto 0) = data_read(base_width-1 downto 0)) then
write(Lw, string'(" => gt0 is correct!")); writeline(output, Lw);
else
write(Lw, string'(" => Error: gt0 is incorrect!!!")); writeline(output, Lw);
assert false report "gt0 is incorrect!!!" severity failure;
end if;
-- compute gt1
---------------
core_x_sel_single <= "01"; -- g1
core_y_sel_single <= "10"; -- R^2
core_dest_op_single <= "01"; -- op_1 = (g1 * R) mod m
timer := NOW;
core_start <= '1';
axi_write_control_reg;
core_start <= '0';
axi_write_control_reg;
wait until IntrEvent = '1';
timer := NOW-timer;
waitclk(10);
readOp(op_1, data_read, base_width);
write(Lw, string'(" Computed gt1: "));
hwrite(Lw, data_read(base_width-1 downto 0));
writeline(output, Lw);
write(Lw, string'(" Read gt1: "));
hwrite(Lw, gt1(base_width-1 downto 0));
writeline(output, Lw);
write(Lw, string'(" => calc time is "));
write(Lw, string'(ToString(timer)));
writeline(output, Lw);
write(Lw, string'(" => expected time is "));
write(Lw, (C_NR_STAGES_TOTAL+(2*(base_width-1)))*CLK_PERIOD);
writeline(output, Lw);
if (gt1(base_width-1 downto 0) = data_read(base_width-1 downto 0)) then
write(Lw, string'(" => gt1 is correct!")); writeline(output, Lw);
else
write(Lw, string'(" => Error: gt1 is incorrect!!!")); writeline(output, Lw);
assert false report "gt1 is incorrect!!!" severity failure;
end if;
-- compute a
-------------
core_x_sel_single <= "10"; -- R^2
core_y_sel_single <= "11"; -- 1
core_dest_op_single <= "11"; -- op_3 = (R) mod m
core_start <= '1';
axi_write_control_reg;
timer := NOW;
core_start <= '0';
axi_write_control_reg;
wait until IntrEvent = '1';
timer := NOW-timer;
waitclk(10);
readOp(op_3, data_read, base_width);
write(Lw, string'(" Computed a=(R)mod m: "));
hwrite(Lw, data_read(base_width-1 downto 0));
writeline(output, Lw);
write(Lw, string'(" Read (R)mod m: "));
hwrite(Lw, R(base_width-1 downto 0));
writeline(output, Lw);
write(Lw, string'(" => calc time is "));
write(Lw, string'(ToString(timer)));
writeline(output, Lw);
write(Lw, string'(" => expected time is "));
write(Lw, (C_NR_STAGES_TOTAL+(2*(base_width-1)))*CLK_PERIOD);
writeline(output, Lw);
if (R(base_width-1 downto 0) = data_read(base_width-1 downto 0)) then
write(Lw, string'(" => (R)mod m is correct!")); writeline(output, Lw);
else
write(Lw, string'(" => Error: (R)mod m is incorrect!!!")); writeline(output, Lw);
assert false report "(R)mod m is incorrect!!!" severity failure;
end if;
-- compute gt01
---------------
core_x_sel_single <= "00"; -- gt0
core_y_sel_single <= "01"; -- gt1
core_dest_op_single <= "10"; -- op_2 = (gt0 * gt1) mod m
core_start <= '1';
axi_write_control_reg;
timer := NOW;
core_start <= '0';
axi_write_control_reg;
wait until IntrEvent = '1';
timer := NOW-timer;
waitclk(10);
readOp(op_2, data_read, base_width);
write(Lw, string'(" Computed gt01: "));
hwrite(Lw, data_read(base_width-1 downto 0));
writeline(output, Lw);
write(Lw, string'(" Read gt01: "));
hwrite(Lw, gt01(base_width-1 downto 0));
writeline(output, Lw);
write(Lw, string'(" => calc time is "));
write(Lw, string'(ToString(timer)));
writeline(output, Lw);
write(Lw, string'(" => expected time is "));
write(Lw, (C_NR_STAGES_TOTAL+(2*(base_width-1)))*CLK_PERIOD);
writeline(output, Lw);
if (gt01(base_width-1 downto 0) = data_read(base_width-1 downto 0)) then
write(Lw, string'(" => gt01 is correct!")); writeline(output, Lw);
else
write(Lw, string'(" => Error: gt01 is incorrect!!!")); writeline(output, Lw);
assert false report "gt01 is incorrect!!!" severity failure;
end if;
-- load exponent fifo
----------------------
writeline(output, Lw);
write(Lw, string'("----- Loading exponent fifo: "));
writeline(output, Lw);
for i in (exponent_width/16)-1 downto 0 loop
temp_data := e1((i*16)+15 downto (i*16)) & e0((i*16)+15 downto (i*16));
LoadFifo(temp_data);
end loop;
waitclk(10);
write(Lw, string'(" => Done"));
writeline(output, Lw);
-- start exponentiation
------------------------
writeline(output, Lw);
write(Lw, string'("----- Starting exponentiation: "));
writeline(output, Lw);
core_exp_m <= '1';
timer := NOW;
core_start <= '1';
axi_write_control_reg;
core_start <= '0';
axi_write_control_reg;
wait until IntrEvent='1';
timer := NOW-timer;
waitclk(10);
write(Lw, string'(" => calc time is "));
write(Lw, string'(ToString(timer)));
writeline(output, Lw);
write(Lw, string'(" => expected time is "));
write(Lw, ((C_NR_STAGES_TOTAL+(2*(base_width-1)))*CLK_PERIOD*7*exponent_width)/4);
writeline(output, Lw);
write(Lw, string'(" => Done"));
core_exp_m <= '0';
writeline(output, Lw);
-- post-computations
---------------------
writeline(output, Lw);
write(Lw, string'("----- Post-computations: "));
writeline(output, Lw);
-- load in 1 to operand 2
loadOp(op_2, one);
-- verify
readOp(op_2, data_read, base_width);
if (one(base_width-1 downto 0) = data_read(base_width-1 downto 0)) then
write(Lw, string'(" 1 written in operand_2")); writeline(output, Lw);
else
write(Lw, string'(" failed to write 1 to operand_2!")); writeline(output, Lw);
assert false report "Load 1 to op2 data verify failed!!" severity failure;
end if;
-- compute result
core_x_sel_single <= "11"; -- a
core_y_sel_single <= "10"; -- 1
core_dest_op_single <= "11"; -- op_3 = (a) mod m
timer := NOW;
core_start <= '1';
axi_write_control_reg;
core_start <= '0';
axi_write_control_reg;
wait until IntrEvent = '1';
timer := NOW-timer;
waitclk(10);
readOp(op_3, data_read, base_width);
write(Lw, string'(" Computed result: "));
hwrite(Lw, data_read(base_width-1 downto 0));
writeline(output, Lw);
write(Lw, string'(" => calc time is "));
write(Lw, string'(ToString(timer)));
writeline(output, Lw);
write(Lw, string'(" => expected time is "));
write(Lw, (C_NR_STAGES_TOTAL+(2*(base_width-1)))*CLK_PERIOD);
writeline(output, Lw);
when 12 => -- check with result
hread(L, result(base_width-1 downto 0), good_value);
assert good_value report "Can not read result! (wrong lenght?)" severity failure;
writeline(output, Lw);
write(Lw, string'("----- verifying result: "));
writeline(output, Lw);
write(Lw, string'(" Read result: "));
hwrite(Lw, result(base_width-1 downto 0));
writeline(output, Lw);
write(Lw, string'(" Computed result: "));
hwrite(Lw, data_read(base_width-1 downto 0));
writeline(output, Lw);
if (result(base_width-1 downto 0) = data_read(base_width-1 downto 0)) then
write(Lw, string'(" => Result is correct!")); writeline(output, Lw);
else
write(Lw, string'(" Error: result is incorrect!!!")); writeline(output, Lw);
assert false report "result is incorrect!!!" severity failure;
end if;
writeline(output, Lw);
when others =>
assert false report "undefined state!" severity failure;
end case;
if (param_count = 12) then
param_count := 0;
else
param_count := param_count+1;
end if;
end loop;
wait for 1 us;
assert false report "End of simulation" severity failure;
end process;
 
 
-------------------------
-- Unit Under Test
-------------------------
uut : entity work.msec_ipcore_axilite
generic map(
C_NR_BITS_TOTAL => C_NR_BITS_TOTAL,
C_NR_STAGES_TOTAL => C_NR_STAGES_TOTAL,
C_NR_STAGES_LOW => C_NR_STAGES_LOW,
C_SPLIT_PIPELINE => C_SPLIT_PIPELINE,
C_FIFO_AW => C_FIFO_AW,
C_MEM_STYLE => C_MEM_STYLE, -- xil_prim, generic, asym are valid options
C_FPGA_MAN => C_FPGA_MAN, -- xilinx, altera are valid options
C_BASEADDR => C_BASEADDR,
C_HIGHADDR => C_HIGHADDR
)
port map(
--USER ports
calc_time => calc_time,
IntrEvent => IntrEvent,
core_clk => core_clk,
-------------------------
-- AXI4lite interface
-------------------------
--- Global signals
S_AXI_ACLK => S_AXI_ACLK,
S_AXI_ARESETN => S_AXI_ARESETN,
--- Write address channel
S_AXI_AWADDR => S_AXI_AWADDR,
S_AXI_AWVALID => S_AXI_AWVALID,
S_AXI_AWREADY => S_AXI_AWREADY,
--- Write data channel
S_AXI_WDATA => S_AXI_WDATA,
S_AXI_WVALID => S_AXI_WVALID,
S_AXI_WREADY => S_AXI_WREADY,
S_AXI_WSTRB => S_AXI_WSTRB,
--- Write response channel
S_AXI_BVALID => S_AXI_BVALID,
S_AXI_BREADY => S_AXI_BREADY,
S_AXI_BRESP => S_AXI_BRESP,
--- Read address channel
S_AXI_ARADDR => S_AXI_ARADDR,
S_AXI_ARVALID => S_AXI_ARVALID,
S_AXI_ARREADY => S_AXI_ARREADY,
--- Read data channel
S_AXI_RDATA => S_AXI_RDATA,
S_AXI_RVALID => S_AXI_RVALID,
S_AXI_RREADY => S_AXI_RREADY,
S_AXI_RRESP => S_AXI_RRESP
);
 
end arch;
 
/multiplier_tb.vhd
0,0 → 1,284
----------------------------------------------------------------------
---- multiplier_tb ----
---- ----
---- This file is part of the ----
---- Modular Simultaneous Exponentiation Core project ----
---- http://www.opencores.org/cores/mod_sim_exp/ ----
---- ----
---- Description ----
---- testbench for the Montgomery multiplier ----
---- Performs some multiplications to verify the design ----
---- Takes input parameters from sim_mult_input.txt and writes ----
---- result and output to sim_mult_output.txt ----
---- ----
---- Dependencies: ----
---- - mont_multiplier ----
---- ----
---- Authors: ----
---- - Geoffrey Ottoy, DraMCo research group ----
---- - Jonas De Craene, JonasDC@opencores.org ----
---- ----
----------------------------------------------------------------------
---- ----
---- Copyright (C) 2011 DraMCo research group and OPENCORES.ORG ----
---- ----
---- This source file may be used and distributed without ----
---- restriction provided that this copyright statement is not ----
---- removed from the file and that any derivative work contains ----
---- the original copyright notice and the associated disclaimer. ----
---- ----
---- This source file is free software; you can redistribute it ----
---- and/or modify it under the terms of the GNU Lesser General ----
---- Public License as published by the Free Software Foundation; ----
---- either version 2.1 of the License, or (at your option) any ----
---- later version. ----
---- ----
---- This source is distributed in the hope that it will be ----
---- useful, but WITHOUT ANY WARRANTY; without even the implied ----
---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ----
---- PURPOSE. See the GNU Lesser General Public License for more ----
---- details. ----
---- ----
---- You should have received a copy of the GNU Lesser General ----
---- Public License along with this source; if not, download it ----
---- from http://www.opencores.org/lgpl.shtml ----
---- ----
----------------------------------------------------------------------
 
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
 
library std;
use std.textio.all;
 
library ieee;
use ieee.std_logic_textio.all;
 
library mod_sim_exp;
use mod_sim_exp.mod_sim_exp_pkg.all;
 
entity multiplier_tb is
end multiplier_tb;
 
architecture test of multiplier_tb is
constant CLK_PERIOD : time := 10 ns;
signal clk : std_logic := '0';
signal reset : std_logic := '1';
file input : text open read_mode is "src/sim_mult_input.txt";
file output : text open write_mode is "out/sim_mult_output.txt";
------------------------------------------------------------------
-- Core parameters
------------------------------------------------------------------
constant NR_BITS_TOTAL : integer := 1536;
constant NR_STAGES_TOTAL : integer := 96;
constant NR_STAGES_LOW : integer := 32;
constant SPLIT_PIPELINE : boolean := true;
-- extra calculated constants
constant NR_BITS_LOW : integer := (NR_BITS_TOTAL/NR_STAGES_TOTAL)*NR_STAGES_LOW;
constant NR_BITS_HIGH : integer := NR_BITS_TOTAL-NR_BITS_LOW;
-- the width of the input operand for the mulitplier test
constant TEST_NR_BITS : integer := NR_BITS_LOW;
------------------------------------------------------------------
-- Signals for multiplier core memory space
------------------------------------------------------------------
-- data busses
signal xy : std_logic_vector(NR_BITS_TOTAL-1 downto 0); -- x and y operand data bus RAM -> multiplier
signal m : std_logic_vector(NR_BITS_TOTAL-1 downto 0); -- modulus data bus RAM -> multiplier
signal r : std_logic_vector(NR_BITS_TOTAL-1 downto 0); -- result data bus RAM <- multiplier
-- control signals
signal p_sel : std_logic_vector(1 downto 0); -- operand selection
signal result_dest_op : std_logic_vector(1 downto 0); -- result destination operand
signal ready : std_logic;
signal start : std_logic;
signal load_op : std_logic;
signal load_x : std_logic;
signal load_m : std_logic;
signal load_result : std_logic;
begin
 
------------------------------------------
-- Generate clk
------------------------------------------
clk_process : process
begin
while (true) loop
clk <= '0';
wait for CLK_PERIOD/2;
clk <= '1';
wait for CLK_PERIOD/2;
end loop;
end process;
 
------------------------------------------
-- Stimulus Process
------------------------------------------
stim_proc : process
procedure waitclk(n : natural := 1) is
begin
for i in 1 to n loop
wait until rising_edge(clk);
end loop;
end waitclk;
 
function ToString(constant Timeval : time) return string is
variable StrPtr : line;
begin
write(StrPtr,Timeval);
return StrPtr.all;
end ToString;
 
-- variables to read file
variable L : line;
variable Lw : line;
variable x_op : std_logic_vector((NR_BITS_TOTAL-1) downto 0) := (others=>'0');
variable y_op : std_logic_vector((NR_BITS_TOTAL-1) downto 0) := (others=>'0');
variable m_op : std_logic_vector((NR_BITS_TOTAL-1) downto 0) := (others=>'0');
variable result : std_logic_vector((NR_BITS_TOTAL-1) downto 0) := (others=>'0');
variable good_value : boolean;
variable param_count : integer := 0;
variable timer : time;
begin
-- initialisation
xy <= (others=>'0');
m <= (others=>'0');
start <='0';
reset <= '0';
load_x <= '0';
write(Lw, string'("----- Selecting pipeline: "));
writeline(output, Lw);
case (TEST_NR_BITS) is
when NR_BITS_TOTAL => p_sel <= "11"; write(Lw, string'(" Full pipeline selected"));
when NR_BITS_HIGH => p_sel <= "10"; write(Lw, string'(" Upper pipeline selected"));
when NR_BITS_LOW => p_sel <= "01"; write(Lw, string'(" Lower pipeline selected"));
when others =>
write(Lw, string'(" Invallid bitwidth for design"));
assert false report "impossible basewidth!" severity failure;
end case;
writeline(output, Lw);
-- Generate active high reset signal
reset <= '1';
waitclk(10);
reset <= '0';
waitclk(10);
while not endfile(input) loop
readline(input, L); -- read next line
next when L(1)='-'; -- skip comment lines
-- read input values
case param_count is
when 0 =>
hread(L, x_op(TEST_NR_BITS-1 downto 0), good_value);
assert good_value report "Can not read x operand" severity failure;
assert false report "Simulating multiplication" severity note;
write(Lw, string'("----------------------------------------------"));
writeline(output, Lw);
write(Lw, string'("-- MULTIPLICATION --"));
writeline(output, Lw);
write(Lw, string'("----------------------------------------------"));
writeline(output, Lw);
write(Lw, string'("----- Variables used:"));
writeline(output, Lw);
write(Lw, string'("x: "));
hwrite(Lw, x_op(TEST_NR_BITS-1 downto 0));
writeline(output, Lw);
when 1 =>
hread(L, y_op(TEST_NR_BITS-1 downto 0), good_value);
assert good_value report "Can not read y operand" severity failure;
write(Lw, string'("y: "));
hwrite(Lw, y_op(TEST_NR_BITS-1 downto 0));
writeline(output, Lw);
when 2 =>
hread(L, m_op(TEST_NR_BITS-1 downto 0), good_value);
assert good_value report "Can not read m operand" severity failure;
write(Lw, string'("m: "));
hwrite(Lw, m_op(TEST_NR_BITS-1 downto 0));
writeline(output, Lw);
-- load in x
xy <= x_op;
wait until rising_edge(clk);
load_x <='1';
wait until rising_edge(clk);
load_x <='0';
-- put y and m on the bus
xy <= y_op;
m <= m_op;
wait until rising_edge(clk);
-- start multiplication and wait for result
start <= '1';
wait until rising_edge(clk);
start <= '0';
wait until ready='1';
wait until rising_edge(clk);
writeline(output, Lw);
write(Lw, string'(" Computed result: "));
hwrite(Lw, r(TEST_NR_BITS-1 downto 0));
writeline(output, Lw);
when 3 =>
hread(L, result(TEST_NR_BITS-1 downto 0), good_value);
assert good_value report "Can not read result" severity failure;
write(Lw, string'(" Read result: "));
hwrite(Lw, result(TEST_NR_BITS-1 downto 0));
writeline(output, Lw);
if (r(TEST_NR_BITS-1 downto 0) = result(TEST_NR_BITS-1 downto 0)) then
write(Lw, string'(" => result is correct!")); writeline(output, Lw);
else
write(Lw, string'(" => Error: result is incorrect!!!")); writeline(output, Lw);
assert false report "result is incorrect!!!" severity error;
end if;
when others =>
assert false report "undefined state!" severity failure;
end case;
if (param_count = 3) then
param_count := 0;
else
param_count := param_count+1;
end if;
end loop;
wait for 1 us;
assert false report "End of simulation" severity failure;
 
end process;
 
------------------------------------------
-- Multiplier instance
------------------------------------------
the_multiplier : mont_multiplier
generic map(
n => NR_BITS_TOTAL,
t => NR_STAGES_TOTAL,
tl => NR_STAGES_LOW,
split => SPLIT_PIPELINE
)
port map(
core_clk => clk,
xy => xy,
m => m,
r => r,
start => start,
reset => reset,
p_sel => p_sel,
load_x => load_x,
ready => ready
);
 
end test;

powered by: WebSVN 2.1.0

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