projet-vlsi/shifter_tb.vhdl

241 lines
7.1 KiB
VHDL

library ieee;
use ieee.math_real.all;
use ieee.numeric_std.all;
use ieee.std_logic_1164.all;
entity shifter_tb is
end shifter_tb;
ARCHITECTURE Structurel OF Shifter_tb is
signal shift_lsl : Std_Logic := '0';
signal shift_lsr : Std_Logic := '0';
signal shift_asr : Std_Logic := '0';
signal shift_ror : Std_Logic := '0';
signal shift_rrx : Std_Logic := '0';
signal shift_val : Std_Logic_Vector(4 downto 0);
signal din : Std_Logic_Vector(31 downto 0);
signal cin : Std_Logic := '0';
signal dout : Std_Logic_Vector(31 downto 0);
signal cout : Std_Logic;
signal vdd : bit := '1';
signal vss : bit := '0';
begin
shift: entity work.Shifter
port map(
shift_lsl => shift_lsl,
shift_lsr => shift_lsr,
shift_asr => shift_asr,
shift_ror => shift_ror,
shift_rrx => shift_rrx,
shift_val => shift_val,
din => din,
cin => cin,
dout => dout,
cout => cout,
vdd => vdd,
vss => vss
);
process
-- Variables for the random number
variable seed1 : positive;
variable seed2 : positive;
variable x : real;
variable y : integer;
variable vdout : std_logic_vector(31 downto 0);
variable vcout : std_logic;
begin
-- set vdd to 5v
vdd <= '1';
-- set vss to gnd
vss <= '0';
-- seeds for random number
seed1 := 1;
seed2 := 1;
wait for 1 ns;
-- lsl
report "lsl with 32 random values";
shift_lsl <= '1';
la : for va in 0 to 31 loop
uniform(seed1, seed2, x);
y := integer(floor(x * 31.0)) + 1;
shift_val <= std_logic_vector(to_unsigned(y, shift_val'length));
uniform(seed1, seed2, x);
y := integer(floor(x * 536870911.0));
din <= std_logic_vector(to_unsigned(y, din'length));
if (y mod 2) = 0 then
cin <= '1';
else
cin <= '0';
end if;
wait for 1 ns;
vdout := din sll shift_val;
vcout := 0;
report "din = " & integer'image(to_integer(unsigned(din)));
report "shift_val = " & integer'image(to_integer(unsigned(shift_val)));
assert (dout = vdout) report "[error] lsl. vdout = " & integer'image(to_integer(unsigned(vdout))) & " versus dout = " & integer'image(to_integer(unsigned(dout))) severity error;
--assert (cout = vcout) report "[error] lsl. vcout = " & integer'image(to_integer(unsigned(vcout))) & " versus cout = " & integer'image(to_integer(unsigned(cout))) severity error;
end loop la;
wait for 1 ns;
-- lsr
report "lsr with 32 random values";
shift_lsl <= '0';
shift_lsr <= '1';
la : for va in 0 to 31 loop
uniform(seed1, seed2, x);
y := integer(floor(x * 31.0)) + 1;
shift_val <= std_logic_vector(to_unsigned(y, shift_val'length));
uniform(seed1, seed2, x);
y := integer(floor(x * 536870911.0));
din <= std_logic_vector(to_unsigned(y, din'length));
if (y mod 2) = 0 then
cin <= '1';
else
cin <= '0';
end if;
wait for 1 ns;
vdout := din ror shift_val;
vcout := 0;
report "din = " & integer'image(to_integer(unsigned(din)));
report "shift_val = " & integer'image(to_integer(unsigned(shift_val)));
assert (dout = vdout) report "[error] lsl. vdout = " & integer'image(to_integer(unsigned(vdout))) & " versus dout = " & integer'image(to_integer(unsigned(dout))) severity error;
--assert (cout = vcout) report "[error] lsl. vcout = " & integer'image(to_integer(unsigned(vcout))) & " versus cout = " & integer'image(to_integer(unsigned(cout))) severity error;
end loop la;
wait for 1 ns;
-- asr
report "asr with 32 random values";
shift_asr <= '1';
shift_lsr <= '0';
la : for va in 0 to 31 loop
uniform(seed1, seed2, x);
y := integer(floor(x * 31.0)) + 1;
shift_val <= std_logic_vector(to_unsigned(y, shift_val'length));
uniform(seed1, seed2, x);
y := integer(floor(x * 536870911.0));
din <= std_logic_vector(to_unsigned(y, din'length));
if (y mod 2) = 0 then
cin <= '1';
else
cin <= '0';
end if;
wait for 1 ns;
vdout := din sra shift_val;
vcout := 0;
report "din = " & integer'image(to_integer(unsigned(din)));
report "shift_val = " & integer'image(to_integer(unsigned(shift_val)));
assert (dout = vdout) report "[error] lsl. vdout = " & integer'image(to_integer(unsigned(vdout))) & " versus dout = " & integer'image(to_integer(unsigned(dout))) severity error;
--assert (cout = vcout) report "[error] lsl. vcout = " & integer'image(to_integer(unsigned(vcout))) & " versus cout = " & integer'image(to_integer(unsigned(cout))) severity error;
end loop la;
wait for 1 ns;
-- ror
report "ror with 32 random values";
shift_ror <= '1';
shift_asr <= '0';
la : for va in 0 to 31 loop
uniform(seed1, seed2, x);
y := integer(floor(x * 31.0)) + 1;
shift_val <= std_logic_vector(to_unsigned(y, shift_val'length));
uniform(seed1, seed2, x);
y := integer(floor(x * 536870911.0));
din <= std_logic_vector(to_unsigned(y, din'length));
if (y mod 2) = 0 then
cin <= '1';
else
cin <= '0';
end if;
wait for 1 ns;
vdout := din ror shift_val;
vcout := 0;
report "din = " & integer'image(to_integer(unsigned(din)));
report "shift_val = " & integer'image(to_integer(unsigned(shift_val)));
assert (dout = vdout) report "[error] lsl. vdout = " & integer'image(to_integer(unsigned(vdout))) & " versus dout = " & integer'image(to_integer(unsigned(dout))) severity error;
--assert (cout = vcout) report "[error] lsl. vcout = " & integer'image(to_integer(unsigned(vcout))) & " versus cout = " & integer'image(to_integer(unsigned(cout))) severity error;
end loop la;
wait for 1 ns;
-- rrx
report "rrx with 32 random values";
shift_rrx <= '1';
shift_ror <= '0';
la : for va in 0 to 31 loop
uniform(seed1, seed2, x);
y := integer(floor(x * 31.0)) + 1;
shift_val <= std_logic_vector(to_unsigned(y, shift_val'length));
uniform(seed1, seed2, x);
y := integer(floor(x * 536870911.0));
din <= std_logic_vector(to_unsigned(y, din'length));
if (y mod 2) = 0 then
cin <= '1';
else
cin <= '0';
end if;
wait for 1 ns;
vdout := din rrx shift_val;
vcout := 0;
report "din = " & integer'image(to_integer(unsigned(din)));
report "shift_val = " & integer'image(to_integer(unsigned(shift_val)));
--assert (dout = vdout) report "[error] lsl. vdout = " & integer'image(to_integer(unsigned(vdout))) & " versus dout = " & integer'image(to_integer(unsigned(dout))) severity error;
--assert (cout = vcout) report "[error] lsl. vcout = " & integer'image(to_integer(unsigned(vcout))) & " versus cout = " & integer'image(to_integer(unsigned(cout))) severity error;
end loop la;
wait for 1 ns;
wait;
end process;
end Structurel;