1//===-- M68kInstrFormats.td - M68k Instruction Formats -----*- tablegen -*-===//
2//                     The LLVM Compiler Infrastructure
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
6//===----------------------------------------------------------------------===//
7///
8/// \file
9/// This file contains M68k instruction formats.
10///
11/// Since M68k has quite a lot memory addressing modes there are more
12/// instruction prefixes than just i, r and m:
13/// TSF  Since     Form                     Letter  Description
14///  00   M68000    Dn or An                 r       any register
15///  01   M68000    Dn                       d       data register direct
16///  02   M68000    An                       a       address register direct
17///  03   M68000    (An)                     j       address register indirect
18///  04   M68000    (An)+                    o       address register indirect with postincrement
19///  05   M68000    -(An)                    e       address register indirect with predecrement
20///  06   M68000    (i,An)                   p       address register indirect with displacement
21///  10   M68000    (i,An,Xn.L)              f       address register indirect with index and scale = 1
22///  07   M68000    (i,An,Xn.W)              F       address register indirect with index and scale = 1
23///  12   M68020    (i,An,Xn.L,SCALE)        g       address register indirect with index
24///  11   M68020    (i,An,Xn.W,SCALE)        G       address register indirect with index
25///  14   M68020    ([bd,An],Xn.L,SCALE,od)  u       memory indirect postindexed mode
26///  13   M68020    ([bd,An],Xn.W,SCALE,od)  U       memory indirect postindexed mode
27///  16   M68020    ([bd,An,Xn.L,SCALE],od)  v       memory indirect preindexed mode
28///  15   M68020    ([bd,An,Xn.W,SCALE],od)  V       memory indirect preindexed mode
29///  20   M68000    abs.L                    b       absolute long address
30///  17   M68000    abs.W                    B       absolute short address
31///  21   M68000    (i,PC)                   q       program counter with displacement
32///  23   M68000    (i,PC,Xn.L)              k       program counter with index and scale = 1
33///  22   M68000    (i,PC,Xn.W)              K       program counter with index and scale = 1
34///  25   M68020    (i,PC,Xn.L,SCALE)        l       program counter with index
35///  24   M68020    (i,PC,Xn.W,SCALE)        L       program counter with index
36///  27   M68020    ([bd,PC],Xn.L,SCALE,od)  x       program counter memory indirect postindexed mode
37///  26   M68020    ([bd,PC],Xn.W,SCALE,od)  X       program counter memory indirect postindexed mode
38///  31   M68020    ([bd,PC,Xn.L,SCALE],od)  y       program counter memory indirect preindexed mode
39///  30   M68020    ([bd,PC,Xn.W,SCALE],od)  Y       program counter memory indirect preindexed mode
40///  32   M68000    #immediate               i       immediate data
41///
42/// NOTE that long form is always lowercase, word variants are capitalized
43///
44/// Operand can be qualified with size where appropriate to force a particular
45/// instruction encoding, e.g.:
46///    (i8,An,Xn.W)             f8      1 extension word
47///    (i16,An,Xn.W)            f16     2 extension words
48///    (i32,An,Xn.W)            f32     3 extension words
49///
50/// Form without size qualifier will adapt to operand size automatically, e.g.:
51///    (i,An,Xn.W)              f       1, 2 or 3 extension words
52///
53/// Some forms already imply a particular size of their operands, e.g.:
54///    (i,An)                   p       1 extension word and i is 16bit
55///
56/// Operand order follows x86 Intel order(destination before source), e.g.:
57///    MOV8df                   MOVE (4,A0,D0), D1
58///
59/// Number after instruction mnemonics determines the size of the data
60///
61//===----------------------------------------------------------------------===//
62
63/// ??? Is it possible to use this stuff for disassembling?
64/// NOTE 1: In case of conditional beads(DA, DAReg), cond part is able to
65/// consume any bit, though a more general instructions must be chosen, e.g.
66/// d -> r, a -> r
67
68//===----------------------------------------------------------------------===//
69// Encoding primitives
70//===----------------------------------------------------------------------===//
71
72class MxBead<bits<4> type, bit b4 = 0, bit b5 = 0, bit b6 = 0, bit b7 = 0> {
73  bits<8> Value = 0b00000000;
74  let Value{3-0} = type;
75  let Value{4} = b4;
76  let Value{5} = b5;
77  let Value{6} = b6;
78  let Value{7} = b7;
79}
80
81/// System beads, allow to control beading flow
82def   MxBeadTerm   : MxBead<0x0, 0, 0, 0, 0>;
83def   MxBeadIgnore : MxBead<0x0, 1, 0, 0, 0>;
84
85/// Add plain bit to the instruction
86class MxBead1Bit  <bits<1> b> : MxBead<0x1, b>;
87class MxBead2Bits <bits<2> b> : MxBead<0x2, b{0}, b{1}>;
88class MxBead3Bits <bits<3> b> : MxBead<0x3, b{0}, b{1}, b{2}>;
89class MxBead4Bits <bits<4> b> : MxBead<0x4, b{0}, b{1}, b{2}, b{3}>;
90
91/// bits<3> o - operand number
92/// bit a     - use alternative, used to select index register or
93///             outer displacement/immediate
94/// suffix NP means non-padded
95class MxBeadDAReg  <bits<3> o, bit a = 0> : MxBead<0x5, o{0}, o{1}, o{2}, a>;
96class MxBeadDA     <bits<3> o, bit a = 0> : MxBead<0x6, o{0}, o{1}, o{2}, a>;
97class MxBeadReg    <bits<3> o, bit a = 0> : MxBead<0x7, o{0}, o{1}, o{2}, a>;
98class MxBeadDReg   <bits<3> o, bit a = 0> : MxBead<0x8, o{0}, o{1}, o{2}, a>;
99class MxBead8Disp  <bits<3> o, bit a = 0> : MxBead<0x9, o{0}, o{1}, o{2}, a>;
100
101/// Add Immediate to the instruction. 8-bit version is padded with zeros to fit
102/// the word.
103class MxBead8Imm   <bits<3> o, bit a = 0> : MxBead<0xA, o{0}, o{1}, o{2}, a>;
104class MxBead16Imm  <bits<3> o, bit a = 0> : MxBead<0xB, o{0}, o{1}, o{2}, a>;
105class MxBead32Imm  <bits<3> o, bit a = 0> : MxBead<0xC, o{0}, o{1}, o{2}, a>;
106
107/// Encodes an immediate 0-7(alt. 1-8) into 3 bit field
108class MxBead3Imm   <bits<3> o, bit a = 0> : MxBead<0xD, o{0}, o{1}, o{2}, a>;
109
110
111class MxEncoding<MxBead n0  = MxBeadTerm, MxBead n1  = MxBeadTerm,
112                 MxBead n2  = MxBeadTerm, MxBead n3  = MxBeadTerm,
113                 MxBead n4  = MxBeadTerm, MxBead n5  = MxBeadTerm,
114                 MxBead n6  = MxBeadTerm, MxBead n7  = MxBeadTerm,
115                 MxBead n8  = MxBeadTerm, MxBead n9  = MxBeadTerm,
116                 MxBead n10 = MxBeadTerm, MxBead n11 = MxBeadTerm,
117                 MxBead n12 = MxBeadTerm, MxBead n13 = MxBeadTerm,
118                 MxBead n14 = MxBeadTerm, MxBead n15 = MxBeadTerm,
119                 MxBead n16 = MxBeadTerm, MxBead n17 = MxBeadTerm,
120                 MxBead n18 = MxBeadTerm, MxBead n19 = MxBeadTerm,
121                 MxBead n20 = MxBeadTerm, MxBead n21 = MxBeadTerm,
122                 MxBead n22 = MxBeadTerm, MxBead n23 = MxBeadTerm> {
123  bits <192> Value;
124  let Value{7-0}     = n0.Value;
125  let Value{15-8}    = n1.Value;
126  let Value{23-16}   = n2.Value;
127  let Value{31-24}   = n3.Value;
128  let Value{39-32}   = n4.Value;
129  let Value{47-40}   = n5.Value;
130  let Value{55-48}   = n6.Value;
131  let Value{63-56}   = n7.Value;
132  let Value{71-64}   = n8.Value;
133  let Value{79-72}   = n9.Value;
134  let Value{87-80}   = n10.Value;
135  let Value{95-88}   = n11.Value;
136  let Value{103-96}  = n12.Value;
137  let Value{111-104} = n13.Value;
138  let Value{119-112} = n14.Value;
139  let Value{127-120} = n15.Value;
140  let Value{135-128} = n16.Value;
141  let Value{143-136} = n17.Value;
142  let Value{151-144} = n18.Value;
143  let Value{159-152} = n19.Value;
144  let Value{167-160} = n20.Value;
145  let Value{175-168} = n21.Value;
146  let Value{183-176} = n22.Value;
147  let Value{191-184} = n23.Value;
148}
149
150class MxEncFixed<bits<16> value> : MxEncoding {
151  let Value{7-0}   = MxBead4Bits<value{3-0}>.Value;
152  let Value{15-8}  = MxBead4Bits<value{7-4}>.Value;
153  let Value{23-16} = MxBead4Bits<value{11-8}>.Value;
154  let Value{31-24} = MxBead4Bits<value{15-12}>.Value;
155}
156
157//===----------------------------------------------------------------------===//
158// Encoding composites
159//
160// These must be lowered to MxEncoding by instr specific wrappers
161//
162// HERE BE DRAGONS...
163//===----------------------------------------------------------------------===//
164
165class MxEncByte<bits<8> value> : MxEncoding {
166  MxBead4Bits LO = MxBead4Bits<value{3-0}>;
167  MxBead4Bits HI = MxBead4Bits<value{7-4}>;
168}
169
170def MxEncEmpty : MxEncoding;
171
172
173/// M68k Standard Effective Address layout:
174///
175/// :-------------------:
176/// | 5  4  3 | 2  1  0 |
177/// |   mode  |   reg   |
178/// :-------------------:
179///
180/// If the EA is a direct register mode, bits 4 and 5 are 0, and the register
181/// number will be encoded in bit 0 - 3. Since the first address register's
182/// (A0) register number is 8, we can easily tell data registers from
183/// address registers by only inspecting bit 3 (i.e. if bit 3 is set, it's an
184/// address register).
185///
186///
187/// But MOVE instruction uses reversed layout for destination EA:
188///
189/// :-------------------:
190/// | 5  4  3 | 2  1  0 |
191/// |   reg   |  mode   |
192/// :-------------------:
193///
194/// And this complicates things a bit because the DA bit is now separated from
195/// the register and we have to encode those separately using MxBeadDA<opN>
196///
197class MxEncEA<MxBead reg, MxBead mode, MxBead da = MxBeadIgnore> {
198  MxBead Reg = reg;
199  MxBead Mode = mode;
200  MxBead DA = da;
201}
202
203class MxEncMemOp {
204  dag EA = (ascend);
205  dag Supplement = (ascend);
206}
207
208// FIXME: Is there a way to factorize the addressing mode suffix (i.e.
209// 'r', 'd', 'a' etc.) and use something like multiclass to replace?
210def MxEncEAr_0: MxEncEA<MxBeadDAReg<0>, MxBead2Bits<0b00>>;
211def MxEncEAd_0: MxEncEA<MxBeadDReg<0>, MxBead2Bits<0b00>, MxBead1Bit<0>>;
212def MxEncEAa_0: MxEncEA<MxBeadReg<0>, MxBead2Bits<0b00>, MxBead1Bit<1>>;
213def MxEncEAj_0: MxEncEA<MxBeadReg<0>, MxBead2Bits<0b01>, MxBead1Bit<0>>;
214def MxEncEAo_0: MxEncEA<MxBeadReg<0>, MxBead2Bits<0b01>, MxBead1Bit<1>>;
215def MxEncEAe_0: MxEncEA<MxBeadReg<0>, MxBead2Bits<0b10>, MxBead1Bit<0>>;
216def MxEncEAp_0: MxEncEA<MxBeadReg<0>, MxBead2Bits<0b10>, MxBead1Bit<1>>;
217def MxEncEAf_0: MxEncEA<MxBeadReg<0>, MxBead2Bits<0b11>, MxBead1Bit<0>>;
218
219def MxEncEAa_0_reflected : MxEncEA<MxBeadReg<0>, MxBead3Bits<0b001>>;
220def MxEncEAr_0_reflected : MxEncEA<MxBeadReg<0>, MxBead2Bits<0b00>, MxBeadDA<0>>;
221
222def MxEncEAr_1: MxEncEA<MxBeadDAReg<1>, MxBead2Bits<0b00>>;
223def MxEncEAd_1: MxEncEA<MxBeadDReg<1>, MxBead2Bits<0b00>, MxBead1Bit<0>>;
224def MxEncEAa_1: MxEncEA<MxBeadReg<1>, MxBead2Bits<0b00>, MxBead1Bit<1>>;
225def MxEncEAj_1: MxEncEA<MxBeadReg<1>, MxBead2Bits<0b01>, MxBead1Bit<0>>;
226def MxEncEAo_1: MxEncEA<MxBeadReg<1>, MxBead2Bits<0b01>, MxBead1Bit<1>>;
227def MxEncEAe_1: MxEncEA<MxBeadReg<1>, MxBead2Bits<0b10>, MxBead1Bit<0>>;
228def MxEncEAp_1: MxEncEA<MxBeadReg<1>, MxBead2Bits<0b10>, MxBead1Bit<1>>;
229def MxEncEAf_1: MxEncEA<MxBeadReg<1>, MxBead2Bits<0b11>, MxBead1Bit<0>>;
230
231def MxEncEAr_2: MxEncEA<MxBeadDAReg<2>, MxBead2Bits<0b00>>;
232def MxEncEAd_2: MxEncEA<MxBeadDReg<2>, MxBead2Bits<0b00>, MxBead1Bit<0>>;
233def MxEncEAa_2: MxEncEA<MxBeadReg<2>, MxBead2Bits<0b00>, MxBead1Bit<1>>;
234def MxEncEAj_2: MxEncEA<MxBeadReg<2>, MxBead2Bits<0b01>, MxBead1Bit<0>>;
235def MxEncEAo_2: MxEncEA<MxBeadReg<2>, MxBead2Bits<0b01>, MxBead1Bit<1>>;
236def MxEncEAe_2: MxEncEA<MxBeadReg<2>, MxBead2Bits<0b10>, MxBead1Bit<0>>;
237def MxEncEAp_2: MxEncEA<MxBeadReg<2>, MxBead2Bits<0b10>, MxBead1Bit<1>>;
238def MxEncEAf_2: MxEncEA<MxBeadReg<2>, MxBead2Bits<0b11>, MxBead1Bit<0>>;
239
240def MxEncEAb : MxEncEA<MxBead3Bits<0b001>, MxBead2Bits<0b11>, MxBead1Bit<1>>;
241def MxEncEAq : MxEncEA<MxBead3Bits<0b010>, MxBead2Bits<0b11>, MxBead1Bit<1>>;
242def MxEncEAk : MxEncEA<MxBead3Bits<0b011>, MxBead2Bits<0b11>, MxBead1Bit<1>>;
243def MxEncEAi : MxEncEA<MxBead3Bits<0b100>, MxBead2Bits<0b11>, MxBead1Bit<1>>;
244
245class MxEncBriefExt<string reg_opnd, string disp_opnd,
246                    bit size_w_l = false, int scale = 1,
247                    string disp_encoder = ""> {
248  dag Value = (descend
249    // D/A + REGISTER
250    (operand "$"#reg_opnd, 4),
251    // W/L
252    size_w_l,
253    // SCALE
254    !cond(
255      !eq(scale, 1) : 0b00,
256      !eq(scale, 2) : 0b01,
257      !eq(scale, 4) : 0b10,
258      !eq(scale, 8) : 0b11
259    ),
260    0b0,
261    // Displacement
262    (operand "$"#disp_opnd, 8, (encoder disp_encoder))
263  );
264}
265
266class MxEncAddrMode_d<string reg_opnd> : MxEncMemOp {
267  let EA = (descend /*MODE*/0b000,
268                    /*REGISTER*/(operand "$"#reg_opnd, 3));
269}
270
271class MxEncAddrMode_a<string reg_opnd> : MxEncMemOp {
272  let EA = (descend /*MODE*/0b001,
273                    /*REGISTER*/(operand "$"#reg_opnd, 3));
274}
275
276class MxEncAddrMode_r<string reg_opnd> : MxEncMemOp {
277  let EA = (descend /*MODE without the last bit*/0b00,
278                    /*REGISTER with D/A bit*/(operand "$"#reg_opnd, 4));
279}
280
281class MxEncAddrMode_k<string opnd_name> : MxEncMemOp {
282  let EA = (descend /*MODE*/0b111,
283                    /*REGISTER*/0b011);
284
285  let Supplement = MxEncBriefExt<opnd_name#".index", opnd_name#".disp",
286                                 /*W/L*/true, /*SCALE*/1,
287                                 "encodePCRelImm<8>">.Value;
288}
289
290class MxEncAddrMode_q<string opnd_name> : MxEncMemOp {
291  let EA = (descend /*MODE*/0b111,
292                     /*REGISTER*/0b010);
293
294  // 16-bit Displacement
295  let Supplement = (operand "$"#opnd_name, 16,
296                            (encoder "encodePCRelImm<16>"));
297}
298
299class MxEncAddrMode_p<string opnd_name> : MxEncMemOp {
300  let EA = (descend /*MODE*/0b101,
301                     /*REGISTER*/(operand "$"#opnd_name#".reg", 3));
302
303  // 16-bit Displacement
304  let Supplement = (operand "$"#opnd_name#".disp", 16,
305                            (encoder "encodeRelocImm<16>"));
306}
307
308class MxEncAddrMode_f<string opnd_name> : MxEncMemOp {
309  let EA = (descend /*MODE*/0b110,
310                     /*REGISTER*/(operand "$"#opnd_name#".reg", 3));
311
312  let Supplement = MxEncBriefExt<opnd_name#".index", opnd_name#".disp",
313                                 /*W/L*/true, /*SCALE*/1,
314                                 "encodeRelocImm<8>">.Value;
315}
316
317class MxEncAddrMode_j<string reg_opnd> : MxEncMemOp {
318  let EA = (descend /*MODE*/0b010,
319                     /*REGISTER*/(operand "$"#reg_opnd, 3));
320}
321
322class MxEncAddrMode_i<string opnd_name, int size> : MxEncMemOp {
323  let EA = (descend /*MODE*/0b111,
324                     /*REGISTER*/0b100);
325
326  // Immediate
327  let Supplement =
328    !cond(
329      !eq(size, 8)  : (descend 0b00000000, (operand "$"#opnd_name, 8)),
330      !eq(size, 16) : (operand "$"#opnd_name, 16),
331      !eq(size, 32) : (ascend (slice "$"#opnd_name, 31, 16),
332                              (slice "$"#opnd_name, 15, 0))
333    );
334}
335
336// abs.W -> size_w_l = false
337// abs.L -> size_w_l = true
338class MxEncAddrMode_abs<string opnd_name, bit size_w_l = false> : MxEncMemOp {
339  let EA = (descend /*MODE*/0b111,
340                    // Wrap the REGISTER part in another dag to make sure
341                    // the dag assigned to EA only has two arguments. Such
342                    // that it's easier for MOV instructions to reverse
343                    // on its destination part.
344                    /*REGISTER*/(descend 0b00, size_w_l));
345
346  // Absolute address
347  let Supplement = !if(size_w_l,
348    // abs.L
349    (operand "$"#opnd_name, 32, (encoder "encodeRelocImm<32>")),
350    // abs.W
351    (operand "$"#opnd_name, 16, (encoder "encodeRelocImm<16>"))
352  );
353}
354
355class MxEncAddrMode_o<string reg_opnd> : MxEncMemOp {
356  let EA = (descend /*MODE*/0b011,
357                    /*REGISTER*/(operand "$"#reg_opnd, 3));
358}
359
360class MxEncAddrMode_e<string reg_opnd> : MxEncMemOp {
361  let EA = (descend /*MODE*/0b100,
362                    /*REGISTER*/(operand "$"#reg_opnd, 3));
363}
364
365// Allows you to specify each bit of opcode
366class MxEncOpMode<MxBead b0, MxBead b1 = MxBeadIgnore, MxBead b2 = MxBeadIgnore> {
367  MxBead B0 = b0;
368  MxBead B1 = b1;
369  MxBead B2 = b2;
370}
371
372// op EA, Dn
373def MxOpMode8dEA  : MxEncOpMode<MxBead3Bits<0b000>>;
374def MxOpMode16dEA : MxEncOpMode<MxBead3Bits<0b001>>;
375def MxOpMode32dEA : MxEncOpMode<MxBead3Bits<0b010>>;
376
377// op EA, An
378def MxOpMode16aEA : MxEncOpMode<MxBead3Bits<0b011>>;
379def MxOpMode32aEA : MxEncOpMode<MxBead3Bits<0b111>>;
380
381// op EA, Rn
382// As you might noticed this guy is special... Since M68k differentiates
383// between Data and Address registers we required to use different OPMODE codes
384// for Address registers DST operands. One way of dealing with it is to use
385// separate tablegen instructions, but in this case it would force Register
386// Allocator to use specific Register Classes and eventually will lead to
387// superfluous moves. Another approach is to use reg-variadic encoding which will
388// change OPMODE base on Register Class used. Luckily, all the bits that differ go
389// from 0 to 1 and can be encoded with MxBeadDA.
390// Basically, if the register used is of Data type these encodings will be
391// the same as MxOpMode{16,32}dEA above and used with regular instructions(e.g. ADD,
392// SUB), but if the register is of Address type the appropriate bits will flip and
393// the instructions become of *A type(e.g ADDA, SUBA).
394def MxOpMode16rEA : MxEncOpMode<MxBead1Bit<1>, MxBeadDA<0>, MxBead1Bit<0>>;
395def MxOpMode32rEA : MxEncOpMode<MxBeadDA<0>, MxBead1Bit<1>, MxBeadDA<0>>;
396
397// op Dn, EA
398def MxOpMode8EAd : MxEncOpMode<MxBead3Bits<0b100>>;
399def MxOpMode16EAd : MxEncOpMode<MxBead3Bits<0b101>>;
400def MxOpMode32EAd : MxEncOpMode<MxBead3Bits<0b110>>;
401
402
403// Represents two types of extension word:
404//   - Imm extension word
405//   - Brief extension word
406class MxEncExt<MxBead imm   = MxBeadIgnore,   MxBead b8 = MxBeadIgnore,
407               MxBead scale = MxBeadIgnore, MxBead wl = MxBeadIgnore,
408               MxBead daReg = MxBeadIgnore> {
409  MxBead Imm = imm;
410  MxBead B8 = b8;
411  MxBead Scale = scale;
412  MxBead WL = wl;
413  MxBead DAReg = daReg;
414}
415
416def MxExtEmpty : MxEncExt;
417
418// These handle encoding of displacement fields, absolute addresses and
419// immediate values, since encoding for these categories is mainly the same,
420// with exception of some weird immediates.
421def  MxExtI8_0 : MxEncExt<MxBead8Imm<0>>;
422def MxExtI16_0 : MxEncExt<MxBead16Imm<0>>;
423def MxExtI32_0 : MxEncExt<MxBead32Imm<0>>;
424
425def  MxExtI8_1 : MxEncExt<MxBead8Imm<1>>;
426def MxExtI16_1 : MxEncExt<MxBead16Imm<1>>;
427def MxExtI32_1 : MxEncExt<MxBead32Imm<1>>;
428
429def  MxExtI8_2 : MxEncExt<MxBead8Imm<2>>;
430def MxExtI16_2 : MxEncExt<MxBead16Imm<2>>;
431def MxExtI32_2 : MxEncExt<MxBead32Imm<2>>;
432
433// NOTE They are all using Long Xn
434def MxExtBrief_0 : MxEncExt<MxBead8Disp<0>, MxBead1Bit<0b0>,
435                            MxBead2Bits<0b00>, MxBead1Bit<1>,
436                            MxBeadDAReg<0, 1>>;
437
438def MxExtBrief_1 : MxEncExt<MxBead8Disp<1>, MxBead1Bit<0b0>,
439                            MxBead2Bits<0b00>, MxBead1Bit<1>,
440                            MxBeadDAReg<1, 1>>;
441
442def MxExtBrief_2 : MxEncExt<MxBead8Disp<2>, MxBead1Bit<0b0>,
443                            MxBead2Bits<0b00>, MxBead1Bit<1>,
444                            MxBeadDAReg<2, 1>>;
445
446def MxExtBrief_3 : MxEncExt<MxBead8Disp<3>, MxBead1Bit<0b0>,
447                            MxBead2Bits<0b00>, MxBead1Bit<1>,
448                            MxBeadDAReg<3, 1>>;
449
450def MxExtBrief_4 : MxEncExt<MxBead8Disp<4>, MxBead1Bit<0b0>,
451                            MxBead2Bits<0b00>, MxBead1Bit<1>,
452                            MxBeadDAReg<4, 1>>;
453
454class MxEncSize<bits<2> value> : MxBead2Bits<value>;
455def MxEncSize8  : MxEncSize<0b00>;
456def MxEncSize16 : MxEncSize<0b01>;
457def MxEncSize32 : MxEncSize<0b10>;
458def MxEncSize64 : MxEncSize<0b11>;
459
460// TODO: Remove "New" in the name after the codebead-based
461// representation is deprecated.
462class MxNewEncSize<bits<2> value> {
463  bits<2> Value = value;
464}
465def MxNewEncSize8  : MxNewEncSize<0b00>;
466def MxNewEncSize16 : MxNewEncSize<0b01>;
467def MxNewEncSize32 : MxNewEncSize<0b10>;
468def MxNewEncSize64 : MxNewEncSize<0b11>;
469
470// M68k INSTRUCTION. Most instructions specify the location of an operand by
471// using the effective address field in the operation word. The effective address
472// is composed of two 3-bit fields: the mode field and the register field. The
473// value in the mode field selects the different address modes. The register
474// field contains the number of a register.  The effective address field may
475// require additional information to fully specify the operand. This additional
476// information, called the effective address extension, is contained in the
477// following word or words and is considered part of the instruction. The
478// effective address modes are grouped into three categories: register direct,
479// memory addressing, and special.
480class MxInst<dag outs, dag ins,
481             string asmStr = "",
482             list<dag> pattern = [],
483             MxEncoding beads = MxEncEmpty,
484             InstrItinClass itin = NoItinerary>
485    : Instruction {
486  let Namespace      = "M68k";
487  let OutOperandList = outs;
488  let InOperandList  = ins;
489  let AsmString      = asmStr;
490  let Pattern        = pattern;
491  let Itinerary      = itin;
492
493  // Byte stream
494  field bits<192> Beads = beads.Value;
495  dag Inst = (ascend);
496
497  // Number of bytes
498  let Size = 0;
499
500  let UseLogicalOperandMappings = 1;
501}
502
503// M68k PSEUDO INSTRUCTION
504class MxPseudo<dag outs, dag ins, list<dag> pattern = []>
505    : MxInst<outs, ins, "; error: this should not be emitted", pattern> {
506  let isPseudo = 1;
507}
508