@@ -487,6 +487,46 @@ static DecodeStatus decodeVersionImm(MCInst &Inst, unsigned Imm,
487
487
//
488
488
// ===----------------------------------------------------------------------===//
489
489
490
+ template <typename InsnType>
491
+ static DecodeStatus
492
+ tryDecodeInst (const AMDGPUDisassembler *Asm, const uint8_t *Table, MCInst &MI,
493
+ InsnType Inst, uint64_t Address, raw_ostream &Comments) {
494
+ assert (MI.getOpcode () == 0 );
495
+ assert (MI.getNumOperands () == 0 );
496
+ MCInst TmpInst;
497
+ Asm->setHasLiteral (false );
498
+ const auto SavedBytes = Asm->getBytes ();
499
+
500
+ SmallString<64 > LocalComments;
501
+ raw_svector_ostream LocalCommentStream (LocalComments);
502
+ Asm->CommentStream = &LocalCommentStream;
503
+
504
+ DecodeStatus Res =
505
+ decodeInstruction (Table, TmpInst, Inst, Address, this , STI);
506
+
507
+ Asm->CommentStream = nullptr ;
508
+
509
+ if (Res != MCDisassembler::Fail) {
510
+ MI = TmpInst;
511
+ Comments << LocalComments;
512
+ return MCDisassembler::Success;
513
+ }
514
+ Asm->setBytes (SavedBytes);
515
+ return MCDisassembler::Fail;
516
+ }
517
+
518
+ template <typename InsnType>
519
+ static DecodeStatus tryDecodeInst (const AMDGPUDisassembler *Asm,
520
+ const uint8_t *Table1, const uint8_t *Table2,
521
+ MCInst &MI, InsnType Inst, uint64_t Address,
522
+ raw_ostream &Comments) {
523
+ for (const uint8_t *T : {Table1, Table2}) {
524
+ if (DecodeStatus Res = tryDecodeInst (Asm, T, MI, Inst, Address, Comments))
525
+ return Res;
526
+ }
527
+ return MCDisassembler::Fail;
528
+ }
529
+
490
530
template <typename T> static inline T eatBytes (ArrayRef<uint8_t >& Bytes) {
491
531
assert (Bytes.size () >= sizeof (T));
492
532
const auto Res =
@@ -538,17 +578,17 @@ DecodeStatus AMDGPUDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
538
578
DecoderUInt128 DecW = eat12Bytes (Bytes);
539
579
540
580
if (isGFX11 () &&
541
- tryDecodeInst (DecoderTableGFX1196, DecoderTableGFX11_FAKE1696, MI ,
542
- DecW, Address, CS))
581
+ tryDecodeInst (Asm, DecoderTableGFX1196, DecoderTableGFX11_FAKE1696 ,
582
+ MI, DecW, Address, CS))
543
583
break ;
544
584
545
585
if (isGFX12 () &&
546
- tryDecodeInst (DecoderTableGFX1296, DecoderTableGFX12_FAKE1696, MI ,
547
- DecW, Address, CS))
586
+ tryDecodeInst (Asm, DecoderTableGFX1296, DecoderTableGFX12_FAKE1696 ,
587
+ MI, DecW, Address, CS))
548
588
break ;
549
589
550
590
if (isGFX12 () &&
551
- tryDecodeInst (DecoderTableGFX12W6496, MI, DecW, Address, CS))
591
+ tryDecodeInst (Asm, DecoderTableGFX12W6496, MI, DecW, Address, CS))
552
592
break ;
553
593
554
594
// Reinitialize Bytes
@@ -557,7 +597,7 @@ DecodeStatus AMDGPUDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
557
597
} else if (Bytes.size () >= 16 &&
558
598
STI.hasFeature (AMDGPU::FeatureGFX950Insts)) {
559
599
DecoderUInt128 DecW = eat16Bytes (Bytes);
560
- if (tryDecodeInst (DecoderTableGFX940128, MI, DecW, Address, CS))
600
+ if (tryDecodeInst (Asm, DecoderTableGFX940128, MI, DecW, Address, CS))
561
601
break ;
562
602
563
603
// Reinitialize Bytes
@@ -568,58 +608,60 @@ DecodeStatus AMDGPUDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
568
608
const uint64_t QW = eatBytes<uint64_t >(Bytes);
569
609
570
610
if (STI.hasFeature (AMDGPU::FeatureGFX10_BEncoding) &&
571
- tryDecodeInst (DecoderTableGFX10_B64, MI, QW, Address, CS))
611
+ tryDecodeInst (Asm, DecoderTableGFX10_B64, MI, QW, Address, CS))
572
612
break ;
573
613
574
614
if (STI.hasFeature (AMDGPU::FeatureUnpackedD16VMem) &&
575
- tryDecodeInst (DecoderTableGFX80_UNPACKED64, MI, QW, Address, CS))
615
+ tryDecodeInst (Asm, DecoderTableGFX80_UNPACKED64, MI, QW, Address, CS))
576
616
break ;
577
617
578
618
if (STI.hasFeature (AMDGPU::FeatureGFX950Insts) &&
579
- tryDecodeInst (DecoderTableGFX95064, MI, QW, Address, CS))
619
+ tryDecodeInst (Asm, DecoderTableGFX95064, MI, QW, Address, CS))
580
620
break ;
581
621
582
622
// Some GFX9 subtargets repurposed the v_mad_mix_f32, v_mad_mixlo_f16 and
583
623
// v_mad_mixhi_f16 for FMA variants. Try to decode using this special
584
624
// table first so we print the correct name.
585
625
if (STI.hasFeature (AMDGPU::FeatureFmaMixInsts) &&
586
- tryDecodeInst (DecoderTableGFX9_DL64, MI, QW, Address, CS))
626
+ tryDecodeInst (Asm, DecoderTableGFX9_DL64, MI, QW, Address, CS))
587
627
break ;
588
628
589
629
if (STI.hasFeature (AMDGPU::FeatureGFX940Insts) &&
590
- tryDecodeInst (DecoderTableGFX94064, MI, QW, Address, CS))
630
+ tryDecodeInst (Asm, DecoderTableGFX94064, MI, QW, Address, CS))
591
631
break ;
592
632
593
633
if (STI.hasFeature (AMDGPU::FeatureGFX90AInsts) &&
594
- tryDecodeInst (DecoderTableGFX90A64, MI, QW, Address, CS))
634
+ tryDecodeInst (Asm, DecoderTableGFX90A64, MI, QW, Address, CS))
595
635
break ;
596
636
597
637
if ((isVI () || isGFX9 ()) &&
598
- tryDecodeInst (DecoderTableGFX864, MI, QW, Address, CS))
638
+ tryDecodeInst (Asm, DecoderTableGFX864, MI, QW, Address, CS))
599
639
break ;
600
640
601
- if (isGFX9 () && tryDecodeInst (DecoderTableGFX964, MI, QW, Address, CS))
641
+ if (isGFX9 () &&
642
+ tryDecodeInst (Asm, DecoderTableGFX964, MI, QW, Address, CS))
602
643
break ;
603
644
604
- if (isGFX10 () && tryDecodeInst (DecoderTableGFX1064, MI, QW, Address, CS))
645
+ if (isGFX10 () &&
646
+ tryDecodeInst (Asm, DecoderTableGFX1064, MI, QW, Address, CS))
605
647
break ;
606
648
607
649
if (isGFX12 () &&
608
- tryDecodeInst (DecoderTableGFX1264, DecoderTableGFX12_FAKE1664, MI, QW ,
609
- Address, CS))
650
+ tryDecodeInst (Asm, DecoderTableGFX1264, DecoderTableGFX12_FAKE1664 ,
651
+ MI, QW, Address, CS))
610
652
break ;
611
653
612
654
if (isGFX11 () &&
613
- tryDecodeInst (DecoderTableGFX1164, DecoderTableGFX11_FAKE1664, MI, QW ,
614
- Address, CS))
655
+ tryDecodeInst (Asm, DecoderTableGFX1164, DecoderTableGFX11_FAKE1664 ,
656
+ MI, QW, Address, CS))
615
657
break ;
616
658
617
659
if (isGFX11 () &&
618
- tryDecodeInst (DecoderTableGFX11W6464, MI, QW, Address, CS))
660
+ tryDecodeInst (Asm, DecoderTableGFX11W6464, MI, QW, Address, CS))
619
661
break ;
620
662
621
663
if (isGFX12 () &&
622
- tryDecodeInst (DecoderTableGFX12W6464, MI, QW, Address, CS))
664
+ tryDecodeInst (Asm, DecoderTableGFX12W6464, MI, QW, Address, CS))
623
665
break ;
624
666
625
667
// Reinitialize Bytes
@@ -631,38 +673,40 @@ DecodeStatus AMDGPUDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
631
673
const uint32_t DW = eatBytes<uint32_t >(Bytes);
632
674
633
675
if ((isVI () || isGFX9 ()) &&
634
- tryDecodeInst (DecoderTableGFX832, MI, DW, Address, CS))
676
+ tryDecodeInst (Asm, DecoderTableGFX832, MI, DW, Address, CS))
635
677
break ;
636
678
637
- if (tryDecodeInst (DecoderTableAMDGPU32, MI, DW, Address, CS))
679
+ if (tryDecodeInst (Asm, DecoderTableAMDGPU32, MI, DW, Address, CS))
638
680
break ;
639
681
640
- if (isGFX9 () && tryDecodeInst (DecoderTableGFX932, MI, DW, Address, CS))
682
+ if (isGFX9 () &&
683
+ tryDecodeInst (Asm, DecoderTableGFX932, MI, DW, Address, CS))
641
684
break ;
642
685
643
686
if (STI.hasFeature (AMDGPU::FeatureGFX950Insts) &&
644
- tryDecodeInst (DecoderTableGFX95032, MI, DW, Address, CS))
687
+ tryDecodeInst (Asm, DecoderTableGFX95032, MI, DW, Address, CS))
645
688
break ;
646
689
647
690
if (STI.hasFeature (AMDGPU::FeatureGFX90AInsts) &&
648
- tryDecodeInst (DecoderTableGFX90A32, MI, DW, Address, CS))
691
+ tryDecodeInst (Asm, DecoderTableGFX90A32, MI, DW, Address, CS))
649
692
break ;
650
693
651
694
if (STI.hasFeature (AMDGPU::FeatureGFX10_BEncoding) &&
652
- tryDecodeInst (DecoderTableGFX10_B32, MI, DW, Address, CS))
695
+ tryDecodeInst (Asm, DecoderTableGFX10_B32, MI, DW, Address, CS))
653
696
break ;
654
697
655
- if (isGFX10 () && tryDecodeInst (DecoderTableGFX1032, MI, DW, Address, CS))
698
+ if (isGFX10 () &&
699
+ tryDecodeInst (Asm, DecoderTableGFX1032, MI, DW, Address, CS))
656
700
break ;
657
701
658
702
if (isGFX11 () &&
659
- tryDecodeInst (DecoderTableGFX1132, DecoderTableGFX11_FAKE1632, MI, DW ,
660
- Address, CS))
703
+ tryDecodeInst (Asm, DecoderTableGFX1132, DecoderTableGFX11_FAKE1632 ,
704
+ MI, DW, Address, CS))
661
705
break ;
662
706
663
707
if (isGFX12 () &&
664
- tryDecodeInst (DecoderTableGFX1232, DecoderTableGFX12_FAKE1632, MI, DW ,
665
- Address, CS))
708
+ tryDecodeInst (Asm, DecoderTableGFX1232, DecoderTableGFX12_FAKE1632 ,
709
+ MI, DW, Address, CS))
666
710
break ;
667
711
}
668
712
0 commit comments