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> : Instruction
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>
35 /// a 32-bit AVR instruction.
36 class AVRInst32<dag outs, dag ins, string asmstr, list<dag> pattern>
37 : AVRInst<outs, ins, asmstr, pattern>
44 // A class for pseudo instructions.
45 // Pseudo instructions are not real AVR instructions. The DAG stores
46 // pseudo instructions which are replaced by real AVR instructions by
47 // AVRExpandPseudoInsts.cpp.
49 // For example, the ADDW (add wide, as in add 16 bit values) instruction
50 // is defined as a pseudo instruction. In AVRExpandPseudoInsts.cpp,
51 // the instruction is then replaced by two add instructions - one for each byte.
52 class Pseudo<dag outs, dag ins, string asmstr, list<dag> pattern>
53 : AVRInst16<outs, ins, asmstr, pattern>
55 let Pattern = pattern;
58 let isCodeGenOnly = 1;
61 //===----------------------------------------------------------------------===//
62 // Register / register instruction: <|opcode|ffrd|dddd|rrrr|>
64 // f = secondary opcode = 2 bits
65 // d = destination = 5 bits
66 // r = source = 5 bits
67 // (Accepts all registers)
68 //===----------------------------------------------------------------------===//
69 class FRdRr<bits<4> opcode, bits<2> f, dag outs, dag ins, string asmstr,
70 list<dag> pattern> : AVRInst16<outs, ins, asmstr, pattern>
75 let Inst{15-12} = opcode;
79 let Inst{3-0} = rr{3-0};
82 class FTST<bits<4> opcode, bits<2> f, dag outs, dag ins, string asmstr,
83 list<dag> pattern> : AVRInst16<outs, ins, asmstr, pattern>
87 let Inst{15-12} = opcode;
91 let Inst{3-0} = rd{3-0};
94 //===----------------------------------------------------------------------===//
95 // Instruction of the format `<mnemonic> Z, Rd`
96 // <|1001|001r|rrrr|0ttt>
97 //===----------------------------------------------------------------------===//
98 class FZRd<bits<3> t, dag outs, dag ins, string asmstr, list<dag> pattern>
99 : AVRInst16<outs, ins, asmstr, pattern>
103 let Inst{15-12} = 0b1001;
105 let Inst{11-9} = 0b001;
108 let Inst{7-4} = rd{3-0};
114 //===----------------------------------------------------------------------===//
115 // Register / immediate8 instruction: <|opcode|KKKK|dddd|KKKK|>
117 // K = constant data = 8 bits
118 // d = destination = 4 bits
119 // (Only accepts r16-r31)
120 //===----------------------------------------------------------------------===//
121 class FRdK<bits<4> opcode, dag outs, dag ins, string asmstr, list<dag> pattern>
122 : AVRInst16<outs, ins, asmstr, pattern>
127 let Inst{15-12} = opcode;
128 let Inst{11-8} = k{7-4};
129 let Inst{7-4} = rd{3-0};
130 let Inst{3-0} = k{3-0};
132 let isAsCheapAsAMove = 1;
135 //===----------------------------------------------------------------------===//
136 // Register instruction: <|opcode|fffd|dddd|ffff|>
138 // f = secondary opcode = 7 bits
139 // d = destination = 5 bits
140 // (Accepts all registers)
141 //===----------------------------------------------------------------------===//
142 class FRd<bits<4> opcode, bits<7> f, dag outs, dag ins, string asmstr,
143 list<dag> pattern> : AVRInst16<outs, ins, asmstr, pattern>
147 let Inst{15-12} = opcode;
148 let Inst{11-9} = f{6-4};
150 let Inst{3-0} = f{3-0};
152 let DecoderMethod = "decodeFRd";
155 //===----------------------------------------------------------------------===//
156 // [STD/LDD] P+q, Rr special encoding: <|10q0|qqtr|rrrr|pqqq>
157 // t = type (1 for STD, 0 for LDD)
158 // q = displacement (6 bits)
159 // r = register (5 bits)
160 // p = pointer register (1 bit) [1 for Y, 0 for Z]
161 //===----------------------------------------------------------------------===//
162 class FSTDLDD<bit type, dag outs, dag ins, string asmstr, list<dag> pattern>
163 : AVRInst16<outs, ins, asmstr, pattern>
166 bits<5> reg; // the GP register
168 let Inst{15-14} = 0b10;
169 let Inst{13} = memri{5};
172 let Inst{11-10} = memri{4-3};
174 let Inst{8} = reg{4};
176 let Inst{7-4} = reg{3-0};
178 let Inst{3} = memri{6};
179 let Inst{2-0} = memri{2-0};
182 //===---------------------------------------------------------------------===//
183 // An ST/LD instruction.
184 // <|100i|00tr|rrrr|ppaa|>
185 // t = type (1 for store, 0 for load)
186 // a = regular/postinc/predec (reg = 0b00, postinc = 0b01, predec = 0b10)
187 // p = pointer register
188 // r = src/dst register
190 // Note that the bit labelled 'i' above does not follow a simple pattern,
191 // so there exists a post encoder method to set it manually.
192 //===---------------------------------------------------------------------===//
193 class FSTLD<bit type, bits<2> mode, dag outs, dag ins,
194 string asmstr, list<dag> pattern>
195 : AVRInst16<outs, ins, asmstr, pattern>
200 let Inst{15-13} = 0b100;
201 // This bit varies depending on the arguments and the mode.
202 // We have a post encoder method to set this bit manually.
205 let Inst{11-10} = 0b00;
207 let Inst{8} = reg{4};
209 let Inst{7-4} = reg{3-0};
211 let Inst{3-2} = ptrreg{1-0};
212 let Inst{1-0} = mode{1-0};
214 let PostEncoderMethod = "loadStorePostEncoder";
217 //===---------------------------------------------------------------------===//
218 // Special format for the LPM/ELPM instructions
220 // <|1001|000d|dddd|01ep>
221 // d = destination register
223 // p = is postincrement
224 //===---------------------------------------------------------------------===//
225 class FLPMX<bit e, bit p, dag outs, dag ins, string asmstr, list<dag> pattern>
226 : AVRInst16<outs, ins, asmstr, pattern>
230 let Inst{15-12} = 0b1001;
232 let Inst{11-9} = 0b000;
233 let Inst{8} = reg{4};
235 let Inst{7-4} = reg{3-0};
237 let Inst{3-2} = 0b01;
241 let DecoderMethod = "decodeFLPMX";
244 //===----------------------------------------------------------------------===//
245 // MOVWRdRr special encoding: <|0000|0001|dddd|rrrr|>
246 // d = destination = 4 bits
247 // r = source = 4 bits
248 // (Only accepts even registers)
249 //===----------------------------------------------------------------------===//
250 class FMOVWRdRr<dag outs, dag ins, string asmstr, list<dag> pattern>
251 : AVRInst16<outs, ins, asmstr, pattern>
256 let Inst{15-8} = 0b00000001;
257 let Inst{7-4} = d{4-1};
258 let Inst{3-0} = r{4-1};
260 let DecoderMethod = "decodeFMOVWRdRr";
263 //===----------------------------------------------------------------------===//
264 // MULSrr special encoding: <|0000|0010|dddd|rrrr|>
265 // d = multiplicand = 4 bits
266 // r = multiplier = 4 bits
267 // (Only accepts r16-r31)
268 //===----------------------------------------------------------------------===//
269 class FMUL2RdRr<bit f, dag outs, dag ins, string asmstr, list<dag> pattern>
270 : AVRInst16<outs, ins, asmstr, pattern>
272 bits<5> rd; // accept 5 bits but only encode the lower 4
273 bits<5> rr; // accept 5 bits but only encode the lower 4
275 let Inst{15-9} = 0b0000001;
277 let Inst{7-4} = rd{3-0};
278 let Inst{3-0} = rr{3-0};
280 let DecoderMethod = "decodeFMUL2RdRr";
283 // Special encoding for the FMUL family of instructions.
285 // <0000|0011|fddd|frrr|>
287 // ff = 0b01 for FMUL
291 // ddd = destination register
292 // rrr = source register
293 class FFMULRdRr<bits<2> f, dag outs, dag ins, string asmstr, list<dag> pattern>
294 : AVRInst16<outs, ins, asmstr, pattern>
299 let Inst{15-8} = 0b00000011;
305 let DecoderMethod = "decodeFFMULRdRr";
309 //===----------------------------------------------------------------------===//
310 // Arithmetic word instructions (ADIW / SBIW): <|1001|011f|kkdd|kkkk|>
311 // f = secondary opcode = 1 bit
312 // k = constant data = 6 bits
313 // d = destination = 4 bits
314 // (Only accepts r25:24 r27:26 r29:28 r31:30)
315 //===----------------------------------------------------------------------===//
316 class FWRdK<bit f, dag outs, dag ins, string asmstr, list<dag> pattern>
317 : AVRInst16<outs, ins, asmstr, pattern>
319 bits<5> dst; // accept 5 bits but only encode bits 1 and 2
322 let Inst{15-9} = 0b1001011;
324 let Inst{7-6} = k{5-4};
325 let Inst{5-4} = dst{2-1};
326 let Inst{3-0} = k{3-0};
328 let DecoderMethod = "decodeFWRdK";
331 //===----------------------------------------------------------------------===//
332 // In I/O instruction: <|1011|0AAd|dddd|AAAA|>
333 // A = I/O location address = 6 bits
334 // d = destination = 5 bits
335 // (Accepts all registers)
336 //===----------------------------------------------------------------------===//
337 class FIORdA<dag outs, dag ins, string asmstr, list<dag> pattern>
338 : AVRInst16<outs, ins, asmstr, pattern>
343 let Inst{15-11} = 0b10110;
344 let Inst{10-9} = A{5-4};
346 let Inst{3-0} = A{3-0};
348 let DecoderMethod = "decodeFIORdA";
351 //===----------------------------------------------------------------------===//
352 // Out I/O instruction: <|1011|1AAr|rrrr|AAAA|>
353 // A = I/O location address = 6 bits
354 // d = destination = 5 bits
355 // (Accepts all registers)
356 //===----------------------------------------------------------------------===//
357 class FIOARr<dag outs, dag ins, string asmstr, list<dag> pattern>
358 : AVRInst16<outs, ins, asmstr, pattern>
363 let Inst{15-11} = 0b10111;
364 let Inst{10-9} = A{5-4};
366 let Inst{3-0} = A{3-0};
368 let DecoderMethod = "decodeFIOARr";
371 //===----------------------------------------------------------------------===//
372 // I/O bit instruction.
373 // <|1001|10tt|AAAA|Abbb>
374 // t = type (1 for SBI, 0 for CBI)
375 // A = I/O location address (5 bits)
377 //===----------------------------------------------------------------------===//
378 class FIOBIT<bits<2> t, dag outs, dag ins, string asmstr, list<dag> pattern>
379 : AVRInst16<outs, ins, asmstr, pattern>
384 let Inst{15-12} = 0b1001;
386 let Inst{11-10} = 0b10;
389 let Inst{7-4} = A{4-1};
392 let Inst{2-0} = b{2-0};
394 let DecoderMethod = "decodeFIOBIT";
397 //===----------------------------------------------------------------------===//
398 // BST/BLD instruction.
399 // <|1111|1ttd|dddd|0bbb>
400 // t = type (1 for BST, 0 for BLD)
401 // d = destination register
403 //===----------------------------------------------------------------------===//
404 class FRdB<bits<2> t, dag outs, dag ins, string asmstr, list<dag> pattern>
405 : AVRInst16<outs, ins, asmstr, pattern>
410 let Inst{15-12} = 0b1111;
416 let Inst{7-4} = rd{3-0};
422 // Special encoding for the `DES K` instruction.
424 // <|1001|0100|KKKK|1011>
426 // KKKK = 4 bit immediate
427 class FDES<dag outs, dag ins, string asmstr, list<dag> pattern>
428 : AVRInst16<outs, ins, asmstr, pattern>
432 let Inst{15-12} = 0b1001;
434 let Inst{11-8} = 0b0100;
438 let Inst{3-0} = 0b1011;
441 //===----------------------------------------------------------------------===//
442 // Conditional Branching instructions: <|1111|0fkk|kkkk|ksss|>
443 // f = secondary opcode = 1 bit
444 // k = constant address = 7 bits
445 // s = bit in status register = 3 bits
446 //===----------------------------------------------------------------------===//
447 class FBRsk<bit f, bits<3> s, dag outs, dag ins, string asmstr, list<dag> pattern>
448 : AVRInst16<outs, ins, asmstr, pattern>
452 let Inst{15-11} = 0b11110;
458 //===----------------------------------------------------------------------===//
459 // Special, opcode only instructions: <|opcode|>
460 //===----------------------------------------------------------------------===//
462 class F16<bits<16> opcode, dag outs, dag ins, string asmstr, list<dag> pattern>
463 : AVRInst16<outs, ins, asmstr, pattern>
468 class F32<bits<32> opcode, dag outs, dag ins, string asmstr, list<dag> pattern>
469 : AVRInst32<outs, ins, asmstr, pattern>
474 //===----------------------------------------------------------------------===//
475 // Branching instructions with immediate12: <|110f|kkkk|kkkk|kkkk|>
476 // f = secondary opcode = 1 bit
477 // k = constant address = 12 bits
478 //===----------------------------------------------------------------------===//
479 class FBRk<bit f, dag outs, dag ins, string asmstr, list<dag> pattern>
480 : AVRInst16<outs, ins, asmstr, pattern>
484 let Inst{15-13} = 0b110;
489 //===----------------------------------------------------------------------===//
490 // 32 bits branching instructions: <|1001|010k|kkkk|fffk|kkkk|kkkk|kkkk|kkkk|>
491 // f = secondary opcode = 3 bits
492 // k = constant address = 22 bits
493 //===----------------------------------------------------------------------===//
494 class F32BRk<bits<3> f, dag outs, dag ins, string asmstr, list<dag> pattern>
495 : AVRInst32<outs, ins, asmstr, pattern>
499 let Inst{31-25} = 0b1001010;
500 let Inst{24-20} = k{21-17};
502 let Inst{16-0} = k{16-0};
505 //===----------------------------------------------------------------------===//
506 // 32 bits direct mem instructions: <|1001|00fd|dddd|0000|kkkk|kkkk|kkkk|kkkk|>
507 // f = secondary opcode = 1 bit
508 // d = destination = 5 bits
509 // k = constant address = 16 bits
510 // (Accepts all registers)
511 //===----------------------------------------------------------------------===//
512 class F32DM<bit f, dag outs, dag ins, string asmstr, list<dag> pattern>
513 : AVRInst32<outs, ins, asmstr, pattern>
518 let Inst{31-28} = 0b1001;
520 let Inst{27-26} = 0b00;
522 let Inst{24} = rd{4};
524 let Inst{23-20} = rd{3-0};
526 let Inst{19-16} = 0b0000;
531 // <|1001|0100|bfff|1000>
532 class FS<bit b, dag outs, dag ins, string asmstr, list<dag> pattern>
533 : AVRInst16<outs, ins, asmstr, pattern>
537 let Inst{15-12} = 0b1001;
539 let Inst{11-8} = 0b0100;
544 let Inst{3-0} = 0b1000;
547 // Set/clr bit in status flag instructions/
549 // ---------------------
550 // <|1111|0fkk|kkkk|ksss>
551 class FSK<bit f, dag outs, dag ins, string asmstr, list<dag> pattern>
552 : AVRInst16<outs, ins, asmstr, pattern>
557 let Inst{15-12} = 0b1111;
561 let Inst{9-8} = k{6-5};
563 let Inst{7-4} = k{4-1};
569 class ExtensionPseudo<dag outs, dag ins, string asmstr, list<dag> pattern>
570 : Pseudo<outs, ins, asmstr, pattern>
575 class StorePseudo<dag outs, dag ins, string asmstr, list<dag> pattern>
576 : Pseudo<outs, ins, asmstr, pattern>
581 class SelectPseudo<dag outs, dag ins, string asmstr, list<dag> pattern>
582 : Pseudo<outs, ins, asmstr, pattern>
584 let usesCustomInserter = 1;
589 class ShiftPseudo<dag outs, dag ins, string asmstr, list<dag> pattern>
590 : Pseudo<outs, ins, asmstr, pattern>
592 let usesCustomInserter = 1;