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

Subversion Repositories distributed_intelligence

[/] [distributed_intelligence/] [trunk/] [BENCH/] [tb_add_sub_x16.vhd] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 leoel
--------------------------------------------------------------------------------
2
-- Company: 
3
-- Engineer: Léo Germond
4
--
5
-- Create Date:   17:35:34 11/07/2009
6
-- Design Name:   
7
-- Module Name:   C:/Users/microcon/tb_add_sub_x16.vhd
8
-- Project Name:  microcon
9
-- Target Device:  
10
-- Tool versions:  
11
-- Description:   
12
-- 
13
-- VHDL Test Bench Created by ISE for module: add_sub_x16
14
-- 
15
-- Dependencies:
16
-- 
17
-- Revision:
18
-- Revision 0.01 - File Created
19
-- Additional Comments:
20
--
21
-- Notes: 
22
-- This testbench has been automatically generated using types std_logic and
23
-- std_logic_vector for the ports of the unit under test.  Xilinx recommends
24
-- that these types always be used for the top-level I/O of a design in order
25
-- to guarantee that the testbench will bind correctly to the post-implementation 
26
-- simulation model.
27
--------------------------------------------------------------------------------
28
LIBRARY ieee;
29
USE ieee.std_logic_1164.ALL;
30
USE ieee.std_logic_unsigned.all;
31
USE ieee.numeric_std.ALL;
32
use work.UnitTest.ALL;
33
 
34
ENTITY tb_add_sub_x16 IS
35
END tb_add_sub_x16;
36
 
37
ARCHITECTURE behavior OF tb_add_sub_x16 IS
38
 
39
    -- Component Declaration for the Unit Under Test (UUT)
40
 
41
    COMPONENT add_sub_x16
42
    PORT(
43
         dataA : IN  std_logic_vector(15 downto 0);
44
         dataB : IN  std_logic_vector(15 downto 0);
45
         sum : OUT  std_logic_vector(15 downto 0);
46
         is_signed : IN  std_logic;
47
         is_sub : IN  std_logic;
48
         overflow : OUT  std_logic
49
        );
50
    END COMPONENT;
51
 
52
 
53
   --Inputs
54
   signal dataA : std_logic_vector(15 downto 0) := (others => '0');
55
   signal dataB : std_logic_vector(15 downto 0) := (others => '0');
56
   signal is_signed : std_logic := '0';
57
   signal is_sub : std_logic := '0';
58
 
59
        --Outputs
60
   signal sum : std_logic_vector(15 downto 0);
61
   signal overflow : std_logic;
62
 
63
        constant MAX_SIGNED:integer := (2**15)-1;
64
        constant MIN_SIGNED:integer := -(2**15);
65
 
66
        constant MAX_UNSIGNED:integer := (2**16)-1;
67
BEGIN
68
 
69
 
70
        -- Instantiate the Unit Under Test (UUT)
71
   uut: add_sub_x16 PORT MAP (
72
          dataA => dataA,
73
          dataB => dataB,
74
          sum => sum,
75
          is_signed => is_signed,
76
          is_sub => is_sub,
77
          overflow => overflow
78
        );
79
 
80
   -- Stimulus process
81
   stim_proc: process
82
 
83
                procedure testAdd(A, B: in integer; argSigne: in std_logic := '-'; delay : in time := 50 ns) is
84
                        variable signe: std_logic;
85
                begin
86
                        -- Préparation des entrées
87
                        if argSigne = '-' then -- On fixe le signe si ca n'a pas déja été fait
88
                                if(A < 0 or B < 0) then
89
                                        signe := '1';
90
                                else
91
                                        signe := '0';
92
                                end if;
93
                        else
94
                                signe := argSigne;
95
                        end if;
96
 
97
                        is_sub <= '0';
98
                        is_signed <= signe;
99
 
100
                        if signe = '1' then
101
                                dataA <= std_logic_vector(to_signed(A, 16));
102
                                dataB <= std_logic_vector(to_signed(B, 16));
103
                        else
104
                                dataA <= std_logic_vector(to_unsigned(A, 16));
105
                                dataB <= std_logic_vector(to_unsigned(B, 16));
106
                        end if;
107
 
108
                        -- Délai d'attente
109
                        wait for delay;
110
 
111
                        -- Vérification du résultat
112
                        if signe = '1' then -- Opération signée
113
                                assertOperationResult(to_integer(signed(sum)), A+B, "signed sum",A+B > MAX_SIGNED or A+B < MIN_SIGNED, overflow);
114
                        else -- Opération non signée
115
                                assertOperationResult(to_integer(unsigned(sum)), A+B, "unsigned sum",A+B > MAX_UNSIGNED or A+B < 0, overflow);
116
                        end if;
117
                end procedure;
118
 
119
                procedure testSub(A, B: in integer; argSigne: in std_logic := '-'; delay : in time := 50 ns) is
120
                        variable signe: std_logic;
121
                begin
122
                        -- Préparation des entrées
123
                        if argSigne = '-' then -- On fixe le signe si ca n'a pas déja été fait
124
                                if(A < 0 or B < 0) then
125
                                        signe := '1';
126
                                else
127
                                        signe := '0';
128
                                end if;
129
                        else
130
                                signe := argSigne;
131
                        end if;
132
 
133
                        is_sub <= '1';
134
                        is_signed <= signe;
135
 
136
                        if signe = '1' then
137
                                dataA <= std_logic_vector(to_signed(A, 16));
138
                                dataB <= std_logic_vector(to_signed(B, 16));
139
                        else
140
                                dataA <= std_logic_vector(to_unsigned(A, 16));
141
                                dataB <= std_logic_vector(to_unsigned(B, 16));
142
                        end if;
143
 
144
                        -- Délai d'attente
145
                        wait for delay;
146
 
147
                        -- Vérification du résultat
148
                        if signe = '1' then -- Opération signée
149
                                assertOperationResult(to_integer(signed(sum)), A-B, "signed subtraction", A-B > MAX_SIGNED or A-B < MIN_SIGNED, overflow);
150
                        else -- Opération non signée
151
                                assertOperationResult(to_integer(unsigned(sum)), A-B, "unsigned subtraction", A-B > MAX_UNSIGNED or A-B < 0, overflow);
152
                        end if;
153
                end procedure;
154
 
155
   begin
156
                -- Additions non signées sans overflow
157
                testAdd(10,15);
158
                testAdd(5,0);
159
                testAdd(2,30);
160
                testAdd(MAX_UNSIGNED, 0);
161
                testAdd(MAX_UNSIGNED-15, 15);
162
 
163
                -- Additions signées sans overflow
164
                testAdd(0,-10);
165
                testAdd(10,-10);
166
                testAdd(11,-10);
167
                testAdd(MAX_SIGNED, MIN_SIGNED);
168
 
169
                -- Additions avec overflow
170
                testAdd(MAX_UNSIGNED,1);
171
                testAdd(MAX_UNSIGNED,MAX_UNSIGNED);
172
 
173
                testAdd(MAX_SIGNED,MAX_SIGNED, '1');
174
                testAdd(MIN_SIGNED, -1);
175
                testAdd(MIN_SIGNED,MIN_SIGNED);
176
 
177
 
178
                -- Additions non signées sans overflow
179
                testSub(10,9);
180
                testSub(5,0);
181
                testSub(2,30);
182
                testSub(MAX_UNSIGNED, 0);
183
                testSub(MAX_UNSIGNED-15, 15);
184
 
185
                -- Additions signées sans overflow
186
                testSub(0,-10);
187
                testSub(10,-10);
188
                testSub(11,-10);
189
                testSub(MAX_SIGNED, MIN_SIGNED);
190
                testSub(MIN_SIGNED, -1);
191
 
192
                -- Additions avec overflow
193
                testSub(MAX_UNSIGNED,1);
194
                testSub(MAX_UNSIGNED,MAX_UNSIGNED);
195
 
196
                testSub(MAX_SIGNED,MAX_SIGNED, '1');
197
                testSub(MIN_SIGNED,MIN_SIGNED);
198
      wait;
199
   end process;
200
 
201
 
202
END;

powered by: WebSVN 2.1.0

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