10b57cec5SDimitry Andric//===-- AVRInstrInfo.td - AVR Instruction Formats ----------*- tablegen -*-===// 20b57cec5SDimitry Andric// 30b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric// 70b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric// 90b57cec5SDimitry Andric// AVR Instruction Format Definitions. 100b57cec5SDimitry Andric// 110b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 120b57cec5SDimitry Andric 130b57cec5SDimitry Andric// A generic AVR instruction. 14349cc55cSDimitry Andricclass AVRInst<dag outs, dag ins, string asmstr, list<dag> pattern> 15349cc55cSDimitry Andric : Instruction { 160b57cec5SDimitry Andric let Namespace = "AVR"; 170b57cec5SDimitry Andric 180b57cec5SDimitry Andric dag OutOperandList = outs; 190b57cec5SDimitry Andric dag InOperandList = ins; 200b57cec5SDimitry Andric let AsmString = asmstr; 210b57cec5SDimitry Andric let Pattern = pattern; 220b57cec5SDimitry Andric 230b57cec5SDimitry Andric field bits<32> SoftFail = 0; 240b57cec5SDimitry Andric} 250b57cec5SDimitry Andric 260b57cec5SDimitry Andric/// A 16-bit AVR instruction. 270b57cec5SDimitry Andricclass AVRInst16<dag outs, dag ins, string asmstr, list<dag> pattern> 28349cc55cSDimitry Andric : AVRInst<outs, ins, asmstr, pattern> { 290b57cec5SDimitry Andric field bits<16> Inst; 300b57cec5SDimitry Andric 310b57cec5SDimitry Andric let Size = 2; 320b57cec5SDimitry Andric} 330b57cec5SDimitry Andric 340b57cec5SDimitry Andric/// a 32-bit AVR instruction. 350b57cec5SDimitry Andricclass AVRInst32<dag outs, dag ins, string asmstr, list<dag> pattern> 36349cc55cSDimitry Andric : AVRInst<outs, ins, asmstr, pattern> { 370b57cec5SDimitry Andric field bits<32> Inst; 380b57cec5SDimitry Andric 390b57cec5SDimitry Andric let Size = 4; 400b57cec5SDimitry Andric} 410b57cec5SDimitry Andric 420b57cec5SDimitry Andric// A class for pseudo instructions. 43480093f4SDimitry Andric// Pseudo instructions are not real AVR instructions. The DAG stores 44480093f4SDimitry Andric// pseudo instructions which are replaced by real AVR instructions by 450b57cec5SDimitry Andric// AVRExpandPseudoInsts.cpp. 460b57cec5SDimitry Andric// 470b57cec5SDimitry Andric// For example, the ADDW (add wide, as in add 16 bit values) instruction 480b57cec5SDimitry Andric// is defined as a pseudo instruction. In AVRExpandPseudoInsts.cpp, 490b57cec5SDimitry Andric// the instruction is then replaced by two add instructions - one for each byte. 500b57cec5SDimitry Andricclass Pseudo<dag outs, dag ins, string asmstr, list<dag> pattern> 51349cc55cSDimitry Andric : AVRInst16<outs, ins, asmstr, pattern> { 520b57cec5SDimitry Andric let Pattern = pattern; 530b57cec5SDimitry Andric 540b57cec5SDimitry Andric let isPseudo = 1; 550b57cec5SDimitry Andric let isCodeGenOnly = 1; 560b57cec5SDimitry Andric} 570b57cec5SDimitry Andric 580b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 590b57cec5SDimitry Andric// Register / register instruction: <|opcode|ffrd|dddd|rrrr|> 600b57cec5SDimitry Andric// opcode = 4 bits. 610b57cec5SDimitry Andric// f = secondary opcode = 2 bits 620b57cec5SDimitry Andric// d = destination = 5 bits 630b57cec5SDimitry Andric// r = source = 5 bits 640b57cec5SDimitry Andric// (Accepts all registers) 650b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 660b57cec5SDimitry Andricclass FRdRr<bits<4> opcode, bits<2> f, dag outs, dag ins, string asmstr, 67349cc55cSDimitry Andric list<dag> pattern> : AVRInst16<outs, ins, asmstr, pattern> { 680b57cec5SDimitry Andric bits<5> rd; 690b57cec5SDimitry Andric bits<5> rr; 700b57cec5SDimitry Andric 710b57cec5SDimitry Andric let Inst{15 - 12} = opcode; 720b57cec5SDimitry Andric let Inst{11 - 10} = f; 730b57cec5SDimitry Andric let Inst{9} = rr{4}; 740b57cec5SDimitry Andric let Inst{8 - 4} = rd; 750b57cec5SDimitry Andric let Inst{3 - 0} = rr{3 - 0}; 760b57cec5SDimitry Andric} 770b57cec5SDimitry Andric 780b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 790b57cec5SDimitry Andric// Instruction of the format `<mnemonic> Z, Rd` 800b57cec5SDimitry Andric// <|1001|001r|rrrr|0ttt> 810b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 820b57cec5SDimitry Andricclass FZRd<bits<3> t, dag outs, dag ins, string asmstr, list<dag> pattern> 83349cc55cSDimitry Andric : AVRInst16<outs, ins, asmstr, pattern> { 840b57cec5SDimitry Andric bits<5> rd; 850b57cec5SDimitry Andric 860b57cec5SDimitry Andric let Inst{15 - 12} = 0b1001; 870b57cec5SDimitry Andric 880b57cec5SDimitry Andric let Inst{11 - 9} = 0b001; 890b57cec5SDimitry Andric let Inst{8} = rd{4}; 900b57cec5SDimitry Andric 910b57cec5SDimitry Andric let Inst{7 - 4} = rd{3 - 0}; 920b57cec5SDimitry Andric 930b57cec5SDimitry Andric let Inst{3} = 0; 940b57cec5SDimitry Andric let Inst{2 - 0} = t; 950b57cec5SDimitry Andric} 960b57cec5SDimitry Andric 970b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 980b57cec5SDimitry Andric// Register / immediate8 instruction: <|opcode|KKKK|dddd|KKKK|> 990b57cec5SDimitry Andric// opcode = 4 bits. 1000b57cec5SDimitry Andric// K = constant data = 8 bits 1010b57cec5SDimitry Andric// d = destination = 4 bits 1020b57cec5SDimitry Andric// (Only accepts r16-r31) 1030b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 1040b57cec5SDimitry Andricclass FRdK<bits<4> opcode, dag outs, dag ins, string asmstr, list<dag> pattern> 105349cc55cSDimitry Andric : AVRInst16<outs, ins, asmstr, pattern> { 1060b57cec5SDimitry Andric bits<4> rd; 1070b57cec5SDimitry Andric bits<8> k; 1080b57cec5SDimitry Andric 1090b57cec5SDimitry Andric let Inst{15 - 12} = opcode; 1100b57cec5SDimitry Andric let Inst{11 - 8} = k{7 - 4}; 1110b57cec5SDimitry Andric let Inst{7 - 4} = rd{3 - 0}; 1120b57cec5SDimitry Andric let Inst{3 - 0} = k{3 - 0}; 1130b57cec5SDimitry Andric 1140b57cec5SDimitry Andric let isAsCheapAsAMove = 1; 1150b57cec5SDimitry Andric} 1160b57cec5SDimitry Andric 1170b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 1180b57cec5SDimitry Andric// Register instruction: <|opcode|fffd|dddd|ffff|> 1190b57cec5SDimitry Andric// opcode = 4 bits. 1200b57cec5SDimitry Andric// f = secondary opcode = 7 bits 1210b57cec5SDimitry Andric// d = destination = 5 bits 1220b57cec5SDimitry Andric// (Accepts all registers) 1230b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 1240b57cec5SDimitry Andricclass FRd<bits<4> opcode, bits<7> f, dag outs, dag ins, string asmstr, 125349cc55cSDimitry Andric list<dag> pattern> : AVRInst16<outs, ins, asmstr, pattern> { 126bdd1243dSDimitry Andric bits<5> rd; 1270b57cec5SDimitry Andric 1280b57cec5SDimitry Andric let Inst{15 - 12} = opcode; 1290b57cec5SDimitry Andric let Inst{11 - 9} = f{6 - 4}; 130bdd1243dSDimitry Andric let Inst{8 - 4} = rd; 1310b57cec5SDimitry Andric let Inst{3 - 0} = f{3 - 0}; 1325ffd83dbSDimitry Andric 1335ffd83dbSDimitry Andric let DecoderMethod = "decodeFRd"; 1340b57cec5SDimitry Andric} 1350b57cec5SDimitry Andric 1360b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 1370b57cec5SDimitry Andric// [STD/LDD] P+q, Rr special encoding: <|10q0|qqtr|rrrr|pqqq> 1380b57cec5SDimitry Andric// t = type (1 for STD, 0 for LDD) 1390b57cec5SDimitry Andric// q = displacement (6 bits) 1400b57cec5SDimitry Andric// r = register (5 bits) 1410b57cec5SDimitry Andric// p = pointer register (1 bit) [1 for Y, 0 for Z] 1420b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 1430b57cec5SDimitry Andricclass FSTDLDD<bit type, dag outs, dag ins, string asmstr, list<dag> pattern> 144349cc55cSDimitry Andric : AVRInst16<outs, ins, asmstr, pattern> { 1450b57cec5SDimitry Andric bits<7> memri; 1460b57cec5SDimitry Andric bits<5> reg; // the GP register 1470b57cec5SDimitry Andric 1480b57cec5SDimitry Andric let Inst{15 - 14} = 0b10; 1490b57cec5SDimitry Andric let Inst{13} = memri{5}; 1500b57cec5SDimitry Andric let Inst{12} = 0; 1510b57cec5SDimitry Andric 1520b57cec5SDimitry Andric let Inst{11 - 10} = memri{4 - 3}; 1530b57cec5SDimitry Andric let Inst{9} = type; 1540b57cec5SDimitry Andric let Inst{8} = reg{4}; 1550b57cec5SDimitry Andric 1560b57cec5SDimitry Andric let Inst{7 - 4} = reg{3 - 0}; 1570b57cec5SDimitry Andric 1580b57cec5SDimitry Andric let Inst{3} = memri{6}; 1590b57cec5SDimitry Andric let Inst{2 - 0} = memri{2 - 0}; 1600b57cec5SDimitry Andric} 1610b57cec5SDimitry Andric 1620b57cec5SDimitry Andric//===---------------------------------------------------------------------===// 1630b57cec5SDimitry Andric// An ST/LD instruction. 1640b57cec5SDimitry Andric// <|100i|00tr|rrrr|ppaa|> 1650b57cec5SDimitry Andric// t = type (1 for store, 0 for load) 1660b57cec5SDimitry Andric// a = regular/postinc/predec (reg = 0b00, postinc = 0b01, predec = 0b10) 1670b57cec5SDimitry Andric// p = pointer register 1680b57cec5SDimitry Andric// r = src/dst register 1690b57cec5SDimitry Andric// 1700b57cec5SDimitry Andric// Note that the bit labelled 'i' above does not follow a simple pattern, 17181ad6265SDimitry Andric// so there exists a post encoder method to set it manually. Also a specified 17281ad6265SDimitry Andric// decoder method is needed. 1730b57cec5SDimitry Andric//===---------------------------------------------------------------------===// 174349cc55cSDimitry Andricclass FSTLD<bit type, bits<2> mode, dag outs, dag ins, string asmstr, 175349cc55cSDimitry Andric list<dag> pattern> : AVRInst16<outs, ins, asmstr, pattern> { 1760b57cec5SDimitry Andric bits<2> ptrreg; 1770b57cec5SDimitry Andric bits<5> reg; 1780b57cec5SDimitry Andric 1790b57cec5SDimitry Andric let Inst{15 - 13} = 0b100; 1800b57cec5SDimitry Andric // This bit varies depending on the arguments and the mode. 1810b57cec5SDimitry Andric // We have a post encoder method to set this bit manually. 1820b57cec5SDimitry Andric let Inst{12} = 0; 1830b57cec5SDimitry Andric 1840b57cec5SDimitry Andric let Inst{11 - 10} = 0b00; 1850b57cec5SDimitry Andric let Inst{9} = type; 1860b57cec5SDimitry Andric let Inst{8} = reg{4}; 1870b57cec5SDimitry Andric 1880b57cec5SDimitry Andric let Inst{7 - 4} = reg{3 - 0}; 1890b57cec5SDimitry Andric 1900b57cec5SDimitry Andric let Inst{3 - 2} = ptrreg{1 - 0}; 1910b57cec5SDimitry Andric let Inst{1 - 0} = mode{1 - 0}; 1920b57cec5SDimitry Andric 19381ad6265SDimitry Andric let DecoderMethod = "decodeLoadStore"; 1940b57cec5SDimitry Andric let PostEncoderMethod = "loadStorePostEncoder"; 1950b57cec5SDimitry Andric} 1960b57cec5SDimitry Andric 1970b57cec5SDimitry Andric//===---------------------------------------------------------------------===// 1980b57cec5SDimitry Andric// Special format for the LPM/ELPM instructions 1990b57cec5SDimitry Andric// [E]LPM Rd, Z[+] 2000b57cec5SDimitry Andric// <|1001|000d|dddd|01ep> 2010b57cec5SDimitry Andric// d = destination register 2020b57cec5SDimitry Andric// e = is elpm 2030b57cec5SDimitry Andric// p = is postincrement 2040b57cec5SDimitry Andric//===---------------------------------------------------------------------===// 2050b57cec5SDimitry Andricclass FLPMX<bit e, bit p, dag outs, dag ins, string asmstr, list<dag> pattern> 206349cc55cSDimitry Andric : AVRInst16<outs, ins, asmstr, pattern> { 207bdd1243dSDimitry Andric bits<5> rd; 2080b57cec5SDimitry Andric 2090b57cec5SDimitry Andric let Inst{15 - 12} = 0b1001; 2100b57cec5SDimitry Andric 2110b57cec5SDimitry Andric let Inst{11 - 9} = 0b000; 212bdd1243dSDimitry Andric let Inst{8} = rd{4}; 2130b57cec5SDimitry Andric 214bdd1243dSDimitry Andric let Inst{7 - 4} = rd{3 - 0}; 2150b57cec5SDimitry Andric 2160b57cec5SDimitry Andric let Inst{3 - 2} = 0b01; 2170b57cec5SDimitry Andric let Inst{1} = e; 2180b57cec5SDimitry Andric let Inst{0} = p; 2195ffd83dbSDimitry Andric 2205ffd83dbSDimitry Andric let DecoderMethod = "decodeFLPMX"; 2210b57cec5SDimitry Andric} 2220b57cec5SDimitry Andric 2230b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 2240b57cec5SDimitry Andric// MOVWRdRr special encoding: <|0000|0001|dddd|rrrr|> 2250b57cec5SDimitry Andric// d = destination = 4 bits 2260b57cec5SDimitry Andric// r = source = 4 bits 2270b57cec5SDimitry Andric// (Only accepts even registers) 2280b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 2290b57cec5SDimitry Andricclass FMOVWRdRr<dag outs, dag ins, string asmstr, list<dag> pattern> 230349cc55cSDimitry Andric : AVRInst16<outs, ins, asmstr, pattern> { 231bdd1243dSDimitry Andric bits<5> rd; 232bdd1243dSDimitry Andric bits<5> rr; 2330b57cec5SDimitry Andric 2340b57cec5SDimitry Andric let Inst{15 - 8} = 0b00000001; 235bdd1243dSDimitry Andric let Inst{7 - 4} = rd{4 - 1}; 236bdd1243dSDimitry Andric let Inst{3 - 0} = rr{4 - 1}; 2375ffd83dbSDimitry Andric 2385ffd83dbSDimitry Andric let DecoderMethod = "decodeFMOVWRdRr"; 2390b57cec5SDimitry Andric} 2400b57cec5SDimitry Andric 2410b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 2420b57cec5SDimitry Andric// MULSrr special encoding: <|0000|0010|dddd|rrrr|> 2430b57cec5SDimitry Andric// d = multiplicand = 4 bits 2440b57cec5SDimitry Andric// r = multiplier = 4 bits 2450b57cec5SDimitry Andric// (Only accepts r16-r31) 2460b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 2470b57cec5SDimitry Andricclass FMUL2RdRr<bit f, dag outs, dag ins, string asmstr, list<dag> pattern> 248349cc55cSDimitry Andric : AVRInst16<outs, ins, asmstr, pattern> { 2490b57cec5SDimitry Andric bits<5> rd; // accept 5 bits but only encode the lower 4 2500b57cec5SDimitry Andric bits<5> rr; // accept 5 bits but only encode the lower 4 2510b57cec5SDimitry Andric 2520b57cec5SDimitry Andric let Inst{15 - 9} = 0b0000001; 2530b57cec5SDimitry Andric let Inst{8} = f; 2540b57cec5SDimitry Andric let Inst{7 - 4} = rd{3 - 0}; 2550b57cec5SDimitry Andric let Inst{3 - 0} = rr{3 - 0}; 2565ffd83dbSDimitry Andric 2575ffd83dbSDimitry Andric let DecoderMethod = "decodeFMUL2RdRr"; 2580b57cec5SDimitry Andric} 2590b57cec5SDimitry Andric 2600b57cec5SDimitry Andric// Special encoding for the FMUL family of instructions. 2610b57cec5SDimitry Andric// 2620b57cec5SDimitry Andric// <0000|0011|fddd|frrr|> 2630b57cec5SDimitry Andric// 2640b57cec5SDimitry Andric// ff = 0b01 for FMUL 2650b57cec5SDimitry Andric// 0b10 for FMULS 2660b57cec5SDimitry Andric// 0b11 for FMULSU 2670b57cec5SDimitry Andric// 2680b57cec5SDimitry Andric// ddd = destination register 2690b57cec5SDimitry Andric// rrr = source register 2700b57cec5SDimitry Andricclass FFMULRdRr<bits<2> f, dag outs, dag ins, string asmstr, list<dag> pattern> 271349cc55cSDimitry Andric : AVRInst16<outs, ins, asmstr, pattern> { 2720b57cec5SDimitry Andric bits<3> rd; 2730b57cec5SDimitry Andric bits<3> rr; 2740b57cec5SDimitry Andric 2750b57cec5SDimitry Andric let Inst{15 - 8} = 0b00000011; 2760b57cec5SDimitry Andric let Inst{7} = f{1}; 2770b57cec5SDimitry Andric let Inst{6 - 4} = rd; 2780b57cec5SDimitry Andric let Inst{3} = f{0}; 2790b57cec5SDimitry Andric let Inst{2 - 0} = rr; 2805ffd83dbSDimitry Andric 2815ffd83dbSDimitry Andric let DecoderMethod = "decodeFFMULRdRr"; 2820b57cec5SDimitry Andric} 2830b57cec5SDimitry Andric 2840b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 2850b57cec5SDimitry Andric// Arithmetic word instructions (ADIW / SBIW): <|1001|011f|kkdd|kkkk|> 2860b57cec5SDimitry Andric// f = secondary opcode = 1 bit 2870b57cec5SDimitry Andric// k = constant data = 6 bits 288bdd1243dSDimitry Andric// d = destination = 2 bits 2890b57cec5SDimitry Andric// (Only accepts r25:24 r27:26 r29:28 r31:30) 2900b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 2910b57cec5SDimitry Andricclass FWRdK<bit f, dag outs, dag ins, string asmstr, list<dag> pattern> 292349cc55cSDimitry Andric : AVRInst16<outs, ins, asmstr, pattern> { 293bdd1243dSDimitry Andric bits<5> rd; // accept 5 bits but only encode bits 1 and 2 2940b57cec5SDimitry Andric bits<6> k; 2950b57cec5SDimitry Andric 2960b57cec5SDimitry Andric let Inst{15 - 9} = 0b1001011; 2970b57cec5SDimitry Andric let Inst{8} = f; 2980b57cec5SDimitry Andric let Inst{7 - 6} = k{5 - 4}; 299bdd1243dSDimitry Andric let Inst{5 - 4} = rd{2 - 1}; 3000b57cec5SDimitry Andric let Inst{3 - 0} = k{3 - 0}; 3015ffd83dbSDimitry Andric 3025ffd83dbSDimitry Andric let DecoderMethod = "decodeFWRdK"; 3030b57cec5SDimitry Andric} 3040b57cec5SDimitry Andric 3050b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 3060b57cec5SDimitry Andric// In I/O instruction: <|1011|0AAd|dddd|AAAA|> 3070b57cec5SDimitry Andric// A = I/O location address = 6 bits 3080b57cec5SDimitry Andric// d = destination = 5 bits 3090b57cec5SDimitry Andric// (Accepts all registers) 3100b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 3110b57cec5SDimitry Andricclass FIORdA<dag outs, dag ins, string asmstr, list<dag> pattern> 312349cc55cSDimitry Andric : AVRInst16<outs, ins, asmstr, pattern> { 313bdd1243dSDimitry Andric bits<5> rd; 3140b57cec5SDimitry Andric bits<6> A; 3150b57cec5SDimitry Andric 3160b57cec5SDimitry Andric let Inst{15 - 11} = 0b10110; 3170b57cec5SDimitry Andric let Inst{10 - 9} = A{5 - 4}; 318bdd1243dSDimitry Andric let Inst{8 - 4} = rd; 3190b57cec5SDimitry Andric let Inst{3 - 0} = A{3 - 0}; 3205ffd83dbSDimitry Andric 3215ffd83dbSDimitry Andric let DecoderMethod = "decodeFIORdA"; 3220b57cec5SDimitry Andric} 3230b57cec5SDimitry Andric 3240b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 3250b57cec5SDimitry Andric// Out I/O instruction: <|1011|1AAr|rrrr|AAAA|> 3260b57cec5SDimitry Andric// A = I/O location address = 6 bits 3270b57cec5SDimitry Andric// d = destination = 5 bits 3280b57cec5SDimitry Andric// (Accepts all registers) 3290b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 3300b57cec5SDimitry Andricclass FIOARr<dag outs, dag ins, string asmstr, list<dag> pattern> 331349cc55cSDimitry Andric : AVRInst16<outs, ins, asmstr, pattern> { 3320b57cec5SDimitry Andric bits<6> A; 333bdd1243dSDimitry Andric bits<5> rr; 3340b57cec5SDimitry Andric 3350b57cec5SDimitry Andric let Inst{15 - 11} = 0b10111; 3360b57cec5SDimitry Andric let Inst{10 - 9} = A{5 - 4}; 337bdd1243dSDimitry Andric let Inst{8 - 4} = rr; 3380b57cec5SDimitry Andric let Inst{3 - 0} = A{3 - 0}; 3395ffd83dbSDimitry Andric 3405ffd83dbSDimitry Andric let DecoderMethod = "decodeFIOARr"; 3410b57cec5SDimitry Andric} 3420b57cec5SDimitry Andric 3430b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 3440b57cec5SDimitry Andric// I/O bit instruction. 3450b57cec5SDimitry Andric// <|1001|10tt|AAAA|Abbb> 3460b57cec5SDimitry Andric// t = type (1 for SBI, 0 for CBI) 3470b57cec5SDimitry Andric// A = I/O location address (5 bits) 3480b57cec5SDimitry Andric// b = bit number 3490b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 3500b57cec5SDimitry Andricclass FIOBIT<bits<2> t, dag outs, dag ins, string asmstr, list<dag> pattern> 351349cc55cSDimitry Andric : AVRInst16<outs, ins, asmstr, pattern> { 352bdd1243dSDimitry Andric bits<5> addr; 3530b57cec5SDimitry Andric bits<3> b; 3540b57cec5SDimitry Andric 3550b57cec5SDimitry Andric let Inst{15 - 12} = 0b1001; 3560b57cec5SDimitry Andric 3570b57cec5SDimitry Andric let Inst{11 - 10} = 0b10; 3580b57cec5SDimitry Andric let Inst{9 - 8} = t; 3590b57cec5SDimitry Andric 360bdd1243dSDimitry Andric let Inst{7 - 4} = addr{4 - 1}; 3610b57cec5SDimitry Andric 362bdd1243dSDimitry Andric let Inst{3} = addr{0}; 3630b57cec5SDimitry Andric let Inst{2 - 0} = b{2 - 0}; 3645ffd83dbSDimitry Andric 3655ffd83dbSDimitry Andric let DecoderMethod = "decodeFIOBIT"; 3660b57cec5SDimitry Andric} 3670b57cec5SDimitry Andric 3680b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 3690b57cec5SDimitry Andric// BST/BLD instruction. 3700b57cec5SDimitry Andric// <|1111|1ttd|dddd|0bbb> 3710b57cec5SDimitry Andric// t = type (1 for BST, 0 for BLD) 3720b57cec5SDimitry Andric// d = destination register 3730b57cec5SDimitry Andric// b = bit 3740b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 3750b57cec5SDimitry Andricclass FRdB<bits<2> t, dag outs, dag ins, string asmstr, list<dag> pattern> 376349cc55cSDimitry Andric : AVRInst16<outs, ins, asmstr, pattern> { 3770b57cec5SDimitry Andric bits<5> rd; 3780b57cec5SDimitry Andric bits<3> b; 3790b57cec5SDimitry Andric 3800b57cec5SDimitry Andric let Inst{15 - 12} = 0b1111; 3810b57cec5SDimitry Andric 3820b57cec5SDimitry Andric let Inst{11} = 0b1; 3830b57cec5SDimitry Andric let Inst{10 - 9} = t; 3840b57cec5SDimitry Andric let Inst{8} = rd{4}; 3850b57cec5SDimitry Andric 3860b57cec5SDimitry Andric let Inst{7 - 4} = rd{3 - 0}; 3870b57cec5SDimitry Andric 3880b57cec5SDimitry Andric let Inst{3} = 0; 3890b57cec5SDimitry Andric let Inst{2 - 0} = b; 3900b57cec5SDimitry Andric} 3910b57cec5SDimitry Andric 3920b57cec5SDimitry Andric// Special encoding for the `DES K` instruction. 3930b57cec5SDimitry Andric// 3940b57cec5SDimitry Andric// <|1001|0100|KKKK|1011> 3950b57cec5SDimitry Andric// 3960b57cec5SDimitry Andric// KKKK = 4 bit immediate 3970b57cec5SDimitry Andricclass FDES<dag outs, dag ins, string asmstr, list<dag> pattern> 398349cc55cSDimitry Andric : AVRInst16<outs, ins, asmstr, pattern> { 3990b57cec5SDimitry Andric bits<4> k; 4000b57cec5SDimitry Andric 4010b57cec5SDimitry Andric let Inst{15 - 12} = 0b1001; 4020b57cec5SDimitry Andric 4030b57cec5SDimitry Andric let Inst{11 - 8} = 0b0100; 4040b57cec5SDimitry Andric 4050b57cec5SDimitry Andric let Inst{7 - 4} = k; 4060b57cec5SDimitry Andric 4070b57cec5SDimitry Andric let Inst{3 - 0} = 0b1011; 4080b57cec5SDimitry Andric} 4090b57cec5SDimitry Andric 4100b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 4110b57cec5SDimitry Andric// Conditional Branching instructions: <|1111|0fkk|kkkk|ksss|> 4120b57cec5SDimitry Andric// f = secondary opcode = 1 bit 4130b57cec5SDimitry Andric// k = constant address = 7 bits 4140b57cec5SDimitry Andric// s = bit in status register = 3 bits 4150b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 416349cc55cSDimitry Andricclass FBRsk<bit f, bits<3> s, dag outs, dag ins, string asmstr, 417349cc55cSDimitry Andric list<dag> pattern> : AVRInst16<outs, ins, asmstr, pattern> { 4180b57cec5SDimitry Andric bits<7> k; 4190b57cec5SDimitry Andric 4200b57cec5SDimitry Andric let Inst{15 - 11} = 0b11110; 4210b57cec5SDimitry Andric let Inst{10} = f; 4220b57cec5SDimitry Andric let Inst{9 - 3} = k; 4230b57cec5SDimitry Andric let Inst{2 - 0} = s; 424*06c3fb27SDimitry Andric 425*06c3fb27SDimitry Andric let DecoderMethod = "decodeCondBranch"; 4260b57cec5SDimitry Andric} 4270b57cec5SDimitry Andric 4280b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 4290b57cec5SDimitry Andric// Special, opcode only instructions: <|opcode|> 4300b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 4310b57cec5SDimitry Andric 4320b57cec5SDimitry Andricclass F16<bits<16> opcode, dag outs, dag ins, string asmstr, list<dag> pattern> 433349cc55cSDimitry Andric : AVRInst16<outs, ins, asmstr, pattern> { 4340b57cec5SDimitry Andric let Inst = opcode; 4350b57cec5SDimitry Andric} 4360b57cec5SDimitry Andric 4370b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 4380b57cec5SDimitry Andric// Branching instructions with immediate12: <|110f|kkkk|kkkk|kkkk|> 4390b57cec5SDimitry Andric// f = secondary opcode = 1 bit 4400b57cec5SDimitry Andric// k = constant address = 12 bits 4410b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 4420b57cec5SDimitry Andricclass FBRk<bit f, dag outs, dag ins, string asmstr, list<dag> pattern> 443349cc55cSDimitry Andric : AVRInst16<outs, ins, asmstr, pattern> { 4440b57cec5SDimitry Andric bits<12> k; 4450b57cec5SDimitry Andric 4460b57cec5SDimitry Andric let Inst{15 - 13} = 0b110; 4470b57cec5SDimitry Andric let Inst{12} = f; 4480b57cec5SDimitry Andric let Inst{11 - 0} = k; 449bdd1243dSDimitry Andric 450bdd1243dSDimitry Andric let DecoderMethod = "decodeFBRk"; 4510b57cec5SDimitry Andric} 4520b57cec5SDimitry Andric 4530b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 4540b57cec5SDimitry Andric// 32 bits branching instructions: <|1001|010k|kkkk|fffk|kkkk|kkkk|kkkk|kkkk|> 4550b57cec5SDimitry Andric// f = secondary opcode = 3 bits 4560b57cec5SDimitry Andric// k = constant address = 22 bits 4570b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 4580b57cec5SDimitry Andricclass F32BRk<bits<3> f, dag outs, dag ins, string asmstr, list<dag> pattern> 459349cc55cSDimitry Andric : AVRInst32<outs, ins, asmstr, pattern> { 4600b57cec5SDimitry Andric bits<22> k; 4610b57cec5SDimitry Andric 4620b57cec5SDimitry Andric let Inst{31 - 25} = 0b1001010; 4630b57cec5SDimitry Andric let Inst{24 - 20} = k{21 - 17}; 4640b57cec5SDimitry Andric let Inst{19 - 17} = f; 4650b57cec5SDimitry Andric let Inst{16 - 0} = k{16 - 0}; 4660b57cec5SDimitry Andric} 4670b57cec5SDimitry Andric 4680b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 4690b57cec5SDimitry Andric// 32 bits direct mem instructions: <|1001|00fd|dddd|0000|kkkk|kkkk|kkkk|kkkk|> 4700b57cec5SDimitry Andric// f = secondary opcode = 1 bit 4710b57cec5SDimitry Andric// d = destination = 5 bits 4720b57cec5SDimitry Andric// k = constant address = 16 bits 4730b57cec5SDimitry Andric// (Accepts all registers) 4740b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 4750b57cec5SDimitry Andricclass F32DM<bit f, dag outs, dag ins, string asmstr, list<dag> pattern> 476349cc55cSDimitry Andric : AVRInst32<outs, ins, asmstr, pattern> { 4770b57cec5SDimitry Andric bits<5> rd; 4780b57cec5SDimitry Andric bits<16> k; 4790b57cec5SDimitry Andric 4800b57cec5SDimitry Andric let Inst{31 - 28} = 0b1001; 4810b57cec5SDimitry Andric 4820b57cec5SDimitry Andric let Inst{27 - 26} = 0b00; 4830b57cec5SDimitry Andric let Inst{25} = f; 4840b57cec5SDimitry Andric let Inst{24} = rd{4}; 4850b57cec5SDimitry Andric 4860b57cec5SDimitry Andric let Inst{23 - 20} = rd{3 - 0}; 4870b57cec5SDimitry Andric 4880b57cec5SDimitry Andric let Inst{19 - 16} = 0b0000; 4890b57cec5SDimitry Andric 4900b57cec5SDimitry Andric let Inst{15 - 0} = k; 4910b57cec5SDimitry Andric} 4920b57cec5SDimitry Andric 493bdd1243dSDimitry Andric//===---------------------------------------------------------------------===// 494bdd1243dSDimitry Andric// Special format for the LDS/STS instructions on AVRTiny. 495bdd1243dSDimitry Andric// <|1010|ikkk|dddd|kkkk> 496bdd1243dSDimitry Andric// d = R16 ~ R31 497bdd1243dSDimitry Andric// i = 0 - lds, 1 - sts 498bdd1243dSDimitry Andric// k = 7-bit data space address 499bdd1243dSDimitry Andric//===---------------------------------------------------------------------===// 500bdd1243dSDimitry Andricclass FLDSSTSTINY<bit i, dag outs, dag ins, string asmstr, list<dag> pattern> 501bdd1243dSDimitry Andric : AVRInst16<outs, ins, asmstr, pattern> { 502bdd1243dSDimitry Andric bits<5> rd; 503bdd1243dSDimitry Andric bits<7> k; 504bdd1243dSDimitry Andric 505bdd1243dSDimitry Andric let Inst{15 - 12} = 0b1010; 506bdd1243dSDimitry Andric 507bdd1243dSDimitry Andric let Inst{11} = i; 508bdd1243dSDimitry Andric 509bdd1243dSDimitry Andric let Inst{10 - 8} = k{6 - 4}; 510bdd1243dSDimitry Andric let Inst{7 - 4} = rd{3 - 0}; 511bdd1243dSDimitry Andric let Inst{3 - 0} = k{3 - 0}; 512bdd1243dSDimitry Andric 513bdd1243dSDimitry Andric let DecoderNamespace = "AVRTiny"; 514bdd1243dSDimitry Andric} 515bdd1243dSDimitry Andric 5160b57cec5SDimitry Andric// <|1001|0100|bfff|1000> 5170b57cec5SDimitry Andricclass FS<bit b, dag outs, dag ins, string asmstr, list<dag> pattern> 518349cc55cSDimitry Andric : AVRInst16<outs, ins, asmstr, pattern> { 5190b57cec5SDimitry Andric bits<3> s; 5200b57cec5SDimitry Andric 5210b57cec5SDimitry Andric let Inst{15 - 12} = 0b1001; 5220b57cec5SDimitry Andric 5230b57cec5SDimitry Andric let Inst{11 - 8} = 0b0100; 5240b57cec5SDimitry Andric 5250b57cec5SDimitry Andric let Inst{7} = b; 5260b57cec5SDimitry Andric let Inst{6 - 4} = s; 5270b57cec5SDimitry Andric 5280b57cec5SDimitry Andric let Inst{3 - 0} = 0b1000; 5290b57cec5SDimitry Andric} 5300b57cec5SDimitry Andric 5310b57cec5SDimitry Andric// Set/clr bit in status flag instructions/ 5320b57cec5SDimitry Andric// <BRBS|BRBC> s, k 5330b57cec5SDimitry Andric// --------------------- 5340b57cec5SDimitry Andric// <|1111|0fkk|kkkk|ksss> 5350b57cec5SDimitry Andricclass FSK<bit f, dag outs, dag ins, string asmstr, list<dag> pattern> 536349cc55cSDimitry Andric : AVRInst16<outs, ins, asmstr, pattern> { 5370b57cec5SDimitry Andric bits<7> k; 5380b57cec5SDimitry Andric bits<3> s; 5390b57cec5SDimitry Andric 5400b57cec5SDimitry Andric let Inst{15 - 12} = 0b1111; 5410b57cec5SDimitry Andric 5420b57cec5SDimitry Andric let Inst{11} = 0; 5430b57cec5SDimitry Andric let Inst{10} = f; 5440b57cec5SDimitry Andric let Inst{9 - 8} = k{6 - 5}; 5450b57cec5SDimitry Andric 5460b57cec5SDimitry Andric let Inst{7 - 4} = k{4 - 1}; 5470b57cec5SDimitry Andric 5480b57cec5SDimitry Andric let Inst{3} = k{0}; 5490b57cec5SDimitry Andric let Inst{2 - 0} = s; 550*06c3fb27SDimitry Andric 551*06c3fb27SDimitry Andric let DecoderMethod = "decodeCondBranch"; 5520b57cec5SDimitry Andric} 5530b57cec5SDimitry Andric 5540b57cec5SDimitry Andricclass ExtensionPseudo<dag outs, dag ins, string asmstr, list<dag> pattern> 555349cc55cSDimitry Andric : Pseudo<outs, ins, asmstr, pattern> { 5560b57cec5SDimitry Andric let Defs = [SREG]; 5570b57cec5SDimitry Andric} 5580b57cec5SDimitry Andric 5590b57cec5SDimitry Andricclass StorePseudo<dag outs, dag ins, string asmstr, list<dag> pattern> 560349cc55cSDimitry Andric : Pseudo<outs, ins, asmstr, pattern> { 5610b57cec5SDimitry Andric let Defs = [SP]; 5620b57cec5SDimitry Andric} 5630b57cec5SDimitry Andric 5640b57cec5SDimitry Andricclass SelectPseudo<dag outs, dag ins, string asmstr, list<dag> pattern> 565349cc55cSDimitry Andric : Pseudo<outs, ins, asmstr, pattern> { 5660b57cec5SDimitry Andric let usesCustomInserter = 1; 5670b57cec5SDimitry Andric 5680b57cec5SDimitry Andric let Uses = [SREG]; 5690b57cec5SDimitry Andric} 5700b57cec5SDimitry Andric 5710b57cec5SDimitry Andricclass ShiftPseudo<dag outs, dag ins, string asmstr, list<dag> pattern> 572349cc55cSDimitry Andric : Pseudo<outs, ins, asmstr, pattern> { 5730b57cec5SDimitry Andric let usesCustomInserter = 1; 5740b57cec5SDimitry Andric 5750b57cec5SDimitry Andric let Defs = [SREG]; 5760b57cec5SDimitry Andric} 577