xref: /freebsd-src/contrib/llvm-project/llvm/lib/Target/CSKY/CSKYInstrFormats.td (revision 81ad626541db97eb356e2c1d4a20eb2a26a766ab)
1e8d8bef9SDimitry Andric//===-- CSKYInstrFormats.td - CSKY Instruction Formats -----*- tablegen -*-===//
2e8d8bef9SDimitry Andric//
3e8d8bef9SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4e8d8bef9SDimitry Andric// See https://llvm.org/LICENSE.txt for license information.
5e8d8bef9SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6e8d8bef9SDimitry Andric//
7e8d8bef9SDimitry Andric//===----------------------------------------------------------------------===//
8e8d8bef9SDimitry Andric
9e8d8bef9SDimitry Andricclass AddrMode<bits<5> val> {
10e8d8bef9SDimitry Andric  bits<5> Value = val;
11e8d8bef9SDimitry Andric}
12e8d8bef9SDimitry Andric
13e8d8bef9SDimitry Andricdef AddrModeNone : AddrMode<0>;
14e8d8bef9SDimitry Andricdef AddrMode32B : AddrMode<1>;   // ld32.b, ld32.bs, st32.b, st32.bs, +4kb
15e8d8bef9SDimitry Andricdef AddrMode32H : AddrMode<2>;   // ld32.h, ld32.hs, st32.h, st32.hs, +8kb
16e8d8bef9SDimitry Andricdef AddrMode32WD : AddrMode<3>;  // ld32.w, st32.w, ld32.d, st32.d, +16kb
17e8d8bef9SDimitry Andricdef AddrMode16B : AddrMode<4>;   // ld16.b, +32b
18e8d8bef9SDimitry Andricdef AddrMode16H : AddrMode<5>;   // ld16.h, +64b
19e8d8bef9SDimitry Andricdef AddrMode16W : AddrMode<6>;   // ld16.w, +128b or +1kb
20e8d8bef9SDimitry Andricdef AddrMode32SDF : AddrMode<7>; // flds, fldd, +1kb
21e8d8bef9SDimitry Andric
22e8d8bef9SDimitry Andricclass CSKYInst<AddrMode am, int sz, dag outs, dag ins, string asmstr,
23e8d8bef9SDimitry Andric               list<dag> pattern> : Instruction {
24e8d8bef9SDimitry Andric  let Namespace = "CSKY";
25e8d8bef9SDimitry Andric  int Size = sz;
26e8d8bef9SDimitry Andric  AddrMode AM = am;
27349cc55cSDimitry Andric  field bits<32> SoftFail = 0;
28e8d8bef9SDimitry Andric  let OutOperandList = outs;
29e8d8bef9SDimitry Andric  let InOperandList = ins;
30e8d8bef9SDimitry Andric  let AsmString = asmstr;
31e8d8bef9SDimitry Andric  let Pattern = pattern;
32e8d8bef9SDimitry Andric  let Itinerary = NoItinerary;
33e8d8bef9SDimitry Andric  let TSFlags{4 - 0} = AM.Value;
34e8d8bef9SDimitry Andric}
35e8d8bef9SDimitry Andric
36e8d8bef9SDimitry Andricclass CSKYPseudo<dag outs, dag ins, string asmstr, list<dag> pattern>
37e8d8bef9SDimitry Andric    : CSKYInst<AddrModeNone, 0, outs, ins, asmstr, pattern> {
38e8d8bef9SDimitry Andric  let isCodeGenOnly = 1;
39e8d8bef9SDimitry Andric  let isPseudo = 1;
40e8d8bef9SDimitry Andric}
41e8d8bef9SDimitry Andric
42e8d8bef9SDimitry Andricclass CSKY32Inst<AddrMode am, bits<6> opcode, dag outs, dag ins, string asmstr,
43e8d8bef9SDimitry Andric                 list<dag> pattern>
44e8d8bef9SDimitry Andric    : CSKYInst<am, 4, outs, ins, asmstr, pattern> {
45e8d8bef9SDimitry Andric  field bits<32> Inst;
46e8d8bef9SDimitry Andric  let Inst{31 - 26} = opcode;
47e8d8bef9SDimitry Andric}
48e8d8bef9SDimitry Andric
49349cc55cSDimitry Andricclass CSKY16Inst<AddrMode am, dag outs, dag ins, string asmstr, list<dag> pattern>
50349cc55cSDimitry Andric  : CSKYInst<am, 2, outs, ins, asmstr, pattern> {
51349cc55cSDimitry Andric  field bits<16> Inst;
52349cc55cSDimitry Andric}
53349cc55cSDimitry Andric
54e8d8bef9SDimitry Andric// CSKY 32-bit instruction
55e8d8bef9SDimitry Andric// Format< OP[6] | Offset[26] >
56e8d8bef9SDimitry Andric// Instruction(1): bsr32
57e8d8bef9SDimitry Andricclass J<bits<6> opcode, dag outs, dag ins, string op, list<dag> pattern>
58e8d8bef9SDimitry Andric    : CSKY32Inst<AddrModeNone, opcode, outs, ins, !strconcat(op, "\t$offset"),
59e8d8bef9SDimitry Andric                 pattern> {
60e8d8bef9SDimitry Andric  bits<26> offset;
61e8d8bef9SDimitry Andric  let Inst{25 - 0} = offset;
62fe6060f1SDimitry Andric  let isCall = 1;
63fe6060f1SDimitry Andric  let Defs = [ R15 ];
64e8d8bef9SDimitry Andric}
65e8d8bef9SDimitry Andric
66e8d8bef9SDimitry Andric// Format< OP[6] | RZ[5] | SOP[3] | OFFSET[18] >
67e8d8bef9SDimitry Andric// Instructions(7): grs, lrs32.b, lrs32.h, lrs32.w, srs32.b, srs32.h, srs32.w
68fe6060f1SDimitry Andricclass I_18_Z_L<bits<3> sop, string asm, dag outs, dag ins, list<dag> pattern>
69fe6060f1SDimitry Andric    : CSKY32Inst<AddrModeNone, 0x33, outs, ins, asm, pattern> {
70e8d8bef9SDimitry Andric  bits<5> rz;
71e8d8bef9SDimitry Andric  bits<18> offset;
72e8d8bef9SDimitry Andric  let Inst{25 - 21} = rz;
73e8d8bef9SDimitry Andric  let Inst{20 - 18} = sop;
74e8d8bef9SDimitry Andric  let Inst{17 - 0} = offset;
75e8d8bef9SDimitry Andric}
76e8d8bef9SDimitry Andric
77e8d8bef9SDimitry Andric// Format< OP[6] | RZ[5] | RX[5] | IMM[16] >
78e8d8bef9SDimitry Andric// Instructions(1): ori32
79e8d8bef9SDimitry Andricclass I_16_ZX<string op, ImmLeaf ImmType, list<dag> pattern>
80e8d8bef9SDimitry Andric    : CSKY32Inst<AddrModeNone, 0x3b,
81e8d8bef9SDimitry Andric                 (outs GPR:$rz), (ins GPR:$rx,ImmType:$imm16),
82e8d8bef9SDimitry Andric                 !strconcat(op, "\t$rz, $rx, $imm16"), pattern> {
83e8d8bef9SDimitry Andric  bits<5> rz;
84e8d8bef9SDimitry Andric  bits<5> rx;
85e8d8bef9SDimitry Andric  bits<16> imm16;
86e8d8bef9SDimitry Andric  let Inst{25 - 21} = rz;
87e8d8bef9SDimitry Andric  let Inst{20 - 16} = rx;
88e8d8bef9SDimitry Andric  let Inst{15 - 0} = imm16;
89e8d8bef9SDimitry Andric}
90e8d8bef9SDimitry Andric
91e8d8bef9SDimitry Andric// Format< OP[6] | SOP[5] | RZ[5] | IMM[16] >
92e8d8bef9SDimitry Andric// Instructions(3): movi32, movih32, (bgeni32)
93e8d8bef9SDimitry Andricclass I_16_MOV<bits<5> sop, string op, ImmLeaf ImmType>
94e8d8bef9SDimitry Andric    : CSKY32Inst<AddrModeNone, 0x3a, (outs GPR:$rz), (ins ImmType:$imm16),
95e8d8bef9SDimitry Andric                 !strconcat(op, "\t$rz, $imm16"),
96e8d8bef9SDimitry Andric                 [(set GPR:$rz, ImmType:$imm16)]> {
97e8d8bef9SDimitry Andric  bits<5> rz;
98e8d8bef9SDimitry Andric  bits<16> imm16;
99e8d8bef9SDimitry Andric  let Inst{25 - 21} = sop;
100e8d8bef9SDimitry Andric  let Inst{20 - 16} = rz;
101e8d8bef9SDimitry Andric  let Inst{15 - 0} = imm16;
102e8d8bef9SDimitry Andric  let isReMaterializable = 1;
103e8d8bef9SDimitry Andric  let isAsCheapAsAMove = 1;
104e8d8bef9SDimitry Andric  let isMoveImm = 1;
105e8d8bef9SDimitry Andric}
106e8d8bef9SDimitry Andric
107e8d8bef9SDimitry Andric// Format< OP[6] | SOP[5] | RZ[5] | OFFSET[16] >
108e8d8bef9SDimitry Andric// Instructions(1): lrw32
109fe6060f1SDimitry Andricclass I_16_Z_L<bits<5> sop, string op, dag ins, list<dag> pattern>
110fe6060f1SDimitry Andric  : CSKY32Inst<AddrModeNone, 0x3a, (outs GPR:$rz), ins,
111fe6060f1SDimitry Andric  !strconcat(op, "\t$rz, $imm16"), pattern> {
112e8d8bef9SDimitry Andric  bits<5> rz;
113e8d8bef9SDimitry Andric  bits<16> imm16;
114e8d8bef9SDimitry Andric  let Inst{25 - 21} = sop;
115e8d8bef9SDimitry Andric  let Inst{20 - 16} = rz;
116e8d8bef9SDimitry Andric  let Inst{15 - 0} = imm16;
117e8d8bef9SDimitry Andric}
118e8d8bef9SDimitry Andric
119e8d8bef9SDimitry Andric// Format< OP[6] | SOP[5] | 00000[5] | OFFSET[16] >
120e8d8bef9SDimitry Andric// Instructions(5): bt32, bf32, br32, jmpi32, jsri32
121fe6060f1SDimitry Andricclass I_16_L<bits<5> sop, dag outs, dag ins, string asm, list<dag> pattern>
122fe6060f1SDimitry Andric    : CSKY32Inst<AddrModeNone, 0x3a, outs, ins, asm, pattern> {
123e8d8bef9SDimitry Andric  bits<16> imm16;
124e8d8bef9SDimitry Andric  let Inst{25 - 21} = sop;
125e8d8bef9SDimitry Andric  let Inst{20 - 16} = 0;
126e8d8bef9SDimitry Andric  let Inst{15 - 0} = imm16;
127e8d8bef9SDimitry Andric}
128e8d8bef9SDimitry Andric
129e8d8bef9SDimitry Andric// Format< OP[6] | SOP[5] | RX[5] | 0000000000000000[16] >
130e8d8bef9SDimitry Andric// Instructions(2): jmp32, jsr32
131e8d8bef9SDimitry Andricclass I_16_JX<bits<5> sop, string op, list<dag> pattern>
132e8d8bef9SDimitry Andric    : CSKY32Inst<AddrModeNone, 0x3a, (outs), (ins GPR:$rx),
133e8d8bef9SDimitry Andric                 !strconcat(op, "\t$rx"), pattern> {
134e8d8bef9SDimitry Andric  bits<5> rx;
135e8d8bef9SDimitry Andric  bits<16> imm16;
136e8d8bef9SDimitry Andric  let Inst{25 - 21} = sop;
137e8d8bef9SDimitry Andric  let Inst{20 - 16} = rx;
138e8d8bef9SDimitry Andric  let Inst{15 - 0} = 0;
139e8d8bef9SDimitry Andric}
140e8d8bef9SDimitry Andric
141e8d8bef9SDimitry Andric// Format< OP[6] | SOP[5] | RX[5] | 00000000000000[14] | IMM[2] >
142e8d8bef9SDimitry Andric// Instructions(1): jmpix32
143e8d8bef9SDimitry Andricclass I_16_J_XI<bits<5> sop, string op, Operand operand, list<dag> pattern>
144e8d8bef9SDimitry Andric    : CSKY32Inst<AddrModeNone, 0x3a, (outs),
145e8d8bef9SDimitry Andric                 (ins GPR:$rx, operand:$imm2),
146e8d8bef9SDimitry Andric                 !strconcat(op, "\t$rx, $imm2"), pattern> {
147e8d8bef9SDimitry Andric  bits<5> rx;
148e8d8bef9SDimitry Andric  bits<2> imm2;
149e8d8bef9SDimitry Andric  let Inst{25 - 21} = sop;
150e8d8bef9SDimitry Andric  let Inst{20 - 16} = rx;
151e8d8bef9SDimitry Andric  let Inst{15 - 2} = 0;
152e8d8bef9SDimitry Andric  let Inst{1 - 0} = imm2;
153e8d8bef9SDimitry Andric}
154e8d8bef9SDimitry Andric
155e8d8bef9SDimitry Andric// Format< OP[6] | SOP[5] | PCODE[5] | 0000000000000000[16] >
156e8d8bef9SDimitry Andric// Instructions(1): rts32
157e8d8bef9SDimitry Andricclass I_16_RET<bits<5> sop, bits<5> pcode, string op, list<dag> pattern>
158e8d8bef9SDimitry Andric    : CSKY32Inst<AddrModeNone, 0x3a, (outs), (ins), op, pattern> {
159e8d8bef9SDimitry Andric  let Inst{25 - 21} = sop;
160e8d8bef9SDimitry Andric  let Inst{20 - 16} = pcode;
161e8d8bef9SDimitry Andric  let Inst{15 - 0} = 0;
162e8d8bef9SDimitry Andric  let isTerminator = 1;
163e8d8bef9SDimitry Andric  let isReturn = 1;
164e8d8bef9SDimitry Andric  let isBarrier = 1;
165349cc55cSDimitry Andric  let Uses = [ R15 ];
166fe6060f1SDimitry Andric}
167fe6060f1SDimitry Andric
168e8d8bef9SDimitry Andric// Format< OP[6] | SOP[5] | RX[5] | IMM16[16] >
169e8d8bef9SDimitry Andric// Instructions(3): cmpnei32, cmphsi32, cmplti32
170fe6060f1SDimitry Andricclass I_16_X<bits<5> sop, string op, Operand operand>
171e8d8bef9SDimitry Andric    : CSKY32Inst<AddrModeNone, 0x3a, (outs CARRY:$ca),
172fe6060f1SDimitry Andric    (ins GPR:$rx, operand:$imm16), !strconcat(op, "\t$rx, $imm16"), []> {
173e8d8bef9SDimitry Andric  bits<16> imm16;
174e8d8bef9SDimitry Andric  bits<5> rx;
175e8d8bef9SDimitry Andric  let Inst{25 - 21} = sop;
176e8d8bef9SDimitry Andric  let Inst{20 - 16} = rx;
177e8d8bef9SDimitry Andric  let Inst{15 - 0} = imm16;
178e8d8bef9SDimitry Andric  let isCompare = 1;
179e8d8bef9SDimitry Andric}
180e8d8bef9SDimitry Andric
181e8d8bef9SDimitry Andric// Format< OP[6] | SOP[5] | RX[5] | OFFSET[16] >
182e8d8bef9SDimitry Andric// Instructions(7): bez32, bnez32, bnezad32, bhz32, blsz32, blz32, bhsz32
183e8d8bef9SDimitry Andricclass I_16_X_L<bits<5> sop, string op, Operand operand>
184e8d8bef9SDimitry Andric    : CSKY32Inst<AddrModeNone, 0x3a, (outs), (ins GPR:$rx, operand:$imm16),
185e8d8bef9SDimitry Andric                 !strconcat(op, "\t$rx, $imm16"), []> {
186e8d8bef9SDimitry Andric  bits<5> rx;
187e8d8bef9SDimitry Andric  bits<16> imm16;
188e8d8bef9SDimitry Andric  let Inst{25 - 21} = sop;
189e8d8bef9SDimitry Andric  let Inst{20 - 16} = rx;
190e8d8bef9SDimitry Andric  let Inst{15 - 0} = imm16;
191e8d8bef9SDimitry Andric  let isBranch = 1;
192e8d8bef9SDimitry Andric  let isTerminator = 1;
193e8d8bef9SDimitry Andric}
194e8d8bef9SDimitry Andric
195e8d8bef9SDimitry Andric// Format< OP[6] | RZ[5] | RX[5] | SOP[4] | IMM[12] >
196e8d8bef9SDimitry Andric// Instructions(5): addi32, subi32, andi32, andni32, xori32
197e8d8bef9SDimitry Andricclass I_12<bits<4> sop, string op, SDNode node, ImmLeaf ImmType>
198e8d8bef9SDimitry Andric    : CSKY32Inst<AddrModeNone, 0x39, (outs GPR:$rz),
199e8d8bef9SDimitry Andric    (ins GPR:$rx, ImmType:$imm12), !strconcat(op, "\t$rz, $rx, $imm12"),
200e8d8bef9SDimitry Andric    [(set GPR:$rz, (node GPR:$rx, ImmType:$imm12))]> {
201e8d8bef9SDimitry Andric  bits<5> rz;
202e8d8bef9SDimitry Andric  bits<5> rx;
203e8d8bef9SDimitry Andric  bits<12> imm12;
204e8d8bef9SDimitry Andric  let Inst{25 - 21} = rz;
205e8d8bef9SDimitry Andric  let Inst{20 - 16} = rx;
206e8d8bef9SDimitry Andric  let Inst{15 - 12} = sop;
207e8d8bef9SDimitry Andric  let Inst{11 - 0} = imm12;
208e8d8bef9SDimitry Andric}
209e8d8bef9SDimitry Andric
210e8d8bef9SDimitry Andricclass I_LDST<AddrMode am, bits<6> opcode, bits<4> sop, dag outs, dag ins,
211e8d8bef9SDimitry Andric             string op, list<dag> pattern>
212fe6060f1SDimitry Andric    : CSKY32Inst<am, opcode, outs, ins, !strconcat(op, "\t$rz, ($rx, ${imm12})"),
213e8d8bef9SDimitry Andric                 pattern> {
214e8d8bef9SDimitry Andric  bits<5> rx;
215e8d8bef9SDimitry Andric  bits<5> rz;
216e8d8bef9SDimitry Andric  bits<12> imm12;
217e8d8bef9SDimitry Andric  let Inst{25 - 21} = rz;
218e8d8bef9SDimitry Andric  let Inst{20 - 16} = rx;
219e8d8bef9SDimitry Andric  let Inst{15 - 12} = sop;
220e8d8bef9SDimitry Andric  let Inst{11 - 0} = imm12;
221e8d8bef9SDimitry Andric}
222e8d8bef9SDimitry Andric
223349cc55cSDimitry Andricclass I_PLDR<AddrMode am, bits<6> opcode, bits<4> sop, dag outs, dag ins,
224349cc55cSDimitry Andric             string op, list<dag> pattern>
225349cc55cSDimitry Andric    : CSKY32Inst<am, opcode, outs, ins, !strconcat(op, "\t($rx, ${imm12})"),
226349cc55cSDimitry Andric                 pattern> {
227349cc55cSDimitry Andric  bits<5> rx;
228349cc55cSDimitry Andric  bits<12> imm12;
229349cc55cSDimitry Andric  let Inst{25 - 21} = 0;
230349cc55cSDimitry Andric  let Inst{20 - 16} = rx;
231349cc55cSDimitry Andric  let Inst{15 - 12} = sop;
232349cc55cSDimitry Andric  let Inst{11 - 0} = imm12;
233349cc55cSDimitry Andric}
234349cc55cSDimitry Andric
235349cc55cSDimitry Andric
236e8d8bef9SDimitry Andric// Format< OP[6] | RZ[5] | RX[5] | SOP[4] | OFFSET[12] >
237349cc55cSDimitry Andric// Instructions(6): ld32.b, ld32.bs, ld32.h, ld32.hs, ld32.w
238e8d8bef9SDimitry Andricclass I_LD<AddrMode am, bits<4> sop, string op, Operand operand>
239e8d8bef9SDimitry Andric    : I_LDST<am, 0x36, sop,
240e8d8bef9SDimitry Andric    (outs GPR:$rz), (ins GPR:$rx, operand:$imm12), op, []>;
241e8d8bef9SDimitry Andric
242e8d8bef9SDimitry Andric// Format< OP[6] | RZ[5] | RX[5] | SOP[4] | OFFSET[12] >
243349cc55cSDimitry Andric// Instructions(4): st32.b, st32.h, st32.w
244e8d8bef9SDimitry Andricclass I_ST<AddrMode am, bits<4> sop, string op, Operand operand>
245e8d8bef9SDimitry Andric    : I_LDST<am, 0x37, sop, (outs),
246e8d8bef9SDimitry Andric    (ins GPR:$rz, GPR:$rx, operand:$imm12), op, []>;
247e8d8bef9SDimitry Andric
248e8d8bef9SDimitry Andric// Format< OP[6] | SOP[5] | PCODE[5] | 0000[4] | 000 | R28 | LIST2[3] | R15 |
249e8d8bef9SDimitry Andric// LIST1[4] >
250e8d8bef9SDimitry Andric// Instructions(2): push32, pop32
251e8d8bef9SDimitry Andricclass I_12_PP<bits<5> sop, bits<5> pcode, dag outs, dag ins, string op>
252e8d8bef9SDimitry Andric    : CSKY32Inst<AddrModeNone, 0x3a, outs, ins, !strconcat(op, "\t$regs"), []> {
253e8d8bef9SDimitry Andric  bits<12> regs;
254e8d8bef9SDimitry Andric  let Inst{25 - 21} = sop;
255e8d8bef9SDimitry Andric  let Inst{20 - 16} = pcode;
256e8d8bef9SDimitry Andric  let Inst{15 - 12} = 0;
257e8d8bef9SDimitry Andric  let Inst{11 - 0} = regs;
258349cc55cSDimitry Andric  let Uses = [R14];
259349cc55cSDimitry Andric  let Defs = [R14];
260e8d8bef9SDimitry Andric}
261e8d8bef9SDimitry Andric
262e8d8bef9SDimitry Andric// Format< OP[6] | RZ[5] | RX[5] | SOP[6] | PCODE[5] | IMM[5]>
263e8d8bef9SDimitry Andric// Instructions(4): incf32, inct32, decf32, dect32
264e8d8bef9SDimitry Andricclass I_5_ZX<bits<6> sop, bits<5> pcode, string op, ImmLeaf ImmType,
265e8d8bef9SDimitry Andric             list<dag> pattern>
266e8d8bef9SDimitry Andric    : CSKY32Inst<AddrModeNone, 0x31, (outs GPR:$rz),
267349cc55cSDimitry Andric    (ins CARRY:$cond, GPR:$false, GPR:$rx, ImmType:$imm5),
268e8d8bef9SDimitry Andric    !strconcat(op, "\t$rz, $rx, $imm5"), pattern> {
269e8d8bef9SDimitry Andric  bits<5> rz;
270e8d8bef9SDimitry Andric  bits<5> rx;
271e8d8bef9SDimitry Andric  bits<5> imm5;
272e8d8bef9SDimitry Andric  let Inst{25 - 21} = rz;
273e8d8bef9SDimitry Andric  let Inst{20 - 16} = rx;
274e8d8bef9SDimitry Andric  let Inst{15 - 10} = sop;
275e8d8bef9SDimitry Andric  let Inst{9 - 5} = pcode;
276e8d8bef9SDimitry Andric  let Inst{4 - 0} = imm5;
277e8d8bef9SDimitry Andric  let Constraints = "$rz = $false";
278e8d8bef9SDimitry Andric}
279e8d8bef9SDimitry Andric
280e8d8bef9SDimitry Andric// Format< OP[6] | IMM[5] | RX[5] | SOP[6] | PCODE[5] | RZ[5]>
281e8d8bef9SDimitry Andric// Instructions(13): decgt32, declt32, decne32, lsli32, lslc32, lsri32
282e8d8bef9SDimitry Andric//                   lsrc32, asri32, asrc32, rotli32, xsr32, bclri32, bseti32
283349cc55cSDimitry Andricclass I_5_XZ<bits<6> sop, bits<5> pcode, string op, dag outs, dag ins,
284e8d8bef9SDimitry Andric             list<dag> pattern>
285349cc55cSDimitry Andric    : CSKY32Inst<AddrModeNone, 0x31, outs, ins,
286e8d8bef9SDimitry Andric                 !strconcat(op, "\t$rz, $rx, $imm5"), pattern> {
287e8d8bef9SDimitry Andric  bits<5> imm5;
288e8d8bef9SDimitry Andric  bits<5> rx;
289e8d8bef9SDimitry Andric  bits<5> rz;
290e8d8bef9SDimitry Andric  let Inst{25 - 21} = imm5;
291e8d8bef9SDimitry Andric  let Inst{20 - 16} = rx;
292e8d8bef9SDimitry Andric  let Inst{15 - 10} = sop;
293e8d8bef9SDimitry Andric  let Inst{9 - 5} = pcode;
294e8d8bef9SDimitry Andric  let Inst{4 - 0} = rz;
295e8d8bef9SDimitry Andric}
296e8d8bef9SDimitry Andric
297349cc55cSDimitry Andric// mtcr32, mfcr32
298349cc55cSDimitry Andricclass I_5_XZ_CR<bits<6> sop, bits<5> pcode, string opStr, dag outs, dag ins,
299349cc55cSDimitry Andric             list<dag> pattern>
300349cc55cSDimitry Andric    : CSKY32Inst<AddrModeNone, 0x30, outs, ins, opStr, pattern> {
301349cc55cSDimitry Andric  bits<5> sel;
302349cc55cSDimitry Andric  bits<5> rx;
303349cc55cSDimitry Andric  bits<5> cr;
304349cc55cSDimitry Andric  let Inst{25 - 21} = sel;
305349cc55cSDimitry Andric  let Inst{20 - 16} = rx;
306349cc55cSDimitry Andric  let Inst{15 - 10} = sop;
307349cc55cSDimitry Andric  let Inst{9 - 5} = pcode;
308349cc55cSDimitry Andric  let Inst{4 - 0} = cr;
309349cc55cSDimitry Andric}
310349cc55cSDimitry Andric
311349cc55cSDimitry Andric// sync
312349cc55cSDimitry Andricclass I_5_XZ_SYNC<bits<6> sop, bits<5> pcode, string opStr, bits<1> S, bits<1> I>
313349cc55cSDimitry Andric    : CSKY32Inst<AddrModeNone, 0x30, (outs), (ins), opStr, []> {
314349cc55cSDimitry Andric  let Inst{25 - 21} = 0;
315349cc55cSDimitry Andric  let Inst{20 - 16} = 0;
316349cc55cSDimitry Andric  let Inst{15 - 10} = sop;
317349cc55cSDimitry Andric  let Inst{9 - 5} = pcode;
318349cc55cSDimitry Andric  let Inst{4 - 0} = 0;
319349cc55cSDimitry Andric  let Inst{25} = S;
320349cc55cSDimitry Andric  let Inst{21} = I;
321349cc55cSDimitry Andric
322349cc55cSDimitry Andric}
323349cc55cSDimitry Andric
324349cc55cSDimitry Andric// Priviledged Instructions
325349cc55cSDimitry Andricclass I_5_XZ_PRIVI<bits<6> sop, bits<5> pcode, string opStr>
326349cc55cSDimitry Andric    : CSKY32Inst<AddrModeNone, 0x30, (outs), (ins), opStr, []> {
327349cc55cSDimitry Andric  let Inst{25 - 21} = 0;
328349cc55cSDimitry Andric  let Inst{20 - 16} = 0;
329349cc55cSDimitry Andric  let Inst{15 - 10} = sop;
330349cc55cSDimitry Andric  let Inst{9 - 5} = pcode;
331349cc55cSDimitry Andric  let Inst{4 - 0} = 0;
332349cc55cSDimitry Andric}
333349cc55cSDimitry Andric
334349cc55cSDimitry Andricclass I_CP<bits<4> sop, dag outs, dag ins, string opStr>
335349cc55cSDimitry Andric    : CSKY32Inst<AddrModeNone, 0x3f, outs, ins, opStr, []> {
336349cc55cSDimitry Andric  bits<5> cpid;
337349cc55cSDimitry Andric  bits<12> usdef;
338349cc55cSDimitry Andric  let Inst{25 - 21} = cpid;
339349cc55cSDimitry Andric  let Inst{20 - 16} = 0;
340349cc55cSDimitry Andric  let Inst{15 - 12} = sop;
341349cc55cSDimitry Andric  let Inst{11 - 0} = usdef;
342349cc55cSDimitry Andric}
343349cc55cSDimitry Andric
344349cc55cSDimitry Andricclass I_CPOP<dag outs, dag ins, string opStr>
345349cc55cSDimitry Andric    : CSKY32Inst<AddrModeNone, 0x3f, outs, ins, opStr, []> {
346349cc55cSDimitry Andric  bits<5> cpid;
347349cc55cSDimitry Andric  bits<20> usdef;
348349cc55cSDimitry Andric  let Inst{25 - 21} = cpid;
349349cc55cSDimitry Andric  let Inst{20 - 16} = usdef{19-15};
350349cc55cSDimitry Andric  let Inst{15} = 1;
351349cc55cSDimitry Andric  let Inst{14 - 0} = usdef{14-0};
352349cc55cSDimitry Andric}
353349cc55cSDimitry Andric
354349cc55cSDimitry Andricclass I_CP_Z<bits<4> sop, dag outs, dag ins, string opStr>
355349cc55cSDimitry Andric    : CSKY32Inst<AddrModeNone, 0x3f, outs, ins, opStr, []> {
356349cc55cSDimitry Andric  bits<5> cpid;
357349cc55cSDimitry Andric  bits<12> usdef;
358349cc55cSDimitry Andric  bits<5> rz;
359349cc55cSDimitry Andric
360349cc55cSDimitry Andric  let Inst{25 - 21} = cpid;
361349cc55cSDimitry Andric  let Inst{20 - 16} = rz;
362349cc55cSDimitry Andric  let Inst{15 - 12} = sop;
363349cc55cSDimitry Andric  let Inst{11 - 0} = usdef;
364349cc55cSDimitry Andric}
365349cc55cSDimitry Andric
366349cc55cSDimitry Andricclass I_5_CACHE<bits<6> sop, bits<5> pcode, string opStr>
367349cc55cSDimitry Andric    : CSKY32Inst<AddrModeNone, 0x30, (outs), (ins), opStr, []> {
368349cc55cSDimitry Andric  let Inst{25 - 21} = pcode;
369349cc55cSDimitry Andric  let Inst{20 - 16} = 0;
370349cc55cSDimitry Andric  let Inst{15 - 10} = sop;
371349cc55cSDimitry Andric  let Inst{9 - 5} = 0b00001;
372349cc55cSDimitry Andric  let Inst{4 - 0} = 0;
373349cc55cSDimitry Andric}
374349cc55cSDimitry Andric
375349cc55cSDimitry Andricclass I_5_X_CACHE<bits<6> sop, bits<5> pcode, string opStr>
376349cc55cSDimitry Andric    : CSKY32Inst<AddrModeNone, 0x30, (outs), (ins GPR:$rx), opStr #"\t$rx", []> {
377349cc55cSDimitry Andric  bits<5> rx;
378349cc55cSDimitry Andric
379349cc55cSDimitry Andric  let Inst{25 - 21} = pcode;
380349cc55cSDimitry Andric  let Inst{20 - 16} = rx;
381349cc55cSDimitry Andric  let Inst{15 - 10} = sop;
382349cc55cSDimitry Andric  let Inst{9 - 5} = 0b00001;
383349cc55cSDimitry Andric  let Inst{4 - 0} = 0;
384349cc55cSDimitry Andric}
385349cc55cSDimitry Andric
386e8d8bef9SDimitry Andric// Format< OP[6] | RY[5] | RX[5] | SOP[6] | PCODE[5] | IMM[5]>
387e8d8bef9SDimitry Andric// Instructions(2): ldm32, (ldq32), stm32, (stq32)
388349cc55cSDimitry Andricclass I_5_YX<bits<6> opcode, bits<6> sop, dag outs, dag ins, string opStr, list<dag> pattern>
389349cc55cSDimitry Andric    : CSKY32Inst<AddrModeNone, opcode, outs, ins, opStr, pattern> {
390349cc55cSDimitry Andric  bits<10> regs;
391e8d8bef9SDimitry Andric  bits<5> rx;
392349cc55cSDimitry Andric
393349cc55cSDimitry Andric  let Inst{25 - 21} = regs{9 - 5}; // ry
394e8d8bef9SDimitry Andric  let Inst{20 - 16} = rx;
395349cc55cSDimitry Andric  let Inst{15 - 10} = sop;
396e8d8bef9SDimitry Andric  let Inst{9 - 5} = 0b00001;
397349cc55cSDimitry Andric  let Inst{4 - 0} = regs{4 - 0}; // imm5
398e8d8bef9SDimitry Andric}
399e8d8bef9SDimitry Andric
400e8d8bef9SDimitry Andric// Format< OP[6] | LSB[5] | RX[5] | SOP[6] | MSB[5] | RZ[5]>
401e8d8bef9SDimitry Andric// Instructions(6): zext32, zextb32, zexth32, sext32, sextb32, sexth32
402fe6060f1SDimitry Andricclass I_5_XZ_U<bits<6> sop, dag outs, dag ins, string op, list<dag> pattern>
403fe6060f1SDimitry Andric    : CSKY32Inst<AddrModeNone, 0x31, outs, ins, op #"\t$rz, $rx, $msb, $lsb",
404e8d8bef9SDimitry Andric                 pattern> {
405e8d8bef9SDimitry Andric  bits<5> rx;
406e8d8bef9SDimitry Andric  bits<5> rz;
407fe6060f1SDimitry Andric  bits<5> msb;
408fe6060f1SDimitry Andric  bits<5> lsb;
409e8d8bef9SDimitry Andric  let Inst{25 - 21} = lsb; // lsb
410e8d8bef9SDimitry Andric  let Inst{20 - 16} = rx;
411e8d8bef9SDimitry Andric  let Inst{15 - 10} = sop;
412e8d8bef9SDimitry Andric  let Inst{9 - 5} = msb; // msb
413e8d8bef9SDimitry Andric  let Inst{4 - 0} = rz;
414e8d8bef9SDimitry Andric}
415e8d8bef9SDimitry Andric
416349cc55cSDimitry Andricclass I_5_XZ_INS<bits<6> sop, dag outs, dag ins, string op, list<dag> pattern>
417349cc55cSDimitry Andric    : CSKY32Inst<AddrModeNone, 0x31, outs, ins, op #"\t$rz, $rx, $msb, $lsb",
418349cc55cSDimitry Andric                 pattern> {
419349cc55cSDimitry Andric  bits<5> rx;
420349cc55cSDimitry Andric  bits<5> rz;
421349cc55cSDimitry Andric  bits<5> msb;
422349cc55cSDimitry Andric  bits<5> lsb;
423349cc55cSDimitry Andric  let Inst{25 - 21} = rz;
424349cc55cSDimitry Andric  let Inst{20 - 16} = rx;
425349cc55cSDimitry Andric  let Inst{15 - 10} = sop;
426349cc55cSDimitry Andric  let Inst{9 - 5} = msb;
427349cc55cSDimitry Andric  let Inst{4 - 0} = lsb;
428349cc55cSDimitry Andric}
429e8d8bef9SDimitry Andric
430349cc55cSDimitry Andric// Format< OP[6] | LSB[5] | RX[5] | SOP[6] | MSB[5] | RZ[5]>
431349cc55cSDimitry Andric// Instructions(6): zext32, zextb32, zexth32, sext32, sextb32, sexth32
432349cc55cSDimitry Andricclass I_5_XZ_U2<bits<6> sop, bits<5> lsb, bits<5> msb, dag outs, dag ins,
433349cc55cSDimitry Andric  string op, list<dag> pattern>
434349cc55cSDimitry Andric  : CSKY32Inst<AddrModeNone, 0x31, outs, ins, !strconcat(op, "\t$rz, $rx"), pattern> {
435349cc55cSDimitry Andric  bits<5> rx;
436349cc55cSDimitry Andric  bits<5> rz;
437349cc55cSDimitry Andric  let Inst{25 - 21} = lsb;     // lsb
438349cc55cSDimitry Andric  let Inst{20 - 16} = rx;
439349cc55cSDimitry Andric  let Inst{15 - 10} = sop;
440349cc55cSDimitry Andric  let Inst{9 - 5} = msb;       // msb
441349cc55cSDimitry Andric  let Inst{4 - 0} = rz;
442349cc55cSDimitry Andric}
443e8d8bef9SDimitry Andric
444e8d8bef9SDimitry Andric// Format< OP[6] | RZ[5] | RX[5] | SOP[6] | SIZE[5] | LSB[5]>
445e8d8bef9SDimitry Andric// Instructions(1): ins32
446e8d8bef9SDimitry Andricclass I_5_ZX_U<bits<6> sop, string op, Operand operand, list<dag> pattern>
447e8d8bef9SDimitry Andric    : CSKY32Inst<AddrModeNone, 0x31, (outs GPR:$rz), (ins operand:$size_lsb),
448e8d8bef9SDimitry Andric                 !strconcat(op, "\t$rz, operand:$size_lsb"), pattern> {
449e8d8bef9SDimitry Andric  bits<10> size_lsb;
450e8d8bef9SDimitry Andric  bits<5> rz;
451e8d8bef9SDimitry Andric  bits<5> rx;
452e8d8bef9SDimitry Andric  let Inst{25 - 21} = rz;
453e8d8bef9SDimitry Andric  let Inst{20 - 16} = rx;
454e8d8bef9SDimitry Andric  let Inst{15 - 10} = sop;
455e8d8bef9SDimitry Andric  let Inst{9 - 5} = size_lsb{9 - 5}; // size
456e8d8bef9SDimitry Andric  let Inst{4 - 0} = size_lsb{4 - 0}; // lsb
457e8d8bef9SDimitry Andric}
458e8d8bef9SDimitry Andric
459349cc55cSDimitry Andric// sextb, sexth
460349cc55cSDimitry Andricclass I_5_XZ_US<bits<6> sop, bits<5> lsb, bits<5> msb, string op,
461349cc55cSDimitry Andric  SDNode opnode, ValueType type>
462349cc55cSDimitry Andric  : I_5_XZ_U2<sop, lsb, msb, (outs GPR:$rz), (ins GPR:$rx), op,
463349cc55cSDimitry Andric  [(set GPR:$rz, (opnode GPR:$rx, type))]>;
464349cc55cSDimitry Andric
465349cc55cSDimitry Andricclass I_5_XZ_UZ<bits<6> sop, bits<5> lsb, bits<5> msb, string op, int v>
466349cc55cSDimitry Andric  : I_5_XZ_U2<sop, lsb, msb, (outs GPR:$rz), (ins GPR:$rx), op,
467349cc55cSDimitry Andric  [(set GPR:$rz, (and GPR:$rx, (i32 v)))]>;
468349cc55cSDimitry Andric
469e8d8bef9SDimitry Andric// Format< OP[6] | IMM[5] | RX[5] | SOP[6] | PCODE[5] | 00000 >
470e8d8bef9SDimitry Andric// Instructions(1): btsti32
471e8d8bef9SDimitry Andricclass I_5_X<bits<6> sop, bits<5> pcode, string op, ImmLeaf ImmType,
472e8d8bef9SDimitry Andric            list<dag> pattern>
473e8d8bef9SDimitry Andric    : CSKY32Inst<AddrModeNone, 0x31,
474e8d8bef9SDimitry Andric    (outs CARRY:$ca), (ins GPR:$rx, ImmType:$imm5),
475e8d8bef9SDimitry Andric    !strconcat(op, "\t$rx, $imm5"), pattern> {
476e8d8bef9SDimitry Andric  bits<5> imm5;
477e8d8bef9SDimitry Andric  bits<5> rx;
478e8d8bef9SDimitry Andric  let Inst{25 - 21} = imm5;
479e8d8bef9SDimitry Andric  let Inst{20 - 16} = rx;
480e8d8bef9SDimitry Andric  let Inst{15 - 10} = sop;
481e8d8bef9SDimitry Andric  let Inst{9 - 5} = pcode;
482e8d8bef9SDimitry Andric  let Inst{4 - 0} = 0;
483e8d8bef9SDimitry Andric  let isCompare = 1;
484e8d8bef9SDimitry Andric}
485e8d8bef9SDimitry Andric
486e8d8bef9SDimitry Andric// Format< OP[6] | IMM[5] | 00000[5] | SOP[6] | PCODE[5] | RZ[5]>
487e8d8bef9SDimitry Andric// Instructions(1): bmaski32
488e8d8bef9SDimitry Andricclass I_5_Z<bits<6> sop, bits<5> pcode, string op, ImmLeaf ImmType,
489e8d8bef9SDimitry Andric            list<dag> pattern>
490e8d8bef9SDimitry Andric    : CSKY32Inst<AddrModeNone, 0x31, (outs GPR:$rz), (ins ImmType:$imm5),
491e8d8bef9SDimitry Andric                 !strconcat(op, "\t$rz, $imm5"), pattern> {
492e8d8bef9SDimitry Andric  bits<5> imm5;
493e8d8bef9SDimitry Andric  bits<5> rz;
494e8d8bef9SDimitry Andric  let Inst{25 - 21} = imm5;
495e8d8bef9SDimitry Andric  let Inst{20 - 16} = 0;
496e8d8bef9SDimitry Andric  let Inst{15 - 10} = sop;
497e8d8bef9SDimitry Andric  let Inst{9 - 5} = pcode;
498e8d8bef9SDimitry Andric  let Inst{4 - 0} = rz;
499e8d8bef9SDimitry Andric}
500e8d8bef9SDimitry Andric
501349cc55cSDimitry Andricclass I_5_IMM5<bits<6> opcode, bits<6> sop, bits<5> pcode, string op, ImmLeaf ImmType,
502349cc55cSDimitry Andric            list<dag> pattern>
503349cc55cSDimitry Andric    : CSKY32Inst<AddrModeNone, opcode, (outs), (ins ImmType:$imm5),
504349cc55cSDimitry Andric                 !strconcat(op, "\t$imm5"), pattern> {
505349cc55cSDimitry Andric  bits<5> imm5;
506349cc55cSDimitry Andric  let Inst{25 - 21} = imm5;
507349cc55cSDimitry Andric  let Inst{20 - 16} = 0;
508349cc55cSDimitry Andric  let Inst{15 - 10} = sop;
509349cc55cSDimitry Andric  let Inst{9 - 5} = pcode;
510349cc55cSDimitry Andric  let Inst{4 - 0} = 0;
511349cc55cSDimitry Andric}
512349cc55cSDimitry Andric
513e8d8bef9SDimitry Andric// Format< OP[6] | RY[5] | RX[5] | SOP[6] | PCODE[5] | RZ[5] >
514e8d8bef9SDimitry Andric// Instructions(24): addu32, addc32, subu32, subc32, (rsub32), ixh32, ixw32,
515e8d8bef9SDimitry Andric// ixd32, and32, andn32, or32, xor32, nor32, lsl32, lsr32, asr32, rotl32
516e8d8bef9SDimitry Andric// mult32, divu32, divs32, mul.(u/s)32, mula.32.l, mula.u32, mulall.s16.s
517e8d8bef9SDimitry Andricclass R_YXZ<bits<6> opcode, bits<6> sop, bits<5> pcode, dag outs, dag ins,
518e8d8bef9SDimitry Andric            string op, list<dag> pattern>
519e8d8bef9SDimitry Andric    : CSKY32Inst<AddrModeNone, opcode, outs, ins,
520e8d8bef9SDimitry Andric                 !strconcat(op, "\t$rz, $rx, $ry"), pattern> {
521e8d8bef9SDimitry Andric  bits<5> ry;
522e8d8bef9SDimitry Andric  bits<5> rx;
523e8d8bef9SDimitry Andric  bits<5> rz;
524e8d8bef9SDimitry Andric  let Inst{25 - 21} = ry;
525e8d8bef9SDimitry Andric  let Inst{20 - 16} = rx;
526e8d8bef9SDimitry Andric  let Inst{15 - 10} = sop;
527e8d8bef9SDimitry Andric  let Inst{9 - 5} = pcode;
528e8d8bef9SDimitry Andric  let Inst{4 - 0} = rz;
529e8d8bef9SDimitry Andric}
530e8d8bef9SDimitry Andric
531e8d8bef9SDimitry Andric// R_YXZ instructions with simple pattern
532e8d8bef9SDimitry Andric// Output: GPR:rz
533e8d8bef9SDimitry Andric// Input: GPR:rx, GPR:ry
534e8d8bef9SDimitry Andric// Asm string: op rz, rx, ry
535e8d8bef9SDimitry Andric// Instructions: addu32, subu32, ixh32, ixw32, ixd32, and32, andn32, or32,
536e8d8bef9SDimitry Andric// xor32, nor32, lsl32, lsr32, asr32, mult32, divu32, divs32
537e8d8bef9SDimitry Andricclass R_YXZ_SP_F1<bits<6> sop, bits<5> pcode, PatFrag opnode, string op,
538e8d8bef9SDimitry Andric  bit Commutable = 0> : R_YXZ<0x31, sop, pcode, (outs GPR:$rz),
539e8d8bef9SDimitry Andric  (ins GPR:$rx, GPR:$ry), op, [(set GPR:$rz, (opnode GPR:$rx, GPR:$ry))]> {
540e8d8bef9SDimitry Andric  let isCommutable = Commutable;
541e8d8bef9SDimitry Andric}
542e8d8bef9SDimitry Andric
543e8d8bef9SDimitry Andric// Format< OP[6] | RY[5] | RX[5] | SOP[6] | PCODE[5] | RZ[5] >
544e8d8bef9SDimitry Andric// Instructions:(8) ldr32.b, ldr32.h, ldr32.bs, ldr32.hs, ldr32.w,
545e8d8bef9SDimitry Andric//                  str32.b, str32.h, str32.w
546fe6060f1SDimitry Andricclass R_YXZ_LDST<bits<6> opcode, bits<6> sop, dag outs,
547e8d8bef9SDimitry Andric                 dag ins, string op, list<dag> pattern>
548e8d8bef9SDimitry Andric    : CSKY32Inst<AddrModeNone, opcode, outs, ins,
549fe6060f1SDimitry Andric                 op # "\t$rz, ($rx, $ry << ${imm})", pattern> {
550e8d8bef9SDimitry Andric  bits<5> rx;
551e8d8bef9SDimitry Andric  bits<5> ry;
552e8d8bef9SDimitry Andric  bits<5> rz;
553fe6060f1SDimitry Andric  bits<5> imm;
554e8d8bef9SDimitry Andric  let Inst{25 - 21} = ry; // ry;
555e8d8bef9SDimitry Andric  let Inst{20 - 16} = rx; // rx;
556e8d8bef9SDimitry Andric  let Inst{15 - 10} = sop;
557fe6060f1SDimitry Andric  let Inst{9 - 5} = imm;  // pcode;
558e8d8bef9SDimitry Andric  let Inst{4 - 0} = rz;
559e8d8bef9SDimitry Andric}
560e8d8bef9SDimitry Andric
561fe6060f1SDimitry Andricclass I_LDR<bits<6> sop, string op> : R_YXZ_LDST<0x34, sop,
562fe6060f1SDimitry Andric  (outs GPR:$rz), (ins GPR:$rx, GPR:$ry, uimm_shift:$imm), op, []>;
563e8d8bef9SDimitry Andric
564fe6060f1SDimitry Andricclass I_STR<bits<6> sop, string op> : R_YXZ_LDST<0x35, sop,
565fe6060f1SDimitry Andric  (outs), (ins GPR:$rz, GPR:$rx, GPR:$ry, uimm_shift:$imm), op, []>;
566e8d8bef9SDimitry Andric
567e8d8bef9SDimitry Andric// Format< OP[6] | RX[5] | RX[5] | SOP[6] | PCODE[5] | RZ[5] >
568e8d8bef9SDimitry Andric// Instructions:(1) not32
569e8d8bef9SDimitry Andricclass R_XXZ<bits<6> sop, bits<5> pcode, dag outs, dag ins, string op,
570e8d8bef9SDimitry Andric            list<dag> pattern>
571e8d8bef9SDimitry Andric    : CSKY32Inst<AddrModeNone, 0x31, outs, ins, !strconcat(op, "\t$rz, $rx"),
572e8d8bef9SDimitry Andric                 pattern> {
573e8d8bef9SDimitry Andric  bits<5> rx;
574e8d8bef9SDimitry Andric  bits<5> rz;
575e8d8bef9SDimitry Andric  let Inst{25 - 21} = rx;
576e8d8bef9SDimitry Andric  let Inst{20 - 16} = rx;
577e8d8bef9SDimitry Andric  let Inst{15 - 10} = sop;
578e8d8bef9SDimitry Andric  let Inst{9 - 5} = pcode;
579e8d8bef9SDimitry Andric  let Inst{4 - 0} = rz;
580e8d8bef9SDimitry Andric}
581e8d8bef9SDimitry Andric
582e8d8bef9SDimitry Andric// Format< OP[6] | RY[5] | RX[5] | SOP[6] | PCODE[5] | 00000[5] >
583e8d8bef9SDimitry Andric// Instructions:(4) cmpne32, cmphs32, cmplt32, tst32
584e8d8bef9SDimitry Andricclass R_YX<bits<6> sop, bits<5> pcode, string op>
585e8d8bef9SDimitry Andric    : CSKY32Inst<AddrModeNone, 0x31, (outs CARRY:$ca),
586e8d8bef9SDimitry Andric                 (ins GPR:$rx, GPR:$ry),
587e8d8bef9SDimitry Andric                 !strconcat(op, "\t$rx, $ry"), []> {
588e8d8bef9SDimitry Andric  bits<5> ry;
589e8d8bef9SDimitry Andric  bits<5> rx;
590e8d8bef9SDimitry Andric  let Inst{25 - 21} = ry;
591e8d8bef9SDimitry Andric  let Inst{20 - 16} = rx;
592e8d8bef9SDimitry Andric  let Inst{15 - 10} = sop;
593e8d8bef9SDimitry Andric  let Inst{9 - 5} = pcode;
594e8d8bef9SDimitry Andric  let Inst{4 - 0} = 0;
595e8d8bef9SDimitry Andric  let isCompare = 1;
596e8d8bef9SDimitry Andric}
597e8d8bef9SDimitry Andric
598e8d8bef9SDimitry Andric// Format< OP[6] | 00000[5] | RX[5] | SOP[6] | PCODE[5] | RZ[5] >
599e8d8bef9SDimitry Andric// Instructions:(12)
600e8d8bef9SDimitry Andric//   mov32, xtrb0.32, xtrb1.32, xtrb2.32, xtrb3.32, brev32, revb32
601e8d8bef9SDimitry Andric//   revh32, abs32, ff0.32, ff1.32, bgenr32
602e8d8bef9SDimitry Andricclass R_XZ<bits<6> sop, bits<5> pcode, string op>
603e8d8bef9SDimitry Andric    : CSKY32Inst<AddrModeNone, 0x31, (outs GPR:$rz), (ins GPR:$rx),
604e8d8bef9SDimitry Andric                 !strconcat(op, "\t$rz, $rx"), []> {
605e8d8bef9SDimitry Andric  bits<5> rx;
606e8d8bef9SDimitry Andric  bits<5> rz;
607e8d8bef9SDimitry Andric  let Inst{25 - 21} = 0;
608e8d8bef9SDimitry Andric  let Inst{20 - 16} = rx;
609e8d8bef9SDimitry Andric  let Inst{15 - 10} = sop;
610e8d8bef9SDimitry Andric  let Inst{9 - 5} = pcode;
611e8d8bef9SDimitry Andric  let Inst{4 - 0} = rz;
612e8d8bef9SDimitry Andric}
613e8d8bef9SDimitry Andric
614e8d8bef9SDimitry Andric// Format< OP[6] | RZ[5] | RX[5] | SOP[6] | PCODE[5] | 00000[5] >
615e8d8bef9SDimitry Andric// Instructions:(2) movf32, movt32
616e8d8bef9SDimitry Andricclass R_ZX<bits<6> sop, bits<5> pcode, string op, list<dag> pattern>
617e8d8bef9SDimitry Andric    : CSKY32Inst<AddrModeNone, 0x31, (outs GPR:$rz),
618e8d8bef9SDimitry Andric                 (ins CARRY:$ca, GPR:$rx, GPR:$false),
619e8d8bef9SDimitry Andric                 !strconcat(op, "\t$rz, $rx"), pattern> {
620e8d8bef9SDimitry Andric  bits<5> rz;
621e8d8bef9SDimitry Andric  bits<5> rx;
622e8d8bef9SDimitry Andric  let Inst{25 - 21} = rz;
623e8d8bef9SDimitry Andric  let Inst{20 - 16} = rx;
624e8d8bef9SDimitry Andric  let Inst{15 - 10} = sop;
625e8d8bef9SDimitry Andric  let Inst{9 - 5} = pcode;
626e8d8bef9SDimitry Andric  let Inst{4 - 0} = 0;
627e8d8bef9SDimitry Andric  let Constraints = "$rz = $false";
628e8d8bef9SDimitry Andric  let isSelect = 1;
629e8d8bef9SDimitry Andric}
630e8d8bef9SDimitry Andric
631e8d8bef9SDimitry Andric// Format< OP[6] | 00000[5] | RX[5] | SOP[6] | PCODE[5] | 00000[5] >
632e8d8bef9SDimitry Andric// Instructions:(1) tstnbz32
633349cc55cSDimitry Andricclass R_X<bits<6> sop, bits<5> pcode, dag outs, dag ins, string op, list<dag> pattern>
634349cc55cSDimitry Andric    : CSKY32Inst<AddrModeNone, 0x31, outs, ins, !strconcat(op, "\t$rx"), pattern> {
635e8d8bef9SDimitry Andric  bits<5> rx;
636e8d8bef9SDimitry Andric  let Inst{25 - 21} = 0;
637e8d8bef9SDimitry Andric  let Inst{20 - 16} = rx;
638e8d8bef9SDimitry Andric  let Inst{15 - 10} = sop;
639e8d8bef9SDimitry Andric  let Inst{9 - 5} = pcode;
640e8d8bef9SDimitry Andric  let Inst{4 - 0} = 0;
641e8d8bef9SDimitry Andric}
642e8d8bef9SDimitry Andric
643e8d8bef9SDimitry Andric// Format< OP[6] | 00000[5] | 00000[5] | SOP[6] | PCODE[5] | RZ[5] >
644e8d8bef9SDimitry Andric// Instructions:(2) mvc32, mvcv32
645e8d8bef9SDimitry Andricclass R_Z_1<bits<6> sop, bits<5> pcode, string op>
646e8d8bef9SDimitry Andric    : CSKY32Inst<AddrModeNone, 0x31, (outs GPR:$rz),
647e8d8bef9SDimitry Andric                 (ins CARRY:$ca), !strconcat(op, "\t$rz"), []> {
648e8d8bef9SDimitry Andric  bits<5> rz;
649e8d8bef9SDimitry Andric  let Inst{25 - 21} = 0;
650e8d8bef9SDimitry Andric  let Inst{20 - 16} = 0;
651e8d8bef9SDimitry Andric  let Inst{15 - 10} = sop;
652e8d8bef9SDimitry Andric  let Inst{9 - 5} = pcode;
653e8d8bef9SDimitry Andric  let Inst{4 - 0} = rz;
654e8d8bef9SDimitry Andric}
655e8d8bef9SDimitry Andric
656e8d8bef9SDimitry Andric// Format< OP[6] | RZ[5] | 00000[5] | SOP[6] | PCODE[5] | 00000[5] >
657e8d8bef9SDimitry Andric// Instructions:(2) clrf32, clrt32
658*81ad6265SDimitry Andricclass R_Z_2<bits<6> sop, bits<5> pcode, string op>
659e8d8bef9SDimitry Andric    : CSKY32Inst<AddrModeNone, 0x31, (outs GPR:$rz),
660e8d8bef9SDimitry Andric    (ins CARRY:$ca, GPR:$false), !strconcat(op, "\t$rz"), []> {
661e8d8bef9SDimitry Andric  bits<5> rz;
662e8d8bef9SDimitry Andric  let Inst{25 - 21} = rz;
663e8d8bef9SDimitry Andric  let Inst{20 - 16} = 0;
664e8d8bef9SDimitry Andric  let Inst{15 - 10} = sop;
665e8d8bef9SDimitry Andric  let Inst{9 - 5} = pcode;
666e8d8bef9SDimitry Andric  let Inst{4 - 0} = 0;
667e8d8bef9SDimitry Andric  let Constraints = "$rz = $false";
668e8d8bef9SDimitry Andric}
669349cc55cSDimitry Andric
670349cc55cSDimitry Andricclass BAR<bits<5> sop, string op, bits<1> signed>
671349cc55cSDimitry Andric  : CSKY32Inst<AddrModeNone, 0x30, (outs), (ins), op, []> {
672349cc55cSDimitry Andric  let Inst{25} = signed;
673349cc55cSDimitry Andric  let Inst{24 - 16} = 0;
674349cc55cSDimitry Andric  let Inst{15 - 5} = 0x421;
675349cc55cSDimitry Andric  let Inst{4 - 0} = sop;
676349cc55cSDimitry Andric  let hasSideEffects = 1;
677349cc55cSDimitry Andric  let mayLoad = 0;
678349cc55cSDimitry Andric  let mayStore = 0;
679349cc55cSDimitry Andric}
680