2 use ieee.std_logic_1164.all;
3 use ieee.numeric_std.all;
8 package ppc_fx_insns is
9 function ppc_addi (ra: std_ulogic_vector(63 downto 0); si: std_ulogic_vector(15 downto 0)) return std_ulogic_vector;
10 function ppc_addis (ra: std_ulogic_vector(63 downto 0); si: std_ulogic_vector(15 downto 0)) return std_ulogic_vector;
11 function ppc_add (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
12 function ppc_subf (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
13 function ppc_neg (ra: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
15 function ppc_addic (ra: std_ulogic_vector(63 downto 0); si: std_ulogic_vector(15 downto 0)) return std_ulogic_vector;
16 function ppc_adde (ra, rb: std_ulogic_vector(63 downto 0); carry: std_ulogic) return std_ulogic_vector;
17 function ppc_subfic (ra: std_ulogic_vector(63 downto 0); si: std_ulogic_vector(15 downto 0)) return std_ulogic_vector;
18 function ppc_subfc (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
19 function ppc_subfe (ra, rb: std_ulogic_vector(63 downto 0); carry: std_ulogic) return std_ulogic_vector;
20 function ppc_addze (ra: std_ulogic_vector(63 downto 0); carry: std_ulogic) return std_ulogic_vector;
22 function ppc_andi (rs: std_ulogic_vector(63 downto 0); ui: std_ulogic_vector(15 downto 0)) return std_ulogic_vector;
23 function ppc_andis (rs: std_ulogic_vector(63 downto 0); ui: std_ulogic_vector(15 downto 0)) return std_ulogic_vector;
24 function ppc_ori (rs: std_ulogic_vector(63 downto 0); ui: std_ulogic_vector(15 downto 0)) return std_ulogic_vector;
25 function ppc_oris (rs: std_ulogic_vector(63 downto 0); ui: std_ulogic_vector(15 downto 0)) return std_ulogic_vector;
26 function ppc_xori (rs: std_ulogic_vector(63 downto 0); ui: std_ulogic_vector(15 downto 0)) return std_ulogic_vector;
27 function ppc_xoris (rs: std_ulogic_vector(63 downto 0); ui: std_ulogic_vector(15 downto 0)) return std_ulogic_vector;
28 function ppc_and (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
29 function ppc_xor (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
30 function ppc_nand (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
31 function ppc_or (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
32 function ppc_nor (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
33 function ppc_andc (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
34 function ppc_eqv (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
35 function ppc_orc (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
37 function ppc_extsb (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
38 function ppc_extsh (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
39 function ppc_extsw (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
41 function ppc_cntlzw (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
42 function ppc_cnttzw (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
43 function ppc_cntlzd (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
44 function ppc_cnttzd (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
46 function ppc_popcntb (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
47 function ppc_popcntw (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
48 function ppc_popcntd (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
50 function ppc_prtyd (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
51 function ppc_prtyw (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
53 function ppc_rlwinm (rs: std_ulogic_vector(63 downto 0); sh, mb, me: std_ulogic_vector(4 downto 0)) return std_ulogic_vector;
54 function ppc_rlwnm (rs, rb: std_ulogic_vector(63 downto 0); mb, me: std_ulogic_vector(4 downto 0)) return std_ulogic_vector;
55 function ppc_rlwimi (ra, rs: std_ulogic_vector(63 downto 0); sh, mb, me: std_ulogic_vector(4 downto 0)) return std_ulogic_vector;
56 function ppc_rldicl (rs: std_ulogic_vector(63 downto 0); sh, mb: std_ulogic_vector(5 downto 0)) return std_ulogic_vector;
57 function ppc_rldicr (rs: std_ulogic_vector(63 downto 0); sh, me: std_ulogic_vector(5 downto 0)) return std_ulogic_vector;
58 function ppc_rldic (rs: std_ulogic_vector(63 downto 0); sh, mb: std_ulogic_vector(5 downto 0)) return std_ulogic_vector;
59 function ppc_rldcl (rs, rb: std_ulogic_vector(63 downto 0); mb: std_ulogic_vector(5 downto 0)) return std_ulogic_vector;
60 function ppc_rldcr (rs, rb: std_ulogic_vector(63 downto 0); me: std_ulogic_vector(5 downto 0)) return std_ulogic_vector;
61 function ppc_rldimi (ra, rs: std_ulogic_vector(63 downto 0); sh, mb: std_ulogic_vector(5 downto 0)) return std_ulogic_vector;
63 function ppc_slw (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
64 function ppc_srw (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
65 function ppc_srawi (rs : std_ulogic_vector(63 downto 0); sh: std_ulogic_vector(5 downto 0)) return std_ulogic_vector;
66 function ppc_sraw (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
67 function ppc_sld (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
68 function ppc_srd (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
69 function ppc_sradi (rs: std_ulogic_vector(63 downto 0); sh: std_ulogic_vector(5 downto 0)) return std_ulogic_vector;
70 function ppc_srad (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
72 function ppc_mulld (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
73 function ppc_mulhd (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
74 function ppc_mulhdu (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
75 function ppc_mulli (ra: std_ulogic_vector(63 downto 0); si: std_ulogic_vector(15 downto 0)) return std_ulogic_vector;
76 function ppc_mullw (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
77 function ppc_mulhw (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
78 function ppc_mulhwu (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
80 function ppc_cmpi (l: std_ulogic; ra: std_ulogic_vector(63 downto 0); si: std_ulogic_vector(15 downto 0)) return std_ulogic_vector;
81 function ppc_cmp (l: std_ulogic; ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
82 function ppc_cmpli (l: std_ulogic; ra: std_ulogic_vector(63 downto 0); si: std_ulogic_vector(15 downto 0)) return std_ulogic_vector;
83 function ppc_cmpl (l: std_ulogic; ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
85 function ppc_cmpb (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
87 function ppc_divw (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
88 function ppc_divdu (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
89 function ppc_divd (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
90 function ppc_divwu (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
92 function ppc_b (nia: std_ulogic_vector(63 downto 0); bd: std_ulogic_vector(23 downto 0)) return std_ulogic_vector;
93 function ppc_bc_taken(bo, bi: std_ulogic_vector(4 downto 0); cr: std_ulogic_vector(31 downto 0); ctr: std_ulogic_vector(63 downto 0)) return integer;
94 function ppc_bcctr_taken(bo, bi: std_ulogic_vector(4 downto 0); cr: std_ulogic_vector(31 downto 0)) return integer;
95 end package ppc_fx_insns;
97 package body ppc_fx_insns is
98 function ppc_addi (ra: std_ulogic_vector(63 downto 0); si: std_ulogic_vector(15 downto 0)) return std_ulogic_vector is
100 return std_ulogic_vector(signed(ra) + signed(si));
103 function ppc_addic (ra: std_ulogic_vector(63 downto 0); si: std_ulogic_vector(15 downto 0)) return std_ulogic_vector is
105 return std_logic_vector(resize(unsigned(ra), 65) + unsigned(resize(signed(si), 64)));
108 function ppc_adde (ra, rb: std_ulogic_vector(63 downto 0); carry: std_ulogic) return std_ulogic_vector is
110 return std_logic_vector(resize(unsigned(ra), 65) + resize(unsigned(rb), 65) + carry);
113 function ppc_subfic (ra: std_ulogic_vector(63 downto 0); si: std_ulogic_vector(15 downto 0)) return std_ulogic_vector is
115 return std_logic_vector(unsigned(resize(signed(si), 64)) + resize(unsigned(not(ra)), 65) + 1);
118 function ppc_subfc (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
120 return std_logic_vector(resize(unsigned(rb), 65) + resize(unsigned(not(ra)), 65) + 1);
123 function ppc_subfe (ra, rb: std_ulogic_vector(63 downto 0); carry: std_ulogic) return std_ulogic_vector is
125 return std_logic_vector(resize(unsigned(rb), 65) + resize(unsigned(not(ra)), 65) + carry);
128 function ppc_addze (ra: std_ulogic_vector(63 downto 0); carry: std_ulogic) return std_ulogic_vector is
130 return std_logic_vector(resize(unsigned(ra), 65) + carry);
133 function ppc_addis (ra: std_ulogic_vector(63 downto 0); si: std_ulogic_vector(15 downto 0)) return std_ulogic_vector is
135 return std_ulogic_vector(signed(ra) + shift_left(resize(signed(si), 32), 16));
138 function ppc_add (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
140 return std_ulogic_vector(signed(ra) + signed(rb));
143 function ppc_subf (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
145 return std_ulogic_vector(signed(rb) - signed(ra));
148 function ppc_neg (ra: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
150 return std_ulogic_vector(-signed(ra));
153 function ppc_andi (rs: std_ulogic_vector(63 downto 0); ui: std_ulogic_vector(15 downto 0)) return std_ulogic_vector is
155 return rs and std_ulogic_vector(resize(unsigned(ui), 64));
158 function ppc_andis (rs: std_ulogic_vector(63 downto 0); ui: std_ulogic_vector(15 downto 0)) return std_ulogic_vector is
160 return rs and std_ulogic_vector(shift_left(resize(unsigned(ui), 64), 16));
163 function ppc_ori (rs: std_ulogic_vector(63 downto 0); ui: std_ulogic_vector(15 downto 0)) return std_ulogic_vector is
165 return rs or std_ulogic_vector(resize(unsigned(ui), 64));
168 function ppc_oris (rs: std_ulogic_vector(63 downto 0); ui: std_ulogic_vector(15 downto 0)) return std_ulogic_vector is
170 return rs or std_ulogic_vector(shift_left(resize(unsigned(ui), 64), 16));
173 function ppc_xori (rs: std_ulogic_vector(63 downto 0); ui: std_ulogic_vector(15 downto 0)) return std_ulogic_vector is
175 return rs xor std_ulogic_vector(resize(unsigned(ui), 64));
178 function ppc_xoris (rs: std_ulogic_vector(63 downto 0); ui: std_ulogic_vector(15 downto 0)) return std_ulogic_vector is
180 return rs xor std_ulogic_vector(shift_left(resize(unsigned(ui), 64), 16));
183 function ppc_and (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
188 function ppc_xor (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
193 function ppc_nand (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
198 function ppc_or (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
203 function ppc_nor (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
208 function ppc_andc (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
210 return rs and not(rb);
213 function ppc_eqv (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
215 return not(rs xor rb);
218 function ppc_orc (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
220 return rs or not(rb);
223 function ppc_extsb (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
225 return std_ulogic_vector(resize(signed(rs(7 downto 0)), rs'length));
228 function ppc_extsh (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
230 return std_ulogic_vector(resize(signed(rs(15 downto 0)), rs'length));
233 function ppc_extsw (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
235 return std_ulogic_vector(resize(signed(rs(31 downto 0)), rs'length));
238 function ppc_cntlzw (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
240 return std_ulogic_vector(to_unsigned(fls_32(rs(31 downto 0)), rs'length));
243 function ppc_cnttzw (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
245 return std_ulogic_vector(to_unsigned(ffs_32(rs(31 downto 0)), rs'length));
248 function ppc_cntlzd (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
250 return std_ulogic_vector(to_unsigned(fls_64(rs), rs'length));
253 function ppc_cnttzd (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
255 return std_ulogic_vector(to_unsigned(ffs_64(rs), rs'length));
258 function ppc_popcntb (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
259 variable ret: std_ulogic_vector (rs'range);
260 variable hi: integer;
261 variable lo: integer;
263 ret := (others => '0');
268 ret(hi downto lo) := popcnt8(rs(hi downto lo));
274 function ppc_popcntw (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
275 variable ret: std_ulogic_vector (rs'range);
276 variable hi: integer;
277 variable lo: integer;
279 ret := (others => '0');
284 ret(hi downto lo) := popcnt32(rs(hi downto lo));
290 function ppc_popcntd (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
295 function ppc_prtyd (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
296 variable tmp : std_ulogic;
297 variable ret : std_ulogic_vector(63 downto 0);
299 ret := (others => '0');
303 tmp := tmp xor rs(i*8);
310 function ppc_prtyw (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
311 variable tmp : std_ulogic;
312 variable ret : std_ulogic_vector(63 downto 0);
314 ret := (others => '0');
318 tmp := tmp xor rs(i*8);
324 tmp := tmp xor rs(i*8);
331 function ppc_rlwinm (rs: std_ulogic_vector(63 downto 0); sh, mb, me: std_ulogic_vector(4 downto 0)) return std_ulogic_vector is
332 variable hi, lo : integer;
333 variable tmp1, tmp2 : std_ulogic_vector(63 downto 0);
335 hi := 31 - to_integer(unsigned(mb));
336 lo := 31 - to_integer(unsigned(me));
337 tmp1 := rs(31 downto 0) & rs(31 downto 0);
338 tmp1 := std_ulogic_vector(rotate_left(unsigned(tmp1), to_integer(unsigned(sh))));
339 tmp2 := (others => '0');
342 for i in 0 to 63 loop
343 if i <= hi or i >= lo then
348 for i in 0 to 63 loop
349 if i >= lo and i <= hi then
357 function ppc_rlwnm (rs, rb: std_ulogic_vector(63 downto 0); mb, me: std_ulogic_vector(4 downto 0)) return std_ulogic_vector is
358 variable hi, lo : integer;
359 variable tmp1, tmp2 : std_ulogic_vector(63 downto 0);
360 variable n : integer;
362 hi := 31 - to_integer(unsigned(mb));
363 lo := 31 - to_integer(unsigned(me));
364 n := to_integer(unsigned(rb(4 downto 0)));
365 tmp1 := rs(31 downto 0) & rs(31 downto 0);
366 tmp1 := std_ulogic_vector(rotate_left(unsigned(tmp1), n));
367 tmp2 := (others => '0');
370 for i in 0 to 63 loop
371 if i <= hi or i >= lo then
376 for i in 0 to 63 loop
377 if i >= lo and i <= hi then
385 function ppc_rlwimi (ra, rs: std_ulogic_vector(63 downto 0); sh, mb, me: std_ulogic_vector(4 downto 0)) return std_ulogic_vector is
386 variable hi, lo : integer;
387 variable tmp1, tmp2 : std_ulogic_vector(63 downto 0);
389 hi := 31 - to_integer(unsigned(mb));
390 lo := 31 - to_integer(unsigned(me));
391 tmp1 := rs(31 downto 0) & rs(31 downto 0);
392 tmp1 := std_ulogic_vector(rotate_left(unsigned(tmp1), to_integer(unsigned(sh))));
396 for i in 0 to 63 loop
397 if i <= hi or i >= lo then
402 for i in 0 to 63 loop
403 if i >= lo and i <= hi then
411 function ppc_rldicl (rs: std_ulogic_vector(63 downto 0); sh, mb: std_ulogic_vector(5 downto 0)) return std_ulogic_vector is
412 variable hi : integer;
413 variable tmp1, tmp2 : std_ulogic_vector(63 downto 0);
415 hi := 63-to_integer(unsigned(mb));
416 tmp1 := std_ulogic_vector(rotate_left(unsigned(rs), to_integer(unsigned(sh))));
417 tmp2 := (others => '0');
418 for i in 0 to 63 loop
426 function ppc_rldicr (rs: std_ulogic_vector(63 downto 0); sh, me: std_ulogic_vector(5 downto 0)) return std_ulogic_vector is
427 variable lo : integer;
428 variable tmp1, tmp2 : std_ulogic_vector(63 downto 0);
430 lo := 63-to_integer(unsigned(me));
431 tmp1 := std_ulogic_vector(rotate_left(unsigned(rs), to_integer(unsigned(sh))));
432 tmp2 := (others => '0');
433 for i in 0 to 63 loop
441 function ppc_rldic (rs: std_ulogic_vector(63 downto 0); sh, mb: std_ulogic_vector(5 downto 0)) return std_ulogic_vector is
442 variable hi, lo : integer;
443 variable tmp1, tmp2 : std_ulogic_vector(63 downto 0);
445 hi := 63-to_integer(unsigned(mb));
446 lo := to_integer(unsigned(sh));
447 tmp1 := std_ulogic_vector(rotate_left(unsigned(rs), to_integer(unsigned(sh))));
448 tmp2 := (others => '0');
451 for i in 0 to 63 loop
452 if i <= hi or i >= lo then
457 for i in 0 to 63 loop
458 if i >= lo and i <= hi then
466 function ppc_rldcl (rs, rb: std_ulogic_vector(63 downto 0); mb: std_ulogic_vector(5 downto 0)) return std_ulogic_vector is
467 variable hi : integer;
468 variable tmp1, tmp2 : std_ulogic_vector(63 downto 0);
470 hi := 63-to_integer(unsigned(mb));
471 tmp1 := std_ulogic_vector(rotate_left(unsigned(rs), to_integer(unsigned(rb(5 downto 0)))));
472 tmp2 := (others => '0');
473 for i in 0 to 63 loop
481 function ppc_rldcr (rs, rb: std_ulogic_vector(63 downto 0); me: std_ulogic_vector(5 downto 0)) return std_ulogic_vector is
482 variable lo : integer;
483 variable tmp1, tmp2 : std_ulogic_vector(63 downto 0);
485 lo := 63-to_integer(unsigned(me));
486 tmp1 := std_ulogic_vector(rotate_left(unsigned(rs), to_integer(unsigned(rb(5 downto 0)))));
487 tmp2 := (others => '0');
488 for i in 0 to 63 loop
496 function ppc_rldimi (ra, rs: std_ulogic_vector(63 downto 0); sh, mb: std_ulogic_vector(5 downto 0)) return std_ulogic_vector is
497 variable hi, lo : integer;
498 variable tmp1, tmp2 : std_ulogic_vector(rs'range);
500 hi := 63-to_integer(unsigned(mb));
501 lo := to_integer(unsigned(sh));
502 tmp1 := std_ulogic_vector(rotate_left(unsigned(rs), lo));
506 for i in 0 to 63 loop
507 if i <= hi or i >= lo then
512 for i in 0 to 63 loop
513 if i >= lo and i <= hi then
521 function ppc_slw (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
522 variable n : integer;
523 variable tmp : unsigned(31 downto 0);
525 n := to_integer(unsigned(rb(5 downto 0)));
526 tmp := shift_left(unsigned(rs(31 downto 0)), n);
528 return (63 downto 32 => '0') & std_ulogic_vector(tmp);
531 function ppc_srw (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
532 variable n : integer;
533 variable tmp : unsigned(31 downto 0);
535 n := to_integer(unsigned(rb(5 downto 0)));
536 tmp := shift_right(unsigned(rs(31 downto 0)), n);
538 return (63 downto 32 => '0') & std_ulogic_vector(tmp);
541 function ppc_srawi (rs : std_ulogic_vector(63 downto 0); sh: std_ulogic_vector(5 downto 0)) return std_ulogic_vector is
542 variable n : integer;
543 variable tmp : signed(31 downto 0);
544 variable mask : std_ulogic_vector(63 downto 0);
545 variable carry: std_ulogic;
547 n := to_integer(unsigned(sh));
548 tmp := shift_right(signed(rs(31 downto 0)), n);
550 mask := (others => '0');
551 for i in 0 to 63 loop
556 carry := '0' when (rs and mask) = (63 downto 0 => '0') else rs(31);
558 return carry & std_ulogic_vector(resize(tmp, rs'length));
561 function ppc_sraw (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
562 variable n : natural;
563 variable tmp : signed(31 downto 0);
564 variable mask : std_ulogic_vector(63 downto 0);
565 variable carry: std_ulogic;
567 n := to_integer(unsigned(rb(5 downto 0)));
568 tmp := shift_right(signed(rs(31 downto 0)), n);
570 mask := (others => '0');
571 for i in 0 to 63 loop
576 carry := or (rs and mask) and rs(31);
577 return carry & std_ulogic_vector(resize(tmp, rs'length));
580 function ppc_sld (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
581 variable n : integer;
583 n := to_integer(unsigned(rb(6 downto 0)));
584 return std_ulogic_vector(shift_left(unsigned(rs), n));
587 function ppc_srd (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
588 variable n : integer;
590 n := to_integer(unsigned(rb(6 downto 0)));
591 return std_ulogic_vector(shift_right(unsigned(rs), n));
594 function ppc_sradi (rs: std_ulogic_vector(63 downto 0); sh: std_ulogic_vector(5 downto 0)) return std_ulogic_vector is
595 variable n : integer;
596 variable carry: std_ulogic;
597 variable mask : std_ulogic_vector(63 downto 0);
599 n := to_integer(unsigned(sh));
601 mask := (others => '0');
602 for i in 0 to 63 loop
607 carry := '0' when (rs and mask) = (63 downto 0 => '0') else rs(63);
609 return carry & std_ulogic_vector(shift_right(signed(rs), n));
612 function ppc_srad (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
613 variable n : integer;
614 variable carry: std_ulogic;
615 variable mask : std_ulogic_vector(63 downto 0);
617 n := to_integer(unsigned(rb(6 downto 0)));
619 mask := (others => '0');
620 for i in 0 to 63 loop
625 carry := '0' when (rs and mask) = (63 downto 0 => '0') else rs(63);
627 return carry & std_ulogic_vector(shift_right(signed(rs), n));
630 -- Not sure how to better communicate the top 64 bits of the result is unused
631 function ppc_mulld (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
632 variable tmp: signed(127 downto 0);
634 tmp := signed(ra) * signed(rb);
635 return std_ulogic_vector(tmp(63 downto 0));
638 -- Not sure how to better communicate the top 64 bits of the result is unused
639 function ppc_mulhd (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
640 variable tmp: signed(127 downto 0);
642 tmp := signed(ra) * signed(rb);
643 return std_ulogic_vector(tmp(127 downto 64));
646 -- Not sure how to better communicate the top 64 bits of the result is unused
647 function ppc_mulhdu (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
648 variable tmp: unsigned(127 downto 0);
650 tmp := unsigned(ra) * unsigned(rb);
651 return std_ulogic_vector(tmp(127 downto 64));
654 -- Not sure how to better communicate the top 16 bits of the result is unused
655 function ppc_mulli (ra: std_ulogic_vector(63 downto 0); si: std_ulogic_vector(15 downto 0)) return std_ulogic_vector is
656 variable tmp: signed(79 downto 0);
658 tmp := signed(ra) * signed(si);
659 return std_ulogic_vector(tmp(63 downto 0));
662 function ppc_mullw (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
664 return std_ulogic_vector(signed(ra(31 downto 0)) * signed(rb(31 downto 0)));
667 function ppc_mulhw (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
668 variable tmp: signed(63 downto 0);
670 tmp := signed(ra(31 downto 0)) * signed(rb(31 downto 0));
671 return std_ulogic_vector(tmp(63 downto 32)) & std_ulogic_vector(tmp(63 downto 32));
674 function ppc_mulhwu (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
675 variable tmp: unsigned(63 downto 0);
677 tmp := unsigned(ra(31 downto 0)) * unsigned(rb(31 downto 0));
678 return std_ulogic_vector(tmp(63 downto 32)) & std_ulogic_vector(tmp(63 downto 32));
681 function ppc_cmpi (l: std_ulogic; ra: std_ulogic_vector(63 downto 0); si: std_ulogic_vector(15 downto 0)) return std_ulogic_vector is
682 variable tmp: signed(ra'range);
686 tmp := resize(signed(ra(31 downto 0)), tmp'length);
689 return ppc_signed_compare(tmp, resize(signed(si), tmp'length));
692 function ppc_cmp (l: std_ulogic; ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
693 variable tmpa, tmpb: signed(ra'range);
698 tmpa := resize(signed(ra(31 downto 0)), ra'length);
699 tmpb := resize(signed(rb(31 downto 0)), ra'length);
702 return ppc_signed_compare(tmpa, tmpb);
705 function ppc_cmpli (l: std_ulogic; ra: std_ulogic_vector(63 downto 0); si: std_ulogic_vector(15 downto 0)) return std_ulogic_vector is
706 variable tmp: unsigned(ra'range);
710 tmp := resize(unsigned(ra(31 downto 0)), tmp'length);
713 return ppc_unsigned_compare(tmp, resize(unsigned(si), tmp'length));
716 function ppc_cmpl (l: std_ulogic; ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
717 variable tmpa, tmpb: unsigned(ra'range);
719 tmpa := unsigned(ra);
720 tmpb := unsigned(rb);
722 tmpa := resize(unsigned(ra(31 downto 0)), ra'length);
723 tmpb := resize(unsigned(rb(31 downto 0)), ra'length);
726 return ppc_unsigned_compare(tmpa, tmpb);
729 function ppc_cmpb (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
730 variable ret: std_ulogic_vector (rs'range);
731 variable hi: integer;
732 variable lo: integer;
737 ret(hi downto lo) := cmp_one_byte(rs(hi downto lo), rb(hi downto lo));
744 function ppc_divw (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
745 variable tmp: signed(31 downto 0);
747 tmp := signed(ra(31 downto 0)) / signed(rb(31 downto 0));
749 return (63 downto 32 => '0') & std_ulogic_vector(tmp);
752 function ppc_divdu (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
753 variable tmp: unsigned(63 downto 0) := (others => '0');
755 if unsigned(rb) /= 0 then
756 tmp := unsigned(ra) / unsigned(rb);
759 return std_ulogic_vector(tmp);
762 function ppc_divd (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
763 variable tmp: signed(63 downto 0) := (others => '0');
765 if signed(rb) /= 0 then
766 tmp := signed(ra) / signed(rb);
769 return std_ulogic_vector(tmp);
772 function ppc_divwu (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
773 variable tmp: unsigned(31 downto 0) := (others => '0');
775 if unsigned(rb(31 downto 0)) /= 0 then
776 tmp := unsigned(ra(31 downto 0)) / unsigned(rb(31 downto 0));
779 return std_ulogic_vector(resize(tmp, ra'length));
782 function ppc_b (nia: std_ulogic_vector(63 downto 0); bd: std_ulogic_vector(23 downto 0)) return std_ulogic_vector is
784 return std_ulogic_vector(signed(nia) + signed(bd & "00"));
787 function ppc_bc_taken(bo, bi: std_ulogic_vector(4 downto 0); cr: std_ulogic_vector(31 downto 0); ctr: std_ulogic_vector(63 downto 0)) return integer is
788 variable crfield: integer;
789 variable crbit_match: std_ulogic;
790 variable ctr_not_zero: std_ulogic;
791 variable ctr_ok: std_ulogic;
792 variable cond_ok: std_ulogic;
793 variable ret: integer;
795 crfield := to_integer(unsigned(bi));
797 crbit_match := '1' when cr(31-crfield) = bo(4-1) else '0';
798 -- We check this before it is decremented
799 ctr_not_zero := '1' when ctr /= x"0000000000000001" else '0';
800 ctr_ok := bo(4-2) or (ctr_not_zero xor bo(4-3));
801 cond_ok := bo(4-0) or crbit_match;
802 if ctr_ok = '1' and cond_ok = '1' then
810 function ppc_bcctr_taken(bo, bi: std_ulogic_vector(4 downto 0); cr: std_ulogic_vector(31 downto 0)) return integer is
811 variable crfield: integer;
812 variable crbit_match: std_ulogic;
813 variable cond_ok: std_ulogic;
814 variable ret: integer;
816 crfield := to_integer(unsigned(bi));
818 crbit_match := '1' when cr(31-crfield) = bo(4-1) else '0';
819 cond_ok := bo(4-0) or crbit_match;
820 if cond_ok = '1' then
827 end package body ppc_fx_insns;