forked from cores/microwatt
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
119 lines
3.8 KiB
VHDL
119 lines
3.8 KiB
VHDL
3 years ago
|
library vunit_lib;
|
||
|
context vunit_lib.vunit_context;
|
||
|
|
||
5 years ago
|
library ieee;
|
||
|
use ieee.std_logic_1164.all;
|
||
|
use ieee.numeric_std.all;
|
||
|
|
||
|
library work;
|
||
|
use work.common.all;
|
||
3 years ago
|
|
||
|
library osvvm;
|
||
|
use osvvm.RandomPkg.all;
|
||
5 years ago
|
|
||
3 years ago
|
entity countbits_tb is
|
||
3 years ago
|
generic (runner_cfg : string := runner_cfg_default);
|
||
3 years ago
|
end countbits_tb;
|
||
5 years ago
|
|
||
3 years ago
|
architecture behave of countbits_tb is
|
||
5 years ago
|
constant clk_period: time := 10 ns;
|
||
|
signal rs: std_ulogic_vector(63 downto 0);
|
||
|
signal is_32bit, count_right: std_ulogic := '0';
|
||
3 years ago
|
signal res: std_ulogic_vector(63 downto 0);
|
||
5 years ago
|
signal clk: std_ulogic;
|
||
5 years ago
|
|
||
|
begin
|
||
3 years ago
|
bitcounter_0: entity work.bit_counter
|
||
4 years ago
|
port map (
|
||
5 years ago
|
clk => clk,
|
||
4 years ago
|
rs => rs,
|
||
3 years ago
|
result => res,
|
||
4 years ago
|
count_right => count_right,
|
||
3 years ago
|
is_32bit => is_32bit,
|
||
|
do_popcnt => '0',
|
||
|
datalen => "0000"
|
||
4 years ago
|
);
|
||
5 years ago
|
|
||
5 years ago
|
clk_process: process
|
||
|
begin
|
||
|
clk <= '0';
|
||
|
wait for clk_period/2;
|
||
|
clk <= '1';
|
||
|
wait for clk_period/2;
|
||
|
end process;
|
||
|
|
||
5 years ago
|
stim_process: process
|
||
|
variable r: std_ulogic_vector(63 downto 0);
|
||
3 years ago
|
variable rnd : RandomPType;
|
||
5 years ago
|
begin
|
||
3 years ago
|
rnd.InitSeed(stim_process'path_name);
|
||
|
|
||
|
test_runner_setup(runner, runner_cfg);
|
||
|
|
||
3 years ago
|
while test_suite loop
|
||
|
if run("Test with input = 0") then
|
||
|
rs <= (others => '0');
|
||
5 years ago
|
is_32bit <= '0';
|
||
3 years ago
|
count_right <= '0';
|
||
5 years ago
|
wait for clk_period;
|
||
3 years ago
|
check_equal(res, 16#40#, result("for cntlzd"));
|
||
3 years ago
|
count_right <= '1';
|
||
5 years ago
|
wait for clk_period;
|
||
3 years ago
|
check_equal(res, 16#40#, result("for cnttzd"));
|
||
5 years ago
|
is_32bit <= '1';
|
||
3 years ago
|
count_right <= '0';
|
||
|
wait for clk_period;
|
||
3 years ago
|
check_equal(res, 16#20#, result("for cntlzw"));
|
||
3 years ago
|
count_right <= '1';
|
||
5 years ago
|
wait for clk_period;
|
||
3 years ago
|
check_equal(res, 16#20#, result("for cnttzw"));
|
||
3 years ago
|
|
||
|
elsif run("Test cntlzd/w") then
|
||
|
count_right <= '0';
|
||
|
for j in 0 to 100 loop
|
||
|
r := rnd.RandSlv(64);
|
||
|
r(63) := '1';
|
||
|
for i in 0 to 63 loop
|
||
|
rs <= r;
|
||
|
is_32bit <= '0';
|
||
|
wait for clk_period;
|
||
3 years ago
|
check_equal(res, i, result("for cntlzd " & to_hstring(rs)));
|
||
3 years ago
|
rs <= r(31 downto 0) & r(63 downto 32);
|
||
|
is_32bit <= '1';
|
||
|
wait for clk_period;
|
||
|
if i < 32 then
|
||
3 years ago
|
check_equal(res, i, result("for cntlzw " & to_hstring(rs)));
|
||
3 years ago
|
else
|
||
3 years ago
|
check_equal(res, 32, result("for cntlzw " & to_hstring(rs)));
|
||
3 years ago
|
end if;
|
||
|
r := '0' & r(63 downto 1);
|
||
|
end loop;
|
||
|
end loop;
|
||
|
|
||
|
elsif run("Test cnttzd/w") then
|
||
|
count_right <= '1';
|
||
|
for j in 0 to 100 loop
|
||
|
r := rnd.RandSlv(64);
|
||
|
r(0) := '1';
|
||
|
for i in 0 to 63 loop
|
||
|
rs <= r;
|
||
|
is_32bit <= '0';
|
||
|
wait for clk_period;
|
||
3 years ago
|
check_equal(res, i, result("for cnttzd " & to_hstring(rs)));
|
||
3 years ago
|
is_32bit <= '1';
|
||
|
wait for clk_period;
|
||
|
if i < 32 then
|
||
3 years ago
|
check_equal(res, i, result("for cnttzw " & to_hstring(rs)));
|
||
3 years ago
|
else
|
||
3 years ago
|
check_equal(res, 32, result("for cnttzw " & to_hstring(rs)));
|
||
3 years ago
|
end if;
|
||
|
r := r(62 downto 0) & '0';
|
||
|
end loop;
|
||
|
end loop;
|
||
|
end if;
|
||
5 years ago
|
end loop;
|
||
|
|
||
3 years ago
|
test_runner_cleanup(runner);
|
||
5 years ago
|
end process;
|
||
|
end behave;
|