summaryrefslogtreecommitdiff
path: root/testsuite/vests/vhdl-ams/ashenden/compliant/packages/test_alu.vhd
blob: 3ed4d1aacd79f2a816c316f3124224577362eb98 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101

-- Copyright (C) 2002 Morgan Kaufmann Publishers, Inc

-- This file is part of VESTs (Vhdl tESTs).

-- VESTs is free software; you can redistribute it and/or modify it
-- under the terms of the GNU General Public License as published by the
-- Free Software Foundation; either version 2 of the License, or (at
-- your option) any later version. 

-- VESTs is distributed in the hope that it will be useful, but WITHOUT
-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-- FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-- for more details. 

-- You should have received a copy of the GNU General Public License
-- along with VESTs; if not, write to the Free Software Foundation,
-- Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 

library ieee;

package alu_types is

  -- code from book (in text)

  use ieee.numeric_bit.all;
  subtype ALU_func is unsigned(3 downto 0);
  subtype data_word is unsigned(15 downto 0);
  -- . . .

  -- end code from book (in text)

end package alu_types;



use work.alu_types.all;

-- code from book (in text)

entity ALU is
  port ( a, b : in data_word;  func : in ALU_func;
         result : out data_word;  carry : out bit );
end entity ALU;

-- end code from book (in text)



architecture structural of ALU is
begin
end architecture structural;


entity test_ALU is
end entity test_ALU;



library ieee;
use work.alu_types.all;

-- code from book

architecture random_test of test_ALU is

  use ieee.numeric_bit.all;
  use ieee.math_real.uniform;

  signal a, b, result : data_word;
  signal func : ALU_func;
  signal carry : bit;

begin

  dut : entity work.ALU(structural)
    port map ( a, b, func, result, carry );

  stimulus : process is
    variable seed1, seed2 : positive := 1;
    variable a_real, b_real, func_real : real;
  begin
    wait for 100 ns;
    uniform ( seed1, seed2, a_real );
    uniform ( seed1, seed2, b_real );
    uniform ( seed1, seed2, func_real );
    a <= to_unsigned( natural(a_real * real(2**integer'(data_word'length)) - 0.5),
                      data_word'length );
    b <= to_unsigned( natural(b_real * real(2**integer'(data_word'length)) - 0.5),
                      data_word'length );
    func <= to_unsigned( natural(func_real
                                 * real(2**integer'(ALU_func'length)) - 0.5),
                         ALU_func'length );
  end process stimulus;

  -- . . .  --verification process to check result and carry

end architecture random_test;

-- end code from book