blob: 0838ac412ee498b7bd0199a932b5686dc24fc256 [file] [log] [blame]
Sean Callanan8ed9f512009-12-19 02:59:52 +00001//===- X86DisassemblerTables.cpp - Disassembler tables ----------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file is part of the X86 Disassembler Emitter.
11// It contains the implementation of the disassembler tables.
12// Documentation for the disassembler emitter in general can be found in
13// X86DisasemblerEmitter.h.
14//
15//===----------------------------------------------------------------------===//
16
Sean Callanan8ed9f512009-12-19 02:59:52 +000017#include "X86DisassemblerTables.h"
Chandler Carruth4ffd89f2012-12-04 10:37:14 +000018#include "X86DisassemblerShared.h"
Joerg Sonnenberger39d7cae2011-04-04 16:25:38 +000019#include "llvm/ADT/STLExtras.h"
Sean Callanan8ed9f512009-12-19 02:59:52 +000020#include "llvm/Support/ErrorHandling.h"
21#include "llvm/Support/Format.h"
Chandler Carruth4ffd89f2012-12-04 10:37:14 +000022#include "llvm/TableGen/TableGenBackend.h"
Craig Topper5a2c6072012-08-01 07:39:18 +000023#include <map>
Sean Callanan8ed9f512009-12-19 02:59:52 +000024
Sean Callanan8ed9f512009-12-19 02:59:52 +000025using namespace llvm;
26using namespace X86Disassembler;
Craig Topper98400092012-07-31 05:27:01 +000027
Sean Callanan8ed9f512009-12-19 02:59:52 +000028/// inheritsFrom - Indicates whether all instructions in one class also belong
29/// to another class.
30///
31/// @param child - The class that may be the subset
32/// @param parent - The class that may be the superset
33/// @return - True if child is a subset of parent, false otherwise.
34static inline bool inheritsFrom(InstructionContext child,
Craig Topper6744a172011-10-04 06:30:42 +000035 InstructionContext parent,
36 bool VEX_LIG = false) {
Sean Callanan8ed9f512009-12-19 02:59:52 +000037 if (child == parent)
38 return true;
Craig Topper98400092012-07-31 05:27:01 +000039
Sean Callanan8ed9f512009-12-19 02:59:52 +000040 switch (parent) {
41 case IC:
Craig Topper5ffedb92011-09-02 04:17:54 +000042 return(inheritsFrom(child, IC_64BIT) ||
43 inheritsFrom(child, IC_OPSIZE) ||
Craig Topper930a1eb2012-02-27 01:54:29 +000044 inheritsFrom(child, IC_ADSIZE) ||
Craig Topper5ffedb92011-09-02 04:17:54 +000045 inheritsFrom(child, IC_XD) ||
46 inheritsFrom(child, IC_XS));
Sean Callanan8ed9f512009-12-19 02:59:52 +000047 case IC_64BIT:
48 return(inheritsFrom(child, IC_64BIT_REXW) ||
49 inheritsFrom(child, IC_64BIT_OPSIZE) ||
Craig Topper930a1eb2012-02-27 01:54:29 +000050 inheritsFrom(child, IC_64BIT_ADSIZE) ||
Sean Callanan8ed9f512009-12-19 02:59:52 +000051 inheritsFrom(child, IC_64BIT_XD) ||
52 inheritsFrom(child, IC_64BIT_XS));
53 case IC_OPSIZE:
Craig Topper5ffedb92011-09-02 04:17:54 +000054 return inheritsFrom(child, IC_64BIT_OPSIZE);
Craig Topper930a1eb2012-02-27 01:54:29 +000055 case IC_ADSIZE:
56 case IC_64BIT_ADSIZE:
57 return false;
Sean Callanan8ed9f512009-12-19 02:59:52 +000058 case IC_XD:
Craig Topper5ffedb92011-09-02 04:17:54 +000059 return inheritsFrom(child, IC_64BIT_XD);
Sean Callanan8ed9f512009-12-19 02:59:52 +000060 case IC_XS:
Craig Topper5ffedb92011-09-02 04:17:54 +000061 return inheritsFrom(child, IC_64BIT_XS);
Craig Toppere1b4a1a2011-10-01 19:54:56 +000062 case IC_XD_OPSIZE:
63 return inheritsFrom(child, IC_64BIT_XD_OPSIZE);
Craig Topper29480fd2011-10-11 04:34:23 +000064 case IC_XS_OPSIZE:
65 return inheritsFrom(child, IC_64BIT_XS_OPSIZE);
Sean Callanan8ed9f512009-12-19 02:59:52 +000066 case IC_64BIT_REXW:
67 return(inheritsFrom(child, IC_64BIT_REXW_XS) ||
68 inheritsFrom(child, IC_64BIT_REXW_XD) ||
69 inheritsFrom(child, IC_64BIT_REXW_OPSIZE));
70 case IC_64BIT_OPSIZE:
71 return(inheritsFrom(child, IC_64BIT_REXW_OPSIZE));
72 case IC_64BIT_XD:
73 return(inheritsFrom(child, IC_64BIT_REXW_XD));
74 case IC_64BIT_XS:
75 return(inheritsFrom(child, IC_64BIT_REXW_XS));
Craig Toppere1b4a1a2011-10-01 19:54:56 +000076 case IC_64BIT_XD_OPSIZE:
Craig Topper29480fd2011-10-11 04:34:23 +000077 case IC_64BIT_XS_OPSIZE:
Craig Toppere1b4a1a2011-10-01 19:54:56 +000078 return false;
Sean Callanan8ed9f512009-12-19 02:59:52 +000079 case IC_64BIT_REXW_XD:
Sean Callanan8ed9f512009-12-19 02:59:52 +000080 case IC_64BIT_REXW_XS:
Sean Callanan8ed9f512009-12-19 02:59:52 +000081 case IC_64BIT_REXW_OPSIZE:
82 return false;
Sean Callanana21e2ea2011-03-15 01:23:15 +000083 case IC_VEX:
Elena Demikhovskyc18f4ef2013-07-28 08:28:38 +000084 return inheritsFrom(child, IC_VEX_L_W) ||
85 inheritsFrom(child, IC_VEX_W) ||
Craig Topper6744a172011-10-04 06:30:42 +000086 (VEX_LIG && inheritsFrom(child, IC_VEX_L));
Sean Callanana21e2ea2011-03-15 01:23:15 +000087 case IC_VEX_XS:
Elena Demikhovskyc18f4ef2013-07-28 08:28:38 +000088 return inheritsFrom(child, IC_VEX_L_W_XS) ||
89 inheritsFrom(child, IC_VEX_W_XS) ||
Craig Topper6744a172011-10-04 06:30:42 +000090 (VEX_LIG && inheritsFrom(child, IC_VEX_L_XS));
Sean Callanana21e2ea2011-03-15 01:23:15 +000091 case IC_VEX_XD:
Elena Demikhovskyc18f4ef2013-07-28 08:28:38 +000092 return inheritsFrom(child, IC_VEX_L_W_XD) ||
93 inheritsFrom(child, IC_VEX_W_XD) ||
Craig Topper6744a172011-10-04 06:30:42 +000094 (VEX_LIG && inheritsFrom(child, IC_VEX_L_XD));
Craig Topper5ffedb92011-09-02 04:17:54 +000095 case IC_VEX_OPSIZE:
Elena Demikhovskyc18f4ef2013-07-28 08:28:38 +000096 return inheritsFrom(child, IC_VEX_L_W_OPSIZE) ||
97 inheritsFrom(child, IC_VEX_W_OPSIZE) ||
Craig Topper6744a172011-10-04 06:30:42 +000098 (VEX_LIG && inheritsFrom(child, IC_VEX_L_OPSIZE));
Sean Callanana21e2ea2011-03-15 01:23:15 +000099 case IC_VEX_W:
Sean Callanana21e2ea2011-03-15 01:23:15 +0000100 case IC_VEX_W_XS:
Sean Callanana21e2ea2011-03-15 01:23:15 +0000101 case IC_VEX_W_XD:
Craig Topper5ffedb92011-09-02 04:17:54 +0000102 case IC_VEX_W_OPSIZE:
103 return false;
104 case IC_VEX_L:
Craig Topper5ffedb92011-09-02 04:17:54 +0000105 case IC_VEX_L_XS:
Craig Topper5ffedb92011-09-02 04:17:54 +0000106 case IC_VEX_L_XD:
Craig Topper5ffedb92011-09-02 04:17:54 +0000107 case IC_VEX_L_OPSIZE:
Elena Demikhovskyc18f4ef2013-07-28 08:28:38 +0000108 return false;
109 case IC_VEX_L_W:
110 case IC_VEX_L_W_XS:
111 case IC_VEX_L_W_XD:
Craig Topperc8eb8802011-11-06 23:04:08 +0000112 case IC_VEX_L_W_OPSIZE:
Craig Topper5ffedb92011-09-02 04:17:54 +0000113 return false;
Elena Demikhovskyc18f4ef2013-07-28 08:28:38 +0000114 case IC_EVEX:
115 return inheritsFrom(child, IC_EVEX_W) ||
116 inheritsFrom(child, IC_EVEX_L_W);
117 case IC_EVEX_XS:
118 return inheritsFrom(child, IC_EVEX_W_XS) ||
119 inheritsFrom(child, IC_EVEX_L_W_XS);
120 case IC_EVEX_XD:
121 return inheritsFrom(child, IC_EVEX_W_XD) ||
122 inheritsFrom(child, IC_EVEX_L_W_XD);
123 case IC_EVEX_OPSIZE:
124 return inheritsFrom(child, IC_EVEX_W_OPSIZE) ||
125 inheritsFrom(child, IC_EVEX_W_OPSIZE);
126 case IC_EVEX_W:
127 case IC_EVEX_W_XS:
128 case IC_EVEX_W_XD:
129 case IC_EVEX_W_OPSIZE:
130 return false;
131 case IC_EVEX_L:
132 case IC_EVEX_L_XS:
133 case IC_EVEX_L_XD:
134 case IC_EVEX_L_OPSIZE:
135 return false;
136 case IC_EVEX_L_W:
137 case IC_EVEX_L_W_XS:
138 case IC_EVEX_L_W_XD:
139 case IC_EVEX_L_W_OPSIZE:
140 return false;
141 case IC_EVEX_L2:
142 case IC_EVEX_L2_XS:
143 case IC_EVEX_L2_XD:
144 case IC_EVEX_L2_OPSIZE:
145 return false;
146 case IC_EVEX_L2_W:
147 case IC_EVEX_L2_W_XS:
148 case IC_EVEX_L2_W_XD:
149 case IC_EVEX_L2_W_OPSIZE:
150 return false;
151 case IC_EVEX_K:
152 return inheritsFrom(child, IC_EVEX_W_K) ||
153 inheritsFrom(child, IC_EVEX_L_W_K);
154 case IC_EVEX_XS_K:
155 return inheritsFrom(child, IC_EVEX_W_XS_K) ||
156 inheritsFrom(child, IC_EVEX_L_W_XS_K);
157 case IC_EVEX_XD_K:
158 return inheritsFrom(child, IC_EVEX_W_XD_K) ||
159 inheritsFrom(child, IC_EVEX_L_W_XD_K);
160 case IC_EVEX_OPSIZE_K:
161 return inheritsFrom(child, IC_EVEX_W_OPSIZE_K) ||
162 inheritsFrom(child, IC_EVEX_W_OPSIZE_K);
163 case IC_EVEX_W_K:
164 case IC_EVEX_W_XS_K:
165 case IC_EVEX_W_XD_K:
166 case IC_EVEX_W_OPSIZE_K:
167 return false;
168 case IC_EVEX_L_K:
169 case IC_EVEX_L_XS_K:
170 case IC_EVEX_L_XD_K:
171 case IC_EVEX_L_OPSIZE_K:
172 return false;
173 case IC_EVEX_L_W_K:
174 case IC_EVEX_L_W_XS_K:
175 case IC_EVEX_L_W_XD_K:
176 case IC_EVEX_L_W_OPSIZE_K:
177 return false;
178 case IC_EVEX_L2_K:
179 case IC_EVEX_L2_B:
180 case IC_EVEX_L2_XS_K:
181 case IC_EVEX_L2_XD_K:
182 case IC_EVEX_L2_OPSIZE_K:
183 case IC_EVEX_L2_OPSIZE_B:
184 return false;
185 case IC_EVEX_L2_W_K:
186 case IC_EVEX_L2_W_XS_K:
187 case IC_EVEX_L2_W_XD_K:
188 case IC_EVEX_L2_W_OPSIZE_K:
189 case IC_EVEX_L2_W_OPSIZE_B:
190 return false;
Sean Callanan8ed9f512009-12-19 02:59:52 +0000191 default:
Craig Topper5ffedb92011-09-02 04:17:54 +0000192 llvm_unreachable("Unknown instruction class");
Sean Callanan8ed9f512009-12-19 02:59:52 +0000193 }
194}
195
196/// outranks - Indicates whether, if an instruction has two different applicable
197/// classes, which class should be preferred when performing decode. This
198/// imposes a total ordering (ties are resolved toward "lower")
199///
200/// @param upper - The class that may be preferable
201/// @param lower - The class that may be less preferable
202/// @return - True if upper is to be preferred, false otherwise.
Craig Topper98400092012-07-31 05:27:01 +0000203static inline bool outranks(InstructionContext upper,
Sean Callanan8ed9f512009-12-19 02:59:52 +0000204 InstructionContext lower) {
205 assert(upper < IC_max);
206 assert(lower < IC_max);
Craig Topper98400092012-07-31 05:27:01 +0000207
Sean Callanan8ed9f512009-12-19 02:59:52 +0000208#define ENUM_ENTRY(n, r, d) r,
Elena Demikhovskyc18f4ef2013-07-28 08:28:38 +0000209#define ENUM_ENTRY_K_B(n, r, d) ENUM_ENTRY(n, r, d) \
210 ENUM_ENTRY(n##_K_B, r, d) ENUM_ENTRY(n##_K, r, d) ENUM_ENTRY(n##_B, r, d)
Sean Callanan8ed9f512009-12-19 02:59:52 +0000211 static int ranks[IC_max] = {
212 INSTRUCTION_CONTEXTS
213 };
214#undef ENUM_ENTRY
Elena Demikhovskyc18f4ef2013-07-28 08:28:38 +0000215#undef ENUM_ENTRY_K_B
Craig Topper98400092012-07-31 05:27:01 +0000216
Sean Callanan8ed9f512009-12-19 02:59:52 +0000217 return (ranks[upper] > ranks[lower]);
218}
219
220/// stringForContext - Returns a string containing the name of a particular
221/// InstructionContext, usually for diagnostic purposes.
222///
223/// @param insnContext - The instruction class to transform to a string.
224/// @return - A statically-allocated string constant that contains the
225/// name of the instruction class.
226static inline const char* stringForContext(InstructionContext insnContext) {
227 switch (insnContext) {
228 default:
229 llvm_unreachable("Unhandled instruction class");
230#define ENUM_ENTRY(n, r, d) case n: return #n; break;
Elena Demikhovskyc18f4ef2013-07-28 08:28:38 +0000231#define ENUM_ENTRY_K_B(n, r, d) ENUM_ENTRY(n, r, d) ENUM_ENTRY(n##_K_B, r, d)\
232 ENUM_ENTRY(n##_K, r, d) ENUM_ENTRY(n##_B, r, d)
Sean Callanan8ed9f512009-12-19 02:59:52 +0000233 INSTRUCTION_CONTEXTS
234#undef ENUM_ENTRY
Elena Demikhovskyc18f4ef2013-07-28 08:28:38 +0000235#undef ENUM_ENTRY_K_B
Sean Callanan8ed9f512009-12-19 02:59:52 +0000236 }
237}
238
239/// stringForOperandType - Like stringForContext, but for OperandTypes.
240static inline const char* stringForOperandType(OperandType type) {
241 switch (type) {
242 default:
243 llvm_unreachable("Unhandled type");
244#define ENUM_ENTRY(i, d) case i: return #i;
245 TYPES
246#undef ENUM_ENTRY
247 }
248}
249
250/// stringForOperandEncoding - like stringForContext, but for
251/// OperandEncodings.
252static inline const char* stringForOperandEncoding(OperandEncoding encoding) {
253 switch (encoding) {
254 default:
255 llvm_unreachable("Unhandled encoding");
256#define ENUM_ENTRY(i, d) case i: return #i;
257 ENCODINGS
258#undef ENUM_ENTRY
259 }
260}
261
Craig Topperde9e3332012-07-31 06:02:05 +0000262void DisassemblerTables::emitOneID(raw_ostream &o, unsigned &i, InstrUID id,
Sean Callanan8ed9f512009-12-19 02:59:52 +0000263 bool addComma) const {
264 if (id)
265 o.indent(i * 2) << format("0x%hx", id);
266 else
267 o.indent(i * 2) << 0;
Craig Topper98400092012-07-31 05:27:01 +0000268
Sean Callanan8ed9f512009-12-19 02:59:52 +0000269 if (addComma)
270 o << ", ";
271 else
272 o << " ";
Craig Topper98400092012-07-31 05:27:01 +0000273
Sean Callanan8ed9f512009-12-19 02:59:52 +0000274 o << "/* ";
275 o << InstructionSpecifiers[id].name;
276 o << "*/";
Craig Topper98400092012-07-31 05:27:01 +0000277
Sean Callanan8ed9f512009-12-19 02:59:52 +0000278 o << "\n";
279}
280
281/// emitEmptyTable - Emits the modRMEmptyTable, which is used as a ID table by
282/// all ModR/M decisions for instructions that are invalid for all possible
283/// ModR/M byte values.
284///
285/// @param o - The output stream on which to emit the table.
286/// @param i - The indentation level for that output stream.
Craig Topperde9e3332012-07-31 06:02:05 +0000287static void emitEmptyTable(raw_ostream &o, unsigned &i) {
Craig Topperce8f4c52012-02-09 07:45:30 +0000288 o.indent(i * 2) << "0x0, /* EmptyTable */\n";
Sean Callanan8ed9f512009-12-19 02:59:52 +0000289}
290
291/// getDecisionType - Determines whether a ModRM decision with 255 entries can
292/// be compacted by eliminating redundant information.
293///
294/// @param decision - The decision to be compacted.
295/// @return - The compactest available representation for the decision.
Craig Toppere08789f2012-07-31 05:42:02 +0000296static ModRMDecisionType getDecisionType(ModRMDecision &decision) {
Sean Callanan8ed9f512009-12-19 02:59:52 +0000297 bool satisfiesOneEntry = true;
298 bool satisfiesSplitRM = true;
Craig Topperf41ab772012-02-09 08:58:07 +0000299 bool satisfiesSplitReg = true;
Craig Topper76b29b52012-09-13 05:45:42 +0000300 bool satisfiesSplitMisc = true;
Craig Topperf41ab772012-02-09 08:58:07 +0000301
Craig Topperde9e3332012-07-31 06:02:05 +0000302 for (unsigned index = 0; index < 256; ++index) {
Sean Callanan8ed9f512009-12-19 02:59:52 +0000303 if (decision.instructionIDs[index] != decision.instructionIDs[0])
304 satisfiesOneEntry = false;
Craig Topperf41ab772012-02-09 08:58:07 +0000305
Sean Callanan8ed9f512009-12-19 02:59:52 +0000306 if (((index & 0xc0) == 0xc0) &&
307 (decision.instructionIDs[index] != decision.instructionIDs[0xc0]))
308 satisfiesSplitRM = false;
Craig Topperf41ab772012-02-09 08:58:07 +0000309
Sean Callanan8ed9f512009-12-19 02:59:52 +0000310 if (((index & 0xc0) != 0xc0) &&
311 (decision.instructionIDs[index] != decision.instructionIDs[0x00]))
312 satisfiesSplitRM = false;
Craig Topperf41ab772012-02-09 08:58:07 +0000313
314 if (((index & 0xc0) == 0xc0) &&
315 (decision.instructionIDs[index] != decision.instructionIDs[index&0xf8]))
316 satisfiesSplitReg = false;
317
318 if (((index & 0xc0) != 0xc0) &&
319 (decision.instructionIDs[index] != decision.instructionIDs[index&0x38]))
Craig Topper76b29b52012-09-13 05:45:42 +0000320 satisfiesSplitMisc = false;
Sean Callanan8ed9f512009-12-19 02:59:52 +0000321 }
Craig Topperf41ab772012-02-09 08:58:07 +0000322
Sean Callanan8ed9f512009-12-19 02:59:52 +0000323 if (satisfiesOneEntry)
324 return MODRM_ONEENTRY;
Craig Topperf41ab772012-02-09 08:58:07 +0000325
Sean Callanan8ed9f512009-12-19 02:59:52 +0000326 if (satisfiesSplitRM)
327 return MODRM_SPLITRM;
Craig Topperf41ab772012-02-09 08:58:07 +0000328
Craig Topper76b29b52012-09-13 05:45:42 +0000329 if (satisfiesSplitReg && satisfiesSplitMisc)
Craig Topperf41ab772012-02-09 08:58:07 +0000330 return MODRM_SPLITREG;
331
Craig Topper76b29b52012-09-13 05:45:42 +0000332 if (satisfiesSplitMisc)
333 return MODRM_SPLITMISC;
334
Sean Callanan8ed9f512009-12-19 02:59:52 +0000335 return MODRM_FULL;
336}
337
338/// stringForDecisionType - Returns a statically-allocated string corresponding
339/// to a particular decision type.
340///
341/// @param dt - The decision type.
Craig Topper98400092012-07-31 05:27:01 +0000342/// @return - A pointer to the statically-allocated string (e.g.,
Sean Callanan8ed9f512009-12-19 02:59:52 +0000343/// "MODRM_ONEENTRY" for MODRM_ONEENTRY).
Craig Toppere08789f2012-07-31 05:42:02 +0000344static const char* stringForDecisionType(ModRMDecisionType dt) {
Sean Callanan8ed9f512009-12-19 02:59:52 +0000345#define ENUM_ENTRY(n) case n: return #n;
346 switch (dt) {
347 default:
Craig Topper98400092012-07-31 05:27:01 +0000348 llvm_unreachable("Unknown decision type");
Sean Callanan8ed9f512009-12-19 02:59:52 +0000349 MODRMTYPES
Craig Topper98400092012-07-31 05:27:01 +0000350 };
Sean Callanan8ed9f512009-12-19 02:59:52 +0000351#undef ENUM_ENTRY
352}
Craig Topper98400092012-07-31 05:27:01 +0000353
Sean Callanan8ed9f512009-12-19 02:59:52 +0000354/// stringForModifierType - Returns a statically-allocated string corresponding
355/// to an opcode modifier type.
356///
357/// @param mt - The modifier type.
358/// @return - A pointer to the statically-allocated string (e.g.,
359/// "MODIFIER_NONE" for MODIFIER_NONE).
Craig Toppere08789f2012-07-31 05:42:02 +0000360static const char* stringForModifierType(ModifierType mt) {
Sean Callanan8ed9f512009-12-19 02:59:52 +0000361#define ENUM_ENTRY(n) case n: return #n;
362 switch(mt) {
363 default:
364 llvm_unreachable("Unknown modifier type");
365 MODIFIER_TYPES
366 };
367#undef ENUM_ENTRY
368}
Craig Topper98400092012-07-31 05:27:01 +0000369
Sean Callanan8ed9f512009-12-19 02:59:52 +0000370DisassemblerTables::DisassemblerTables() {
371 unsigned i;
Craig Topper98400092012-07-31 05:27:01 +0000372
Joerg Sonnenberger39d7cae2011-04-04 16:25:38 +0000373 for (i = 0; i < array_lengthof(Tables); i++) {
Sean Callanan8ed9f512009-12-19 02:59:52 +0000374 Tables[i] = new ContextDecision;
Daniel Dunbar87830872009-12-19 04:16:57 +0000375 memset(Tables[i], 0, sizeof(ContextDecision));
Sean Callanan8ed9f512009-12-19 02:59:52 +0000376 }
Craig Topper98400092012-07-31 05:27:01 +0000377
Sean Callanan8ed9f512009-12-19 02:59:52 +0000378 HasConflicts = false;
379}
Craig Topper98400092012-07-31 05:27:01 +0000380
Sean Callanan8ed9f512009-12-19 02:59:52 +0000381DisassemblerTables::~DisassemblerTables() {
382 unsigned i;
Craig Topper98400092012-07-31 05:27:01 +0000383
Joerg Sonnenberger39d7cae2011-04-04 16:25:38 +0000384 for (i = 0; i < array_lengthof(Tables); i++)
Sean Callanan8ed9f512009-12-19 02:59:52 +0000385 delete Tables[i];
386}
Craig Topper98400092012-07-31 05:27:01 +0000387
Craig Toppere08789f2012-07-31 05:42:02 +0000388void DisassemblerTables::emitModRMDecision(raw_ostream &o1, raw_ostream &o2,
Craig Topperde9e3332012-07-31 06:02:05 +0000389 unsigned &i1, unsigned &i2,
Craig Toppere08789f2012-07-31 05:42:02 +0000390 ModRMDecision &decision) const {
Craig Topperde9e3332012-07-31 06:02:05 +0000391 static uint32_t sTableNumber = 0;
392 static uint32_t sEntryNumber = 1;
Sean Callanan8ed9f512009-12-19 02:59:52 +0000393 ModRMDecisionType dt = getDecisionType(decision);
Craig Topperce8f4c52012-02-09 07:45:30 +0000394
Sean Callanan8ed9f512009-12-19 02:59:52 +0000395 if (dt == MODRM_ONEENTRY && decision.instructionIDs[0] == 0)
396 {
397 o2.indent(i2) << "{ /* ModRMDecision */" << "\n";
398 i2++;
Craig Topperce8f4c52012-02-09 07:45:30 +0000399
Sean Callanan8ed9f512009-12-19 02:59:52 +0000400 o2.indent(i2) << stringForDecisionType(dt) << "," << "\n";
Craig Topperce8f4c52012-02-09 07:45:30 +0000401 o2.indent(i2) << 0 << " /* EmptyTable */\n";
402
Sean Callanan8ed9f512009-12-19 02:59:52 +0000403 i2--;
404 o2.indent(i2) << "}";
405 return;
406 }
Sean Callanan8ed9f512009-12-19 02:59:52 +0000407
Craig Topperce8f4c52012-02-09 07:45:30 +0000408 o1 << "/* Table" << sTableNumber << " */\n";
Sean Callanan8ed9f512009-12-19 02:59:52 +0000409 i1++;
Craig Topperce8f4c52012-02-09 07:45:30 +0000410
Sean Callanan8ed9f512009-12-19 02:59:52 +0000411 switch (dt) {
412 default:
413 llvm_unreachable("Unknown decision type");
414 case MODRM_ONEENTRY:
Craig Topperce8f4c52012-02-09 07:45:30 +0000415 emitOneID(o1, i1, decision.instructionIDs[0], true);
Sean Callanan8ed9f512009-12-19 02:59:52 +0000416 break;
417 case MODRM_SPLITRM:
418 emitOneID(o1, i1, decision.instructionIDs[0x00], true); // mod = 0b00
Craig Topperce8f4c52012-02-09 07:45:30 +0000419 emitOneID(o1, i1, decision.instructionIDs[0xc0], true); // mod = 0b11
Sean Callanan8ed9f512009-12-19 02:59:52 +0000420 break;
Craig Topperf41ab772012-02-09 08:58:07 +0000421 case MODRM_SPLITREG:
Craig Topperde9e3332012-07-31 06:02:05 +0000422 for (unsigned index = 0; index < 64; index += 8)
Craig Topperf41ab772012-02-09 08:58:07 +0000423 emitOneID(o1, i1, decision.instructionIDs[index], true);
Craig Topperde9e3332012-07-31 06:02:05 +0000424 for (unsigned index = 0xc0; index < 256; index += 8)
Craig Topperf41ab772012-02-09 08:58:07 +0000425 emitOneID(o1, i1, decision.instructionIDs[index], true);
426 break;
Craig Topper76b29b52012-09-13 05:45:42 +0000427 case MODRM_SPLITMISC:
428 for (unsigned index = 0; index < 64; index += 8)
429 emitOneID(o1, i1, decision.instructionIDs[index], true);
430 for (unsigned index = 0xc0; index < 256; ++index)
431 emitOneID(o1, i1, decision.instructionIDs[index], true);
432 break;
Sean Callanan8ed9f512009-12-19 02:59:52 +0000433 case MODRM_FULL:
Craig Topperde9e3332012-07-31 06:02:05 +0000434 for (unsigned index = 0; index < 256; ++index)
Craig Topperce8f4c52012-02-09 07:45:30 +0000435 emitOneID(o1, i1, decision.instructionIDs[index], true);
Sean Callanan8ed9f512009-12-19 02:59:52 +0000436 break;
437 }
Craig Topperce8f4c52012-02-09 07:45:30 +0000438
Sean Callanan8ed9f512009-12-19 02:59:52 +0000439 i1--;
Craig Topperce8f4c52012-02-09 07:45:30 +0000440
Sean Callanan8ed9f512009-12-19 02:59:52 +0000441 o2.indent(i2) << "{ /* struct ModRMDecision */" << "\n";
442 i2++;
Craig Topperce8f4c52012-02-09 07:45:30 +0000443
Sean Callanan8ed9f512009-12-19 02:59:52 +0000444 o2.indent(i2) << stringForDecisionType(dt) << "," << "\n";
Craig Topperce8f4c52012-02-09 07:45:30 +0000445 o2.indent(i2) << sEntryNumber << " /* Table" << sTableNumber << " */\n";
446
Sean Callanan8ed9f512009-12-19 02:59:52 +0000447 i2--;
448 o2.indent(i2) << "}";
Craig Topperce8f4c52012-02-09 07:45:30 +0000449
450 switch (dt) {
451 default:
452 llvm_unreachable("Unknown decision type");
453 case MODRM_ONEENTRY:
454 sEntryNumber += 1;
455 break;
456 case MODRM_SPLITRM:
457 sEntryNumber += 2;
458 break;
Craig Topperf41ab772012-02-09 08:58:07 +0000459 case MODRM_SPLITREG:
460 sEntryNumber += 16;
461 break;
Craig Topper76b29b52012-09-13 05:45:42 +0000462 case MODRM_SPLITMISC:
463 sEntryNumber += 8 + 64;
464 break;
Craig Topperce8f4c52012-02-09 07:45:30 +0000465 case MODRM_FULL:
466 sEntryNumber += 256;
467 break;
468 }
469
Craig Topper9e6dc8b2012-09-11 04:19:21 +0000470 // We assume that the index can fit into uint16_t.
471 assert(sEntryNumber < 65536U &&
472 "Index into ModRMDecision is too large for uint16_t!");
473
Sean Callanan8ed9f512009-12-19 02:59:52 +0000474 ++sTableNumber;
475}
476
Craig Toppere08789f2012-07-31 05:42:02 +0000477void DisassemblerTables::emitOpcodeDecision(raw_ostream &o1, raw_ostream &o2,
Craig Topperde9e3332012-07-31 06:02:05 +0000478 unsigned &i1, unsigned &i2,
Craig Toppere08789f2012-07-31 05:42:02 +0000479 OpcodeDecision &decision) const {
Sean Callanan8ed9f512009-12-19 02:59:52 +0000480 o2.indent(i2) << "{ /* struct OpcodeDecision */" << "\n";
481 i2++;
482 o2.indent(i2) << "{" << "\n";
483 i2++;
484
Craig Topperde9e3332012-07-31 06:02:05 +0000485 for (unsigned index = 0; index < 256; ++index) {
Sean Callanan8ed9f512009-12-19 02:59:52 +0000486 o2.indent(i2);
487
488 o2 << "/* 0x" << format("%02hhx", index) << " */" << "\n";
489
490 emitModRMDecision(o1, o2, i1, i2, decision.modRMDecisions[index]);
491
492 if (index < 255)
493 o2 << ",";
494
495 o2 << "\n";
496 }
497
498 i2--;
499 o2.indent(i2) << "}" << "\n";
500 i2--;
501 o2.indent(i2) << "}" << "\n";
502}
503
Craig Toppere08789f2012-07-31 05:42:02 +0000504void DisassemblerTables::emitContextDecision(raw_ostream &o1, raw_ostream &o2,
Craig Topperde9e3332012-07-31 06:02:05 +0000505 unsigned &i1, unsigned &i2,
Craig Toppere08789f2012-07-31 05:42:02 +0000506 ContextDecision &decision,
507 const char* name) const {
Benjamin Kramer4d1dca92010-10-23 09:10:44 +0000508 o2.indent(i2) << "static const struct ContextDecision " << name << " = {\n";
Sean Callanan8ed9f512009-12-19 02:59:52 +0000509 i2++;
510 o2.indent(i2) << "{ /* opcodeDecisions */" << "\n";
511 i2++;
512
Craig Topperde9e3332012-07-31 06:02:05 +0000513 for (unsigned index = 0; index < IC_max; ++index) {
Sean Callanan8ed9f512009-12-19 02:59:52 +0000514 o2.indent(i2) << "/* ";
515 o2 << stringForContext((InstructionContext)index);
516 o2 << " */";
517 o2 << "\n";
518
519 emitOpcodeDecision(o1, o2, i1, i2, decision.opcodeDecisions[index]);
520
521 if (index + 1 < IC_max)
522 o2 << ", ";
523 }
524
525 i2--;
526 o2.indent(i2) << "}" << "\n";
527 i2--;
528 o2.indent(i2) << "};" << "\n";
529}
530
Craig Topperde9e3332012-07-31 06:02:05 +0000531void DisassemblerTables::emitInstructionInfo(raw_ostream &o,
532 unsigned &i) const {
Craig Topper5a2c6072012-08-01 07:39:18 +0000533 unsigned NumInstructions = InstructionSpecifiers.size();
534
535 o << "static const struct OperandSpecifier x86OperandSets[]["
536 << X86_MAX_OPERANDS << "] = {\n";
537
538 typedef std::vector<std::pair<const char *, const char *> > OperandListTy;
539 std::map<OperandListTy, unsigned> OperandSets;
540
541 unsigned OperandSetNum = 0;
542 for (unsigned Index = 0; Index < NumInstructions; ++Index) {
543 OperandListTy OperandList;
544
545 for (unsigned OperandIndex = 0; OperandIndex < X86_MAX_OPERANDS;
546 ++OperandIndex) {
547 const char *Encoding =
548 stringForOperandEncoding((OperandEncoding)InstructionSpecifiers[Index]
549 .operands[OperandIndex].encoding);
550 const char *Type =
551 stringForOperandType((OperandType)InstructionSpecifiers[Index]
552 .operands[OperandIndex].type);
553 OperandList.push_back(std::make_pair(Encoding, Type));
554 }
555 unsigned &N = OperandSets[OperandList];
556 if (N != 0) continue;
557
558 N = ++OperandSetNum;
559
560 o << " { /* " << (OperandSetNum - 1) << " */\n";
561 for (unsigned i = 0, e = OperandList.size(); i != e; ++i) {
562 o << " { " << OperandList[i].first << ", "
563 << OperandList[i].second << " },\n";
564 }
565 o << " },\n";
566 }
567 o << "};" << "\n\n";
568
Benjamin Kramer4d1dca92010-10-23 09:10:44 +0000569 o.indent(i * 2) << "static const struct InstructionSpecifier ";
570 o << INSTRUCTIONS_STR "[" << InstructionSpecifiers.size() << "] = {\n";
Craig Topper98400092012-07-31 05:27:01 +0000571
Sean Callanan8ed9f512009-12-19 02:59:52 +0000572 i++;
573
Craig Topper5a2c6072012-08-01 07:39:18 +0000574 for (unsigned index = 0; index < NumInstructions; ++index) {
Sean Callanan8ed9f512009-12-19 02:59:52 +0000575 o.indent(i * 2) << "{ /* " << index << " */" << "\n";
576 i++;
Craig Topper991271d2012-03-04 02:16:41 +0000577
578 o.indent(i * 2) << stringForModifierType(
579 (ModifierType)InstructionSpecifiers[index].modifierType);
Craig Topper5a2c6072012-08-01 07:39:18 +0000580 o << ",\n";
Craig Topper991271d2012-03-04 02:16:41 +0000581
Sean Callanan8ed9f512009-12-19 02:59:52 +0000582 o.indent(i * 2) << "0x";
583 o << format("%02hhx", (uint16_t)InstructionSpecifiers[index].modifierBase);
Craig Topper5a2c6072012-08-01 07:39:18 +0000584 o << ",\n";
Sean Callanan8ed9f512009-12-19 02:59:52 +0000585
Craig Topper5a2c6072012-08-01 07:39:18 +0000586 OperandListTy OperandList;
587 for (unsigned OperandIndex = 0; OperandIndex < X86_MAX_OPERANDS;
588 ++OperandIndex) {
589 const char *Encoding =
590 stringForOperandEncoding((OperandEncoding)InstructionSpecifiers[index]
591 .operands[OperandIndex].encoding);
592 const char *Type =
593 stringForOperandType((OperandType)InstructionSpecifiers[index]
594 .operands[OperandIndex].type);
595 OperandList.push_back(std::make_pair(Encoding, Type));
Sean Callanan8ed9f512009-12-19 02:59:52 +0000596 }
Craig Topper5a2c6072012-08-01 07:39:18 +0000597 o.indent(i * 2) << (OperandSets[OperandList] - 1) << ",\n";
Craig Topper98400092012-07-31 05:27:01 +0000598
Benjamin Kramer953362c2012-02-11 14:50:54 +0000599 o.indent(i * 2) << "/* " << InstructionSpecifiers[index].name << " */";
Sean Callanan8ed9f512009-12-19 02:59:52 +0000600 o << "\n";
601
602 i--;
603 o.indent(i * 2) << "}";
604
Craig Topper5a2c6072012-08-01 07:39:18 +0000605 if (index + 1 < NumInstructions)
Sean Callanan8ed9f512009-12-19 02:59:52 +0000606 o << ",";
607
608 o << "\n";
609 }
610
611 i--;
612 o.indent(i * 2) << "};" << "\n";
613}
614
Craig Topperde9e3332012-07-31 06:02:05 +0000615void DisassemblerTables::emitContextTable(raw_ostream &o, unsigned &i) const {
Craig Topper19dbe2f2012-07-31 06:15:39 +0000616 o.indent(i * 2) << "static const uint8_t " CONTEXTS_STR
Benjamin Kramer86c69c52010-10-23 09:28:42 +0000617 "[256] = {\n";
Sean Callanan8ed9f512009-12-19 02:59:52 +0000618 i++;
619
Craig Topperde9e3332012-07-31 06:02:05 +0000620 for (unsigned index = 0; index < 256; ++index) {
Sean Callanan8ed9f512009-12-19 02:59:52 +0000621 o.indent(i * 2);
622
Craig Topperc8eb8802011-11-06 23:04:08 +0000623 if ((index & ATTR_VEXL) && (index & ATTR_REXW) && (index & ATTR_OPSIZE))
624 o << "IC_VEX_L_W_OPSIZE";
625 else if ((index & ATTR_VEXL) && (index & ATTR_OPSIZE))
Sean Callanana21e2ea2011-03-15 01:23:15 +0000626 o << "IC_VEX_L_OPSIZE";
627 else if ((index & ATTR_VEXL) && (index & ATTR_XD))
628 o << "IC_VEX_L_XD";
629 else if ((index & ATTR_VEXL) && (index & ATTR_XS))
630 o << "IC_VEX_L_XS";
631 else if ((index & ATTR_VEX) && (index & ATTR_REXW) && (index & ATTR_OPSIZE))
632 o << "IC_VEX_W_OPSIZE";
633 else if ((index & ATTR_VEX) && (index & ATTR_REXW) && (index & ATTR_XD))
634 o << "IC_VEX_W_XD";
635 else if ((index & ATTR_VEX) && (index & ATTR_REXW) && (index & ATTR_XS))
636 o << "IC_VEX_W_XS";
637 else if (index & ATTR_VEXL)
638 o << "IC_VEX_L";
639 else if ((index & ATTR_VEX) && (index & ATTR_REXW))
640 o << "IC_VEX_W";
641 else if ((index & ATTR_VEX) && (index & ATTR_OPSIZE))
642 o << "IC_VEX_OPSIZE";
643 else if ((index & ATTR_VEX) && (index & ATTR_XD))
644 o << "IC_VEX_XD";
645 else if ((index & ATTR_VEX) && (index & ATTR_XS))
646 o << "IC_VEX_XS";
Craig Topper113061d2011-08-25 07:42:00 +0000647 else if (index & ATTR_VEX)
648 o << "IC_VEX";
Sean Callanana21e2ea2011-03-15 01:23:15 +0000649 else if ((index & ATTR_64BIT) && (index & ATTR_REXW) && (index & ATTR_XS))
Sean Callanan8ed9f512009-12-19 02:59:52 +0000650 o << "IC_64BIT_REXW_XS";
651 else if ((index & ATTR_64BIT) && (index & ATTR_REXW) && (index & ATTR_XD))
652 o << "IC_64BIT_REXW_XD";
Craig Topper98400092012-07-31 05:27:01 +0000653 else if ((index & ATTR_64BIT) && (index & ATTR_REXW) &&
Sean Callanan8ed9f512009-12-19 02:59:52 +0000654 (index & ATTR_OPSIZE))
655 o << "IC_64BIT_REXW_OPSIZE";
Craig Toppere1b4a1a2011-10-01 19:54:56 +0000656 else if ((index & ATTR_64BIT) && (index & ATTR_XD) && (index & ATTR_OPSIZE))
657 o << "IC_64BIT_XD_OPSIZE";
Craig Topper29480fd2011-10-11 04:34:23 +0000658 else if ((index & ATTR_64BIT) && (index & ATTR_XS) && (index & ATTR_OPSIZE))
659 o << "IC_64BIT_XS_OPSIZE";
Sean Callanan8ed9f512009-12-19 02:59:52 +0000660 else if ((index & ATTR_64BIT) && (index & ATTR_XS))
661 o << "IC_64BIT_XS";
662 else if ((index & ATTR_64BIT) && (index & ATTR_XD))
663 o << "IC_64BIT_XD";
664 else if ((index & ATTR_64BIT) && (index & ATTR_OPSIZE))
665 o << "IC_64BIT_OPSIZE";
Craig Topper930a1eb2012-02-27 01:54:29 +0000666 else if ((index & ATTR_64BIT) && (index & ATTR_ADSIZE))
667 o << "IC_64BIT_ADSIZE";
Sean Callanan8ed9f512009-12-19 02:59:52 +0000668 else if ((index & ATTR_64BIT) && (index & ATTR_REXW))
669 o << "IC_64BIT_REXW";
670 else if ((index & ATTR_64BIT))
671 o << "IC_64BIT";
Craig Topper29480fd2011-10-11 04:34:23 +0000672 else if ((index & ATTR_XS) && (index & ATTR_OPSIZE))
673 o << "IC_XS_OPSIZE";
Craig Toppere1b4a1a2011-10-01 19:54:56 +0000674 else if ((index & ATTR_XD) && (index & ATTR_OPSIZE))
675 o << "IC_XD_OPSIZE";
Sean Callanan8ed9f512009-12-19 02:59:52 +0000676 else if (index & ATTR_XS)
677 o << "IC_XS";
678 else if (index & ATTR_XD)
679 o << "IC_XD";
680 else if (index & ATTR_OPSIZE)
681 o << "IC_OPSIZE";
Craig Topper930a1eb2012-02-27 01:54:29 +0000682 else if (index & ATTR_ADSIZE)
683 o << "IC_ADSIZE";
Sean Callanan8ed9f512009-12-19 02:59:52 +0000684 else
685 o << "IC";
686
687 if (index < 255)
688 o << ",";
689 else
690 o << " ";
691
692 o << " /* " << index << " */";
693
694 o << "\n";
695 }
696
697 i--;
698 o.indent(i * 2) << "};" << "\n";
699}
700
Craig Toppere08789f2012-07-31 05:42:02 +0000701void DisassemblerTables::emitContextDecisions(raw_ostream &o1, raw_ostream &o2,
Craig Topperde9e3332012-07-31 06:02:05 +0000702 unsigned &i1, unsigned &i2) const {
Sean Callanan8ed9f512009-12-19 02:59:52 +0000703 emitContextDecision(o1, o2, i1, i2, *Tables[0], ONEBYTE_STR);
704 emitContextDecision(o1, o2, i1, i2, *Tables[1], TWOBYTE_STR);
705 emitContextDecision(o1, o2, i1, i2, *Tables[2], THREEBYTE38_STR);
706 emitContextDecision(o1, o2, i1, i2, *Tables[3], THREEBYTE3A_STR);
Joerg Sonnenberger4a8ac8d2011-04-04 16:58:13 +0000707 emitContextDecision(o1, o2, i1, i2, *Tables[4], THREEBYTEA6_STR);
708 emitContextDecision(o1, o2, i1, i2, *Tables[5], THREEBYTEA7_STR);
Sean Callanan8ed9f512009-12-19 02:59:52 +0000709}
710
711void DisassemblerTables::emit(raw_ostream &o) const {
Craig Topperde9e3332012-07-31 06:02:05 +0000712 unsigned i1 = 0;
713 unsigned i2 = 0;
Craig Topper98400092012-07-31 05:27:01 +0000714
Sean Callanan8ed9f512009-12-19 02:59:52 +0000715 std::string s1;
716 std::string s2;
Craig Topper98400092012-07-31 05:27:01 +0000717
Sean Callanan8ed9f512009-12-19 02:59:52 +0000718 raw_string_ostream o1(s1);
719 raw_string_ostream o2(s2);
Craig Topper98400092012-07-31 05:27:01 +0000720
Sean Callanan8ed9f512009-12-19 02:59:52 +0000721 emitInstructionInfo(o, i2);
722 o << "\n";
723
724 emitContextTable(o, i2);
725 o << "\n";
Craig Topperce8f4c52012-02-09 07:45:30 +0000726
727 o << "static const InstrUID modRMTable[] = {\n";
728 i1++;
Sean Callanan8ed9f512009-12-19 02:59:52 +0000729 emitEmptyTable(o1, i1);
Craig Topperce8f4c52012-02-09 07:45:30 +0000730 i1--;
Sean Callanan8ed9f512009-12-19 02:59:52 +0000731 emitContextDecisions(o1, o2, i1, i2);
Craig Topperce8f4c52012-02-09 07:45:30 +0000732
Sean Callanan8ed9f512009-12-19 02:59:52 +0000733 o << o1.str();
Craig Topperce8f4c52012-02-09 07:45:30 +0000734 o << " 0x0\n";
735 o << "};\n";
Sean Callanan8ed9f512009-12-19 02:59:52 +0000736 o << "\n";
737 o << o2.str();
738 o << "\n";
739 o << "\n";
740}
741
742void DisassemblerTables::setTableFields(ModRMDecision &decision,
743 const ModRMFilter &filter,
744 InstrUID uid,
745 uint8_t opcode) {
Craig Topperde9e3332012-07-31 06:02:05 +0000746 for (unsigned index = 0; index < 256; ++index) {
Sean Callanan8ed9f512009-12-19 02:59:52 +0000747 if (filter.accepts(index)) {
748 if (decision.instructionIDs[index] == uid)
749 continue;
750
751 if (decision.instructionIDs[index] != 0) {
752 InstructionSpecifier &newInfo =
753 InstructionSpecifiers[uid];
754 InstructionSpecifier &previousInfo =
755 InstructionSpecifiers[decision.instructionIDs[index]];
Craig Topper98400092012-07-31 05:27:01 +0000756
Sean Callanan8ed9f512009-12-19 02:59:52 +0000757 if(newInfo.filtered)
758 continue; // filtered instructions get lowest priority
Craig Topper98400092012-07-31 05:27:01 +0000759
Craig Topper842f58f2011-09-11 20:23:20 +0000760 if(previousInfo.name == "NOOP" && (newInfo.name == "XCHG16ar" ||
761 newInfo.name == "XCHG32ar" ||
Craig Topper25f6dfd2011-10-07 05:35:38 +0000762 newInfo.name == "XCHG32ar64" ||
Craig Topper842f58f2011-09-11 20:23:20 +0000763 newInfo.name == "XCHG64ar"))
764 continue; // special case for XCHG*ar and NOOP
Sean Callanan8ed9f512009-12-19 02:59:52 +0000765
766 if (outranks(previousInfo.insnContext, newInfo.insnContext))
767 continue;
Craig Topper98400092012-07-31 05:27:01 +0000768
Sean Callanan8ed9f512009-12-19 02:59:52 +0000769 if (previousInfo.insnContext == newInfo.insnContext &&
770 !previousInfo.filtered) {
771 errs() << "Error: Primary decode conflict: ";
772 errs() << newInfo.name << " would overwrite " << previousInfo.name;
773 errs() << "\n";
774 errs() << "ModRM " << index << "\n";
775 errs() << "Opcode " << (uint16_t)opcode << "\n";
776 errs() << "Context " << stringForContext(newInfo.insnContext) << "\n";
777 HasConflicts = true;
778 }
779 }
780
781 decision.instructionIDs[index] = uid;
782 }
783 }
784}
785
786void DisassemblerTables::setTableFields(OpcodeType type,
787 InstructionContext insnContext,
788 uint8_t opcode,
789 const ModRMFilter &filter,
Craig Topper4da632e2011-09-23 06:57:25 +0000790 InstrUID uid,
Craig Topper6744a172011-10-04 06:30:42 +0000791 bool is32bit,
792 bool ignoresVEX_L) {
Sean Callanan8ed9f512009-12-19 02:59:52 +0000793 ContextDecision &decision = *Tables[type];
794
Craig Topperde9e3332012-07-31 06:02:05 +0000795 for (unsigned index = 0; index < IC_max; ++index) {
Craig Topper4da632e2011-09-23 06:57:25 +0000796 if (is32bit && inheritsFrom((InstructionContext)index, IC_64BIT))
797 continue;
798
Craig Topper98400092012-07-31 05:27:01 +0000799 if (inheritsFrom((InstructionContext)index,
Craig Topper6744a172011-10-04 06:30:42 +0000800 InstructionSpecifiers[uid].insnContext, ignoresVEX_L))
Craig Topper98400092012-07-31 05:27:01 +0000801 setTableFields(decision.opcodeDecisions[index].modRMDecisions[opcode],
Sean Callanan8ed9f512009-12-19 02:59:52 +0000802 filter,
803 uid,
804 opcode);
805 }
806}