OpenCores
URL https://opencores.org/ocsvn/fpu100/fpu100/trunk

Subversion Repositories fpu100

[/] [fpu100/] [branches/] [avendor/] [test_bench/] [tb_fpu.vhd] - Blame information for rev 6

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 jidan
-------------------------------------------------------------------------------
2
--
3
-- Project:     <Floating Point Unit Core>
4
--      
5
-- Description: test bench for the FPU core
6
-------------------------------------------------------------------------------
7
--
8
--                              100101011010011100100
9
--                              110000111011100100000
10
--                              100000111011000101101
11
--                              100010111100101111001
12
--                              110000111011101101001
13
--                              010000001011101001010
14
--                              110100111001001100001
15
--                              110111010000001100111
16
--                              110110111110001011101
17
--                              101110110010111101000
18
--                              100000010111000000000
19
--
20
--      Author:          Jidan Al-eryani 
21
--      E-mail:          jidan@gmx.net
22
--
23
--  Copyright (C) 2006
24
--
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.
29
--                                                           
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. 
43
--
44
 
45
library ieee;
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;
51 6 jidan
use std.textio.all;
52
use work.txt_util.all;
53 2 jidan
 
54 6 jidan
        -- fpu operations (fpu_op_i):
55
                -- ========================
56
                -- 000 = add, 
57
                -- 001 = substract, 
58
                -- 010 = multiply, 
59
                -- 011 = divide,
60
                -- 100 = square root
61
                -- 101 = unused
62
                -- 110 = unused
63
                -- 111 = unused
64
 
65
        -- Rounding Mode: 
66
        -- ==============
67
        -- 00 = round to nearest even(default), 
68
        -- 01 = round to zero, 
69
        -- 10 = round up, 
70
        -- 11 = round down
71 2 jidan
 
72
 
73
entity tb_fpu is
74
end tb_fpu;
75
 
76
architecture rtl of tb_fpu is
77
 
78
component fpu
79
    port (
80
        clk_i           : in std_logic;
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
96
        );
97
end component;
98
 
99
 
100
signal clk_i : std_logic:= '0';
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;
107
 
108
 
109 6 jidan
 
110
signal slv_out : std_logic_vector(31 downto 0);
111
 
112 2 jidan
constant CLK_PERIOD :time := 10 ns; -- period of clk period
113
 
114 6 jidan
 
115 2 jidan
begin
116
 
117 6 jidan
    -- instantiate fpu
118 2 jidan
    i_fpu: fpu port map (
119
                        clk_i => clk_i,
120
                        opa_i => opa_i,
121
                        opb_i => opb_i,
122
                        fpu_op_i =>     fpu_op_i,
123
                        rmode_i => rmode_i,
124
                        output_o => output_o,
125
                        ine_o => ine_o,
126
                        overflow_o => overflow_o,
127
                        underflow_o => underflow_o,
128
                div_zero_o => div_zero_o,
129
                inf_o => inf_o,
130
                zero_o => zero_o,
131
                qnan_o => qnan_o,
132
                snan_o => snan_o,
133
                start_i => start_i,
134
                ready_o => ready_o);
135
 
136
 
137
    ---------------------------------------------------------------------------
138
    -- toggle clock
139
    ---------------------------------------------------------------------------
140
    clk_i <= not(clk_i) after 5 ns;
141
 
142
 
143 6 jidan
    verify : process
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. 
146
 
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);
151 2 jidan
    begin
152
 
153
 
154 6 jidan
                ---------------------------------------------------------------------------------------------------------------------------------------------------
155
                ---------------------------------------------------SoftFloat test vectors (10000 test cases for each operation) --------------------------------------------------------------------
156 2 jidan
 
157 6 jidan
                while not endfile(testcases_file) loop
158 2 jidan
 
159 6 jidan
                        wait for CLK_PERIOD; start_i <= '1';
160 2 jidan
 
161 6 jidan
                        str_read(testcases_file,str_in);
162
                        opa_i <= strhex_to_slv(str_in);
163 2 jidan
 
164 6 jidan
                        str_read(testcases_file,str_in);
165
                        opb_i <= strhex_to_slv(str_in);
166 2 jidan
 
167 6 jidan
                        str_read(testcases_file,str_fpu_op);
168
                        fpu_op_i <= to_std_logic_vector(str_fpu_op);
169 2 jidan
 
170 6 jidan
                        str_read(testcases_file,str_rmode);
171
                        rmode_i <= to_std_logic_vector(str_rmode);
172 2 jidan
 
173 6 jidan
                        str_read(testcases_file,str_in);
174
                        slv_out <= strhex_to_slv(str_in);
175 2 jidan
 
176
                        wait for CLK_PERIOD; start_i <= '0'; wait until ready_o='1';
177
 
178 6 jidan
                        assert output_o = slv_out
179 2 jidan
                        report "Error!!!"
180
                        severity failure;
181 6 jidan
                        str_read(testcases_file,str_in);
182 2 jidan
 
183 6 jidan
                end loop;
184 2 jidan
 
185
 
186
 
187 6 jidan
                ----------------------------------------------------------------------------------------------------------------------------------------------------
188
                assert false
189
                report "Success!!!.......Yahoooooooooooooo"
190
                severity failure;
191 2 jidan
 
192
        wait;
193
 
194
    end process verify;
195
 
196
end rtl;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.