-
Notifications
You must be signed in to change notification settings - Fork 0
/
butterfly_tb.vhd
94 lines (75 loc) · 3.7 KB
/
butterfly_tb.vhd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity butterfly_tb is
end;
architecture TB of butterfly_tb is
-- Clock period
constant clk_period : time := 10 ns;
-- Pipeline length
constant pipeline_length : positive := 1;
-- Generics
constant width : positive := 16;
-- Ports
signal clk : std_logic := '0';
signal rst : std_logic;
signal en : std_logic := '1';
signal input_0_real : std_logic_vector(width - 1 downto 0);
signal input_0_img : std_logic_vector(width - 1 downto 0);
signal input_1_real : std_logic_vector(width - 1 downto 0);
signal input_1_img : std_logic_vector(width - 1 downto 0);
signal output_0_real : std_logic_vector(width - 1 downto 0);
signal output_0_img : std_logic_vector(width - 1 downto 0);
signal output_1_real : std_logic_vector(width - 1 downto 0);
signal output_1_img : std_logic_vector(width - 1 downto 0);
signal sim_done : std_logic := '0';
begin
-- toggle clock
clk <= not clk after clk_period when sim_done = '0' else
clk;
-- output_0 = input0 + input1
-- output_1 = input0 - input1
UUT : entity work.butterfly
generic map(
width => width
)
port map(
clk => clk,
rst => rst,
en => en,
input_0_real => input_0_real,
input_0_img => input_0_img,
input_1_real => input_1_real,
input_1_img => input_1_img,
output_0_real => output_0_real,
output_0_img => output_0_img,
output_1_real => output_1_real,
output_1_img => output_1_img
);
process
variable expected_output_0_real, expected_output_0_img : integer;
variable expected_output_1_real, expected_output_1_img : integer;
begin
rst <= '1';
wait until rising_edge(clk);
rst <= '0';
wait until rising_edge(clk);
input_0_real <= std_logic_vector(to_signed(1, input_0_real'length));
input_0_img <= std_logic_vector(to_signed(2, input_0_img'length));
input_1_real <= std_logic_vector(to_signed(3, input_1_real'length));
input_1_img <= std_logic_vector(to_signed(4, input_1_img'length));
for i in 0 to pipeline_length loop
wait until rising_edge(clk);
end loop; -- i
expected_output_0_real := 4;
expected_output_0_img := 6;
expected_output_1_real := (-2);
expected_output_1_img := (-2);
assert output_0_real = std_logic_vector(to_signed(expected_output_0_real, output_0_real'length)) report "unexpected value. expected_output_0_real = " & integer'image(expected_output_0_real) & ", output_0_real = " & integer'image(to_integer(signed(output_0_real)));
assert output_0_img = std_logic_vector(to_signed(expected_output_0_img, output_0_img'length)) report "unexpected value. expected_output_0_img = " & integer'image(expected_output_0_img) & ", output_0_img = " & integer'image(to_integer(signed(output_0_img)));
assert output_1_real = std_logic_vector(to_signed(expected_output_1_real, output_1_real'length)) report "unexpected value. expected_output_1_real = " & integer'image(expected_output_1_real) & ", output_1_real = " & integer'image(to_integer(signed(output_1_real)));
assert output_1_img = std_logic_vector(to_signed(expected_output_1_img, output_1_img'length)) report "unexpected value. expected_output_1_img = " & integer'image(expected_output_1_img) & ", output_1_img = " & integer'image(to_integer(signed(output_1_img)));
sim_done <= '1';
report "SIMULATION FINISHED!!!";
end process;
end TB;