1 //===-- MSP430InstrFormats.td - MSP430 Instruction Formats -*- tablegen -*-===//
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 //===----------------------------------------------------------------------===//
10 // Describe MSP430 instructions format here
13 class SourceMode<bits<2> val> {
17 def SrcReg : SourceMode<0>; // r
18 def SrcMem : SourceMode<1>; // m
19 def SrcIndReg : SourceMode<2>; // n
20 def SrcPostInc : SourceMode<3>; // p
21 def SrcImm : SourceMode<3>; // i
22 // SrcCGImm : SourceMode< >; // c
24 class DestMode<bit val> {
28 def DstReg : DestMode<0>; // r
29 def DstMem : DestMode<1>; // m
31 // Generic MSP430 Format
32 class MSP430Inst<dag outs, dag ins, int size, string asmstr> : Instruction {
34 field bits<48> SoftFail = 0;
36 let Namespace = "MSP430";
38 dag OutOperandList = outs;
39 dag InOperandList = ins;
41 let AsmString = asmstr;
45 // MSP430 Double Operand (Format I) Instructions
46 class IForm<bits<4> opcode, DestMode ad, bit bw, SourceMode as, int size,
47 dag outs, dag ins, string asmstr, list<dag> pattern>
48 : MSP430Inst<outs, ins, size, asmstr> {
49 let Pattern = pattern;
54 let Inst{15-12} = opcode;
56 let Inst{7} = ad.Value;
58 let Inst{5-4} = as.Value;
62 // 8 bit IForm instructions
63 class IForm8<bits<4> opcode, DestMode dest, SourceMode src, int size,
64 dag outs, dag ins, string asmstr, list<dag> pattern>
65 : IForm<opcode, dest, 1, src, size, outs, ins, asmstr, pattern>;
67 class I8rr<bits<4> opcode,
68 dag outs, dag ins, string asmstr, list<dag> pattern>
69 : IForm8<opcode, DstReg, SrcReg, 2, outs, ins, asmstr, pattern> {
70 let DecoderNamespace = "Alpha";
73 class I8ri<bits<4> opcode,
74 dag outs, dag ins, string asmstr, list<dag> pattern>
75 : IForm8<opcode, DstReg, SrcImm, 4, outs, ins, asmstr, pattern> {
76 let DecoderNamespace = "Gamma";
78 let Inst{31-16} = imm;
82 class I8rc<bits<4> opcode,
83 dag outs, dag ins, string asmstr, list<dag> pattern>
84 : MSP430Inst<outs, ins, 2, asmstr> {
85 let DecoderNamespace = "Beta";
86 let Pattern = pattern;
91 let Inst{15-12} = opcode;
92 let Inst{11-8} = imm{3-0};
93 let Inst{7} = DstReg.Value;
95 let Inst{5-4} = imm{5-4};
99 class I8rm<bits<4> opcode,
100 dag outs, dag ins, string asmstr, list<dag> pattern>
101 : IForm8<opcode, DstReg, SrcMem, 4, outs, ins, asmstr, pattern> {
102 let DecoderNamespace = "Gamma";
105 let Inst{31-16} = src{19-4};
108 class I8rn<bits<4> opcode,
109 dag outs, dag ins, string asmstr, list<dag> pattern>
110 : IForm8<opcode, DstReg, SrcIndReg, 2, outs, ins, asmstr, pattern> {
111 let DecoderNamespace = "Delta";
114 class I8rp<bits<4> opcode,
115 dag outs, dag ins, string asmstr, list<dag> pattern>
116 : IForm8<opcode, DstReg, SrcPostInc, 2, outs, ins, asmstr, pattern> {
117 let DecoderNamespace = "Delta";
120 class I8mr<bits<4> opcode,
121 dag outs, dag ins, string asmstr, list<dag> pattern>
122 : IForm8<opcode, DstMem, SrcReg, 4, outs, ins, asmstr, pattern> {
123 let DecoderNamespace = "Alpha";
126 let Inst{31-16} = dst{19-4};
129 class I8mi<bits<4> opcode,
130 dag outs, dag ins, string asmstr, list<dag> pattern>
131 : IForm8<opcode, DstMem, SrcImm, 6, outs, ins, asmstr, pattern> {
132 let DecoderNamespace = "Gamma";
136 let Inst{31-16} = imm;
138 let Inst{47-32} = dst{19-4};
141 class I8mc<bits<4> opcode,
142 dag outs, dag ins, string asmstr, list<dag> pattern>
143 : MSP430Inst<outs, ins, 4, asmstr> {
144 let DecoderNamespace = "Beta";
145 let Pattern = pattern;
150 let Inst{31-16} = dst{19-4};
151 let Inst{15-12} = opcode;
152 let Inst{11-8} = imm{3-0};
153 let Inst{7} = DstMem.Value;
155 let Inst{5-4} = imm{5-4};
156 let Inst{3-0} = dst{3-0};
159 class I8mm<bits<4> opcode,
160 dag outs, dag ins, string asmstr, list<dag> pattern>
161 : IForm8<opcode, DstMem, SrcMem, 6, outs, ins, asmstr, pattern> {
162 let DecoderNamespace = "Gamma";
166 let Inst{31-16} = src{19-4};
168 let Inst{47-32} = dst{19-4};
171 class I8mn<bits<4> opcode,
172 dag outs, dag ins, string asmstr, list<dag> pattern>
173 : IForm8<opcode, DstMem, SrcIndReg, 4, outs, ins, asmstr, pattern> {
174 let DecoderNamespace = "Delta";
177 let Inst{31-16} = dst{19-4};
180 class I8mp<bits<4> opcode,
181 dag outs, dag ins, string asmstr, list<dag> pattern>
182 : IForm8<opcode, DstMem, SrcPostInc, 4, outs, ins, asmstr, pattern> {
183 let DecoderNamespace = "Delta";
186 let Inst{31-16} = dst{19-4};
189 // 16 bit IForm instructions
190 class IForm16<bits<4> opcode, DestMode dest, SourceMode src, int size,
191 dag outs, dag ins, string asmstr, list<dag> pattern>
192 : IForm<opcode, dest, 0, src, size, outs, ins, asmstr, pattern>;
194 class I16rr<bits<4> opcode,
195 dag outs, dag ins, string asmstr, list<dag> pattern>
196 : IForm16<opcode, DstReg, SrcReg, 2, outs, ins, asmstr, pattern> {
197 let DecoderNamespace = "Alpha";
200 class I16ri<bits<4> opcode,
201 dag outs, dag ins, string asmstr, list<dag> pattern>
202 : IForm16<opcode, DstReg, SrcImm, 4, outs, ins, asmstr, pattern> {
203 let DecoderNamespace = "Gamma";
205 let Inst{31-16} = imm;
209 class I16rc<bits<4> opcode,
210 dag outs, dag ins, string asmstr, list<dag> pattern>
211 : MSP430Inst<outs, ins, 2, asmstr> {
212 let DecoderNamespace = "Beta";
213 let Pattern = pattern;
218 let Inst{15-12} = opcode;
219 let Inst{11-8} = imm{3-0};
220 let Inst{7} = DstReg.Value;
222 let Inst{5-4} = imm{5-4};
226 class I16rm<bits<4> opcode,
227 dag outs, dag ins, string asmstr, list<dag> pattern>
228 : IForm16<opcode, DstReg, SrcMem, 4, outs, ins, asmstr, pattern> {
229 let DecoderNamespace = "Gamma";
232 let Inst{31-16} = src{19-4};
235 class I16rn<bits<4> opcode,
236 dag outs, dag ins, string asmstr, list<dag> pattern>
237 : IForm16<opcode, DstReg, SrcIndReg, 2, outs, ins, asmstr, pattern> {
238 let DecoderNamespace = "Delta";
241 class I16rp<bits<4> opcode,
242 dag outs, dag ins, string asmstr, list<dag> pattern>
243 : IForm16<opcode, DstReg, SrcPostInc, 2, outs, ins, asmstr, pattern> {
244 let DecoderNamespace = "Delta";
247 class I16mr<bits<4> opcode,
248 dag outs, dag ins, string asmstr, list<dag> pattern>
249 : IForm16<opcode, DstMem, SrcReg, 4, outs, ins, asmstr, pattern> {
250 let DecoderNamespace = "Alpha";
253 let Inst{31-16} = dst{19-4};
256 class I16mi<bits<4> opcode,
257 dag outs, dag ins, string asmstr, list<dag> pattern>
258 : IForm16<opcode, DstMem, SrcImm, 6, outs, ins, asmstr, pattern> {
259 let DecoderNamespace = "Gamma";
262 let Inst{31-16} = imm;
265 let Inst{47-32} = dst{19-4};
268 class I16mc<bits<4> opcode,
269 dag outs, dag ins, string asmstr, list<dag> pattern>
270 : MSP430Inst<outs, ins, 4, asmstr> {
271 let DecoderNamespace = "Beta";
272 let Pattern = pattern;
277 let Inst{31-16} = dst{19-4};
278 let Inst{15-12} = opcode;
279 let Inst{11-8} = imm{3-0};
280 let Inst{7} = DstMem.Value;
282 let Inst{5-4} = imm{5-4};
283 let Inst{3-0} = dst{3-0};
286 class I16mm<bits<4> opcode,
287 dag outs, dag ins, string asmstr, list<dag> pattern>
288 : IForm16<opcode, DstMem, SrcMem, 6, outs, ins, asmstr, pattern> {
289 let DecoderNamespace = "Gamma";
293 let Inst{31-16} = src{19-4};
295 let Inst{47-32} = dst{19-4};
298 class I16mn<bits<4> opcode,
299 dag outs, dag ins, string asmstr, list<dag> pattern>
300 : IForm16<opcode, DstMem, SrcIndReg, 4, outs, ins, asmstr, pattern> {
301 let DecoderNamespace = "Delta";
304 let Inst{31-16} = dst{19-4};
307 class I16mp<bits<4> opcode,
308 dag outs, dag ins, string asmstr, list<dag> pattern>
309 : IForm16<opcode, DstMem, SrcPostInc, 4, outs, ins, asmstr, pattern> {
310 let DecoderNamespace = "Delta";
313 let Inst{31-16} = dst{19-4};
316 // MSP430 Single Operand (Format II) Instructions
317 class IIForm<bits<3> opcode, bit bw, SourceMode as, int size,
318 dag outs, dag ins, string asmstr, list<dag> pattern>
319 : MSP430Inst<outs, ins, size, asmstr> {
320 let Pattern = pattern;
324 let Inst{15-10} = 0b000100;
325 let Inst{9-7} = opcode;
327 let Inst{5-4} = as.Value;
331 // 8 bit IIForm instructions
332 class IIForm8<bits<3> opcode, SourceMode src, int size,
333 dag outs, dag ins, string asmstr, list<dag> pattern>
334 : IIForm<opcode, 1, src, size, outs, ins, asmstr, pattern>;
336 class II8r<bits<3> opcode,
337 dag outs, dag ins, string asmstr, list<dag> pattern>
338 : IIForm8<opcode, SrcReg, 2, outs, ins, asmstr, pattern>;
340 class II8m<bits<3> opcode,
341 dag outs, dag ins, string asmstr, list<dag> pattern>
342 : IIForm8<opcode, SrcMem, 4, outs, ins, asmstr, pattern> {
345 let Inst{31-16} = src{19-4};
348 class II8i<bits<3> opcode,
349 dag outs, dag ins, string asmstr, list<dag> pattern>
350 : IIForm8<opcode, SrcImm, 4, outs, ins, asmstr, pattern> {
353 let Inst{31-16} = imm;
356 class II8c<bits<3> opcode,
357 dag outs, dag ins, string asmstr, list<dag> pattern>
358 : MSP430Inst<outs, ins, 2, asmstr> {
359 let Pattern = pattern;
363 let Inst{15-10} = 0b000100;
364 let Inst{9-7} = opcode;
369 class II8n<bits<3> opcode,
370 dag outs, dag ins, string asmstr, list<dag> pattern>
371 : IIForm8<opcode, SrcIndReg, 2, outs, ins, asmstr, pattern>;
373 class II8p<bits<3> opcode,
374 dag outs, dag ins, string asmstr, list<dag> pattern>
375 : IIForm8<opcode, SrcPostInc, 2, outs, ins, asmstr, pattern>;
377 // 16 bit IIForm instructions
378 class IIForm16<bits<3> opcode, SourceMode src, int size,
379 dag outs, dag ins, string asmstr, list<dag> pattern>
380 : IIForm<opcode, 0, src, size, outs, ins, asmstr, pattern>;
382 class II16r<bits<3> opcode,
383 dag outs, dag ins, string asmstr, list<dag> pattern>
384 : IIForm16<opcode, SrcReg, 2, outs, ins, asmstr, pattern>;
386 class II16m<bits<3> opcode,
387 dag outs, dag ins, string asmstr, list<dag> pattern>
388 : IIForm16<opcode, SrcMem, 4, outs, ins, asmstr, pattern> {
391 let Inst{31-16} = src{19-4};
394 class II16i<bits<3> opcode,
395 dag outs, dag ins, string asmstr, list<dag> pattern>
396 : IIForm16<opcode, SrcImm, 4, outs, ins, asmstr, pattern> {
399 let Inst{31-16} = imm;
402 class II16c<bits<3> opcode,
403 dag outs, dag ins, string asmstr, list<dag> pattern>
404 : MSP430Inst<outs, ins, 2, asmstr> {
405 let Pattern = pattern;
409 let Inst{15-10} = 0b000100;
410 let Inst{9-7} = opcode;
415 class II16n<bits<3> opcode,
416 dag outs, dag ins, string asmstr, list<dag> pattern>
417 : IIForm16<opcode, SrcIndReg, 2, outs, ins, asmstr, pattern>;
419 class II16p<bits<3> opcode,
420 dag outs, dag ins, string asmstr, list<dag> pattern>
421 : IIForm16<opcode, SrcPostInc, 2, outs, ins, asmstr, pattern>;
423 // MSP430 Conditional Jumps Instructions
424 class CJForm<dag outs, dag ins, string asmstr, list<dag> pattern>
425 : MSP430Inst<outs, ins, 2, asmstr> {
426 let Pattern = pattern;
431 let Inst{15-13} = 0b001;
432 let Inst{12-10} = cond;
436 // Pseudo instructions
437 class Pseudo<dag outs, dag ins, string asmstr, list<dag> pattern>
438 : MSP430Inst<outs, ins, 0, asmstr> {
439 let Pattern = pattern;