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

Subversion Repositories igor

[/] [igor/] [trunk/] [processor/] [mc/] [divider_tb.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 atypic
-- ==============================================================================
2
-- Generic signed/unsigned restoring divider Testbench 
3
-- 
4
-- This library is free software; you can redistribute it and/or modify it 
5
-- under the terms of the GNU Lesser General Public License as published 
6
-- by the Free Software Foundation; either version 2.1 of the License, or 
7
-- (at your option) any later version.
8
-- 
9
-- This library is distributed in the hope that it will be useful, but WITHOUT
10
-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
-- FITNESS FOR A PARTICULAR PURPOSE.   See the GNU Lesser General Public 
12
-- License for more details.   See http://www.gnu.org/copyleft/lesser.txt
13
-- 
14
-- ------------------------------------------------------------------------------
15
-- Version   Author          Date          Changes
16
-- 0.1       Hans Tiggeler   07/18/02      Tested on Modelsim SE 5.6
17
-- ==============================================================================
18
 
19
library ieee;
20
use ieee.std_logic_1164.all;
21
use ieee.std_logic_arith.all;
22
use ieee.std_logic_unsigned.all;
23
 
24
entity divider_tb is
25
generic (width_divider : integer := 8;
26
         width_divisor : integer := 8);
27
end entity divider_tb;
28
 
29
architecture rtl of divider_tb is
30
 
31
component divider is
32
    generic (width_divid : integer := 4;
33
             width_divis : integer := 4);
34
    port (      dividend  : in   std_logic_vector (width_divid-1 downto 0);
35
                divisor   : in     std_logic_vector (width_divis-1 downto 0);
36
                quotient  : out    std_logic_vector (width_divid-1 downto 0);
37
                remainder : out    std_logic_vector (width_divis-1 downto 0);
38
                twocomp   : in     std_logic);                    -- '1'=2's complement, '0'=unsigned
39
end component divider;
40
 
41
 
42
signal dividend_s  :  std_logic_vector (width_divider-1 downto 0);
43
signal divisor_s   :  std_logic_vector (width_divisor-1 downto 0);
44
signal quotient_s  :  std_logic_vector (width_divider-1 downto 0);
45
signal remainder_s :  std_logic_vector (width_divisor-1 downto 0);
46
signal twocomp_s   :  std_logic;
47
 
48
signal q_s  : integer;
49
signal r_s  : integer;
50
 
51
 
52
begin
53
    dut : divider
54
                generic map (width_divid =>  width_divider,
55
                             width_divis =>  width_divisor)
56
                port map (dividend  => dividend_s,
57
                          divisor   => divisor_s,
58
                          quotient  => quotient_s,
59
                          remainder => remainder_s,
60
                          twocomp   => twocomp_s);
61
 
62
process
63
        begin
64
                twocomp_s  <= '0';
65
                dividend_s <= (others => '0');
66
                divisor_s  <= (others => '1');
67
                wait for 20 ns;
68
 
69
                for twocomp_v in 0 to 1 loop
70
                        if twocomp_v=0 then
71
                                twocomp_s<= '0';report "**** Testing Unsigned Divider ****";
72
                        else
73
                                twocomp_s<= '1';report "**** Testing Signed Divider ****";
74
                        end if;
75
                        for i in 0 to (2 ** width_divider - 1) loop
76
                                for j in 1 to (2 ** width_divisor - 1) loop
77
                                        dividend_s <= conv_std_logic_vector(i,width_divider);
78
                                        divisor_s  <= conv_std_logic_vector(j,width_divisor);
79
 
80
                                        wait for 10 ns;
81
                                        if twocomp_s='1' then
82
                                                q_s <=conv_integer(signed(dividend_s)) /   conv_integer(signed(divisor_s));
83
                                                r_s <=conv_integer(signed(dividend_s)) rem conv_integer(signed(divisor_s));
84
                                                wait for 1 ns;
85
                                                if (q_s <= (2**(width_divider-1)-1)) then         -- check for overflow -2^(n-1) .. 2^(n-1)-1
86
                                                        assert (q_s=conv_integer(signed(quotient_s)))  report "Signed quotient failure" severity note;
87
                                                        assert (r_s=conv_integer(signed(remainder_s))) report "Signed remainder failure" severity note;
88
                                                else
89
                                                        report "Overflow, Signed divide skipped";
90
                                                end if;
91
                                        else
92
                                                q_s <=conv_integer(dividend_s) /   conv_integer(divisor_s);
93
                                                r_s <=conv_integer(dividend_s) rem conv_integer(divisor_s);
94
                                                wait for 1 ns;
95
                                                assert (q_s=conv_integer(quotient_s))  report "Unsigned quotient failure" severity note;
96
                                                assert (r_s=conv_integer(remainder_s)) report "Unsigned remainder failure" severity note;
97
                                        end if;
98
                                        wait for 10 ns;
99
                                end loop;
100
                        end loop;
101
                end loop;
102
 
103
                assert (false) report " end of sim" severity failure;
104
 end process;
105
 
106
 
107
end architecture rtl;

powered by: WebSVN 2.1.0

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