2 context vunit_lib.vunit_context;
5 use ieee.std_logic_1164.all;
6 use ieee.numeric_std.all;
9 use work.decode_types.all;
11 use work.ppc_fx_insns.all;
14 use osvvm.RandomPkg.all;
17 generic (runner_cfg : string := runner_cfg_default);
20 architecture behave of multiply_tb is
21 signal clk : std_ulogic;
22 constant clk_period : time := 10 ns;
24 constant pipeline_depth : integer := 4;
26 signal m1 : MultiplyInputType := MultiplyInputInit;
27 signal m2 : MultiplyOutputType;
30 multiply_0: entity work.multiply
31 generic map (PIPELINE_DEPTH => pipeline_depth)
32 port map (clk => clk, m_in => m1, m_out => m2);
37 wait for clk_period/2;
39 wait for clk_period/2;
43 variable ra, rb, rt, behave_rt: std_ulogic_vector(63 downto 0);
44 variable si: std_ulogic_vector(15 downto 0);
45 variable rnd : RandomPType;
47 rnd.InitSeed(stim_process'path_name);
49 test_runner_setup(runner, runner_cfg);
52 if run("Test interface") then
56 m1.data1 <= x"0000000000001000";
57 m1.data2 <= x"0000000000001111";
60 check_false(?? m2.valid, result("for valid"));
65 check_false(?? m2.valid, result("for valid"));
68 check_false(?? m2.valid, result("for valid"));
71 check_true(?? m2.valid, result("for valid"));
72 check_equal(m2.result, 16#1111000#);
75 check_false(?? m2.valid, result("for valid"));
80 check_false(?? m2.valid, result("for valid"));
84 wait for clk_period * (pipeline_depth-1);
85 check_true(?? m2.valid, result("for valid"));
86 check_equal(m2.result, 16#1111000#);
88 elsif run("Test mulld") then
89 mulld_loop : for i in 0 to 1000 loop
90 ra := rnd.RandSlv(ra'length);
91 rb := rnd.RandSlv(rb'length);
93 behave_rt := ppc_mulld(ra, rb);
99 m1.addend <= (others => '0');
106 wait for clk_period * (pipeline_depth-1);
108 check_true(?? m2.valid, result("for valid"));
109 check_equal(m2.result(63 downto 0), behave_rt, result("for mulld " & to_hstring(behave_rt)));
112 elsif run("Test mulhdu") then
113 mulhdu_loop : for i in 0 to 1000 loop
114 ra := rnd.RandSlv(ra'length);
115 rb := rnd.RandSlv(rb'length);
117 behave_rt := ppc_mulhdu(ra, rb);
123 m1.addend <= (others => '0');
130 wait for clk_period * (pipeline_depth-1);
132 check_true(?? m2.valid, result("for valid"));
133 check_equal(m2.result(127 downto 64), behave_rt, result("for mulhdu " & to_hstring(behave_rt)));
136 elsif run("Test mulhd") then
137 mulhd_loop : for i in 0 to 1000 loop
138 ra := rnd.RandSlv(ra'length);
139 rb := rnd.RandSlv(rb'length);
141 behave_rt := ppc_mulhd(ra, rb);
147 m1.addend <= (others => '0');
154 wait for clk_period * (pipeline_depth-1);
156 check_true(?? m2.valid, result("for valid"));
157 check_equal(m2.result(127 downto 64), behave_rt, result("for mulhd " & to_hstring(behave_rt)));
160 elsif run("Test mullw") then
161 mullw_loop : for i in 0 to 1000 loop
162 ra := rnd.RandSlv(ra'length);
163 rb := rnd.RandSlv(rb'length);
165 behave_rt := ppc_mullw(ra, rb);
167 m1.data1 <= (others => ra(31));
168 m1.data1(31 downto 0) <= ra(31 downto 0);
169 m1.data2 <= (others => rb(31));
170 m1.data2(31 downto 0) <= rb(31 downto 0);
173 m1.addend <= (others => '0');
180 wait for clk_period * (pipeline_depth-1);
182 check_true(?? m2.valid, result("for valid"));
183 check_equal(m2.result(63 downto 0), behave_rt, result("for mullw " & to_hstring(behave_rt)));
186 elsif run("Test mulhw") then
187 mulhw_loop : for i in 0 to 1000 loop
188 ra := rnd.RandSlv(ra'length);
189 rb := rnd.RandSlv(rb'length);
191 behave_rt := ppc_mulhw(ra, rb);
193 m1.data1 <= (others => ra(31));
194 m1.data1(31 downto 0) <= ra(31 downto 0);
195 m1.data2 <= (others => rb(31));
196 m1.data2(31 downto 0) <= rb(31 downto 0);
199 m1.addend <= (others => '0');
206 wait for clk_period * (pipeline_depth-1);
208 check_true(?? m2.valid, result("for valid"));
209 check_equal(m2.result(63 downto 32) & m2.result(63 downto 32), behave_rt, result("for mulhw " & to_hstring(behave_rt)));
212 elsif run("Test mulhwu") then
213 mulhwu_loop : for i in 0 to 1000 loop
214 ra := rnd.RandSlv(ra'length);
215 rb := rnd.RandSlv(rb'length);
217 behave_rt := ppc_mulhwu(ra, rb);
219 m1.data1 <= (others => '0');
220 m1.data1(31 downto 0) <= ra(31 downto 0);
221 m1.data2 <= (others => '0');
222 m1.data2(31 downto 0) <= rb(31 downto 0);
225 m1.addend <= (others => '0');
232 wait for clk_period * (pipeline_depth-1);
234 check_true(?? m2.valid, result("for valid"));
235 check_equal(m2.result(63 downto 32) & m2.result(63 downto 32), behave_rt, result("for mulhwu " & to_hstring(behave_rt)));
238 elsif run("Test mulli") then
239 mulli_loop : for i in 0 to 1000 loop
240 ra := rnd.RandSlv(ra'length);
241 si := rnd.RandSlv(si'length);
243 behave_rt := ppc_mulli(ra, si);
246 m1.data2 <= (others => si(15));
247 m1.data2(15 downto 0) <= si;
250 m1.addend <= (others => '0');
257 wait for clk_period * (pipeline_depth-1);
259 check_true(?? m2.valid, result("for valid"));
260 check_equal(m2.result(63 downto 0), behave_rt, result("for mulli " & to_hstring(behave_rt)));
265 test_runner_cleanup(runner);