1 //===-- AVRInstrInfo.td - AVR Instruction Formats ----------*- tablegen -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // AVR Instruction Format Definitions.
12 //===----------------------------------------------------------------------===//
14 // A generic AVR instruction.
15 class AVRInst<dag outs, dag ins, string asmstr, list<dag> pattern> : Instruction
17 let Namespace = "AVR";
19 dag OutOperandList = outs;
20 dag InOperandList = ins;
21 let AsmString = asmstr;
22 let Pattern = pattern;
24 field bits<32> SoftFail = 0;
27 /// A 16-bit AVR instruction.
28 class AVRInst16<dag outs, dag ins, string asmstr, list<dag> pattern>
29 : AVRInst<outs, ins, asmstr, pattern>
36 /// a 32-bit AVR instruction.
37 class AVRInst32<dag outs, dag ins, string asmstr, list<dag> pattern>
38 : AVRInst<outs, ins, asmstr, pattern>
45 // A class for pseudo instructions.
46 // Psuedo instructions are not real AVR instructions. The DAG stores
47 // psuedo instructions which are replaced by real AVR instructions by
48 // AVRExpandPseudoInsts.cpp.
50 // For example, the ADDW (add wide, as in add 16 bit values) instruction
51 // is defined as a pseudo instruction. In AVRExpandPseudoInsts.cpp,
52 // the instruction is then replaced by two add instructions - one for each byte.
53 class Pseudo<dag outs, dag ins, string asmstr, list<dag> pattern>
54 : AVRInst16<outs, ins, asmstr, pattern>
56 let Pattern = pattern;
59 let isCodeGenOnly = 1;
62 //===----------------------------------------------------------------------===//
63 // Register / register instruction: <|opcode|ffrd|dddd|rrrr|>
65 // f = secondary opcode = 2 bits
66 // d = destination = 5 bits
67 // r = source = 5 bits
68 // (Accepts all registers)
69 //===----------------------------------------------------------------------===//
70 class FRdRr<bits<4> opcode, bits<2> f, dag outs, dag ins, string asmstr,
71 list<dag> pattern> : AVRInst16<outs, ins, asmstr, pattern>
76 let Inst{15-12} = opcode;
80 let Inst{3-0} = rr{3-0};
83 class FTST<bits<4> opcode, bits<2> f, dag outs, dag ins, string asmstr,
84 list<dag> pattern> : AVRInst16<outs, ins, asmstr, pattern>
88 let Inst{15-12} = opcode;
92 let Inst{3-0} = rd{3-0};
95 //===----------------------------------------------------------------------===//
96 // Instruction of the format `<mnemonic> Z, Rd`
97 // <|1001|001r|rrrr|0ttt>
98 //===----------------------------------------------------------------------===//
99 class FZRd<bits<3> t, dag outs, dag ins, string asmstr, list<dag> pattern>
100 : AVRInst16<outs, ins, asmstr, pattern>
104 let Inst{15-12} = 0b1001;
106 let Inst{11-9} = 0b001;
109 let Inst{7-4} = rd{3-0};
115 //===----------------------------------------------------------------------===//
116 // Register / immediate8 instruction: <|opcode|KKKK|dddd|KKKK|>
118 // K = constant data = 8 bits
119 // d = destination = 4 bits
120 // (Only accepts r16-r31)
121 //===----------------------------------------------------------------------===//
122 class FRdK<bits<4> opcode, dag outs, dag ins, string asmstr, list<dag> pattern>
123 : AVRInst16<outs, ins, asmstr, pattern>
128 let Inst{15-12} = opcode;
129 let Inst{11-8} = k{7-4};
130 let Inst{7-4} = rd{3-0};
131 let Inst{3-0} = k{3-0};
133 let isAsCheapAsAMove = 1;
136 //===----------------------------------------------------------------------===//
137 // Register instruction: <|opcode|fffd|dddd|ffff|>
139 // f = secondary opcode = 7 bits
140 // d = destination = 5 bits
141 // (Accepts all registers)
142 //===----------------------------------------------------------------------===//
143 class FRd<bits<4> opcode, bits<7> f, dag outs, dag ins, string asmstr,
144 list<dag> pattern> : AVRInst16<outs, ins, asmstr, pattern>
148 let Inst{15-12} = opcode;
149 let Inst{11-9} = f{6-4};
151 let Inst{3-0} = f{3-0};
154 //===----------------------------------------------------------------------===//
155 // [STD/LDD] P+q, Rr special encoding: <|10q0|qqtr|rrrr|pqqq>
156 // t = type (1 for STD, 0 for LDD)
157 // q = displacement (6 bits)
158 // r = register (5 bits)
159 // p = pointer register (1 bit) [1 for Y, 0 for Z]
160 //===----------------------------------------------------------------------===//
161 class FSTDLDD<bit type, dag outs, dag ins, string asmstr, list<dag> pattern>
162 : AVRInst16<outs, ins, asmstr, pattern>
165 bits<5> reg; // the GP register
167 let Inst{15-14} = 0b10;
168 let Inst{13} = memri{5};
171 let Inst{11-10} = memri{4-3};
173 let Inst{8} = reg{4};
175 let Inst{7-4} = reg{3-0};
177 let Inst{3} = memri{6};
178 let Inst{2-0} = memri{2-0};
181 //===---------------------------------------------------------------------===//
182 // An ST/LD instruction.
183 // <|100i|00tr|rrrr|ppaa|>
184 // t = type (1 for store, 0 for load)
185 // a = regular/postinc/predec (reg = 0b00, postinc = 0b01, predec = 0b10)
186 // p = pointer register
187 // r = src/dst register
189 // Note that the bit labelled 'i' above does not follow a simple pattern,
190 // so there exists a post encoder method to set it manually.
191 //===---------------------------------------------------------------------===//
192 class FSTLD<bit type, bits<2> mode, dag outs, dag ins,
193 string asmstr, list<dag> pattern>
194 : AVRInst16<outs, ins, asmstr, pattern>
199 let Inst{15-13} = 0b100;
200 // This bit varies depending on the arguments and the mode.
201 // We have a post encoder method to set this bit manually.
204 let Inst{11-10} = 0b00;
206 let Inst{8} = reg{4};
208 let Inst{7-4} = reg{3-0};
210 let Inst{3-2} = ptrreg{1-0};
211 let Inst{1-0} = mode{1-0};
213 let PostEncoderMethod = "loadStorePostEncoder";
216 //===---------------------------------------------------------------------===//
217 // Special format for the LPM/ELPM instructions
219 // <|1001|000d|dddd|01ep>
220 // d = destination register
222 // p = is postincrement
223 //===---------------------------------------------------------------------===//
224 class FLPMX<bit e, bit p, dag outs, dag ins, string asmstr, list<dag> pattern>
225 : AVRInst16<outs, ins, asmstr, pattern>
229 let Inst{15-12} = 0b1001;
231 let Inst{11-9} = 0b000;
232 let Inst{8} = reg{4};
234 let Inst{7-4} = reg{3-0};
236 let Inst{3-2} = 0b01;
241 //===----------------------------------------------------------------------===//
242 // MOVWRdRr special encoding: <|0000|0001|dddd|rrrr|>
243 // d = destination = 4 bits
244 // r = source = 4 bits
245 // (Only accepts even registers)
246 //===----------------------------------------------------------------------===//
247 class FMOVWRdRr<dag outs, dag ins, string asmstr, list<dag> pattern>
248 : AVRInst16<outs, ins, asmstr, pattern>
253 let Inst{15-8} = 0b00000001;
254 let Inst{7-4} = d{4-1};
255 let Inst{3-0} = r{4-1};
258 //===----------------------------------------------------------------------===//
259 // MULSrr special encoding: <|0000|0010|dddd|rrrr|>
260 // d = multiplicand = 4 bits
261 // r = multiplier = 4 bits
262 // (Only accepts r16-r31)
263 //===----------------------------------------------------------------------===//
264 class FMUL2RdRr<bit f, dag outs, dag ins, string asmstr, list<dag> pattern>
265 : AVRInst16<outs, ins, asmstr, pattern>
267 bits<5> rd; // accept 5 bits but only encode the lower 4
268 bits<5> rr; // accept 5 bits but only encode the lower 4
270 let Inst{15-9} = 0b0000001;
272 let Inst{7-4} = rd{3-0};
273 let Inst{3-0} = rr{3-0};
276 // Special encoding for the FMUL family of instructions.
278 // <0000|0011|fddd|frrr|>
280 // ff = 0b01 for FMUL
284 // ddd = destination register
285 // rrr = source register
286 class FFMULRdRr<bits<2> f, dag outs, dag ins, string asmstr, list<dag> pattern>
287 : AVRInst16<outs, ins, asmstr, pattern>
292 let Inst{15-8} = 0b00000011;
300 //===----------------------------------------------------------------------===//
301 // Arithmetic word instructions (ADIW / SBIW): <|1001|011f|kkdd|kkkk|>
302 // f = secondary opcode = 1 bit
303 // k = constant data = 6 bits
304 // d = destination = 4 bits
305 // (Only accepts r25:24 r27:26 r29:28 r31:30)
306 //===----------------------------------------------------------------------===//
307 class FWRdK<bit f, dag outs, dag ins, string asmstr, list<dag> pattern>
308 : AVRInst16<outs, ins, asmstr, pattern>
310 bits<5> dst; // accept 5 bits but only encode bits 1 and 2
313 let Inst{15-9} = 0b1001011;
315 let Inst{7-6} = k{5-4};
316 let Inst{5-4} = dst{2-1};
317 let Inst{3-0} = k{3-0};
320 //===----------------------------------------------------------------------===//
321 // In I/O instruction: <|1011|0AAd|dddd|AAAA|>
322 // A = I/O location address = 6 bits
323 // d = destination = 5 bits
324 // (Accepts all registers)
325 //===----------------------------------------------------------------------===//
326 class FIORdA<dag outs, dag ins, string asmstr, list<dag> pattern>
327 : AVRInst16<outs, ins, asmstr, pattern>
332 let Inst{15-11} = 0b10110;
333 let Inst{10-9} = A{5-4};
335 let Inst{3-0} = A{3-0};
338 //===----------------------------------------------------------------------===//
339 // Out I/O instruction: <|1011|1AAr|rrrr|AAAA|>
340 // A = I/O location address = 6 bits
341 // d = destination = 5 bits
342 // (Accepts all registers)
343 //===----------------------------------------------------------------------===//
344 class FIOARr<dag outs, dag ins, string asmstr, list<dag> pattern>
345 : AVRInst16<outs, ins, asmstr, pattern>
350 let Inst{15-11} = 0b10111;
351 let Inst{10-9} = A{5-4};
353 let Inst{3-0} = A{3-0};
356 //===----------------------------------------------------------------------===//
357 // I/O bit instruction.
358 // <|1001|10tt|AAAA|Abbb>
359 // t = type (1 for SBI, 0 for CBI)
360 // A = I/O location address (5 bits)
362 //===----------------------------------------------------------------------===//
363 class FIOBIT<bits<2> t, dag outs, dag ins, string asmstr, list<dag> pattern>
364 : AVRInst16<outs, ins, asmstr, pattern>
369 let Inst{15-12} = 0b1001;
371 let Inst{11-10} = 0b10;
374 let Inst{7-4} = A{4-1};
377 let Inst{2-0} = b{2-0};
380 //===----------------------------------------------------------------------===//
381 // BST/BLD instruction.
382 // <|1111|1ttd|dddd|0bbb>
383 // t = type (1 for BST, 0 for BLD)
384 // d = destination register
386 //===----------------------------------------------------------------------===//
387 class FRdB<bits<2> t, dag outs, dag ins, string asmstr, list<dag> pattern>
388 : AVRInst16<outs, ins, asmstr, pattern>
393 let Inst{15-12} = 0b1111;
399 let Inst{7-4} = rd{3-0};
405 // Special encoding for the `DES K` instruction.
407 // <|1001|0100|KKKK|1011>
409 // KKKK = 4 bit immediate
410 class FDES<dag outs, dag ins, string asmstr, list<dag> pattern>
411 : AVRInst16<outs, ins, asmstr, pattern>
415 let Inst{15-12} = 0b1001;
417 let Inst{11-8} = 0b0100;
421 let Inst{3-0} = 0b1011;
424 //===----------------------------------------------------------------------===//
425 // Conditional Branching instructions: <|1111|0fkk|kkkk|ksss|>
426 // f = secondary opcode = 1 bit
427 // k = constant address = 7 bits
428 // s = bit in status register = 3 bits
429 //===----------------------------------------------------------------------===//
430 class FBRsk<bit f, bits<3> s, dag outs, dag ins, string asmstr, list<dag> pattern>
431 : AVRInst16<outs, ins, asmstr, pattern>
435 let Inst{15-11} = 0b11110;
441 //===----------------------------------------------------------------------===//
442 // Special, opcode only instructions: <|opcode|>
443 //===----------------------------------------------------------------------===//
445 class F16<bits<16> opcode, dag outs, dag ins, string asmstr, list<dag> pattern>
446 : AVRInst16<outs, ins, asmstr, pattern>
451 class F32<bits<32> opcode, dag outs, dag ins, string asmstr, list<dag> pattern>
452 : AVRInst32<outs, ins, asmstr, pattern>
457 //===----------------------------------------------------------------------===//
458 // Branching instructions with immediate12: <|110f|kkkk|kkkk|kkkk|>
459 // f = secondary opcode = 1 bit
460 // k = constant address = 12 bits
461 //===----------------------------------------------------------------------===//
462 class FBRk<bit f, dag outs, dag ins, string asmstr, list<dag> pattern>
463 : AVRInst16<outs, ins, asmstr, pattern>
467 let Inst{15-13} = 0b110;
472 //===----------------------------------------------------------------------===//
473 // 32 bits branching instructions: <|1001|010k|kkkk|fffk|kkkk|kkkk|kkkk|kkkk|>
474 // f = secondary opcode = 3 bits
475 // k = constant address = 22 bits
476 //===----------------------------------------------------------------------===//
477 class F32BRk<bits<3> f, dag outs, dag ins, string asmstr, list<dag> pattern>
478 : AVRInst32<outs, ins, asmstr, pattern>
482 let Inst{31-25} = 0b1001010;
483 let Inst{24-20} = k{21-17};
485 let Inst{16-0} = k{16-0};
488 //===----------------------------------------------------------------------===//
489 // 32 bits direct mem instructions: <|1001|00fd|dddd|0000|kkkk|kkkk|kkkk|kkkk|>
490 // f = secondary opcode = 1 bit
491 // d = destination = 5 bits
492 // k = constant address = 16 bits
493 // (Accepts all registers)
494 //===----------------------------------------------------------------------===//
495 class F32DM<bit f, dag outs, dag ins, string asmstr, list<dag> pattern>
496 : AVRInst32<outs, ins, asmstr, pattern>
501 let Inst{31-28} = 0b1001;
503 let Inst{27-26} = 0b00;
505 let Inst{24} = rd{4};
507 let Inst{23-20} = rd{3-0};
509 let Inst{19-16} = 0b0000;
514 // <|1001|0100|bfff|1000>
515 class FS<bit b, dag outs, dag ins, string asmstr, list<dag> pattern>
516 : AVRInst16<outs, ins, asmstr, pattern>
520 let Inst{15-12} = 0b1001;
522 let Inst{11-8} = 0b0100;
527 let Inst{3-0} = 0b1000;
530 // Set/clr bit in status flag instructions/
532 // ---------------------
533 // <|1111|0fkk|kkkk|ksss>
534 class FSK<bit f, dag outs, dag ins, string asmstr, list<dag> pattern>
535 : AVRInst16<outs, ins, asmstr, pattern>
540 let Inst{15-12} = 0b1111;
544 let Inst{9-8} = k{6-5};
546 let Inst{7-4} = k{4-1};
552 class ExtensionPseudo<dag outs, dag ins, string asmstr, list<dag> pattern>
553 : Pseudo<outs, ins, asmstr, pattern>
558 class StorePseudo<dag outs, dag ins, string asmstr, list<dag> pattern>
559 : Pseudo<outs, ins, asmstr, pattern>
564 class SelectPseudo<dag outs, dag ins, string asmstr, list<dag> pattern>
565 : Pseudo<outs, ins, asmstr, pattern>
567 let usesCustomInserter = 1;
572 class ShiftPseudo<dag outs, dag ins, string asmstr, list<dag> pattern>
573 : Pseudo<outs, ins, asmstr, pattern>
575 let usesCustomInserter = 1;