Skip to content
Snippets Groups Projects
Commit d81f9928 authored by Eric Kooistra's avatar Eric Kooistra
Browse files

Verify RESIZE_NUM() and common_resize.vhd.

parent aab5818c
No related branches found
No related tags found
1 merge request!165Resolve L2SDP-303
...@@ -24,16 +24,28 @@ USE IEEE.STD_LOGIC_1164.ALL; ...@@ -24,16 +24,28 @@ USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.NUMERIC_STD.ALL; USE IEEE.NUMERIC_STD.ALL;
USE work.common_pkg.ALL; USE work.common_pkg.ALL;
-- Purpose: Test bench for common_resize.vhd -- Purpose: Test bench for common_resize.vhd and for RESIZE_NUM() from
-- common_pkg.vhd
-- Usage: -- Usage:
-- > do wave_resize.do -- > do wave_resize.do
-- > run 500 ns -- or use:
-- . Verify clipping using c_clip=TRUE and c_clip_symmetric=TRUE or FALSE -- > as 5
-- . Verify wrapping using c_clip=FALSE -- and manually set the signed data output signals to radix decimal
-- > run -a
-- . Verify clipping using g_clip=TRUE and g_clip_symmetric=TRUE or FALSE
-- . Verify wrapping using g_clip=FALSE
-- . Observe reg_dat with respect to out_sdat, out_sovr for signed -- . Observe reg_dat with respect to out_sdat, out_sovr for signed
-- . Observe reg_dat with respect to out_udat, out_uovr for unsigned -- . Observe reg_dat with respect to out_udat, out_uovr for unsigned
ENTITY tb_resize IS ENTITY tb_resize IS
GENERIC (
-- Supported for RESIZE_NUM() and common_resize.vhd
g_in_dat_w : NATURAL := 5;
g_out_dat_w : NATURAL := 3;
-- Only supported for common_resize.vhd
g_clip : BOOLEAN := TRUE;
g_clip_symmetric : BOOLEAN := TRUE
);
END tb_resize; END tb_resize;
ARCHITECTURE tb OF tb_resize IS ARCHITECTURE tb OF tb_resize IS
...@@ -43,27 +55,37 @@ ARCHITECTURE tb OF tb_resize IS ...@@ -43,27 +55,37 @@ ARCHITECTURE tb OF tb_resize IS
CONSTANT c_pipeline_input : NATURAL := 0; CONSTANT c_pipeline_input : NATURAL := 0;
CONSTANT c_pipeline_output : NATURAL := 1; CONSTANT c_pipeline_output : NATURAL := 1;
CONSTANT c_pipeline : NATURAL := c_pipeline_input + c_pipeline_output; CONSTANT c_pipeline : NATURAL := c_pipeline_input + c_pipeline_output;
CONSTANT c_clip : BOOLEAN := TRUE;
CONSTANT c_clip_symmetric : BOOLEAN := TRUE;
CONSTANT c_in_dat_w : NATURAL := 5;
CONSTANT c_out_dat_w : NATURAL := 3;
-- Test data
SIGNAL in_val : STD_LOGIC; SIGNAL in_val : STD_LOGIC;
SIGNAL in_dat : STD_LOGIC_VECTOR(c_in_dat_w-1 DOWNTO 0); SIGNAL in_dat : STD_LOGIC_VECTOR(g_in_dat_w-1 DOWNTO 0);
SIGNAL in_vec : STD_LOGIC_VECTOR(c_in_dat_w DOWNTO 0);
SIGNAL reg_vec : STD_LOGIC_VECTOR(c_in_dat_w DOWNTO 0);
SIGNAL reg_val : STD_LOGIC; SIGNAL reg_val : STD_LOGIC;
SIGNAL reg_dat : STD_LOGIC_VECTOR(c_in_dat_w-1 DOWNTO 0); SIGNAL reg_dat : STD_LOGIC_VECTOR(g_in_dat_w-1 DOWNTO 0);
SIGNAL out_sdat : STD_LOGIC_VECTOR(c_out_dat_w-1 DOWNTO 0);
SIGNAL out_udat : STD_LOGIC_VECTOR(c_out_dat_w-1 DOWNTO 0); -- Signed output data, view as radix decimal in Wave window
SIGNAL out_sovr : STD_LOGIC; SIGNAL reg_sdat : STD_LOGIC_VECTOR(g_in_dat_w-1 DOWNTO 0);
SIGNAL out_uovr : STD_LOGIC; SIGNAL lowrange_sdat : STD_LOGIC_VECTOR(g_out_dat_w-1 DOWNTO 0); -- keep LSbits or sign extend
SIGNAL resize_num_sdat : STD_LOGIC_VECTOR(g_out_dat_w-1 DOWNTO 0); -- using RESIZE_NUM() from common_pkg.vhd
SIGNAL resize_sdat : STD_LOGIC_VECTOR(g_out_dat_w-1 DOWNTO 0); -- using RESIZE() from IEEE.NUMERIC_STD
SIGNAL out_sdat : STD_LOGIC_VECTOR(g_out_dat_w-1 DOWNTO 0); -- using common_resize.vhd
SIGNAL out_sovr : STD_LOGIC; -- overflow for out_sdat
-- Unsigned output data, view as radix unsigned in Wave window
SIGNAL reg_udat : STD_LOGIC_VECTOR(g_in_dat_w-1 DOWNTO 0);
SIGNAL lowrange_udat : STD_LOGIC_VECTOR(g_out_dat_w-1 DOWNTO 0); -- keep LSbits
SIGNAL resize_num_udat : STD_LOGIC_VECTOR(g_out_dat_w-1 DOWNTO 0); -- using RESIZE_NUM() from common_pkg.vhd
SIGNAL resize_udat : STD_LOGIC_VECTOR(g_out_dat_w-1 DOWNTO 0); -- using RESIZE() from IEEE.NUMERIC_STD
SIGNAL out_udat : STD_LOGIC_VECTOR(g_out_dat_w-1 DOWNTO 0); -- using common_resize.vhd
SIGNAL out_uovr : STD_LOGIC; -- overflow for out_udat
SIGNAL tb_end : STD_LOGIC := '0'; SIGNAL tb_end : STD_LOGIC := '0';
SIGNAL clk : STD_LOGIC := '1'; SIGNAL clk : STD_LOGIC := '1';
SIGNAL rst : STD_LOGIC; SIGNAL rst : STD_LOGIC;
CONSTANT c_init : STD_LOGIC_VECTOR(in_dat'RANGE) := (OTHERS=>'0'); CONSTANT c_init : STD_LOGIC_VECTOR(in_dat'RANGE) := (OTHERS=>'0');
CONSTANT g_clip_umax : NATURAL := 2**g_out_dat_w - 1;
CONSTANT g_clip_smax : NATURAL := 2**(g_out_dat_w - 1) - 1;
CONSTANT g_clip_smin : INTEGER := -2**(g_out_dat_w - 1);
BEGIN BEGIN
...@@ -99,35 +121,54 @@ BEGIN ...@@ -99,35 +121,54 @@ BEGIN
END IF; END IF;
END PROCESS; END PROCESS;
-- Delay input as much as DUT output -- Delay input as much as DUT output, assume c_pipeline = 1
in_vec <= in_val & in_dat; reg_val <= in_val WHEN rising_edge(clk);
reg_dat <= in_dat WHEN rising_edge(clk);
reg_sdat <= reg_dat;
reg_udat <= reg_dat;
u_pipe : ENTITY work.common_pipeline gen_extend_lowrange : IF g_out_dat_w >= g_in_dat_w GENERATE
GENERIC MAP ( p_extend_lowrange : PROCESS(clk)
g_representation => "SIGNED", BEGIN
g_pipeline => c_pipeline, IF rising_edge(clk) THEN
g_in_dat_w => c_in_dat_w+1, -- Extend MSbits for "SIGNED" and "UNSIGNED"
g_out_dat_w => c_in_dat_w+1 lowrange_sdat <= (OTHERS => in_dat(g_in_dat_w-1)); -- Extend MSbit for "SIGNED"
) lowrange_udat <= (OTHERS => '0'); -- Extend '0' for "UNSIGNED"
PORT MAP ( lowrange_sdat(g_in_dat_w-1 DOWNTO 0) <= in_dat;
clk => clk, lowrange_udat(g_in_dat_w-1 DOWNTO 0) <= in_dat;
in_dat => in_vec, END IF;
out_dat => reg_vec END PROCESS;
); END GENERATE;
gen_reduce_lowrange : IF g_out_dat_w < g_in_dat_w GENERATE
p_reduce_lowrange : PROCESS(clk)
BEGIN
IF rising_edge(clk) THEN
-- Remove MSbits for "SIGNED" and "UNSIGNED"
lowrange_sdat <= in_dat(g_out_dat_w-1 DOWNTO 0);
lowrange_udat <= in_dat(g_out_dat_w-1 DOWNTO 0);
END IF;
END PROCESS;
END GENERATE;
reg_val <= reg_vec(c_in_dat_w); -- IEEE RESIZE() for "SIGNED" and "UNSIGNED"
reg_dat <= reg_vec(c_in_dat_w-1 DOWNTO 0); resize_sdat <= STD_LOGIC_VECTOR(RESIZE( SIGNED(in_dat), g_out_dat_w)) WHEN rising_edge(clk);
resize_udat <= STD_LOGIC_VECTOR(RESIZE(UNSIGNED(in_dat), g_out_dat_w)) WHEN rising_edge(clk);
-- RESIZE_NUM() from common_pkg.vhd for "SIGNED" and "UNSIGNED"
resize_num_sdat <= STD_LOGIC_VECTOR(RESIZE_NUM( SIGNED(in_dat), g_out_dat_w)) WHEN rising_edge(clk);
resize_num_udat <= STD_LOGIC_VECTOR(RESIZE_NUM(UNSIGNED(in_dat), g_out_dat_w)) WHEN rising_edge(clk);
-- DUT for "SIGNED" -- DUT for "SIGNED"
u_s_resize : ENTITY work.common_resize u_s_resize : ENTITY work.common_resize
GENERIC MAP ( GENERIC MAP (
g_representation => "SIGNED", g_representation => "SIGNED",
g_clip => c_clip, g_clip => g_clip,
g_clip_symmetric => c_clip_symmetric, g_clip_symmetric => g_clip_symmetric,
g_pipeline_input => c_pipeline_input, g_pipeline_input => c_pipeline_input,
g_pipeline_output => c_pipeline_output, g_pipeline_output => c_pipeline_output,
g_in_dat_w => c_in_dat_w, g_in_dat_w => g_in_dat_w,
g_out_dat_w => c_out_dat_w g_out_dat_w => g_out_dat_w
) )
PORT MAP ( PORT MAP (
clk => clk, clk => clk,
...@@ -140,12 +181,12 @@ BEGIN ...@@ -140,12 +181,12 @@ BEGIN
u_u_resize : ENTITY work.common_resize u_u_resize : ENTITY work.common_resize
GENERIC MAP ( GENERIC MAP (
g_representation => "UNSIGNED", g_representation => "UNSIGNED",
g_clip => c_clip, g_clip => g_clip,
g_clip_symmetric => c_clip_symmetric, g_clip_symmetric => g_clip_symmetric,
g_pipeline_input => c_pipeline_input, g_pipeline_input => c_pipeline_input,
g_pipeline_output => c_pipeline_output, g_pipeline_output => c_pipeline_output,
g_in_dat_w => c_in_dat_w, g_in_dat_w => g_in_dat_w,
g_out_dat_w => c_out_dat_w g_out_dat_w => g_out_dat_w
) )
PORT MAP ( PORT MAP (
clk => clk, clk => clk,
...@@ -155,16 +196,49 @@ BEGIN ...@@ -155,16 +196,49 @@ BEGIN
); );
-- Verification -- Verification
p_verify_increase : PROCESS p_verify : PROCESS
BEGIN BEGIN
WAIT UNTIL rising_edge(clk); WAIT UNTIL rising_edge(clk);
IF reg_val = '1' AND c_in_dat_w<=c_out_dat_w THEN IF reg_val = '1' THEN
IF SIGNED(out_sdat) /= SIGNED(reg_dat) THEN IF g_in_dat_w<=g_out_dat_w THEN
REPORT "Mismatch between signed resize to larger vector" SEVERITY ERROR; -- For extended width expected value is same as input value
ASSERT SIGNED( lowrange_sdat) = SIGNED(reg_dat) REPORT "Wrong extended lowrange_sdat" SEVERITY ERROR;
ASSERT UNSIGNED( lowrange_udat) = UNSIGNED(reg_dat) REPORT "Wrong extended lowrange_udat" SEVERITY ERROR;
ASSERT SIGNED( resize_sdat) = SIGNED(reg_dat) REPORT "Wrong extended resize_sdat" SEVERITY ERROR;
ASSERT UNSIGNED( resize_udat) = UNSIGNED(reg_dat) REPORT "Wrong extended resize_udat" SEVERITY ERROR;
ASSERT SIGNED(resize_num_sdat) = SIGNED(reg_dat) REPORT "Wrong extended resize_num_sdat" SEVERITY ERROR;
ASSERT UNSIGNED(resize_num_udat) = UNSIGNED(reg_dat) REPORT "Wrong extended resize_num_udat" SEVERITY ERROR;
ASSERT SIGNED( out_sdat) = SIGNED(reg_dat) REPORT "Wrong extended out_sdat" SEVERITY ERROR;
ASSERT UNSIGNED( out_udat) = UNSIGNED(reg_dat) REPORT "Wrong extended out_udat" SEVERITY ERROR;
ELSE
-- For reduced width compare unsigned with lowrange
ASSERT UNSIGNED( resize_udat) = UNSIGNED(lowrange_udat) REPORT "Wrong wrapped resize_udat" SEVERITY ERROR;
ASSERT UNSIGNED(resize_num_udat) = UNSIGNED(lowrange_udat) REPORT "Wrong wrapped resize_num_udat" SEVERITY ERROR;
ASSERT UNSIGNED( out_udat) = UNSIGNED(lowrange_udat) OR
UNSIGNED( out_udat) = g_clip_umax REPORT "Wrong clipped out_udat" SEVERITY ERROR;
-- For reduced width compare signed with lowrange
-- . no need to verify RESIZE(), because it is part of IEEE.NUMERIC_STD
-- . verify RESIZE_NUM() below for all g_out_dat_w
-- . verify common_resize here
IF g_clip THEN
IF g_clip_symmetric THEN
ASSERT (SIGNED(out_sdat) = SIGNED(lowrange_sdat) OR SIGNED(out_sdat) = -g_clip_smax OR SIGNED(out_sdat) = g_clip_smax) AND
SIGNED(out_sdat) /= g_clip_smin AND
SIGNED(out_sdat) /= -g_clip_smin REPORT "Wrong clipped symmetrical out_sdat" SEVERITY ERROR;
ELSE
ASSERT (SIGNED(out_sdat) = SIGNED(lowrange_sdat) OR SIGNED(out_sdat) = g_clip_smin OR SIGNED(out_sdat) = g_clip_smax)
REPORT "Wrong clipped out_sdat" SEVERITY ERROR;
END IF;
ELSE
ASSERT SIGNED(out_sdat) = SIGNED(lowrange_sdat) REPORT "Wrong wrapped out_sdat" SEVERITY ERROR;
END IF; END IF;
IF UNSIGNED(out_udat) /= UNSIGNED(reg_dat) THEN
REPORT "Mismatch between unsigned resize to larger vector" SEVERITY ERROR;
END IF; END IF;
-- RESIZE_NUM() in common_pkg.vhd is always equivalent to lowrange
ASSERT SIGNED(resize_num_sdat) = SIGNED(lowrange_sdat) REPORT "Wrong resize_num_sdat /= lowrange_sdat" SEVERITY ERROR;
ASSERT UNSIGNED(resize_num_udat) = UNSIGNED(lowrange_udat) REPORT "Wrong resize_num_udat /= lowrange_udat" SEVERITY ERROR;
END IF; END IF;
END PROCESS; END PROCESS;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment