1 //===-- CSKYInstrFormats.td - CSKY 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 class AddrMode<bits<5> val> {
13 def AddrModeNone : AddrMode<0>;
14 def AddrMode32B : AddrMode<1>; // ld32.b, ld32.bs, st32.b, st32.bs, +4kb
15 def AddrMode32H : AddrMode<2>; // ld32.h, ld32.hs, st32.h, st32.hs, +8kb
16 def AddrMode32WD : AddrMode<3>; // ld32.w, st32.w, ld32.d, st32.d, +16kb
17 def AddrMode16B : AddrMode<4>; // ld16.b, +32b
18 def AddrMode16H : AddrMode<5>; // ld16.h, +64b
19 def AddrMode16W : AddrMode<6>; // ld16.w, +128b or +1kb
20 def AddrMode32SDF : AddrMode<7>; // flds, fldd, +1kb
22 class CSKYInst<AddrMode am, int sz, dag outs, dag ins, string asmstr,
23 list<dag> pattern> : Instruction {
24 let Namespace = "CSKY";
28 let OutOperandList = outs;
29 let InOperandList = ins;
30 let AsmString = asmstr;
31 let Pattern = pattern;
32 let Itinerary = NoItinerary;
33 let TSFlags{4 - 0} = AM.Value;
36 class CSKYPseudo<dag outs, dag ins, string asmstr, list<dag> pattern>
37 : CSKYInst<AddrModeNone, 0, outs, ins, asmstr, pattern> {
38 let isCodeGenOnly = 1;
42 class CSKY32Inst<AddrMode am, bits<6> opcode, dag outs, dag ins, string asmstr,
44 : CSKYInst<am, 4, outs, ins, asmstr, pattern> {
46 let Inst{31 - 26} = opcode;
49 // CSKY 32-bit instruction
50 // Format< OP[6] | Offset[26] >
51 // Instruction(1): bsr32
52 class J<bits<6> opcode, dag outs, dag ins, string op, list<dag> pattern>
53 : CSKY32Inst<AddrModeNone, opcode, outs, ins, !strconcat(op, "\t$offset"),
56 let Inst{25 - 0} = offset;
61 // Format< OP[6] | RZ[5] | SOP[3] | OFFSET[18] >
62 // Instructions(7): grs, lrs32.b, lrs32.h, lrs32.w, srs32.b, srs32.h, srs32.w
63 class I_18_Z_L<bits<3> sop, string asm, dag outs, dag ins, list<dag> pattern>
64 : CSKY32Inst<AddrModeNone, 0x33, outs, ins, asm, pattern> {
67 let Inst{25 - 21} = rz;
68 let Inst{20 - 18} = sop;
69 let Inst{17 - 0} = offset;
72 // Format< OP[6] | RZ[5] | RX[5] | IMM[16] >
73 // Instructions(1): ori32
74 class I_16_ZX<string op, ImmLeaf ImmType, list<dag> pattern>
75 : CSKY32Inst<AddrModeNone, 0x3b,
76 (outs GPR:$rz), (ins GPR:$rx,ImmType:$imm16),
77 !strconcat(op, "\t$rz, $rx, $imm16"), pattern> {
81 let Inst{25 - 21} = rz;
82 let Inst{20 - 16} = rx;
83 let Inst{15 - 0} = imm16;
86 // Format< OP[6] | SOP[5] | RZ[5] | IMM[16] >
87 // Instructions(3): movi32, movih32, (bgeni32)
88 class I_16_MOV<bits<5> sop, string op, ImmLeaf ImmType>
89 : CSKY32Inst<AddrModeNone, 0x3a, (outs GPR:$rz), (ins ImmType:$imm16),
90 !strconcat(op, "\t$rz, $imm16"),
91 [(set GPR:$rz, ImmType:$imm16)]> {
94 let Inst{25 - 21} = sop;
95 let Inst{20 - 16} = rz;
96 let Inst{15 - 0} = imm16;
97 let isReMaterializable = 1;
98 let isAsCheapAsAMove = 1;
102 // Format< OP[6] | SOP[5] | RZ[5] | OFFSET[16] >
103 // Instructions(1): lrw32
104 class I_16_Z_L<bits<5> sop, string op, dag ins, list<dag> pattern>
105 : CSKY32Inst<AddrModeNone, 0x3a, (outs GPR:$rz), ins,
106 !strconcat(op, "\t$rz, $imm16"), pattern> {
109 let Inst{25 - 21} = sop;
110 let Inst{20 - 16} = rz;
111 let Inst{15 - 0} = imm16;
114 // Format< OP[6] | SOP[5] | 00000[5] | OFFSET[16] >
115 // Instructions(5): bt32, bf32, br32, jmpi32, jsri32
116 class I_16_L<bits<5> sop, dag outs, dag ins, string asm, list<dag> pattern>
117 : CSKY32Inst<AddrModeNone, 0x3a, outs, ins, asm, pattern> {
119 let Inst{25 - 21} = sop;
120 let Inst{20 - 16} = 0;
121 let Inst{15 - 0} = imm16;
124 // Format< OP[6] | SOP[5] | RX[5] | 0000000000000000[16] >
125 // Instructions(2): jmp32, jsr32
126 class I_16_JX<bits<5> sop, string op, list<dag> pattern>
127 : CSKY32Inst<AddrModeNone, 0x3a, (outs), (ins GPR:$rx),
128 !strconcat(op, "\t$rx"), pattern> {
131 let Inst{25 - 21} = sop;
132 let Inst{20 - 16} = rx;
133 let Inst{15 - 0} = 0;
136 // Format< OP[6] | SOP[5] | RX[5] | 00000000000000[14] | IMM[2] >
137 // Instructions(1): jmpix32
138 class I_16_J_XI<bits<5> sop, string op, Operand operand, list<dag> pattern>
139 : CSKY32Inst<AddrModeNone, 0x3a, (outs),
140 (ins GPR:$rx, operand:$imm2),
141 !strconcat(op, "\t$rx, $imm2"), pattern> {
144 let Inst{25 - 21} = sop;
145 let Inst{20 - 16} = rx;
146 let Inst{15 - 2} = 0;
147 let Inst{1 - 0} = imm2;
150 // Format< OP[6] | SOP[5] | PCODE[5] | 0000000000000000[16] >
151 // Instructions(1): rts32
152 class I_16_RET<bits<5> sop, bits<5> pcode, string op, list<dag> pattern>
153 : CSKY32Inst<AddrModeNone, 0x3a, (outs), (ins), op, pattern> {
154 let Inst{25 - 21} = sop;
155 let Inst{20 - 16} = pcode;
156 let Inst{15 - 0} = 0;
157 let isTerminator = 1;
162 // Instructions(1): rte32
163 class I_16_RET_I<bits<5> sop, bits<5> pcode, string op, list<dag> pattern>
164 : CSKY32Inst<AddrModeNone, 0x30, (outs), (ins), op, pattern> {
165 let Inst{25 - 21} = sop;
166 let Inst{20 - 16} = pcode;
167 let Inst{15 - 10} = 0x10;
170 let isTerminator = 1;
175 // Format< OP[6] | SOP[5] | RX[5] | IMM16[16] >
176 // Instructions(3): cmpnei32, cmphsi32, cmplti32
177 class I_16_X<bits<5> sop, string op, Operand operand>
178 : CSKY32Inst<AddrModeNone, 0x3a, (outs CARRY:$ca),
179 (ins GPR:$rx, operand:$imm16), !strconcat(op, "\t$rx, $imm16"), []> {
182 let Inst{25 - 21} = sop;
183 let Inst{20 - 16} = rx;
184 let Inst{15 - 0} = imm16;
188 // Format< OP[6] | SOP[5] | RX[5] | OFFSET[16] >
189 // Instructions(7): bez32, bnez32, bnezad32, bhz32, blsz32, blz32, bhsz32
190 class I_16_X_L<bits<5> sop, string op, Operand operand>
191 : CSKY32Inst<AddrModeNone, 0x3a, (outs), (ins GPR:$rx, operand:$imm16),
192 !strconcat(op, "\t$rx, $imm16"), []> {
195 let Inst{25 - 21} = sop;
196 let Inst{20 - 16} = rx;
197 let Inst{15 - 0} = imm16;
199 let isTerminator = 1;
202 // Format< OP[6] | RZ[5] | RX[5] | SOP[4] | IMM[12] >
203 // Instructions(5): addi32, subi32, andi32, andni32, xori32
204 class I_12<bits<4> sop, string op, SDNode node, ImmLeaf ImmType>
205 : CSKY32Inst<AddrModeNone, 0x39, (outs GPR:$rz),
206 (ins GPR:$rx, ImmType:$imm12), !strconcat(op, "\t$rz, $rx, $imm12"),
207 [(set GPR:$rz, (node GPR:$rx, ImmType:$imm12))]> {
211 let Inst{25 - 21} = rz;
212 let Inst{20 - 16} = rx;
213 let Inst{15 - 12} = sop;
214 let Inst{11 - 0} = imm12;
217 class I_LDST<AddrMode am, bits<6> opcode, bits<4> sop, dag outs, dag ins,
218 string op, list<dag> pattern>
219 : CSKY32Inst<am, opcode, outs, ins, !strconcat(op, "\t$rz, ($rx, ${imm12})"),
224 let Inst{25 - 21} = rz;
225 let Inst{20 - 16} = rx;
226 let Inst{15 - 12} = sop;
227 let Inst{11 - 0} = imm12;
230 // Format< OP[6] | RZ[5] | RX[5] | SOP[4] | OFFSET[12] >
231 // Instructions(6): ld32.b, ld32.bs, ld32.h, ld32.hs, ld32.w, ld32.d
232 class I_LD<AddrMode am, bits<4> sop, string op, Operand operand>
233 : I_LDST<am, 0x36, sop,
234 (outs GPR:$rz), (ins GPR:$rx, operand:$imm12), op, []>;
236 // Format< OP[6] | RZ[5] | RX[5] | SOP[4] | OFFSET[12] >
237 // Instructions(4): st32.b, st32.h, st32.w, st32.d
238 class I_ST<AddrMode am, bits<4> sop, string op, Operand operand>
239 : I_LDST<am, 0x37, sop, (outs),
240 (ins GPR:$rz, GPR:$rx, operand:$imm12), op, []>;
242 // Format< OP[6] | SOP[5] | PCODE[5] | 0000[4] | 000 | R28 | LIST2[3] | R15 |
244 // Instructions(2): push32, pop32
245 class I_12_PP<bits<5> sop, bits<5> pcode, dag outs, dag ins, string op>
246 : CSKY32Inst<AddrModeNone, 0x3a, outs, ins, !strconcat(op, "\t$regs"), []> {
248 let Inst{25 - 21} = sop;
249 let Inst{20 - 16} = pcode;
250 let Inst{15 - 12} = 0;
251 let Inst{11 - 0} = regs;
254 // Format< OP[6] | RZ[5] | RX[5] | SOP[6] | PCODE[5] | IMM[5]>
255 // Instructions(4): incf32, inct32, decf32, dect32
256 class I_5_ZX<bits<6> sop, bits<5> pcode, string op, ImmLeaf ImmType,
258 : CSKY32Inst<AddrModeNone, 0x31, (outs GPR:$rz),
259 (ins GPR:$false, GPR:$rx, ImmType:$imm5),
260 !strconcat(op, "\t$rz, $rx, $imm5"), pattern> {
264 let Inst{25 - 21} = rz;
265 let Inst{20 - 16} = rx;
266 let Inst{15 - 10} = sop;
267 let Inst{9 - 5} = pcode;
268 let Inst{4 - 0} = imm5;
269 let Constraints = "$rz = $false";
272 // Format< OP[6] | IMM[5] | RX[5] | SOP[6] | PCODE[5] | RZ[5]>
273 // Instructions(13): decgt32, declt32, decne32, lsli32, lslc32, lsri32
274 // lsrc32, asri32, asrc32, rotli32, xsr32, bclri32, bseti32
275 class I_5_XZ<bits<6> sop, bits<5> pcode, string op, dag ins, dag outs,
277 : CSKY32Inst<AddrModeNone, 0x31, ins, outs,
278 !strconcat(op, "\t$rz, $rx, $imm5"), pattern> {
282 let Inst{25 - 21} = imm5;
283 let Inst{20 - 16} = rx;
284 let Inst{15 - 10} = sop;
285 let Inst{9 - 5} = pcode;
286 let Inst{4 - 0} = rz;
289 // Format< OP[6] | RY[5] | RX[5] | SOP[6] | PCODE[5] | IMM[5]>
290 // Instructions(2): ldm32, (ldq32), stm32, (stq32)
291 class I_5_YX<bits<6> opcode, dag outs, dag ins, string op, list<dag> pattern,
293 : CSKY32Inst<AddrModeNone, opcode, outs, ins,
294 op #"\t${ry}, (${rx}), " #!cast<int>(imm5), pattern> {
297 let Inst{25 - 21} = ry; // ry
298 let Inst{20 - 16} = rx;
299 let Inst{15 - 10} = 0b000111;
300 let Inst{9 - 5} = 0b00001;
301 let Inst{4 - 0} = imm5{4 - 0}; // imm5
304 // Format< OP[6] | LSB[5] | RX[5] | SOP[6] | MSB[5] | RZ[5]>
305 // Instructions(6): zext32, zextb32, zexth32, sext32, sextb32, sexth32
306 class I_5_XZ_U<bits<6> sop, dag outs, dag ins, string op, list<dag> pattern>
307 : CSKY32Inst<AddrModeNone, 0x31, outs, ins, op #"\t$rz, $rx, $msb, $lsb",
313 let Inst{25 - 21} = lsb; // lsb
314 let Inst{20 - 16} = rx;
315 let Inst{15 - 10} = sop;
316 let Inst{9 - 5} = msb; // msb
317 let Inst{4 - 0} = rz;
321 class I_5_XZ_US<bits<6> sop, string op, SDNode opnode,
322 ValueType type> : I_5_XZ_U<sop, (outs GPR:$rz), (ins GPR:$rx, uimm5:$msb, uimm5:$lsb), op,
323 [(set GPR:$rz, (opnode GPR:$rx, type))]>;
325 class I_5_XZ_UZ<bits<6> sop, string op, int v>
326 : I_5_XZ_U<sop, (outs GPR:$rz), (ins GPR:$rx, uimm5:$msb, uimm5:$lsb), op,
327 [(set GPR:$rz, (and GPR:$rx, (i32 v)))]>;
329 // Format< OP[6] | RZ[5] | RX[5] | SOP[6] | SIZE[5] | LSB[5]>
330 // Instructions(1): ins32
331 class I_5_ZX_U<bits<6> sop, string op, Operand operand, list<dag> pattern>
332 : CSKY32Inst<AddrModeNone, 0x31, (outs GPR:$rz), (ins operand:$size_lsb),
333 !strconcat(op, "\t$rz, operand:$size_lsb"), pattern> {
337 let Inst{25 - 21} = rz;
338 let Inst{20 - 16} = rx;
339 let Inst{15 - 10} = sop;
340 let Inst{9 - 5} = size_lsb{9 - 5}; // size
341 let Inst{4 - 0} = size_lsb{4 - 0}; // lsb
344 // Format< OP[6] | IMM[5] | RX[5] | SOP[6] | PCODE[5] | 00000 >
345 // Instructions(1): btsti32
346 class I_5_X<bits<6> sop, bits<5> pcode, string op, ImmLeaf ImmType,
348 : CSKY32Inst<AddrModeNone, 0x31,
349 (outs CARRY:$ca), (ins GPR:$rx, ImmType:$imm5),
350 !strconcat(op, "\t$rx, $imm5"), pattern> {
353 let Inst{25 - 21} = imm5;
354 let Inst{20 - 16} = rx;
355 let Inst{15 - 10} = sop;
356 let Inst{9 - 5} = pcode;
361 // Format< OP[6] | IMM[5] | 00000[5] | SOP[6] | PCODE[5] | RZ[5]>
362 // Instructions(1): bmaski32
363 class I_5_Z<bits<6> sop, bits<5> pcode, string op, ImmLeaf ImmType,
365 : CSKY32Inst<AddrModeNone, 0x31, (outs GPR:$rz), (ins ImmType:$imm5),
366 !strconcat(op, "\t$rz, $imm5"), pattern> {
369 let Inst{25 - 21} = imm5;
370 let Inst{20 - 16} = 0;
371 let Inst{15 - 10} = sop;
372 let Inst{9 - 5} = pcode;
373 let Inst{4 - 0} = rz;
376 // Format< OP[6] | RY[5] | RX[5] | SOP[6] | PCODE[5] | RZ[5] >
377 // Instructions(24): addu32, addc32, subu32, subc32, (rsub32), ixh32, ixw32,
378 // ixd32, and32, andn32, or32, xor32, nor32, lsl32, lsr32, asr32, rotl32
379 // mult32, divu32, divs32, mul.(u/s)32, mula.32.l, mula.u32, mulall.s16.s
380 class R_YXZ<bits<6> opcode, bits<6> sop, bits<5> pcode, dag outs, dag ins,
381 string op, list<dag> pattern>
382 : CSKY32Inst<AddrModeNone, opcode, outs, ins,
383 !strconcat(op, "\t$rz, $rx, $ry"), pattern> {
387 let Inst{25 - 21} = ry;
388 let Inst{20 - 16} = rx;
389 let Inst{15 - 10} = sop;
390 let Inst{9 - 5} = pcode;
391 let Inst{4 - 0} = rz;
394 // R_YXZ instructions with simple pattern
396 // Input: GPR:rx, GPR:ry
397 // Asm string: op rz, rx, ry
398 // Instructions: addu32, subu32, ixh32, ixw32, ixd32, and32, andn32, or32,
399 // xor32, nor32, lsl32, lsr32, asr32, mult32, divu32, divs32
400 class R_YXZ_SP_F1<bits<6> sop, bits<5> pcode, PatFrag opnode, string op,
401 bit Commutable = 0> : R_YXZ<0x31, sop, pcode, (outs GPR:$rz),
402 (ins GPR:$rx, GPR:$ry), op, [(set GPR:$rz, (opnode GPR:$rx, GPR:$ry))]> {
403 let isCommutable = Commutable;
406 // Format< OP[6] | RY[5] | RX[5] | SOP[6] | PCODE[5] | RZ[5] >
407 // Instructions:(8) ldr32.b, ldr32.h, ldr32.bs, ldr32.hs, ldr32.w,
408 // str32.b, str32.h, str32.w
409 class R_YXZ_LDST<bits<6> opcode, bits<6> sop, dag outs,
410 dag ins, string op, list<dag> pattern>
411 : CSKY32Inst<AddrModeNone, opcode, outs, ins,
412 op # "\t$rz, ($rx, $ry << ${imm})", pattern> {
417 let Inst{25 - 21} = ry; // ry;
418 let Inst{20 - 16} = rx; // rx;
419 let Inst{15 - 10} = sop;
420 let Inst{9 - 5} = imm; // pcode;
421 let Inst{4 - 0} = rz;
424 class I_LDR<bits<6> sop, string op> : R_YXZ_LDST<0x34, sop,
425 (outs GPR:$rz), (ins GPR:$rx, GPR:$ry, uimm_shift:$imm), op, []>;
427 class I_STR<bits<6> sop, string op> : R_YXZ_LDST<0x35, sop,
428 (outs), (ins GPR:$rz, GPR:$rx, GPR:$ry, uimm_shift:$imm), op, []>;
430 // Format< OP[6] | RX[5] | RX[5] | SOP[6] | PCODE[5] | RZ[5] >
431 // Instructions:(1) not32
432 class R_XXZ<bits<6> sop, bits<5> pcode, dag outs, dag ins, string op,
434 : CSKY32Inst<AddrModeNone, 0x31, outs, ins, !strconcat(op, "\t$rz, $rx"),
438 let Inst{25 - 21} = rx;
439 let Inst{20 - 16} = rx;
440 let Inst{15 - 10} = sop;
441 let Inst{9 - 5} = pcode;
442 let Inst{4 - 0} = rz;
445 // Format< OP[6] | RY[5] | RX[5] | SOP[6] | PCODE[5] | 00000[5] >
446 // Instructions:(4) cmpne32, cmphs32, cmplt32, tst32
447 class R_YX<bits<6> sop, bits<5> pcode, string op>
448 : CSKY32Inst<AddrModeNone, 0x31, (outs CARRY:$ca),
449 (ins GPR:$rx, GPR:$ry),
450 !strconcat(op, "\t$rx, $ry"), []> {
453 let Inst{25 - 21} = ry;
454 let Inst{20 - 16} = rx;
455 let Inst{15 - 10} = sop;
456 let Inst{9 - 5} = pcode;
461 // Format< OP[6] | 00000[5] | RX[5] | SOP[6] | PCODE[5] | RZ[5] >
463 // mov32, xtrb0.32, xtrb1.32, xtrb2.32, xtrb3.32, brev32, revb32
464 // revh32, abs32, ff0.32, ff1.32, bgenr32
465 class R_XZ<bits<6> sop, bits<5> pcode, string op>
466 : CSKY32Inst<AddrModeNone, 0x31, (outs GPR:$rz), (ins GPR:$rx),
467 !strconcat(op, "\t$rz, $rx"), []> {
470 let Inst{25 - 21} = 0;
471 let Inst{20 - 16} = rx;
472 let Inst{15 - 10} = sop;
473 let Inst{9 - 5} = pcode;
474 let Inst{4 - 0} = rz;
477 // Format< OP[6] | RZ[5] | RX[5] | SOP[6] | PCODE[5] | 00000[5] >
478 // Instructions:(2) movf32, movt32
479 class R_ZX<bits<6> sop, bits<5> pcode, string op, list<dag> pattern>
480 : CSKY32Inst<AddrModeNone, 0x31, (outs GPR:$rz),
481 (ins CARRY:$ca, GPR:$rx, GPR:$false),
482 !strconcat(op, "\t$rz, $rx"), pattern> {
485 let Inst{25 - 21} = rz;
486 let Inst{20 - 16} = rx;
487 let Inst{15 - 10} = sop;
488 let Inst{9 - 5} = pcode;
490 let Constraints = "$rz = $false";
494 // Format< OP[6] | 00000[5] | RX[5] | SOP[6] | PCODE[5] | 00000[5] >
495 // Instructions:(1) tstnbz32
496 class R_X<bits<6> sop, bits<5> pcode, string op, list<dag> pattern>
497 : CSKY32Inst<AddrModeNone, 0x31, (outs CARRY:$ca),(ins GPR:$rx),
498 !strconcat(op, "\t$rx"), pattern> {
500 let Inst{25 - 21} = 0;
501 let Inst{20 - 16} = rx;
502 let Inst{15 - 10} = sop;
503 let Inst{9 - 5} = pcode;
507 // Format< OP[6] | 00000[5] | 00000[5] | SOP[6] | PCODE[5] | RZ[5] >
508 // Instructions:(2) mvc32, mvcv32
509 class R_Z_1<bits<6> sop, bits<5> pcode, string op>
510 : CSKY32Inst<AddrModeNone, 0x31, (outs GPR:$rz),
511 (ins CARRY:$ca), !strconcat(op, "\t$rz"), []> {
513 let Inst{25 - 21} = 0;
514 let Inst{20 - 16} = 0;
515 let Inst{15 - 10} = sop;
516 let Inst{9 - 5} = pcode;
517 let Inst{4 - 0} = rz;
520 // Format< OP[6] | RZ[5] | 00000[5] | SOP[6] | PCODE[5] | 00000[5] >
521 // Instructions:(2) clrf32, clrt32
522 class R_Z_2<bits<6> sop, bits<5> pcode, string op, list<dag> pattern>
523 : CSKY32Inst<AddrModeNone, 0x31, (outs GPR:$rz),
524 (ins CARRY:$ca, GPR:$false), !strconcat(op, "\t$rz"), []> {
526 let Inst{25 - 21} = rz;
527 let Inst{20 - 16} = 0;
528 let Inst{15 - 10} = sop;
529 let Inst{9 - 5} = pcode;
531 let Constraints = "$rz = $false";