Skip to content

Commit 61b62e5

Browse files
committed
[X86] Space out the encodings of X86 instruction formats. I plan to add some new encodings in future commits and this will reduce the size of those commits. NFC
This tries to keep all the ModRM memory and register forms in their own regions of the encodings. Hoping to make it simple on some of the switch statements that operate on these encodings. llvm-svn: 279422
1 parent 1867c6a commit 61b62e5

File tree

3 files changed

+187
-175
lines changed

3 files changed

+187
-175
lines changed

llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h

Lines changed: 61 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -234,88 +234,94 @@ namespace X86II {
234234
/// their one register operand added to their opcode.
235235
AddRegFrm = 2,
236236

237-
/// MRMDestReg - This form is used for instructions that use the Mod/RM byte
238-
/// to specify a destination, which in this case is a register.
239-
///
240-
MRMDestReg = 3,
241-
242-
/// MRMDestMem - This form is used for instructions that use the Mod/RM byte
243-
/// to specify a destination, which in this case is memory.
244-
///
245-
MRMDestMem = 4,
246-
247-
/// MRMSrcReg - This form is used for instructions that use the Mod/RM byte
248-
/// to specify a source, which in this case is a register.
249-
///
250-
MRMSrcReg = 5,
251-
252-
/// MRMSrcMem - This form is used for instructions that use the Mod/RM byte
253-
/// to specify a source, which in this case is memory.
254-
///
255-
MRMSrcMem = 6,
256-
257237
/// RawFrmMemOffs - This form is for instructions that store an absolute
258238
/// memory offset as an immediate with a possible segment override.
259-
RawFrmMemOffs = 7,
239+
RawFrmMemOffs = 3,
260240

261241
/// RawFrmSrc - This form is for instructions that use the source index
262242
/// register SI/ESI/RSI with a possible segment override.
263-
RawFrmSrc = 8,
243+
RawFrmSrc = 4,
264244

265245
/// RawFrmDst - This form is for instructions that use the destination index
266246
/// register DI/EDI/ESI.
267-
RawFrmDst = 9,
247+
RawFrmDst = 5,
268248

269249
/// RawFrmSrc - This form is for instructions that use the source index
270250
/// register SI/ESI/ERI with a possible segment override, and also the
271251
/// destination index register DI/ESI/RDI.
272-
RawFrmDstSrc = 10,
252+
RawFrmDstSrc = 6,
273253

274254
/// RawFrmImm8 - This is used for the ENTER instruction, which has two
275255
/// immediates, the first of which is a 16-bit immediate (specified by
276256
/// the imm encoding) and the second is a 8-bit fixed value.
277-
RawFrmImm8 = 11,
257+
RawFrmImm8 = 7,
278258

279259
/// RawFrmImm16 - This is used for CALL FAR instructions, which have two
280260
/// immediates, the first of which is a 16 or 32-bit immediate (specified by
281261
/// the imm encoding) and the second is a 16-bit fixed value. In the AMD
282262
/// manual, this operand is described as pntr16:32 and pntr16:16
283-
RawFrmImm16 = 12,
284-
285-
/// MRMX[rm] - The forms are used to represent instructions that use a
286-
/// Mod/RM byte, and don't use the middle field for anything.
287-
MRMXr = 14, MRMXm = 15,
263+
RawFrmImm16 = 8,
288264

289265
/// MRM[0-7][rm] - These forms are used to represent instructions that use
290266
/// a Mod/RM byte, and use the middle field to hold extended opcode
291267
/// information. In the intel manual these are represented as /0, /1, ...
292268
///
293269

294-
// First, instructions that operate on a register r/m operand...
295-
MRM0r = 16, MRM1r = 17, MRM2r = 18, MRM3r = 19, // Format /0 /1 /2 /3
296-
MRM4r = 20, MRM5r = 21, MRM6r = 22, MRM7r = 23, // Format /4 /5 /6 /7
270+
/// MRMDestMem - This form is used for instructions that use the Mod/RM byte
271+
/// to specify a destination, which in this case is memory.
272+
///
273+
MRMDestMem = 32,
274+
275+
/// MRMSrcMem - This form is used for instructions that use the Mod/RM byte
276+
/// to specify a source, which in this case is memory.
277+
///
278+
MRMSrcMem = 33,
279+
280+
/// MRMXm - This form is used for instructions that use the Mod/RM byte
281+
/// to specify a memory source, but doesn't use the middle field.
282+
///
283+
MRMXm = 39, // Instruction that uses Mod/RM but not the middle field.
297284

298285
// Next, instructions that operate on a memory r/m operand...
299-
MRM0m = 24, MRM1m = 25, MRM2m = 26, MRM3m = 27, // Format /0 /1 /2 /3
300-
MRM4m = 28, MRM5m = 29, MRM6m = 30, MRM7m = 31, // Format /4 /5 /6 /7
301-
302-
//// MRM_XX - A mod/rm byte of exactly 0xXX.
303-
MRM_C0 = 32, MRM_C1 = 33, MRM_C2 = 34, MRM_C3 = 35,
304-
MRM_C4 = 36, MRM_C5 = 37, MRM_C6 = 38, MRM_C7 = 39,
305-
MRM_C8 = 40, MRM_C9 = 41, MRM_CA = 42, MRM_CB = 43,
306-
MRM_CC = 44, MRM_CD = 45, MRM_CE = 46, MRM_CF = 47,
307-
MRM_D0 = 48, MRM_D1 = 49, MRM_D2 = 50, MRM_D3 = 51,
308-
MRM_D4 = 52, MRM_D5 = 53, MRM_D6 = 54, MRM_D7 = 55,
309-
MRM_D8 = 56, MRM_D9 = 57, MRM_DA = 58, MRM_DB = 59,
310-
MRM_DC = 60, MRM_DD = 61, MRM_DE = 62, MRM_DF = 63,
311-
MRM_E0 = 64, MRM_E1 = 65, MRM_E2 = 66, MRM_E3 = 67,
312-
MRM_E4 = 68, MRM_E5 = 69, MRM_E6 = 70, MRM_E7 = 71,
313-
MRM_E8 = 72, MRM_E9 = 73, MRM_EA = 74, MRM_EB = 75,
314-
MRM_EC = 76, MRM_ED = 77, MRM_EE = 78, MRM_EF = 79,
315-
MRM_F0 = 80, MRM_F1 = 81, MRM_F2 = 82, MRM_F3 = 83,
316-
MRM_F4 = 84, MRM_F5 = 85, MRM_F6 = 86, MRM_F7 = 87,
317-
MRM_F8 = 88, MRM_F9 = 89, MRM_FA = 90, MRM_FB = 91,
318-
MRM_FC = 92, MRM_FD = 93, MRM_FE = 94, MRM_FF = 95,
286+
MRM0m = 40, MRM1m = 41, MRM2m = 42, MRM3m = 43, // Format /0 /1 /2 /3
287+
MRM4m = 44, MRM5m = 45, MRM6m = 46, MRM7m = 47, // Format /4 /5 /6 /7
288+
289+
/// MRMDestReg - This form is used for instructions that use the Mod/RM byte
290+
/// to specify a destination, which in this case is a register.
291+
///
292+
MRMDestReg = 48,
293+
294+
/// MRMSrcReg - This form is used for instructions that use the Mod/RM byte
295+
/// to specify a source, which in this case is a register.
296+
///
297+
MRMSrcReg = 49,
298+
299+
/// MRMXr - This form is used for instructions that use the Mod/RM byte
300+
/// to specify a register source, but doesn't use the middle field.
301+
///
302+
MRMXr = 55, // Instruction that uses Mod/RM but not the middle field.
303+
304+
// Instructions that operate on a register r/m operand...
305+
MRM0r = 56, MRM1r = 57, MRM2r = 58, MRM3r = 59, // Format /0 /1 /2 /3
306+
MRM4r = 60, MRM5r = 61, MRM6r = 62, MRM7r = 63, // Format /4 /5 /6 /7
307+
308+
/// MRM_XX - A mod/rm byte of exactly 0xXX.
309+
MRM_C0 = 64, MRM_C1 = 65, MRM_C2 = 66, MRM_C3 = 67,
310+
MRM_C4 = 68, MRM_C5 = 69, MRM_C6 = 70, MRM_C7 = 71,
311+
MRM_C8 = 72, MRM_C9 = 73, MRM_CA = 74, MRM_CB = 75,
312+
MRM_CC = 76, MRM_CD = 77, MRM_CE = 78, MRM_CF = 79,
313+
MRM_D0 = 80, MRM_D1 = 81, MRM_D2 = 82, MRM_D3 = 83,
314+
MRM_D4 = 84, MRM_D5 = 85, MRM_D6 = 86, MRM_D7 = 87,
315+
MRM_D8 = 88, MRM_D9 = 89, MRM_DA = 90, MRM_DB = 91,
316+
MRM_DC = 92, MRM_DD = 93, MRM_DE = 94, MRM_DF = 95,
317+
MRM_E0 = 96, MRM_E1 = 97, MRM_E2 = 98, MRM_E3 = 99,
318+
MRM_E4 = 100, MRM_E5 = 101, MRM_E6 = 102, MRM_E7 = 103,
319+
MRM_E8 = 104, MRM_E9 = 105, MRM_EA = 106, MRM_EB = 107,
320+
MRM_EC = 108, MRM_ED = 109, MRM_EE = 110, MRM_EF = 111,
321+
MRM_F0 = 112, MRM_F1 = 113, MRM_F2 = 114, MRM_F3 = 115,
322+
MRM_F4 = 116, MRM_F5 = 117, MRM_F6 = 118, MRM_F7 = 119,
323+
MRM_F8 = 120, MRM_F9 = 121, MRM_FA = 122, MRM_FB = 123,
324+
MRM_FC = 124, MRM_FD = 125, MRM_FE = 126, MRM_FF = 127,
319325

320326
FormMask = 127,
321327

@@ -651,8 +657,6 @@ namespace X86II {
651657
case X86II::Pseudo:
652658
case X86II::RawFrm:
653659
case X86II::AddRegFrm:
654-
case X86II::MRMDestReg:
655-
case X86II::MRMSrcReg:
656660
case X86II::RawFrmImm8:
657661
case X86II::RawFrmImm16:
658662
case X86II::RawFrmMemOffs:
@@ -666,6 +670,8 @@ namespace X86II {
666670
// Start from 1, skip any registers encoded in VEX_VVVV or I8IMM, or a
667671
// mask register.
668672
return 1 + HasVEX_4V + HasMemOp4 + HasEVEX_K;
673+
case X86II::MRMDestReg:
674+
case X86II::MRMSrcReg:
669675
case X86II::MRMXr:
670676
case X86II::MRM0r: case X86II::MRM1r:
671677
case X86II::MRM2r: case X86II::MRM3r:

llvm/lib/Target/X86/X86InstrFormats.td

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -18,43 +18,49 @@ class Format<bits<7> val> {
1818
bits<7> Value = val;
1919
}
2020

21-
def Pseudo : Format<0>; def RawFrm : Format<1>;
22-
def AddRegFrm : Format<2>; def MRMDestReg : Format<3>;
23-
def MRMDestMem : Format<4>; def MRMSrcReg : Format<5>;
24-
def MRMSrcMem : Format<6>; def RawFrmMemOffs : Format<7>;
25-
def RawFrmSrc : Format<8>; def RawFrmDst : Format<9>;
26-
def RawFrmDstSrc: Format<10>;
27-
def RawFrmImm8 : Format<11>;
28-
def RawFrmImm16 : Format<12>;
29-
def MRMXr : Format<14>; def MRMXm : Format<15>;
30-
def MRM0r : Format<16>; def MRM1r : Format<17>; def MRM2r : Format<18>;
31-
def MRM3r : Format<19>; def MRM4r : Format<20>; def MRM5r : Format<21>;
32-
def MRM6r : Format<22>; def MRM7r : Format<23>;
33-
def MRM0m : Format<24>; def MRM1m : Format<25>; def MRM2m : Format<26>;
34-
def MRM3m : Format<27>; def MRM4m : Format<28>; def MRM5m : Format<29>;
35-
def MRM6m : Format<30>; def MRM7m : Format<31>;
36-
def MRM_C0 : Format<32>; def MRM_C1 : Format<33>; def MRM_C2 : Format<34>;
37-
def MRM_C3 : Format<35>; def MRM_C4 : Format<36>; def MRM_C5 : Format<37>;
38-
def MRM_C6 : Format<38>; def MRM_C7 : Format<39>; def MRM_C8 : Format<40>;
39-
def MRM_C9 : Format<41>; def MRM_CA : Format<42>; def MRM_CB : Format<43>;
40-
def MRM_CC : Format<44>; def MRM_CD : Format<45>; def MRM_CE : Format<46>;
41-
def MRM_CF : Format<47>; def MRM_D0 : Format<48>; def MRM_D1 : Format<49>;
42-
def MRM_D2 : Format<50>; def MRM_D3 : Format<51>; def MRM_D4 : Format<52>;
43-
def MRM_D5 : Format<53>; def MRM_D6 : Format<54>; def MRM_D7 : Format<55>;
44-
def MRM_D8 : Format<56>; def MRM_D9 : Format<57>; def MRM_DA : Format<58>;
45-
def MRM_DB : Format<59>; def MRM_DC : Format<60>; def MRM_DD : Format<61>;
46-
def MRM_DE : Format<62>; def MRM_DF : Format<63>; def MRM_E0 : Format<64>;
47-
def MRM_E1 : Format<65>; def MRM_E2 : Format<66>; def MRM_E3 : Format<67>;
48-
def MRM_E4 : Format<68>; def MRM_E5 : Format<69>; def MRM_E6 : Format<70>;
49-
def MRM_E7 : Format<71>; def MRM_E8 : Format<72>; def MRM_E9 : Format<73>;
50-
def MRM_EA : Format<74>; def MRM_EB : Format<75>; def MRM_EC : Format<76>;
51-
def MRM_ED : Format<77>; def MRM_EE : Format<78>; def MRM_EF : Format<79>;
52-
def MRM_F0 : Format<80>; def MRM_F1 : Format<81>; def MRM_F2 : Format<82>;
53-
def MRM_F3 : Format<83>; def MRM_F4 : Format<84>; def MRM_F5 : Format<85>;
54-
def MRM_F6 : Format<86>; def MRM_F7 : Format<87>; def MRM_F8 : Format<88>;
55-
def MRM_F9 : Format<89>; def MRM_FA : Format<90>; def MRM_FB : Format<91>;
56-
def MRM_FC : Format<92>; def MRM_FD : Format<93>; def MRM_FE : Format<94>;
57-
def MRM_FF : Format<95>;
21+
def Pseudo : Format<0>;
22+
def RawFrm : Format<1>;
23+
def AddRegFrm : Format<2>;
24+
def RawFrmMemOffs : Format<3>;
25+
def RawFrmSrc : Format<4>;
26+
def RawFrmDst : Format<5>;
27+
def RawFrmDstSrc : Format<6>;
28+
def RawFrmImm8 : Format<7>;
29+
def RawFrmImm16 : Format<8>;
30+
def MRMDestMem : Format<32>;
31+
def MRMSrcMem : Format<33>;
32+
def MRMXm : Format<39>;
33+
def MRM0m : Format<40>; def MRM1m : Format<41>; def MRM2m : Format<42>;
34+
def MRM3m : Format<43>; def MRM4m : Format<44>; def MRM5m : Format<45>;
35+
def MRM6m : Format<46>; def MRM7m : Format<47>;
36+
def MRMDestReg : Format<48>;
37+
def MRMSrcReg : Format<49>;
38+
def MRMXr : Format<55>;
39+
def MRM0r : Format<56>; def MRM1r : Format<57>; def MRM2r : Format<58>;
40+
def MRM3r : Format<59>; def MRM4r : Format<60>; def MRM5r : Format<61>;
41+
def MRM6r : Format<62>; def MRM7r : Format<63>;
42+
def MRM_C0 : Format<64>; def MRM_C1 : Format<65>; def MRM_C2 : Format<66>;
43+
def MRM_C3 : Format<67>; def MRM_C4 : Format<68>; def MRM_C5 : Format<69>;
44+
def MRM_C6 : Format<70>; def MRM_C7 : Format<71>; def MRM_C8 : Format<72>;
45+
def MRM_C9 : Format<73>; def MRM_CA : Format<74>; def MRM_CB : Format<75>;
46+
def MRM_CC : Format<76>; def MRM_CD : Format<77>; def MRM_CE : Format<78>;
47+
def MRM_CF : Format<79>; def MRM_D0 : Format<80>; def MRM_D1 : Format<81>;
48+
def MRM_D2 : Format<82>; def MRM_D3 : Format<83>; def MRM_D4 : Format<84>;
49+
def MRM_D5 : Format<85>; def MRM_D6 : Format<86>; def MRM_D7 : Format<87>;
50+
def MRM_D8 : Format<88>; def MRM_D9 : Format<89>; def MRM_DA : Format<90>;
51+
def MRM_DB : Format<91>; def MRM_DC : Format<92>; def MRM_DD : Format<93>;
52+
def MRM_DE : Format<94>; def MRM_DF : Format<95>; def MRM_E0 : Format<96>;
53+
def MRM_E1 : Format<97>; def MRM_E2 : Format<98>; def MRM_E3 : Format<99>;
54+
def MRM_E4 : Format<100>; def MRM_E5 : Format<101>; def MRM_E6 : Format<102>;
55+
def MRM_E7 : Format<103>; def MRM_E8 : Format<104>; def MRM_E9 : Format<105>;
56+
def MRM_EA : Format<106>; def MRM_EB : Format<107>; def MRM_EC : Format<108>;
57+
def MRM_ED : Format<109>; def MRM_EE : Format<110>; def MRM_EF : Format<111>;
58+
def MRM_F0 : Format<112>; def MRM_F1 : Format<113>; def MRM_F2 : Format<114>;
59+
def MRM_F3 : Format<115>; def MRM_F4 : Format<116>; def MRM_F5 : Format<117>;
60+
def MRM_F6 : Format<118>; def MRM_F7 : Format<119>; def MRM_F8 : Format<120>;
61+
def MRM_F9 : Format<121>; def MRM_FA : Format<122>; def MRM_FB : Format<123>;
62+
def MRM_FC : Format<124>; def MRM_FD : Format<125>; def MRM_FE : Format<126>;
63+
def MRM_FF : Format<127>;
5864

5965
// ImmType - This specifies the immediate type used by an instruction. This is
6066
// part of the ad-hoc solution used to emit machine instruction encodings by our

0 commit comments

Comments
 (0)