blob: 3dba7ce30cadeb5017e9b7875f587839af6e1403 [file] [log] [blame]
Akira Hatanaka7d7ee0c2011-09-24 01:40:18 +00001//===- Mips64InstrInfo.td - Mips64 Instruction Information -*- tablegen -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file describes Mips64 instructions.
11//
12//===----------------------------------------------------------------------===//
Akira Hatanakac1179672011-09-28 17:50:27 +000013
14//===----------------------------------------------------------------------===//
Akira Hatanaka7769a772011-09-30 02:08:54 +000015// Mips Operand, Complex Patterns and Transformations Definitions.
16//===----------------------------------------------------------------------===//
17
Akira Hatanaka2a232d82011-12-19 19:44:09 +000018// shamt must fit in 6 bits.
19def immZExt6 : ImmLeaf<i32, [{return Imm == (Imm & 0x3f);}]>;
Akira Hatanaka61e256a2011-09-30 03:18:46 +000020
Kai Nacke6da86e82014-04-04 16:21:59 +000021// Node immediate fits as 10-bit sign extended on target immediate.
22// e.g. seqi, snei
23def immSExt10_64 : PatLeaf<(i64 imm),
24 [{ return isInt<10>(N->getSExtValue()); }]>;
25
Daniel Sanders0fa60412014-06-12 13:39:06 +000026def immZExt16_64 : PatLeaf<(i64 imm),
Simon Dardis5676d062016-04-22 13:19:22 +000027 [{ return isUInt<16>(N->getZExtValue()); }]>;
Daniel Sanders0fa60412014-06-12 13:39:06 +000028
Kai Nacke63072f82015-01-20 16:10:51 +000029def immZExt5_64 : ImmLeaf<i64, [{ return Imm == (Imm & 0x1f); }]>;
30
31// Transformation function: get log2 of low 32 bits of immediate
32def Log2LO : SDNodeXForm<imm, [{
33 return getImm(N, Log2_64((unsigned) N->getZExtValue()));
34}]>;
35
36// Transformation function: get log2 of high 32 bits of immediate
37def Log2HI : SDNodeXForm<imm, [{
38 return getImm(N, Log2_64((unsigned) (N->getZExtValue() >> 32)));
39}]>;
40
41// Predicate: True if immediate is a power of 2 and fits 32 bits
42def PowerOf2LO : PatLeaf<(imm), [{
43 if (N->getValueType(0) == MVT::i64) {
44 uint64_t Imm = N->getZExtValue();
45 return isPowerOf2_64(Imm) && (Imm & 0xffffffff) == Imm;
46 }
47 else
48 return false;
49}]>;
50
51// Predicate: True if immediate is a power of 2 and exceeds 32 bits
52def PowerOf2HI : PatLeaf<(imm), [{
53 if (N->getValueType(0) == MVT::i64) {
54 uint64_t Imm = N->getZExtValue();
55 return isPowerOf2_64(Imm) && (Imm & 0xffffffff00000000) == Imm;
56 }
57 else
58 return false;
59}]>;
60
Vasileios Kalintiris3751d412016-04-13 15:07:45 +000061def assertzext_lt_i32 : PatFrag<(ops node:$src), (assertzext node:$src), [{
62 return cast<VTSDNode>(N->getOperand(1))->getVT().bitsLT(MVT::i32);
63}]>;
64
Akira Hatanaka7769a772011-09-30 02:08:54 +000065//===----------------------------------------------------------------------===//
Akira Hatanaka36036412011-09-29 20:37:56 +000066// Instructions specific format
67//===----------------------------------------------------------------------===//
Akira Hatanaka6781fc12013-08-20 21:08:22 +000068let usesCustomInserter = 1 in {
69 def ATOMIC_LOAD_ADD_I64 : Atomic2Ops<atomic_load_add_64, GPR64>;
70 def ATOMIC_LOAD_SUB_I64 : Atomic2Ops<atomic_load_sub_64, GPR64>;
71 def ATOMIC_LOAD_AND_I64 : Atomic2Ops<atomic_load_and_64, GPR64>;
72 def ATOMIC_LOAD_OR_I64 : Atomic2Ops<atomic_load_or_64, GPR64>;
73 def ATOMIC_LOAD_XOR_I64 : Atomic2Ops<atomic_load_xor_64, GPR64>;
74 def ATOMIC_LOAD_NAND_I64 : Atomic2Ops<atomic_load_nand_64, GPR64>;
75 def ATOMIC_SWAP_I64 : Atomic2Ops<atomic_swap_64, GPR64>;
76 def ATOMIC_CMP_SWAP_I64 : AtomicCmpSwap<atomic_cmp_swap_64, GPR64>;
Akira Hatanaka21cbc252011-11-11 04:14:30 +000077}
78
Akira Hatanaka42543192013-04-30 23:22:09 +000079/// Pseudo instructions for loading and storing accumulator registers.
Simon Dardise661e522016-06-14 09:35:29 +000080let isPseudo = 1, isCodeGenOnly = 1, hasNoSchedulingInfo = 1 in {
Akira Hatanaka6781fc12013-08-20 21:08:22 +000081 def LOAD_ACC128 : Load<"", ACC128>;
82 def STORE_ACC128 : Store<"", ACC128>;
Akira Hatanakac8d85022013-03-30 00:54:52 +000083}
84
Akira Hatanaka36036412011-09-29 20:37:56 +000085//===----------------------------------------------------------------------===//
86// Instruction definition
87//===----------------------------------------------------------------------===//
Akira Hatanaka71928e62012-04-17 18:03:21 +000088let DecoderNamespace = "Mips64" in {
Akira Hatanaka7769a772011-09-30 02:08:54 +000089/// Arithmetic Instructions (ALU Immediate)
Simon Dardise661e522016-06-14 09:35:29 +000090def DADDi : ArithLogicI<"daddi", simm16_64, GPR64Opnd, II_DADDI>,
91 ADDI_FM<0x18>, ISA_MIPS3_NOT_32R6_64R6;
Zlatko Buljan53a037f2016-04-08 07:27:26 +000092let AdditionalPredicates = [NotInMicroMips] in {
93 def DADDiu : StdMMR6Rel, ArithLogicI<"daddiu", simm16_64, GPR64Opnd,
94 II_DADDIU, immSExt16, add>,
95 ADDI_FM<0x19>, IsAsCheapAsAMove, ISA_MIPS3;
96}
Akira Hatanakac7e39982013-08-06 23:01:10 +000097
98let isCodeGenOnly = 1 in {
Vasileios Kalintiris36901dd2016-03-01 20:25:43 +000099def SLTi64 : SetCC_I<"slti", setlt, simm16_64, immSExt16, GPR64Opnd>,
100 SLTI_FM<0xa>;
101def SLTiu64 : SetCC_I<"sltiu", setult, simm16_64, immSExt16, GPR64Opnd>,
102 SLTI_FM<0xb>;
Daniel Sanders306ef072014-01-16 15:57:05 +0000103def ANDi64 : ArithLogicI<"andi", uimm16_64, GPR64Opnd, II_AND, immZExt16, and>,
Akira Hatanakad6445682013-07-31 00:57:41 +0000104 ADDI_FM<0xc>;
Daniel Sanders306ef072014-01-16 15:57:05 +0000105def ORi64 : ArithLogicI<"ori", uimm16_64, GPR64Opnd, II_OR, immZExt16, or>,
Akira Hatanakaab1b715b2012-12-20 03:40:03 +0000106 ADDI_FM<0xd>;
Daniel Sanders306ef072014-01-16 15:57:05 +0000107def XORi64 : ArithLogicI<"xori", uimm16_64, GPR64Opnd, II_XOR, immZExt16, xor>,
Akira Hatanakaab1b715b2012-12-20 03:40:03 +0000108 ADDI_FM<0xe>;
Daniel Sandersf8bb23e2016-02-01 15:13:31 +0000109def LUi64 : LoadUpper<"lui", GPR64Opnd, uimm16_64_relaxed>, LUI_FM;
Akira Hatanakac7e39982013-08-06 23:01:10 +0000110}
Akira Hatanaka7769a772011-09-30 02:08:54 +0000111
Akira Hatanaka36036412011-09-29 20:37:56 +0000112/// Arithmetic Instructions (3-Operand, R-Type)
Zlatko Buljan53a037f2016-04-08 07:27:26 +0000113let AdditionalPredicates = [NotInMicroMips] in {
114 def DADD : StdMMR6Rel, ArithLogicR<"dadd", GPR64Opnd, 1, II_DADD>,
115 ADD_FM<0, 0x2c>, ISA_MIPS3;
116 def DADDu : StdMMR6Rel, ArithLogicR<"daddu", GPR64Opnd, 1, II_DADDU, add>,
117 ADD_FM<0, 0x2d>, ISA_MIPS3;
Zlatko Buljande0bbe62016-04-27 11:31:44 +0000118 def DSUBu : StdMMR6Rel, ArithLogicR<"dsubu", GPR64Opnd, 0, II_DSUBU, sub>, ADD_FM<0, 0x2f>,
119 ISA_MIPS3;
120 def DSUB : StdMMR6Rel, ArithLogicR<"dsub", GPR64Opnd, 0, II_DSUB>, ADD_FM<0, 0x2e>,
121 ISA_MIPS3;
Zlatko Buljan53a037f2016-04-08 07:27:26 +0000122}
Akira Hatanakae2a39e72013-08-06 22:35:29 +0000123
124let isCodeGenOnly = 1 in {
Vasileios Kalintiris36901dd2016-03-01 20:25:43 +0000125def SLT64 : SetCC_R<"slt", setlt, GPR64Opnd>, ADD_FM<0, 0x2a>;
126def SLTu64 : SetCC_R<"sltu", setult, GPR64Opnd>, ADD_FM<0, 0x2b>;
Daniel Sanders980589a2014-01-16 14:27:20 +0000127def AND64 : ArithLogicR<"and", GPR64Opnd, 1, II_AND, and>, ADD_FM<0, 0x24>;
128def OR64 : ArithLogicR<"or", GPR64Opnd, 1, II_OR, or>, ADD_FM<0, 0x25>;
129def XOR64 : ArithLogicR<"xor", GPR64Opnd, 1, II_XOR, xor>, ADD_FM<0, 0x26>;
Akira Hatanaka13e6ccf2013-08-06 23:08:38 +0000130def NOR64 : LogicNOR<"nor", GPR64Opnd>, ADD_FM<0, 0x27>;
Akira Hatanakae2a39e72013-08-06 22:35:29 +0000131}
Akira Hatanaka61e256a2011-09-30 03:18:46 +0000132
133/// Shift Instructions
Hrvoje Vargaaeb1fe82016-05-11 11:17:04 +0000134let AdditionalPredicates = [NotInMicroMips] in {
Hrvoje Vargaf1e0a032016-06-16 07:06:25 +0000135 def DSLL : StdMMR6Rel, shift_rotate_imm<"dsll", uimm6, GPR64Opnd, II_DSLL,
136 shl, immZExt6>,
137 SRA_FM<0x38, 0>, ISA_MIPS3;
Hrvoje Varga24b975d2016-06-27 08:23:28 +0000138 def DSRL : StdMMR6Rel, shift_rotate_imm<"dsrl", uimm6, GPR64Opnd, II_DSRL,
139 srl, immZExt6>,
Daniel Sandersf2056be2014-05-09 13:02:27 +0000140 SRA_FM<0x3a, 0>, ISA_MIPS3;
Hrvoje Vargaf1e0a032016-06-16 07:06:25 +0000141 def DSRA : StdMMR6Rel, shift_rotate_imm<"dsra", uimm6, GPR64Opnd, II_DSRA,
142 sra, immZExt6>,
Daniel Sandersf2056be2014-05-09 13:02:27 +0000143 SRA_FM<0x3b, 0>, ISA_MIPS3;
Hrvoje Vargaf1e0a032016-06-16 07:06:25 +0000144 def DSLLV : StdMMR6Rel, shift_rotate_reg<"dsllv", GPR64Opnd, II_DSLLV, shl>,
145 SRLV_FM<0x14, 0>, ISA_MIPS3;
Hrvoje Vargaf1e0a032016-06-16 07:06:25 +0000146 def DSRAV : StdMMR6Rel, shift_rotate_reg<"dsrav", GPR64Opnd, II_DSRAV, sra>,
Hrvoje Vargaaeb1fe82016-05-11 11:17:04 +0000147 SRLV_FM<0x17, 0>, ISA_MIPS3;
Hrvoje Varga24b975d2016-06-27 08:23:28 +0000148 def DSRLV : StdMMR6Rel, shift_rotate_reg<"dsrlv", GPR64Opnd, II_DSRLV, srl>,
149 SRLV_FM<0x16, 0>, ISA_MIPS3;
Hrvoje Vargaf1e0a032016-06-16 07:06:25 +0000150 def DSLL32 : StdMMR6Rel, shift_rotate_imm<"dsll32", uimm5, GPR64Opnd,
151 II_DSLL32>,
Hrvoje Vargaaeb1fe82016-05-11 11:17:04 +0000152 SRA_FM<0x3c, 0>, ISA_MIPS3;
Hrvoje Varga24b975d2016-06-27 08:23:28 +0000153 def DSRL32 : StdMMR6Rel, shift_rotate_imm<"dsrl32", uimm5, GPR64Opnd,
154 II_DSRL32>,
155 SRA_FM<0x3e, 0>, ISA_MIPS3;
Hrvoje Vargaf1e0a032016-06-16 07:06:25 +0000156 def DSRA32 : StdMMR6Rel, shift_rotate_imm<"dsra32", uimm5, GPR64Opnd,
157 II_DSRA32>,
Hrvoje Vargaaeb1fe82016-05-11 11:17:04 +0000158 SRA_FM<0x3f, 0>, ISA_MIPS3;
Akira Hatanakac7e39982013-08-06 23:01:10 +0000159
Akira Hatanaka7ba8a8d2011-09-30 18:51:46 +0000160// Rotate Instructions
Hrvoje Vargaf1e0a032016-06-16 07:06:25 +0000161 def DROTR : StdMMR6Rel, shift_rotate_imm<"drotr", uimm6, GPR64Opnd, II_DROTR,
162 rotr, immZExt6>,
163 SRA_FM<0x3a, 1>, ISA_MIPS64R2;
164 def DROTRV : StdMMR6Rel, shift_rotate_reg<"drotrv", GPR64Opnd, II_DROTRV,
165 rotr>,
166 SRLV_FM<0x16, 1>, ISA_MIPS64R2;
167 def DROTR32 : StdMMR6Rel, shift_rotate_imm<"drotr32", uimm5, GPR64Opnd,
168 II_DROTR32>,
169 SRA_FM<0x3e, 1>, ISA_MIPS64R2;
170}
Akira Hatanaka7ba8a8d2011-09-30 18:51:46 +0000171
Akira Hatanakabe68f3c2011-10-11 00:27:28 +0000172/// Load and Store Instructions
Jia Liuf54f60f2012-02-28 07:46:26 +0000173/// aligned
Akira Hatanakac7e39982013-08-06 23:01:10 +0000174let isCodeGenOnly = 1 in {
Daniel Sanders0b385ac2014-01-21 15:21:14 +0000175def LB64 : Load<"lb", GPR64Opnd, sextloadi8, II_LB>, LW_FM<0x20>;
176def LBu64 : Load<"lbu", GPR64Opnd, zextloadi8, II_LBU>, LW_FM<0x24>;
177def LH64 : Load<"lh", GPR64Opnd, sextloadi16, II_LH>, LW_FM<0x21>;
178def LHu64 : Load<"lhu", GPR64Opnd, zextloadi16, II_LHU>, LW_FM<0x25>;
179def LW64 : Load<"lw", GPR64Opnd, sextloadi32, II_LW>, LW_FM<0x23>;
Daniel Sanders37463f72014-01-23 10:31:31 +0000180def SB64 : Store<"sb", GPR64Opnd, truncstorei8, II_SB>, LW_FM<0x28>;
181def SH64 : Store<"sh", GPR64Opnd, truncstorei16, II_SH>, LW_FM<0x29>;
182def SW64 : Store<"sw", GPR64Opnd, truncstorei32, II_SW>, LW_FM<0x2b>;
Akira Hatanakac7e39982013-08-06 23:01:10 +0000183}
184
Hrvoje Varga24b975d2016-06-27 08:23:28 +0000185let AdditionalPredicates = [NotInMicroMips] in {
186 def LWu : StdMMR6Rel, MMRel, Load<"lwu", GPR64Opnd, zextloadi32, II_LWU>,
187 LW_FM<0x27>, ISA_MIPS3;
188 def LD : StdMMR6Rel, LoadMemory<"ld", GPR64Opnd, mem_simm16, load, II_LD>,
189 LW_FM<0x37>, ISA_MIPS3;
190 def SD : StdMMR6Rel, StoreMemory<"sd", GPR64Opnd, mem_simm16, store, II_SD>,
191 LW_FM<0x3f>, ISA_MIPS3;
192}
193
194
Akira Hatanakabe68f3c2011-10-11 00:27:28 +0000195
Akira Hatanakaf11571d2012-06-02 00:04:19 +0000196/// load/store left/right
Akira Hatanakac7e39982013-08-06 23:01:10 +0000197let isCodeGenOnly = 1 in {
Daniel Sanders0b385ac2014-01-21 15:21:14 +0000198def LWL64 : LoadLeftRight<"lwl", MipsLWL, GPR64Opnd, II_LWL>, LW_FM<0x22>;
199def LWR64 : LoadLeftRight<"lwr", MipsLWR, GPR64Opnd, II_LWR>, LW_FM<0x26>;
Daniel Sanders37463f72014-01-23 10:31:31 +0000200def SWL64 : StoreLeftRight<"swl", MipsSWL, GPR64Opnd, II_SWL>, LW_FM<0x2a>;
201def SWR64 : StoreLeftRight<"swr", MipsSWR, GPR64Opnd, II_SWR>, LW_FM<0x2e>;
Akira Hatanakac7e39982013-08-06 23:01:10 +0000202}
Jack Carter873c7242013-01-12 01:03:14 +0000203
Daniel Sandersf2056be2014-05-09 13:02:27 +0000204def LDL : LoadLeftRight<"ldl", MipsLDL, GPR64Opnd, II_LDL>, LW_FM<0x1a>,
Daniel Sandersac272632014-05-23 13:18:02 +0000205 ISA_MIPS3_NOT_32R6_64R6;
Daniel Sandersf2056be2014-05-09 13:02:27 +0000206def LDR : LoadLeftRight<"ldr", MipsLDR, GPR64Opnd, II_LDR>, LW_FM<0x1b>,
Daniel Sandersac272632014-05-23 13:18:02 +0000207 ISA_MIPS3_NOT_32R6_64R6;
Daniel Sandersf2056be2014-05-09 13:02:27 +0000208def SDL : StoreLeftRight<"sdl", MipsSDL, GPR64Opnd, II_SDL>, LW_FM<0x2c>,
Daniel Sandersac272632014-05-23 13:18:02 +0000209 ISA_MIPS3_NOT_32R6_64R6;
Daniel Sandersf2056be2014-05-09 13:02:27 +0000210def SDR : StoreLeftRight<"sdr", MipsSDR, GPR64Opnd, II_SDR>, LW_FM<0x2d>,
Daniel Sandersac272632014-05-23 13:18:02 +0000211 ISA_MIPS3_NOT_32R6_64R6;
Akira Hatanakaf11571d2012-06-02 00:04:19 +0000212
Akira Hatanaka21cbc252011-11-11 04:14:30 +0000213/// Load-linked, Store-conditional
Hrvoje Varga24b975d2016-06-27 08:23:28 +0000214let AdditionalPredicates = [NotInMicroMips] in {
215 def LLD : StdMMR6Rel, LLBase<"lld", GPR64Opnd, mem_simm16>, LW_FM<0x34>,
216 ISA_MIPS3_NOT_32R6_64R6;
217}
Daniel Sanders6a803f62014-06-16 13:13:03 +0000218def SCD : SCBase<"scd", GPR64Opnd>, LW_FM<0x3c>, ISA_MIPS3_NOT_32R6_64R6;
Akira Hatanaka21cbc252011-11-11 04:14:30 +0000219
Simon Dardis4fbf76f2016-06-14 11:29:28 +0000220let AdditionalPredicates = [NotInMicroMips],
221 DecoderNamespace = "Mips32_64_PTR64" in {
222def LL64 : LLBase<"ll", GPR32Opnd>, LW_FM<0x30>, PTR_64,
223 ISA_MIPS2_NOT_32R6_64R6;
224def SC64 : SCBase<"sc", GPR32Opnd>, LW_FM<0x38>, PTR_64,
225 ISA_MIPS2_NOT_32R6_64R6;
Simon Dardis57f4ae42016-08-04 09:17:07 +0000226def JR64 : IndirectBranch<"jr", GPR64Opnd>, MTLO_FM<8>, PTR_64;
Simon Dardis4fbf76f2016-06-14 11:29:28 +0000227}
228
Simon Dardis57f4ae42016-08-04 09:17:07 +0000229def JALR64 : JumpLinkReg<"jalr", GPR64Opnd>, JALR_FM;
230
Akira Hatanaka4b6ac982011-10-11 18:49:17 +0000231/// Jump and Branch Instructions
Akira Hatanakac7e39982013-08-06 23:01:10 +0000232let isCodeGenOnly = 1 in {
Daniel Sandersf5a5fbd2014-07-09 10:21:59 +0000233 def BEQ64 : CBranch<"beq", brtarget, seteq, GPR64Opnd>, BEQ_FM<4>;
234 def BNE64 : CBranch<"bne", brtarget, setne, GPR64Opnd>, BEQ_FM<5>;
235 def BGEZ64 : CBranchZero<"bgez", brtarget, setge, GPR64Opnd>, BGEZ_FM<1, 1>;
236 def BGTZ64 : CBranchZero<"bgtz", brtarget, setgt, GPR64Opnd>, BGEZ_FM<7, 0>;
237 def BLEZ64 : CBranchZero<"blez", brtarget, setle, GPR64Opnd>, BGEZ_FM<6, 0>;
238 def BLTZ64 : CBranchZero<"bltz", brtarget, setlt, GPR64Opnd>, BGEZ_FM<1, 0>;
Daniel Sandersf5a5fbd2014-07-09 10:21:59 +0000239 def JALR64Pseudo : JumpLinkRegPseudo<GPR64Opnd, JALR, RA, GPR32Opnd>;
Akira Hatanaka34a32c02013-08-06 22:20:40 +0000240}
241
Simon Dardisea343152016-08-18 13:22:43 +0000242def TAILCALLREG64 : TailCallReg<GPR64Opnd>;
Simon Dardis57f4ae42016-08-04 09:17:07 +0000243
Daniel Sanders338513b2014-07-09 10:16:07 +0000244def PseudoReturn64 : PseudoReturnBase<GPR64Opnd>;
Daniel Sandersf5a5fbd2014-07-09 10:21:59 +0000245def PseudoIndirectBranch64 : PseudoIndirectBranchBase<GPR64Opnd>;
Daniel Sanders338513b2014-07-09 10:16:07 +0000246
Akira Hatanakaa279d9b2011-10-03 20:01:11 +0000247/// Multiply and Divide Instructions.
Zlatko Buljan31c9ebe2016-05-06 08:24:14 +0000248let AdditionalPredicates = [NotInMicroMips] in {
249 def DMULT : Mult<"dmult", II_DMULT, GPR64Opnd, [HI0_64, LO0_64]>,
250 MULT_FM<0, 0x1c>, ISA_MIPS3_NOT_32R6_64R6;
251 def DMULTu : Mult<"dmultu", II_DMULTU, GPR64Opnd, [HI0_64, LO0_64]>,
252 MULT_FM<0, 0x1d>, ISA_MIPS3_NOT_32R6_64R6;
253}
Akira Hatanaka00fcf2e2013-08-08 21:54:26 +0000254def PseudoDMULT : MultDivPseudo<DMULT, ACC128, GPR64Opnd, MipsMult,
Daniel Sanders308181e2014-06-12 10:44:10 +0000255 II_DMULT>, ISA_MIPS3_NOT_32R6_64R6;
Akira Hatanaka00fcf2e2013-08-08 21:54:26 +0000256def PseudoDMULTu : MultDivPseudo<DMULTu, ACC128, GPR64Opnd, MipsMultu,
Daniel Sanders308181e2014-06-12 10:44:10 +0000257 II_DMULTU>, ISA_MIPS3_NOT_32R6_64R6;
Zlatko Buljan58d6a952016-04-13 08:02:26 +0000258let AdditionalPredicates = [NotInMicroMips] in {
259 def DSDIV : Div<"ddiv", II_DDIV, GPR64Opnd, [HI0_64, LO0_64]>,
260 MULT_FM<0, 0x1e>, ISA_MIPS3_NOT_32R6_64R6;
261 def DUDIV : Div<"ddivu", II_DDIVU, GPR64Opnd, [HI0_64, LO0_64]>,
262 MULT_FM<0, 0x1f>, ISA_MIPS3_NOT_32R6_64R6;
263}
Akira Hatanaka00fcf2e2013-08-08 21:54:26 +0000264def PseudoDSDIV : MultDivPseudo<DSDIV, ACC128, GPR64Opnd, MipsDivRem,
Daniel Sanders308181e2014-06-12 10:44:10 +0000265 II_DDIV, 0, 1, 1>, ISA_MIPS3_NOT_32R6_64R6;
Akira Hatanaka00fcf2e2013-08-08 21:54:26 +0000266def PseudoDUDIV : MultDivPseudo<DUDIV, ACC128, GPR64Opnd, MipsDivRemU,
Daniel Sanders308181e2014-06-12 10:44:10 +0000267 II_DDIVU, 0, 1, 1>, ISA_MIPS3_NOT_32R6_64R6;
Akira Hatanakaa279d9b2011-10-03 20:01:11 +0000268
Akira Hatanakac7e39982013-08-06 23:01:10 +0000269let isCodeGenOnly = 1 in {
Daniel Sanders308181e2014-06-12 10:44:10 +0000270def MTHI64 : MoveToLOHI<"mthi", GPR64Opnd, [HI0_64]>, MTLO_FM<0x11>,
271 ISA_MIPS3_NOT_32R6_64R6;
272def MTLO64 : MoveToLOHI<"mtlo", GPR64Opnd, [LO0_64]>, MTLO_FM<0x13>,
273 ISA_MIPS3_NOT_32R6_64R6;
274def MFHI64 : MoveFromLOHI<"mfhi", GPR64Opnd, AC0_64>, MFLO_FM<0x10>,
275 ISA_MIPS3_NOT_32R6_64R6;
276def MFLO64 : MoveFromLOHI<"mflo", GPR64Opnd, AC0_64>, MFLO_FM<0x12>,
277 ISA_MIPS3_NOT_32R6_64R6;
278def PseudoMFHI64 : PseudoMFLOHI<GPR64, ACC128, MipsMFHI>,
279 ISA_MIPS3_NOT_32R6_64R6;
280def PseudoMFLO64 : PseudoMFLOHI<GPR64, ACC128, MipsMFLO>,
281 ISA_MIPS3_NOT_32R6_64R6;
282def PseudoMTLOHI64 : PseudoMTLOHI<ACC128, GPR64>, ISA_MIPS3_NOT_32R6_64R6;
Akira Hatanakacdcc7452011-10-03 19:28:44 +0000283
Akira Hatanaka9f7ec152012-01-24 21:41:09 +0000284/// Sign Ext In Register Instructions.
Daniel Sandersfcea8102014-05-12 12:28:15 +0000285def SEB64 : SignExtInReg<"seb", i8, GPR64Opnd, II_SEB>, SEB_FM<0x10, 0x20>,
286 ISA_MIPS32R2;
287def SEH64 : SignExtInReg<"seh", i16, GPR64Opnd, II_SEH>, SEB_FM<0x18, 0x20>,
288 ISA_MIPS32R2;
Akira Hatanakac7e39982013-08-06 23:01:10 +0000289}
Akira Hatanaka9f7ec152012-01-24 21:41:09 +0000290
Akira Hatanaka48a72ca2011-10-03 21:16:50 +0000291/// Count Leading
Hrvoje Vargaf1e0a032016-06-16 07:06:25 +0000292let AdditionalPredicates = [NotInMicroMips] in {
Simon Dardisf1148202016-08-24 13:00:47 +0000293 def DCLZ : StdMMR6Rel, CountLeading0<"dclz", GPR64Opnd, II_DCLZ>,
294 CLO_FM<0x24>, ISA_MIPS64_NOT_64R6;
295 def DCLO : StdMMR6Rel, CountLeading1<"dclo", GPR64Opnd, II_DCLO>,
296 CLO_FM<0x25>, ISA_MIPS64_NOT_64R6;
Akira Hatanaka48a72ca2011-10-03 21:16:50 +0000297
Akira Hatanaka4706ac92011-12-20 23:56:43 +0000298/// Double Word Swap Bytes/HalfWords
Simon Dardisf1148202016-08-24 13:00:47 +0000299 def DSBH : SubwordSwap<"dsbh", GPR64Opnd, II_DSBH>, SEB_FM<2, 0x24>,
300 ISA_MIPS64R2;
301 def DSHD : SubwordSwap<"dshd", GPR64Opnd, II_DSHD>, SEB_FM<5, 0x24>,
302 ISA_MIPS64R2;
Hrvoje Vargaaeb1fe82016-05-11 11:17:04 +0000303}
Akira Hatanaka4706ac92011-12-20 23:56:43 +0000304
Akira Hatanaka6781fc12013-08-20 21:08:22 +0000305def LEA_ADDiu64 : EffectiveAddress<"daddiu", GPR64Opnd>, LW_FM<0x19>;
Akira Hatanaka6ac2fc42012-12-21 23:21:32 +0000306
Akira Hatanakac7e39982013-08-06 23:01:10 +0000307let isCodeGenOnly = 1 in
Akira Hatanaka85ccf232013-08-08 21:37:32 +0000308def RDHWR64 : ReadHardware<GPR64Opnd, HWRegsOpnd>, RDHWR_FM;
Akira Hatanaka4350c182011-12-07 23:31:26 +0000309
Zoran Jovanovic366783e2015-08-12 12:45:16 +0000310let AdditionalPredicates = [NotInMicroMips] in {
Daniel Sanders611eb822016-02-29 15:26:54 +0000311 // The 'pos + size' constraints are enforced by the code that lowers into
312 // MipsISD::Ext.
313 def DEXT : ExtBase<"dext", GPR64Opnd, uimm5_report_uimm6, uimm5_plus1,
Simon Dardis724e5302016-06-23 09:06:20 +0000314 immZExt5, immZExt5Plus1, MipsExt>, EXT_FM<3>,
315 ISA_MIPS64R2;
Daniel Sanders611eb822016-02-29 15:26:54 +0000316 def DEXTM : ExtBase<"dextm", GPR64Opnd, uimm5, uimm5_plus33, immZExt5,
Simon Dardis724e5302016-06-23 09:06:20 +0000317 immZExt5Plus33, MipsExt>, EXT_FM<1>, ISA_MIPS64R2;
Zlatko Buljan5da2f6c2015-12-21 13:08:58 +0000318 def DEXTU : ExtBase<"dextu", GPR64Opnd, uimm5_plus32, uimm5_plus1,
Simon Dardis724e5302016-06-23 09:06:20 +0000319 immZExt5Plus32, immZExt5Plus1, MipsExt>, EXT_FM<2>,
320 ISA_MIPS64R2;
Hrvoje Varga46458d02016-02-25 12:53:29 +0000321 def DINS : InsBase<"dins", GPR64Opnd, uimm6, uimm5_inssize_plus1, MipsIns>,
Simon Dardis724e5302016-06-23 09:06:20 +0000322 EXT_FM<7>, ISA_MIPS64R2;
Hrvoje Varga46458d02016-02-25 12:53:29 +0000323 def DINSU : InsBase<"dinsu", GPR64Opnd, uimm5_plus32, uimm5_inssize_plus1>,
Simon Dardis724e5302016-06-23 09:06:20 +0000324 EXT_FM<6>, ISA_MIPS64R2;
Hrvoje Varga46458d02016-02-25 12:53:29 +0000325 def DINSM : InsBase<"dinsm", GPR64Opnd, uimm5, uimm5_inssize_plus1>,
Simon Dardis724e5302016-06-23 09:06:20 +0000326 EXT_FM<5>, ISA_MIPS64R2;
Zoran Jovanovic366783e2015-08-12 12:45:16 +0000327}
Akira Hatanaka31213532013-09-07 00:02:02 +0000328
Petar Jovanovicb71386a2017-03-15 13:10:08 +0000329let isCodeGenOnly = 1, AdditionalPredicates = [NotInMicroMips] in {
330 def DEXT64_32 : InstSE<(outs GPR64Opnd:$rt),
331 (ins GPR32Opnd:$rs, uimm5_report_uimm6:$pos,
332 uimm5_plus1:$size),
333 "dext $rt, $rs, $pos, $size", [], II_EXT, FrmR, "dext">,
334 EXT_FM<3>, ISA_MIPS64R2;
335}
336
Jack Carterf4946cf2012-08-07 00:35:22 +0000337let isCodeGenOnly = 1, rs = 0, shamt = 0 in {
Akira Hatanaka13e6ccf2013-08-06 23:08:38 +0000338 def DSLL64_32 : FR<0x00, 0x3c, (outs GPR64:$rd), (ins GPR32:$rt),
Daniel Sanders980589a2014-01-16 14:27:20 +0000339 "dsll\t$rd, $rt, 32", [], II_DSLL>;
Akira Hatanaka13e6ccf2013-08-06 23:08:38 +0000340 def SLL64_32 : FR<0x0, 0x00, (outs GPR64:$rd), (ins GPR32:$rt),
Daniel Sanders980589a2014-01-16 14:27:20 +0000341 "sll\t$rd, $rt, 0", [], II_SLL>;
Akira Hatanaka13e6ccf2013-08-06 23:08:38 +0000342 def SLL64_64 : FR<0x0, 0x00, (outs GPR64:$rd), (ins GPR64:$rt),
Daniel Sanders980589a2014-01-16 14:27:20 +0000343 "sll\t$rd, $rt, 0", [], II_SLL>;
Jack Carterf4946cf2012-08-07 00:35:22 +0000344}
Kai Nacke93fe5e82014-03-20 11:51:58 +0000345
Sasa Stankovice41db2f2014-05-27 18:53:06 +0000346// We need the following pseudo instruction to avoid offset calculation for
Sasa Stankovic7b061a42014-04-30 15:06:25 +0000347// long branches. See the comment in file MipsLongBranch.cpp for detailed
348// explanation.
349
Sasa Stankovic7b061a42014-04-30 15:06:25 +0000350// Expands to: daddiu $dst, $src, %PART($tgt - $baltgt)
Sasa Stankovice41db2f2014-05-27 18:53:06 +0000351// where %PART may be %hi or %lo, depending on the relocation kind
Sasa Stankovic7b061a42014-04-30 15:06:25 +0000352// that $tgt is annotated with.
353def LONG_BRANCH_DADDiu : PseudoSE<(outs GPR64Opnd:$dst),
354 (ins GPR64Opnd:$src, brtarget:$tgt, brtarget:$baltgt), []>;
355
Kai Nacke3adf9b82015-05-28 16:23:16 +0000356// Cavium Octeon cnMIPS instructions
357let DecoderNamespace = "CnMips",
Daniel Sandersf6921302016-03-24 11:40:48 +0000358 // FIXME: The lack of HasStdEnc is probably a bug
359 EncodingPredicates = []<Predicate> in {
Kai Nacke93fe5e82014-03-20 11:51:58 +0000360
361class Count1s<string opstr, RegisterOperand RO>:
362 InstSE<(outs RO:$rd), (ins RO:$rs), !strconcat(opstr, "\t$rd, $rs"),
Kai Nacke13673ac2014-04-02 18:40:43 +0000363 [(set RO:$rd, (ctpop RO:$rs))], II_POP, FrmR, opstr> {
364 let TwoOperandAliasConstraint = "$rd = $rs";
365}
366
Petar Jovanovicb71386a2017-03-15 13:10:08 +0000367class ExtsCins<string opstr, InstrItinClass itin, RegisterOperand RO,
368 PatFrag PosImm, SDPatternOperator Op = null_frag>:
369 InstSE<(outs RO:$rt), (ins RO:$rs, uimm5:$pos, uimm5:$lenm1),
370 !strconcat(opstr, "\t$rt, $rs, $pos, $lenm1"),
371 [(set RO:$rt, (Op RO:$rs, PosImm:$pos, imm:$lenm1))],
Simon Dardisf1148202016-08-24 13:00:47 +0000372 itin, FrmR, opstr> {
Kai Nacke13673ac2014-04-02 18:40:43 +0000373 let TwoOperandAliasConstraint = "$rt = $rs";
374}
Kai Nacke93fe5e82014-03-20 11:51:58 +0000375
376class SetCC64_R<string opstr, PatFrag cond_op> :
377 InstSE<(outs GPR64Opnd:$rd), (ins GPR64Opnd:$rs, GPR64Opnd:$rt),
378 !strconcat(opstr, "\t$rd, $rs, $rt"),
Vasileios Kalintiris36901dd2016-03-01 20:25:43 +0000379 [(set GPR64Opnd:$rd, (zext (cond_op GPR64Opnd:$rs,
380 GPR64Opnd:$rt)))],
Kai Nacke13673ac2014-04-02 18:40:43 +0000381 II_SEQ_SNE, FrmR, opstr> {
382 let TwoOperandAliasConstraint = "$rd = $rs";
383}
Kai Nacke93fe5e82014-03-20 11:51:58 +0000384
Kai Nacke6da86e82014-04-04 16:21:59 +0000385class SetCC64_I<string opstr, PatFrag cond_op>:
386 InstSE<(outs GPR64Opnd:$rt), (ins GPR64Opnd:$rs, simm10_64:$imm10),
387 !strconcat(opstr, "\t$rt, $rs, $imm10"),
Vasileios Kalintiris36901dd2016-03-01 20:25:43 +0000388 [(set GPR64Opnd:$rt, (zext (cond_op GPR64Opnd:$rs,
389 immSExt10_64:$imm10)))],
Kai Nacke6da86e82014-04-04 16:21:59 +0000390 II_SEQI_SNEI, FrmI, opstr> {
391 let TwoOperandAliasConstraint = "$rt = $rs";
392}
393
Kai Nacke63072f82015-01-20 16:10:51 +0000394class CBranchBitNum<string opstr, DAGOperand opnd, PatFrag cond_op,
Daniel Sandersdaa4b6f2015-11-26 16:35:41 +0000395 RegisterOperand RO, Operand ImmOp, bits<64> shift = 1> :
396 InstSE<(outs), (ins RO:$rs, ImmOp:$p, opnd:$offset),
Kai Nacke63072f82015-01-20 16:10:51 +0000397 !strconcat(opstr, "\t$rs, $p, $offset"),
Vasileios Kalintiris36901dd2016-03-01 20:25:43 +0000398 [(brcond (i32 (cond_op (and RO:$rs, (shl shift, immZExt5_64:$p)), 0)),
Daniel Sanders86cce702015-09-22 13:36:28 +0000399 bb:$offset)], II_BBIT, FrmI, opstr> {
Kai Nacke63072f82015-01-20 16:10:51 +0000400 let isBranch = 1;
401 let isTerminator = 1;
402 let hasDelaySlot = 1;
403 let Defs = [AT];
404}
405
Simon Dardisf1148202016-08-24 13:00:47 +0000406class MFC2OP<string asmstr, RegisterOperand RO, InstrItinClass itin> :
Kai Nacke3adf9b82015-05-28 16:23:16 +0000407 InstSE<(outs RO:$rt, uimm16:$imm16), (ins),
Simon Dardisf1148202016-08-24 13:00:47 +0000408 !strconcat(asmstr, "\t$rt, $imm16"), [], itin, FrmFR>;
Kai Nacke3adf9b82015-05-28 16:23:16 +0000409
Kai Nacke93fe5e82014-03-20 11:51:58 +0000410// Unsigned Byte Add
Kai Nacke13673ac2014-04-02 18:40:43 +0000411def BADDu : ArithLogicR<"baddu", GPR64Opnd, 1, II_BADDU>,
Daniel Sandersf6921302016-03-24 11:40:48 +0000412 ADD_FM<0x1c, 0x28>, ASE_CNMIPS {
413 let Pattern = [(set GPR64Opnd:$rd,
414 (and (add GPR64Opnd:$rs, GPR64Opnd:$rt), 255))];
415}
Kai Nacke93fe5e82014-03-20 11:51:58 +0000416
Kai Nacke63072f82015-01-20 16:10:51 +0000417// Branch on Bit Clear /+32
Daniel Sandersdaa4b6f2015-11-26 16:35:41 +0000418def BBIT0 : CBranchBitNum<"bbit0", brtarget, seteq, GPR64Opnd,
Daniel Sandersf6921302016-03-24 11:40:48 +0000419 uimm5_64_report_uimm6>, BBIT_FM<0x32>, ASE_CNMIPS;
Daniel Sandersdaa4b6f2015-11-26 16:35:41 +0000420def BBIT032: CBranchBitNum<"bbit032", brtarget, seteq, GPR64Opnd, uimm5_64,
Daniel Sandersf6921302016-03-24 11:40:48 +0000421 0x100000000>, BBIT_FM<0x36>, ASE_CNMIPS;
Kai Nacke63072f82015-01-20 16:10:51 +0000422
423// Branch on Bit Set /+32
Daniel Sandersdaa4b6f2015-11-26 16:35:41 +0000424def BBIT1 : CBranchBitNum<"bbit1", brtarget, setne, GPR64Opnd,
Daniel Sandersf6921302016-03-24 11:40:48 +0000425 uimm5_64_report_uimm6>, BBIT_FM<0x3a>, ASE_CNMIPS;
Daniel Sandersdaa4b6f2015-11-26 16:35:41 +0000426def BBIT132: CBranchBitNum<"bbit132", brtarget, setne, GPR64Opnd, uimm5_64,
Daniel Sandersf6921302016-03-24 11:40:48 +0000427 0x100000000>, BBIT_FM<0x3e>, ASE_CNMIPS;
Kai Nacke63072f82015-01-20 16:10:51 +0000428
Kai Nacke93fe5e82014-03-20 11:51:58 +0000429// Multiply Doubleword to GPR
Kai Nacke93fe5e82014-03-20 11:51:58 +0000430def DMUL : ArithLogicR<"dmul", GPR64Opnd, 1, II_DMUL, mul>,
Daniel Sandersf6921302016-03-24 11:40:48 +0000431 ADD_FM<0x1c, 0x03>, ASE_CNMIPS {
432 let Defs = [HI0, LO0, P0, P1, P2];
433}
Kai Nacke93fe5e82014-03-20 11:51:58 +0000434
Petar Jovanovicb71386a2017-03-15 13:10:08 +0000435let AdditionalPredicates = [NotInMicroMips] in {
436 // Extract a signed bit field /+32
437 def EXTS : ExtsCins<"exts", II_EXT, GPR64Opnd, immZExt5>, EXTS_FM<0x3a>,
438 ASE_MIPS64_CNMIPS;
439 def EXTS32: ExtsCins<"exts32", II_EXT, GPR64Opnd, immZExt5Plus32>,
440 EXTS_FM<0x3b>, ASE_MIPS64_CNMIPS;
Kai Nacke13673ac2014-04-02 18:40:43 +0000441
Petar Jovanovicb71386a2017-03-15 13:10:08 +0000442 // Clear and insert a bit field /+32
443 def CINS : ExtsCins<"cins", II_INS, GPR64Opnd, immZExt5, MipsCIns>,
444 EXTS_FM<0x32>, ASE_MIPS64_CNMIPS;
445 def CINS32: ExtsCins<"cins32", II_INS, GPR64Opnd, immZExt5Plus32, MipsCIns>,
446 EXTS_FM<0x33>, ASE_MIPS64_CNMIPS;
447 let isCodeGenOnly = 1 in {
448 def CINS_i32 : ExtsCins<"cins", II_INS, GPR32Opnd, immZExt5, MipsCIns>,
449 EXTS_FM<0x32>, ASE_MIPS64_CNMIPS;
450 def CINS64_32 :InstSE<(outs GPR64Opnd:$rt),
451 (ins GPR32Opnd:$rs, uimm5:$pos, uimm5:$lenm1),
452 "cins\t$rt, $rs, $pos, $lenm1", [], II_INS, FrmR,
453 "cins">,
454 EXTS_FM<0x32>, ASE_MIPS64_CNMIPS;
455 }
456}
Kai Nacke13673ac2014-04-02 18:40:43 +0000457
Kai Nackeaf47f602014-04-01 18:35:26 +0000458// Move to multiplier/product register
Daniel Sandersf6921302016-03-24 11:40:48 +0000459def MTM0 : MoveToLOHI<"mtm0", GPR64Opnd, [MPL0, P0, P1, P2]>, MTMR_FM<0x08>,
460 ASE_CNMIPS;
461def MTM1 : MoveToLOHI<"mtm1", GPR64Opnd, [MPL1, P0, P1, P2]>, MTMR_FM<0x0c>,
462 ASE_CNMIPS;
463def MTM2 : MoveToLOHI<"mtm2", GPR64Opnd, [MPL2, P0, P1, P2]>, MTMR_FM<0x0d>,
464 ASE_CNMIPS;
465def MTP0 : MoveToLOHI<"mtp0", GPR64Opnd, [P0]>, MTMR_FM<0x09>, ASE_CNMIPS;
466def MTP1 : MoveToLOHI<"mtp1", GPR64Opnd, [P1]>, MTMR_FM<0x0a>, ASE_CNMIPS;
467def MTP2 : MoveToLOHI<"mtp2", GPR64Opnd, [P2]>, MTMR_FM<0x0b>, ASE_CNMIPS;
Kai Nackeaf47f602014-04-01 18:35:26 +0000468
Kai Nacke93fe5e82014-03-20 11:51:58 +0000469// Count Ones in a Word/Doubleword
Daniel Sandersf6921302016-03-24 11:40:48 +0000470def POP : Count1s<"pop", GPR32Opnd>, POP_FM<0x2c>, ASE_CNMIPS;
471def DPOP : Count1s<"dpop", GPR64Opnd>, POP_FM<0x2d>, ASE_CNMIPS;
Kai Nacke93fe5e82014-03-20 11:51:58 +0000472
473// Set on equal/not equal
Daniel Sandersf6921302016-03-24 11:40:48 +0000474def SEQ : SetCC64_R<"seq", seteq>, SEQ_FM<0x2a>, ASE_CNMIPS;
475def SEQi : SetCC64_I<"seqi", seteq>, SEQI_FM<0x2e>, ASE_CNMIPS;
476def SNE : SetCC64_R<"sne", setne>, SEQ_FM<0x2b>, ASE_CNMIPS;
477def SNEi : SetCC64_I<"snei", setne>, SEQI_FM<0x2f>, ASE_CNMIPS;
Kai Nacke6da86e82014-04-04 16:21:59 +0000478
Matheus Almeida583a13c2014-04-24 16:31:10 +0000479// 192-bit x 64-bit Unsigned Multiply and Add
Daniel Sandersf6921302016-03-24 11:40:48 +0000480def V3MULU: ArithLogicR<"v3mulu", GPR64Opnd, 0, II_DMUL>, ADD_FM<0x1c, 0x11>,
481 ASE_CNMIPS {
482 let Defs = [P0, P1, P2];
483}
Kai Nacke6da86e82014-04-04 16:21:59 +0000484
485// 64-bit Unsigned Multiply and Add Move
Daniel Sandersf6921302016-03-24 11:40:48 +0000486def VMM0 : ArithLogicR<"vmm0", GPR64Opnd, 0, II_DMUL>, ADD_FM<0x1c, 0x10>,
487 ASE_CNMIPS {
488 let Defs = [MPL0, P0, P1, P2];
489}
Kai Nacke6da86e82014-04-04 16:21:59 +0000490
491// 64-bit Unsigned Multiply and Add
Daniel Sandersf6921302016-03-24 11:40:48 +0000492def VMULU : ArithLogicR<"vmulu", GPR64Opnd, 0, II_DMUL>, ADD_FM<0x1c, 0x0f>,
493 ASE_CNMIPS {
494 let Defs = [MPL1, MPL2, P0, P1, P2];
495}
Kai Nacke6da86e82014-04-04 16:21:59 +0000496
Kai Nacke3adf9b82015-05-28 16:23:16 +0000497// Move between CPU and coprocessor registers
Simon Dardisf1148202016-08-24 13:00:47 +0000498def DMFC2_OCTEON : MFC2OP<"dmfc2", GPR64Opnd, II_DMFC2>, MFC2OP_FM<0x12, 1>,
499 ASE_CNMIPS;
500def DMTC2_OCTEON : MFC2OP<"dmtc2", GPR64Opnd, II_DMTC2>, MFC2OP_FM<0x12, 5>,
501 ASE_CNMIPS;
Kai Nacke93fe5e82014-03-20 11:51:58 +0000502}
503
Akira Hatanaka71928e62012-04-17 18:03:21 +0000504}
Kai Nacke13673ac2014-04-02 18:40:43 +0000505
Toma Tabacua90f1442015-02-24 11:52:19 +0000506/// Move between CPU and coprocessor registers
507let DecoderNamespace = "Mips64", Predicates = [HasMips64] in {
Simon Dardise661e522016-06-14 09:35:29 +0000508def DMFC0 : MFC3OP<"dmfc0", GPR64Opnd, COP0Opnd, II_DMFC0>, MFC3OP_FM<0x10, 1>,
509 ISA_MIPS3;
510def DMTC0 : MTC3OP<"dmtc0", COP0Opnd, GPR64Opnd, II_DMTC0>, MFC3OP_FM<0x10, 5>,
511 ISA_MIPS3;
512def DMFC2 : MFC3OP<"dmfc2", GPR64Opnd, COP2Opnd, II_DMFC2>, MFC3OP_FM<0x12, 1>,
513 ISA_MIPS3;
514def DMTC2 : MTC3OP<"dmtc2", COP2Opnd, GPR64Opnd, II_DMTC2>, MFC3OP_FM<0x12, 5>,
515 ISA_MIPS3;
Toma Tabacua90f1442015-02-24 11:52:19 +0000516}
517
Akira Hatanaka7ba8a8d2011-09-30 18:51:46 +0000518//===----------------------------------------------------------------------===//
519// Arbitrary patterns that map to one or more instructions
520//===----------------------------------------------------------------------===//
521
Simon Dardis61897522016-07-25 09:57:28 +0000522// Materialize i64 constants.
523defm : MaterializeImms<i64, ZERO_64, DADDiu, LUi64, ORi64>;
524
525def : MipsPat<(i64 immZExt32Low16Zero:$imm),
526 (DSLL (ORi64 ZERO_64, (HI16 imm:$imm)), 16)>;
527
528def : MipsPat<(i64 immZExt32:$imm),
529 (ORi64 (DSLL (ORi64 ZERO_64, (HI16 imm:$imm)), 16),
530 (LO16 imm:$imm))>;
531
Akira Hatanakaf93b3f42011-11-14 19:06:14 +0000532// extended loads
Daniel Sandersf5625822014-04-29 16:24:10 +0000533def : MipsPat<(i64 (extloadi1 addr:$src)), (LB64 addr:$src)>;
534def : MipsPat<(i64 (extloadi8 addr:$src)), (LB64 addr:$src)>;
535def : MipsPat<(i64 (extloadi16 addr:$src)), (LH64 addr:$src)>;
536def : MipsPat<(i64 (extloadi32 addr:$src)), (LW64 addr:$src)>;
Akira Hatanaka09b23eb2011-10-11 00:55:05 +0000537
538// hi/lo relocs
Simon Dardisca74dd72017-01-27 11:36:52 +0000539let AdditionalPredicates = [NotInMicroMips] in
540defm : MipsHiLoRelocs<LUi64, DADDiu, ZERO_64, GPR64Opnd>, SYM_32;
Akira Hatanaka7b8547c2011-11-16 22:39:56 +0000541
Simon Dardisca74dd72017-01-27 11:36:52 +0000542def : MipsPat<(MipsGotHi tglobaladdr:$in), (LUi64 tglobaladdr:$in)>;
543def : MipsPat<(MipsGotHi texternalsym:$in), (LUi64 texternalsym:$in)>;
Akira Hatanaka7b8547c2011-11-16 22:39:56 +0000544
Simon Dardisca74dd72017-01-27 11:36:52 +0000545multiclass MipsHighestHigherHiLoRelocs<Instruction Lui, Instruction Daddiu> {
546 def : MipsPat<(MipsJmpLink (i64 texternalsym:$dst)),
547 (JAL texternalsym:$dst)>;
548 def : MipsPat<(MipsHighest (i64 tglobaladdr:$in)),
549 (Lui tglobaladdr:$in)>;
550 def : MipsPat<(MipsHighest (i64 tblockaddress:$in)),
551 (Lui tblockaddress:$in)>;
552 def : MipsPat<(MipsHighest (i64 tjumptable:$in)),
553 (Lui tjumptable:$in)>;
554 def : MipsPat<(MipsHighest (i64 tconstpool:$in)),
555 (Lui tconstpool:$in)>;
556 def : MipsPat<(MipsHighest (i64 tglobaltlsaddr:$in)),
557 (Lui tglobaltlsaddr:$in)>;
558 def : MipsPat<(MipsHighest (i64 texternalsym:$in)),
559 (Lui texternalsym:$in)>;
Akira Hatanakaf75add62011-10-11 18:53:46 +0000560
Simon Dardisca74dd72017-01-27 11:36:52 +0000561 def : MipsPat<(MipsHigher (i64 tglobaladdr:$in)),
562 (Daddiu ZERO_64, tglobaladdr:$in)>;
563 def : MipsPat<(MipsHigher (i64 tblockaddress:$in)),
564 (Daddiu ZERO_64, tblockaddress:$in)>;
565 def : MipsPat<(MipsHigher (i64 tjumptable:$in)),
566 (Daddiu ZERO_64, tjumptable:$in)>;
567 def : MipsPat<(MipsHigher (i64 tconstpool:$in)),
568 (Daddiu ZERO_64, tconstpool:$in)>;
569 def : MipsPat<(MipsHigher (i64 tglobaltlsaddr:$in)),
570 (Daddiu ZERO_64, tglobaltlsaddr:$in)>;
571 def : MipsPat<(MipsHigher (i64 texternalsym:$in)),
572 (Daddiu ZERO_64, texternalsym:$in)>;
573
574 def : MipsPat<(add GPR64:$hi, (MipsHigher (i64 tglobaladdr:$lo))),
575 (Daddiu GPR64:$hi, tglobaladdr:$lo)>;
576 def : MipsPat<(add GPR64:$hi, (MipsHigher (i64 tblockaddress:$lo))),
577 (Daddiu GPR64:$hi, tblockaddress:$lo)>;
578 def : MipsPat<(add GPR64:$hi, (MipsHigher (i64 tjumptable:$lo))),
579 (Daddiu GPR64:$hi, tjumptable:$lo)>;
580 def : MipsPat<(add GPR64:$hi, (MipsHigher (i64 tconstpool:$lo))),
581 (Daddiu GPR64:$hi, tconstpool:$lo)>;
582 def : MipsPat<(add GPR64:$hi, (MipsHigher (i64 tglobaltlsaddr:$lo))),
583 (Daddiu GPR64:$hi, tglobaltlsaddr:$lo)>;
584
585 def : MipsPat<(add GPR64:$hi, (MipsHi (i64 tglobaladdr:$lo))),
586 (Daddiu GPR64:$hi, tglobaladdr:$lo)>;
587 def : MipsPat<(add GPR64:$hi, (MipsHi (i64 tblockaddress:$lo))),
588 (Daddiu GPR64:$hi, tblockaddress:$lo)>;
589 def : MipsPat<(add GPR64:$hi, (MipsHi (i64 tjumptable:$lo))),
590 (Daddiu GPR64:$hi, tjumptable:$lo)>;
591 def : MipsPat<(add GPR64:$hi, (MipsHi (i64 tconstpool:$lo))),
592 (Daddiu GPR64:$hi, tconstpool:$lo)>;
593 def : MipsPat<(add GPR64:$hi, (MipsHi (i64 tglobaltlsaddr:$lo))),
594 (Daddiu GPR64:$hi, tglobaltlsaddr:$lo)>;
595
596 def : MipsPat<(add GPR64:$hi, (MipsLo (i64 tglobaladdr:$lo))),
597 (Daddiu GPR64:$hi, tglobaladdr:$lo)>;
598 def : MipsPat<(add GPR64:$hi, (MipsLo (i64 tblockaddress:$lo))),
599 (Daddiu GPR64:$hi, tblockaddress:$lo)>;
600 def : MipsPat<(add GPR64:$hi, (MipsLo (i64 tjumptable:$lo))),
601 (Daddiu GPR64:$hi, tjumptable:$lo)>;
602 def : MipsPat<(add GPR64:$hi, (MipsLo (i64 tconstpool:$lo))),
603 (Daddiu GPR64:$hi, tconstpool:$lo)>;
604 def : MipsPat<(add GPR64:$hi, (MipsLo (i64 tglobaltlsaddr:$lo))),
605 (Daddiu GPR64:$hi, tglobaltlsaddr:$lo)>;
606
Zlatko Buljan53a037f2016-04-08 07:27:26 +0000607}
Akira Hatanakab2e05cb2011-12-07 22:11:43 +0000608
Simon Dardisca74dd72017-01-27 11:36:52 +0000609// highest/higher/hi/lo relocs
610let AdditionalPredicates = [NotInMicroMips] in
611defm : MipsHighestHigherHiLoRelocs<LUi64, DADDiu>, SYM_64;
612
613def : WrapperPat<tglobaladdr, DADDiu, GPR64>;
614def : WrapperPat<tconstpool, DADDiu, GPR64>;
615def : WrapperPat<texternalsym, DADDiu, GPR64>;
616def : WrapperPat<tblockaddress, DADDiu, GPR64>;
617def : WrapperPat<tjumptable, DADDiu, GPR64>;
618def : WrapperPat<tglobaltlsaddr, DADDiu, GPR64>;
619
620
Hrvoje Varga2db00ce2016-07-22 07:18:33 +0000621defm : BrcondPats<GPR64, BEQ64, BEQ, BNE64, SLT64, SLTu64, SLTi64, SLTiu64,
Vasileios Kalintiris36901dd2016-03-01 20:25:43 +0000622 ZERO_64>;
Vasileios Kalintiris36901dd2016-03-01 20:25:43 +0000623def : MipsPat<(brcond (i32 (setlt i64:$lhs, 1)), bb:$dst),
Akira Hatanaka68710312013-05-21 17:13:47 +0000624 (BLEZ64 i64:$lhs, bb:$dst)>;
Vasileios Kalintiris36901dd2016-03-01 20:25:43 +0000625def : MipsPat<(brcond (i32 (setgt i64:$lhs, -1)), bb:$dst),
Akira Hatanaka68710312013-05-21 17:13:47 +0000626 (BGEZ64 i64:$lhs, bb:$dst)>;
627
Akira Hatanakaf75add62011-10-11 18:53:46 +0000628// setcc patterns
Hrvoje Varga2db00ce2016-07-22 07:18:33 +0000629let AdditionalPredicates = [NotInMicroMips] in {
630 defm : SeteqPats<GPR64, SLTiu64, XOR64, SLTu64, ZERO_64>;
631 defm : SetlePats<GPR64, XORi, SLT64, SLTu64>;
632 defm : SetgtPats<GPR64, SLT64, SLTu64>;
633 defm : SetgePats<GPR64, XORi, SLT64, SLTu64>;
634 defm : SetgeImmPats<GPR64, XORi, SLTi64, SLTiu64>;
635}
Akira Hatanakad5c13292011-11-07 18:57:41 +0000636// truncate
Daniel Sandersc43cda82014-11-07 16:54:21 +0000637def : MipsPat<(trunc (assertsext GPR64:$src)),
638 (EXTRACT_SUBREG GPR64:$src, sub_32)>;
Vasileios Kalintiris3751d412016-04-13 15:07:45 +0000639// The forward compatibility strategy employed by MIPS requires us to treat
640// values as being sign extended to an infinite number of bits. This allows
641// existing software to run without modification on any future MIPS
642// implementation (e.g. 128-bit, or 1024-bit). Being compatible with this
643// strategy requires that truncation acts as a sign-extension for values being
644// fed into instructions operating on 32-bit values. Such instructions have
645// undefined results if this is not true.
646// For our case, this means that we can't issue an extract_subreg for nodes
647// such as (trunc:i32 (assertzext:i64 X, i32)), because the sign-bit of the
648// lower subreg would not be replicated into the upper half.
649def : MipsPat<(trunc (assertzext_lt_i32 GPR64:$src)),
Daniel Sandersc43cda82014-11-07 16:54:21 +0000650 (EXTRACT_SUBREG GPR64:$src, sub_32)>;
Akira Hatanaka13e6ccf2013-08-06 23:08:38 +0000651def : MipsPat<(i32 (trunc GPR64:$src)),
Daniel Sanders3dc2c012014-05-07 10:27:09 +0000652 (SLL (EXTRACT_SUBREG GPR64:$src, sub_32), 0)>;
Jia Liuf54f60f2012-02-28 07:46:26 +0000653
Vasileios Kalintiris32177d62015-04-21 10:49:03 +0000654// variable shift instructions patterns
655def : MipsPat<(shl GPR64:$rt, (i32 (trunc GPR64:$rs))),
656 (DSLLV GPR64:$rt, (EXTRACT_SUBREG GPR64:$rs, sub_32))>;
657def : MipsPat<(srl GPR64:$rt, (i32 (trunc GPR64:$rs))),
658 (DSRLV GPR64:$rt, (EXTRACT_SUBREG GPR64:$rs, sub_32))>;
659def : MipsPat<(sra GPR64:$rt, (i32 (trunc GPR64:$rs))),
660 (DSRAV GPR64:$rt, (EXTRACT_SUBREG GPR64:$rs, sub_32))>;
Hrvoje Vargaf1e0a032016-06-16 07:06:25 +0000661let AdditionalPredicates = [NotInMicroMips] in {
662 def : MipsPat<(rotr GPR64:$rt, (i32 (trunc GPR64:$rs))),
663 (DROTRV GPR64:$rt, (EXTRACT_SUBREG GPR64:$rs, sub_32))>;
664}
Vasileios Kalintiris32177d62015-04-21 10:49:03 +0000665
Akira Hatanakaae378af2011-12-07 23:14:41 +0000666// 32-to-64-bit extension
Vasileios Kalintiris29620ac2016-02-29 15:58:12 +0000667def : MipsPat<(i64 (anyext GPR32:$src)),
668 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GPR32:$src, sub_32)>;
Akira Hatanaka13e6ccf2013-08-06 23:08:38 +0000669def : MipsPat<(i64 (zext GPR32:$src)), (DSRL (DSLL64_32 GPR32:$src), 32)>;
670def : MipsPat<(i64 (sext GPR32:$src)), (SLL64_32 GPR32:$src)>;
Akira Hatanaka4e210692011-12-20 22:06:20 +0000671
Petar Jovanovicb71386a2017-03-15 13:10:08 +0000672let AdditionalPredicates = [NotInMicroMips] in {
673 def : MipsPat<(i64 (zext GPR32:$src)), (DEXT64_32 GPR32:$src, 0, 32)>,
674 ISA_MIPS64R2;
675 def : MipsPat<(i64 (zext (i32 (shl GPR32:$rt, immZExt5:$imm)))),
676 (CINS64_32 GPR32:$rt, imm:$imm, (immZExt5To31 imm:$imm))>,
677 ASE_MIPS64_CNMIPS;
678}
679
Akira Hatanaka494fdf12011-12-20 22:40:40 +0000680// Sign extend in register
Akira Hatanaka13e6ccf2013-08-06 23:08:38 +0000681def : MipsPat<(i64 (sext_inreg GPR64:$src, i32)),
682 (SLL64_64 GPR64:$src)>;
Akira Hatanaka494fdf12011-12-20 22:40:40 +0000683
Akira Hatanakad8ab16b2012-06-14 21:03:23 +0000684// bswap MipsPattern
Akira Hatanaka13e6ccf2013-08-06 23:08:38 +0000685def : MipsPat<(bswap GPR64:$rt), (DSHD (DSBH GPR64:$rt))>;
David Chisnall37051252012-10-09 16:27:43 +0000686
Vasileios Kalintirisef96a8e2015-01-26 12:33:22 +0000687// Carry pattern
Zlatko Buljan53a037f2016-04-08 07:27:26 +0000688let AdditionalPredicates = [NotInMicroMips] in {
Zlatko Buljande0bbe62016-04-27 11:31:44 +0000689 def : MipsPat<(subc GPR64:$lhs, GPR64:$rhs),
690 (DSUBu GPR64:$lhs, GPR64:$rhs)>;
Vasileios Kalintirisef96a8e2015-01-26 12:33:22 +0000691 def : MipsPat<(addc GPR64:$lhs, GPR64:$rhs),
Zlatko Buljan53a037f2016-04-08 07:27:26 +0000692 (DADDu GPR64:$lhs, GPR64:$rhs)>, ASE_NOT_DSP;
Vasileios Kalintirisef96a8e2015-01-26 12:33:22 +0000693 def : MipsPat<(addc GPR64:$lhs, immSExt16:$imm),
Zlatko Buljan53a037f2016-04-08 07:27:26 +0000694 (DADDiu GPR64:$lhs, imm:$imm)>, ASE_NOT_DSP;
Vasileios Kalintirisef96a8e2015-01-26 12:33:22 +0000695}
696
Kai Nacke63072f82015-01-20 16:10:51 +0000697// Octeon bbit0/bbit1 MipsPattern
Vasileios Kalintiris36901dd2016-03-01 20:25:43 +0000698def : MipsPat<(brcond (i32 (seteq (and i64:$lhs, PowerOf2LO:$mask), 0)), bb:$dst),
Daniel Sandersf6921302016-03-24 11:40:48 +0000699 (BBIT0 i64:$lhs, (Log2LO PowerOf2LO:$mask), bb:$dst)>, ASE_MIPS64_CNMIPS;
Vasileios Kalintiris36901dd2016-03-01 20:25:43 +0000700def : MipsPat<(brcond (i32 (seteq (and i64:$lhs, PowerOf2HI:$mask), 0)), bb:$dst),
Daniel Sandersf6921302016-03-24 11:40:48 +0000701 (BBIT032 i64:$lhs, (Log2HI PowerOf2HI:$mask), bb:$dst)>, ASE_MIPS64_CNMIPS;
Vasileios Kalintiris36901dd2016-03-01 20:25:43 +0000702def : MipsPat<(brcond (i32 (setne (and i64:$lhs, PowerOf2LO:$mask), 0)), bb:$dst),
Daniel Sandersf6921302016-03-24 11:40:48 +0000703 (BBIT1 i64:$lhs, (Log2LO PowerOf2LO:$mask), bb:$dst)>, ASE_MIPS64_CNMIPS;
Vasileios Kalintiris36901dd2016-03-01 20:25:43 +0000704def : MipsPat<(brcond (i32 (setne (and i64:$lhs, PowerOf2HI:$mask), 0)), bb:$dst),
Daniel Sandersf6921302016-03-24 11:40:48 +0000705 (BBIT132 i64:$lhs, (Log2HI PowerOf2HI:$mask), bb:$dst)>, ASE_MIPS64_CNMIPS;
Kai Nacke63072f82015-01-20 16:10:51 +0000706
Vasileios Kalintirisb04672c2015-11-06 12:07:20 +0000707// Atomic load patterns.
708def : MipsPat<(atomic_load_8 addr:$a), (LB64 addr:$a)>;
709def : MipsPat<(atomic_load_16 addr:$a), (LH64 addr:$a)>;
710def : MipsPat<(atomic_load_32 addr:$a), (LW64 addr:$a)>;
711def : MipsPat<(atomic_load_64 addr:$a), (LD addr:$a)>;
712
713// Atomic store patterns.
714def : MipsPat<(atomic_store_8 addr:$a, GPR64:$v), (SB64 GPR64:$v, addr:$a)>;
715def : MipsPat<(atomic_store_16 addr:$a, GPR64:$v), (SH64 GPR64:$v, addr:$a)>;
716def : MipsPat<(atomic_store_32 addr:$a, GPR64:$v), (SW64 GPR64:$v, addr:$a)>;
717def : MipsPat<(atomic_store_64 addr:$a, GPR64:$v), (SD GPR64:$v, addr:$a)>;
718
David Chisnall37051252012-10-09 16:27:43 +0000719//===----------------------------------------------------------------------===//
720// Instruction aliases
721//===----------------------------------------------------------------------===//
Zlatko Buljan53a037f2016-04-08 07:27:26 +0000722let AdditionalPredicates = [NotInMicroMips] in {
723 def : MipsInstAlias<"move $dst, $src",
724 (OR64 GPR64Opnd:$dst, GPR64Opnd:$src, ZERO_64), 1>,
725 GPR_64;
726 def : MipsInstAlias<"move $dst, $src",
727 (DADDu GPR64Opnd:$dst, GPR64Opnd:$src, ZERO_64), 1>,
728 GPR_64;
729 def : MipsInstAlias<"dadd $rs, $rt, $imm",
730 (DADDi GPR64Opnd:$rs, GPR64Opnd:$rt, simm16_64:$imm),
731 0>, ISA_MIPS3_NOT_32R6_64R6;
732 def : MipsInstAlias<"dadd $rs, $imm",
733 (DADDi GPR64Opnd:$rs, GPR64Opnd:$rs, simm16_64:$imm),
734 0>, ISA_MIPS3_NOT_32R6_64R6;
735 def : MipsInstAlias<"daddu $rs, $rt, $imm",
736 (DADDiu GPR64Opnd:$rs, GPR64Opnd:$rt, simm16_64:$imm),
737 0>, ISA_MIPS3;
738 def : MipsInstAlias<"daddu $rs, $imm",
739 (DADDiu GPR64Opnd:$rs, GPR64Opnd:$rs, simm16_64:$imm),
740 0>, ISA_MIPS3;
Simon Dardisaa208812017-02-24 14:34:32 +0000741
742 defm : OneOrTwoOperandMacroImmediateAlias<"and", ANDi64, GPR64Opnd, imm64>,
743 GPR_64;
744
745 defm : OneOrTwoOperandMacroImmediateAlias<"or", ORi64, GPR64Opnd, imm64>,
746 GPR_64;
747
748 defm : OneOrTwoOperandMacroImmediateAlias<"xor", XORi64, GPR64Opnd, imm64>,
749 GPR_64;
Zlatko Buljan53a037f2016-04-08 07:27:26 +0000750}
Zlatko Buljande0bbe62016-04-27 11:31:44 +0000751let AdditionalPredicates = [NotInMicroMips] in {
752 def : MipsInstAlias<"dneg $rt, $rs",
753 (DSUB GPR64Opnd:$rt, ZERO_64, GPR64Opnd:$rs), 1>,
754 ISA_MIPS3;
755 def : MipsInstAlias<"dneg $rt",
Simon Dardis273fc262016-07-26 09:13:46 +0000756 (DSUB GPR64Opnd:$rt, ZERO_64, GPR64Opnd:$rt), 1>,
Zlatko Buljande0bbe62016-04-27 11:31:44 +0000757 ISA_MIPS3;
758 def : MipsInstAlias<"dnegu $rt, $rs",
759 (DSUBu GPR64Opnd:$rt, ZERO_64, GPR64Opnd:$rs), 1>,
760 ISA_MIPS3;
Simon Dardis273fc262016-07-26 09:13:46 +0000761 def : MipsInstAlias<"dnegu $rt",
762 (DSUBu GPR64Opnd:$rt, ZERO_64, GPR64Opnd:$rt), 1>,
763 ISA_MIPS3;
Zlatko Buljande0bbe62016-04-27 11:31:44 +0000764}
Daniel Sanderse8982362014-06-13 12:49:06 +0000765def : MipsInstAlias<"dsubi $rs, $rt, $imm",
766 (DADDi GPR64Opnd:$rs, GPR64Opnd:$rt,
767 InvertedImOperand64:$imm),
768 0>, ISA_MIPS3_NOT_32R6_64R6;
769def : MipsInstAlias<"dsubi $rs, $imm",
770 (DADDi GPR64Opnd:$rs, GPR64Opnd:$rs,
771 InvertedImOperand64:$imm),
772 0>, ISA_MIPS3_NOT_32R6_64R6;
773def : MipsInstAlias<"dsub $rs, $rt, $imm",
774 (DADDi GPR64Opnd:$rs, GPR64Opnd:$rt,
775 InvertedImOperand64:$imm),
776 0>, ISA_MIPS3_NOT_32R6_64R6;
Daniel Sanders7d290b02014-05-08 16:12:31 +0000777def : MipsInstAlias<"dsub $rs, $imm",
778 (DADDi GPR64Opnd:$rs, GPR64Opnd:$rs,
779 InvertedImOperand64:$imm),
Daniel Sanderse8982362014-06-13 12:49:06 +0000780 0>, ISA_MIPS3_NOT_32R6_64R6;
Zlatko Buljan53a037f2016-04-08 07:27:26 +0000781let AdditionalPredicates = [NotInMicroMips] in {
782 def : MipsInstAlias<"dsubu $rt, $rs, $imm",
783 (DADDiu GPR64Opnd:$rt, GPR64Opnd:$rs,
784 InvertedImOperand64:$imm), 0>, ISA_MIPS3;
785 def : MipsInstAlias<"dsubu $rs, $imm",
786 (DADDiu GPR64Opnd:$rs, GPR64Opnd:$rs,
787 InvertedImOperand64:$imm), 0>, ISA_MIPS3;
788}
Daniel Sanders52bdd652014-05-09 09:24:49 +0000789def : MipsInstAlias<"dsra $rd, $rt, $rs",
Daniel Sandersf2056be2014-05-09 13:02:27 +0000790 (DSRAV GPR64Opnd:$rd, GPR64Opnd:$rt, GPR32Opnd:$rs), 0>,
791 ISA_MIPS3;
Hrvoje Varga24b975d2016-06-27 08:23:28 +0000792let AdditionalPredicates = [NotInMicroMips] in {
Simon Dardis4155c8f2017-06-27 13:35:17 +0000793 def : MipsInstAlias<"dsll $rd, $rt, $rs",
794 (DSLLV GPR64Opnd:$rd, GPR64Opnd:$rt, GPR32Opnd:$rs), 0>,
795 ISA_MIPS3;
Hrvoje Varga24b975d2016-06-27 08:23:28 +0000796 def : MipsInstAlias<"dsrl $rd, $rt, $rs",
797 (DSRLV GPR64Opnd:$rd, GPR64Opnd:$rt, GPR32Opnd:$rs), 0>,
798 ISA_MIPS3;
Simon Dardis4155c8f2017-06-27 13:35:17 +0000799 def : MipsInstAlias<"dsrl $rd, $rt",
800 (DSRLV GPR64Opnd:$rd, GPR64Opnd:$rd, GPR32Opnd:$rt), 0>,
801 ISA_MIPS3;
802 def : MipsInstAlias<"dsll $rd, $rt",
803 (DSLLV GPR64Opnd:$rd, GPR64Opnd:$rd, GPR32Opnd:$rt), 0>,
804 ISA_MIPS3;
Jack Carter86c2c562013-01-18 20:15:06 +0000805
David Chisnall6a00ab42012-10-11 10:21:34 +0000806// Two operand (implicit 0 selector) versions:
Hrvoje Varga2cb74ac2016-03-24 08:02:09 +0000807 def : MipsInstAlias<"dmtc0 $rt, $rd",
808 (DMTC0 COP0Opnd:$rd, GPR64Opnd:$rt, 0), 0>;
Zlatko Buljan6221be82016-03-31 08:51:24 +0000809 def : MipsInstAlias<"dmfc0 $rt, $rd",
810 (DMFC0 GPR64Opnd:$rt, COP0Opnd:$rd, 0), 0>;
Hrvoje Varga2cb74ac2016-03-24 08:02:09 +0000811}
Daniel Sandersa3134fa2015-06-27 15:39:19 +0000812def : MipsInstAlias<"dmfc2 $rt, $rd", (DMFC2 GPR64Opnd:$rt, COP2Opnd:$rd, 0), 0>;
813def : MipsInstAlias<"dmtc2 $rt, $rd", (DMTC2 COP2Opnd:$rd, GPR64Opnd:$rt, 0), 0>;
David Chisnall6a00ab42012-10-11 10:21:34 +0000814
Daniel Sandersf6921302016-03-24 11:40:48 +0000815def : MipsInstAlias<"synciobdma", (SYNC 0x2), 0>, ASE_MIPS64_CNMIPS;
816def : MipsInstAlias<"syncs", (SYNC 0x6), 0>, ASE_MIPS64_CNMIPS;
817def : MipsInstAlias<"syncw", (SYNC 0x4), 0>, ASE_MIPS64_CNMIPS;
818def : MipsInstAlias<"syncws", (SYNC 0x5), 0>, ASE_MIPS64_CNMIPS;
Toma Tabacua90f1442015-02-24 11:52:19 +0000819
Daniel Sandersdaa4b6f2015-11-26 16:35:41 +0000820// cnMIPS Aliases.
821
822// bbit* with $p 32-63 converted to bbit*32 with $p 0-31
823def : MipsInstAlias<"bbit0 $rs, $p, $offset",
824 (BBIT032 GPR64Opnd:$rs, uimm5_plus32_normalize_64:$p,
825 brtarget:$offset), 0>,
826 ASE_CNMIPS;
827def : MipsInstAlias<"bbit1 $rs, $p, $offset",
828 (BBIT132 GPR64Opnd:$rs, uimm5_plus32_normalize_64:$p,
829 brtarget:$offset), 0>,
830 ASE_CNMIPS;
831
832// exts with $pos 32-63 in converted to exts32 with $pos 0-31
833def : MipsInstAlias<"exts $rt, $rs, $pos, $lenm1",
834 (EXTS32 GPR64Opnd:$rt, GPR64Opnd:$rs,
835 uimm5_plus32_normalize:$pos, uimm5:$lenm1), 0>,
Petar Jovanovicb71386a2017-03-15 13:10:08 +0000836 ASE_MIPS64_CNMIPS;
Daniel Sandersdaa4b6f2015-11-26 16:35:41 +0000837def : MipsInstAlias<"exts $rt, $pos, $lenm1",
838 (EXTS32 GPR64Opnd:$rt, GPR64Opnd:$rt,
839 uimm5_plus32_normalize:$pos, uimm5:$lenm1), 0>,
Petar Jovanovicb71386a2017-03-15 13:10:08 +0000840 ASE_MIPS64_CNMIPS;
Daniel Sandersdaa4b6f2015-11-26 16:35:41 +0000841
842// cins with $pos 32-63 in converted to cins32 with $pos 0-31
843def : MipsInstAlias<"cins $rt, $rs, $pos, $lenm1",
844 (CINS32 GPR64Opnd:$rt, GPR64Opnd:$rs,
845 uimm5_plus32_normalize:$pos, uimm5:$lenm1), 0>,
Petar Jovanovicb71386a2017-03-15 13:10:08 +0000846 ASE_MIPS64_CNMIPS;
Daniel Sandersdaa4b6f2015-11-26 16:35:41 +0000847def : MipsInstAlias<"cins $rt, $pos, $lenm1",
848 (CINS32 GPR64Opnd:$rt, GPR64Opnd:$rt,
849 uimm5_plus32_normalize:$pos, uimm5:$lenm1), 0>,
Petar Jovanovicb71386a2017-03-15 13:10:08 +0000850 ASE_MIPS64_CNMIPS;
Daniel Sandersdaa4b6f2015-11-26 16:35:41 +0000851
Toma Tabacua90f1442015-02-24 11:52:19 +0000852//===----------------------------------------------------------------------===//
853// Assembler Pseudo Instructions
854//===----------------------------------------------------------------------===//
855
Toma Tabacue1e3ffe2015-03-04 13:01:14 +0000856class LoadImmediate64<string instr_asm, Operand Od, RegisterOperand RO> :
Toma Tabacua90f1442015-02-24 11:52:19 +0000857 MipsAsmPseudoInst<(outs RO:$rt), (ins Od:$imm64),
858 !strconcat(instr_asm, "\t$rt, $imm64")> ;
Toma Tabacue1e3ffe2015-03-04 13:01:14 +0000859def LoadImm64 : LoadImmediate64<"dli", imm64, GPR64Opnd>;
Daniel Sandersa39ef1c2015-08-17 10:11:55 +0000860
861def LoadAddrReg64 : MipsAsmPseudoInst<(outs GPR64Opnd:$rt), (ins mem:$addr),
862 "dla\t$rt, $addr">;
863def LoadAddrImm64 : MipsAsmPseudoInst<(outs GPR64Opnd:$rt), (ins imm64:$imm64),
864 "dla\t$rt, $imm64">;
Simon Dardis3c82a642017-02-08 16:25:05 +0000865
866def DMULImmMacro : MipsAsmPseudoInst<(outs), (ins GPR64Opnd:$rs, GPR64Opnd:$rt,
867 simm32_relaxed:$imm),
868 "dmul\t$rs, $rt, $imm">,
869 ISA_MIPS3_NOT_32R6_64R6;
870def DMULOMacro : MipsAsmPseudoInst<(outs), (ins GPR64Opnd:$rs, GPR64Opnd:$rt,
871 GPR64Opnd:$rd),
872 "dmulo\t$rs, $rt, $rd">,
873 ISA_MIPS3_NOT_32R6_64R6;
874def DMULOUMacro : MipsAsmPseudoInst<(outs), (ins GPR64Opnd:$rs, GPR64Opnd:$rt,
875 GPR64Opnd:$rd),
876 "dmulou\t$rs, $rt, $rd">,
877 ISA_MIPS3_NOT_32R6_64R6;
878
879def DMULMacro : MipsAsmPseudoInst<(outs), (ins GPR64Opnd:$rs, GPR64Opnd:$rt,
880 GPR64Opnd:$rd),
881 "dmul\t$rs, $rt, $rd"> {
882 let InsnPredicates = [HasMips3, NotMips64r6, NotCnMips];
883}
Simon Dardis509da1a2017-02-13 16:06:48 +0000884
885let AdditionalPredicates = [NotInMicroMips] in {
886 def DSDivMacro : MipsAsmPseudoInst<(outs GPR64Opnd:$rd),
887 (ins GPR64Opnd:$rs, GPR64Opnd:$rt),
888 "ddiv\t$rd, $rs, $rt">,
889 ISA_MIPS3_NOT_32R6_64R6;
890 def DSDivIMacro : MipsAsmPseudoInst<(outs GPR64Opnd:$rd),
891 (ins GPR64Opnd:$rs, imm64:$imm),
892 "ddiv\t$rd, $rs, $imm">,
893 ISA_MIPS3_NOT_32R6_64R6;
894 def DUDivMacro : MipsAsmPseudoInst<(outs GPR64Opnd:$rd),
895 (ins GPR64Opnd:$rs, GPR64Opnd:$rt),
896 "ddivu\t$rd, $rs, $rt">,
897 ISA_MIPS3_NOT_32R6_64R6;
898 def DUDivIMacro : MipsAsmPseudoInst<(outs GPR64Opnd:$rd),
899 (ins GPR64Opnd:$rs, imm64:$imm),
900 "ddivu\t$rd, $rs, $imm">,
901 ISA_MIPS3_NOT_32R6_64R6;
902
903 // GAS expands 'div' and 'ddiv' differently when the destination
904 // register is $zero and the instruction is in the two operand
905 // form. 'ddiv' gets expanded, while 'div' is not expanded.
906
907 def : MipsInstAlias<"ddiv $rs, $rt", (DSDivMacro GPR64Opnd:$rs,
908 GPR64Opnd:$rs,
909 GPR64Opnd:$rt), 0>,
910 ISA_MIPS3_NOT_32R6_64R6;
911 def : MipsInstAlias<"ddiv $rd, $imm", (DSDivIMacro GPR64Opnd:$rd,
912 GPR64Opnd:$rd,
913 imm64:$imm), 0>,
914 ISA_MIPS3_NOT_32R6_64R6;
915
916 // GAS expands 'divu' and 'ddivu' differently when the destination
917 // register is $zero and the instruction is in the two operand
918 // form. 'ddivu' gets expanded, while 'divu' is not expanded.
919
920 def : MipsInstAlias<"ddivu $rt, $rs", (DUDivMacro GPR64Opnd:$rt,
921 GPR64Opnd:$rt,
922 GPR64Opnd:$rs), 0>,
923 ISA_MIPS3_NOT_32R6_64R6;
924 def : MipsInstAlias<"ddivu $rd, $imm", (DUDivIMacro GPR64Opnd:$rd,
925 GPR64Opnd:$rd,
926 imm64:$imm), 0>,
927 ISA_MIPS3_NOT_32R6_64R6;
928}
Simon Dardise3cceed2017-02-28 15:55:23 +0000929
930def NORImm64 : NORIMM_DESC_BASE<GPR64Opnd, imm64>, GPR_64;
931def : MipsInstAlias<"nor\t$rs, $imm", (NORImm64 GPR64Opnd:$rs, GPR64Opnd:$rs,
932 imm64:$imm)>, GPR_64;
933def SLTImm64 : MipsAsmPseudoInst<(outs GPR64Opnd:$rs),
934 (ins GPR64Opnd:$rt, imm64:$imm),
935 "slt\t$rs, $rt, $imm">, GPR_64;
936def : MipsInstAlias<"slt\t$rs, $imm", (SLTImm64 GPR64Opnd:$rs, GPR64Opnd:$rs,
937 imm64:$imm)>, GPR_64;
938def SLTUImm64 : MipsAsmPseudoInst<(outs GPR64Opnd:$rs),
939 (ins GPR64Opnd:$rt, imm64:$imm),
940 "sltu\t$rs, $rt, $imm">, GPR_64;
941def : MipsInstAlias<"sltu\t$rs, $imm", (SLTUImm64 GPR64Opnd:$rs, GPR64Opnd:$rs,
942 imm64:$imm)>, GPR_64;