1/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\
2|* *|
3|* * Lanai Disassembler *|
4|* *|
5|* Automatically generated file, do not edit! *|
6|* *|
7\*===----------------------------------------------------------------------===*/
8
9
10#include "llvm/MC/MCInst.h"
11#include "llvm/MC/MCSubtargetInfo.h"
12#include "llvm/Support/DataTypes.h"
13#include "llvm/Support/Debug.h"
14#include "llvm/Support/LEB128.h"
15#include "llvm/Support/raw_ostream.h"
16#include "llvm/TargetParser/SubtargetFeature.h"
17#include <assert.h>
18
19namespace {
20
21// Helper functions for extracting fields from encoded instructions.
22// InsnType must either be integral or an APInt-like object that must:
23// * be default-constructible and copy-constructible
24// * be constructible from an APInt (this can be private)
25// * Support insertBits(bits, startBit, numBits)
26// * Support extractBitsAsZExtValue(numBits, startBit)
27// * Support the ~, &, ==, and != operators with other objects of the same type
28// * Support the != and bitwise & with uint64_t
29// * Support put (<<) to raw_ostream&
30template <typename InsnType>
31#if defined(_MSC_VER) && !defined(__clang__)
32__declspec(noinline)
33#endif
34static std::enable_if_t<std::is_integral<InsnType>::value, InsnType>
35fieldFromInstruction(const InsnType &insn, unsigned startBit,
36 unsigned numBits) {
37 assert(startBit + numBits <= 64 && "Cannot support >64-bit extractions!");
38 assert(startBit + numBits <= (sizeof(InsnType) * 8) &&
39 "Instruction field out of bounds!");
40 InsnType fieldMask;
41 if (numBits == sizeof(InsnType) * 8)
42 fieldMask = (InsnType)(-1LL);
43 else
44 fieldMask = (((InsnType)1 << numBits) - 1) << startBit;
45 return (insn & fieldMask) >> startBit;
46}
47
48template <typename InsnType>
49static std::enable_if_t<!std::is_integral<InsnType>::value, uint64_t>
50fieldFromInstruction(const InsnType &insn, unsigned startBit,
51 unsigned numBits) {
52 return insn.extractBitsAsZExtValue(numBits, startBit);
53}
54
55// Helper function for inserting bits extracted from an encoded instruction into
56// a field.
57template <typename InsnType>
58static void insertBits(InsnType &field, InsnType bits, unsigned startBit,
59 unsigned numBits) {
60 if constexpr (std::is_integral<InsnType>::value) {
61 assert(startBit + numBits <= sizeof field * 8);
62 (void)numBits;
63 field |= (InsnType)bits << startBit;
64 } else {
65 field.insertBits(bits, startBit, numBits);
66 }
67}
68
69static bool Check(DecodeStatus &Out, DecodeStatus In) {
70 Out = static_cast<DecodeStatus>(Out & In);
71 return Out != MCDisassembler::Fail;
72}
73
74static const uint8_t DecoderTableLanai32[] = {
75/* 0 */ MCD::OPC_ExtractField, 28, 4, // Inst{31-28} ...
76/* 3 */ MCD::OPC_FilterValue, 0, 120, 0, // Skip to: 127
77/* 7 */ MCD::OPC_ExtractField, 16, 2, // Inst{17-16} ...
78/* 10 */ MCD::OPC_FilterValue, 0, 91, 0, // Skip to: 105
79/* 14 */ MCD::OPC_ExtractField, 0, 16, // Inst{15-0} ...
80/* 17 */ MCD::OPC_FilterValue, 1, 10, 0, // Skip to: 31
81/* 21 */ MCD::OPC_CheckField, 18, 10, 0, 74, 0, // Skip to: 101
82/* 27 */ MCD::OPC_Decode, 230, 2, 0, // Opcode: NOP, DecodeIdx: 0
83/* 31 */ MCD::OPC_FilterValue, 2, 10, 0, // Skip to: 45
84/* 35 */ MCD::OPC_CheckField, 18, 10, 0, 60, 0, // Skip to: 101
85/* 41 */ MCD::OPC_Decode, 224, 2, 0, // Opcode: LOG0, DecodeIdx: 0
86/* 45 */ MCD::OPC_FilterValue, 3, 10, 0, // Skip to: 59
87/* 49 */ MCD::OPC_CheckField, 18, 10, 0, 46, 0, // Skip to: 101
88/* 55 */ MCD::OPC_Decode, 225, 2, 0, // Opcode: LOG1, DecodeIdx: 0
89/* 59 */ MCD::OPC_FilterValue, 4, 10, 0, // Skip to: 73
90/* 63 */ MCD::OPC_CheckField, 18, 10, 0, 32, 0, // Skip to: 101
91/* 69 */ MCD::OPC_Decode, 226, 2, 0, // Opcode: LOG2, DecodeIdx: 0
92/* 73 */ MCD::OPC_FilterValue, 5, 10, 0, // Skip to: 87
93/* 77 */ MCD::OPC_CheckField, 18, 10, 0, 18, 0, // Skip to: 101
94/* 83 */ MCD::OPC_Decode, 227, 2, 0, // Opcode: LOG3, DecodeIdx: 0
95/* 87 */ MCD::OPC_FilterValue, 6, 10, 0, // Skip to: 101
96/* 91 */ MCD::OPC_CheckField, 18, 10, 0, 4, 0, // Skip to: 101
97/* 97 */ MCD::OPC_Decode, 228, 2, 0, // Opcode: LOG4, DecodeIdx: 0
98/* 101 */ MCD::OPC_Decode, 197, 2, 1, // Opcode: ADD_I_LO, DecodeIdx: 1
99/* 105 */ MCD::OPC_FilterValue, 1, 4, 0, // Skip to: 113
100/* 109 */ MCD::OPC_Decode, 196, 2, 1, // Opcode: ADD_I_HI, DecodeIdx: 1
101/* 113 */ MCD::OPC_FilterValue, 2, 4, 0, // Skip to: 121
102/* 117 */ MCD::OPC_Decode, 194, 2, 1, // Opcode: ADD_F_I_LO, DecodeIdx: 1
103/* 121 */ MCD::OPC_FilterValueOrFail, 3,
104/* 123 */ MCD::OPC_Decode, 193, 2, 1, // Opcode: ADD_F_I_HI, DecodeIdx: 1
105/* 127 */ MCD::OPC_FilterValue, 1, 33, 0, // Skip to: 164
106/* 131 */ MCD::OPC_ExtractField, 16, 2, // Inst{17-16} ...
107/* 134 */ MCD::OPC_FilterValue, 0, 4, 0, // Skip to: 142
108/* 138 */ MCD::OPC_Decode, 191, 2, 1, // Opcode: ADDC_I_LO, DecodeIdx: 1
109/* 142 */ MCD::OPC_FilterValue, 1, 4, 0, // Skip to: 150
110/* 146 */ MCD::OPC_Decode, 190, 2, 1, // Opcode: ADDC_I_HI, DecodeIdx: 1
111/* 150 */ MCD::OPC_FilterValue, 2, 4, 0, // Skip to: 158
112/* 154 */ MCD::OPC_Decode, 188, 2, 1, // Opcode: ADDC_F_I_LO, DecodeIdx: 1
113/* 158 */ MCD::OPC_FilterValueOrFail, 3,
114/* 160 */ MCD::OPC_Decode, 187, 2, 1, // Opcode: ADDC_F_I_HI, DecodeIdx: 1
115/* 164 */ MCD::OPC_FilterValue, 2, 33, 0, // Skip to: 201
116/* 168 */ MCD::OPC_ExtractField, 16, 2, // Inst{17-16} ...
117/* 171 */ MCD::OPC_FilterValue, 0, 4, 0, // Skip to: 179
118/* 175 */ MCD::OPC_Decode, 142, 3, 1, // Opcode: SUB_I_LO, DecodeIdx: 1
119/* 179 */ MCD::OPC_FilterValue, 1, 4, 0, // Skip to: 187
120/* 183 */ MCD::OPC_Decode, 141, 3, 1, // Opcode: SUB_I_HI, DecodeIdx: 1
121/* 187 */ MCD::OPC_FilterValue, 2, 4, 0, // Skip to: 195
122/* 191 */ MCD::OPC_Decode, 139, 3, 1, // Opcode: SUB_F_I_LO, DecodeIdx: 1
123/* 195 */ MCD::OPC_FilterValueOrFail, 3,
124/* 197 */ MCD::OPC_Decode, 138, 3, 1, // Opcode: SUB_F_I_HI, DecodeIdx: 1
125/* 201 */ MCD::OPC_FilterValue, 3, 33, 0, // Skip to: 238
126/* 205 */ MCD::OPC_ExtractField, 16, 2, // Inst{17-16} ...
127/* 208 */ MCD::OPC_FilterValue, 0, 4, 0, // Skip to: 216
128/* 212 */ MCD::OPC_Decode, 136, 3, 1, // Opcode: SUBB_I_LO, DecodeIdx: 1
129/* 216 */ MCD::OPC_FilterValue, 1, 4, 0, // Skip to: 224
130/* 220 */ MCD::OPC_Decode, 135, 3, 1, // Opcode: SUBB_I_HI, DecodeIdx: 1
131/* 224 */ MCD::OPC_FilterValue, 2, 4, 0, // Skip to: 232
132/* 228 */ MCD::OPC_Decode, 133, 3, 1, // Opcode: SUBB_F_I_LO, DecodeIdx: 1
133/* 232 */ MCD::OPC_FilterValueOrFail, 3,
134/* 234 */ MCD::OPC_Decode, 132, 3, 1, // Opcode: SUBB_F_I_HI, DecodeIdx: 1
135/* 238 */ MCD::OPC_FilterValue, 4, 33, 0, // Skip to: 275
136/* 242 */ MCD::OPC_ExtractField, 16, 2, // Inst{17-16} ...
137/* 245 */ MCD::OPC_FilterValue, 0, 4, 0, // Skip to: 253
138/* 249 */ MCD::OPC_Decode, 203, 2, 1, // Opcode: AND_I_LO, DecodeIdx: 1
139/* 253 */ MCD::OPC_FilterValue, 1, 4, 0, // Skip to: 261
140/* 257 */ MCD::OPC_Decode, 202, 2, 1, // Opcode: AND_I_HI, DecodeIdx: 1
141/* 261 */ MCD::OPC_FilterValue, 2, 4, 0, // Skip to: 269
142/* 265 */ MCD::OPC_Decode, 200, 2, 1, // Opcode: AND_F_I_LO, DecodeIdx: 1
143/* 269 */ MCD::OPC_FilterValueOrFail, 3,
144/* 271 */ MCD::OPC_Decode, 199, 2, 1, // Opcode: AND_F_I_HI, DecodeIdx: 1
145/* 275 */ MCD::OPC_FilterValue, 5, 33, 0, // Skip to: 312
146/* 279 */ MCD::OPC_ExtractField, 16, 2, // Inst{17-16} ...
147/* 282 */ MCD::OPC_FilterValue, 0, 4, 0, // Skip to: 290
148/* 286 */ MCD::OPC_Decode, 235, 2, 1, // Opcode: OR_I_LO, DecodeIdx: 1
149/* 290 */ MCD::OPC_FilterValue, 1, 4, 0, // Skip to: 298
150/* 294 */ MCD::OPC_Decode, 234, 2, 1, // Opcode: OR_I_HI, DecodeIdx: 1
151/* 298 */ MCD::OPC_FilterValue, 2, 4, 0, // Skip to: 306
152/* 302 */ MCD::OPC_Decode, 232, 2, 1, // Opcode: OR_F_I_LO, DecodeIdx: 1
153/* 306 */ MCD::OPC_FilterValueOrFail, 3,
154/* 308 */ MCD::OPC_Decode, 231, 2, 1, // Opcode: OR_F_I_HI, DecodeIdx: 1
155/* 312 */ MCD::OPC_FilterValue, 6, 33, 0, // Skip to: 349
156/* 316 */ MCD::OPC_ExtractField, 16, 2, // Inst{17-16} ...
157/* 319 */ MCD::OPC_FilterValue, 0, 4, 0, // Skip to: 327
158/* 323 */ MCD::OPC_Decode, 151, 3, 1, // Opcode: XOR_I_LO, DecodeIdx: 1
159/* 327 */ MCD::OPC_FilterValue, 1, 4, 0, // Skip to: 335
160/* 331 */ MCD::OPC_Decode, 150, 3, 1, // Opcode: XOR_I_HI, DecodeIdx: 1
161/* 335 */ MCD::OPC_FilterValue, 2, 4, 0, // Skip to: 343
162/* 339 */ MCD::OPC_Decode, 148, 3, 1, // Opcode: XOR_F_I_LO, DecodeIdx: 1
163/* 343 */ MCD::OPC_FilterValueOrFail, 3,
164/* 345 */ MCD::OPC_Decode, 147, 3, 1, // Opcode: XOR_F_I_HI, DecodeIdx: 1
165/* 349 */ MCD::OPC_FilterValue, 7, 33, 0, // Skip to: 386
166/* 353 */ MCD::OPC_ExtractField, 16, 2, // Inst{17-16} ...
167/* 356 */ MCD::OPC_FilterValue, 0, 4, 0, // Skip to: 364
168/* 360 */ MCD::OPC_Decode, 250, 2, 2, // Opcode: SL_I, DecodeIdx: 2
169/* 364 */ MCD::OPC_FilterValue, 1, 4, 0, // Skip to: 372
170/* 368 */ MCD::OPC_Decode, 240, 2, 2, // Opcode: SA_I, DecodeIdx: 2
171/* 372 */ MCD::OPC_FilterValue, 2, 4, 0, // Skip to: 380
172/* 376 */ MCD::OPC_Decode, 249, 2, 2, // Opcode: SL_F_I, DecodeIdx: 2
173/* 380 */ MCD::OPC_FilterValueOrFail, 3,
174/* 382 */ MCD::OPC_Decode, 239, 2, 2, // Opcode: SA_F_I, DecodeIdx: 2
175/* 386 */ MCD::OPC_FilterValue, 8, 17, 0, // Skip to: 407
176/* 390 */ MCD::OPC_CheckField, 0, 28, 252, 255, 219, 8, 4, 0, // Skip to: 403
177/* 399 */ MCD::OPC_Decode, 238, 2, 0, // Opcode: RET, DecodeIdx: 0
178/* 403 */ MCD::OPC_Decode, 220, 2, 3, // Opcode: LDW_RI, DecodeIdx: 3
179/* 407 */ MCD::OPC_FilterValue, 9, 4, 0, // Skip to: 415
180/* 411 */ MCD::OPC_Decode, 144, 3, 3, // Opcode: SW_RI, DecodeIdx: 3
181/* 415 */ MCD::OPC_FilterValue, 10, 49, 0, // Skip to: 468
182/* 419 */ MCD::OPC_ExtractField, 0, 3, // Inst{2-0} ...
183/* 422 */ MCD::OPC_FilterValue, 0, 4, 0, // Skip to: 430
184/* 426 */ MCD::OPC_Decode, 217, 2, 4, // Opcode: LDHs_RR, DecodeIdx: 4
185/* 430 */ MCD::OPC_FilterValue, 1, 4, 0, // Skip to: 438
186/* 434 */ MCD::OPC_Decode, 219, 2, 4, // Opcode: LDHz_RR, DecodeIdx: 4
187/* 438 */ MCD::OPC_FilterValue, 2, 4, 0, // Skip to: 446
188/* 442 */ MCD::OPC_Decode, 221, 2, 4, // Opcode: LDW_RR, DecodeIdx: 4
189/* 446 */ MCD::OPC_FilterValue, 3, 4, 0, // Skip to: 454
190/* 450 */ MCD::OPC_Decode, 222, 2, 4, // Opcode: LDWz_RR, DecodeIdx: 4
191/* 454 */ MCD::OPC_FilterValue, 4, 4, 0, // Skip to: 462
192/* 458 */ MCD::OPC_Decode, 213, 2, 4, // Opcode: LDBs_RR, DecodeIdx: 4
193/* 462 */ MCD::OPC_FilterValueOrFail, 5,
194/* 464 */ MCD::OPC_Decode, 215, 2, 4, // Opcode: LDBz_RR, DecodeIdx: 4
195/* 468 */ MCD::OPC_FilterValue, 11, 25, 0, // Skip to: 497
196/* 472 */ MCD::OPC_ExtractField, 0, 3, // Inst{2-0} ...
197/* 475 */ MCD::OPC_FilterValue, 0, 4, 0, // Skip to: 483
198/* 479 */ MCD::OPC_Decode, 131, 3, 4, // Opcode: STH_RR, DecodeIdx: 4
199/* 483 */ MCD::OPC_FilterValue, 2, 4, 0, // Skip to: 491
200/* 487 */ MCD::OPC_Decode, 145, 3, 4, // Opcode: SW_RR, DecodeIdx: 4
201/* 491 */ MCD::OPC_FilterValueOrFail, 4,
202/* 493 */ MCD::OPC_Decode, 129, 3, 4, // Opcode: STB_RR, DecodeIdx: 4
203/* 497 */ MCD::OPC_FilterValue, 12, 0, 1, // Skip to: 757
204/* 501 */ MCD::OPC_ExtractField, 3, 8, // Inst{10-3} ...
205/* 504 */ MCD::OPC_FilterValue, 0, 17, 0, // Skip to: 525
206/* 508 */ MCD::OPC_ExtractField, 17, 1, // Inst{17} ...
207/* 511 */ MCD::OPC_FilterValue, 0, 4, 0, // Skip to: 519
208/* 515 */ MCD::OPC_Decode, 198, 2, 5, // Opcode: ADD_R, DecodeIdx: 5
209/* 519 */ MCD::OPC_FilterValueOrFail, 1,
210/* 521 */ MCD::OPC_Decode, 195, 2, 5, // Opcode: ADD_F_R, DecodeIdx: 5
211/* 525 */ MCD::OPC_FilterValue, 32, 17, 0, // Skip to: 546
212/* 529 */ MCD::OPC_ExtractField, 17, 1, // Inst{17} ...
213/* 532 */ MCD::OPC_FilterValue, 0, 4, 0, // Skip to: 540
214/* 536 */ MCD::OPC_Decode, 192, 2, 5, // Opcode: ADDC_R, DecodeIdx: 5
215/* 540 */ MCD::OPC_FilterValueOrFail, 1,
216/* 542 */ MCD::OPC_Decode, 189, 2, 5, // Opcode: ADDC_F_R, DecodeIdx: 5
217/* 546 */ MCD::OPC_FilterValue, 64, 17, 0, // Skip to: 567
218/* 550 */ MCD::OPC_ExtractField, 17, 1, // Inst{17} ...
219/* 553 */ MCD::OPC_FilterValue, 0, 4, 0, // Skip to: 561
220/* 557 */ MCD::OPC_Decode, 143, 3, 5, // Opcode: SUB_R, DecodeIdx: 5
221/* 561 */ MCD::OPC_FilterValueOrFail, 1,
222/* 563 */ MCD::OPC_Decode, 140, 3, 5, // Opcode: SUB_F_R, DecodeIdx: 5
223/* 567 */ MCD::OPC_FilterValue, 96, 17, 0, // Skip to: 588
224/* 571 */ MCD::OPC_ExtractField, 17, 1, // Inst{17} ...
225/* 574 */ MCD::OPC_FilterValue, 0, 4, 0, // Skip to: 582
226/* 578 */ MCD::OPC_Decode, 137, 3, 5, // Opcode: SUBB_R, DecodeIdx: 5
227/* 582 */ MCD::OPC_FilterValueOrFail, 1,
228/* 584 */ MCD::OPC_Decode, 134, 3, 5, // Opcode: SUBB_F_R, DecodeIdx: 5
229/* 588 */ MCD::OPC_FilterValue, 128, 1, 17, 0, // Skip to: 610
230/* 593 */ MCD::OPC_ExtractField, 17, 1, // Inst{17} ...
231/* 596 */ MCD::OPC_FilterValue, 0, 4, 0, // Skip to: 604
232/* 600 */ MCD::OPC_Decode, 204, 2, 5, // Opcode: AND_R, DecodeIdx: 5
233/* 604 */ MCD::OPC_FilterValueOrFail, 1,
234/* 606 */ MCD::OPC_Decode, 201, 2, 5, // Opcode: AND_F_R, DecodeIdx: 5
235/* 610 */ MCD::OPC_FilterValue, 160, 1, 65, 0, // Skip to: 680
236/* 615 */ MCD::OPC_ExtractField, 17, 1, // Inst{17} ...
237/* 618 */ MCD::OPC_FilterValue, 0, 52, 0, // Skip to: 674
238/* 622 */ MCD::OPC_CheckField, 18, 10, 64, 16, 0, // Skip to: 644
239/* 628 */ MCD::OPC_CheckField, 16, 1, 0, 10, 0, // Skip to: 644
240/* 634 */ MCD::OPC_CheckField, 0, 3, 0, 4, 0, // Skip to: 644
241/* 640 */ MCD::OPC_Decode, 210, 2, 6, // Opcode: JR, DecodeIdx: 6
242/* 644 */ MCD::OPC_CheckField, 23, 5, 2, 10, 0, // Skip to: 660
243/* 650 */ MCD::OPC_CheckField, 11, 5, 0, 4, 0, // Skip to: 660
244/* 656 */ MCD::OPC_Decode, 206, 2, 7, // Opcode: BRIND_CC, DecodeIdx: 7
245/* 660 */ MCD::OPC_CheckField, 23, 5, 2, 4, 0, // Skip to: 670
246/* 666 */ MCD::OPC_Decode, 207, 2, 8, // Opcode: BRIND_CCA, DecodeIdx: 8
247/* 670 */ MCD::OPC_Decode, 236, 2, 5, // Opcode: OR_R, DecodeIdx: 5
248/* 674 */ MCD::OPC_FilterValueOrFail, 1,
249/* 676 */ MCD::OPC_Decode, 233, 2, 5, // Opcode: OR_F_R, DecodeIdx: 5
250/* 680 */ MCD::OPC_FilterValue, 192, 1, 17, 0, // Skip to: 702
251/* 685 */ MCD::OPC_ExtractField, 17, 1, // Inst{17} ...
252/* 688 */ MCD::OPC_FilterValue, 0, 4, 0, // Skip to: 696
253/* 692 */ MCD::OPC_Decode, 152, 3, 5, // Opcode: XOR_R, DecodeIdx: 5
254/* 696 */ MCD::OPC_FilterValueOrFail, 1,
255/* 698 */ MCD::OPC_Decode, 149, 3, 5, // Opcode: XOR_F_R, DecodeIdx: 5
256/* 702 */ MCD::OPC_FilterValue, 224, 1, 8, 0, // Skip to: 715
257/* 707 */ MCD::OPC_CheckFieldOrFail, 17, 1, 0,
258/* 711 */ MCD::OPC_Decode, 242, 2, 9, // Opcode: SELECT, DecodeIdx: 9
259/* 715 */ MCD::OPC_FilterValue, 240, 1, 17, 0, // Skip to: 737
260/* 720 */ MCD::OPC_ExtractField, 17, 1, // Inst{17} ...
261/* 723 */ MCD::OPC_FilterValue, 0, 4, 0, // Skip to: 731
262/* 727 */ MCD::OPC_Decode, 247, 2, 5, // Opcode: SHL_R, DecodeIdx: 5
263/* 731 */ MCD::OPC_FilterValueOrFail, 1,
264/* 733 */ MCD::OPC_Decode, 246, 2, 5, // Opcode: SHL_F_R, DecodeIdx: 5
265/* 737 */ MCD::OPC_FilterValueOrFail, 248, 1,
266/* 740 */ MCD::OPC_ExtractField, 17, 1, // Inst{17} ...
267/* 743 */ MCD::OPC_FilterValue, 0, 4, 0, // Skip to: 751
268/* 747 */ MCD::OPC_Decode, 252, 2, 5, // Opcode: SRA_R, DecodeIdx: 5
269/* 751 */ MCD::OPC_FilterValueOrFail, 1,
270/* 753 */ MCD::OPC_Decode, 251, 2, 5, // Opcode: SRA_F_R, DecodeIdx: 5
271/* 757 */ MCD::OPC_FilterValue, 13, 25, 0, // Skip to: 786
272/* 761 */ MCD::OPC_ExtractField, 0, 18, // Inst{17-0} ...
273/* 764 */ MCD::OPC_FilterValue, 1, 4, 0, // Skip to: 772
274/* 768 */ MCD::OPC_Decode, 237, 2, 10, // Opcode: POPC, DecodeIdx: 10
275/* 772 */ MCD::OPC_FilterValue, 2, 4, 0, // Skip to: 780
276/* 776 */ MCD::OPC_Decode, 223, 2, 10, // Opcode: LEADZ, DecodeIdx: 10
277/* 780 */ MCD::OPC_FilterValueOrFail, 3,
278/* 782 */ MCD::OPC_Decode, 146, 3, 10, // Opcode: TRAILZ, DecodeIdx: 10
279/* 786 */ MCD::OPC_FilterValue, 14, 54, 0, // Skip to: 844
280/* 790 */ MCD::OPC_ExtractField, 1, 1, // Inst{1} ...
281/* 793 */ MCD::OPC_FilterValue, 0, 20, 0, // Skip to: 817
282/* 797 */ MCD::OPC_CheckField, 25, 3, 0, 10, 0, // Skip to: 813
283/* 803 */ MCD::OPC_CheckField, 0, 1, 0, 4, 0, // Skip to: 813
284/* 809 */ MCD::OPC_Decode, 209, 2, 11, // Opcode: BT, DecodeIdx: 11
285/* 813 */ MCD::OPC_Decode, 205, 2, 12, // Opcode: BRCC, DecodeIdx: 12
286/* 817 */ MCD::OPC_FilterValueOrFail, 1,
287/* 819 */ MCD::OPC_ExtractField, 23, 2, // Inst{24-23} ...
288/* 822 */ MCD::OPC_FilterValue, 0, 8, 0, // Skip to: 834
289/* 826 */ MCD::OPC_CheckFieldOrFail, 2, 16, 0,
290/* 830 */ MCD::OPC_Decode, 241, 2, 13, // Opcode: SCC, DecodeIdx: 13
291/* 834 */ MCD::OPC_FilterValueOrFail, 2,
292/* 836 */ MCD::OPC_CheckFieldOrFail, 16, 7, 0,
293/* 840 */ MCD::OPC_Decode, 208, 2, 14, // Opcode: BRR, DecodeIdx: 14
294/* 844 */ MCD::OPC_FilterValueOrFail, 15,
295/* 846 */ MCD::OPC_ExtractField, 16, 2, // Inst{17-16} ...
296/* 849 */ MCD::OPC_FilterValue, 0, 4, 0, // Skip to: 857
297/* 853 */ MCD::OPC_Decode, 211, 2, 15, // Opcode: LDADDR, DecodeIdx: 15
298/* 857 */ MCD::OPC_FilterValue, 1, 4, 0, // Skip to: 865
299/* 861 */ MCD::OPC_Decode, 255, 2, 15, // Opcode: STADDR, DecodeIdx: 15
300/* 865 */ MCD::OPC_FilterValue, 2, 4, 0, // Skip to: 873
301/* 869 */ MCD::OPC_Decode, 248, 2, 15, // Opcode: SLI, DecodeIdx: 15
302/* 873 */ MCD::OPC_FilterValueOrFail, 3,
303/* 875 */ MCD::OPC_ExtractField, 12, 4, // Inst{15-12} ...
304/* 878 */ MCD::OPC_FilterValue, 0, 4, 0, // Skip to: 886
305/* 882 */ MCD::OPC_Decode, 216, 2, 16, // Opcode: LDHs_RI, DecodeIdx: 16
306/* 886 */ MCD::OPC_FilterValue, 1, 4, 0, // Skip to: 894
307/* 890 */ MCD::OPC_Decode, 218, 2, 16, // Opcode: LDHz_RI, DecodeIdx: 16
308/* 894 */ MCD::OPC_FilterValue, 2, 4, 0, // Skip to: 902
309/* 898 */ MCD::OPC_Decode, 130, 3, 16, // Opcode: STH_RI, DecodeIdx: 16
310/* 902 */ MCD::OPC_FilterValue, 4, 4, 0, // Skip to: 910
311/* 906 */ MCD::OPC_Decode, 212, 2, 16, // Opcode: LDBs_RI, DecodeIdx: 16
312/* 910 */ MCD::OPC_FilterValue, 5, 4, 0, // Skip to: 918
313/* 914 */ MCD::OPC_Decode, 214, 2, 16, // Opcode: LDBz_RI, DecodeIdx: 16
314/* 918 */ MCD::OPC_FilterValueOrFail, 6,
315/* 920 */ MCD::OPC_Decode, 128, 3, 16, // Opcode: STB_RI, DecodeIdx: 16
316/* 924 */ MCD::OPC_Fail,
317 0
318};
319
320// Handling 17 cases.
321template <typename InsnType>
322static DecodeStatus decodeToMCInst(unsigned Idx, DecodeStatus S, InsnType insn, MCInst &MI, uint64_t Address, const MCDisassembler *Decoder, bool &DecodeComplete) {
323 DecodeComplete = true;
324 using TmpType = std::conditional_t<std::is_integral<InsnType>::value, InsnType, uint64_t>;
325 TmpType tmp;
326 switch (Idx) {
327 default: llvm_unreachable("Invalid index!");
328 case 0:
329 return S;
330 case 1:
331 tmp = fieldFromInstruction(insn, 23, 5);
332 if (!Check(S, DecodeGPRRegisterClass(MI, tmp, Address, Decoder))) { return MCDisassembler::Fail; }
333 tmp = fieldFromInstruction(insn, 18, 5);
334 if (!Check(S, DecodeGPRRegisterClass(MI, tmp, Address, Decoder))) { return MCDisassembler::Fail; }
335 tmp = fieldFromInstruction(insn, 0, 16);
336 MI.addOperand(Op: MCOperand::createImm(Val: tmp));
337 return S;
338 case 2:
339 tmp = fieldFromInstruction(insn, 23, 5);
340 if (!Check(S, DecodeGPRRegisterClass(MI, tmp, Address, Decoder))) { return MCDisassembler::Fail; }
341 tmp = fieldFromInstruction(insn, 18, 5);
342 if (!Check(S, DecodeGPRRegisterClass(MI, tmp, Address, Decoder))) { return MCDisassembler::Fail; }
343 tmp = fieldFromInstruction(insn, 0, 16);
344 if (!Check(S, decodeShiftImm(MI, tmp, Address, Decoder))) { return MCDisassembler::Fail; }
345 return S;
346 case 3:
347 tmp = fieldFromInstruction(insn, 23, 5);
348 if (!Check(S, DecodeGPRRegisterClass(MI, tmp, Address, Decoder))) { return MCDisassembler::Fail; }
349 tmp = fieldFromInstruction(insn, 0, 23);
350 if (!Check(S, decodeRiMemoryValue(MI, tmp, Address, Decoder))) { return MCDisassembler::Fail; }
351 return S;
352 case 4:
353 tmp = fieldFromInstruction(insn, 23, 5);
354 if (!Check(S, DecodeGPRRegisterClass(MI, tmp, Address, Decoder))) { return MCDisassembler::Fail; }
355 tmp = 0x0;
356 insertBits(tmp, fieldFromInstruction(insn, 3, 8), 0, 8);
357 insertBits(tmp, fieldFromInstruction(insn, 11, 5), 10, 5);
358 insertBits(tmp, fieldFromInstruction(insn, 16, 2), 8, 2);
359 insertBits(tmp, fieldFromInstruction(insn, 18, 5), 15, 5);
360 if (!Check(S, decodeRrMemoryValue(MI, tmp, Address, Decoder))) { return MCDisassembler::Fail; }
361 return S;
362 case 5:
363 tmp = fieldFromInstruction(insn, 23, 5);
364 if (!Check(S, DecodeGPRRegisterClass(MI, tmp, Address, Decoder))) { return MCDisassembler::Fail; }
365 tmp = fieldFromInstruction(insn, 18, 5);
366 if (!Check(S, DecodeGPRRegisterClass(MI, tmp, Address, Decoder))) { return MCDisassembler::Fail; }
367 tmp = fieldFromInstruction(insn, 11, 5);
368 if (!Check(S, DecodeGPRRegisterClass(MI, tmp, Address, Decoder))) { return MCDisassembler::Fail; }
369 tmp = 0x0;
370 insertBits(tmp, fieldFromInstruction(insn, 0, 3), 1, 3);
371 insertBits(tmp, fieldFromInstruction(insn, 16, 1), 0, 1);
372 if (!Check(S, decodePredicateOperand(MI, tmp, Address, Decoder))) { return MCDisassembler::Fail; }
373 return S;
374 case 6:
375 tmp = fieldFromInstruction(insn, 11, 5);
376 if (!Check(S, DecodeGPRRegisterClass(MI, tmp, Address, Decoder))) { return MCDisassembler::Fail; }
377 return S;
378 case 7:
379 tmp = fieldFromInstruction(insn, 18, 5);
380 if (!Check(S, DecodeGPRRegisterClass(MI, tmp, Address, Decoder))) { return MCDisassembler::Fail; }
381 tmp = 0x0;
382 insertBits(tmp, fieldFromInstruction(insn, 0, 3), 1, 3);
383 insertBits(tmp, fieldFromInstruction(insn, 16, 1), 0, 1);
384 MI.addOperand(Op: MCOperand::createImm(Val: tmp));
385 return S;
386 case 8:
387 tmp = fieldFromInstruction(insn, 18, 5);
388 if (!Check(S, DecodeGPRRegisterClass(MI, tmp, Address, Decoder))) { return MCDisassembler::Fail; }
389 tmp = fieldFromInstruction(insn, 11, 5);
390 if (!Check(S, DecodeGPRRegisterClass(MI, tmp, Address, Decoder))) { return MCDisassembler::Fail; }
391 tmp = 0x0;
392 insertBits(tmp, fieldFromInstruction(insn, 0, 3), 1, 3);
393 insertBits(tmp, fieldFromInstruction(insn, 16, 1), 0, 1);
394 MI.addOperand(Op: MCOperand::createImm(Val: tmp));
395 return S;
396 case 9:
397 tmp = fieldFromInstruction(insn, 23, 5);
398 if (!Check(S, DecodeGPRRegisterClass(MI, tmp, Address, Decoder))) { return MCDisassembler::Fail; }
399 tmp = fieldFromInstruction(insn, 18, 5);
400 if (!Check(S, DecodeGPRRegisterClass(MI, tmp, Address, Decoder))) { return MCDisassembler::Fail; }
401 tmp = fieldFromInstruction(insn, 11, 5);
402 if (!Check(S, DecodeGPRRegisterClass(MI, tmp, Address, Decoder))) { return MCDisassembler::Fail; }
403 tmp = 0x0;
404 insertBits(tmp, fieldFromInstruction(insn, 0, 3), 1, 3);
405 insertBits(tmp, fieldFromInstruction(insn, 16, 1), 0, 1);
406 MI.addOperand(Op: MCOperand::createImm(Val: tmp));
407 return S;
408 case 10:
409 tmp = fieldFromInstruction(insn, 23, 5);
410 if (!Check(S, DecodeGPRRegisterClass(MI, tmp, Address, Decoder))) { return MCDisassembler::Fail; }
411 tmp = fieldFromInstruction(insn, 18, 5);
412 if (!Check(S, DecodeGPRRegisterClass(MI, tmp, Address, Decoder))) { return MCDisassembler::Fail; }
413 return S;
414 case 11:
415 tmp = fieldFromInstruction(insn, 2, 23) << 2;
416 if (!Check(S, decodeBranch(MI, tmp, Address, Decoder))) { return MCDisassembler::Fail; }
417 return S;
418 case 12:
419 tmp = fieldFromInstruction(insn, 2, 23) << 2;
420 if (!Check(S, decodeBranch(MI, tmp, Address, Decoder))) { return MCDisassembler::Fail; }
421 tmp = 0x0;
422 insertBits(tmp, fieldFromInstruction(insn, 0, 1), 0, 1);
423 insertBits(tmp, fieldFromInstruction(insn, 25, 3), 1, 3);
424 MI.addOperand(Op: MCOperand::createImm(Val: tmp));
425 return S;
426 case 13:
427 tmp = fieldFromInstruction(insn, 18, 5);
428 if (!Check(S, DecodeGPRRegisterClass(MI, tmp, Address, Decoder))) { return MCDisassembler::Fail; }
429 tmp = 0x0;
430 insertBits(tmp, fieldFromInstruction(insn, 0, 1), 0, 1);
431 insertBits(tmp, fieldFromInstruction(insn, 25, 3), 1, 3);
432 MI.addOperand(Op: MCOperand::createImm(Val: tmp));
433 return S;
434 case 14:
435 tmp = fieldFromInstruction(insn, 2, 14) << 2;
436 MI.addOperand(Op: MCOperand::createImm(Val: tmp));
437 tmp = 0x0;
438 insertBits(tmp, fieldFromInstruction(insn, 0, 1), 0, 1);
439 insertBits(tmp, fieldFromInstruction(insn, 25, 3), 1, 3);
440 MI.addOperand(Op: MCOperand::createImm(Val: tmp));
441 return S;
442 case 15:
443 tmp = fieldFromInstruction(insn, 23, 5);
444 if (!Check(S, DecodeGPRRegisterClass(MI, tmp, Address, Decoder))) { return MCDisassembler::Fail; }
445 tmp = 0x0;
446 insertBits(tmp, fieldFromInstruction(insn, 0, 16), 0, 16);
447 insertBits(tmp, fieldFromInstruction(insn, 18, 5), 16, 5);
448 MI.addOperand(Op: MCOperand::createImm(Val: tmp));
449 return S;
450 case 16:
451 tmp = fieldFromInstruction(insn, 23, 5);
452 if (!Check(S, DecodeGPRRegisterClass(MI, tmp, Address, Decoder))) { return MCDisassembler::Fail; }
453 tmp = 0x0;
454 insertBits(tmp, fieldFromInstruction(insn, 0, 12), 0, 12);
455 insertBits(tmp, fieldFromInstruction(insn, 18, 5), 12, 5);
456 if (!Check(S, decodeSplsValue(MI, tmp, Address, Decoder))) { return MCDisassembler::Fail; }
457 return S;
458 }
459}
460
461static unsigned decodeNumToSkip(const uint8_t *&Ptr) {
462 unsigned NumToSkip = *Ptr++;
463 NumToSkip |= (*Ptr++) << 8;
464 return NumToSkip;
465}
466
467template <typename InsnType>
468static DecodeStatus decodeInstruction(const uint8_t DecodeTable[], MCInst &MI,
469 InsnType insn, uint64_t Address,
470 const MCDisassembler *DisAsm,
471 const MCSubtargetInfo &STI) {
472
473 const uint8_t *Ptr = DecodeTable;
474 uint64_t CurFieldValue = 0;
475 DecodeStatus S = MCDisassembler::Success;
476 while (true) {
477 ptrdiff_t Loc = Ptr - DecodeTable;
478 const uint8_t DecoderOp = *Ptr++;
479 switch (DecoderOp) {
480 default:
481 errs() << Loc << ": Unexpected decode table opcode: "
482 << (int)DecoderOp << '\n';
483 return MCDisassembler::Fail;
484 case MCD::OPC_ExtractField: {
485 // Decode the start value.
486 unsigned Start = decodeULEB128AndIncUnsafe(p&: Ptr);
487 unsigned Len = *Ptr++;
488 CurFieldValue = fieldFromInstruction(insn, Start, Len);
489 LLVM_DEBUG(dbgs() << Loc << ": OPC_ExtractField(" << Start << ", "
490 << Len << "): " << CurFieldValue << "\n");
491 break;
492 }
493 case MCD::OPC_FilterValue:
494 case MCD::OPC_FilterValueOrFail: {
495 bool IsFail = DecoderOp == MCD::OPC_FilterValueOrFail;
496 // Decode the field value.
497 uint64_t Val = decodeULEB128AndIncUnsafe(p&: Ptr);
498 bool Failed = Val != CurFieldValue;
499 unsigned NumToSkip = IsFail ? 0 : decodeNumToSkip(Ptr);
500
501 // Note: Print NumToSkip even for OPC_FilterValueOrFail to simplify debug
502 // prints.
503 LLVM_DEBUG({
504 StringRef OpName = IsFail ? "OPC_FilterValueOrFail" : "OPC_FilterValue";
505 dbgs() << Loc << ": " << OpName << '(' << Val << ", " << NumToSkip
506 << ") " << (Failed ? "FAIL:" : "PASS:")
507 << " continuing at " << (Ptr - DecodeTable) << '\n';
508 });
509
510 // Perform the filter operation.
511 if (Failed) {
512 if (IsFail)
513 return MCDisassembler::Fail;
514 Ptr += NumToSkip;
515 }
516 break;
517 }
518 case MCD::OPC_CheckField:
519 case MCD::OPC_CheckFieldOrFail: {
520 bool IsFail = DecoderOp == MCD::OPC_CheckFieldOrFail;
521 // Decode the start value.
522 unsigned Start = decodeULEB128AndIncUnsafe(p&: Ptr);
523 unsigned Len = *Ptr;
524 uint64_t FieldValue = fieldFromInstruction(insn, Start, Len);
525 // Decode the field value.
526 unsigned PtrLen = 0;
527 uint64_t ExpectedValue = decodeULEB128(p: ++Ptr, n: &PtrLen);
528 Ptr += PtrLen;
529 bool Failed = ExpectedValue != FieldValue;
530 unsigned NumToSkip = IsFail ? 0 : decodeNumToSkip(Ptr);
531
532 LLVM_DEBUG({
533 StringRef OpName = IsFail ? "OPC_CheckFieldOrFail" : "OPC_CheckField";
534 dbgs() << Loc << ": " << OpName << '(' << Start << ", " << Len << ", "
535 << ExpectedValue << ", " << NumToSkip << "): FieldValue = "
536 << FieldValue << ", ExpectedValue = " << ExpectedValue << ": "
537 << (Failed ? "FAIL\n" : "PASS\n");
538 });
539
540 // If the actual and expected values don't match, skip or fail.
541 if (Failed) {
542 if (IsFail)
543 return MCDisassembler::Fail;
544 Ptr += NumToSkip;
545 }
546 break;
547 }
548 case MCD::OPC_Decode: {
549 // Decode the Opcode value.
550 unsigned Opc = decodeULEB128AndIncUnsafe(p&: Ptr);
551 unsigned DecodeIdx = decodeULEB128AndIncUnsafe(p&: Ptr);
552
553 MI.clear();
554 MI.setOpcode(Opc);
555 bool DecodeComplete;
556 S = decodeToMCInst(DecodeIdx, S, insn, MI, Address, DisAsm, DecodeComplete);
557 assert(DecodeComplete);
558
559 LLVM_DEBUG(dbgs() << Loc << ": OPC_Decode: opcode " << Opc
560 << ", using decoder " << DecodeIdx << ": "
561 << (S != MCDisassembler::Fail ? "PASS\n" : "FAIL\n"));
562 return S;
563 }
564 case MCD::OPC_Fail: {
565 LLVM_DEBUG(dbgs() << Loc << ": OPC_Fail\n");
566 return MCDisassembler::Fail;
567 }
568 }
569 }
570 llvm_unreachable("bogosity detected in disassembler state machine!");
571}
572
573
574} // namespace
575