1 |
2 |
bro |
------------------------------------------------------------------------------
|
2 |
|
|
-- Project : openFPU64 - Testbench for Avalon Bus
|
3 |
|
|
-------------------------------------------------------------------------------
|
4 |
|
|
-- File : openfpu64_tb.vhd
|
5 |
|
|
-- Author : Peter Huewe <peterhuewe@gmx.de>
|
6 |
|
|
-- Created : 2010-04-19
|
7 |
|
|
-- Last update: 2010-04-19
|
8 |
|
|
-- Standard : VHDL'87
|
9 |
|
|
-------------------------------------------------------------------------------
|
10 |
|
|
-- Description: Testbench for openFPU64, Avalon Bus interface.
|
11 |
|
|
--
|
12 |
|
|
-------------------------------------------------------------------------------
|
13 |
|
|
-- Copyright (c) 2010
|
14 |
|
|
-------------------------------------------------------------------------------
|
15 |
|
|
-- License: gplv3, see licence.txt
|
16 |
|
|
-------------------------------------------------------------------------------
|
17 |
|
|
|
18 |
|
|
library ieee;
|
19 |
|
|
use ieee.std_logic_1164.all;
|
20 |
|
|
library ieee;
|
21 |
|
|
use ieee.std_logic_1164.all;
|
22 |
|
|
use ieee.numeric_std.all;
|
23 |
|
|
library work;
|
24 |
|
|
use work.helpers.all;
|
25 |
|
|
use work.fpu_package.all;
|
26 |
|
|
-------------------------------------------------------------------------------
|
27 |
|
|
|
28 |
|
|
entity openFPU64_tb is
|
29 |
|
|
|
30 |
|
|
end openFPU64_tb;
|
31 |
|
|
|
32 |
|
|
-------------------------------------------------------------------------------
|
33 |
|
|
|
34 |
|
|
architecture openFPU64_tb of openFPU64_tb is
|
35 |
|
|
|
36 |
|
|
component openFPU64
|
37 |
|
|
port (
|
38 |
|
|
reset_n : in std_logic := '0';
|
39 |
|
|
read : in std_logic := '0';
|
40 |
|
|
write : in std_logic := '1';
|
41 |
|
|
address : in std_logic_vector (4 downto 0) := (others => '0');
|
42 |
|
|
readdata : out std_logic_vector(31 downto 0) := (others => '0');
|
43 |
|
|
writedata : in std_logic_vector(31 downto 0) := (others => '0');
|
44 |
|
|
waitrequest : out std_logic := '0';
|
45 |
|
|
begintransfer : in std_logic := '0';
|
46 |
|
|
-- out_port : out std_logic_vector(9 downto 0);
|
47 |
|
|
clk : in std_logic := '0');
|
48 |
|
|
end component;
|
49 |
|
|
|
50 |
|
|
-- component ports
|
51 |
|
|
signal reset_n : std_logic := '0';
|
52 |
|
|
signal read : std_logic := '0';
|
53 |
|
|
signal write : std_logic := '1';
|
54 |
|
|
signal address : std_logic_vector (4 downto 0) := (others => '0');
|
55 |
|
|
signal readdata : std_logic_vector(31 downto 0) := (others => '0');
|
56 |
|
|
signal writedata : std_logic_vector(31 downto 0) := (others => '0');
|
57 |
|
|
-- signal data_in_a : std_logic_vector(63 downto 0) := x"AFAFAFAFEFEFEFEF";
|
58 |
|
|
-- signal data_in_b : std_logic_vector(63 downto 0) := x"BFBFBFBFCFCFCFCF";
|
59 |
|
|
signal data_in_a : std_logic_vector(63 downto 0) := "0011111111110000000000000000000000000000000000000000000000000000";
|
60 |
|
|
signal data_in_b : std_logic_vector(63 downto 0) := "0100000000000000000000000000000000000000000000000000000000000000";
|
61 |
|
|
|
62 |
|
|
|
63 |
|
|
signal data_out : std_logic_vector(63 downto 0);
|
64 |
|
|
signal readback : std_logic_vector(31 downto 0) := (others => '0');
|
65 |
|
|
signal waitrequest : std_logic := '0';
|
66 |
|
|
signal begintransfer : std_logic := '0';
|
67 |
|
|
signal clk : std_logic := '0';
|
68 |
|
|
signal out_port : std_logic_vector(9 downto 0);
|
69 |
|
|
-- clock
|
70 |
|
|
-- signal Clk : std_logic := '1';
|
71 |
|
|
constant clk_period : time := 10 ns;
|
72 |
|
|
constant mem_delay : time := 10 ns;
|
73 |
|
|
begin -- openFPU64_tb
|
74 |
|
|
|
75 |
|
|
-- component instantiation
|
76 |
|
|
DUT : openFPU64
|
77 |
|
|
port map (
|
78 |
|
|
reset_n => reset_n,
|
79 |
|
|
read => read,
|
80 |
|
|
write => write,
|
81 |
|
|
address => address,
|
82 |
|
|
readdata => readdata,
|
83 |
|
|
writedata => writedata,
|
84 |
|
|
waitrequest => waitrequest,
|
85 |
|
|
begintransfer => begintransfer,
|
86 |
|
|
clk => clk);
|
87 |
|
|
|
88 |
|
|
-- clock generation
|
89 |
|
|
|
90 |
|
|
|
91 |
|
|
|
92 |
|
|
-- waveform generation
|
93 |
|
|
tb : process
|
94 |
|
|
procedure run_cycle
|
95 |
|
|
(
|
96 |
|
|
count : inout integer -- cycle count for statistical purposes
|
97 |
|
|
)
|
98 |
|
|
is
|
99 |
|
|
begin
|
100 |
|
|
clk <= '0';
|
101 |
|
|
wait for clk_period / 2;
|
102 |
|
|
clk <= '1';
|
103 |
|
|
wait for clk_period / 2;
|
104 |
|
|
count := count+1;
|
105 |
|
|
end procedure;
|
106 |
14 |
bro |
|
107 |
2 |
bro |
procedure testcase
|
108 |
|
|
(
|
109 |
|
|
number : in integer; -- Testcase number, will be reported
|
110 |
|
|
operand_a : in std_logic_vector(63 downto 0); -- first operand
|
111 |
|
|
operand_b : in std_logic_vector (63 downto 0); -- second operand
|
112 |
|
|
expected : in std_logic_vector(63 downto 0); -- expected result
|
113 |
|
|
operation : in std_logic_vector (2 downto 0) -- desired operation
|
114 |
|
|
)
|
115 |
|
|
is
|
116 |
|
|
variable i : integer;
|
117 |
|
|
variable denormalA_n : std_logic;
|
118 |
|
|
variable denormalB_n : std_logic;
|
119 |
|
|
begin
|
120 |
|
|
i :=0;
|
121 |
|
|
|
122 |
|
|
|
123 |
|
|
|
124 |
|
|
|
125 |
|
|
-- reset the fpu
|
126 |
|
|
begintransfer <= '0';
|
127 |
|
|
reset_n <= '0';
|
128 |
|
|
run_cycle(i);
|
129 |
|
|
reset_n <= '1';
|
130 |
|
|
run_cycle(i);
|
131 |
|
|
-- begin transfer of first 32bit (MSB..) of first operand
|
132 |
|
|
-- and specify operation (encoded in address, see fpu_package.vhd for details
|
133 |
|
|
write <= '1';
|
134 |
|
|
begintransfer <= '1';
|
135 |
|
|
writedata <= operand_a(63 downto 32);
|
136 |
|
|
address <= operation & addr_a_hi;
|
137 |
|
|
run_cycle(i);
|
138 |
|
|
begintransfer <= '0'; --all other signals irrelevant/unstable
|
139 |
|
|
run_cycle(i);
|
140 |
|
|
|
141 |
|
|
-- begin transfer of second 32bits (..LSB) of first operand
|
142 |
|
|
write <= '1';
|
143 |
|
|
begintransfer <= '1';
|
144 |
|
|
address <= operation& addr_a_lo;
|
145 |
|
|
writedata <= operand_a(31 downto 0);
|
146 |
|
|
run_cycle(i);
|
147 |
|
|
begintransfer <= '0';
|
148 |
|
|
run_cycle(i);
|
149 |
|
|
|
150 |
|
|
-- begin transfer of first 32bits (MSB..) of second operand
|
151 |
|
|
write <= '1';
|
152 |
|
|
address <= operation& addr_b_hi;
|
153 |
|
|
writedata <= operand_b(63 downto 32);
|
154 |
|
|
begintransfer <= '1';
|
155 |
|
|
run_cycle(i);
|
156 |
|
|
begintransfer <= '0';
|
157 |
|
|
run_cycle(i);
|
158 |
|
|
|
159 |
|
|
-- begin transfer of second 32bits (..LSB) of second operand
|
160 |
|
|
address <= operation& addr_b_lo;
|
161 |
|
|
writedata <= operand_b(31 downto 0);
|
162 |
|
|
begintransfer <= '1';
|
163 |
|
|
run_cycle(i);
|
164 |
|
|
begintransfer <= '0';
|
165 |
|
|
write <= '0';
|
166 |
|
|
run_cycle(i);
|
167 |
|
|
|
168 |
|
|
-- begin reading first 32bits of result
|
169 |
|
|
-- blocking read, all signals have to remain stable until waitrequest is deasserted
|
170 |
|
|
read <= '1';
|
171 |
|
|
begintransfer <= '1';
|
172 |
|
|
address <= operation & addr_result_hi;
|
173 |
|
|
run_cycle(i);
|
174 |
|
|
begintransfer <= '0';
|
175 |
|
|
L : while waitrequest = '1' loop
|
176 |
|
|
run_cycle(i);
|
177 |
|
|
end loop;
|
178 |
|
|
data_out(63 downto 32) <= readdata;
|
179 |
|
|
run_cycle(i);
|
180 |
|
|
|
181 |
|
|
-- begin reading second 32bits of result
|
182 |
|
|
-- blocking read, all signals have to remain stable until waitrequest is deasserted
|
183 |
|
|
-- in practice waitrequest is already deasserted.
|
184 |
|
|
read <= '1';
|
185 |
|
|
begintransfer <= '1';
|
186 |
|
|
address <= operation & addr_result_lo;
|
187 |
|
|
run_cycle(i);
|
188 |
|
|
begintransfer <= '0';
|
189 |
|
|
K :while waitrequest = '1' loop
|
190 |
|
|
run_cycle(i);
|
191 |
|
|
end loop;
|
192 |
|
|
data_out(31 downto 0) <= readdata;
|
193 |
|
|
run_cycle(i);
|
194 |
|
|
-- Bus transfers complete
|
195 |
|
|
|
196 |
|
|
-- compare actual result with expected result
|
197 |
14 |
bro |
if data_out /= expected
|
198 |
|
|
then
|
199 |
|
|
-- check if the _both_ expected and actual result is NaN,
|
200 |
|
|
-- if this is the case don't check the sign - NaNs don't have a sign
|
201 |
|
|
-- without this check false positives will be generated for NaNs with different signs.
|
202 |
|
|
if data_out(62 downto 52) = expected(62 downto 52)
|
203 |
|
|
and data_out(51 downto 0) = expected(51 downto 0)
|
204 |
|
|
and data_out(62 downto 52) = std_logic_vector(ONES(62 downto 52))
|
205 |
|
|
and data_out(51 downto 0) /= std_logic_vector(ZEROS(51 downto 0))
|
206 |
|
|
then
|
207 |
|
|
if DEBUG_MODE = '1' then -- if we are in DEBUG_MODE,print out the result anyway
|
208 |
|
|
assert false report "NaN:"&integer'image(number)&" result was"&
|
209 |
|
|
" S:"&std_logic'image(data_out(63)) &
|
210 |
|
|
" E:"&to_string(data_out(62 downto 52)) &
|
211 |
|
|
" M:"&to_string(data_out(51 downto 0)) &
|
212 |
|
|
" expected" &
|
213 |
|
|
" S:"&std_logic'image(expected(63)) &
|
214 |
|
|
" E:"&to_string(expected(62 downto 52)) &
|
215 |
|
|
" M:"&to_string(expected(51 downto 0)) severity error;
|
216 |
|
|
end if;
|
217 |
|
|
else
|
218 |
|
|
-- if we reach here, we have a real error - printout the actual and the expected result
|
219 |
|
|
assert false report "doh "&integer'image(number)&" result was"&
|
220 |
|
|
" S:"&std_logic'image(data_out(63)) &
|
221 |
|
|
" E:"&to_string(data_out(62 downto 52)) &
|
222 |
|
|
" M:"&to_string(data_out(51 downto 0)) &
|
223 |
|
|
" expected" &
|
224 |
|
|
" S:"&std_logic'image(expected(63)) &
|
225 |
|
|
" E:"&to_string(expected(62 downto 52)) &
|
226 |
|
|
" M:"&to_string(expected(51 downto 0)) severity error;
|
227 |
|
|
end if;
|
228 |
|
|
end if;
|
229 |
2 |
bro |
-- print out statistics
|
230 |
|
|
assert false report "Testcases "&integer'image(number)&" needed " &integer'image(i) &" cycles" severity note;
|
231 |
|
|
end procedure;
|
232 |
|
|
variable i : integer;
|
233 |
|
|
begin
|