2 use ieee.std_logic_1164.all;
3 use ieee.numeric_std.all;
7 end entity post_alu_tb;
9 architecture sim of post_alu_tb is
13 sys_clk : in std_logic;
14 sys_res_n : in std_logic;
15 \opcode.NOP\ : in std_logic;
16 \opcode.SUB\ : in std_logic;
17 \opcode.ADD\ : in std_logic;
18 \opcode.MUL\ : in std_logic;
19 \opcode.DIV\ : in std_logic;
20 \opcode.DONE\ : in std_logic;
21 op1 : in std_logic_vector(31 downto 0);
22 op2 : in std_logic_vector(31 downto 0);
23 op3 : out std_logic_vector(31 downto 0);
24 do_calc : in std_logic;
25 calc_done : out std_logic
29 signal sys_clk, sys_res_n, do_calc, calc_done : std_logic;
30 signal opcode : alu_ops;
31 signal \opcode.NOP\ : std_logic;
32 signal \opcode.SUB\ : std_logic;
33 signal \opcode.ADD\ : std_logic;
34 signal \opcode.MUL\ : std_logic;
35 signal \opcode.DIV\ : std_logic;
36 signal \opcode.DONE\ : std_logic;
37 signal op1, op2, op3 : std_logic_vector(31 downto 0);
38 signal stop : boolean := false;
44 sys_res_n => sys_res_n,
46 calc_done => calc_done,
50 \opcode.NOP\ => \opcode.NOP\,
51 \opcode.SUB\ => \opcode.SUB\,
52 \opcode.ADD\ => \opcode.ADD\,
53 \opcode.MUL\ => \opcode.MUL\,
54 \opcode.DIV\ => \opcode.DIV\,
55 \opcode.DONE\ => \opcode.DONE\
70 type alu_testv is record
77 -- ggf. groesse des arrays erhoehen
78 type alu_testv_array is array (natural range 0 to 20) of alu_testv;
80 variable testmatrix : alu_testv_array :=
81 ( 0 => (-5, DIV, 3, -1),
88 7 => (-7, MUL, 3, -21),
89 8 => (268435456, MUL, -2, -536870912),
90 9 => (268435456, MUL, 2**5, 0), -- um fuenf nach links shiften
91 10 => (268435456 + 5, MUL, 2**5, 160), -- = 5 * (2^5)
92 11 => (100, DIV, 10, 10),
93 12 => (100, DIV, 51, 1),
94 13 => (100, DIV, 49, 2),
95 14 => (153156, DIV, 3543, 43),
96 15 => (-153156, DIV, 3543, -43),
97 16 => (153156, DIV, -3543, -43),
98 17 => (-153156, DIV, -3543, 43),
99 others => (0, ADD, 0, 0)
107 for i in testmatrix'range loop
114 \opcode.DONE\ <= '0';
115 op1 <= std_logic_vector(to_signed(testmatrix(i).o1,CBITS));
116 case testmatrix(i).o is
117 when NOP => \opcode.NOP\ <= '1';
118 when SUB => \opcode.SUB\ <= '1';
119 when ADD => \opcode.ADD\ <= '1';
120 when MUL => \opcode.MUL\ <= '1';
121 when DIV => \opcode.DIV\ <= '1';
122 when DONE => \opcode.DONE\ <= '1';
124 op2 <= std_logic_vector(to_signed(testmatrix(i).o2,CBITS));
126 -- berechnung kann los gehen
129 -- warten auf die alu einheit
132 assert op3 = std_logic_vector(to_signed(testmatrix(i).expected,CBITS))
133 report "" & cinteger'image(testmatrix(i).o1) &
134 " " & alu_ops'image(opcode) &
135 " " & cinteger'image(testmatrix(i).o2) &
136 "/= " & integer'image(to_integer(signed(op3))) &
137 " -- erwartet: " & cinteger'image(testmatrix(i).expected);
145 report "alle testfaelle der ALU waren erfolgreich!";
149 end architecture sim;