1 -------------------------------------------------------------------------------
3 -- Project: <Floating Point Unit Core>
5 -- Description: test bench for the FPU core
6 -------------------------------------------------------------------------------
8 -- 100101011010011100100
9 -- 110000111011100100000
10 -- 100000111011000101101
11 -- 100010111100101111001
12 -- 110000111011101101001
13 -- 010000001011101001010
14 -- 110100111001001100001
15 -- 110111010000001100111
16 -- 110110111110001011101
17 -- 101110110010111101000
18 -- 100000010111000000000
20 -- Author: Jidan Al-eryani
25 -- This source file may be used and distributed without
26 -- restriction provided that this copyright statement is not
27 -- removed from the file and that any derivative work contains
28 -- the original copyright notice and the associated disclaimer.
30 -- THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY
31 -- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
32 -- TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
33 -- FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR
34 -- OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
35 -- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
36 -- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
37 -- GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
38 -- BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
39 -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
40 -- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
41 -- OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 -- POSSIBILITY OF SUCH DAMAGE.
46 use ieee.std_logic_1164.all;
47 use ieee.std_logic_unsigned.all;
48 use ieee.math_real.all;
49 use ieee.std_logic_arith.all;
50 use ieee.std_logic_misc.all;
52 use work.txt_util.all;
54 -- fpu operations (fpu_op_i):
55 -- ========================
67 -- 00 = round to nearest even(default),
68 -- 01 = round to zero,
76 architecture rtl of tb_fpu is
81 opa_i : in std_logic_vector(31 downto 0);
82 opb_i : in std_logic_vector(31 downto 0);
83 fpu_op_i : in std_logic_vector(2 downto 0);
84 rmode_i : in std_logic_vector(1 downto 0);
85 output_o : out std_logic_vector(31 downto 0);
86 ine_o : out std_logic;
87 overflow_o : out std_logic;
88 underflow_o : out std_logic;
89 div_zero_o : out std_logic;
90 inf_o : out std_logic;
91 zero_o : out std_logic;
92 qnan_o : out std_logic;
93 snan_o : out std_logic;
94 start_i : in std_logic;
95 ready_o : out std_logic
100 signal clk_i : std_logic:= '1';
101 signal opa_i, opb_i : std_logic_vector(31 downto 0);
102 signal fpu_op_i : std_logic_vector(2 downto 0);
103 signal rmode_i : std_logic_vector(1 downto 0);
104 signal output_o : std_logic_vector(31 downto 0);
105 signal start_i, ready_o : std_logic ;
106 signal ine_o, overflow_o, underflow_o, div_zero_o, inf_o, zero_o, qnan_o, snan_o: std_logic;
110 signal slv_out : std_logic_vector(31 downto 0);
112 constant CLK_PERIOD :time := 10 ns; -- period of clk period
118 i_fpu: fpu port map (
122 fpu_op_i => fpu_op_i,
124 output_o => output_o,
126 overflow_o => overflow_o,
127 underflow_o => underflow_o,
128 div_zero_o => div_zero_o,
137 ---------------------------------------------------------------------------
139 ---------------------------------------------------------------------------
140 clk_i <= not(clk_i) after 5 ns;
144 --The operands and results are in Hex format. The test vectors must be placed in a strict order for the verfication to work.
145 file testcases_file: TEXT open read_mode is "testcases.txt"; --Name of the file containing the test cases.
147 variable file_line: line;
148 variable str_in: string(8 downto 1);
149 variable str_fpu_op: string(3 downto 1);
150 variable str_rmode: string(2 downto 1);
154 ---------------------------------------------------------------------------------------------------------------------------------------------------
155 ---------------------------------------------------SoftFloat test vectors (10000 test cases for each operation) --------------------------------------------------------------------
157 while not endfile(testcases_file) loop
159 wait for CLK_PERIOD; start_i <= '1';
161 str_read(testcases_file,str_in);
162 opa_i <= strhex_to_slv(str_in);
164 str_read(testcases_file,str_in);
165 opb_i <= strhex_to_slv(str_in);
167 str_read(testcases_file,str_fpu_op);
168 fpu_op_i <= to_std_logic_vector(str_fpu_op);
170 str_read(testcases_file,str_rmode);
171 rmode_i <= to_std_logic_vector(str_rmode);
173 str_read(testcases_file,str_in);
174 slv_out <= strhex_to_slv(str_in);
176 wait for CLK_PERIOD; start_i <= '0'; wait until ready_o='1';
178 assert output_o = slv_out
181 str_read(testcases_file,str_in);
185 -------- Boundary values-----
188 -- seeeeeeeefffffffffffffffffffffff
190 wait for CLK_PERIOD; start_i <= '1';
191 opa_i <= "01111111011111111111111111111111";
192 opb_i <= "01111111011111111111111111111111";
195 wait for CLK_PERIOD; start_i <= '0'; wait until ready_o='1';
196 assert output_o="01111111100000000000000000000000"
200 -- seeeeeeeefffffffffffffffffffffff
201 -- 1 x1.001 - 1x1.000 = 0x0.001
202 wait for CLK_PERIOD; start_i <= '1';
203 opa_i <= "00000000100100000000000000000000";
204 opb_i <= "10000000100000000000000000000000";
207 wait for CLK_PERIOD; start_i <= '0'; wait until ready_o='1';
208 assert output_o="00000000000100000000000000000000"
212 -- seeeeeeeefffffffffffffffffffffff
213 -- 10 x 1.0001 - 10 x 1.0000 =
214 wait for CLK_PERIOD; start_i <= '1';
215 opa_i <= "00000001000010000000000000000000";
216 opb_i <= "10000001000000000000000000000000";
219 wait for CLK_PERIOD; start_i <= '0'; wait until ready_o='1';
220 assert output_o="00000000000100000000000000000000"
225 -- seeeeeeeefffffffffffffffffffffff
227 wait for CLK_PERIOD; start_i <= '1';
228 opa_i <= "10000000000000000000000000000000";
229 opb_i <= "10000000000000000000000000000000";
232 wait for CLK_PERIOD; start_i <= '0'; wait until ready_o='1';
233 assert output_o="10000000000000000000000000000000"
237 -- seeeeeeeefffffffffffffffffffffff
239 wait for CLK_PERIOD; start_i <= '1';
240 opa_i <= "00000000000000000000000000000000";
241 opb_i <= "01000010001000001000000000100000";
244 wait for CLK_PERIOD; start_i <= '0'; wait until ready_o='1';
245 assert output_o="01000010001000001000000000100000"
250 ----------------------------------------------------------------------------------------------------------------------------------------------------
252 report "Success!!!.......Yahoooooooooooooo"