forked from antonblanchard/microwatt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ppc_fx_insns.vhdl
811 lines (701 loc) · 28.7 KB
/
ppc_fx_insns.vhdl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
library work;
use work.helpers.all;
package ppc_fx_insns is
function ppc_addi (ra: std_ulogic_vector(63 downto 0); si: std_ulogic_vector(15 downto 0)) return std_ulogic_vector;
function ppc_addis (ra: std_ulogic_vector(63 downto 0); si: std_ulogic_vector(15 downto 0)) return std_ulogic_vector;
function ppc_add (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
function ppc_subf (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
function ppc_neg (ra: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
function ppc_addic (ra: std_ulogic_vector(63 downto 0); si: std_ulogic_vector(15 downto 0)) return std_ulogic_vector;
function ppc_adde (ra, rb: std_ulogic_vector(63 downto 0); carry: std_ulogic) return std_ulogic_vector;
function ppc_subfic (ra: std_ulogic_vector(63 downto 0); si: std_ulogic_vector(15 downto 0)) return std_ulogic_vector;
function ppc_subfc (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
function ppc_subfe (ra, rb: std_ulogic_vector(63 downto 0); carry: std_ulogic) return std_ulogic_vector;
function ppc_addze (ra: std_ulogic_vector(63 downto 0); carry: std_ulogic) return std_ulogic_vector;
function ppc_andi (rs: std_ulogic_vector(63 downto 0); ui: std_ulogic_vector(15 downto 0)) return std_ulogic_vector;
function ppc_andis (rs: std_ulogic_vector(63 downto 0); ui: std_ulogic_vector(15 downto 0)) return std_ulogic_vector;
function ppc_ori (rs: std_ulogic_vector(63 downto 0); ui: std_ulogic_vector(15 downto 0)) return std_ulogic_vector;
function ppc_oris (rs: std_ulogic_vector(63 downto 0); ui: std_ulogic_vector(15 downto 0)) return std_ulogic_vector;
function ppc_xori (rs: std_ulogic_vector(63 downto 0); ui: std_ulogic_vector(15 downto 0)) return std_ulogic_vector;
function ppc_xoris (rs: std_ulogic_vector(63 downto 0); ui: std_ulogic_vector(15 downto 0)) return std_ulogic_vector;
function ppc_and (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
function ppc_xor (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
function ppc_nand (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
function ppc_or (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
function ppc_nor (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
function ppc_andc (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
function ppc_eqv (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
function ppc_orc (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
function ppc_extsb (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
function ppc_extsh (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
function ppc_extsw (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
function ppc_cntlzw (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
function ppc_cnttzw (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
function ppc_cntlzd (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
function ppc_cnttzd (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
function ppc_popcntb (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
function ppc_popcntw (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
function ppc_popcntd (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
function ppc_prtyd (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
function ppc_prtyw (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
function ppc_rlwinm (rs: std_ulogic_vector(63 downto 0); sh, mb, me: std_ulogic_vector(4 downto 0)) return std_ulogic_vector;
function ppc_rlwnm (rs, rb: std_ulogic_vector(63 downto 0); mb, me: std_ulogic_vector(4 downto 0)) return std_ulogic_vector;
function ppc_rlwimi (ra, rs: std_ulogic_vector(63 downto 0); sh, mb, me: std_ulogic_vector(4 downto 0)) return std_ulogic_vector;
function ppc_rldicl (rs: std_ulogic_vector(63 downto 0); sh, mb: std_ulogic_vector(5 downto 0)) return std_ulogic_vector;
function ppc_rldicr (rs: std_ulogic_vector(63 downto 0); sh, me: std_ulogic_vector(5 downto 0)) return std_ulogic_vector;
function ppc_rldic (rs: std_ulogic_vector(63 downto 0); sh, mb: std_ulogic_vector(5 downto 0)) return std_ulogic_vector;
function ppc_rldcl (rs, rb: std_ulogic_vector(63 downto 0); mb: std_ulogic_vector(5 downto 0)) return std_ulogic_vector;
function ppc_rldcr (rs, rb: std_ulogic_vector(63 downto 0); me: std_ulogic_vector(5 downto 0)) return std_ulogic_vector;
function ppc_rldimi (ra, rs: std_ulogic_vector(63 downto 0); sh, mb: std_ulogic_vector(5 downto 0)) return std_ulogic_vector;
function ppc_slw (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
function ppc_srw (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
function ppc_srawi (rs : std_ulogic_vector(63 downto 0); sh: std_ulogic_vector(5 downto 0)) return std_ulogic_vector;
function ppc_sraw (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
function ppc_sld (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
function ppc_srd (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
function ppc_sradi (rs: std_ulogic_vector(63 downto 0); sh: std_ulogic_vector(5 downto 0)) return std_ulogic_vector;
function ppc_srad (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
function ppc_mulld (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
function ppc_mulhd (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
function ppc_mulhdu (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
function ppc_mulli (ra: std_ulogic_vector(63 downto 0); si: std_ulogic_vector(15 downto 0)) return std_ulogic_vector;
function ppc_mullw (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
function ppc_mulhw (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
function ppc_mulhwu (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
function ppc_cmpi (l: std_ulogic; ra: std_ulogic_vector(63 downto 0); si: std_ulogic_vector(15 downto 0);
so: std_ulogic) return std_ulogic_vector;
function ppc_cmp (l: std_ulogic; ra, rb: std_ulogic_vector(63 downto 0);
so: std_ulogic) return std_ulogic_vector;
function ppc_cmpli (l: std_ulogic; ra: std_ulogic_vector(63 downto 0); si: std_ulogic_vector(15 downto 0);
so: std_ulogic) return std_ulogic_vector;
function ppc_cmpl (l: std_ulogic; ra, rb: std_ulogic_vector(63 downto 0);
so: std_ulogic) return std_ulogic_vector;
function ppc_cmpb (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
function ppc_divw (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
function ppc_divdu (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
function ppc_divd (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
function ppc_divwu (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector;
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;
end package ppc_fx_insns;
package body ppc_fx_insns is
function ppc_addi (ra: std_ulogic_vector(63 downto 0); si: std_ulogic_vector(15 downto 0)) return std_ulogic_vector is
begin
return std_ulogic_vector(signed(ra) + signed(si));
end;
function ppc_addic (ra: std_ulogic_vector(63 downto 0); si: std_ulogic_vector(15 downto 0)) return std_ulogic_vector is
begin
return std_logic_vector(resize(unsigned(ra), 65) + unsigned(resize(signed(si), 64)));
end;
function ppc_adde (ra, rb: std_ulogic_vector(63 downto 0); carry: std_ulogic) return std_ulogic_vector is
begin
return std_logic_vector(resize(unsigned(ra), 65) + resize(unsigned(rb), 65) + carry);
end;
function ppc_subfic (ra: std_ulogic_vector(63 downto 0); si: std_ulogic_vector(15 downto 0)) return std_ulogic_vector is
begin
return std_logic_vector(unsigned(resize(signed(si), 64)) + resize(unsigned(not(ra)), 65) + 1);
end;
function ppc_subfc (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
begin
return std_logic_vector(resize(unsigned(rb), 65) + resize(unsigned(not(ra)), 65) + 1);
end;
function ppc_subfe (ra, rb: std_ulogic_vector(63 downto 0); carry: std_ulogic) return std_ulogic_vector is
begin
return std_logic_vector(resize(unsigned(rb), 65) + resize(unsigned(not(ra)), 65) + carry);
end;
function ppc_addze (ra: std_ulogic_vector(63 downto 0); carry: std_ulogic) return std_ulogic_vector is
begin
return std_logic_vector(resize(unsigned(ra), 65) + carry);
end;
function ppc_addis (ra: std_ulogic_vector(63 downto 0); si: std_ulogic_vector(15 downto 0)) return std_ulogic_vector is
begin
return std_ulogic_vector(signed(ra) + shift_left(resize(signed(si), 32), 16));
end;
function ppc_add (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
begin
return std_ulogic_vector(signed(ra) + signed(rb));
end;
function ppc_subf (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
begin
return std_ulogic_vector(signed(rb) - signed(ra));
end;
function ppc_neg (ra: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
begin
return std_ulogic_vector(-signed(ra));
end;
function ppc_andi (rs: std_ulogic_vector(63 downto 0); ui: std_ulogic_vector(15 downto 0)) return std_ulogic_vector is
begin
return rs and std_ulogic_vector(resize(unsigned(ui), 64));
end;
function ppc_andis (rs: std_ulogic_vector(63 downto 0); ui: std_ulogic_vector(15 downto 0)) return std_ulogic_vector is
begin
return rs and std_ulogic_vector(shift_left(resize(unsigned(ui), 64), 16));
end;
function ppc_ori (rs: std_ulogic_vector(63 downto 0); ui: std_ulogic_vector(15 downto 0)) return std_ulogic_vector is
begin
return rs or std_ulogic_vector(resize(unsigned(ui), 64));
end;
function ppc_oris (rs: std_ulogic_vector(63 downto 0); ui: std_ulogic_vector(15 downto 0)) return std_ulogic_vector is
begin
return rs or std_ulogic_vector(shift_left(resize(unsigned(ui), 64), 16));
end;
function ppc_xori (rs: std_ulogic_vector(63 downto 0); ui: std_ulogic_vector(15 downto 0)) return std_ulogic_vector is
begin
return rs xor std_ulogic_vector(resize(unsigned(ui), 64));
end;
function ppc_xoris (rs: std_ulogic_vector(63 downto 0); ui: std_ulogic_vector(15 downto 0)) return std_ulogic_vector is
begin
return rs xor std_ulogic_vector(shift_left(resize(unsigned(ui), 64), 16));
end;
function ppc_and (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
begin
return rs and rb;
end;
function ppc_xor (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
begin
return rs xor rb;
end;
function ppc_nand (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
begin
return rs nand rb;
end;
function ppc_or (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
begin
return rs or rb;
end;
function ppc_nor (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
begin
return rs nor rb;
end;
function ppc_andc (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
begin
return rs and not(rb);
end;
function ppc_eqv (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
begin
return not(rs xor rb);
end;
function ppc_orc (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
begin
return rs or not(rb);
end;
function ppc_extsb (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
begin
return std_ulogic_vector(resize(signed(rs(7 downto 0)), rs'length));
end;
function ppc_extsh (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
begin
return std_ulogic_vector(resize(signed(rs(15 downto 0)), rs'length));
end;
function ppc_extsw (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
begin
return std_ulogic_vector(resize(signed(rs(31 downto 0)), rs'length));
end;
function ppc_cntlzw (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
begin
return std_ulogic_vector(to_unsigned(fls_32(rs(31 downto 0)), rs'length));
end;
function ppc_cnttzw (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
begin
return std_ulogic_vector(to_unsigned(ffs_32(rs(31 downto 0)), rs'length));
end;
function ppc_cntlzd (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
begin
return std_ulogic_vector(to_unsigned(fls_64(rs), rs'length));
end;
function ppc_cnttzd (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
begin
return std_ulogic_vector(to_unsigned(ffs_64(rs), rs'length));
end;
function ppc_popcntb (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
variable ret: std_ulogic_vector (rs'range);
variable hi: integer;
variable lo: integer;
begin
ret := (others => '0');
for i in 1 to 8 loop
hi := (8*i)-1;
lo := 8*(i-1);
ret(hi downto lo) := popcnt8(rs(hi downto lo));
end loop;
return ret;
end;
function ppc_popcntw (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
variable ret: std_ulogic_vector (rs'range);
variable hi: integer;
variable lo: integer;
begin
ret := (others => '0');
for i in 1 to 2 loop
hi := (32*i)-1;
lo := 32*(i-1);
ret(hi downto lo) := popcnt32(rs(hi downto lo));
end loop;
return ret;
end;
function ppc_popcntd (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
begin
return popcnt64(rs);
end;
function ppc_prtyd (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
variable tmp : std_ulogic;
variable ret : std_ulogic_vector(63 downto 0);
begin
ret := (others => '0');
tmp := '0';
for i in 0 to 7 loop
tmp := tmp xor rs(i*8);
end loop;
ret(0) := tmp;
return ret;
end;
function ppc_prtyw (rs: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
variable tmp : std_ulogic;
variable ret : std_ulogic_vector(63 downto 0);
begin
ret := (others => '0');
tmp := '0';
for i in 0 to 3 loop
tmp := tmp xor rs(i*8);
end loop;
ret(0) := tmp;
tmp := '0';
for i in 4 to 7 loop
tmp := tmp xor rs(i*8);
end loop;
ret(32) := tmp;
return ret;
end;
function ppc_rlwinm (rs: std_ulogic_vector(63 downto 0); sh, mb, me: std_ulogic_vector(4 downto 0)) return std_ulogic_vector is
variable hi, lo : integer;
variable tmp1, tmp2 : std_ulogic_vector(63 downto 0);
begin
hi := 31 - to_integer(unsigned(mb));
lo := 31 - to_integer(unsigned(me));
tmp1 := rs(31 downto 0) & rs(31 downto 0);
tmp1 := std_ulogic_vector(rotate_left(unsigned(tmp1), to_integer(unsigned(sh))));
tmp2 := (others => '0');
if hi < lo then
-- Mask wraps around
for i in 0 to 63 loop
if i <= hi or i >= lo then
tmp2(i) := tmp1(i);
end if;
end loop;
else
for i in 0 to 63 loop
if i >= lo and i <= hi then
tmp2(i) := tmp1(i);
end if;
end loop;
end if;
return tmp2;
end;
function ppc_rlwnm (rs, rb: std_ulogic_vector(63 downto 0); mb, me: std_ulogic_vector(4 downto 0)) return std_ulogic_vector is
variable hi, lo : integer;
variable tmp1, tmp2 : std_ulogic_vector(63 downto 0);
variable n : integer;
begin
hi := 31 - to_integer(unsigned(mb));
lo := 31 - to_integer(unsigned(me));
n := to_integer(unsigned(rb(4 downto 0)));
tmp1 := rs(31 downto 0) & rs(31 downto 0);
tmp1 := std_ulogic_vector(rotate_left(unsigned(tmp1), n));
tmp2 := (others => '0');
if hi < lo then
-- Mask wraps around
for i in 0 to 63 loop
if i <= hi or i >= lo then
tmp2(i) := tmp1(i);
end if;
end loop;
else
for i in 0 to 63 loop
if i >= lo and i <= hi then
tmp2(i) := tmp1(i);
end if;
end loop;
end if;
return tmp2;
end;
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
variable hi, lo : integer;
variable tmp1, tmp2 : std_ulogic_vector(63 downto 0);
begin
hi := 31 - to_integer(unsigned(mb));
lo := 31 - to_integer(unsigned(me));
tmp1 := rs(31 downto 0) & rs(31 downto 0);
tmp1 := std_ulogic_vector(rotate_left(unsigned(tmp1), to_integer(unsigned(sh))));
tmp2 := ra;
if hi < lo then
-- Mask wraps around
for i in 0 to 63 loop
if i <= hi or i >= lo then
tmp2(i) := tmp1(i);
end if;
end loop;
else
for i in 0 to 63 loop
if i >= lo and i <= hi then
tmp2(i) := tmp1(i);
end if;
end loop;
end if;
return tmp2;
end;
function ppc_rldicl (rs: std_ulogic_vector(63 downto 0); sh, mb: std_ulogic_vector(5 downto 0)) return std_ulogic_vector is
variable hi : integer;
variable tmp1, tmp2 : std_ulogic_vector(63 downto 0);
begin
hi := 63-to_integer(unsigned(mb));
tmp1 := std_ulogic_vector(rotate_left(unsigned(rs), to_integer(unsigned(sh))));
tmp2 := (others => '0');
for i in 0 to 63 loop
if i <= hi then
tmp2(i) := tmp1(i);
end if;
end loop;
return tmp2;
end;
function ppc_rldicr (rs: std_ulogic_vector(63 downto 0); sh, me: std_ulogic_vector(5 downto 0)) return std_ulogic_vector is
variable lo : integer;
variable tmp1, tmp2 : std_ulogic_vector(63 downto 0);
begin
lo := 63-to_integer(unsigned(me));
tmp1 := std_ulogic_vector(rotate_left(unsigned(rs), to_integer(unsigned(sh))));
tmp2 := (others => '0');
for i in 0 to 63 loop
if i >= lo then
tmp2(i) := tmp1(i);
end if;
end loop;
return tmp2;
end;
function ppc_rldic (rs: std_ulogic_vector(63 downto 0); sh, mb: std_ulogic_vector(5 downto 0)) return std_ulogic_vector is
variable hi, lo : integer;
variable tmp1, tmp2 : std_ulogic_vector(63 downto 0);
begin
hi := 63-to_integer(unsigned(mb));
lo := to_integer(unsigned(sh));
tmp1 := std_ulogic_vector(rotate_left(unsigned(rs), to_integer(unsigned(sh))));
tmp2 := (others => '0');
if hi < lo then
-- Mask wraps around
for i in 0 to 63 loop
if i <= hi or i >= lo then
tmp2(i) := tmp1(i);
end if;
end loop;
else
for i in 0 to 63 loop
if i >= lo and i <= hi then
tmp2(i) := tmp1(i);
end if;
end loop;
end if;
return tmp2;
end;
function ppc_rldcl (rs, rb: std_ulogic_vector(63 downto 0); mb: std_ulogic_vector(5 downto 0)) return std_ulogic_vector is
variable hi : integer;
variable tmp1, tmp2 : std_ulogic_vector(63 downto 0);
begin
hi := 63-to_integer(unsigned(mb));
tmp1 := std_ulogic_vector(rotate_left(unsigned(rs), to_integer(unsigned(rb(5 downto 0)))));
tmp2 := (others => '0');
for i in 0 to 63 loop
if i <= hi then
tmp2(i) := tmp1(i);
end if;
end loop;
return tmp2;
end;
function ppc_rldcr (rs, rb: std_ulogic_vector(63 downto 0); me: std_ulogic_vector(5 downto 0)) return std_ulogic_vector is
variable lo : integer;
variable tmp1, tmp2 : std_ulogic_vector(63 downto 0);
begin
lo := 63-to_integer(unsigned(me));
tmp1 := std_ulogic_vector(rotate_left(unsigned(rs), to_integer(unsigned(rb(5 downto 0)))));
tmp2 := (others => '0');
for i in 0 to 63 loop
if i >= lo then
tmp2(i) := tmp1(i);
end if;
end loop;
return tmp2;
end;
function ppc_rldimi (ra, rs: std_ulogic_vector(63 downto 0); sh, mb: std_ulogic_vector(5 downto 0)) return std_ulogic_vector is
variable hi, lo : integer;
variable tmp1, tmp2 : std_ulogic_vector(rs'range);
begin
hi := 63-to_integer(unsigned(mb));
lo := to_integer(unsigned(sh));
tmp1 := std_ulogic_vector(rotate_left(unsigned(rs), lo));
tmp2 := ra;
if hi < lo then
-- Mask wraps around
for i in 0 to 63 loop
if i <= hi or i >= lo then
tmp2(i) := tmp1(i);
end if;
end loop;
else
for i in 0 to 63 loop
if i >= lo and i <= hi then
tmp2(i) := tmp1(i);
end if;
end loop;
end if;
return tmp2;
end;
function ppc_slw (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
variable n : integer;
variable tmp : unsigned(31 downto 0);
begin
n := to_integer(unsigned(rb(5 downto 0)));
tmp := shift_left(unsigned(rs(31 downto 0)), n);
return (63 downto 32 => '0') & std_ulogic_vector(tmp);
end;
function ppc_srw (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
variable n : integer;
variable tmp : unsigned(31 downto 0);
begin
n := to_integer(unsigned(rb(5 downto 0)));
tmp := shift_right(unsigned(rs(31 downto 0)), n);
return (63 downto 32 => '0') & std_ulogic_vector(tmp);
end;
function ppc_srawi (rs : std_ulogic_vector(63 downto 0); sh: std_ulogic_vector(5 downto 0)) return std_ulogic_vector is
variable n : integer;
variable tmp : signed(31 downto 0);
variable mask : std_ulogic_vector(63 downto 0);
variable carry: std_ulogic;
begin
n := to_integer(unsigned(sh));
tmp := shift_right(signed(rs(31 downto 0)), n);
-- what about n = 0?
mask := (others => '0');
for i in 0 to 63 loop
if i < n then
mask(i) := '1';
end if;
end loop;
carry := '0' when (rs and mask) = (63 downto 0 => '0') else rs(31);
return carry & std_ulogic_vector(resize(tmp, rs'length));
end;
function ppc_sraw (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
variable n : natural;
variable tmp : signed(31 downto 0);
variable mask : std_ulogic_vector(63 downto 0);
variable carry: std_ulogic;
begin
n := to_integer(unsigned(rb(5 downto 0)));
tmp := shift_right(signed(rs(31 downto 0)), n);
-- what about n = 0?
mask := (others => '0');
for i in 0 to 63 loop
if i < n then
mask(i) := '1';
end if;
end loop;
carry := or (rs and mask) and rs(31);
return carry & std_ulogic_vector(resize(tmp, rs'length));
end;
function ppc_sld (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
variable n : integer;
begin
n := to_integer(unsigned(rb(6 downto 0)));
return std_ulogic_vector(shift_left(unsigned(rs), n));
end;
function ppc_srd (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
variable n : integer;
begin
n := to_integer(unsigned(rb(6 downto 0)));
return std_ulogic_vector(shift_right(unsigned(rs), n));
end;
function ppc_sradi (rs: std_ulogic_vector(63 downto 0); sh: std_ulogic_vector(5 downto 0)) return std_ulogic_vector is
variable n : integer;
variable carry: std_ulogic;
variable mask : std_ulogic_vector(63 downto 0);
begin
n := to_integer(unsigned(sh));
-- what about n = 0?
mask := (others => '0');
for i in 0 to 63 loop
if i < n then
mask(i) := '1';
end if;
end loop;
carry := '0' when (rs and mask) = (63 downto 0 => '0') else rs(63);
return carry & std_ulogic_vector(shift_right(signed(rs), n));
end;
function ppc_srad (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
variable n : integer;
variable carry: std_ulogic;
variable mask : std_ulogic_vector(63 downto 0);
begin
n := to_integer(unsigned(rb(6 downto 0)));
-- what about n = 0?
mask := (others => '0');
for i in 0 to 63 loop
if i < n then
mask(i) := '1';
end if;
end loop;
carry := '0' when (rs and mask) = (63 downto 0 => '0') else rs(63);
return carry & std_ulogic_vector(shift_right(signed(rs), n));
end;
-- Not sure how to better communicate the top 64 bits of the result is unused
function ppc_mulld (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
variable tmp: signed(127 downto 0);
begin
tmp := signed(ra) * signed(rb);
return std_ulogic_vector(tmp(63 downto 0));
end;
-- Not sure how to better communicate the top 64 bits of the result is unused
function ppc_mulhd (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
variable tmp: signed(127 downto 0);
begin
tmp := signed(ra) * signed(rb);
return std_ulogic_vector(tmp(127 downto 64));
end;
-- Not sure how to better communicate the top 64 bits of the result is unused
function ppc_mulhdu (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
variable tmp: unsigned(127 downto 0);
begin
tmp := unsigned(ra) * unsigned(rb);
return std_ulogic_vector(tmp(127 downto 64));
end;
-- Not sure how to better communicate the top 16 bits of the result is unused
function ppc_mulli (ra: std_ulogic_vector(63 downto 0); si: std_ulogic_vector(15 downto 0)) return std_ulogic_vector is
variable tmp: signed(79 downto 0);
begin
tmp := signed(ra) * signed(si);
return std_ulogic_vector(tmp(63 downto 0));
end;
function ppc_mullw (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
begin
return std_ulogic_vector(signed(ra(31 downto 0)) * signed(rb(31 downto 0)));
end;
function ppc_mulhw (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
variable tmp: signed(63 downto 0);
begin
tmp := signed(ra(31 downto 0)) * signed(rb(31 downto 0));
return std_ulogic_vector(tmp(63 downto 32)) & std_ulogic_vector(tmp(63 downto 32));
end;
function ppc_mulhwu (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
variable tmp: unsigned(63 downto 0);
begin
tmp := unsigned(ra(31 downto 0)) * unsigned(rb(31 downto 0));
return std_ulogic_vector(tmp(63 downto 32)) & std_ulogic_vector(tmp(63 downto 32));
end;
function ppc_cmpi (l: std_ulogic; ra: std_ulogic_vector(63 downto 0); si: std_ulogic_vector(15 downto 0);
so: std_ulogic) return std_ulogic_vector is
variable tmp: signed(ra'range);
begin
tmp := signed(ra);
if l = '0' then
tmp := resize(signed(ra(31 downto 0)), tmp'length);
end if;
return ppc_signed_compare(tmp, resize(signed(si), tmp'length), so);
end;
function ppc_cmp (l: std_ulogic; ra, rb: std_ulogic_vector(63 downto 0);
so: std_ulogic) return std_ulogic_vector is
variable tmpa, tmpb: signed(ra'range);
begin
tmpa := signed(ra);
tmpb := signed(rb);
if l = '0' then
tmpa := resize(signed(ra(31 downto 0)), ra'length);
tmpb := resize(signed(rb(31 downto 0)), ra'length);
end if;
return ppc_signed_compare(tmpa, tmpb, so);
end;
function ppc_cmpli (l: std_ulogic; ra: std_ulogic_vector(63 downto 0); si: std_ulogic_vector(15 downto 0);
so: std_ulogic) return std_ulogic_vector is
variable tmp: unsigned(ra'range);
begin
tmp := unsigned(ra);
if l = '0' then
tmp := resize(unsigned(ra(31 downto 0)), tmp'length);
end if;
return ppc_unsigned_compare(tmp, resize(unsigned(si), tmp'length), so);
end;
function ppc_cmpl (l: std_ulogic; ra, rb: std_ulogic_vector(63 downto 0);
so: std_ulogic) return std_ulogic_vector is
variable tmpa, tmpb: unsigned(ra'range);
begin
tmpa := unsigned(ra);
tmpb := unsigned(rb);
if l = '0' then
tmpa := resize(unsigned(ra(31 downto 0)), ra'length);
tmpb := resize(unsigned(rb(31 downto 0)), ra'length);
end if;
return ppc_unsigned_compare(tmpa, tmpb, so);
end;
function ppc_cmpb (rs, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
variable ret: std_ulogic_vector (rs'range);
variable hi: integer;
variable lo: integer;
begin
for i in 1 to 8 loop
hi := (8*i)-1;
lo := 8*(i-1);
ret(hi downto lo) := cmp_one_byte(rs(hi downto lo), rb(hi downto lo));
end loop;
return ret;
end;
-- Not synthesizable
function ppc_divw (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
variable tmp: signed(31 downto 0);
begin
tmp := signed(ra(31 downto 0)) / signed(rb(31 downto 0));
return (63 downto 32 => '0') & std_ulogic_vector(tmp);
end;
function ppc_divdu (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
variable tmp: unsigned(63 downto 0) := (others => '0');
begin
if unsigned(rb) /= 0 then
tmp := unsigned(ra) / unsigned(rb);
end if;
return std_ulogic_vector(tmp);
end;
function ppc_divd (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
variable tmp: signed(63 downto 0) := (others => '0');
begin
if signed(rb) /= 0 then
tmp := signed(ra) / signed(rb);
end if;
return std_ulogic_vector(tmp);
end;
function ppc_divwu (ra, rb: std_ulogic_vector(63 downto 0)) return std_ulogic_vector is
variable tmp: unsigned(31 downto 0) := (others => '0');
begin
if unsigned(rb(31 downto 0)) /= 0 then
tmp := unsigned(ra(31 downto 0)) / unsigned(rb(31 downto 0));
end if;
return std_ulogic_vector(resize(tmp, ra'length));
end;
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
variable crfield: integer;
variable crbit_match: std_ulogic;
variable ctr_not_zero: std_ulogic;
variable ctr_ok: std_ulogic;
variable cond_ok: std_ulogic;
variable ret: integer;
begin
crfield := to_integer(unsigned(bi));
-- BE bit numbering
crbit_match := '1' when cr(31-crfield) = bo(4-1) else '0';
-- We check this before it is decremented
ctr_not_zero := '1' when ctr /= x"0000000000000001" else '0';
ctr_ok := bo(4-2) or (ctr_not_zero xor bo(4-3));
cond_ok := bo(4-0) or crbit_match;
if ctr_ok = '1' and cond_ok = '1' then
ret := 1;
else
ret := 0;
end if;
return ret;
end;
end package body ppc_fx_insns;