2 context vunit_lib.vunit_context;
5 use ieee.std_logic_1164.all;
6 use ieee.numeric_std.all;
10 use work.ppc_fx_insns.all;
11 use work.insn_helpers.all;
14 use osvvm.RandomPkg.all;
17 generic (runner_cfg : string := runner_cfg_default);
20 architecture behave of rotator_tb is
21 constant clk_period: time := 10 ns;
22 signal ra, rs: std_ulogic_vector(63 downto 0);
23 signal shift: std_ulogic_vector(6 downto 0) := (others => '0');
24 signal insn: std_ulogic_vector(31 downto 0) := (others => '0');
25 signal is_32bit, right_shift, arith, clear_left, clear_right: std_ulogic := '0';
26 signal res: std_ulogic_vector(63 downto 0);
27 signal carry_out: std_ulogic;
28 signal extsw: std_ulogic;
31 rotator_0: entity work.rotator
38 right_shift => right_shift,
40 clear_left => clear_left,
41 clear_right => clear_right,
44 carry_out => carry_out
48 variable behave_ra: std_ulogic_vector(63 downto 0);
49 variable behave_ca_ra: std_ulogic_vector(64 downto 0);
50 variable rnd : RandomPType;
52 rnd.InitSeed(stim_process'path_name);
54 -- TODO: Consider making debug messages visible with a command line option
55 -- rather than uncommenting this line:
56 -- show(display_handler, debug);
58 test_runner_setup(runner, runner_cfg);
61 if run("Test rlw[i]nm") then
62 ra <= (others => '0');
69 rlwnm_loop : for i in 0 to 1000 loop
70 rs <= rnd.RandSlv(64);
71 shift <= rnd.RandSlv(7);
72 insn <= x"00000" & '0' & rnd.RandSlv(10) & '0';
74 behave_ra := ppc_rlwinm(rs, shift(4 downto 0), insn_mb32(insn), insn_me32(insn));
75 check_equal(res, behave_ra, result("for rlwnm"));
78 elsif run("Test rlwimi") then
84 rlwimi_loop : for i in 0 to 1000 loop
85 rs <= rnd.RandSlv(64);
86 ra <= rnd.RandSlv(64);
87 shift <= "00" & rnd.RandSlv(5);
88 insn <= x"00000" & '0' & rnd.RandSlv(10) & '0';
90 behave_ra := ppc_rlwimi(ra, rs, shift(4 downto 0), insn_mb32(insn), insn_me32(insn));
91 check_equal(res, behave_ra, result("for rlwnimi"));
94 elsif run("Test rld[i]cl") then
95 ra <= (others => '0');
101 rldicl_loop : for i in 0 to 1000 loop
102 rs <= rnd.RandSlv(64);
103 shift <= rnd.RandSlv(7);
104 insn <= x"00000" & '0' & rnd.RandSlv(10) & '0';
106 behave_ra := ppc_rldicl(rs, shift(5 downto 0), insn_mb(insn));
107 check_equal(res, behave_ra, result("for rldicl"));
110 elsif run("Test rld[i]cr") then
111 ra <= (others => '0');
117 rldicr_loop : for i in 0 to 1000 loop
118 rs <= rnd.RandSlv(64);
119 shift <= rnd.RandSlv(7);
120 insn <= x"00000" & '0' & rnd.RandSlv(10) & '0';
122 behave_ra := ppc_rldicr(rs, shift(5 downto 0), insn_me(insn));
123 debug("rs = " & to_hstring(rs));
124 debug("ra = " & to_hstring(ra));
125 debug("shift = " & to_hstring(shift));
126 debug("insn me = " & to_hstring(insn_me(insn)));
127 debug("result = " & to_hstring(res));
128 check_equal(res, behave_ra, result("for rldicr"));
131 elsif run("Test rldic") then
132 ra <= (others => '0');
138 rldic_loop : for i in 0 to 1000 loop
139 rs <= rnd.RandSlv(64);
140 shift <= '0' & rnd.RandSlv(6);
141 insn <= x"00000" & '0' & rnd.RandSlv(10) & '0';
143 behave_ra := ppc_rldic(rs, shift(5 downto 0), insn_mb(insn));
144 check_equal(res, behave_ra, result("for rldic"));
147 elsif run("Test rldimi") then
153 rldimi_loop : for i in 0 to 1000 loop
154 rs <= rnd.RandSlv(64);
155 ra <= rnd.RandSlv(64);
156 shift <= '0' & rnd.RandSlv(6);
157 insn <= x"00000" & '0' & rnd.RandSlv(10) & '0';
159 behave_ra := ppc_rldimi(ra, rs, shift(5 downto 0), insn_mb(insn));
160 check_equal(res, behave_ra, result("for rldimi"));
163 elsif run("Test slw") then
164 ra <= (others => '0');
170 slw_loop : for i in 0 to 1000 loop
171 rs <= rnd.RandSlv(64);
172 shift <= rnd.RandSlv(7);
174 behave_ra := ppc_slw(rs, std_ulogic_vector(resize(unsigned(shift), 64)));
175 check_equal(res, behave_ra, result("for slv"));
178 elsif run("Test sld") then
179 ra <= (others => '0');
185 sld_loop : for i in 0 to 1000 loop
186 rs <= rnd.RandSlv(64);
187 shift <= rnd.RandSlv(7);
189 behave_ra := ppc_sld(rs, std_ulogic_vector(resize(unsigned(shift), 64)));
190 check_equal(res, behave_ra, result("for sld"));
193 elsif run("Test srw") then
194 ra <= (others => '0');
200 srw_loop : for i in 0 to 1000 loop
201 rs <= rnd.RandSlv(64);
202 shift <= rnd.RandSlv(7);
204 behave_ra := ppc_srw(rs, std_ulogic_vector(resize(unsigned(shift), 64)));
205 check_equal(res, behave_ra, result("for srw"));
208 elsif run("Test srd") then
209 ra <= (others => '0');
215 srd_loop : for i in 0 to 1000 loop
216 rs <= rnd.RandSlv(64);
217 shift <= rnd.RandSlv(7);
219 behave_ra := ppc_srd(rs, std_ulogic_vector(resize(unsigned(shift), 64)));
220 check_equal(res, behave_ra, result("for srd"));
223 elsif run("Test sraw[i]") then
224 ra <= (others => '0');
230 sraw_loop : for i in 0 to 1000 loop
231 rs <= rnd.RandSlv(64);
232 shift <= '0' & rnd.RandSlv(6);
234 behave_ca_ra := ppc_sraw(rs, std_ulogic_vector(resize(unsigned(shift), 64)));
235 debug("rs = " & to_hstring(rs));
236 debug("ra = " & to_hstring(ra));
237 debug("shift = " & to_hstring(shift));
238 debug("result = " & to_hstring(carry_out & res));
239 check_equal(res, behave_ca_ra(63 downto 0), result("for sraw"));
240 check_equal(carry_out, behave_ca_ra(64), result("for sraw carry_out"));
243 elsif run("Test srad[i]") then
244 ra <= (others => '0');
250 srad_loop : for i in 0 to 1000 loop
251 rs <= rnd.RandSlv(64);
252 shift <= rnd.RandSlv(7);
254 behave_ca_ra := ppc_srad(rs, std_ulogic_vector(resize(unsigned(shift), 64)));
255 debug("rs = " & to_hstring(rs));
256 debug("ra = " & to_hstring(ra));
257 debug("shift = " & to_hstring(shift));
258 debug("result = " & to_hstring(carry_out & res));
259 check_equal(res, behave_ca_ra(63 downto 0), result("for srad"));
260 check_equal(carry_out, behave_ca_ra(64), result("for srad carry_out"));
263 elsif run("Test extswsli") then
264 ra <= (others => '0');
271 extswsli_loop : for i in 0 to 1000 loop
272 rs <= rnd.RandSlv(64);
273 shift <= '0' & rnd.RandSlv(6);
276 behave_ra(63 downto 32) := (others => rs(31));
277 behave_ra := std_ulogic_vector(shift_left(unsigned(behave_ra),
278 to_integer(unsigned(shift))));
279 debug("rs = " & to_hstring(rs));
280 debug("ra = " & to_hstring(ra));
281 debug("shift = " & to_hstring(shift));
282 debug("result = " & to_hstring(carry_out & res));
283 check_equal(res, behave_ra, result("for extswsli"));
287 test_runner_cleanup(runner);