parser: erste gehversuche. im moment wird die eingabe einfach zurueckgegeben zur...
[hwmod.git] / src / beh_alu_tb.vhd
1 library ieee;
2 use ieee.std_logic_1164.all;
3 use ieee.numeric_std.all;
4 use work.gen_pkg.all;
5
6 entity beh_alu_tb is
7 end entity beh_alu_tb;
8
9 architecture sim of beh_alu_tb is
10         signal sys_clk, sys_res_n, do_calc, calc_done : std_logic;
11         signal opcode : alu_ops;
12         signal op1, op2, op3 : csigned;
13         signal stop : boolean := false;
14 begin
15         inst : entity work.alu(beh)
16         port map
17         (
18                 sys_clk => sys_clk,
19                 sys_res_n => sys_res_n,
20                 do_calc => do_calc,
21                 calc_done => calc_done,
22                 op1 => op1,
23                 op2 => op2,
24                 op3 => op3,
25                 opcode => opcode
26         );
27
28         process
29         begin
30                 sys_clk <= '0';
31                 wait for 15 ns;
32                 sys_clk <= '1';
33                 wait for 15 ns;
34                 if stop = true then
35                         wait;
36                 end if;
37         end process;
38
39         process
40                 type alu_testv is record
41                         o1 : cinteger;
42                         o : alu_ops;
43                         o2 : cinteger;
44                         expected : cinteger;
45                 end record alu_testv;
46
47                 -- ggf. groesse des arrays erhoehen
48                 type alu_testv_array is array (natural range 0 to 30) of alu_testv;
49
50                 variable testmatrix : alu_testv_array :=
51                         ( 0 => (-5, ALU_DIV, 3, -1),
52                           1 => (7, ALU_ADD, 3, 10),
53                           2 => (7, ALU_SUB, 1, 6),
54                           3 => (7, ALU_DIV, 1, 7),
55                           4 => (7, ALU_DIV, 3, 2),
56                           5 => (7, ALU_ADD, 1, 8),
57                           6 => (7, ALU_MUL, 3, 21),
58                           7 => (-7, ALU_MUL, 3, -21),
59                           8 => (268435456, ALU_MUL, -2, -536870912),
60                           9 => (268435456, ALU_MUL, 2**5, 0), -- um fuenf nach links shiften
61                           10 => (268435456 + 5, ALU_MUL, 2**5, 160), -- = 5 * (2^5)
62                           11 => (100, ALU_DIV, 10, 10),
63                           12 => (100, ALU_DIV, 51, 1),
64                           13 => (100, ALU_DIV, 49, 2),
65                           14 => (153156, ALU_DIV, 3543, 43),
66                           15 => (-153156, ALU_DIV, 3543, -43),
67                           16 => (153156, ALU_DIV, -3543, -43),
68                           17 => (-153156, ALU_DIV, -3543, 43),
69                           others => (0, ALU_ADD, 0, 0)
70                         );
71                 variable checkall : boolean := true;
72         begin
73                 -- init & reset
74                 sys_res_n <= '0';
75                 do_calc <= '0';
76                 opcode <= ALU_NOP;
77                 op1 <= (others => '0');
78                 op2 <= (others => '0');
79
80                 icwait(sys_clk, 30);
81                 sys_res_n <= '1';
82
83                 for i in testmatrix'range loop
84                         icwait(sys_clk, 10);
85                         op1 <= to_signed(testmatrix(i).o1,CBITS);
86                         opcode <= testmatrix(i).o;
87                         op2 <= to_signed(testmatrix(i).o2,CBITS);
88
89                         -- berechnung kann los gehen
90                         do_calc <= '1';
91
92                         -- warten auf die alu einheit
93                         wait on calc_done;
94                         icwait(sys_clk, 1);
95
96                         assert op3 = to_signed(testmatrix(i).expected,CBITS)
97                                 report "" & cinteger'image(testmatrix(i).o1) & 
98                                 " " & integer'image(to_integer(signed(opcode))) &
99                                 " " & cinteger'image(testmatrix(i).o2) &
100                                 "/= " & integer'image(to_integer(op3)) &
101                                 " -- erwartet: " & cinteger'image(testmatrix(i).expected);
102
103                         if op3 /= to_signed(testmatrix(i).expected,CBITS) then
104                                 checkall := false;
105                         end if;
106
107                         icwait(sys_clk, 2);
108                         -- ack it!
109                         do_calc <= '0';
110                 end loop;
111
112                 if checkall then
113                         report "alle testfaelle der ALU waren erfolgreich!";
114                 else
115                         report "nicht alle testfaelle der ALU waren erfolgreich!";
116                 end if;
117                 stop <= true;
118                 wait;
119         end process;
120 end architecture sim;