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);
81 so: std_ulogic) return std_ulogic_vector;
82 function ppc_cmp (l: std_ulogic; ra, rb: std_ulogic_vector(63 downto 0);
83 so: std_ulogic) return std_ulogic_vector;
84 function ppc_cmpli (l: std_ulogic; ra: std_ulogic_vector(63 downto 0); si: std_ulogic_vector(15 downto 0);
85 so: std_ulogic) return std_ulogic_vector;
86 function ppc_cmpl (l: std_ulogic; ra, rb: std_ulogic_vector(63 downto 0);
87 so: std_ulogic) return std_ulogic_vector;
89 function ppc_cmpb (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
90 function ppc_cmpeqb (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
91 function ppc_cmprb (ra, rb: std_ulogic_vector(63 downto 0); l: std_ulogic) return std_ulogic_vector;
93 function ppc_divw (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
94 function ppc_divdu (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
95 function ppc_divd (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
96 function ppc_divwu (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
98 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 std_ulogic;
99 end package ppc_fx_insns;
101 package body ppc_fx_insns is
102 function ppc_addi (ra: std_ulogic_vector(63 downto 0); si: std_ulogic_vector(15 downto 0)) return std_ulogic_vector is
104 return std_ulogic_vector(signed(ra) + signed(si));
107 function ppc_addic (ra: std_ulogic_vector(63 downto 0); si: std_ulogic_vector(15 downto 0)) return std_ulogic_vector is
109 return std_logic_vector(resize(unsigned(ra), 65) + unsigned(resize(signed(si), 64)));
112 function ppc_adde (ra, rb: std_ulogic_vector(63 downto 0); carry: std_ulogic) return std_ulogic_vector is
114 return std_logic_vector(resize(unsigned(ra), 65) + resize(unsigned(rb), 65) + carry);
117 function ppc_subfic (ra: std_ulogic_vector(63 downto 0); si: std_ulogic_vector(15 downto 0)) return std_ulogic_vector is
119 return std_logic_vector(unsigned(resize(signed(si), 64)) + resize(unsigned(not(ra)), 65) + 1);
122 function ppc_subfc (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
124 return std_logic_vector(resize(unsigned(rb), 65) + resize(unsigned(not(ra)), 65) + 1);
127 function ppc_subfe (ra, rb: std_ulogic_vector(63 downto 0); carry: std_ulogic) return std_ulogic_vector is
129 return std_logic_vector(resize(unsigned(rb), 65) + resize(unsigned(not(ra)), 65) + carry);
132 function ppc_addze (ra: std_ulogic_vector(63 downto 0); carry: std_ulogic) return std_ulogic_vector is
134 return std_logic_vector(resize(unsigned(ra), 65) + carry);
137 function ppc_addis (ra: std_ulogic_vector(63 downto 0); si: std_ulogic_vector(15 downto 0)) return std_ulogic_vector is
139 return std_ulogic_vector(signed(ra) + shift_left(resize(signed(si), 32), 16));
142 function ppc_add (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
144 return std_ulogic_vector(signed(ra) + signed(rb));
147 function ppc_subf (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
149 return std_ulogic_vector(signed(rb) - signed(ra));
152 function ppc_neg (ra: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
154 return std_ulogic_vector(-signed(ra));
157 function ppc_andi (rs: std_ulogic_vector(63 downto 0); ui: std_ulogic_vector(15 downto 0)) return std_ulogic_vector is
159 return rs and std_ulogic_vector(resize(unsigned(ui), 64));
162 function ppc_andis (rs: std_ulogic_vector(63 downto 0); ui: std_ulogic_vector(15 downto 0)) return std_ulogic_vector is
164 return rs and std_ulogic_vector(shift_left(resize(unsigned(ui), 64), 16));
167 function ppc_ori (rs: std_ulogic_vector(63 downto 0); ui: std_ulogic_vector(15 downto 0)) return std_ulogic_vector is
169 return rs or std_ulogic_vector(resize(unsigned(ui), 64));
172 function ppc_oris (rs: std_ulogic_vector(63 downto 0); ui: std_ulogic_vector(15 downto 0)) return std_ulogic_vector is
174 return rs or std_ulogic_vector(shift_left(resize(unsigned(ui), 64), 16));
177 function ppc_xori (rs: std_ulogic_vector(63 downto 0); ui: std_ulogic_vector(15 downto 0)) return std_ulogic_vector is
179 return rs xor std_ulogic_vector(resize(unsigned(ui), 64));
182 function ppc_xoris (rs: std_ulogic_vector(63 downto 0); ui: std_ulogic_vector(15 downto 0)) return std_ulogic_vector is
184 return rs xor std_ulogic_vector(shift_left(resize(unsigned(ui), 64), 16));
187 function ppc_and (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
192 function ppc_xor (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
197 function ppc_nand (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
202 function ppc_or (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
207 function ppc_nor (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
212 function ppc_andc (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
214 return rs and not(rb);
217 function ppc_eqv (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
219 return not(rs xor rb);
222 function ppc_orc (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
224 return rs or not(rb);
227 function ppc_extsb (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
229 return std_ulogic_vector(resize(signed(rs(7 downto 0)), rs'length));
232 function ppc_extsh (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
234 return std_ulogic_vector(resize(signed(rs(15 downto 0)), rs'length));
237 function ppc_extsw (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
239 return std_ulogic_vector(resize(signed(rs(31 downto 0)), rs'length));
242 function ppc_cntlzw (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
244 return std_ulogic_vector(to_unsigned(fls_32(rs(31 downto 0)), rs'length));
247 function ppc_cnttzw (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
249 return std_ulogic_vector(to_unsigned(ffs_32(rs(31 downto 0)), rs'length));
252 function ppc_cntlzd (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
254 return std_ulogic_vector(to_unsigned(fls_64(rs), rs'length));
257 function ppc_cnttzd (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
259 return std_ulogic_vector(to_unsigned(ffs_64(rs), rs'length));
262 function ppc_popcntb (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
263 variable ret: std_ulogic_vector (rs'range);
264 variable hi: integer;
265 variable lo: integer;
267 ret := (others => '0');
272 ret(hi downto lo) := popcnt8(rs(hi downto lo));
278 function ppc_popcntw (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
279 variable ret: std_ulogic_vector (rs'range);
280 variable hi: integer;
281 variable lo: integer;
283 ret := (others => '0');
288 ret(hi downto lo) := popcnt32(rs(hi downto lo));
294 function ppc_popcntd (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
299 function ppc_prtyd (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
300 variable tmp : std_ulogic;
301 variable ret : std_ulogic_vector(63 downto 0);
303 ret := (others => '0');
307 tmp := tmp xor rs(i*8);
314 function ppc_prtyw (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
315 variable tmp : std_ulogic;
316 variable ret : std_ulogic_vector(63 downto 0);
318 ret := (others => '0');
322 tmp := tmp xor rs(i*8);
328 tmp := tmp xor rs(i*8);
335 function ppc_rlwinm (rs: std_ulogic_vector(63 downto 0); sh, mb, me: std_ulogic_vector(4 downto 0)) return std_ulogic_vector is
336 variable hi, lo : integer;
337 variable tmp1, tmp2 : std_ulogic_vector(63 downto 0);
339 hi := 31 - to_integer(unsigned(mb));
340 lo := 31 - to_integer(unsigned(me));
341 tmp1 := rs(31 downto 0) & rs(31 downto 0);
342 tmp1 := std_ulogic_vector(rotate_left(unsigned(tmp1), to_integer(unsigned(sh))));
343 tmp2 := (others => '0');
346 for i in 0 to 63 loop
347 if i <= hi or i >= lo then
352 for i in 0 to 63 loop
353 if i >= lo and i <= hi then
361 function ppc_rlwnm (rs, rb: std_ulogic_vector(63 downto 0); mb, me: std_ulogic_vector(4 downto 0)) return std_ulogic_vector is
362 variable hi, lo : integer;
363 variable tmp1, tmp2 : std_ulogic_vector(63 downto 0);
364 variable n : integer;
366 hi := 31 - to_integer(unsigned(mb));
367 lo := 31 - to_integer(unsigned(me));
368 n := to_integer(unsigned(rb(4 downto 0)));
369 tmp1 := rs(31 downto 0) & rs(31 downto 0);
370 tmp1 := std_ulogic_vector(rotate_left(unsigned(tmp1), n));
371 tmp2 := (others => '0');
374 for i in 0 to 63 loop
375 if i <= hi or i >= lo then
380 for i in 0 to 63 loop
381 if i >= lo and i <= hi then
389 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
390 variable hi, lo : integer;
391 variable tmp1, tmp2 : std_ulogic_vector(63 downto 0);
393 hi := 31 - to_integer(unsigned(mb));
394 lo := 31 - to_integer(unsigned(me));
395 tmp1 := rs(31 downto 0) & rs(31 downto 0);
396 tmp1 := std_ulogic_vector(rotate_left(unsigned(tmp1), to_integer(unsigned(sh))));
400 for i in 0 to 63 loop
401 if i <= hi or i >= lo then
406 for i in 0 to 63 loop
407 if i >= lo and i <= hi then
415 function ppc_rldicl (rs: std_ulogic_vector(63 downto 0); sh, mb: std_ulogic_vector(5 downto 0)) return std_ulogic_vector is
416 variable hi : integer;
417 variable tmp1, tmp2 : std_ulogic_vector(63 downto 0);
419 hi := 63-to_integer(unsigned(mb));
420 tmp1 := std_ulogic_vector(rotate_left(unsigned(rs), to_integer(unsigned(sh))));
421 tmp2 := (others => '0');
422 for i in 0 to 63 loop
430 function ppc_rldicr (rs: std_ulogic_vector(63 downto 0); sh, me: std_ulogic_vector(5 downto 0)) return std_ulogic_vector is
431 variable lo : integer;
432 variable tmp1, tmp2 : std_ulogic_vector(63 downto 0);
434 lo := 63-to_integer(unsigned(me));
435 tmp1 := std_ulogic_vector(rotate_left(unsigned(rs), to_integer(unsigned(sh))));
436 tmp2 := (others => '0');
437 for i in 0 to 63 loop
445 function ppc_rldic (rs: std_ulogic_vector(63 downto 0); sh, mb: std_ulogic_vector(5 downto 0)) return std_ulogic_vector is
446 variable hi, lo : integer;
447 variable tmp1, tmp2 : std_ulogic_vector(63 downto 0);
449 hi := 63-to_integer(unsigned(mb));
450 lo := to_integer(unsigned(sh));
451 tmp1 := std_ulogic_vector(rotate_left(unsigned(rs), to_integer(unsigned(sh))));
452 tmp2 := (others => '0');
455 for i in 0 to 63 loop
456 if i <= hi or i >= lo then
461 for i in 0 to 63 loop
462 if i >= lo and i <= hi then
470 function ppc_rldcl (rs, rb: std_ulogic_vector(63 downto 0); mb: std_ulogic_vector(5 downto 0)) return std_ulogic_vector is
471 variable hi : integer;
472 variable tmp1, tmp2 : std_ulogic_vector(63 downto 0);
474 hi := 63-to_integer(unsigned(mb));
475 tmp1 := std_ulogic_vector(rotate_left(unsigned(rs), to_integer(unsigned(rb(5 downto 0)))));
476 tmp2 := (others => '0');
477 for i in 0 to 63 loop
485 function ppc_rldcr (rs, rb: std_ulogic_vector(63 downto 0); me: std_ulogic_vector(5 downto 0)) return std_ulogic_vector is
486 variable lo : integer;
487 variable tmp1, tmp2 : std_ulogic_vector(63 downto 0);
489 lo := 63-to_integer(unsigned(me));
490 tmp1 := std_ulogic_vector(rotate_left(unsigned(rs), to_integer(unsigned(rb(5 downto 0)))));
491 tmp2 := (others => '0');
492 for i in 0 to 63 loop
500 function ppc_rldimi (ra, rs: std_ulogic_vector(63 downto 0); sh, mb: std_ulogic_vector(5 downto 0)) return std_ulogic_vector is
501 variable hi, lo : integer;
502 variable tmp1, tmp2 : std_ulogic_vector(rs'range);
504 hi := 63-to_integer(unsigned(mb));
505 lo := to_integer(unsigned(sh));
506 tmp1 := std_ulogic_vector(rotate_left(unsigned(rs), lo));
510 for i in 0 to 63 loop
511 if i <= hi or i >= lo then
516 for i in 0 to 63 loop
517 if i >= lo and i <= hi then
525 function ppc_slw (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
526 variable n : integer;
527 variable tmp : unsigned(31 downto 0);
529 n := to_integer(unsigned(rb(5 downto 0)));
530 tmp := shift_left(unsigned(rs(31 downto 0)), n);
532 return (63 downto 32 => '0') & std_ulogic_vector(tmp);
535 function ppc_srw (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
536 variable n : integer;
537 variable tmp : unsigned(31 downto 0);
539 n := to_integer(unsigned(rb(5 downto 0)));
540 tmp := shift_right(unsigned(rs(31 downto 0)), n);
542 return (63 downto 32 => '0') & std_ulogic_vector(tmp);
545 function ppc_srawi (rs : std_ulogic_vector(63 downto 0); sh: std_ulogic_vector(5 downto 0)) return std_ulogic_vector is
546 variable n : integer;
547 variable tmp : signed(31 downto 0);
548 variable mask : std_ulogic_vector(63 downto 0);
549 variable carry: std_ulogic;
551 n := to_integer(unsigned(sh));
552 tmp := shift_right(signed(rs(31 downto 0)), n);
554 mask := (others => '0');
555 for i in 0 to 63 loop
560 carry := '0' when (rs and mask) = (63 downto 0 => '0') else rs(31);
562 return carry & std_ulogic_vector(resize(tmp, rs'length));
565 function ppc_sraw (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
566 variable n : natural;
567 variable tmp : signed(31 downto 0);
568 variable mask : std_ulogic_vector(63 downto 0);
569 variable carry: std_ulogic;
571 n := to_integer(unsigned(rb(5 downto 0)));
572 tmp := shift_right(signed(rs(31 downto 0)), n);
574 mask := (others => '0');
575 for i in 0 to 63 loop
580 carry := or (rs and mask) and rs(31);
581 return carry & std_ulogic_vector(resize(tmp, rs'length));
584 function ppc_sld (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
585 variable n : integer;
587 n := to_integer(unsigned(rb(6 downto 0)));
588 return std_ulogic_vector(shift_left(unsigned(rs), n));
591 function ppc_srd (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
592 variable n : integer;
594 n := to_integer(unsigned(rb(6 downto 0)));
595 return std_ulogic_vector(shift_right(unsigned(rs), n));
598 function ppc_sradi (rs: std_ulogic_vector(63 downto 0); sh: std_ulogic_vector(5 downto 0)) return std_ulogic_vector is
599 variable n : integer;
600 variable carry: std_ulogic;
601 variable mask : std_ulogic_vector(63 downto 0);
603 n := to_integer(unsigned(sh));
605 mask := (others => '0');
606 for i in 0 to 63 loop
611 carry := '0' when (rs and mask) = (63 downto 0 => '0') else rs(63);
613 return carry & std_ulogic_vector(shift_right(signed(rs), n));
616 function ppc_srad (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
617 variable n : integer;
618 variable carry: std_ulogic;
619 variable mask : std_ulogic_vector(63 downto 0);
621 n := to_integer(unsigned(rb(6 downto 0)));
623 mask := (others => '0');
624 for i in 0 to 63 loop
629 carry := '0' when (rs and mask) = (63 downto 0 => '0') else rs(63);
631 return carry & std_ulogic_vector(shift_right(signed(rs), n));
634 -- Not sure how to better communicate the top 64 bits of the result is unused
635 function ppc_mulld (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
636 variable tmp: signed(127 downto 0);
638 tmp := signed(ra) * signed(rb);
639 return std_ulogic_vector(tmp(63 downto 0));
642 -- Not sure how to better communicate the top 64 bits of the result is unused
643 function ppc_mulhd (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
644 variable tmp: signed(127 downto 0);
646 tmp := signed(ra) * signed(rb);
647 return std_ulogic_vector(tmp(127 downto 64));
650 -- Not sure how to better communicate the top 64 bits of the result is unused
651 function ppc_mulhdu (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
652 variable tmp: unsigned(127 downto 0);
654 tmp := unsigned(ra) * unsigned(rb);
655 return std_ulogic_vector(tmp(127 downto 64));
658 -- Not sure how to better communicate the top 16 bits of the result is unused
659 function ppc_mulli (ra: std_ulogic_vector(63 downto 0); si: std_ulogic_vector(15 downto 0)) return std_ulogic_vector is
660 variable tmp: signed(79 downto 0);
662 tmp := signed(ra) * signed(si);
663 return std_ulogic_vector(tmp(63 downto 0));
666 function ppc_mullw (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
668 return std_ulogic_vector(signed(ra(31 downto 0)) * signed(rb(31 downto 0)));
671 function ppc_mulhw (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
672 variable tmp: signed(63 downto 0);
674 tmp := signed(ra(31 downto 0)) * signed(rb(31 downto 0));
675 return std_ulogic_vector(tmp(63 downto 32)) & std_ulogic_vector(tmp(63 downto 32));
678 function ppc_mulhwu (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
679 variable tmp: unsigned(63 downto 0);
681 tmp := unsigned(ra(31 downto 0)) * unsigned(rb(31 downto 0));
682 return std_ulogic_vector(tmp(63 downto 32)) & std_ulogic_vector(tmp(63 downto 32));
685 function ppc_cmpi (l: std_ulogic; ra: std_ulogic_vector(63 downto 0); si: std_ulogic_vector(15 downto 0);
686 so: std_ulogic) return std_ulogic_vector is
687 variable tmp: signed(ra'range);
691 tmp := resize(signed(ra(31 downto 0)), tmp'length);
694 return ppc_signed_compare(tmp, resize(signed(si), tmp'length), so);
697 function ppc_cmp (l: std_ulogic; ra, rb: std_ulogic_vector(63 downto 0);
698 so: std_ulogic) return std_ulogic_vector is
699 variable tmpa, tmpb: signed(ra'range);
704 tmpa := resize(signed(ra(31 downto 0)), ra'length);
705 tmpb := resize(signed(rb(31 downto 0)), ra'length);
708 return ppc_signed_compare(tmpa, tmpb, so);
711 function ppc_cmpli (l: std_ulogic; ra: std_ulogic_vector(63 downto 0); si: std_ulogic_vector(15 downto 0);
712 so: std_ulogic) return std_ulogic_vector is
713 variable tmp: unsigned(ra'range);
717 tmp := resize(unsigned(ra(31 downto 0)), tmp'length);
720 return ppc_unsigned_compare(tmp, resize(unsigned(si), tmp'length), so);
723 function ppc_cmpl (l: std_ulogic; ra, rb: std_ulogic_vector(63 downto 0);
724 so: std_ulogic) return std_ulogic_vector is
725 variable tmpa, tmpb: unsigned(ra'range);
727 tmpa := unsigned(ra);
728 tmpb := unsigned(rb);
730 tmpa := resize(unsigned(ra(31 downto 0)), ra'length);
731 tmpb := resize(unsigned(rb(31 downto 0)), ra'length);
734 return ppc_unsigned_compare(tmpa, tmpb, so);
737 function ppc_cmpb (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
738 variable ret: std_ulogic_vector (rs'range);
739 variable hi: integer;
740 variable lo: integer;
745 ret(hi downto lo) := cmp_one_byte(rs(hi downto lo), rb(hi downto lo));
751 function ppc_cmpeqb (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
752 variable match: std_ulogic;
758 if ra(7 downto 0) = rb(j + 7 downto j) then
762 return '0' & match & "00";
765 function ppc_cmprb (ra, rb: std_ulogic_vector(63 downto 0); l: std_ulogic) return std_ulogic_vector is
766 variable match: std_ulogic;
767 variable v: unsigned(7 downto 0);
770 v := unsigned(ra(7 downto 0));
771 if v >= unsigned(rb(7 downto 0)) and v <= unsigned(rb(15 downto 8)) then
773 elsif l = '1' and v >= unsigned(rb(23 downto 16)) and v <= unsigned(rb(31 downto 24)) then
776 return '0' & match & "00";
780 function ppc_divw (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
781 variable tmp: signed(31 downto 0);
783 tmp := signed(ra(31 downto 0)) / signed(rb(31 downto 0));
785 return (63 downto 32 => '0') & std_ulogic_vector(tmp);
788 function ppc_divdu (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
789 variable tmp: unsigned(63 downto 0) := (others => '0');
791 if unsigned(rb) /= 0 then
792 tmp := unsigned(ra) / unsigned(rb);
795 return std_ulogic_vector(tmp);
798 function ppc_divd (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
799 variable tmp: signed(63 downto 0) := (others => '0');
801 if signed(rb) /= 0 then
802 tmp := signed(ra) / signed(rb);
805 return std_ulogic_vector(tmp);
808 function ppc_divwu (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
809 variable tmp: unsigned(31 downto 0) := (others => '0');
811 if unsigned(rb(31 downto 0)) /= 0 then
812 tmp := unsigned(ra(31 downto 0)) / unsigned(rb(31 downto 0));
815 return std_ulogic_vector(resize(tmp, ra'length));
818 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 std_ulogic is
819 variable crfield: integer;
820 variable crbit_match: std_ulogic;
821 variable ctr_not_zero: std_ulogic;
822 variable ctr_ok: std_ulogic;
823 variable cond_ok: std_ulogic;
825 crfield := to_integer(unsigned(bi));
827 crbit_match := '1' when cr(31-crfield) = bo(4-1) else '0';
828 -- We check this before it is decremented
829 ctr_not_zero := '1' when ctr /= x"0000000000000001" else '0';
830 ctr_ok := bo(4-2) or (ctr_not_zero xor bo(4-3));
831 cond_ok := bo(4-0) or crbit_match;
832 return ctr_ok and cond_ok;
835 end package body ppc_fx_insns;