1 //===-- AVRInstrInfo.td - AVR 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 // AVR Instruction Format Definitions.
11 //===----------------------------------------------------------------------===//
13 // A generic AVR instruction.
14 class AVRInst<dag outs, dag ins, string asmstr, list<dag> pattern>
16 let Namespace = "AVR";
18 dag OutOperandList = outs;
19 dag InOperandList = ins;
20 let AsmString = asmstr;
21 let Pattern = pattern;
23 field bits<32> SoftFail = 0;
26 /// A 16-bit AVR instruction.
27 class AVRInst16<dag outs, dag ins, string asmstr, list<dag> pattern>
28 : AVRInst<outs, ins, asmstr, pattern> {
34 /// a 32-bit AVR instruction.
35 class AVRInst32<dag outs, dag ins, string asmstr, list<dag> pattern>
36 : AVRInst<outs, ins, asmstr, pattern> {
42 // A class for pseudo instructions.
43 // Pseudo instructions are not real AVR instructions. The DAG stores
44 // pseudo instructions which are replaced by real AVR instructions by
45 // AVRExpandPseudoInsts.cpp.
47 // For example, the ADDW (add wide, as in add 16 bit values) instruction
48 // is defined as a pseudo instruction. In AVRExpandPseudoInsts.cpp,
49 // the instruction is then replaced by two add instructions - one for each byte.
50 class Pseudo<dag outs, dag ins, string asmstr, list<dag> pattern>
51 : AVRInst16<outs, ins, asmstr, pattern> {
52 let Pattern = pattern;
55 let isCodeGenOnly = 1;
58 //===----------------------------------------------------------------------===//
59 // Register / register instruction: <|opcode|ffrd|dddd|rrrr|>
61 // f = secondary opcode = 2 bits
62 // d = destination = 5 bits
63 // r = source = 5 bits
64 // (Accepts all registers)
65 //===----------------------------------------------------------------------===//
66 class FRdRr<bits<4> opcode, bits<2> f, dag outs, dag ins, string asmstr,
67 list<dag> pattern> : AVRInst16<outs, ins, asmstr, pattern> {
71 let Inst{15 - 12} = opcode;
72 let Inst{11 - 10} = f;
75 let Inst{3 - 0} = rr{3 - 0};
78 class FTST<bits<4> opcode, bits<2> f, dag outs, dag ins, string asmstr,
79 list<dag> pattern> : AVRInst16<outs, ins, asmstr, pattern> {
82 let Inst{15 - 12} = opcode;
83 let Inst{11 - 10} = f;
86 let Inst{3 - 0} = rd{3 - 0};
89 //===----------------------------------------------------------------------===//
90 // Instruction of the format `<mnemonic> Z, Rd`
91 // <|1001|001r|rrrr|0ttt>
92 //===----------------------------------------------------------------------===//
93 class FZRd<bits<3> t, dag outs, dag ins, string asmstr, list<dag> pattern>
94 : AVRInst16<outs, ins, asmstr, pattern> {
97 let Inst{15 - 12} = 0b1001;
99 let Inst{11 - 9} = 0b001;
102 let Inst{7 - 4} = rd{3 - 0};
108 //===----------------------------------------------------------------------===//
109 // Register / immediate8 instruction: <|opcode|KKKK|dddd|KKKK|>
111 // K = constant data = 8 bits
112 // d = destination = 4 bits
113 // (Only accepts r16-r31)
114 //===----------------------------------------------------------------------===//
115 class FRdK<bits<4> opcode, dag outs, dag ins, string asmstr, list<dag> pattern>
116 : AVRInst16<outs, ins, asmstr, pattern> {
120 let Inst{15 - 12} = opcode;
121 let Inst{11 - 8} = k{7 - 4};
122 let Inst{7 - 4} = rd{3 - 0};
123 let Inst{3 - 0} = k{3 - 0};
125 let isAsCheapAsAMove = 1;
128 //===----------------------------------------------------------------------===//
129 // Register instruction: <|opcode|fffd|dddd|ffff|>
131 // f = secondary opcode = 7 bits
132 // d = destination = 5 bits
133 // (Accepts all registers)
134 //===----------------------------------------------------------------------===//
135 class FRd<bits<4> opcode, bits<7> f, dag outs, dag ins, string asmstr,
136 list<dag> pattern> : AVRInst16<outs, ins, asmstr, pattern> {
139 let Inst{15 - 12} = opcode;
140 let Inst{11 - 9} = f{6 - 4};
141 let Inst{8 - 4} = rd;
142 let Inst{3 - 0} = f{3 - 0};
144 let DecoderMethod = "decodeFRd";
147 //===----------------------------------------------------------------------===//
148 // [STD/LDD] P+q, Rr special encoding: <|10q0|qqtr|rrrr|pqqq>
149 // t = type (1 for STD, 0 for LDD)
150 // q = displacement (6 bits)
151 // r = register (5 bits)
152 // p = pointer register (1 bit) [1 for Y, 0 for Z]
153 //===----------------------------------------------------------------------===//
154 class FSTDLDD<bit type, dag outs, dag ins, string asmstr, list<dag> pattern>
155 : AVRInst16<outs, ins, asmstr, pattern> {
157 bits<5> reg; // the GP register
159 let Inst{15 - 14} = 0b10;
160 let Inst{13} = memri{5};
163 let Inst{11 - 10} = memri{4 - 3};
165 let Inst{8} = reg{4};
167 let Inst{7 - 4} = reg{3 - 0};
169 let Inst{3} = memri{6};
170 let Inst{2 - 0} = memri{2 - 0};
173 //===---------------------------------------------------------------------===//
174 // An ST/LD instruction.
175 // <|100i|00tr|rrrr|ppaa|>
176 // t = type (1 for store, 0 for load)
177 // a = regular/postinc/predec (reg = 0b00, postinc = 0b01, predec = 0b10)
178 // p = pointer register
179 // r = src/dst register
181 // Note that the bit labelled 'i' above does not follow a simple pattern,
182 // so there exists a post encoder method to set it manually. Also a specified
183 // decoder method is needed.
184 //===---------------------------------------------------------------------===//
185 class FSTLD<bit type, bits<2> mode, dag outs, dag ins, string asmstr,
186 list<dag> pattern> : AVRInst16<outs, ins, asmstr, pattern> {
190 let Inst{15 - 13} = 0b100;
191 // This bit varies depending on the arguments and the mode.
192 // We have a post encoder method to set this bit manually.
195 let Inst{11 - 10} = 0b00;
197 let Inst{8} = reg{4};
199 let Inst{7 - 4} = reg{3 - 0};
201 let Inst{3 - 2} = ptrreg{1 - 0};
202 let Inst{1 - 0} = mode{1 - 0};
204 let DecoderMethod = "decodeLoadStore";
205 let PostEncoderMethod = "loadStorePostEncoder";
208 //===---------------------------------------------------------------------===//
209 // Special format for the LPM/ELPM instructions
211 // <|1001|000d|dddd|01ep>
212 // d = destination register
214 // p = is postincrement
215 //===---------------------------------------------------------------------===//
216 class FLPMX<bit e, bit p, dag outs, dag ins, string asmstr, list<dag> pattern>
217 : AVRInst16<outs, ins, asmstr, pattern> {
220 let Inst{15 - 12} = 0b1001;
222 let Inst{11 - 9} = 0b000;
225 let Inst{7 - 4} = rd{3 - 0};
227 let Inst{3 - 2} = 0b01;
231 let DecoderMethod = "decodeFLPMX";
234 //===----------------------------------------------------------------------===//
235 // MOVWRdRr special encoding: <|0000|0001|dddd|rrrr|>
236 // d = destination = 4 bits
237 // r = source = 4 bits
238 // (Only accepts even registers)
239 //===----------------------------------------------------------------------===//
240 class FMOVWRdRr<dag outs, dag ins, string asmstr, list<dag> pattern>
241 : AVRInst16<outs, ins, asmstr, pattern> {
245 let Inst{15 - 8} = 0b00000001;
246 let Inst{7 - 4} = rd{4 - 1};
247 let Inst{3 - 0} = rr{4 - 1};
249 let DecoderMethod = "decodeFMOVWRdRr";
252 //===----------------------------------------------------------------------===//
253 // MULSrr special encoding: <|0000|0010|dddd|rrrr|>
254 // d = multiplicand = 4 bits
255 // r = multiplier = 4 bits
256 // (Only accepts r16-r31)
257 //===----------------------------------------------------------------------===//
258 class FMUL2RdRr<bit f, dag outs, dag ins, string asmstr, list<dag> pattern>
259 : AVRInst16<outs, ins, asmstr, pattern> {
260 bits<5> rd; // accept 5 bits but only encode the lower 4
261 bits<5> rr; // accept 5 bits but only encode the lower 4
263 let Inst{15 - 9} = 0b0000001;
265 let Inst{7 - 4} = rd{3 - 0};
266 let Inst{3 - 0} = rr{3 - 0};
268 let DecoderMethod = "decodeFMUL2RdRr";
271 // Special encoding for the FMUL family of instructions.
273 // <0000|0011|fddd|frrr|>
275 // ff = 0b01 for FMUL
279 // ddd = destination register
280 // rrr = source register
281 class FFMULRdRr<bits<2> f, dag outs, dag ins, string asmstr, list<dag> pattern>
282 : AVRInst16<outs, ins, asmstr, pattern> {
286 let Inst{15 - 8} = 0b00000011;
288 let Inst{6 - 4} = rd;
290 let Inst{2 - 0} = rr;
292 let DecoderMethod = "decodeFFMULRdRr";
295 //===----------------------------------------------------------------------===//
296 // Arithmetic word instructions (ADIW / SBIW): <|1001|011f|kkdd|kkkk|>
297 // f = secondary opcode = 1 bit
298 // k = constant data = 6 bits
299 // d = destination = 2 bits
300 // (Only accepts r25:24 r27:26 r29:28 r31:30)
301 //===----------------------------------------------------------------------===//
302 class FWRdK<bit f, dag outs, dag ins, string asmstr, list<dag> pattern>
303 : AVRInst16<outs, ins, asmstr, pattern> {
304 bits<5> rd; // accept 5 bits but only encode bits 1 and 2
307 let Inst{15 - 9} = 0b1001011;
309 let Inst{7 - 6} = k{5 - 4};
310 let Inst{5 - 4} = rd{2 - 1};
311 let Inst{3 - 0} = k{3 - 0};
313 let DecoderMethod = "decodeFWRdK";
316 //===----------------------------------------------------------------------===//
317 // In I/O instruction: <|1011|0AAd|dddd|AAAA|>
318 // A = I/O location address = 6 bits
319 // d = destination = 5 bits
320 // (Accepts all registers)
321 //===----------------------------------------------------------------------===//
322 class FIORdA<dag outs, dag ins, string asmstr, list<dag> pattern>
323 : AVRInst16<outs, ins, asmstr, pattern> {
327 let Inst{15 - 11} = 0b10110;
328 let Inst{10 - 9} = A{5 - 4};
329 let Inst{8 - 4} = rd;
330 let Inst{3 - 0} = A{3 - 0};
332 let DecoderMethod = "decodeFIORdA";
335 //===----------------------------------------------------------------------===//
336 // Out I/O instruction: <|1011|1AAr|rrrr|AAAA|>
337 // A = I/O location address = 6 bits
338 // d = destination = 5 bits
339 // (Accepts all registers)
340 //===----------------------------------------------------------------------===//
341 class FIOARr<dag outs, dag ins, string asmstr, list<dag> pattern>
342 : AVRInst16<outs, ins, asmstr, pattern> {
346 let Inst{15 - 11} = 0b10111;
347 let Inst{10 - 9} = A{5 - 4};
348 let Inst{8 - 4} = rr;
349 let Inst{3 - 0} = A{3 - 0};
351 let DecoderMethod = "decodeFIOARr";
354 //===----------------------------------------------------------------------===//
355 // I/O bit instruction.
356 // <|1001|10tt|AAAA|Abbb>
357 // t = type (1 for SBI, 0 for CBI)
358 // A = I/O location address (5 bits)
360 //===----------------------------------------------------------------------===//
361 class FIOBIT<bits<2> t, dag outs, dag ins, string asmstr, list<dag> pattern>
362 : AVRInst16<outs, ins, asmstr, pattern> {
366 let Inst{15 - 12} = 0b1001;
368 let Inst{11 - 10} = 0b10;
371 let Inst{7 - 4} = addr{4 - 1};
373 let Inst{3} = addr{0};
374 let Inst{2 - 0} = b{2 - 0};
376 let DecoderMethod = "decodeFIOBIT";
379 //===----------------------------------------------------------------------===//
380 // BST/BLD instruction.
381 // <|1111|1ttd|dddd|0bbb>
382 // t = type (1 for BST, 0 for BLD)
383 // d = destination register
385 //===----------------------------------------------------------------------===//
386 class FRdB<bits<2> t, dag outs, dag ins, string asmstr, list<dag> pattern>
387 : AVRInst16<outs, ins, asmstr, pattern> {
391 let Inst{15 - 12} = 0b1111;
394 let Inst{10 - 9} = t;
397 let Inst{7 - 4} = rd{3 - 0};
403 // Special encoding for the `DES K` instruction.
405 // <|1001|0100|KKKK|1011>
407 // KKKK = 4 bit immediate
408 class FDES<dag outs, dag ins, string asmstr, list<dag> pattern>
409 : AVRInst16<outs, ins, asmstr, pattern> {
412 let Inst{15 - 12} = 0b1001;
414 let Inst{11 - 8} = 0b0100;
418 let Inst{3 - 0} = 0b1011;
421 //===----------------------------------------------------------------------===//
422 // Conditional Branching instructions: <|1111|0fkk|kkkk|ksss|>
423 // f = secondary opcode = 1 bit
424 // k = constant address = 7 bits
425 // s = bit in status register = 3 bits
426 //===----------------------------------------------------------------------===//
427 class FBRsk<bit f, bits<3> s, dag outs, dag ins, string asmstr,
428 list<dag> pattern> : AVRInst16<outs, ins, asmstr, pattern> {
431 let Inst{15 - 11} = 0b11110;
437 //===----------------------------------------------------------------------===//
438 // Special, opcode only instructions: <|opcode|>
439 //===----------------------------------------------------------------------===//
441 class F16<bits<16> opcode, dag outs, dag ins, string asmstr, list<dag> pattern>
442 : AVRInst16<outs, ins, asmstr, pattern> {
446 class F32<bits<32> opcode, dag outs, dag ins, string asmstr, list<dag> pattern>
447 : AVRInst32<outs, ins, asmstr, pattern> {
451 //===----------------------------------------------------------------------===//
452 // Branching instructions with immediate12: <|110f|kkkk|kkkk|kkkk|>
453 // f = secondary opcode = 1 bit
454 // k = constant address = 12 bits
455 //===----------------------------------------------------------------------===//
456 class FBRk<bit f, dag outs, dag ins, string asmstr, list<dag> pattern>
457 : AVRInst16<outs, ins, asmstr, pattern> {
460 let Inst{15 - 13} = 0b110;
462 let Inst{11 - 0} = k;
464 let DecoderMethod = "decodeFBRk";
467 //===----------------------------------------------------------------------===//
468 // 32 bits branching instructions: <|1001|010k|kkkk|fffk|kkkk|kkkk|kkkk|kkkk|>
469 // f = secondary opcode = 3 bits
470 // k = constant address = 22 bits
471 //===----------------------------------------------------------------------===//
472 class F32BRk<bits<3> f, dag outs, dag ins, string asmstr, list<dag> pattern>
473 : AVRInst32<outs, ins, asmstr, pattern> {
476 let Inst{31 - 25} = 0b1001010;
477 let Inst{24 - 20} = k{21 - 17};
478 let Inst{19 - 17} = f;
479 let Inst{16 - 0} = k{16 - 0};
482 //===----------------------------------------------------------------------===//
483 // 32 bits direct mem instructions: <|1001|00fd|dddd|0000|kkkk|kkkk|kkkk|kkkk|>
484 // f = secondary opcode = 1 bit
485 // d = destination = 5 bits
486 // k = constant address = 16 bits
487 // (Accepts all registers)
488 //===----------------------------------------------------------------------===//
489 class F32DM<bit f, dag outs, dag ins, string asmstr, list<dag> pattern>
490 : AVRInst32<outs, ins, asmstr, pattern> {
494 let Inst{31 - 28} = 0b1001;
496 let Inst{27 - 26} = 0b00;
498 let Inst{24} = rd{4};
500 let Inst{23 - 20} = rd{3 - 0};
502 let Inst{19 - 16} = 0b0000;
504 let Inst{15 - 0} = k;
507 //===---------------------------------------------------------------------===//
508 // Special format for the LDS/STS instructions on AVRTiny.
509 // <|1010|ikkk|dddd|kkkk>
511 // i = 0 - lds, 1 - sts
512 // k = 7-bit data space address
513 //===---------------------------------------------------------------------===//
514 class FLDSSTSTINY<bit i, dag outs, dag ins, string asmstr, list<dag> pattern>
515 : AVRInst16<outs, ins, asmstr, pattern> {
519 let Inst{15 - 12} = 0b1010;
523 let Inst{10 - 8} = k{6 - 4};
524 let Inst{7 - 4} = rd{3 - 0};
525 let Inst{3 - 0} = k{3 - 0};
527 let DecoderNamespace = "AVRTiny";
530 // <|1001|0100|bfff|1000>
531 class FS<bit b, dag outs, dag ins, string asmstr, list<dag> pattern>
532 : AVRInst16<outs, ins, asmstr, pattern> {
535 let Inst{15 - 12} = 0b1001;
537 let Inst{11 - 8} = 0b0100;
542 let Inst{3 - 0} = 0b1000;
545 // Set/clr bit in status flag instructions/
547 // ---------------------
548 // <|1111|0fkk|kkkk|ksss>
549 class FSK<bit f, dag outs, dag ins, string asmstr, list<dag> pattern>
550 : AVRInst16<outs, ins, asmstr, pattern> {
554 let Inst{15 - 12} = 0b1111;
558 let Inst{9 - 8} = k{6 - 5};
560 let Inst{7 - 4} = k{4 - 1};
566 class ExtensionPseudo<dag outs, dag ins, string asmstr, list<dag> pattern>
567 : Pseudo<outs, ins, asmstr, pattern> {
571 class StorePseudo<dag outs, dag ins, string asmstr, list<dag> pattern>
572 : Pseudo<outs, ins, asmstr, pattern> {
576 class SelectPseudo<dag outs, dag ins, string asmstr, list<dag> pattern>
577 : Pseudo<outs, ins, asmstr, pattern> {
578 let usesCustomInserter = 1;
583 class ShiftPseudo<dag outs, dag ins, string asmstr, list<dag> pattern>
584 : Pseudo<outs, ins, asmstr, pattern> {
585 let usesCustomInserter = 1;