ci_mul_tb.vhd 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.numeric_std.all;
  4. use ieee.std_logic_textio.all;
  5. library std;
  6. use std.textio.all;
  7. entity tb is
  8. end entity;
  9. architecture bench of tb is
  10. constant CLK_PERIOD : time := 10 ns;
  11. signal stop : boolean := false;
  12. signal clk : std_logic;
  13. signal clk_en : std_logic;
  14. signal reset : std_logic := '0';
  15. signal dataa : std_logic_vector(31 downto 0);
  16. signal datab : std_logic_vector(31 downto 0);
  17. signal result : std_logic_vector(31 downto 0);
  18. type test_vector_t is array (0 to 4) of std_logic_vector(31 downto 0);
  19. type result_vector_t is array (0 to 14) of std_logic_vector(31 downto 0);
  20. constant test_vector : test_vector_t := (
  21. x"00010000", -- one
  22. x"11110000", -- -one
  23. x"fff842ab", -- x
  24. x"ffe2859a", -- y
  25. x"001e3999" -- z
  26. );
  27. constant result_vector : result_vector_t := (
  28. x"00010000", -- one * one
  29. x"11110000", -- one * -one
  30. x"fff842ab", -- one * x
  31. x"ffe2859a", -- one * y
  32. x"001e3999", -- one * z
  33. x"00010000", -- -one * -one
  34. x"00010000", -- -one * x
  35. x"00010000", -- -one * y
  36. x"00010000", -- -one * z
  37. x"003be6ac", -- x * x
  38. x"00e425f0", -- x * y
  39. x"ff161241", -- x * z
  40. x"0364f5a1", -- y * y
  41. x"fc85062d", -- y * z
  42. x"03918cd1" -- z * z
  43. );
  44. begin
  45. ci_mul_inst : entity work.ci_mul
  46. port map (
  47. clk => clk,
  48. clk_en => clk_en,
  49. reset => reset,
  50. dataa => dataa,
  51. datab => datab,
  52. result => result
  53. );
  54. stimulus : process
  55. variable ri : integer := -2;
  56. begin
  57. reset <= '1';
  58. dataa <= x"00000000";
  59. datab <= x"00000000";
  60. wait for 50 ns;
  61. for i in 0 to test_vector'length - 1 loop
  62. for j in i to test_vector'length - 1 loop
  63. wait until rising_edge(clk);
  64. if not (i = 0 and j = 0) then
  65. report "testing dataa=" & to_string(dataa) & " * datab=" & to_string(datab);
  66. end if;
  67. if ri > -1 then
  68. report "correct=" & to_string(result = result_vector(ri));
  69. report " result=" & to_string(result);
  70. report " actual=" & to_string(result_vector(ri));
  71. end if;
  72. wait until rising_edge(clk);
  73. if i = 0 and j = 0 then
  74. reset <= '0';
  75. clk_en <= '1';
  76. end if;
  77. dataa <= test_vector(i);
  78. datab <= test_vector(j);
  79. ri := ri + 1;
  80. end loop;
  81. end loop;
  82. wait until rising_edge(clk);
  83. clk_en <= '0';
  84. stop <= true;
  85. wait;
  86. end process;
  87. generate_clk : process
  88. begin
  89. while not stop loop
  90. clk <= '1', '0' after CLK_PERIOD / 2;
  91. wait for CLK_PERIOD;
  92. end loop;
  93. wait;
  94. end process;
  95. end architecture;