1 //===- X86DisassemblerTables.cpp - Disassembler tables ----------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file is part of the X86 Disassembler Emitter.
10 // It contains the implementation of the disassembler tables.
11 // Documentation for the disassembler emitter in general can be found in
12 // X86DisassemblerEmitter.h.
14 //===----------------------------------------------------------------------===//
16 #include "X86DisassemblerTables.h"
17 #include "X86DisassemblerShared.h"
18 #include "llvm/ADT/STLExtras.h"
19 #include "llvm/Support/ErrorHandling.h"
20 #include "llvm/Support/Format.h"
24 using namespace X86Disassembler
;
26 /// stringForContext - Returns a string containing the name of a particular
27 /// InstructionContext, usually for diagnostic purposes.
29 /// @param insnContext - The instruction class to transform to a string.
30 /// @return - A statically-allocated string constant that contains the
31 /// name of the instruction class.
32 static inline const char* stringForContext(InstructionContext insnContext
) {
33 switch (insnContext
) {
35 llvm_unreachable("Unhandled instruction class");
36 #define ENUM_ENTRY(n, r, d) case n: return #n; break;
37 #define ENUM_ENTRY_K_B(n, r, d) ENUM_ENTRY(n, r, d) ENUM_ENTRY(n##_K_B, r, d)\
38 ENUM_ENTRY(n##_KZ, r, d) ENUM_ENTRY(n##_K, r, d) ENUM_ENTRY(n##_B, r, d)\
39 ENUM_ENTRY(n##_KZ_B, r, d)
46 /// stringForOperandType - Like stringForContext, but for OperandTypes.
47 static inline const char* stringForOperandType(OperandType type
) {
50 llvm_unreachable("Unhandled type");
51 #define ENUM_ENTRY(i, d) case i: return #i;
57 /// stringForOperandEncoding - like stringForContext, but for
59 static inline const char* stringForOperandEncoding(OperandEncoding encoding
) {
62 llvm_unreachable("Unhandled encoding");
63 #define ENUM_ENTRY(i, d) case i: return #i;
69 /// inheritsFrom - Indicates whether all instructions in one class also belong
72 /// @param child - The class that may be the subset
73 /// @param parent - The class that may be the superset
74 /// @return - True if child is a subset of parent, false otherwise.
75 static inline bool inheritsFrom(InstructionContext child
,
76 InstructionContext parent
, bool noPrefix
= true,
77 bool VEX_LIG
= false, bool VEX_WIG
= false,
78 bool AdSize64
= false) {
84 return(inheritsFrom(child
, IC_64BIT
, AdSize64
) ||
85 (noPrefix
&& inheritsFrom(child
, IC_OPSIZE
, noPrefix
)) ||
86 inheritsFrom(child
, IC_ADSIZE
) ||
87 (noPrefix
&& inheritsFrom(child
, IC_XD
, noPrefix
)) ||
88 (noPrefix
&& inheritsFrom(child
, IC_XS
, noPrefix
)));
90 return(inheritsFrom(child
, IC_64BIT_REXW
) ||
91 (noPrefix
&& inheritsFrom(child
, IC_64BIT_OPSIZE
, noPrefix
)) ||
92 (!AdSize64
&& inheritsFrom(child
, IC_64BIT_ADSIZE
)) ||
93 (noPrefix
&& inheritsFrom(child
, IC_64BIT_XD
, noPrefix
)) ||
94 (noPrefix
&& inheritsFrom(child
, IC_64BIT_XS
, noPrefix
)));
96 return inheritsFrom(child
, IC_64BIT_OPSIZE
) ||
97 inheritsFrom(child
, IC_OPSIZE_ADSIZE
);
99 return (noPrefix
&& inheritsFrom(child
, IC_OPSIZE_ADSIZE
, noPrefix
));
100 case IC_OPSIZE_ADSIZE
:
102 case IC_64BIT_ADSIZE
:
103 return (noPrefix
&& inheritsFrom(child
, IC_64BIT_OPSIZE_ADSIZE
, noPrefix
));
104 case IC_64BIT_OPSIZE_ADSIZE
:
107 return inheritsFrom(child
, IC_64BIT_XD
);
109 return inheritsFrom(child
, IC_64BIT_XS
);
111 return inheritsFrom(child
, IC_64BIT_XD_OPSIZE
);
113 return inheritsFrom(child
, IC_64BIT_XS_OPSIZE
);
115 return inheritsFrom(child
, IC_64BIT_XD_ADSIZE
);
117 return inheritsFrom(child
, IC_64BIT_XS_ADSIZE
);
119 return((noPrefix
&& inheritsFrom(child
, IC_64BIT_REXW_XS
, noPrefix
)) ||
120 (noPrefix
&& inheritsFrom(child
, IC_64BIT_REXW_XD
, noPrefix
)) ||
121 (noPrefix
&& inheritsFrom(child
, IC_64BIT_REXW_OPSIZE
, noPrefix
)) ||
122 (!AdSize64
&& inheritsFrom(child
, IC_64BIT_REXW_ADSIZE
)));
123 case IC_64BIT_OPSIZE
:
124 return inheritsFrom(child
, IC_64BIT_REXW_OPSIZE
) ||
125 (!AdSize64
&& inheritsFrom(child
, IC_64BIT_OPSIZE_ADSIZE
)) ||
126 (!AdSize64
&& inheritsFrom(child
, IC_64BIT_REXW_ADSIZE
));
128 return(inheritsFrom(child
, IC_64BIT_REXW_XD
) ||
129 (!AdSize64
&& inheritsFrom(child
, IC_64BIT_XD_ADSIZE
)));
131 return(inheritsFrom(child
, IC_64BIT_REXW_XS
) ||
132 (!AdSize64
&& inheritsFrom(child
, IC_64BIT_XS_ADSIZE
)));
133 case IC_64BIT_XD_OPSIZE
:
134 case IC_64BIT_XS_OPSIZE
:
136 case IC_64BIT_XD_ADSIZE
:
137 case IC_64BIT_XS_ADSIZE
:
139 case IC_64BIT_REXW_XD
:
140 case IC_64BIT_REXW_XS
:
141 case IC_64BIT_REXW_OPSIZE
:
142 case IC_64BIT_REXW_ADSIZE
:
145 return (VEX_LIG
&& VEX_WIG
&& inheritsFrom(child
, IC_VEX_L_W
)) ||
146 (VEX_WIG
&& inheritsFrom(child
, IC_VEX_W
)) ||
147 (VEX_LIG
&& inheritsFrom(child
, IC_VEX_L
));
149 return (VEX_LIG
&& VEX_WIG
&& inheritsFrom(child
, IC_VEX_L_W_XS
)) ||
150 (VEX_WIG
&& inheritsFrom(child
, IC_VEX_W_XS
)) ||
151 (VEX_LIG
&& inheritsFrom(child
, IC_VEX_L_XS
));
153 return (VEX_LIG
&& VEX_WIG
&& inheritsFrom(child
, IC_VEX_L_W_XD
)) ||
154 (VEX_WIG
&& inheritsFrom(child
, IC_VEX_W_XD
)) ||
155 (VEX_LIG
&& inheritsFrom(child
, IC_VEX_L_XD
));
157 return (VEX_LIG
&& VEX_WIG
&& inheritsFrom(child
, IC_VEX_L_W_OPSIZE
)) ||
158 (VEX_WIG
&& inheritsFrom(child
, IC_VEX_W_OPSIZE
)) ||
159 (VEX_LIG
&& inheritsFrom(child
, IC_VEX_L_OPSIZE
));
161 return VEX_LIG
&& inheritsFrom(child
, IC_VEX_L_W
);
163 return VEX_LIG
&& inheritsFrom(child
, IC_VEX_L_W_XS
);
165 return VEX_LIG
&& inheritsFrom(child
, IC_VEX_L_W_XD
);
166 case IC_VEX_W_OPSIZE
:
167 return VEX_LIG
&& inheritsFrom(child
, IC_VEX_L_W_OPSIZE
);
169 return VEX_WIG
&& inheritsFrom(child
, IC_VEX_L_W
);
171 return VEX_WIG
&& inheritsFrom(child
, IC_VEX_L_W_XS
);
173 return VEX_WIG
&& inheritsFrom(child
, IC_VEX_L_W_XD
);
174 case IC_VEX_L_OPSIZE
:
175 return VEX_WIG
&& inheritsFrom(child
, IC_VEX_L_W_OPSIZE
);
179 case IC_VEX_L_W_OPSIZE
:
182 return (VEX_LIG
&& VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L_W
)) ||
183 (VEX_LIG
&& VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L2_W
)) ||
184 (VEX_WIG
&& inheritsFrom(child
, IC_EVEX_W
)) ||
185 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L
)) ||
186 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L2
));
188 return (VEX_LIG
&& VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L_W_XS
)) ||
189 (VEX_LIG
&& VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L2_W_XS
)) ||
190 (VEX_WIG
&& inheritsFrom(child
, IC_EVEX_W_XS
)) ||
191 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L_XS
)) ||
192 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L2_XS
));
194 return (VEX_LIG
&& VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L_W_XD
)) ||
195 (VEX_LIG
&& VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L2_W_XD
)) ||
196 (VEX_WIG
&& inheritsFrom(child
, IC_EVEX_W_XD
)) ||
197 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L_XD
)) ||
198 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L2_XD
));
200 return (VEX_LIG
&& VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L_W_OPSIZE
)) ||
201 (VEX_LIG
&& VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L2_W_OPSIZE
)) ||
202 (VEX_WIG
&& inheritsFrom(child
, IC_EVEX_W_OPSIZE
)) ||
203 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L_OPSIZE
)) ||
204 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L2_OPSIZE
));
206 return (VEX_LIG
&& VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L_W_K
)) ||
207 (VEX_LIG
&& VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L2_W_K
)) ||
208 (VEX_WIG
&& inheritsFrom(child
, IC_EVEX_W_K
)) ||
209 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L_K
)) ||
210 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L2_K
));
212 return (VEX_LIG
&& VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L_W_XS_K
)) ||
213 (VEX_LIG
&& VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L2_W_XS_K
)) ||
214 (VEX_WIG
&& inheritsFrom(child
, IC_EVEX_W_XS_K
)) ||
215 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L_XS_K
)) ||
216 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L2_XS_K
));
218 return (VEX_LIG
&& VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L_W_XD_K
)) ||
219 (VEX_LIG
&& VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L2_W_XD_K
)) ||
220 (VEX_WIG
&& inheritsFrom(child
, IC_EVEX_W_XD_K
)) ||
221 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L_XD_K
)) ||
222 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L2_XD_K
));
223 case IC_EVEX_OPSIZE_K
:
224 return (VEX_LIG
&& VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L_W_OPSIZE_K
)) ||
225 (VEX_LIG
&& VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L2_W_OPSIZE_K
)) ||
226 (VEX_WIG
&& inheritsFrom(child
, IC_EVEX_W_OPSIZE_K
)) ||
227 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L_OPSIZE_K
)) ||
228 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L2_OPSIZE_K
));
230 return (VEX_LIG
&& VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L_W_KZ
)) ||
231 (VEX_LIG
&& VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L2_W_KZ
)) ||
232 (VEX_WIG
&& inheritsFrom(child
, IC_EVEX_W_KZ
)) ||
233 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L_KZ
)) ||
234 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L2_KZ
));
236 return (VEX_LIG
&& VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L_W_XS_KZ
)) ||
237 (VEX_LIG
&& VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L2_W_XS_KZ
)) ||
238 (VEX_WIG
&& inheritsFrom(child
, IC_EVEX_W_XS_KZ
)) ||
239 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L_XS_KZ
)) ||
240 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L2_XS_KZ
));
242 return (VEX_LIG
&& VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L_W_XD_KZ
)) ||
243 (VEX_LIG
&& VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L2_W_XD_KZ
)) ||
244 (VEX_WIG
&& inheritsFrom(child
, IC_EVEX_W_XD_KZ
)) ||
245 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L_XD_KZ
)) ||
246 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L2_XD_KZ
));
247 case IC_EVEX_OPSIZE_KZ
:
248 return (VEX_LIG
&& VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L_W_OPSIZE_KZ
)) ||
249 (VEX_LIG
&& VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L2_W_OPSIZE_KZ
)) ||
250 (VEX_WIG
&& inheritsFrom(child
, IC_EVEX_W_OPSIZE_KZ
)) ||
251 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L_OPSIZE_KZ
)) ||
252 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L2_OPSIZE_KZ
));
254 return (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L_W
)) ||
255 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L2_W
));
257 return (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L_W_XS
)) ||
258 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L2_W_XS
));
260 return (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L_W_XD
)) ||
261 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L2_W_XD
));
262 case IC_EVEX_W_OPSIZE
:
263 return (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L_W_OPSIZE
)) ||
264 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L2_W_OPSIZE
));
266 return (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L_W_K
)) ||
267 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L2_W_K
));
269 return (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L_W_XS_K
)) ||
270 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L2_W_XS_K
));
272 return (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L_W_XD_K
)) ||
273 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L2_W_XD_K
));
274 case IC_EVEX_W_OPSIZE_K
:
275 return (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L_W_OPSIZE_K
)) ||
276 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L2_W_OPSIZE_K
));
278 return (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L_W_KZ
)) ||
279 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L2_W_KZ
));
280 case IC_EVEX_W_XS_KZ
:
281 return (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L_W_XS_KZ
)) ||
282 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L2_W_XS_KZ
));
283 case IC_EVEX_W_XD_KZ
:
284 return (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L_W_XD_KZ
)) ||
285 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L2_W_XD_KZ
));
286 case IC_EVEX_W_OPSIZE_KZ
:
287 return (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L_W_OPSIZE_KZ
)) ||
288 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L2_W_OPSIZE_KZ
));
290 return VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L_W
);
292 return VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L_W_XS
);
294 return VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L_W_XD
);
295 case IC_EVEX_L_OPSIZE
:
296 return VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L_W_OPSIZE
);
298 return VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L_W_K
);
300 return VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L_W_XS_K
);
302 return VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L_W_XD_K
);
303 case IC_EVEX_L_OPSIZE_K
:
304 return VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L_W_OPSIZE_K
);
306 return VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L_W_KZ
);
307 case IC_EVEX_L_XS_KZ
:
308 return VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L_W_XS_KZ
);
309 case IC_EVEX_L_XD_KZ
:
310 return VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L_W_XD_KZ
);
311 case IC_EVEX_L_OPSIZE_KZ
:
312 return VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L_W_OPSIZE_KZ
);
316 case IC_EVEX_L_W_OPSIZE
:
319 case IC_EVEX_L_W_XS_K
:
320 case IC_EVEX_L_W_XD_K
:
321 case IC_EVEX_L_W_OPSIZE_K
:
324 case IC_EVEX_L_W_XS_KZ
:
325 case IC_EVEX_L_W_XD_KZ
:
326 case IC_EVEX_L_W_OPSIZE_KZ
:
329 return VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L2_W
);
331 return VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L2_W_XS
);
333 return VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L2_W_XD
);
334 case IC_EVEX_L2_OPSIZE
:
335 return VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L2_W_OPSIZE
);
337 return VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L2_W_K
);
338 case IC_EVEX_L2_XS_K
:
339 return VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L2_W_XS_K
);
340 case IC_EVEX_L2_XD_K
:
341 return VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L2_W_XD_K
);
342 case IC_EVEX_L2_OPSIZE_K
:
343 return VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L2_W_OPSIZE_K
);
345 return VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L2_W_KZ
);
346 case IC_EVEX_L2_XS_KZ
:
347 return VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L2_W_XS_KZ
);
348 case IC_EVEX_L2_XD_KZ
:
349 return VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L2_W_XD_KZ
);
350 case IC_EVEX_L2_OPSIZE_KZ
:
351 return VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L2_W_OPSIZE_KZ
);
353 case IC_EVEX_L2_W_XS
:
354 case IC_EVEX_L2_W_XD
:
355 case IC_EVEX_L2_W_OPSIZE
:
358 case IC_EVEX_L2_W_XS_K
:
359 case IC_EVEX_L2_W_XD_K
:
360 case IC_EVEX_L2_W_OPSIZE_K
:
362 case IC_EVEX_L2_W_KZ
:
363 case IC_EVEX_L2_W_XS_KZ
:
364 case IC_EVEX_L2_W_XD_KZ
:
365 case IC_EVEX_L2_W_OPSIZE_KZ
:
368 return (VEX_LIG
&& VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L_W_B
)) ||
369 (VEX_LIG
&& VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L2_W_B
)) ||
370 (VEX_WIG
&& inheritsFrom(child
, IC_EVEX_W_B
)) ||
371 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L_B
)) ||
372 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L2_B
));
374 return (VEX_LIG
&& VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L_W_XS_B
)) ||
375 (VEX_LIG
&& VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L2_W_XS_B
)) ||
376 (VEX_WIG
&& inheritsFrom(child
, IC_EVEX_W_XS_B
)) ||
377 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L_XS_B
)) ||
378 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L2_XS_B
));
380 return (VEX_LIG
&& VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L_W_XD_B
)) ||
381 (VEX_LIG
&& VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L2_W_XD_B
)) ||
382 (VEX_WIG
&& inheritsFrom(child
, IC_EVEX_W_XD_B
)) ||
383 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L_XD_B
)) ||
384 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L2_XD_B
));
385 case IC_EVEX_OPSIZE_B
:
386 return (VEX_LIG
&& VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L_W_OPSIZE_B
)) ||
387 (VEX_LIG
&& VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L2_W_OPSIZE_B
)) ||
388 (VEX_WIG
&& inheritsFrom(child
, IC_EVEX_W_OPSIZE_B
)) ||
389 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L_OPSIZE_B
)) ||
390 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L2_OPSIZE_B
));
392 return (VEX_LIG
&& VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L_W_K_B
)) ||
393 (VEX_LIG
&& VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L2_W_K_B
)) ||
394 (VEX_WIG
&& inheritsFrom(child
, IC_EVEX_W_K_B
)) ||
395 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L_K_B
)) ||
396 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L2_K_B
));
398 return (VEX_LIG
&& VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L_W_XS_K_B
)) ||
399 (VEX_LIG
&& VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L2_W_XS_K_B
)) ||
400 (VEX_WIG
&& inheritsFrom(child
, IC_EVEX_W_XS_K_B
)) ||
401 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L_XS_K_B
)) ||
402 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L2_XS_K_B
));
404 return (VEX_LIG
&& VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L_W_XD_K_B
)) ||
405 (VEX_LIG
&& VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L2_W_XD_K_B
)) ||
406 (VEX_WIG
&& inheritsFrom(child
, IC_EVEX_W_XD_K_B
)) ||
407 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L_XD_K_B
)) ||
408 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L2_XD_K_B
));
409 case IC_EVEX_OPSIZE_K_B
:
410 return (VEX_LIG
&& VEX_WIG
&&
411 inheritsFrom(child
, IC_EVEX_L_W_OPSIZE_K_B
)) ||
412 (VEX_LIG
&& VEX_WIG
&&
413 inheritsFrom(child
, IC_EVEX_L2_W_OPSIZE_K_B
)) ||
414 (VEX_WIG
&& inheritsFrom(child
, IC_EVEX_W_OPSIZE_K_B
)) ||
415 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L_OPSIZE_K_B
)) ||
416 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L2_OPSIZE_K_B
));
418 return (VEX_LIG
&& VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L_W_KZ_B
)) ||
419 (VEX_LIG
&& VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L2_W_KZ_B
)) ||
420 (VEX_WIG
&& inheritsFrom(child
, IC_EVEX_W_KZ_B
)) ||
421 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L_KZ_B
)) ||
422 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L2_KZ_B
));
423 case IC_EVEX_XS_KZ_B
:
424 return (VEX_LIG
&& VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L_W_XS_KZ_B
)) ||
425 (VEX_LIG
&& VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L2_W_XS_KZ_B
)) ||
426 (VEX_WIG
&& inheritsFrom(child
, IC_EVEX_W_XS_KZ_B
)) ||
427 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L_XS_KZ_B
)) ||
428 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L2_XS_KZ_B
));
429 case IC_EVEX_XD_KZ_B
:
430 return (VEX_LIG
&& VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L_W_XD_KZ_B
)) ||
431 (VEX_LIG
&& VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L2_W_XD_KZ_B
)) ||
432 (VEX_WIG
&& inheritsFrom(child
, IC_EVEX_W_XD_KZ_B
)) ||
433 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L_XD_KZ_B
)) ||
434 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L2_XD_KZ_B
));
435 case IC_EVEX_OPSIZE_KZ_B
:
436 return (VEX_LIG
&& VEX_WIG
&&
437 inheritsFrom(child
, IC_EVEX_L_W_OPSIZE_KZ_B
)) ||
438 (VEX_LIG
&& VEX_WIG
&&
439 inheritsFrom(child
, IC_EVEX_L2_W_OPSIZE_KZ_B
)) ||
440 (VEX_WIG
&& inheritsFrom(child
, IC_EVEX_W_OPSIZE_KZ_B
)) ||
441 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L_OPSIZE_KZ_B
)) ||
442 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L2_OPSIZE_KZ_B
));
444 return (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L_W_B
)) ||
445 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L2_W_B
));
447 return (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L_W_XS_B
)) ||
448 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L2_W_XS_B
));
450 return (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L_W_XD_B
)) ||
451 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L2_W_XD_B
));
452 case IC_EVEX_W_OPSIZE_B
:
453 return (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L_W_OPSIZE_B
)) ||
454 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L2_W_OPSIZE_B
));
456 return (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L_W_K_B
)) ||
457 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L2_W_K_B
));
458 case IC_EVEX_W_XS_K_B
:
459 return (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L_W_XS_K_B
)) ||
460 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L2_W_XS_K_B
));
461 case IC_EVEX_W_XD_K_B
:
462 return (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L_W_XD_K_B
)) ||
463 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L2_W_XD_K_B
));
464 case IC_EVEX_W_OPSIZE_K_B
:
465 return (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L_W_OPSIZE_K_B
)) ||
466 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L2_W_OPSIZE_K_B
));
468 return (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L_W_KZ_B
)) ||
469 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L2_W_KZ_B
));
470 case IC_EVEX_W_XS_KZ_B
:
471 return (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L_W_XS_KZ_B
)) ||
472 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L2_W_XS_KZ_B
));
473 case IC_EVEX_W_XD_KZ_B
:
474 return (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L_W_XD_KZ_B
)) ||
475 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L2_W_XD_KZ_B
));
476 case IC_EVEX_W_OPSIZE_KZ_B
:
477 return (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L_W_OPSIZE_KZ_B
)) ||
478 (VEX_LIG
&& inheritsFrom(child
, IC_EVEX_L2_W_OPSIZE_KZ_B
));
480 return VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L_W_B
);
482 return VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L_W_XS_B
);
484 return VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L_W_XD_B
);
485 case IC_EVEX_L_OPSIZE_B
:
486 return VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L_W_OPSIZE_B
);
488 return VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L_W_K_B
);
489 case IC_EVEX_L_XS_K_B
:
490 return VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L_W_XS_K_B
);
491 case IC_EVEX_L_XD_K_B
:
492 return VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L_W_XD_K_B
);
493 case IC_EVEX_L_OPSIZE_K_B
:
494 return VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L_W_OPSIZE_K_B
);
496 return VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L_W_KZ_B
);
497 case IC_EVEX_L_XS_KZ_B
:
498 return VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L_W_XS_KZ_B
);
499 case IC_EVEX_L_XD_KZ_B
:
500 return VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L_W_XD_KZ_B
);
501 case IC_EVEX_L_OPSIZE_KZ_B
:
502 return VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L_W_OPSIZE_KZ_B
);
504 case IC_EVEX_L_W_XS_B
:
505 case IC_EVEX_L_W_XD_B
:
506 case IC_EVEX_L_W_OPSIZE_B
:
508 case IC_EVEX_L_W_K_B
:
509 case IC_EVEX_L_W_XS_K_B
:
510 case IC_EVEX_L_W_XD_K_B
:
511 case IC_EVEX_L_W_OPSIZE_K_B
:
513 case IC_EVEX_L_W_KZ_B
:
514 case IC_EVEX_L_W_XS_KZ_B
:
515 case IC_EVEX_L_W_XD_KZ_B
:
516 case IC_EVEX_L_W_OPSIZE_KZ_B
:
519 return VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L2_W_B
);
520 case IC_EVEX_L2_XS_B
:
521 return VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L2_W_XS_B
);
522 case IC_EVEX_L2_XD_B
:
523 return VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L2_W_XD_B
);
524 case IC_EVEX_L2_OPSIZE_B
:
525 return VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L2_W_OPSIZE_B
);
527 return VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L2_W_K_B
);
528 case IC_EVEX_L2_XS_K_B
:
529 return VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L2_W_XS_K_B
);
530 case IC_EVEX_L2_XD_K_B
:
531 return VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L2_W_XD_K_B
);
532 case IC_EVEX_L2_OPSIZE_K_B
:
533 return VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L2_W_OPSIZE_K_B
);
534 case IC_EVEX_L2_KZ_B
:
535 return VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L2_W_KZ_B
);
536 case IC_EVEX_L2_XS_KZ_B
:
537 return VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L2_W_XS_KZ_B
);
538 case IC_EVEX_L2_XD_KZ_B
:
539 return VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L2_W_XD_KZ_B
);
540 case IC_EVEX_L2_OPSIZE_KZ_B
:
541 return VEX_WIG
&& inheritsFrom(child
, IC_EVEX_L2_W_OPSIZE_KZ_B
);
543 case IC_EVEX_L2_W_XS_B
:
544 case IC_EVEX_L2_W_XD_B
:
545 case IC_EVEX_L2_W_OPSIZE_B
:
547 case IC_EVEX_L2_W_K_B
:
548 case IC_EVEX_L2_W_XS_K_B
:
549 case IC_EVEX_L2_W_XD_K_B
:
550 case IC_EVEX_L2_W_OPSIZE_K_B
:
552 case IC_EVEX_L2_W_KZ_B
:
553 case IC_EVEX_L2_W_XS_KZ_B
:
554 case IC_EVEX_L2_W_XD_KZ_B
:
555 case IC_EVEX_L2_W_OPSIZE_KZ_B
:
558 errs() << "Unknown instruction class: " <<
559 stringForContext((InstructionContext
)parent
) << "\n";
560 llvm_unreachable("Unknown instruction class");
564 /// outranks - Indicates whether, if an instruction has two different applicable
565 /// classes, which class should be preferred when performing decode. This
566 /// imposes a total ordering (ties are resolved toward "lower")
568 /// @param upper - The class that may be preferable
569 /// @param lower - The class that may be less preferable
570 /// @return - True if upper is to be preferred, false otherwise.
571 static inline bool outranks(InstructionContext upper
,
572 InstructionContext lower
) {
573 assert(upper
< IC_max
);
574 assert(lower
< IC_max
);
576 #define ENUM_ENTRY(n, r, d) r,
577 #define ENUM_ENTRY_K_B(n, r, d) ENUM_ENTRY(n, r, d) \
578 ENUM_ENTRY(n##_K_B, r, d) ENUM_ENTRY(n##_KZ_B, r, d) \
579 ENUM_ENTRY(n##_KZ, r, d) ENUM_ENTRY(n##_K, r, d) ENUM_ENTRY(n##_B, r, d)
580 static int ranks
[IC_max
] = {
584 #undef ENUM_ENTRY_K_B
586 return (ranks
[upper
] > ranks
[lower
]);
589 /// getDecisionType - Determines whether a ModRM decision with 255 entries can
590 /// be compacted by eliminating redundant information.
592 /// @param decision - The decision to be compacted.
593 /// @return - The compactest available representation for the decision.
594 static ModRMDecisionType
getDecisionType(ModRMDecision
&decision
) {
595 bool satisfiesOneEntry
= true;
596 bool satisfiesSplitRM
= true;
597 bool satisfiesSplitReg
= true;
598 bool satisfiesSplitMisc
= true;
600 for (unsigned index
= 0; index
< 256; ++index
) {
601 if (decision
.instructionIDs
[index
] != decision
.instructionIDs
[0])
602 satisfiesOneEntry
= false;
604 if (((index
& 0xc0) == 0xc0) &&
605 (decision
.instructionIDs
[index
] != decision
.instructionIDs
[0xc0]))
606 satisfiesSplitRM
= false;
608 if (((index
& 0xc0) != 0xc0) &&
609 (decision
.instructionIDs
[index
] != decision
.instructionIDs
[0x00]))
610 satisfiesSplitRM
= false;
612 if (((index
& 0xc0) == 0xc0) &&
613 (decision
.instructionIDs
[index
] != decision
.instructionIDs
[index
&0xf8]))
614 satisfiesSplitReg
= false;
616 if (((index
& 0xc0) != 0xc0) &&
617 (decision
.instructionIDs
[index
] != decision
.instructionIDs
[index
&0x38]))
618 satisfiesSplitMisc
= false;
621 if (satisfiesOneEntry
)
622 return MODRM_ONEENTRY
;
624 if (satisfiesSplitRM
)
625 return MODRM_SPLITRM
;
627 if (satisfiesSplitReg
&& satisfiesSplitMisc
)
628 return MODRM_SPLITREG
;
630 if (satisfiesSplitMisc
)
631 return MODRM_SPLITMISC
;
636 /// stringForDecisionType - Returns a statically-allocated string corresponding
637 /// to a particular decision type.
639 /// @param dt - The decision type.
640 /// @return - A pointer to the statically-allocated string (e.g.,
641 /// "MODRM_ONEENTRY" for MODRM_ONEENTRY).
642 static const char* stringForDecisionType(ModRMDecisionType dt
) {
643 #define ENUM_ENTRY(n) case n: return #n;
646 llvm_unreachable("Unknown decision type");
652 DisassemblerTables::DisassemblerTables() {
653 for (unsigned i
= 0; i
< array_lengthof(Tables
); i
++)
654 Tables
[i
] = std::make_unique
<ContextDecision
>();
656 HasConflicts
= false;
659 DisassemblerTables::~DisassemblerTables() {
662 void DisassemblerTables::emitModRMDecision(raw_ostream
&o1
, raw_ostream
&o2
,
663 unsigned &i1
, unsigned &i2
,
664 unsigned &ModRMTableNum
,
665 ModRMDecision
&decision
) const {
666 static uint32_t sTableNumber
= 0;
667 static uint32_t sEntryNumber
= 1;
668 ModRMDecisionType dt
= getDecisionType(decision
);
670 if (dt
== MODRM_ONEENTRY
&& decision
.instructionIDs
[0] == 0)
672 o2
.indent(i2
) << "{ /* ModRMDecision */" << "\n";
675 o2
.indent(i2
) << stringForDecisionType(dt
) << "," << "\n";
676 o2
.indent(i2
) << 0 << " /* EmptyTable */\n";
679 o2
.indent(i2
) << "}";
683 std::vector
<unsigned> ModRMDecision
;
687 llvm_unreachable("Unknown decision type");
689 ModRMDecision
.push_back(decision
.instructionIDs
[0]);
692 ModRMDecision
.push_back(decision
.instructionIDs
[0x00]);
693 ModRMDecision
.push_back(decision
.instructionIDs
[0xc0]);
696 for (unsigned index
= 0; index
< 64; index
+= 8)
697 ModRMDecision
.push_back(decision
.instructionIDs
[index
]);
698 for (unsigned index
= 0xc0; index
< 256; index
+= 8)
699 ModRMDecision
.push_back(decision
.instructionIDs
[index
]);
701 case MODRM_SPLITMISC
:
702 for (unsigned index
= 0; index
< 64; index
+= 8)
703 ModRMDecision
.push_back(decision
.instructionIDs
[index
]);
704 for (unsigned index
= 0xc0; index
< 256; ++index
)
705 ModRMDecision
.push_back(decision
.instructionIDs
[index
]);
708 for (unsigned index
= 0; index
< 256; ++index
)
709 ModRMDecision
.push_back(decision
.instructionIDs
[index
]);
713 unsigned &EntryNumber
= ModRMTable
[ModRMDecision
];
714 if (EntryNumber
== 0) {
715 EntryNumber
= ModRMTableNum
;
717 ModRMTableNum
+= ModRMDecision
.size();
718 o1
<< "/* Table" << EntryNumber
<< " */\n";
720 for (std::vector
<unsigned>::const_iterator I
= ModRMDecision
.begin(),
721 E
= ModRMDecision
.end(); I
!= E
; ++I
) {
722 o1
.indent(i1
* 2) << format("0x%hx", *I
) << ", /* "
723 << InstructionSpecifiers
[*I
].name
<< " */\n";
728 o2
.indent(i2
) << "{ /* struct ModRMDecision */" << "\n";
731 o2
.indent(i2
) << stringForDecisionType(dt
) << "," << "\n";
732 o2
.indent(i2
) << EntryNumber
<< " /* Table" << EntryNumber
<< " */\n";
735 o2
.indent(i2
) << "}";
739 llvm_unreachable("Unknown decision type");
749 case MODRM_SPLITMISC
:
750 sEntryNumber
+= 8 + 64;
757 // We assume that the index can fit into uint16_t.
758 assert(sEntryNumber
< 65536U &&
759 "Index into ModRMDecision is too large for uint16_t!");
764 void DisassemblerTables::emitOpcodeDecision(raw_ostream
&o1
, raw_ostream
&o2
,
765 unsigned &i1
, unsigned &i2
,
766 unsigned &ModRMTableNum
,
767 OpcodeDecision
&decision
) const {
768 o2
.indent(i2
) << "{ /* struct OpcodeDecision */" << "\n";
770 o2
.indent(i2
) << "{" << "\n";
773 for (unsigned index
= 0; index
< 256; ++index
) {
776 o2
<< "/* 0x" << format("%02hhx", index
) << " */" << "\n";
778 emitModRMDecision(o1
, o2
, i1
, i2
, ModRMTableNum
,
779 decision
.modRMDecisions
[index
]);
788 o2
.indent(i2
) << "}" << "\n";
790 o2
.indent(i2
) << "}" << "\n";
793 void DisassemblerTables::emitContextDecision(raw_ostream
&o1
, raw_ostream
&o2
,
794 unsigned &i1
, unsigned &i2
,
795 unsigned &ModRMTableNum
,
796 ContextDecision
&decision
,
797 const char* name
) const {
798 o2
.indent(i2
) << "static const struct ContextDecision " << name
<< " = {\n";
800 o2
.indent(i2
) << "{ /* opcodeDecisions */" << "\n";
803 for (unsigned index
= 0; index
< IC_max
; ++index
) {
804 o2
.indent(i2
) << "/* ";
805 o2
<< stringForContext((InstructionContext
)index
);
809 emitOpcodeDecision(o1
, o2
, i1
, i2
, ModRMTableNum
,
810 decision
.opcodeDecisions
[index
]);
812 if (index
+ 1 < IC_max
)
817 o2
.indent(i2
) << "}" << "\n";
819 o2
.indent(i2
) << "};" << "\n";
822 void DisassemblerTables::emitInstructionInfo(raw_ostream
&o
,
824 unsigned NumInstructions
= InstructionSpecifiers
.size();
826 o
<< "static const struct OperandSpecifier x86OperandSets[]["
827 << X86_MAX_OPERANDS
<< "] = {\n";
829 typedef SmallVector
<std::pair
<OperandEncoding
, OperandType
>,
830 X86_MAX_OPERANDS
> OperandListTy
;
831 std::map
<OperandListTy
, unsigned> OperandSets
;
833 unsigned OperandSetNum
= 0;
834 for (unsigned Index
= 0; Index
< NumInstructions
; ++Index
) {
835 OperandListTy OperandList
;
837 for (unsigned OperandIndex
= 0; OperandIndex
< X86_MAX_OPERANDS
;
839 OperandEncoding Encoding
= (OperandEncoding
)InstructionSpecifiers
[Index
]
840 .operands
[OperandIndex
].encoding
;
841 OperandType Type
= (OperandType
)InstructionSpecifiers
[Index
]
842 .operands
[OperandIndex
].type
;
843 OperandList
.push_back(std::make_pair(Encoding
, Type
));
845 unsigned &N
= OperandSets
[OperandList
];
846 if (N
!= 0) continue;
850 o
<< " { /* " << (OperandSetNum
- 1) << " */\n";
851 for (unsigned i
= 0, e
= OperandList
.size(); i
!= e
; ++i
) {
852 const char *Encoding
= stringForOperandEncoding(OperandList
[i
].first
);
853 const char *Type
= stringForOperandType(OperandList
[i
].second
);
854 o
<< " { " << Encoding
<< ", " << Type
<< " },\n";
860 o
.indent(i
* 2) << "static const struct InstructionSpecifier ";
861 o
<< INSTRUCTIONS_STR
"[" << InstructionSpecifiers
.size() << "] = {\n";
865 for (unsigned index
= 0; index
< NumInstructions
; ++index
) {
866 o
.indent(i
* 2) << "{ /* " << index
<< " */\n";
869 OperandListTy OperandList
;
870 for (unsigned OperandIndex
= 0; OperandIndex
< X86_MAX_OPERANDS
;
872 OperandEncoding Encoding
= (OperandEncoding
)InstructionSpecifiers
[index
]
873 .operands
[OperandIndex
].encoding
;
874 OperandType Type
= (OperandType
)InstructionSpecifiers
[index
]
875 .operands
[OperandIndex
].type
;
876 OperandList
.push_back(std::make_pair(Encoding
, Type
));
878 o
.indent(i
* 2) << (OperandSets
[OperandList
] - 1) << ",\n";
880 o
.indent(i
* 2) << "/* " << InstructionSpecifiers
[index
].name
<< " */\n";
883 o
.indent(i
* 2) << "},\n";
887 o
.indent(i
* 2) << "};" << "\n";
890 void DisassemblerTables::emitContextTable(raw_ostream
&o
, unsigned &i
) const {
891 o
.indent(i
* 2) << "static const uint8_t " CONTEXTS_STR
892 "[" << ATTR_max
<< "] = {\n";
895 for (unsigned index
= 0; index
< ATTR_max
; ++index
) {
898 if ((index
& ATTR_EVEX
) || (index
& ATTR_VEX
) || (index
& ATTR_VEXL
)) {
899 if (index
& ATTR_EVEX
)
904 if ((index
& ATTR_EVEX
) && (index
& ATTR_EVEXL2
))
906 else if (index
& ATTR_VEXL
)
909 if (index
& ATTR_REXW
)
912 if (index
& ATTR_OPSIZE
)
914 else if (index
& ATTR_XD
)
916 else if (index
& ATTR_XS
)
919 if ((index
& ATTR_EVEX
)) {
920 if (index
& ATTR_EVEXKZ
)
922 else if (index
& ATTR_EVEXK
)
925 if (index
& ATTR_EVEXB
)
929 else if ((index
& ATTR_64BIT
) && (index
& ATTR_REXW
) && (index
& ATTR_XS
))
930 o
<< "IC_64BIT_REXW_XS";
931 else if ((index
& ATTR_64BIT
) && (index
& ATTR_REXW
) && (index
& ATTR_XD
))
932 o
<< "IC_64BIT_REXW_XD";
933 else if ((index
& ATTR_64BIT
) && (index
& ATTR_REXW
) &&
934 (index
& ATTR_OPSIZE
))
935 o
<< "IC_64BIT_REXW_OPSIZE";
936 else if ((index
& ATTR_64BIT
) && (index
& ATTR_REXW
) &&
937 (index
& ATTR_ADSIZE
))
938 o
<< "IC_64BIT_REXW_ADSIZE";
939 else if ((index
& ATTR_64BIT
) && (index
& ATTR_XD
) && (index
& ATTR_OPSIZE
))
940 o
<< "IC_64BIT_XD_OPSIZE";
941 else if ((index
& ATTR_64BIT
) && (index
& ATTR_XD
) && (index
& ATTR_ADSIZE
))
942 o
<< "IC_64BIT_XD_ADSIZE";
943 else if ((index
& ATTR_64BIT
) && (index
& ATTR_XS
) && (index
& ATTR_OPSIZE
))
944 o
<< "IC_64BIT_XS_OPSIZE";
945 else if ((index
& ATTR_64BIT
) && (index
& ATTR_XS
) && (index
& ATTR_ADSIZE
))
946 o
<< "IC_64BIT_XS_ADSIZE";
947 else if ((index
& ATTR_64BIT
) && (index
& ATTR_XS
))
949 else if ((index
& ATTR_64BIT
) && (index
& ATTR_XD
))
951 else if ((index
& ATTR_64BIT
) && (index
& ATTR_OPSIZE
) &&
952 (index
& ATTR_ADSIZE
))
953 o
<< "IC_64BIT_OPSIZE_ADSIZE";
954 else if ((index
& ATTR_64BIT
) && (index
& ATTR_OPSIZE
))
955 o
<< "IC_64BIT_OPSIZE";
956 else if ((index
& ATTR_64BIT
) && (index
& ATTR_ADSIZE
))
957 o
<< "IC_64BIT_ADSIZE";
958 else if ((index
& ATTR_64BIT
) && (index
& ATTR_REXW
))
959 o
<< "IC_64BIT_REXW";
960 else if ((index
& ATTR_64BIT
))
962 else if ((index
& ATTR_XS
) && (index
& ATTR_OPSIZE
))
964 else if ((index
& ATTR_XD
) && (index
& ATTR_OPSIZE
))
966 else if ((index
& ATTR_XS
) && (index
& ATTR_ADSIZE
))
968 else if ((index
& ATTR_XD
) && (index
& ATTR_ADSIZE
))
970 else if (index
& ATTR_XS
)
972 else if (index
& ATTR_XD
)
974 else if ((index
& ATTR_OPSIZE
) && (index
& ATTR_ADSIZE
))
975 o
<< "IC_OPSIZE_ADSIZE";
976 else if (index
& ATTR_OPSIZE
)
978 else if (index
& ATTR_ADSIZE
)
983 o
<< ", /* " << index
<< " */";
989 o
.indent(i
* 2) << "};" << "\n";
992 void DisassemblerTables::emitContextDecisions(raw_ostream
&o1
, raw_ostream
&o2
,
993 unsigned &i1
, unsigned &i2
,
994 unsigned &ModRMTableNum
) const {
995 emitContextDecision(o1
, o2
, i1
, i2
, ModRMTableNum
, *Tables
[0], ONEBYTE_STR
);
996 emitContextDecision(o1
, o2
, i1
, i2
, ModRMTableNum
, *Tables
[1], TWOBYTE_STR
);
997 emitContextDecision(o1
, o2
, i1
, i2
, ModRMTableNum
, *Tables
[2], THREEBYTE38_STR
);
998 emitContextDecision(o1
, o2
, i1
, i2
, ModRMTableNum
, *Tables
[3], THREEBYTE3A_STR
);
999 emitContextDecision(o1
, o2
, i1
, i2
, ModRMTableNum
, *Tables
[4], XOP8_MAP_STR
);
1000 emitContextDecision(o1
, o2
, i1
, i2
, ModRMTableNum
, *Tables
[5], XOP9_MAP_STR
);
1001 emitContextDecision(o1
, o2
, i1
, i2
, ModRMTableNum
, *Tables
[6], XOPA_MAP_STR
);
1002 emitContextDecision(o1
, o2
, i1
, i2
, ModRMTableNum
, *Tables
[7], THREEDNOW_MAP_STR
);
1005 void DisassemblerTables::emit(raw_ostream
&o
) const {
1012 raw_string_ostream
o1(s1
);
1013 raw_string_ostream
o2(s2
);
1015 emitInstructionInfo(o
, i2
);
1018 emitContextTable(o
, i2
);
1021 unsigned ModRMTableNum
= 0;
1023 o
<< "static const InstrUID modRMTable[] = {\n";
1025 std::vector
<unsigned> EmptyTable(1, 0);
1026 ModRMTable
[EmptyTable
] = ModRMTableNum
;
1027 ModRMTableNum
+= EmptyTable
.size();
1028 o1
<< "/* EmptyTable */\n";
1029 o1
.indent(i1
* 2) << "0x0,\n";
1031 emitContextDecisions(o1
, o2
, i1
, i2
, ModRMTableNum
);
1042 void DisassemblerTables::setTableFields(ModRMDecision
&decision
,
1043 const ModRMFilter
&filter
,
1046 for (unsigned index
= 0; index
< 256; ++index
) {
1047 if (filter
.accepts(index
)) {
1048 if (decision
.instructionIDs
[index
] == uid
)
1051 if (decision
.instructionIDs
[index
] != 0) {
1052 InstructionSpecifier
&newInfo
=
1053 InstructionSpecifiers
[uid
];
1054 InstructionSpecifier
&previousInfo
=
1055 InstructionSpecifiers
[decision
.instructionIDs
[index
]];
1057 if(previousInfo
.name
== "NOOP" && (newInfo
.name
== "XCHG16ar" ||
1058 newInfo
.name
== "XCHG32ar" ||
1059 newInfo
.name
== "XCHG64ar"))
1060 continue; // special case for XCHG*ar and NOOP
1062 if (outranks(previousInfo
.insnContext
, newInfo
.insnContext
))
1065 if (previousInfo
.insnContext
== newInfo
.insnContext
) {
1066 errs() << "Error: Primary decode conflict: ";
1067 errs() << newInfo
.name
<< " would overwrite " << previousInfo
.name
;
1069 errs() << "ModRM " << index
<< "\n";
1070 errs() << "Opcode " << (uint16_t)opcode
<< "\n";
1071 errs() << "Context " << stringForContext(newInfo
.insnContext
) << "\n";
1072 HasConflicts
= true;
1076 decision
.instructionIDs
[index
] = uid
;
1081 void DisassemblerTables::setTableFields(OpcodeType type
,
1082 InstructionContext insnContext
,
1084 const ModRMFilter
&filter
,
1090 unsigned addressSize
) {
1091 ContextDecision
&decision
= *Tables
[type
];
1093 for (unsigned index
= 0; index
< IC_max
; ++index
) {
1094 if ((is32bit
|| addressSize
== 16) &&
1095 inheritsFrom((InstructionContext
)index
, IC_64BIT
))
1098 bool adSize64
= addressSize
== 64;
1099 if (inheritsFrom((InstructionContext
)index
,
1100 InstructionSpecifiers
[uid
].insnContext
, noPrefix
,
1101 ignoresVEX_L
, ignoresVEX_W
, adSize64
))
1102 setTableFields(decision
.opcodeDecisions
[index
].modRMDecisions
[opcode
],