]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/Target/Hexagon/HexagonInstrInfoV4.td
Import Amazon Elastic Network Adapter (ENA) HAL to sys/contrib/
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / Target / Hexagon / HexagonInstrInfoV4.td
1 //=- HexagonInstrInfoV4.td - Target Desc. for Hexagon Target -*- 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 the Hexagon V4 instructions in TableGen format.
11 //
12 //===----------------------------------------------------------------------===//
13
14 def DuplexIClass0:  InstDuplex < 0 >;
15 def DuplexIClass1:  InstDuplex < 1 >;
16 def DuplexIClass2:  InstDuplex < 2 >;
17 let isExtendable = 1 in {
18   def DuplexIClass3:  InstDuplex < 3 >;
19   def DuplexIClass4:  InstDuplex < 4 >;
20   def DuplexIClass5:  InstDuplex < 5 >;
21   def DuplexIClass6:  InstDuplex < 6 >;
22   def DuplexIClass7:  InstDuplex < 7 >;
23 }
24 def DuplexIClass8:  InstDuplex < 8 >;
25 def DuplexIClass9:  InstDuplex < 9 >;
26 def DuplexIClassA:  InstDuplex < 0xA >;
27 def DuplexIClassB:  InstDuplex < 0xB >;
28 def DuplexIClassC:  InstDuplex < 0xC >;
29 def DuplexIClassD:  InstDuplex < 0xD >;
30 def DuplexIClassE:  InstDuplex < 0xE >;
31 def DuplexIClassF:  InstDuplex < 0xF >;
32
33 let hasSideEffects = 0 in
34 class T_Immext<Operand ImmType>
35   : EXTENDERInst<(outs), (ins ImmType:$imm),
36                  "immext(#$imm)", []> {
37     bits<32> imm;
38     let IClass = 0b0000;
39
40     let Inst{27-16} = imm{31-20};
41     let Inst{13-0} = imm{19-6};
42   }
43
44 def A4_ext : T_Immext<u26_6Imm>;
45 let isCodeGenOnly = 1 in {
46   let isBranch = 1 in
47     def A4_ext_b : T_Immext<brtarget>;
48   let isCall = 1 in
49     def A4_ext_c : T_Immext<calltarget>;
50   def A4_ext_g : T_Immext<globaladdress>;
51 }
52
53 // Hexagon V4 Architecture spec defines 8 instruction classes:
54 // LD ST ALU32 XTYPE J JR MEMOP NV CR SYSTEM(system is not implemented in the
55 // compiler)
56
57 // LD Instructions:
58 // ========================================
59 // Loads (8/16/32/64 bit)
60 // Deallocframe
61
62 // ST Instructions:
63 // ========================================
64 // Stores (8/16/32/64 bit)
65 // Allocframe
66
67 // ALU32 Instructions:
68 // ========================================
69 // Arithmetic / Logical (32 bit)
70 // Vector Halfword
71
72 // XTYPE Instructions (32/64 bit):
73 // ========================================
74 // Arithmetic, Logical, Bit Manipulation
75 // Multiply (Integer, Fractional, Complex)
76 // Permute / Vector Permute Operations
77 // Predicate Operations
78 // Shift / Shift with Add/Sub/Logical
79 // Vector Byte ALU
80 // Vector Halfword (ALU, Shift, Multiply)
81 // Vector Word (ALU, Shift)
82
83 // J Instructions:
84 // ========================================
85 // Jump/Call PC-relative
86
87 // JR Instructions:
88 // ========================================
89 // Jump/Call Register
90
91 // MEMOP Instructions:
92 // ========================================
93 // Operation on memory (8/16/32 bit)
94
95 // NV Instructions:
96 // ========================================
97 // New-value Jumps
98 // New-value Stores
99
100 // CR Instructions:
101 // ========================================
102 // Control-Register Transfers
103 // Hardware Loop Setup
104 // Predicate Logicals & Reductions
105
106 // SYSTEM Instructions (not implemented in the compiler):
107 // ========================================
108 // Prefetch
109 // Cache Maintenance
110 // Bus Operations
111
112
113 //===----------------------------------------------------------------------===//
114 // ALU32 +
115 //===----------------------------------------------------------------------===//
116
117 class T_ALU32_3op_not<string mnemonic, bits<3> MajOp, bits<3> MinOp,
118                       bit OpsRev>
119   : T_ALU32_3op<mnemonic, MajOp, MinOp, OpsRev, 0> {
120   let AsmString = "$Rd = "#mnemonic#"($Rs, ~$Rt)";
121 }
122
123 let BaseOpcode = "andn_rr", CextOpcode = "andn" in
124 def A4_andn    : T_ALU32_3op_not<"and", 0b001, 0b100, 1>;
125 let BaseOpcode = "orn_rr", CextOpcode = "orn" in
126 def A4_orn     : T_ALU32_3op_not<"or",  0b001, 0b101, 1>;
127
128 let CextOpcode = "rcmp.eq" in
129 def A4_rcmpeq  : T_ALU32_3op<"cmp.eq",  0b011, 0b010, 0, 1>;
130 let CextOpcode = "!rcmp.eq" in
131 def A4_rcmpneq : T_ALU32_3op<"!cmp.eq", 0b011, 0b011, 0, 1>;
132
133 def C4_cmpneq  : T_ALU32_3op_cmp<"!cmp.eq",  0b00, 1, 1>;
134 def C4_cmplte  : T_ALU32_3op_cmp<"!cmp.gt",  0b10, 1, 0>;
135 def C4_cmplteu : T_ALU32_3op_cmp<"!cmp.gtu", 0b11, 1, 0>;
136
137 class T_CMP_rrbh<string mnemonic, bits<3> MinOp, bit IsComm>
138   : SInst<(outs PredRegs:$Pd), (ins IntRegs:$Rs, IntRegs:$Rt),
139     "$Pd = "#mnemonic#"($Rs, $Rt)", [], "", S_3op_tc_2early_SLOT23>,
140     ImmRegRel {
141   let InputType = "reg";
142   let CextOpcode = mnemonic;
143   let isCompare = 1;
144   let isCommutable = IsComm;
145   let hasSideEffects = 0;
146
147   bits<2> Pd;
148   bits<5> Rs;
149   bits<5> Rt;
150
151   let IClass = 0b1100;
152   let Inst{27-21} = 0b0111110;
153   let Inst{20-16} = Rs;
154   let Inst{12-8} = Rt;
155   let Inst{7-5} = MinOp;
156   let Inst{1-0} = Pd;
157 }
158
159 def A4_cmpbeq  : T_CMP_rrbh<"cmpb.eq",  0b110, 1>;
160 def A4_cmpbgt  : T_CMP_rrbh<"cmpb.gt",  0b010, 0>;
161 def A4_cmpbgtu : T_CMP_rrbh<"cmpb.gtu", 0b111, 0>;
162 def A4_cmpheq  : T_CMP_rrbh<"cmph.eq",  0b011, 1>;
163 def A4_cmphgt  : T_CMP_rrbh<"cmph.gt",  0b100, 0>;
164 def A4_cmphgtu : T_CMP_rrbh<"cmph.gtu", 0b101, 0>;
165
166 class T_CMP_ribh<string mnemonic, bits<2> MajOp, bit IsHalf, bit IsComm,
167                  Operand ImmType, bit IsImmExt, bit IsImmSigned, int ImmBits>
168   : ALU64Inst<(outs PredRegs:$Pd), (ins IntRegs:$Rs, ImmType:$Imm),
169     "$Pd = "#mnemonic#"($Rs, #$Imm)", [], "", ALU64_tc_2early_SLOT23>,
170     ImmRegRel {
171   let InputType = "imm";
172   let CextOpcode = mnemonic;
173   let isCompare = 1;
174   let isCommutable = IsComm;
175   let hasSideEffects = 0;
176   let isExtendable = IsImmExt;
177   let opExtendable = !if (IsImmExt, 2, 0);
178   let isExtentSigned = IsImmSigned;
179   let opExtentBits = ImmBits;
180
181   bits<2> Pd;
182   bits<5> Rs;
183   bits<8> Imm;
184
185   let IClass = 0b1101;
186   let Inst{27-24} = 0b1101;
187   let Inst{22-21} = MajOp;
188   let Inst{20-16} = Rs;
189   let Inst{12-5} = Imm;
190   let Inst{4} = 0b0;
191   let Inst{3} = IsHalf;
192   let Inst{1-0} = Pd;
193 }
194
195 def A4_cmpbeqi  : T_CMP_ribh<"cmpb.eq",  0b00, 0, 1, u8_0Imm, 0, 0, 8>;
196 def A4_cmpbgti  : T_CMP_ribh<"cmpb.gt",  0b01, 0, 0, s8_0Imm, 0, 1, 8>;
197 def A4_cmpbgtui : T_CMP_ribh<"cmpb.gtu", 0b10, 0, 0, u7_0Ext, 1, 0, 7>;
198 def A4_cmpheqi  : T_CMP_ribh<"cmph.eq",  0b00, 1, 1, s8_0Ext, 1, 1, 8>;
199 def A4_cmphgti  : T_CMP_ribh<"cmph.gt",  0b01, 1, 0, s8_0Ext, 1, 1, 8>;
200 def A4_cmphgtui : T_CMP_ribh<"cmph.gtu", 0b10, 1, 0, u7_0Ext, 1, 0, 7>;
201
202 class T_RCMP_EQ_ri<string mnemonic, bit IsNeg>
203   : ALU32_ri<(outs IntRegs:$Rd), (ins IntRegs:$Rs, s8_0Ext:$s8),
204     "$Rd = "#mnemonic#"($Rs, #$s8)", [], "", ALU32_2op_tc_1_SLOT0123>,
205     ImmRegRel {
206   let InputType = "imm";
207   let CextOpcode = !if (IsNeg, "!rcmp.eq", "rcmp.eq");
208   let isExtendable = 1;
209   let opExtendable = 2;
210   let isExtentSigned = 1;
211   let opExtentBits = 8;
212   let hasNewValue = 1;
213
214   bits<5> Rd;
215   bits<5> Rs;
216   bits<8> s8;
217
218   let IClass = 0b0111;
219   let Inst{27-24} = 0b0011;
220   let Inst{22} = 0b1;
221   let Inst{21} = IsNeg;
222   let Inst{20-16} = Rs;
223   let Inst{13} = 0b1;
224   let Inst{12-5} = s8;
225   let Inst{4-0} = Rd;
226 }
227
228 def A4_rcmpeqi  : T_RCMP_EQ_ri<"cmp.eq",  0>;
229 def A4_rcmpneqi : T_RCMP_EQ_ri<"!cmp.eq", 1>;
230
231 //===----------------------------------------------------------------------===//
232 // ALU32 -
233 //===----------------------------------------------------------------------===//
234
235
236 //===----------------------------------------------------------------------===//
237 // ALU32/PERM +
238 //===----------------------------------------------------------------------===//
239
240 // Combine a word and an immediate into a register pair.
241 let hasSideEffects = 0, isExtentSigned = 1, isExtendable = 1,
242     opExtentBits = 8 in
243 class T_Combine1 <bits<2> MajOp, dag ins, string AsmStr>
244   : ALU32Inst <(outs DoubleRegs:$Rdd), ins, AsmStr> {
245     bits<5> Rdd;
246     bits<5> Rs;
247     bits<8> s8;
248
249     let IClass      = 0b0111;
250     let Inst{27-24} = 0b0011;
251     let Inst{22-21} = MajOp;
252     let Inst{20-16} = Rs;
253     let Inst{13}    = 0b1;
254     let Inst{12-5}  = s8;
255     let Inst{4-0}   = Rdd;
256   }
257
258 let opExtendable = 2 in
259 def A4_combineri : T_Combine1<0b00, (ins IntRegs:$Rs, s8_0Ext:$s8),
260                                     "$Rdd = combine($Rs, #$s8)">;
261
262 let opExtendable = 1 in
263 def A4_combineir : T_Combine1<0b01, (ins s8_0Ext:$s8, IntRegs:$Rs),
264                                     "$Rdd = combine(#$s8, $Rs)">;
265
266 // A4_combineii: Set two small immediates.
267 let hasSideEffects = 0, isExtendable = 1, opExtentBits = 6, opExtendable = 2 in
268 def A4_combineii: ALU32Inst<(outs DoubleRegs:$Rdd), (ins s8_0Imm:$s8, u6_0Ext:$U6),
269   "$Rdd = combine(#$s8, #$U6)"> {
270     bits<5> Rdd;
271     bits<8> s8;
272     bits<6> U6;
273
274     let IClass = 0b0111;
275     let Inst{27-23} = 0b11001;
276     let Inst{20-16} = U6{5-1};
277     let Inst{13}    = U6{0};
278     let Inst{12-5}  = s8;
279     let Inst{4-0}   = Rdd;
280   }
281
282 //===----------------------------------------------------------------------===//
283 // ALU32/PERM -
284 //===----------------------------------------------------------------------===//
285
286 //===----------------------------------------------------------------------===//
287 // LD +
288 //===----------------------------------------------------------------------===//
289
290 //===----------------------------------------------------------------------===//
291 // Template class for load instructions with Absolute set addressing mode.
292 //===----------------------------------------------------------------------===//
293 let isExtended = 1, opExtendable = 2, opExtentBits = 6, addrMode = AbsoluteSet,
294     hasSideEffects = 0 in
295 class T_LD_abs_set<string mnemonic, RegisterClass RC, bits<4>MajOp>:
296             LDInst<(outs RC:$dst1, IntRegs:$dst2),
297             (ins u6_0Ext:$addr),
298             "$dst1 = "#mnemonic#"($dst2 = #$addr)",
299             []> {
300   bits<7> name;
301   bits<5> dst1;
302   bits<5> dst2;
303   bits<6> addr;
304
305   let IClass = 0b1001;
306   let Inst{27-25} = 0b101;
307   let Inst{24-21} = MajOp;
308   let Inst{13-12} = 0b01;
309   let Inst{4-0}   = dst1;
310   let Inst{20-16} = dst2;
311   let Inst{11-8}  = addr{5-2};
312   let Inst{6-5}   = addr{1-0};
313 }
314
315 let accessSize = ByteAccess, hasNewValue = 1 in {
316   def L4_loadrb_ap   : T_LD_abs_set <"memb",   IntRegs, 0b1000>;
317   def L4_loadrub_ap  : T_LD_abs_set <"memub",  IntRegs, 0b1001>;
318 }
319
320 let accessSize = HalfWordAccess, hasNewValue = 1 in {
321   def L4_loadrh_ap  : T_LD_abs_set <"memh",  IntRegs, 0b1010>;
322   def L4_loadruh_ap : T_LD_abs_set <"memuh", IntRegs, 0b1011>;
323   def L4_loadbsw2_ap : T_LD_abs_set <"membh",  IntRegs, 0b0001>;
324   def L4_loadbzw2_ap : T_LD_abs_set <"memubh", IntRegs, 0b0011>;
325 }
326
327 let accessSize = WordAccess, hasNewValue = 1 in
328   def L4_loadri_ap : T_LD_abs_set <"memw", IntRegs, 0b1100>;
329
330 let accessSize = WordAccess in {
331   def L4_loadbzw4_ap : T_LD_abs_set <"memubh", DoubleRegs, 0b0101>;
332   def L4_loadbsw4_ap : T_LD_abs_set <"membh",  DoubleRegs, 0b0111>;
333 }
334
335 let accessSize = DoubleWordAccess in
336 def L4_loadrd_ap : T_LD_abs_set <"memd", DoubleRegs, 0b1110>;
337
338 let accessSize = ByteAccess in
339   def L4_loadalignb_ap : T_LD_abs_set <"memb_fifo", DoubleRegs, 0b0100>;
340
341 let accessSize = HalfWordAccess in
342 def L4_loadalignh_ap : T_LD_abs_set <"memh_fifo", DoubleRegs, 0b0010>;
343
344 // Load - Indirect with long offset
345 let InputType = "imm", addrMode = BaseLongOffset, isExtended = 1,
346 opExtentBits = 6, opExtendable = 3 in
347 class T_LoadAbsReg <string mnemonic, string CextOp, RegisterClass RC,
348                     bits<4> MajOp>
349   : LDInst <(outs RC:$dst), (ins IntRegs:$src1, u2_0Imm:$src2, u6_0Ext:$src3),
350   "$dst = "#mnemonic#"($src1<<#$src2 + #$src3)",
351   [] >, ImmRegShl {
352     bits<5> dst;
353     bits<5> src1;
354     bits<2> src2;
355     bits<6> src3;
356     let CextOpcode = CextOp;
357     let hasNewValue = !if (!eq(!cast<string>(RC), "DoubleRegs"), 0, 1);
358
359     let IClass = 0b1001;
360     let Inst{27-25} = 0b110;
361     let Inst{24-21} = MajOp;
362     let Inst{20-16} = src1;
363     let Inst{13}    = src2{1};
364     let Inst{12}    = 0b1;
365     let Inst{11-8}  = src3{5-2};
366     let Inst{7}     = src2{0};
367     let Inst{6-5}   = src3{1-0};
368     let Inst{4-0}   = dst;
369   }
370
371 let accessSize = ByteAccess in {
372   def L4_loadrb_ur  : T_LoadAbsReg<"memb",  "LDrib", IntRegs, 0b1000>;
373   def L4_loadrub_ur : T_LoadAbsReg<"memub", "LDriub", IntRegs, 0b1001>;
374   def L4_loadalignb_ur : T_LoadAbsReg<"memb_fifo", "LDrib_fifo",
375                                       DoubleRegs, 0b0100>;
376 }
377
378 let accessSize = HalfWordAccess in {
379   def L4_loadrh_ur   : T_LoadAbsReg<"memh",   "LDrih",    IntRegs, 0b1010>;
380   def L4_loadruh_ur  : T_LoadAbsReg<"memuh",  "LDriuh",   IntRegs, 0b1011>;
381   def L4_loadbsw2_ur : T_LoadAbsReg<"membh",  "LDribh2",  IntRegs, 0b0001>;
382   def L4_loadbzw2_ur : T_LoadAbsReg<"memubh", "LDriubh2", IntRegs, 0b0011>;
383   def L4_loadalignh_ur : T_LoadAbsReg<"memh_fifo", "LDrih_fifo",
384                                       DoubleRegs, 0b0010>;
385 }
386
387 let accessSize = WordAccess in {
388   def L4_loadri_ur   : T_LoadAbsReg<"memw", "LDriw", IntRegs, 0b1100>;
389   def L4_loadbsw4_ur : T_LoadAbsReg<"membh", "LDribh4", DoubleRegs, 0b0111>;
390   def L4_loadbzw4_ur : T_LoadAbsReg<"memubh", "LDriubh4", DoubleRegs, 0b0101>;
391 }
392
393 let accessSize = DoubleWordAccess in
394 def L4_loadrd_ur  : T_LoadAbsReg<"memd", "LDrid", DoubleRegs, 0b1110>;
395
396
397 //===----------------------------------------------------------------------===//
398 // Template classes for the non-predicated load instructions with
399 // base + register offset addressing mode
400 //===----------------------------------------------------------------------===//
401 class T_load_rr <string mnemonic, RegisterClass RC, bits<3> MajOp>:
402    LDInst<(outs RC:$dst), (ins IntRegs:$src1, IntRegs:$src2, u2_0Imm:$u2),
403   "$dst = "#mnemonic#"($src1 + $src2<<#$u2)",
404   [], "", V4LDST_tc_ld_SLOT01>, ImmRegShl, AddrModeRel {
405     bits<5> dst;
406     bits<5> src1;
407     bits<5> src2;
408     bits<2> u2;
409
410     let IClass = 0b0011;
411
412     let Inst{27-24} = 0b1010;
413     let Inst{23-21} = MajOp;
414     let Inst{20-16} = src1;
415     let Inst{12-8}  = src2;
416     let Inst{13}    = u2{1};
417     let Inst{7}     = u2{0};
418     let Inst{4-0}   = dst;
419   }
420
421 //===----------------------------------------------------------------------===//
422 // Template classes for the predicated load instructions with
423 // base + register offset addressing mode
424 //===----------------------------------------------------------------------===//
425 let isPredicated =  1 in
426 class T_pload_rr <string mnemonic, RegisterClass RC, bits<3> MajOp,
427                   bit isNot, bit isPredNew>:
428    LDInst <(outs RC:$dst),
429            (ins PredRegs:$src1, IntRegs:$src2, IntRegs:$src3, u2_0Imm:$u2),
430   !if(isNot, "if (!$src1", "if ($src1")#!if(isPredNew, ".new) ",
431   ") ")#"$dst = "#mnemonic#"($src2+$src3<<#$u2)",
432   [], "", V4LDST_tc_ld_SLOT01>, AddrModeRel {
433     bits<5> dst;
434     bits<2> src1;
435     bits<5> src2;
436     bits<5> src3;
437     bits<2> u2;
438
439     let isPredicatedFalse = isNot;
440     let isPredicatedNew = isPredNew;
441
442     let IClass = 0b0011;
443
444     let Inst{27-26} = 0b00;
445     let Inst{25}    = isPredNew;
446     let Inst{24}    = isNot;
447     let Inst{23-21} = MajOp;
448     let Inst{20-16} = src2;
449     let Inst{12-8}  = src3;
450     let Inst{13}    = u2{1};
451     let Inst{7}     = u2{0};
452     let Inst{6-5}   = src1;
453     let Inst{4-0}   = dst;
454   }
455
456 //===----------------------------------------------------------------------===//
457 // multiclass for load instructions with base + register offset
458 // addressing mode
459 //===----------------------------------------------------------------------===//
460 let hasSideEffects = 0, addrMode = BaseRegOffset in
461 multiclass ld_idxd_shl <string mnemonic, string CextOp, RegisterClass RC,
462                         bits<3> MajOp > {
463   let CextOpcode = CextOp, BaseOpcode = CextOp#_indexed_shl,
464       InputType = "reg" in {
465     let isPredicable = 1 in
466     def L4_#NAME#_rr : T_load_rr <mnemonic, RC, MajOp>;
467
468     // Predicated
469     def L4_p#NAME#t_rr : T_pload_rr <mnemonic, RC, MajOp, 0, 0>;
470     def L4_p#NAME#f_rr : T_pload_rr <mnemonic, RC, MajOp, 1, 0>;
471
472     // Predicated new
473     def L4_p#NAME#tnew_rr : T_pload_rr <mnemonic, RC, MajOp, 0, 1>;
474     def L4_p#NAME#fnew_rr : T_pload_rr <mnemonic, RC, MajOp, 1, 1>;
475   }
476 }
477
478 let hasNewValue = 1, accessSize = ByteAccess in {
479   defm loadrb  : ld_idxd_shl<"memb", "LDrib", IntRegs, 0b000>;
480   defm loadrub : ld_idxd_shl<"memub", "LDriub", IntRegs, 0b001>;
481 }
482
483 let hasNewValue = 1, accessSize = HalfWordAccess in {
484   defm loadrh  : ld_idxd_shl<"memh", "LDrih", IntRegs, 0b010>;
485   defm loadruh : ld_idxd_shl<"memuh", "LDriuh", IntRegs, 0b011>;
486 }
487
488 let hasNewValue = 1, accessSize = WordAccess in
489 defm loadri : ld_idxd_shl<"memw", "LDriw", IntRegs, 0b100>;
490
491 let accessSize = DoubleWordAccess in
492 defm loadrd  : ld_idxd_shl<"memd", "LDrid", DoubleRegs, 0b110>;
493
494 //===----------------------------------------------------------------------===//
495 // LD -
496 //===----------------------------------------------------------------------===//
497
498 //===----------------------------------------------------------------------===//
499 // ST +
500 //===----------------------------------------------------------------------===//
501 ///
502 //===----------------------------------------------------------------------===//
503 // Template class for store instructions with Absolute set addressing mode.
504 //===----------------------------------------------------------------------===//
505 let isExtended = 1, opExtendable = 1, opExtentBits = 6,
506     addrMode = AbsoluteSet in
507 class T_ST_absset <string mnemonic, string BaseOp, RegisterClass RC,
508                    bits<3> MajOp, MemAccessSize AccessSz, bit isHalf = 0>
509   : STInst<(outs IntRegs:$dst),
510            (ins u6_0Ext:$addr, RC:$src),
511     mnemonic#"($dst = #$addr) = $src"#!if(isHalf, ".h","")>, NewValueRel {
512     bits<5> dst;
513     bits<6> addr;
514     bits<5> src;
515     let accessSize = AccessSz;
516     let BaseOpcode = BaseOp#"_AbsSet";
517
518     // Store upper-half and store doubleword cannot be NV.
519     let isNVStorable = !if (!eq(mnemonic, "memd"), 0, !if(isHalf,0,1));
520
521     let IClass = 0b1010;
522
523     let Inst{27-24} = 0b1011;
524     let Inst{23-21} = MajOp;
525     let Inst{20-16} = dst;
526     let Inst{13}    = 0b0;
527     let Inst{12-8}  = src;
528     let Inst{7}     = 0b1;
529     let Inst{5-0}   = addr;
530   }
531
532 def S4_storerb_ap : T_ST_absset <"memb", "STrib", IntRegs, 0b000, ByteAccess>;
533 def S4_storerh_ap : T_ST_absset <"memh", "STrih", IntRegs, 0b010,
534                                  HalfWordAccess>;
535 def S4_storeri_ap : T_ST_absset <"memw", "STriw", IntRegs, 0b100, WordAccess>;
536
537 let isNVStorable = 0 in {
538   def S4_storerf_ap : T_ST_absset <"memh", "STrif", IntRegs,
539                                    0b011, HalfWordAccess, 1>;
540   def S4_storerd_ap : T_ST_absset <"memd", "STrid", DoubleRegs,
541                                    0b110, DoubleWordAccess>;
542 }
543
544 let opExtendable = 1, isNewValue = 1, isNVStore = 1, opNewValue = 2,
545 isExtended = 1, opExtentBits= 6 in
546 class T_ST_absset_nv <string mnemonic, string BaseOp, bits<2> MajOp,
547                       MemAccessSize AccessSz >
548   : NVInst <(outs IntRegs:$dst),
549             (ins u6_0Ext:$addr, IntRegs:$src),
550     mnemonic#"($dst = #$addr) = $src.new">, NewValueRel {
551     bits<5> dst;
552     bits<6> addr;
553     bits<3> src;
554     let accessSize = AccessSz;
555     let BaseOpcode = BaseOp#"_AbsSet";
556
557     let IClass = 0b1010;
558
559     let Inst{27-21} = 0b1011101;
560     let Inst{20-16} = dst;
561     let Inst{13-11} = 0b000;
562     let Inst{12-11} = MajOp;
563     let Inst{10-8}  = src;
564     let Inst{7}     = 0b1;
565     let Inst{5-0}   = addr;
566   }
567
568 let mayStore = 1, addrMode = AbsoluteSet in {
569   def S4_storerbnew_ap : T_ST_absset_nv <"memb", "STrib", 0b00, ByteAccess>;
570   def S4_storerhnew_ap : T_ST_absset_nv <"memh", "STrih", 0b01, HalfWordAccess>;
571   def S4_storerinew_ap : T_ST_absset_nv <"memw", "STriw", 0b10, WordAccess>;
572 }
573
574 let isExtended = 1, opExtendable = 2, opExtentBits = 6, InputType = "imm",
575     addrMode = BaseLongOffset, AddedComplexity = 40 in
576 class T_StoreAbsReg <string mnemonic, string CextOp, RegisterClass RC,
577                      bits<3> MajOp, MemAccessSize AccessSz, bit isHalf = 0>
578   : STInst<(outs),
579            (ins IntRegs:$src1, u2_0Imm:$src2, u6_0Ext:$src3, RC:$src4),
580    mnemonic#"($src1<<#$src2 + #$src3) = $src4"#!if(isHalf, ".h",""),
581    []>, ImmRegShl, NewValueRel {
582
583     bits<5> src1;
584     bits<2> src2;
585     bits<6> src3;
586     bits<5> src4;
587
588     let accessSize = AccessSz;
589     let CextOpcode = CextOp;
590     let BaseOpcode = CextOp#"_shl";
591
592     // Store upper-half and store doubleword cannot be NV.
593     let isNVStorable = !if (!eq(mnemonic, "memd"), 0, !if(isHalf,0,1));
594
595     let IClass = 0b1010;
596
597     let Inst{27-24} =0b1101;
598     let Inst{23-21} = MajOp;
599     let Inst{20-16} = src1;
600     let Inst{13}    = src2{1};
601     let Inst{12-8}  = src4;
602     let Inst{7}     = 0b1;
603     let Inst{6}     = src2{0};
604     let Inst{5-0}   = src3;
605 }
606
607 def S4_storerb_ur : T_StoreAbsReg <"memb", "STrib", IntRegs, 0b000, ByteAccess>;
608 def S4_storerh_ur : T_StoreAbsReg <"memh", "STrih", IntRegs, 0b010,
609                                    HalfWordAccess>;
610 def S4_storerf_ur : T_StoreAbsReg <"memh", "STrif", IntRegs, 0b011,
611                                    HalfWordAccess, 1>;
612 def S4_storeri_ur : T_StoreAbsReg <"memw", "STriw", IntRegs, 0b100, WordAccess>;
613 def S4_storerd_ur : T_StoreAbsReg <"memd", "STrid", DoubleRegs, 0b110,
614                                    DoubleWordAccess>;
615
616 let mayStore = 1, isNVStore = 1, isExtended = 1, addrMode = BaseLongOffset,
617     opExtentBits = 6, isNewValue = 1, opNewValue = 3, opExtendable = 2 in
618 class T_StoreAbsRegNV <string mnemonic, string CextOp, bits<2> MajOp,
619                        MemAccessSize AccessSz>
620   : NVInst <(outs ),
621             (ins IntRegs:$src1, u2_0Imm:$src2, u6_0Ext:$src3, IntRegs:$src4),
622   mnemonic#"($src1<<#$src2 + #$src3) = $src4.new">, NewValueRel {
623     bits<5> src1;
624     bits<2> src2;
625     bits<6> src3;
626     bits<3> src4;
627
628     let CextOpcode  = CextOp;
629     let BaseOpcode  = CextOp#"_shl";
630     let IClass      = 0b1010;
631
632     let Inst{27-21} = 0b1101101;
633     let Inst{12-11} = 0b00;
634     let Inst{7}     = 0b1;
635     let Inst{20-16} = src1;
636     let Inst{13}    = src2{1};
637     let Inst{12-11} = MajOp;
638     let Inst{10-8}  = src4;
639     let Inst{6}     = src2{0};
640     let Inst{5-0}   = src3;
641   }
642
643 def S4_storerbnew_ur : T_StoreAbsRegNV <"memb", "STrib", 0b00, ByteAccess>;
644 def S4_storerhnew_ur : T_StoreAbsRegNV <"memh", "STrih", 0b01, HalfWordAccess>;
645 def S4_storerinew_ur : T_StoreAbsRegNV <"memw", "STriw", 0b10, WordAccess>;
646
647 //===----------------------------------------------------------------------===//
648 // Template classes for the non-predicated store instructions with
649 // base + register offset addressing mode
650 //===----------------------------------------------------------------------===//
651 let isPredicable = 1 in
652 class T_store_rr <string mnemonic, RegisterClass RC, bits<3> MajOp, bit isH>
653   : STInst < (outs ), (ins IntRegs:$Rs, IntRegs:$Ru, u2_0Imm:$u2, RC:$Rt),
654   mnemonic#"($Rs + $Ru<<#$u2) = $Rt"#!if(isH, ".h",""),
655   [],"",V4LDST_tc_st_SLOT01>, ImmRegShl, AddrModeRel {
656
657     bits<5> Rs;
658     bits<5> Ru;
659     bits<2> u2;
660     bits<5> Rt;
661
662     // Store upper-half and store doubleword cannot be NV.
663     let isNVStorable = !if (!eq(mnemonic, "memd"), 0, !if(isH,0,1));
664
665     let IClass = 0b0011;
666
667     let Inst{27-24} = 0b1011;
668     let Inst{23-21} = MajOp;
669     let Inst{20-16} = Rs;
670     let Inst{12-8}  = Ru;
671     let Inst{13}    = u2{1};
672     let Inst{7}     = u2{0};
673     let Inst{4-0}   = Rt;
674   }
675
676 //===----------------------------------------------------------------------===//
677 // Template classes for the predicated store instructions with
678 // base + register offset addressing mode
679 //===----------------------------------------------------------------------===//
680 let isPredicated = 1 in
681 class T_pstore_rr <string mnemonic, RegisterClass RC, bits<3> MajOp,
682                    bit isNot, bit isPredNew, bit isH>
683   : STInst <(outs),
684             (ins PredRegs:$Pv, IntRegs:$Rs, IntRegs:$Ru, u2_0Imm:$u2, RC:$Rt),
685
686   !if(isNot, "if (!$Pv", "if ($Pv")#!if(isPredNew, ".new) ",
687   ") ")#mnemonic#"($Rs+$Ru<<#$u2) = $Rt"#!if(isH, ".h",""),
688   [], "", V4LDST_tc_st_SLOT01> , AddrModeRel{
689     bits<2> Pv;
690     bits<5> Rs;
691     bits<5> Ru;
692     bits<2> u2;
693     bits<5> Rt;
694
695     let isPredicatedFalse = isNot;
696     let isPredicatedNew = isPredNew;
697     // Store upper-half and store doubleword cannot be NV.
698     let isNVStorable = !if (!eq(mnemonic, "memd"), 0, !if(isH,0,1));
699
700     let IClass = 0b0011;
701
702     let Inst{27-26} = 0b01;
703     let Inst{25}    = isPredNew;
704     let Inst{24}    = isNot;
705     let Inst{23-21} = MajOp;
706     let Inst{20-16} = Rs;
707     let Inst{12-8}  = Ru;
708     let Inst{13}    = u2{1};
709     let Inst{7}     = u2{0};
710     let Inst{6-5}   = Pv;
711     let Inst{4-0}   = Rt;
712   }
713
714 //===----------------------------------------------------------------------===//
715 // Template classes for the new-value store instructions with
716 // base + register offset addressing mode
717 //===----------------------------------------------------------------------===//
718 let isPredicable = 1, isNewValue = 1, opNewValue = 3 in
719 class T_store_new_rr <string mnemonic, bits<2> MajOp> :
720   NVInst < (outs ), (ins IntRegs:$Rs, IntRegs:$Ru, u2_0Imm:$u2, IntRegs:$Nt),
721   mnemonic#"($Rs + $Ru<<#$u2) = $Nt.new",
722   [],"",V4LDST_tc_st_SLOT0>, ImmRegShl, AddrModeRel {
723
724     bits<5> Rs;
725     bits<5> Ru;
726     bits<2> u2;
727     bits<3> Nt;
728
729     let IClass = 0b0011;
730
731     let Inst{27-21} = 0b1011101;
732     let Inst{20-16} = Rs;
733     let Inst{12-8}  = Ru;
734     let Inst{13}    = u2{1};
735     let Inst{7}     = u2{0};
736     let Inst{4-3}   = MajOp;
737     let Inst{2-0}   = Nt;
738   }
739
740 //===----------------------------------------------------------------------===//
741 // Template classes for the predicated new-value store instructions with
742 // base + register offset addressing mode
743 //===----------------------------------------------------------------------===//
744 let isPredicated = 1, isNewValue = 1, opNewValue = 4 in
745 class T_pstore_new_rr <string mnemonic, bits<2> MajOp, bit isNot, bit isPredNew>
746   : NVInst<(outs),
747            (ins PredRegs:$Pv, IntRegs:$Rs, IntRegs:$Ru, u2_0Imm:$u2, IntRegs:$Nt),
748    !if(isNot, "if (!$Pv", "if ($Pv")#!if(isPredNew, ".new) ",
749    ") ")#mnemonic#"($Rs+$Ru<<#$u2) = $Nt.new",
750    [], "", V4LDST_tc_st_SLOT0>, AddrModeRel {
751     bits<2> Pv;
752     bits<5> Rs;
753     bits<5> Ru;
754     bits<2> u2;
755     bits<3> Nt;
756
757     let isPredicatedFalse = isNot;
758     let isPredicatedNew = isPredNew;
759
760     let IClass = 0b0011;
761     let Inst{27-26} = 0b01;
762     let Inst{25}    = isPredNew;
763     let Inst{24}    = isNot;
764     let Inst{23-21} = 0b101;
765     let Inst{20-16} = Rs;
766     let Inst{12-8}  = Ru;
767     let Inst{13}    = u2{1};
768     let Inst{7}     = u2{0};
769     let Inst{6-5}   = Pv;
770     let Inst{4-3}   = MajOp;
771     let Inst{2-0}   = Nt;
772   }
773
774 //===----------------------------------------------------------------------===//
775 // multiclass for store instructions with base + register offset addressing
776 // mode
777 //===----------------------------------------------------------------------===//
778 let isNVStorable = 1 in
779 multiclass ST_Idxd_shl<string mnemonic, string CextOp, RegisterClass RC,
780                        bits<3> MajOp, bit isH = 0> {
781   let CextOpcode = CextOp, BaseOpcode = CextOp#_indexed_shl in {
782     def S4_#NAME#_rr : T_store_rr <mnemonic, RC, MajOp, isH>;
783
784     // Predicated
785     def S4_p#NAME#t_rr : T_pstore_rr <mnemonic, RC, MajOp, 0, 0, isH>;
786     def S4_p#NAME#f_rr : T_pstore_rr <mnemonic, RC, MajOp, 1, 0, isH>;
787
788     // Predicated new
789     def S4_p#NAME#tnew_rr : T_pstore_rr <mnemonic, RC, MajOp, 0, 1, isH>;
790     def S4_p#NAME#fnew_rr : T_pstore_rr <mnemonic, RC, MajOp, 1, 1, isH>;
791   }
792 }
793
794 //===----------------------------------------------------------------------===//
795 // multiclass for new-value store instructions with base + register offset
796 // addressing mode.
797 //===----------------------------------------------------------------------===//
798 let mayStore = 1, isNVStore = 1 in
799 multiclass ST_Idxd_shl_nv <string mnemonic, string CextOp, RegisterClass RC,
800                            bits<2> MajOp> {
801   let CextOpcode = CextOp, BaseOpcode = CextOp#_indexed_shl in {
802     def S4_#NAME#new_rr : T_store_new_rr<mnemonic, MajOp>;
803
804     // Predicated
805     def S4_p#NAME#newt_rr : T_pstore_new_rr <mnemonic, MajOp, 0, 0>;
806     def S4_p#NAME#newf_rr : T_pstore_new_rr <mnemonic, MajOp, 1, 0>;
807
808     // Predicated new
809     def S4_p#NAME#newtnew_rr : T_pstore_new_rr <mnemonic, MajOp, 0, 1>;
810     def S4_p#NAME#newfnew_rr : T_pstore_new_rr <mnemonic, MajOp, 1, 1>;
811   }
812 }
813
814 let addrMode = BaseRegOffset, InputType = "reg", hasSideEffects = 0 in {
815   let accessSize = ByteAccess in
816   defm storerb: ST_Idxd_shl<"memb", "STrib", IntRegs, 0b000>,
817                 ST_Idxd_shl_nv<"memb", "STrib", IntRegs, 0b00>;
818
819   let accessSize = HalfWordAccess in
820   defm storerh: ST_Idxd_shl<"memh", "STrih", IntRegs, 0b010>,
821                 ST_Idxd_shl_nv<"memh", "STrih", IntRegs, 0b01>;
822
823   let accessSize = WordAccess in
824   defm storeri: ST_Idxd_shl<"memw", "STriw", IntRegs, 0b100>,
825                 ST_Idxd_shl_nv<"memw", "STriw", IntRegs, 0b10>;
826
827   let isNVStorable = 0, accessSize = DoubleWordAccess in
828   defm storerd: ST_Idxd_shl<"memd", "STrid", DoubleRegs, 0b110>;
829
830   let isNVStorable = 0, accessSize = HalfWordAccess in
831   defm storerf: ST_Idxd_shl<"memh", "STrif", IntRegs, 0b011, 1>;
832 }
833
834 //===----------------------------------------------------------------------===//
835 // Template class
836 //===----------------------------------------------------------------------===//
837 let isPredicable = 1, isExtendable = 1, isExtentSigned = 1, opExtentBits = 8,
838     opExtendable = 2 in
839 class T_StoreImm <string mnemonic, Operand OffsetOp, bits<2> MajOp >
840   : STInst <(outs ), (ins IntRegs:$Rs, OffsetOp:$offset, s8_0Ext:$S8),
841   mnemonic#"($Rs+#$offset)=#$S8",
842   [], "", V4LDST_tc_st_SLOT01>,
843   ImmRegRel, PredNewRel {
844     bits<5> Rs;
845     bits<8> S8;
846     bits<8> offset;
847     bits<6> offsetBits;
848
849     string OffsetOpStr = !cast<string>(OffsetOp);
850     let offsetBits = !if (!eq(OffsetOpStr, "u6_2Imm"), offset{7-2},
851                      !if (!eq(OffsetOpStr, "u6_1Imm"), offset{6-1},
852                                          /* u6_0Imm */ offset{5-0}));
853
854     let IClass = 0b0011;
855
856     let Inst{27-25} = 0b110;
857     let Inst{22-21} = MajOp;
858     let Inst{20-16} = Rs;
859     let Inst{12-7}  = offsetBits;
860     let Inst{13}    = S8{7};
861     let Inst{6-0}   = S8{6-0};
862   }
863
864 let isPredicated = 1, isExtendable = 1, isExtentSigned = 1, opExtentBits = 6,
865     opExtendable = 3 in
866 class T_StoreImm_pred <string mnemonic, Operand OffsetOp, bits<2> MajOp,
867                        bit isPredNot, bit isPredNew >
868   : STInst <(outs ),
869             (ins PredRegs:$Pv, IntRegs:$Rs, OffsetOp:$offset, s6_0Ext:$S6),
870   !if(isPredNot, "if (!$Pv", "if ($Pv")#!if(isPredNew, ".new) ",
871   ") ")#mnemonic#"($Rs+#$offset)=#$S6",
872   [], "", V4LDST_tc_st_SLOT01>,
873   ImmRegRel, PredNewRel {
874     bits<2> Pv;
875     bits<5> Rs;
876     bits<6> S6;
877     bits<8> offset;
878     bits<6> offsetBits;
879
880     string OffsetOpStr = !cast<string>(OffsetOp);
881     let offsetBits = !if (!eq(OffsetOpStr, "u6_2Imm"), offset{7-2},
882                      !if (!eq(OffsetOpStr, "u6_1Imm"), offset{6-1},
883                                          /* u6_0Imm */ offset{5-0}));
884     let isPredicatedNew = isPredNew;
885     let isPredicatedFalse = isPredNot;
886
887     let IClass = 0b0011;
888
889     let Inst{27-25} = 0b100;
890     let Inst{24}    = isPredNew;
891     let Inst{23}    = isPredNot;
892     let Inst{22-21} = MajOp;
893     let Inst{20-16} = Rs;
894     let Inst{13}    = S6{5};
895     let Inst{12-7}  = offsetBits;
896     let Inst{6-5}   = Pv;
897     let Inst{4-0}   = S6{4-0};
898   }
899
900
901 //===----------------------------------------------------------------------===//
902 // multiclass for store instructions with base + immediate offset
903 // addressing mode and immediate stored value.
904 // mem[bhw](Rx++#s4:3)=#s8
905 // if ([!]Pv[.new]) mem[bhw](Rx++#s4:3)=#s6
906 //===----------------------------------------------------------------------===//
907
908 multiclass ST_Imm_Pred <string mnemonic, Operand OffsetOp, bits<2> MajOp,
909                         bit PredNot> {
910   def _io    : T_StoreImm_pred <mnemonic, OffsetOp, MajOp, PredNot, 0>;
911   // Predicate new
912   def new_io : T_StoreImm_pred <mnemonic, OffsetOp, MajOp, PredNot, 1>;
913 }
914
915 multiclass ST_Imm <string mnemonic, string CextOp, Operand OffsetOp,
916                    bits<2> MajOp> {
917   let CextOpcode = CextOp, BaseOpcode = CextOp#_imm in {
918     def _io : T_StoreImm <mnemonic, OffsetOp, MajOp>;
919
920     defm t : ST_Imm_Pred <mnemonic, OffsetOp, MajOp, 0>;
921     defm f : ST_Imm_Pred <mnemonic, OffsetOp, MajOp, 1>;
922   }
923 }
924
925 let hasSideEffects = 0, addrMode = BaseImmOffset,
926     InputType = "imm" in {
927   let accessSize = ByteAccess in
928   defm S4_storeirb : ST_Imm<"memb", "STrib", u6_0Imm, 0b00>;
929
930   let accessSize = HalfWordAccess in
931   defm S4_storeirh : ST_Imm<"memh", "STrih", u6_1Imm, 0b01>;
932
933   let accessSize = WordAccess in
934   defm S4_storeiri : ST_Imm<"memw", "STriw", u6_2Imm, 0b10>;
935 }
936
937 //===----------------------------------------------------------------------===
938 // ST -
939 //===----------------------------------------------------------------------===
940
941
942 //===----------------------------------------------------------------------===//
943 // NV/ST +
944 //===----------------------------------------------------------------------===//
945
946 let opNewValue = 2, opExtendable = 1, isExtentSigned = 1, isPredicable = 1 in
947 class T_store_io_nv <string mnemonic, RegisterClass RC,
948                     Operand ImmOp, bits<2>MajOp>
949   : NVInst_V4 <(outs),
950                (ins IntRegs:$src1, ImmOp:$src2, RC:$src3),
951   mnemonic#"($src1+#$src2) = $src3.new",
952   [],"",ST_tc_st_SLOT0> {
953     bits<5> src1;
954     bits<13> src2; // Actual address offset
955     bits<3> src3;
956     bits<11> offsetBits; // Represents offset encoding
957
958     let opExtentBits = !if (!eq(mnemonic, "memb"), 11,
959                        !if (!eq(mnemonic, "memh"), 12,
960                        !if (!eq(mnemonic, "memw"), 13, 0)));
961
962     let opExtentAlign = !if (!eq(mnemonic, "memb"), 0,
963                         !if (!eq(mnemonic, "memh"), 1,
964                         !if (!eq(mnemonic, "memw"), 2, 0)));
965
966     let offsetBits = !if (!eq(mnemonic, "memb"),  src2{10-0},
967                      !if (!eq(mnemonic, "memh"),  src2{11-1},
968                      !if (!eq(mnemonic, "memw"),  src2{12-2}, 0)));
969
970     let IClass = 0b1010;
971
972     let Inst{27} = 0b0;
973     let Inst{26-25} = offsetBits{10-9};
974     let Inst{24-21} = 0b1101;
975     let Inst{20-16} = src1;
976     let Inst{13} = offsetBits{8};
977     let Inst{12-11} = MajOp;
978     let Inst{10-8} = src3;
979     let Inst{7-0} = offsetBits{7-0};
980   }
981
982 let opExtendable = 2, opNewValue = 3, isPredicated = 1 in
983 class T_pstore_io_nv <string mnemonic, RegisterClass RC, Operand predImmOp,
984                          bits<2>MajOp, bit PredNot, bit isPredNew>
985   : NVInst_V4 <(outs),
986                (ins PredRegs:$src1, IntRegs:$src2, predImmOp:$src3, RC:$src4),
987   !if(PredNot, "if (!$src1", "if ($src1")#!if(isPredNew, ".new) ",
988   ") ")#mnemonic#"($src2+#$src3) = $src4.new",
989   [],"",V2LDST_tc_st_SLOT0> {
990     bits<2> src1;
991     bits<5> src2;
992     bits<9> src3;
993     bits<3> src4;
994     bits<6> offsetBits; // Represents offset encoding
995
996     let isPredicatedNew = isPredNew;
997     let isPredicatedFalse = PredNot;
998     let opExtentBits = !if (!eq(mnemonic, "memb"), 6,
999                        !if (!eq(mnemonic, "memh"), 7,
1000                        !if (!eq(mnemonic, "memw"), 8, 0)));
1001
1002     let opExtentAlign = !if (!eq(mnemonic, "memb"), 0,
1003                         !if (!eq(mnemonic, "memh"), 1,
1004                         !if (!eq(mnemonic, "memw"), 2, 0)));
1005
1006     let offsetBits = !if (!eq(mnemonic, "memb"), src3{5-0},
1007                      !if (!eq(mnemonic, "memh"), src3{6-1},
1008                      !if (!eq(mnemonic, "memw"), src3{7-2}, 0)));
1009
1010     let IClass = 0b0100;
1011
1012     let Inst{27}    = 0b0;
1013     let Inst{26}    = PredNot;
1014     let Inst{25}    = isPredNew;
1015     let Inst{24-21} = 0b0101;
1016     let Inst{20-16} = src2;
1017     let Inst{13}    = offsetBits{5};
1018     let Inst{12-11} = MajOp;
1019     let Inst{10-8}  = src4;
1020     let Inst{7-3}   = offsetBits{4-0};
1021     let Inst{2}     = 0b0;
1022     let Inst{1-0}   = src1;
1023   }
1024
1025 // multiclass for new-value store instructions with base + immediate offset.
1026 //
1027 let mayStore = 1, isNVStore = 1, isNewValue = 1, hasSideEffects = 0,
1028     isExtendable = 1 in
1029 multiclass ST_Idxd_nv<string mnemonic, string CextOp, RegisterClass RC,
1030                    Operand ImmOp, Operand predImmOp, bits<2> MajOp> {
1031
1032   let CextOpcode = CextOp, BaseOpcode = CextOp#_indexed in {
1033     def S2_#NAME#new_io : T_store_io_nv <mnemonic, RC, ImmOp, MajOp>;
1034     // Predicated
1035     def S2_p#NAME#newt_io :T_pstore_io_nv <mnemonic, RC, predImmOp, MajOp, 0, 0>;
1036     def S2_p#NAME#newf_io :T_pstore_io_nv <mnemonic, RC, predImmOp, MajOp, 1, 0>;
1037     // Predicated new
1038     def S4_p#NAME#newtnew_io :T_pstore_io_nv <mnemonic, RC, predImmOp,
1039                                               MajOp, 0, 1>;
1040     def S4_p#NAME#newfnew_io :T_pstore_io_nv <mnemonic, RC, predImmOp,
1041                                               MajOp, 1, 1>;
1042   }
1043 }
1044
1045 let addrMode = BaseImmOffset, InputType = "imm" in {
1046   let accessSize = ByteAccess in
1047   defm storerb: ST_Idxd_nv<"memb", "STrib", IntRegs, s11_0Ext,
1048                            u6_0Ext, 0b00>, AddrModeRel;
1049
1050   let accessSize = HalfWordAccess, opExtentAlign = 1 in
1051   defm storerh: ST_Idxd_nv<"memh", "STrih", IntRegs, s11_1Ext,
1052                            u6_1Ext, 0b01>, AddrModeRel;
1053
1054   let accessSize = WordAccess, opExtentAlign = 2 in
1055   defm storeri: ST_Idxd_nv<"memw", "STriw", IntRegs, s11_2Ext,
1056                            u6_2Ext, 0b10>, AddrModeRel;
1057 }
1058
1059 //===----------------------------------------------------------------------===//
1060 // Post increment loads with register offset.
1061 //===----------------------------------------------------------------------===//
1062
1063 let hasNewValue = 1 in
1064 def L2_loadbsw2_pr : T_load_pr <"membh", IntRegs, 0b0001, HalfWordAccess>;
1065
1066 def L2_loadbsw4_pr : T_load_pr <"membh", DoubleRegs, 0b0111, WordAccess>;
1067
1068 let hasSideEffects = 0, addrMode = PostInc in
1069 class T_loadalign_pr <string mnemonic, bits<4> MajOp, MemAccessSize AccessSz>
1070   : LDInstPI <(outs DoubleRegs:$dst, IntRegs:$_dst_),
1071               (ins DoubleRegs:$src1, IntRegs:$src2, ModRegs:$src3),
1072   "$dst = "#mnemonic#"($src2++$src3)", [],
1073   "$src1 = $dst, $src2 = $_dst_"> {
1074     bits<5> dst;
1075     bits<5> src2;
1076     bits<1> src3;
1077
1078     let accessSize = AccessSz;
1079     let IClass = 0b1001;
1080
1081     let Inst{27-25} = 0b110;
1082     let Inst{24-21} = MajOp;
1083     let Inst{20-16} = src2;
1084     let Inst{13}    = src3;
1085     let Inst{12}    = 0b0;
1086     let Inst{7}     = 0b0;
1087     let Inst{4-0}   = dst;
1088   }
1089
1090 def L2_loadalignb_pr : T_loadalign_pr <"memb_fifo", 0b0100, ByteAccess>;
1091 def L2_loadalignh_pr : T_loadalign_pr <"memh_fifo", 0b0010, HalfWordAccess>;
1092
1093 //===----------------------------------------------------------------------===//
1094 // Template class for non-predicated post increment .new stores
1095 // mem[bhwd](Rx++#s4:[0123])=Nt.new
1096 //===----------------------------------------------------------------------===//
1097 let isPredicable = 1, hasSideEffects = 0, addrMode = PostInc, isNVStore = 1,
1098     isNewValue = 1, opNewValue = 3 in
1099 class T_StorePI_nv <string mnemonic, Operand ImmOp, bits<2> MajOp >
1100   : NVInstPI_V4 <(outs IntRegs:$_dst_),
1101                  (ins IntRegs:$src1, ImmOp:$offset, IntRegs:$src2),
1102   mnemonic#"($src1++#$offset) = $src2.new",
1103   [], "$src1 = $_dst_">,
1104   AddrModeRel {
1105     bits<5> src1;
1106     bits<3> src2;
1107     bits<7> offset;
1108     bits<4> offsetBits;
1109
1110     string ImmOpStr = !cast<string>(ImmOp);
1111     let offsetBits = !if (!eq(ImmOpStr, "s4_2Imm"), offset{5-2},
1112                      !if (!eq(ImmOpStr, "s4_1Imm"), offset{4-1},
1113                                       /* s4_0Imm */ offset{3-0}));
1114     let IClass = 0b1010;
1115
1116     let Inst{27-21} = 0b1011101;
1117     let Inst{20-16} = src1;
1118     let Inst{13} = 0b0;
1119     let Inst{12-11} = MajOp;
1120     let Inst{10-8} = src2;
1121     let Inst{7} = 0b0;
1122     let Inst{6-3} = offsetBits;
1123     let Inst{1} = 0b0;
1124   }
1125
1126 //===----------------------------------------------------------------------===//
1127 // Template class for predicated post increment .new stores
1128 // if([!]Pv[.new]) mem[bhwd](Rx++#s4:[0123])=Nt.new
1129 //===----------------------------------------------------------------------===//
1130 let isPredicated = 1, hasSideEffects = 0, addrMode = PostInc, isNVStore = 1,
1131     isNewValue = 1, opNewValue = 4 in
1132 class T_StorePI_nv_pred <string mnemonic, Operand ImmOp,
1133                          bits<2> MajOp, bit isPredNot, bit isPredNew >
1134   : NVInstPI_V4 <(outs IntRegs:$_dst_),
1135                  (ins PredRegs:$src1, IntRegs:$src2,
1136                       ImmOp:$offset, IntRegs:$src3),
1137   !if(isPredNot, "if (!$src1", "if ($src1")#!if(isPredNew, ".new) ",
1138   ") ")#mnemonic#"($src2++#$offset) = $src3.new",
1139   [], "$src2 = $_dst_">,
1140   AddrModeRel {
1141     bits<2> src1;
1142     bits<5> src2;
1143     bits<3> src3;
1144     bits<7> offset;
1145     bits<4> offsetBits;
1146
1147     string ImmOpStr = !cast<string>(ImmOp);
1148     let offsetBits = !if (!eq(ImmOpStr, "s4_2Imm"), offset{5-2},
1149                      !if (!eq(ImmOpStr, "s4_1Imm"), offset{4-1},
1150                                       /* s4_0Imm */ offset{3-0}));
1151     let isPredicatedNew = isPredNew;
1152     let isPredicatedFalse = isPredNot;
1153
1154     let IClass = 0b1010;
1155
1156     let Inst{27-21} = 0b1011101;
1157     let Inst{20-16} = src2;
1158     let Inst{13} = 0b1;
1159     let Inst{12-11} = MajOp;
1160     let Inst{10-8} = src3;
1161     let Inst{7} = isPredNew;
1162     let Inst{6-3} = offsetBits;
1163     let Inst{2} = isPredNot;
1164     let Inst{1-0} = src1;
1165   }
1166
1167 multiclass ST_PostInc_Pred_nv<string mnemonic, Operand ImmOp,
1168                               bits<2> MajOp, bit PredNot> {
1169   def _pi : T_StorePI_nv_pred <mnemonic, ImmOp, MajOp, PredNot, 0>;
1170
1171   // Predicate new
1172   def new_pi : T_StorePI_nv_pred <mnemonic, ImmOp, MajOp, PredNot, 1>;
1173 }
1174
1175 multiclass ST_PostInc_nv<string mnemonic, string BaseOp, Operand ImmOp,
1176                          bits<2> MajOp> {
1177   let BaseOpcode = "POST_"#BaseOp in {
1178     def S2_#NAME#_pi : T_StorePI_nv <mnemonic, ImmOp, MajOp>;
1179
1180     // Predicated
1181     defm S2_p#NAME#t : ST_PostInc_Pred_nv <mnemonic, ImmOp, MajOp, 0>;
1182     defm S2_p#NAME#f : ST_PostInc_Pred_nv <mnemonic, ImmOp, MajOp, 1>;
1183   }
1184 }
1185
1186 let accessSize = ByteAccess in
1187 defm storerbnew: ST_PostInc_nv <"memb", "STrib", s4_0Imm, 0b00>;
1188
1189 let accessSize = HalfWordAccess in
1190 defm storerhnew: ST_PostInc_nv <"memh", "STrih", s4_1Imm, 0b01>;
1191
1192 let accessSize = WordAccess in
1193 defm storerinew: ST_PostInc_nv <"memw", "STriw", s4_2Imm, 0b10>;
1194
1195 //===----------------------------------------------------------------------===//
1196 // Template class for post increment .new stores with register offset
1197 //===----------------------------------------------------------------------===//
1198 let isNewValue = 1, mayStore = 1, isNVStore = 1, opNewValue = 3 in
1199 class T_StorePI_RegNV <string mnemonic, bits<2> MajOp, MemAccessSize AccessSz>
1200   : NVInstPI_V4 <(outs IntRegs:$_dst_),
1201                  (ins IntRegs:$src1, ModRegs:$src2, IntRegs:$src3),
1202   #mnemonic#"($src1++$src2) = $src3.new",
1203   [], "$src1 = $_dst_"> {
1204     bits<5> src1;
1205     bits<1> src2;
1206     bits<3> src3;
1207     let accessSize = AccessSz;
1208
1209     let IClass = 0b1010;
1210
1211     let Inst{27-21} = 0b1101101;
1212     let Inst{20-16} = src1;
1213     let Inst{13}    = src2;
1214     let Inst{12-11} = MajOp;
1215     let Inst{10-8}  = src3;
1216     let Inst{7}     = 0b0;
1217   }
1218
1219 def S2_storerbnew_pr : T_StorePI_RegNV<"memb", 0b00, ByteAccess>;
1220 def S2_storerhnew_pr : T_StorePI_RegNV<"memh", 0b01, HalfWordAccess>;
1221 def S2_storerinew_pr : T_StorePI_RegNV<"memw", 0b10, WordAccess>;
1222
1223 // memb(Rx++#s4:0:circ(Mu))=Nt.new
1224 // memb(Rx++I:circ(Mu))=Nt.new
1225 // memb(Rx++Mu:brev)=Nt.new
1226 // memh(Rx++#s4:1:circ(Mu))=Nt.new
1227 // memh(Rx++I:circ(Mu))=Nt.new
1228 // memh(Rx++Mu)=Nt.new
1229 // memh(Rx++Mu:brev)=Nt.new
1230
1231 // memw(Rx++#s4:2:circ(Mu))=Nt.new
1232 // memw(Rx++I:circ(Mu))=Nt.new
1233 // memw(Rx++Mu)=Nt.new
1234 // memw(Rx++Mu:brev)=Nt.new
1235
1236 //===----------------------------------------------------------------------===//
1237 // NV/ST -
1238 //===----------------------------------------------------------------------===//
1239
1240 //===----------------------------------------------------------------------===//
1241 // NV/J +
1242 //===----------------------------------------------------------------------===//
1243
1244 //===----------------------------------------------------------------------===//
1245 // multiclass/template class for the new-value compare jumps with the register
1246 // operands.
1247 //===----------------------------------------------------------------------===//
1248
1249 let isExtendable = 1, opExtendable = 2, isExtentSigned = 1, opExtentBits = 11,
1250     opExtentAlign = 2 in
1251 class NVJrr_template<string mnemonic, bits<3> majOp, bit NvOpNum,
1252                       bit isNegCond, bit isTak>
1253   : NVInst_V4<(outs),
1254     (ins IntRegs:$src1, IntRegs:$src2, brtarget:$offset),
1255     "if ("#!if(isNegCond, "!","")#mnemonic#
1256     "($src1"#!if(!eq(NvOpNum, 0),".new, ",", ")#
1257     "$src2"#!if(!eq(NvOpNum, 1),".new))","))")#" jump:"
1258     #!if(isTak, "t","nt")#" $offset", []> {
1259
1260       bits<5> src1;
1261       bits<5> src2;
1262       bits<3> Ns;    // New-Value Operand
1263       bits<5> RegOp; // Non-New-Value Operand
1264       bits<11> offset;
1265
1266       let isTaken = isTak;
1267       let isPredicatedFalse = isNegCond;
1268       let opNewValue{0} = NvOpNum;
1269
1270       let Ns = !if(!eq(NvOpNum, 0), src1{2-0}, src2{2-0});
1271       let RegOp = !if(!eq(NvOpNum, 0), src2, src1);
1272
1273       let IClass = 0b0010;
1274       let Inst{27-26} = 0b00;
1275       let Inst{25-23} = majOp;
1276       let Inst{22} = isNegCond;
1277       let Inst{18-16} = Ns;
1278       let Inst{13} = isTak;
1279       let Inst{12-8} = RegOp;
1280       let Inst{21-20} = offset{10-9};
1281       let Inst{7-1} = offset{8-2};
1282 }
1283
1284
1285 multiclass NVJrr_cond<string mnemonic, bits<3> majOp, bit NvOpNum,
1286                        bit isNegCond> {
1287   // Branch not taken:
1288   def _nt: NVJrr_template<mnemonic, majOp, NvOpNum, isNegCond, 0>;
1289   // Branch taken:
1290   def _t : NVJrr_template<mnemonic, majOp, NvOpNum, isNegCond, 1>;
1291 }
1292
1293 // NvOpNum = 0 -> First Operand is a new-value Register
1294 // NvOpNum = 1 -> Second Operand is a new-value Register
1295
1296 multiclass NVJrr_base<string mnemonic, string BaseOp, bits<3> majOp,
1297                        bit NvOpNum> {
1298   let BaseOpcode = BaseOp#_NVJ in {
1299     defm _t_jumpnv : NVJrr_cond<mnemonic, majOp, NvOpNum, 0>; // True cond
1300     defm _f_jumpnv : NVJrr_cond<mnemonic, majOp, NvOpNum, 1>; // False cond
1301   }
1302 }
1303
1304 // if ([!]cmp.eq(Ns.new,Rt)) jump:[n]t #r9:2
1305 // if ([!]cmp.gt(Ns.new,Rt)) jump:[n]t #r9:2
1306 // if ([!]cmp.gtu(Ns.new,Rt)) jump:[n]t #r9:2
1307 // if ([!]cmp.gt(Rt,Ns.new)) jump:[n]t #r9:2
1308 // if ([!]cmp.gtu(Rt,Ns.new)) jump:[n]t #r9:2
1309
1310 let isPredicated = 1, isBranch = 1, isNewValue = 1, isTerminator = 1,
1311     Defs = [PC], hasSideEffects = 0 in {
1312   defm J4_cmpeq  : NVJrr_base<"cmp.eq",  "CMPEQ",  0b000, 0>, PredRel;
1313   defm J4_cmpgt  : NVJrr_base<"cmp.gt",  "CMPGT",  0b001, 0>, PredRel;
1314   defm J4_cmpgtu : NVJrr_base<"cmp.gtu", "CMPGTU", 0b010, 0>, PredRel;
1315   defm J4_cmplt  : NVJrr_base<"cmp.gt",  "CMPLT",  0b011, 1>, PredRel;
1316   defm J4_cmpltu : NVJrr_base<"cmp.gtu", "CMPLTU", 0b100, 1>, PredRel;
1317 }
1318
1319 //===----------------------------------------------------------------------===//
1320 // multiclass/template class for the new-value compare jumps instruction
1321 // with a register and an unsigned immediate (U5) operand.
1322 //===----------------------------------------------------------------------===//
1323
1324 let isExtendable = 1, opExtendable = 2, isExtentSigned = 1, opExtentBits = 11,
1325     opExtentAlign = 2 in
1326 class NVJri_template<string mnemonic, bits<3> majOp, bit isNegCond,
1327                          bit isTak>
1328   : NVInst_V4<(outs),
1329     (ins IntRegs:$src1, u5_0Imm:$src2, brtarget:$offset),
1330     "if ("#!if(isNegCond, "!","")#mnemonic#"($src1.new, #$src2)) jump:"
1331     #!if(isTak, "t","nt")#" $offset", []> {
1332
1333       let isTaken = isTak;
1334       let isPredicatedFalse = isNegCond;
1335       let isTaken = isTak;
1336
1337       bits<3> src1;
1338       bits<5> src2;
1339       bits<11> offset;
1340
1341       let IClass = 0b0010;
1342       let Inst{26} = 0b1;
1343       let Inst{25-23} = majOp;
1344       let Inst{22} = isNegCond;
1345       let Inst{18-16} = src1;
1346       let Inst{13} = isTak;
1347       let Inst{12-8} = src2;
1348       let Inst{21-20} = offset{10-9};
1349       let Inst{7-1} = offset{8-2};
1350 }
1351
1352 multiclass NVJri_cond<string mnemonic, bits<3> majOp, bit isNegCond> {
1353   // Branch not taken:
1354   def _nt: NVJri_template<mnemonic, majOp, isNegCond, 0>;
1355   // Branch taken:
1356   def _t : NVJri_template<mnemonic, majOp, isNegCond, 1>;
1357 }
1358
1359 multiclass NVJri_base<string mnemonic, string BaseOp, bits<3> majOp> {
1360   let BaseOpcode = BaseOp#_NVJri in {
1361     defm _t_jumpnv : NVJri_cond<mnemonic, majOp, 0>; // True Cond
1362     defm _f_jumpnv : NVJri_cond<mnemonic, majOp, 1>; // False cond
1363   }
1364 }
1365
1366 // if ([!]cmp.eq(Ns.new,#U5)) jump:[n]t #r9:2
1367 // if ([!]cmp.gt(Ns.new,#U5)) jump:[n]t #r9:2
1368 // if ([!]cmp.gtu(Ns.new,#U5)) jump:[n]t #r9:2
1369
1370 let isPredicated = 1, isBranch = 1, isNewValue = 1, isTerminator = 1,
1371     Defs = [PC], hasSideEffects = 0 in {
1372   defm J4_cmpeqi  : NVJri_base<"cmp.eq", "CMPEQ", 0b000>, PredRel;
1373   defm J4_cmpgti  : NVJri_base<"cmp.gt", "CMPGT", 0b001>, PredRel;
1374   defm J4_cmpgtui : NVJri_base<"cmp.gtu", "CMPGTU", 0b010>, PredRel;
1375 }
1376
1377 //===----------------------------------------------------------------------===//
1378 // multiclass/template class for the new-value compare jumps instruction
1379 // with a register and an hardcoded 0/-1 immediate value.
1380 //===----------------------------------------------------------------------===//
1381
1382 let isExtendable = 1, isExtentSigned = 1, opExtentBits = 11,
1383     opExtentAlign = 2 in
1384 class NVJ_ConstImm_template<string mnemonic, bits<3> majOp, string ImmVal,
1385                             bit isNegCond, bit isTak>
1386   : NVInst_V4<(outs),
1387     !if(!eq(ImmVal, "{-1}"),
1388         (ins IntRegs:$src1, n1Const:$n1, brtarget:$offset),
1389         (ins IntRegs:$src1, brtarget:$offset)),
1390     "if ("#!if(isNegCond, "!","")#mnemonic
1391     #"($src1.new, #" # !if(!eq(ImmVal, "{-1}"), "$n1", ImmVal) # ")) jump:"
1392     #!if(isTak, "t","nt")#" $offset", []> {
1393
1394       let isTaken = isTak;
1395       let isPredicatedFalse = isNegCond;
1396       let isTaken = isTak;
1397       let opExtendable = !if(!eq(ImmVal, "{-1}"), 2, 1);
1398
1399       bits<3> src1;
1400       bits<11> offset;
1401       let IClass = 0b0010;
1402       let Inst{26} = 0b1;
1403       let Inst{25-23} = majOp;
1404       let Inst{22} = isNegCond;
1405       let Inst{18-16} = src1;
1406       let Inst{13} = isTak;
1407       let Inst{21-20} = offset{10-9};
1408       let Inst{7-1} = offset{8-2};
1409 }
1410
1411 multiclass NVJ_ConstImm_cond<string mnemonic, bits<3> majOp, string ImmVal,
1412                              bit isNegCond> {
1413   // Branch not taken:
1414   def _nt: NVJ_ConstImm_template<mnemonic, majOp, ImmVal, isNegCond, 0>;
1415   // Branch taken:
1416   def _t : NVJ_ConstImm_template<mnemonic, majOp, ImmVal, isNegCond, 1>;
1417 }
1418
1419 multiclass NVJ_ConstImm_base<string mnemonic, string BaseOp, bits<3> majOp,
1420                              string ImmVal> {
1421   let BaseOpcode = BaseOp#_NVJ_ConstImm in {
1422     defm _t_jumpnv : NVJ_ConstImm_cond<mnemonic, majOp, ImmVal, 0>; // True
1423     defm _f_jumpnv : NVJ_ConstImm_cond<mnemonic, majOp, ImmVal, 1>; // False
1424   }
1425 }
1426
1427 // if ([!]tstbit(Ns.new,#0)) jump:[n]t #r9:2
1428 // if ([!]cmp.eq(Ns.new,#-1)) jump:[n]t #r9:2
1429 // if ([!]cmp.gt(Ns.new,#-1)) jump:[n]t #r9:2
1430
1431 let isPredicated = 1, isBranch = 1, isNewValue = 1, isTerminator=1,
1432     Defs = [PC], hasSideEffects = 0 in {
1433   defm J4_tstbit0 : NVJ_ConstImm_base<"tstbit", "TSTBIT", 0b011, "0">, PredRel;
1434   defm J4_cmpeqn1 : NVJ_ConstImm_base<"cmp.eq", "CMPEQ",  0b100, "{-1}">, PredRel;
1435   defm J4_cmpgtn1 : NVJ_ConstImm_base<"cmp.gt", "CMPGT",  0b101, "{-1}">, PredRel;
1436 }
1437
1438 // J4_hintjumpr: Hint indirect conditional jump.
1439 let isBranch = 1, isIndirectBranch = 1, hasSideEffects = 0 in
1440 def J4_hintjumpr: JRInst <
1441   (outs),
1442   (ins IntRegs:$Rs),
1443   "hintjr($Rs)"> {
1444     bits<5> Rs;
1445     let IClass = 0b0101;
1446     let Inst{27-21} = 0b0010101;
1447     let Inst{20-16} = Rs;
1448   }
1449
1450 //===----------------------------------------------------------------------===//
1451 // NV/J -
1452 //===----------------------------------------------------------------------===//
1453
1454 //===----------------------------------------------------------------------===//
1455 // CR +
1456 //===----------------------------------------------------------------------===//
1457
1458 // PC-relative add
1459 let hasNewValue = 1, isExtendable = 1, opExtendable = 1,
1460     isExtentSigned = 0, opExtentBits = 6, hasSideEffects = 0, Uses = [PC] in
1461 def C4_addipc : CRInst <(outs IntRegs:$Rd), (ins u6_0Ext:$u6),
1462   "$Rd = add(pc, #$u6)", [], "", CR_tc_2_SLOT3 > {
1463     bits<5> Rd;
1464     bits<6> u6;
1465
1466     let IClass = 0b0110;
1467     let Inst{27-16} = 0b101001001001;
1468     let Inst{12-7} = u6;
1469     let Inst{4-0} = Rd;
1470   }
1471
1472
1473
1474 let hasSideEffects = 0 in
1475 class T_LOGICAL_3OP<string MnOp1, string MnOp2, bits<2> OpBits, bit IsNeg>
1476     : CRInst<(outs PredRegs:$Pd),
1477              (ins PredRegs:$Ps, PredRegs:$Pt, PredRegs:$Pu),
1478              "$Pd = " # MnOp1 # "($Ps, " # MnOp2 # "($Pt, " #
1479                    !if (IsNeg,"!","") # "$Pu))",
1480              [], "", CR_tc_2early_SLOT23> {
1481   bits<2> Pd;
1482   bits<2> Ps;
1483   bits<2> Pt;
1484   bits<2> Pu;
1485
1486   let IClass = 0b0110;
1487   let Inst{27-24} = 0b1011;
1488   let Inst{23} = IsNeg;
1489   let Inst{22-21} = OpBits;
1490   let Inst{20} = 0b1;
1491   let Inst{17-16} = Ps;
1492   let Inst{13} = 0b0;
1493   let Inst{9-8} = Pt;
1494   let Inst{7-6} = Pu;
1495   let Inst{1-0} = Pd;
1496 }
1497
1498 def C4_and_and  : T_LOGICAL_3OP<"and", "and", 0b00, 0>;
1499 def C4_and_or   : T_LOGICAL_3OP<"and", "or",  0b01, 0>;
1500 def C4_or_and   : T_LOGICAL_3OP<"or",  "and", 0b10, 0>;
1501 def C4_or_or    : T_LOGICAL_3OP<"or",  "or",  0b11, 0>;
1502 def C4_and_andn : T_LOGICAL_3OP<"and", "and", 0b00, 1>;
1503 def C4_and_orn  : T_LOGICAL_3OP<"and", "or",  0b01, 1>;
1504 def C4_or_andn  : T_LOGICAL_3OP<"or",  "and", 0b10, 1>;
1505 def C4_or_orn   : T_LOGICAL_3OP<"or",  "or",  0b11, 1>;
1506
1507 //===----------------------------------------------------------------------===//
1508 // CR -
1509 //===----------------------------------------------------------------------===//
1510
1511 //===----------------------------------------------------------------------===//
1512 // XTYPE/ALU +
1513 //===----------------------------------------------------------------------===//
1514
1515 // Logical with-not instructions.
1516 def A4_andnp : T_ALU64_logical<"and", 0b001, 1, 0, 1>;
1517 def A4_ornp  : T_ALU64_logical<"or",  0b011, 1, 0, 1>;
1518
1519 let hasNewValue = 1, hasSideEffects = 0 in
1520 def S4_parity: ALU64Inst<(outs IntRegs:$Rd), (ins IntRegs:$Rs, IntRegs:$Rt),
1521       "$Rd = parity($Rs, $Rt)", [], "", ALU64_tc_2_SLOT23> {
1522   bits<5> Rd;
1523   bits<5> Rs;
1524   bits<5> Rt;
1525
1526   let IClass = 0b1101;
1527   let Inst{27-21} = 0b0101111;
1528   let Inst{20-16} = Rs;
1529   let Inst{12-8} = Rt;
1530   let Inst{4-0} = Rd;
1531 }
1532
1533 //  Add and accumulate.
1534 //  Rd=add(Rs,add(Ru,#s6))
1535 let isExtentSigned = 1, hasNewValue = 1, isExtendable = 1, opExtentBits = 6,
1536     opExtendable = 3 in
1537 def S4_addaddi : ALU64Inst <(outs IntRegs:$Rd),
1538                             (ins IntRegs:$Rs, IntRegs:$Ru, s6_0Ext:$s6),
1539   "$Rd = add($Rs, add($Ru, #$s6))" , [],
1540   "", ALU64_tc_2_SLOT23> {
1541     bits<5> Rd;
1542     bits<5> Rs;
1543     bits<5> Ru;
1544     bits<6> s6;
1545
1546     let IClass = 0b1101;
1547
1548     let Inst{27-23} = 0b10110;
1549     let Inst{22-21} = s6{5-4};
1550     let Inst{20-16} = Rs;
1551     let Inst{13}    = s6{3};
1552     let Inst{12-8}  = Rd;
1553     let Inst{7-5}   = s6{2-0};
1554     let Inst{4-0}   = Ru;
1555   }
1556
1557 let isExtentSigned = 1, hasSideEffects = 0, hasNewValue = 1, isExtendable = 1,
1558     opExtentBits = 6, opExtendable = 2 in
1559 def S4_subaddi: ALU64Inst <(outs IntRegs:$Rd),
1560                            (ins IntRegs:$Rs, s6_0Ext:$s6, IntRegs:$Ru),
1561   "$Rd = add($Rs, sub(#$s6, $Ru))",
1562   [], "", ALU64_tc_2_SLOT23> {
1563     bits<5> Rd;
1564     bits<5> Rs;
1565     bits<6> s6;
1566     bits<5> Ru;
1567
1568     let IClass = 0b1101;
1569
1570     let Inst{27-23} = 0b10111;
1571     let Inst{22-21} = s6{5-4};
1572     let Inst{20-16} = Rs;
1573     let Inst{13}    = s6{3};
1574     let Inst{12-8}  = Rd;
1575     let Inst{7-5}   = s6{2-0};
1576     let Inst{4-0}   = Ru;
1577   }
1578
1579 def S4_extractp_rp : T_S3op_64 < "extract",  0b11, 0b100, 0>;
1580 def S4_extractp    : T_S2op_extract <"extract",  0b1010, DoubleRegs, u6_0Imm>;
1581
1582 let hasNewValue = 1 in {
1583   def S4_extract_rp : T_S3op_extract<"extract",  0b01>;
1584   def S4_extract    : T_S2op_extract <"extract",  0b1101, IntRegs, u5_0Imm>;
1585 }
1586
1587 // Complex add/sub halfwords/words
1588 let Defs = [USR_OVF] in {
1589   def S4_vxaddsubh : T_S3op_64 < "vxaddsubh", 0b01, 0b100, 0, 1>;
1590   def S4_vxaddsubw : T_S3op_64 < "vxaddsubw", 0b01, 0b000, 0, 1>;
1591   def S4_vxsubaddh : T_S3op_64 < "vxsubaddh", 0b01, 0b110, 0, 1>;
1592   def S4_vxsubaddw : T_S3op_64 < "vxsubaddw", 0b01, 0b010, 0, 1>;
1593 }
1594
1595 let Defs = [USR_OVF] in {
1596   def S4_vxaddsubhr : T_S3op_64 < "vxaddsubh", 0b11, 0b000, 0, 1, 1, 1>;
1597   def S4_vxsubaddhr : T_S3op_64 < "vxsubaddh", 0b11, 0b010, 0, 1, 1, 1>;
1598 }
1599
1600 let Itinerary = M_tc_3x_SLOT23, Defs = [USR_OVF] in {
1601   def M4_mac_up_s1_sat: T_MType_acc_rr<"+= mpy", 0b011, 0b000, 0, [], 0, 1, 1>;
1602   def M4_nac_up_s1_sat: T_MType_acc_rr<"-= mpy", 0b011, 0b001, 0, [], 0, 1, 1>;
1603 }
1604
1605 // Logical xor with xor accumulation.
1606 // Rxx^=xor(Rss,Rtt)
1607 let hasSideEffects = 0 in
1608 def M4_xor_xacc
1609   : SInst <(outs DoubleRegs:$Rxx),
1610            (ins DoubleRegs:$dst2, DoubleRegs:$Rss, DoubleRegs:$Rtt),
1611   "$Rxx ^= xor($Rss, $Rtt)", [],
1612   "$dst2 = $Rxx", S_3op_tc_1_SLOT23> {
1613     bits<5> Rxx;
1614     bits<5> Rss;
1615     bits<5> Rtt;
1616
1617     let IClass = 0b1100;
1618
1619     let Inst{27-22} = 0b101010;
1620     let Inst{20-16} = Rss;
1621     let Inst{12-8}  = Rtt;
1622     let Inst{7-5}   = 0b000;
1623     let Inst{4-0}   = Rxx;
1624   }
1625
1626 // Rotate and reduce bytes
1627 // Rdd=vrcrotate(Rss,Rt,#u2)
1628 let hasSideEffects = 0 in
1629 def S4_vrcrotate
1630   : SInst <(outs DoubleRegs:$Rdd),
1631            (ins DoubleRegs:$Rss, IntRegs:$Rt, u2_0Imm:$u2),
1632   "$Rdd = vrcrotate($Rss, $Rt, #$u2)",
1633   [], "", S_3op_tc_3x_SLOT23> {
1634     bits<5> Rdd;
1635     bits<5> Rss;
1636     bits<5> Rt;
1637     bits<2> u2;
1638
1639     let IClass = 0b1100;
1640
1641     let Inst{27-22} = 0b001111;
1642     let Inst{20-16} = Rss;
1643     let Inst{13}    = u2{1};
1644     let Inst{12-8}  = Rt;
1645     let Inst{7-6}   = 0b11;
1646     let Inst{5}     = u2{0};
1647     let Inst{4-0}   = Rdd;
1648   }
1649
1650 // Rotate and reduce bytes with accumulation
1651 // Rxx+=vrcrotate(Rss,Rt,#u2)
1652 let hasSideEffects = 0 in
1653 def S4_vrcrotate_acc
1654   : SInst <(outs DoubleRegs:$Rxx),
1655            (ins DoubleRegs:$dst2, DoubleRegs:$Rss, IntRegs:$Rt, u2_0Imm:$u2),
1656   "$Rxx += vrcrotate($Rss, $Rt, #$u2)", [],
1657   "$dst2 = $Rxx", S_3op_tc_3x_SLOT23> {
1658     bits<5> Rxx;
1659     bits<5> Rss;
1660     bits<5> Rt;
1661     bits<2> u2;
1662
1663     let IClass = 0b1100;
1664
1665     let Inst{27-21} = 0b1011101;
1666     let Inst{20-16} = Rss;
1667     let Inst{13}    = u2{1};
1668     let Inst{12-8}  = Rt;
1669     let Inst{5}     = u2{0};
1670     let Inst{4-0}   = Rxx;
1671   }
1672
1673 // Vector reduce conditional negate halfwords
1674 let hasSideEffects = 0 in
1675 def S2_vrcnegh
1676   : SInst <(outs DoubleRegs:$Rxx),
1677            (ins DoubleRegs:$dst2, DoubleRegs:$Rss, IntRegs:$Rt),
1678   "$Rxx += vrcnegh($Rss, $Rt)", [],
1679   "$dst2 = $Rxx", S_3op_tc_3x_SLOT23> {
1680     bits<5> Rxx;
1681     bits<5> Rss;
1682     bits<5> Rt;
1683
1684     let IClass = 0b1100;
1685
1686     let Inst{27-21} = 0b1011001;
1687     let Inst{20-16} = Rss;
1688     let Inst{13}    = 0b1;
1689     let Inst{12-8}  = Rt;
1690     let Inst{7-5}   = 0b111;
1691     let Inst{4-0}   = Rxx;
1692   }
1693
1694 // Split bitfield
1695 def A4_bitspliti : T_S2op_2_di <"bitsplit", 0b110, 0b100>;
1696
1697 // Arithmetic/Convergent round
1698 def A4_cround_ri : T_S2op_2_ii <"cround", 0b111, 0b000>;
1699
1700 def A4_round_ri  : T_S2op_2_ii <"round", 0b111, 0b100>;
1701
1702 let Defs = [USR_OVF] in
1703 def A4_round_ri_sat : T_S2op_2_ii <"round", 0b111, 0b110, 1>;
1704
1705 // Logical-logical words.
1706 // Compound or-and -- Rx=or(Ru,and(Rx,#s10))
1707 let isExtentSigned = 1, hasNewValue = 1, isExtendable = 1, opExtentBits = 10,
1708     opExtendable = 3 in
1709 def S4_or_andix:
1710   ALU64Inst<(outs IntRegs:$Rx),
1711             (ins IntRegs:$Ru, IntRegs:$_src_, s10_0Ext:$s10),
1712   "$Rx = or($Ru, and($_src_, #$s10))" , [] ,
1713   "$_src_ = $Rx", ALU64_tc_2_SLOT23> {
1714     bits<5> Rx;
1715     bits<5> Ru;
1716     bits<10> s10;
1717
1718     let IClass = 0b1101;
1719
1720     let Inst{27-22} = 0b101001;
1721     let Inst{20-16} = Rx;
1722     let Inst{21}    = s10{9};
1723     let Inst{13-5}  = s10{8-0};
1724     let Inst{4-0}   = Ru;
1725   }
1726
1727 // Miscellaneous ALU64 instructions.
1728 //
1729 let hasNewValue = 1, hasSideEffects = 0 in
1730 def A4_modwrapu: ALU64Inst<(outs IntRegs:$Rd), (ins IntRegs:$Rs, IntRegs:$Rt),
1731       "$Rd = modwrap($Rs, $Rt)", [], "", ALU64_tc_2_SLOT23> {
1732   bits<5> Rd;
1733   bits<5> Rs;
1734   bits<5> Rt;
1735
1736   let IClass = 0b1101;
1737   let Inst{27-21} = 0b0011111;
1738   let Inst{20-16} = Rs;
1739   let Inst{12-8} = Rt;
1740   let Inst{7-5} = 0b111;
1741   let Inst{4-0} = Rd;
1742 }
1743
1744 let hasSideEffects = 0 in
1745 def A4_bitsplit: ALU64Inst<(outs DoubleRegs:$Rd),
1746       (ins IntRegs:$Rs, IntRegs:$Rt),
1747       "$Rd = bitsplit($Rs, $Rt)", [], "", ALU64_tc_1_SLOT23> {
1748   bits<5> Rd;
1749   bits<5> Rs;
1750   bits<5> Rt;
1751
1752   let IClass = 0b1101;
1753   let Inst{27-24} = 0b0100;
1754   let Inst{21} = 0b1;
1755   let Inst{20-16} = Rs;
1756   let Inst{12-8} = Rt;
1757   let Inst{4-0} = Rd;
1758 }
1759
1760 let hasSideEffects = 0 in
1761 def dep_S2_packhl: ALU64Inst<(outs DoubleRegs:$Rd),
1762       (ins IntRegs:$Rs, IntRegs:$Rt),
1763       "$Rd = packhl($Rs, $Rt):deprecated", [], "", ALU64_tc_1_SLOT23> {
1764   bits<5> Rd;
1765   bits<5> Rs;
1766   bits<5> Rt;
1767
1768   let IClass = 0b1101;
1769   let Inst{27-24} = 0b0100;
1770   let Inst{21} = 0b0;
1771   let Inst{20-16} = Rs;
1772   let Inst{12-8} = Rt;
1773   let Inst{4-0} = Rd;
1774 }
1775
1776 let hasNewValue = 1, hasSideEffects = 0 in
1777 def dep_A2_addsat: ALU64Inst<(outs IntRegs:$Rd),
1778       (ins IntRegs:$Rs, IntRegs:$Rt),
1779       "$Rd = add($Rs, $Rt):sat:deprecated", [], "", ALU64_tc_2_SLOT23> {
1780   bits<5> Rd;
1781   bits<5> Rs;
1782   bits<5> Rt;
1783
1784   let IClass = 0b1101;
1785   let Inst{27-21} = 0b0101100;
1786   let Inst{20-16} = Rs;
1787   let Inst{12-8} = Rt;
1788   let Inst{7} = 0b0;
1789   let Inst{4-0} = Rd;
1790 }
1791
1792 let hasNewValue = 1, hasSideEffects = 0 in
1793 def dep_A2_subsat: ALU64Inst<(outs IntRegs:$Rd),
1794       (ins IntRegs:$Rs, IntRegs:$Rt),
1795       "$Rd = sub($Rs, $Rt):sat:deprecated", [], "", ALU64_tc_2_SLOT23> {
1796   bits<5> Rd;
1797   bits<5> Rs;
1798   bits<5> Rt;
1799
1800   let IClass = 0b1101;
1801   let Inst{27-21} = 0b0101100;
1802   let Inst{20-16} = Rt;
1803   let Inst{12-8} = Rs;
1804   let Inst{7} = 0b1;
1805   let Inst{4-0} = Rd;
1806 }
1807
1808 // Rx[&|]=xor(Rs,Rt)
1809 def M4_or_xor   : T_MType_acc_rr < "|= xor", 0b110, 0b001, 0>;
1810 def M4_and_xor  : T_MType_acc_rr < "&= xor", 0b010, 0b010, 0>;
1811
1812 // Rx[&|^]=or(Rs,Rt)
1813 def M4_xor_or   : T_MType_acc_rr < "^= or",  0b110, 0b011, 0>;
1814
1815 let CextOpcode = "ORr_ORr" in
1816 def M4_or_or    : T_MType_acc_rr < "|= or",  0b110, 0b000, 0>;
1817 def M4_and_or   : T_MType_acc_rr < "&= or",  0b010, 0b001, 0>;
1818
1819 // Rx[&|^]=and(Rs,Rt)
1820 def M4_xor_and  : T_MType_acc_rr < "^= and", 0b110, 0b010, 0>;
1821
1822 let CextOpcode = "ORr_ANDr" in
1823 def M4_or_and   : T_MType_acc_rr < "|= and", 0b010, 0b011, 0>;
1824 def M4_and_and  : T_MType_acc_rr < "&= and", 0b010, 0b000, 0>;
1825
1826 // Rx[&|^]=and(Rs,~Rt)
1827 def M4_xor_andn : T_MType_acc_rr < "^= and", 0b001, 0b010, 0, [], 1>;
1828 def M4_or_andn  : T_MType_acc_rr < "|= and", 0b001, 0b000, 0, [], 1>;
1829 def M4_and_andn : T_MType_acc_rr < "&= and", 0b001, 0b001, 0, [], 1>;
1830
1831 // Compound or-or and or-and
1832 let isExtentSigned = 1, InputType = "imm", hasNewValue = 1, isExtendable = 1,
1833     opExtentBits = 10, opExtendable = 3 in
1834 class T_CompOR <string mnemonic, bits<2> MajOp, SDNode OpNode>
1835   : MInst_acc <(outs IntRegs:$Rx),
1836                (ins IntRegs:$src1, IntRegs:$Rs, s10_0Ext:$s10),
1837   "$Rx |= "#mnemonic#"($Rs, #$s10)", [],
1838   "$src1 = $Rx", ALU64_tc_2_SLOT23>, ImmRegRel {
1839     bits<5> Rx;
1840     bits<5> Rs;
1841     bits<10> s10;
1842
1843     let IClass = 0b1101;
1844
1845     let Inst{27-24} = 0b1010;
1846     let Inst{23-22} = MajOp;
1847     let Inst{20-16} = Rs;
1848     let Inst{21}    = s10{9};
1849     let Inst{13-5}  = s10{8-0};
1850     let Inst{4-0}   = Rx;
1851   }
1852
1853 let CextOpcode = "ORr_ANDr" in
1854 def S4_or_andi : T_CompOR <"and", 0b00, and>;
1855
1856 let CextOpcode = "ORr_ORr" in
1857 def S4_or_ori : T_CompOR <"or", 0b10, or>;
1858
1859 //    Modulo wrap
1860 //        Rd=modwrap(Rs,Rt)
1861 //    Round
1862 //        Rd=cround(Rs,#u5)
1863 //        Rd=cround(Rs,Rt)
1864 //        Rd=round(Rs,#u5)[:sat]
1865 //        Rd=round(Rs,Rt)[:sat]
1866 //    Vector reduce add unsigned halfwords
1867 //        Rd=vraddh(Rss,Rtt)
1868 //    Vector add bytes
1869 //        Rdd=vaddb(Rss,Rtt)
1870 //    Vector conditional negate
1871 //        Rdd=vcnegh(Rss,Rt)
1872 //        Rxx+=vrcnegh(Rss,Rt)
1873 //    Vector maximum bytes
1874 //        Rdd=vmaxb(Rtt,Rss)
1875 //    Vector reduce maximum halfwords
1876 //        Rxx=vrmaxh(Rss,Ru)
1877 //        Rxx=vrmaxuh(Rss,Ru)
1878 //    Vector reduce maximum words
1879 //        Rxx=vrmaxuw(Rss,Ru)
1880 //        Rxx=vrmaxw(Rss,Ru)
1881 //    Vector minimum bytes
1882 //        Rdd=vminb(Rtt,Rss)
1883 //    Vector reduce minimum halfwords
1884 //        Rxx=vrminh(Rss,Ru)
1885 //        Rxx=vrminuh(Rss,Ru)
1886 //    Vector reduce minimum words
1887 //        Rxx=vrminuw(Rss,Ru)
1888 //        Rxx=vrminw(Rss,Ru)
1889 //    Vector subtract bytes
1890 //        Rdd=vsubb(Rss,Rtt)
1891
1892 //===----------------------------------------------------------------------===//
1893 // XTYPE/ALU -
1894 //===----------------------------------------------------------------------===//
1895
1896 //===----------------------------------------------------------------------===//
1897 // XTYPE/BIT +
1898 //===----------------------------------------------------------------------===//
1899
1900 // Bit reverse
1901 def S2_brevp : T_S2op_3 <"brev", 0b11, 0b110>;
1902
1903 // Bit count
1904 def S2_ct0p : T_COUNT_LEADING_64<"ct0", 0b111, 0b010>;
1905 def S2_ct1p : T_COUNT_LEADING_64<"ct1", 0b111, 0b100>;
1906 def S4_clbpnorm : T_COUNT_LEADING_64<"normamt", 0b011, 0b000>;
1907
1908 let hasSideEffects = 0, hasNewValue = 1 in
1909 def S4_clbaddi : SInst<(outs IntRegs:$Rd), (ins IntRegs:$Rs, s6_0Imm:$s6),
1910     "$Rd = add(clb($Rs), #$s6)", [], "", S_2op_tc_2_SLOT23> {
1911   bits<5> Rs;
1912   bits<5> Rd;
1913   bits<6> s6;
1914   let IClass = 0b1000;
1915   let Inst{27-24} = 0b1100;
1916   let Inst{23-21} = 0b001;
1917   let Inst{20-16} = Rs;
1918   let Inst{13-8} = s6;
1919   let Inst{7-5} = 0b000;
1920   let Inst{4-0} = Rd;
1921 }
1922
1923 let hasSideEffects = 0, hasNewValue = 1 in
1924 def S4_clbpaddi : SInst<(outs IntRegs:$Rd), (ins DoubleRegs:$Rs, s6_0Imm:$s6),
1925     "$Rd = add(clb($Rs), #$s6)", [], "", S_2op_tc_2_SLOT23> {
1926   bits<5> Rs;
1927   bits<5> Rd;
1928   bits<6> s6;
1929   let IClass = 0b1000;
1930   let Inst{27-24} = 0b1000;
1931   let Inst{23-21} = 0b011;
1932   let Inst{20-16} = Rs;
1933   let Inst{13-8} = s6;
1934   let Inst{7-5} = 0b010;
1935   let Inst{4-0} = Rd;
1936 }
1937
1938
1939 // Bit test/set/clear
1940 def S4_ntstbit_i : T_TEST_BIT_IMM<"!tstbit", 0b001>;
1941 def S4_ntstbit_r : T_TEST_BIT_REG<"!tstbit", 1>;
1942
1943 def C4_nbitsset  : T_TEST_BITS_REG<"!bitsset", 0b01, 1>;
1944 def C4_nbitsclr  : T_TEST_BITS_REG<"!bitsclr", 0b10, 1>;
1945 def C4_nbitsclri : T_TEST_BITS_IMM<"!bitsclr", 0b10, 1>;
1946
1947 //===----------------------------------------------------------------------===//
1948 // XTYPE/BIT -
1949 //===----------------------------------------------------------------------===//
1950
1951 //===----------------------------------------------------------------------===//
1952 // XTYPE/MPY +
1953 //===----------------------------------------------------------------------===//
1954
1955 // Rd=add(#u6,mpyi(Rs,#U6)) -- Multiply by immed and add immed.
1956
1957 let hasNewValue = 1, isExtendable = 1, opExtentBits = 6, opExtendable = 1 in
1958 def M4_mpyri_addi : MInst<(outs IntRegs:$Rd),
1959   (ins u6_0Ext:$u6, IntRegs:$Rs, u6_0Imm:$U6),
1960   "$Rd = add(#$u6, mpyi($Rs, #$U6))" , [],"",ALU64_tc_3x_SLOT23> {
1961     bits<5> Rd;
1962     bits<6> u6;
1963     bits<5> Rs;
1964     bits<6> U6;
1965
1966     let IClass = 0b1101;
1967
1968     let Inst{27-24} = 0b1000;
1969     let Inst{23}    = U6{5};
1970     let Inst{22-21} = u6{5-4};
1971     let Inst{20-16} = Rs;
1972     let Inst{13}    = u6{3};
1973     let Inst{12-8}  = Rd;
1974     let Inst{7-5}   = u6{2-0};
1975     let Inst{4-0}   = U6{4-0};
1976   }
1977
1978 // Rd=add(#u6,mpyi(Rs,Rt))
1979 let CextOpcode = "ADD_MPY", InputType = "imm", hasNewValue = 1,
1980     isExtendable = 1, opExtentBits = 6, opExtendable = 1 in
1981 def M4_mpyrr_addi : MInst <(outs IntRegs:$Rd),
1982   (ins u6_0Ext:$u6, IntRegs:$Rs, IntRegs:$Rt),
1983   "$Rd = add(#$u6, mpyi($Rs, $Rt))" , [], "", ALU64_tc_3x_SLOT23>, ImmRegRel {
1984     bits<5> Rd;
1985     bits<6> u6;
1986     bits<5> Rs;
1987     bits<5> Rt;
1988
1989     let IClass = 0b1101;
1990
1991     let Inst{27-23} = 0b01110;
1992     let Inst{22-21} = u6{5-4};
1993     let Inst{20-16} = Rs;
1994     let Inst{13}    = u6{3};
1995     let Inst{12-8}  = Rt;
1996     let Inst{7-5}   = u6{2-0};
1997     let Inst{4-0}   = Rd;
1998   }
1999
2000 let hasNewValue = 1 in
2001 class T_AddMpy <bit MajOp, PatLeaf ImmPred, dag ins>
2002   : ALU64Inst <(outs IntRegs:$dst), ins,
2003   "$dst = add($src1, mpyi("#!if(MajOp,"$src3, #$src2))",
2004                                       "#$src2, $src3))"), [],
2005   "", ALU64_tc_3x_SLOT23> {
2006     bits<5> dst;
2007     bits<5> src1;
2008     bits<8> src2;
2009     bits<5> src3;
2010
2011     let IClass = 0b1101;
2012
2013     bits<6> ImmValue = !if(MajOp, src2{5-0}, src2{7-2});
2014
2015     let Inst{27-24} = 0b1111;
2016     let Inst{23}    = MajOp;
2017     let Inst{22-21} = ImmValue{5-4};
2018     let Inst{20-16} = src3;
2019     let Inst{13}    = ImmValue{3};
2020     let Inst{12-8}  = dst;
2021     let Inst{7-5}   = ImmValue{2-0};
2022     let Inst{4-0}   = src1;
2023   }
2024
2025 def M4_mpyri_addr_u2 : T_AddMpy<0b0, u6_2ImmPred,
2026                        (ins IntRegs:$src1, u6_2Imm:$src2, IntRegs:$src3)>;
2027
2028 let isExtendable = 1, opExtentBits = 6, opExtendable = 3,
2029     CextOpcode = "ADD_MPY", InputType = "imm" in
2030 def M4_mpyri_addr : T_AddMpy<0b1, u32_0ImmPred,
2031                     (ins IntRegs:$src1, IntRegs:$src3, u6_0Ext:$src2)>, ImmRegRel;
2032
2033 // Rx=add(Ru,mpyi(Rx,Rs))
2034 let CextOpcode = "ADD_MPY", InputType = "reg", hasNewValue = 1 in
2035 def M4_mpyrr_addr: MInst_acc <(outs IntRegs:$Rx),
2036                               (ins IntRegs:$Ru, IntRegs:$_src_, IntRegs:$Rs),
2037   "$Rx = add($Ru, mpyi($_src_, $Rs))", [],
2038   "$_src_ = $Rx", M_tc_3x_SLOT23>, ImmRegRel {
2039     bits<5> Rx;
2040     bits<5> Ru;
2041     bits<5> Rs;
2042
2043     let IClass = 0b1110;
2044
2045     let Inst{27-21} = 0b0011000;
2046     let Inst{12-8} = Rx;
2047     let Inst{4-0} = Ru;
2048     let Inst{20-16} = Rs;
2049   }
2050
2051
2052 // Vector reduce multiply word by signed half (32x16)
2053 //Rdd=vrmpyweh(Rss,Rtt)[:<<1]
2054 def M4_vrmpyeh_s0 : T_M2_vmpy<"vrmpyweh", 0b010, 0b100, 0, 0, 0>;
2055 def M4_vrmpyeh_s1 : T_M2_vmpy<"vrmpyweh", 0b110, 0b100, 1, 0, 0>;
2056
2057 //Rdd=vrmpywoh(Rss,Rtt)[:<<1]
2058 def M4_vrmpyoh_s0 : T_M2_vmpy<"vrmpywoh", 0b001, 0b010, 0, 0, 0>;
2059 def M4_vrmpyoh_s1 : T_M2_vmpy<"vrmpywoh", 0b101, 0b010, 1, 0, 0>;
2060
2061 //Rdd+=vrmpyweh(Rss,Rtt)[:<<1]
2062 def M4_vrmpyeh_acc_s0: T_M2_vmpy_acc<"vrmpyweh", 0b001, 0b110, 0, 0>;
2063 def M4_vrmpyeh_acc_s1: T_M2_vmpy_acc<"vrmpyweh", 0b101, 0b110, 1, 0>;
2064
2065 //Rdd=vrmpywoh(Rss,Rtt)[:<<1]
2066 def M4_vrmpyoh_acc_s0: T_M2_vmpy_acc<"vrmpywoh", 0b011, 0b110, 0, 0>;
2067 def M4_vrmpyoh_acc_s1: T_M2_vmpy_acc<"vrmpywoh", 0b111, 0b110, 1, 0>;
2068
2069 // Vector multiply halfwords, signed by unsigned
2070 // Rdd=vmpyhsu(Rs,Rt)[:<<]:sat
2071 def M2_vmpy2su_s0 : T_XTYPE_mpy64 < "vmpyhsu", 0b000, 0b111, 1, 0, 0>;
2072 def M2_vmpy2su_s1 : T_XTYPE_mpy64 < "vmpyhsu", 0b100, 0b111, 1, 1, 0>;
2073
2074 // Rxx+=vmpyhsu(Rs,Rt)[:<<1]:sat
2075 def M2_vmac2su_s0 : T_XTYPE_mpy64_acc < "vmpyhsu", "+", 0b011, 0b101, 1, 0, 0>;
2076 def M2_vmac2su_s1 : T_XTYPE_mpy64_acc < "vmpyhsu", "+", 0b111, 0b101, 1, 1, 0>;
2077
2078 // Vector polynomial multiply halfwords
2079 // Rdd=vpmpyh(Rs,Rt)
2080 def M4_vpmpyh : T_XTYPE_mpy64 < "vpmpyh", 0b110, 0b111, 0, 0, 0>;
2081
2082 // Rxx^=vpmpyh(Rs,Rt)
2083 def M4_vpmpyh_acc : T_XTYPE_mpy64_acc < "vpmpyh", "^", 0b101, 0b111, 0, 0, 0>;
2084
2085 // Polynomial multiply words
2086 // Rdd=pmpyw(Rs,Rt)
2087 def M4_pmpyw : T_XTYPE_mpy64 < "pmpyw", 0b010, 0b111, 0, 0, 0>;
2088
2089 // Rxx^=pmpyw(Rs,Rt)
2090 def M4_pmpyw_acc  : T_XTYPE_mpy64_acc < "pmpyw", "^", 0b001, 0b111, 0, 0, 0>;
2091
2092 //===----------------------------------------------------------------------===//
2093 // XTYPE/MPY -
2094 //===----------------------------------------------------------------------===//
2095
2096 //===----------------------------------------------------------------------===//
2097 // ALU64/Vector compare
2098 //===----------------------------------------------------------------------===//
2099 //===----------------------------------------------------------------------===//
2100 // Template class for vector compare
2101 //===----------------------------------------------------------------------===//
2102
2103 let hasSideEffects = 0 in
2104 class T_vcmpImm <string Str, bits<2> cmpOp, bits<2> minOp, Operand ImmOprnd>
2105   : ALU64_rr <(outs PredRegs:$Pd),
2106               (ins DoubleRegs:$Rss, ImmOprnd:$Imm),
2107   "$Pd = "#Str#"($Rss, #$Imm)",
2108   [], "", ALU64_tc_2early_SLOT23> {
2109     bits<2> Pd;
2110     bits<5> Rss;
2111     bits<32> Imm;
2112     bits<8> ImmBits;
2113     let ImmBits{6-0} = Imm{6-0};
2114     let ImmBits{7} = !if (!eq(cmpOp,0b10), 0b0, Imm{7}); // 0 for vcmp[bhw].gtu
2115
2116     let IClass = 0b1101;
2117
2118     let Inst{27-24} = 0b1100;
2119     let Inst{22-21} = cmpOp;
2120     let Inst{20-16} = Rss;
2121     let Inst{12-5} = ImmBits;
2122     let Inst{4-3} = minOp;
2123     let Inst{1-0} = Pd;
2124   }
2125
2126 // Vector compare bytes
2127 def A4_vcmpbgt   : T_vcmp <"vcmpb.gt", 0b1010>;
2128
2129 let AsmString = "$Pd = any8(vcmpb.eq($Rss, $Rtt))" in
2130 def A4_vcmpbeq_any : T_vcmp <"any8(vcmpb.gt", 0b1000>;
2131
2132 def A4_vcmpbeqi  : T_vcmpImm <"vcmpb.eq",  0b00, 0b00, u8_0Imm>;
2133 def A4_vcmpbgti  : T_vcmpImm <"vcmpb.gt",  0b01, 0b00, s8_0Imm>;
2134 def A4_vcmpbgtui : T_vcmpImm <"vcmpb.gtu", 0b10, 0b00, u7_0Imm>;
2135
2136 // Vector compare halfwords
2137 def A4_vcmpheqi  : T_vcmpImm <"vcmph.eq",  0b00, 0b01, s8_0Imm>;
2138 def A4_vcmphgti  : T_vcmpImm <"vcmph.gt",  0b01, 0b01, s8_0Imm>;
2139 def A4_vcmphgtui : T_vcmpImm <"vcmph.gtu", 0b10, 0b01, u7_0Imm>;
2140
2141 // Vector compare words
2142 def A4_vcmpweqi  : T_vcmpImm <"vcmpw.eq",  0b00, 0b10, s8_0Imm>;
2143 def A4_vcmpwgti  : T_vcmpImm <"vcmpw.gt",  0b01, 0b10, s8_0Imm>;
2144 def A4_vcmpwgtui : T_vcmpImm <"vcmpw.gtu", 0b10, 0b10, u7_0Imm>;
2145
2146 //===----------------------------------------------------------------------===//
2147 // XTYPE/SHIFT +
2148 //===----------------------------------------------------------------------===//
2149 // Shift by immediate and accumulate/logical.
2150 // Rx=add(#u8,asl(Rx,#U5))  Rx=add(#u8,lsr(Rx,#U5))
2151 // Rx=sub(#u8,asl(Rx,#U5))  Rx=sub(#u8,lsr(Rx,#U5))
2152 // Rx=and(#u8,asl(Rx,#U5))  Rx=and(#u8,lsr(Rx,#U5))
2153 // Rx=or(#u8,asl(Rx,#U5))   Rx=or(#u8,lsr(Rx,#U5))
2154 let isExtendable = 1, opExtendable = 1, isExtentSigned = 0, opExtentBits = 8,
2155     hasNewValue = 1, opNewValue = 0 in
2156 class T_S4_ShiftOperate<string MnOp, string MnSh, bit asl_lsr,
2157                         bits<2> MajOp, InstrItinClass Itin>
2158   : MInst_acc<(outs IntRegs:$Rd), (ins u8_0Ext:$u8, IntRegs:$Rx, u5_0Imm:$U5),
2159       "$Rd = "#MnOp#"(#$u8, "#MnSh#"($Rx, #$U5))",
2160       [], "$Rd = $Rx", Itin> {
2161
2162   bits<5> Rd;
2163   bits<8> u8;
2164   bits<5> Rx;
2165   bits<5> U5;
2166
2167   let IClass = 0b1101;
2168   let Inst{27-24} = 0b1110;
2169   let Inst{23-21} = u8{7-5};
2170   let Inst{20-16} = Rd;
2171   let Inst{13} = u8{4};
2172   let Inst{12-8} = U5;
2173   let Inst{7-5} = u8{3-1};
2174   let Inst{4} = asl_lsr;
2175   let Inst{3} = u8{0};
2176   let Inst{2-1} = MajOp;
2177 }
2178
2179 multiclass T_ShiftOperate<string mnemonic, bits<2> MajOp, InstrItinClass Itin> {
2180   def _asl_ri : T_S4_ShiftOperate<mnemonic, "asl", 0, MajOp, Itin>;
2181   def _lsr_ri : T_S4_ShiftOperate<mnemonic, "lsr", 1, MajOp, Itin>;
2182 }
2183
2184 defm S4_addi : T_ShiftOperate<"add", 0b10, ALU64_tc_2_SLOT23>;
2185 defm S4_andi : T_ShiftOperate<"and", 0b00, ALU64_tc_2_SLOT23>;
2186 defm S4_ori  : T_ShiftOperate<"or",  0b01, ALU64_tc_1_SLOT23>;
2187 defm S4_subi : T_ShiftOperate<"sub", 0b11, ALU64_tc_1_SLOT23>;
2188
2189 // Vector conditional negate
2190 // Rdd=vcnegh(Rss,Rt)
2191 let Defs = [USR_OVF], Itinerary = S_3op_tc_2_SLOT23 in
2192 def S2_vcnegh   : T_S3op_shiftVect < "vcnegh",   0b11, 0b01>;
2193
2194 // Rd=[cround|round](Rs,Rt)
2195 let hasNewValue = 1, Itinerary = S_3op_tc_2_SLOT23 in {
2196   def A4_cround_rr    : T_S3op_3 < "cround", IntRegs, 0b11, 0b00>;
2197   def A4_round_rr     : T_S3op_3 < "round", IntRegs, 0b11, 0b10>;
2198 }
2199
2200 // Rd=round(Rs,Rt):sat
2201 let hasNewValue = 1, Defs = [USR_OVF], Itinerary = S_3op_tc_2_SLOT23 in
2202 def A4_round_rr_sat : T_S3op_3 < "round", IntRegs, 0b11, 0b11, 1>;
2203
2204 // Rd=[cmpyiwh|cmpyrwh](Rss,Rt):<<1:rnd:sat
2205 let Defs = [USR_OVF], Itinerary = S_3op_tc_3x_SLOT23 in {
2206   def M4_cmpyi_wh     : T_S3op_8<"cmpyiwh", 0b100, 1, 1, 1>;
2207   def M4_cmpyr_wh     : T_S3op_8<"cmpyrwh", 0b110, 1, 1, 1>;
2208 }
2209
2210 // Rdd=[add|sub](Rss,Rtt,Px):carry
2211 let isPredicateLate = 1, hasSideEffects = 0 in
2212 class T_S3op_carry <string mnemonic, bits<3> MajOp>
2213   : SInst < (outs DoubleRegs:$Rdd, PredRegs:$Px),
2214             (ins DoubleRegs:$Rss, DoubleRegs:$Rtt, PredRegs:$Pu),
2215   "$Rdd = "#mnemonic#"($Rss, $Rtt, $Pu):carry",
2216   [], "$Px = $Pu", S_3op_tc_1_SLOT23 > {
2217     bits<5> Rdd;
2218     bits<5> Rss;
2219     bits<5> Rtt;
2220     bits<2> Pu;
2221
2222     let IClass = 0b1100;
2223
2224     let Inst{27-24} = 0b0010;
2225     let Inst{23-21} = MajOp;
2226     let Inst{20-16} = Rss;
2227     let Inst{12-8}  = Rtt;
2228     let Inst{6-5}   = Pu;
2229     let Inst{4-0}   = Rdd;
2230   }
2231
2232 def A4_addp_c : T_S3op_carry < "add", 0b110 >;
2233 def A4_subp_c : T_S3op_carry < "sub", 0b111 >;
2234
2235 let Itinerary = S_3op_tc_3_SLOT23, hasSideEffects = 0 in
2236 class T_S3op_6 <string mnemonic, bits<3> MinOp, bit isUnsigned>
2237   : SInst <(outs DoubleRegs:$Rxx),
2238            (ins DoubleRegs:$dst2, DoubleRegs:$Rss, IntRegs:$Ru),
2239   "$Rxx = "#mnemonic#"($Rss, $Ru)" ,
2240   [] , "$dst2 = $Rxx"> {
2241     bits<5> Rxx;
2242     bits<5> Rss;
2243     bits<5> Ru;
2244
2245     let IClass = 0b1100;
2246
2247     let Inst{27-21} = 0b1011001;
2248     let Inst{20-16} = Rss;
2249     let Inst{13}    = isUnsigned;
2250     let Inst{12-8}  = Rxx;
2251     let Inst{7-5}   = MinOp;
2252     let Inst{4-0}   = Ru;
2253   }
2254
2255 // Vector reduce maximum halfwords
2256 // Rxx=vrmax[u]h(Rss,Ru)
2257 def A4_vrmaxh  : T_S3op_6 < "vrmaxh",  0b001, 0>;
2258 def A4_vrmaxuh : T_S3op_6 < "vrmaxuh", 0b001, 1>;
2259
2260 // Vector reduce maximum words
2261 // Rxx=vrmax[u]w(Rss,Ru)
2262 def A4_vrmaxw  : T_S3op_6 < "vrmaxw",  0b010, 0>;
2263 def A4_vrmaxuw : T_S3op_6 < "vrmaxuw", 0b010, 1>;
2264
2265 // Vector reduce minimum halfwords
2266 // Rxx=vrmin[u]h(Rss,Ru)
2267 def A4_vrminh  : T_S3op_6 < "vrminh",  0b101, 0>;
2268 def A4_vrminuh : T_S3op_6 < "vrminuh", 0b101, 1>;
2269
2270 // Vector reduce minimum words
2271 // Rxx=vrmin[u]w(Rss,Ru)
2272 def A4_vrminw  : T_S3op_6 < "vrminw",  0b110, 0>;
2273 def A4_vrminuw : T_S3op_6 < "vrminuw", 0b110, 1>;
2274
2275 // Shift an immediate left by register amount.
2276 let hasNewValue = 1, hasSideEffects = 0 in
2277 def S4_lsli: SInst <(outs IntRegs:$Rd), (ins s6_0Imm:$s6, IntRegs:$Rt),
2278   "$Rd = lsl(#$s6, $Rt)" , [], "", S_3op_tc_1_SLOT23> {
2279     bits<5> Rd;
2280     bits<6> s6;
2281     bits<5> Rt;
2282
2283     let IClass = 0b1100;
2284
2285     let Inst{27-22} = 0b011010;
2286     let Inst{20-16} = s6{5-1};
2287     let Inst{12-8}  = Rt;
2288     let Inst{7-6}   = 0b11;
2289     let Inst{4-0}   = Rd;
2290     let Inst{5}     = s6{0};
2291   }
2292
2293 //===----------------------------------------------------------------------===//
2294 // XTYPE/SHIFT -
2295 //===----------------------------------------------------------------------===//
2296
2297 //===----------------------------------------------------------------------===//
2298 // MEMOP
2299 //===----------------------------------------------------------------------===//
2300
2301
2302 //===----------------------------------------------------------------------===//
2303 // Template class for MemOp instructions with the register value.
2304 //===----------------------------------------------------------------------===//
2305 class MemOp_rr_base <string opc, bits<2> opcBits, Operand ImmOp,
2306                      string memOp, bits<2> memOpBits> :
2307       MEMInst_V4<(outs),
2308                  (ins IntRegs:$base, ImmOp:$offset, IntRegs:$delta),
2309                  opc#"($base+#$offset)"#memOp#"$delta",
2310                  []>,
2311                  Requires<[UseMEMOP]> {
2312
2313     bits<5> base;
2314     bits<5> delta;
2315     bits<32> offset;
2316     bits<6> offsetBits; // memb - u6:0 , memh - u6:1, memw - u6:2
2317
2318     let offsetBits = !if (!eq(opcBits, 0b00), offset{5-0},
2319                      !if (!eq(opcBits, 0b01), offset{6-1},
2320                      !if (!eq(opcBits, 0b10), offset{7-2},0)));
2321
2322     let opExtentAlign = opcBits;
2323     let IClass = 0b0011;
2324     let Inst{27-24} = 0b1110;
2325     let Inst{22-21} = opcBits;
2326     let Inst{20-16} = base;
2327     let Inst{13} = 0b0;
2328     let Inst{12-7} = offsetBits;
2329     let Inst{6-5} = memOpBits;
2330     let Inst{4-0} = delta;
2331 }
2332
2333 //===----------------------------------------------------------------------===//
2334 // Template class for MemOp instructions with the immediate value.
2335 //===----------------------------------------------------------------------===//
2336 class MemOp_ri_base <string opc, bits<2> opcBits, Operand ImmOp,
2337                      string memOp, bits<2> memOpBits> :
2338       MEMInst_V4 <(outs),
2339                   (ins IntRegs:$base, ImmOp:$offset, u5_0Imm:$delta),
2340                   opc#"($base+#$offset)"#memOp#"#$delta"
2341                   #!if(memOpBits{1},")", ""), // clrbit, setbit - include ')'
2342                   []>,
2343                   Requires<[UseMEMOP]> {
2344
2345     bits<5> base;
2346     bits<5> delta;
2347     bits<32> offset;
2348     bits<6> offsetBits; // memb - u6:0 , memh - u6:1, memw - u6:2
2349
2350     let offsetBits = !if (!eq(opcBits, 0b00), offset{5-0},
2351                      !if (!eq(opcBits, 0b01), offset{6-1},
2352                      !if (!eq(opcBits, 0b10), offset{7-2},0)));
2353
2354     let opExtentAlign = opcBits;
2355     let IClass = 0b0011;
2356     let Inst{27-24} = 0b1111;
2357     let Inst{22-21} = opcBits;
2358     let Inst{20-16} = base;
2359     let Inst{13} = 0b0;
2360     let Inst{12-7} = offsetBits;
2361     let Inst{6-5} = memOpBits;
2362     let Inst{4-0} = delta;
2363 }
2364
2365 // multiclass to define MemOp instructions with register operand.
2366 multiclass MemOp_rr<string opc, bits<2> opcBits, Operand ImmOp> {
2367   def L4_add#NAME : MemOp_rr_base <opc, opcBits, ImmOp, " += ", 0b00>; // add
2368   def L4_sub#NAME : MemOp_rr_base <opc, opcBits, ImmOp, " -= ", 0b01>; // sub
2369   def L4_and#NAME : MemOp_rr_base <opc, opcBits, ImmOp, " &= ", 0b10>; // and
2370   def L4_or#NAME  : MemOp_rr_base <opc, opcBits, ImmOp, " |= ", 0b11>; // or
2371 }
2372
2373 // multiclass to define MemOp instructions with immediate Operand.
2374 multiclass MemOp_ri<string opc, bits<2> opcBits, Operand ImmOp> {
2375   def L4_iadd#NAME : MemOp_ri_base <opc, opcBits, ImmOp, " += ", 0b00 >;
2376   def L4_isub#NAME : MemOp_ri_base <opc, opcBits, ImmOp, " -= ", 0b01 >;
2377   def L4_iand#NAME : MemOp_ri_base<opc, opcBits, ImmOp, " = clrbit(", 0b10>;
2378   def L4_ior#NAME : MemOp_ri_base<opc, opcBits, ImmOp, " = setbit(", 0b11>;
2379 }
2380
2381 multiclass MemOp_base <string opc, bits<2> opcBits, Operand ImmOp> {
2382   defm _#NAME : MemOp_rr <opc, opcBits, ImmOp>;
2383   defm _#NAME : MemOp_ri <opc, opcBits, ImmOp>;
2384 }
2385
2386 // Define MemOp instructions.
2387 let isExtendable = 1, opExtendable = 1, isExtentSigned = 0 in {
2388   let opExtentBits = 6, accessSize = ByteAccess in
2389   defm memopb_io : MemOp_base <"memb", 0b00, u6_0Ext>;
2390
2391   let opExtentBits = 7, accessSize = HalfWordAccess in
2392   defm memoph_io : MemOp_base <"memh", 0b01, u6_1Ext>;
2393
2394   let opExtentBits = 8, accessSize = WordAccess in
2395   defm memopw_io : MemOp_base <"memw", 0b10, u6_2Ext>;
2396 }
2397
2398
2399 //===----------------------------------------------------------------------===//
2400 // XTYPE/PRED +
2401 //===----------------------------------------------------------------------===//
2402
2403 // Hexagon V4 only supports these flavors of byte/half compare instructions:
2404 // EQ/GT/GTU. Other flavors like GE/GEU/LT/LTU/LE/LEU are not supported by
2405 // hardware. However, compiler can still implement these patterns through
2406 // appropriate patterns combinations based on current implemented patterns.
2407 // The implemented patterns are: EQ/GT/GTU.
2408 // Missing patterns are: GE/GEU/LT/LTU/LE/LEU.
2409
2410 // Following instruction is not being extended as it results into the
2411 // incorrect code for negative numbers.
2412 // Pd=cmpb.eq(Rs,#u8)
2413
2414 // p=!cmp.eq(r1,#s10)
2415 def C4_cmpneqi  : T_CMP <"cmp.eq",  0b00, 1, s10_0Ext>;
2416 def C4_cmpltei  : T_CMP <"cmp.gt",  0b01, 1, s10_0Ext>;
2417 def C4_cmplteui : T_CMP <"cmp.gtu", 0b10, 1, u9_0Ext>;
2418
2419 //===----------------------------------------------------------------------===//
2420 // XTYPE/PRED -
2421 //===----------------------------------------------------------------------===//
2422
2423 //===----------------------------------------------------------------------===//
2424 // Multiclass for DeallocReturn
2425 //===----------------------------------------------------------------------===//
2426 class L4_RETURN<string mnemonic, bit isNot, bit isPredNew, bit isTak>
2427   : LD0Inst<(outs), (ins PredRegs:$src),
2428   !if(isNot, "if (!$src", "if ($src")#
2429   !if(isPredNew, ".new) ", ") ")#mnemonic#
2430   !if(isPredNew, #!if(isTak,":t", ":nt"),""),
2431   [], "", LD_tc_3or4stall_SLOT0> {
2432
2433     bits<2> src;
2434     let BaseOpcode = "L4_RETURN";
2435     let isPredicatedFalse = isNot;
2436     let isPredicatedNew = isPredNew;
2437     let isTaken = isTak;
2438     let IClass = 0b1001;
2439
2440     let Inst{27-16} = 0b011000011110;
2441
2442     let Inst{13} = isNot;
2443     let Inst{12} = isTak;
2444     let Inst{11} = isPredNew;
2445     let Inst{10} = 0b0;
2446     let Inst{9-8} = src;
2447     let Inst{4-0} = 0b11110;
2448   }
2449
2450 // Produce all predicated forms, p, !p, p.new, !p.new, :t, :nt
2451 multiclass L4_RETURN_PRED<string mnemonic, bit PredNot> {
2452   let isPredicated = 1 in {
2453     def _#NAME# : L4_RETURN <mnemonic, PredNot, 0, 1>;
2454     def _#NAME#new_pnt : L4_RETURN <mnemonic, PredNot, 1, 0>;
2455     def _#NAME#new_pt : L4_RETURN <mnemonic, PredNot, 1, 1>;
2456   }
2457 }
2458
2459 multiclass LD_MISC_L4_RETURN<string mnemonic> {
2460   let isBarrier = 1, isPredicable = 1 in
2461     def NAME : LD0Inst <(outs), (ins), mnemonic, [], "",
2462                         LD_tc_3or4stall_SLOT0> {
2463       let BaseOpcode = "L4_RETURN";
2464       let IClass = 0b1001;
2465       let Inst{27-16} = 0b011000011110;
2466       let Inst{13-10} = 0b0000;
2467       let Inst{4-0} = 0b11110;
2468     }
2469   defm t : L4_RETURN_PRED<mnemonic, 0 >;
2470   defm f : L4_RETURN_PRED<mnemonic, 1 >;
2471 }
2472
2473 let isReturn = 1, isTerminator = 1,
2474     Defs = [R29, R30, R31, PC], Uses = [R30], hasSideEffects = 0 in
2475 defm L4_return: LD_MISC_L4_RETURN <"dealloc_return">, PredNewRel;
2476
2477 // Restore registers and dealloc return function call.
2478 let isCall = 1, isBarrier = 1, isReturn = 1, isTerminator = 1,
2479     Defs = [R29, R30, R31, PC], isPredicable = 0, isAsmParserOnly = 1 in {
2480   def RESTORE_DEALLOC_RET_JMP_V4 : T_JMP<"">;
2481
2482   let isExtended = 1, opExtendable = 0 in
2483   def RESTORE_DEALLOC_RET_JMP_V4_EXT : T_JMP<"">;
2484
2485   let Defs = [R14, R15, R28, R29, R30, R31, PC] in {
2486     def RESTORE_DEALLOC_RET_JMP_V4_PIC : T_JMP<"">;
2487
2488     let isExtended = 1, opExtendable = 0 in
2489     def RESTORE_DEALLOC_RET_JMP_V4_EXT_PIC : T_JMP<"">;
2490   }
2491 }
2492
2493 // Restore registers and dealloc frame before a tail call.
2494 let isCall = 1, Defs = [R29, R30, R31, PC], isAsmParserOnly = 1 in {
2495   def RESTORE_DEALLOC_BEFORE_TAILCALL_V4 : T_Call<0, "">, PredRel;
2496
2497   let isExtended = 1, opExtendable = 0 in
2498   def RESTORE_DEALLOC_BEFORE_TAILCALL_V4_EXT : T_Call<0, "">, PredRel;
2499
2500   let Defs = [R14, R15, R28, R29, R30, R31, PC] in {
2501     def RESTORE_DEALLOC_BEFORE_TAILCALL_V4_PIC : T_Call<0, "">, PredRel;
2502
2503     let isExtended = 1, opExtendable = 0 in
2504     def RESTORE_DEALLOC_BEFORE_TAILCALL_V4_EXT_PIC : T_Call<0, "">, PredRel;
2505   }
2506 }
2507
2508 // Save registers function call.
2509 let isCall = 1, Uses = [R29, R31], isAsmParserOnly = 1 in {
2510   def SAVE_REGISTERS_CALL_V4 : T_Call<0, "">, PredRel;
2511
2512   let isExtended = 1, opExtendable = 0 in
2513   def SAVE_REGISTERS_CALL_V4_EXT : T_Call<0, "">, PredRel;
2514
2515   let Defs = [P0] in
2516   def SAVE_REGISTERS_CALL_V4STK : T_Call<0, "">, PredRel;
2517
2518   let Defs = [P0], isExtended = 1, opExtendable = 0 in
2519   def SAVE_REGISTERS_CALL_V4STK_EXT : T_Call<0, "">, PredRel;
2520
2521   let Defs = [R14, R15, R28] in
2522   def SAVE_REGISTERS_CALL_V4_PIC : T_Call<0, "">, PredRel;
2523
2524   let Defs = [R14, R15, R28], isExtended = 1, opExtendable = 0 in
2525   def SAVE_REGISTERS_CALL_V4_EXT_PIC : T_Call<0, "">, PredRel;
2526
2527   let Defs = [R14, R15, R28, P0] in
2528   def SAVE_REGISTERS_CALL_V4STK_PIC : T_Call<0, "">, PredRel;
2529
2530   let Defs = [R14, R15, R28, P0], isExtended = 1, opExtendable = 0 in
2531   def SAVE_REGISTERS_CALL_V4STK_EXT_PIC : T_Call<0, "">, PredRel;
2532 }
2533
2534 //===----------------------------------------------------------------------===//
2535 // Template class for non predicated store instructions with
2536 // GP-Relative or absolute addressing.
2537 //===----------------------------------------------------------------------===//
2538 let hasSideEffects = 0, isPredicable = 1 in
2539 class T_StoreAbsGP <string mnemonic, RegisterClass RC, Operand ImmOp,
2540                     bits<2>MajOp, bit isAbs, bit isHalf>
2541   : STInst<(outs), (ins ImmOp:$addr, RC:$src),
2542   mnemonic # "(#$addr) = $src"#!if(isHalf, ".h",""),
2543   [], "", V2LDST_tc_st_SLOT01> {
2544     bits<19> addr;
2545     bits<5> src;
2546     bits<16> offsetBits;
2547
2548     string ImmOpStr = !cast<string>(ImmOp);
2549     let offsetBits = !if (!eq(ImmOpStr, "u16_3Imm"), addr{18-3},
2550                      !if (!eq(ImmOpStr, "u16_2Imm"), addr{17-2},
2551                      !if (!eq(ImmOpStr, "u16_1Imm"), addr{16-1},
2552                                       /* u16_0Imm */ addr{15-0})));
2553     // Store upper-half and store doubleword cannot be NV.
2554     let isNVStorable = !if (!eq(mnemonic, "memd"), 0, !if(isHalf,0,1));
2555     let Uses = !if (isAbs, [], [GP]);
2556
2557     let IClass = 0b0100;
2558     let Inst{27} = 1;
2559     let Inst{26-25} = offsetBits{15-14};
2560     let Inst{24}    = 0b0;
2561     let Inst{23-22} = MajOp;
2562     let Inst{21}    = isHalf;
2563     let Inst{20-16} = offsetBits{13-9};
2564     let Inst{13}    = offsetBits{8};
2565     let Inst{12-8}  = src;
2566     let Inst{7-0}   = offsetBits{7-0};
2567   }
2568
2569 //===----------------------------------------------------------------------===//
2570 // Template class for predicated store instructions with
2571 // GP-Relative or absolute addressing.
2572 //===----------------------------------------------------------------------===//
2573 let hasSideEffects = 0, isPredicated = 1, opExtentBits = 6, opExtendable = 1 in
2574 class T_StoreAbs_Pred <string mnemonic, RegisterClass RC, bits<2> MajOp,
2575                        bit isHalf, bit isNot, bit isNew>
2576   : STInst<(outs), (ins PredRegs:$src1, u32_0MustExt:$absaddr, RC: $src2),
2577   !if(isNot, "if (!$src1", "if ($src1")#!if(isNew, ".new) ",
2578   ") ")#mnemonic#"(#$absaddr) = $src2"#!if(isHalf, ".h",""),
2579   [], "", ST_tc_st_SLOT01>, AddrModeRel {
2580     bits<2> src1;
2581     bits<6> absaddr;
2582     bits<5> src2;
2583
2584     let isPredicatedNew = isNew;
2585     let isPredicatedFalse = isNot;
2586     // Store upper-half and store doubleword cannot be NV.
2587     let isNVStorable = !if (!eq(mnemonic, "memd"), 0, !if(isHalf,0,1));
2588
2589     let IClass = 0b1010;
2590
2591     let Inst{27-24} = 0b1111;
2592     let Inst{23-22} = MajOp;
2593     let Inst{21}    = isHalf;
2594     let Inst{17-16} = absaddr{5-4};
2595     let Inst{13}    = isNew;
2596     let Inst{12-8}  = src2;
2597     let Inst{7}     = 0b1;
2598     let Inst{6-3}   = absaddr{3-0};
2599     let Inst{2}     = isNot;
2600     let Inst{1-0}   = src1;
2601   }
2602
2603 //===----------------------------------------------------------------------===//
2604 // Template class for predicated store instructions with absolute addressing.
2605 //===----------------------------------------------------------------------===//
2606 class T_StoreAbs <string mnemonic, RegisterClass RC, Operand ImmOp,
2607                  bits<2> MajOp, bit isHalf>
2608   : T_StoreAbsGP <mnemonic, RC, u32_0MustExt, MajOp, 1, isHalf>,
2609                   AddrModeRel {
2610   string ImmOpStr = !cast<string>(ImmOp);
2611   let opExtentBits = !if (!eq(ImmOpStr, "u16_3Imm"), 19,
2612                      !if (!eq(ImmOpStr, "u16_2Imm"), 18,
2613                      !if (!eq(ImmOpStr, "u16_1Imm"), 17,
2614                                       /* u16_0Imm */ 16)));
2615
2616   let opExtentAlign = !if (!eq(ImmOpStr, "u16_3Imm"), 3,
2617                       !if (!eq(ImmOpStr, "u16_2Imm"), 2,
2618                       !if (!eq(ImmOpStr, "u16_1Imm"), 1,
2619                                        /* u16_0Imm */ 0)));
2620 }
2621
2622 //===----------------------------------------------------------------------===//
2623 // Multiclass for store instructions with absolute addressing.
2624 //===----------------------------------------------------------------------===//
2625 let addrMode = Absolute, isExtended = 1 in
2626 multiclass ST_Abs<string mnemonic, string CextOp, RegisterClass RC,
2627                   Operand ImmOp, bits<2> MajOp, bit isHalf = 0> {
2628   let CextOpcode = CextOp, BaseOpcode = CextOp#_abs in {
2629     let opExtendable = 0, isPredicable = 1 in
2630     def PS_#NAME#abs : T_StoreAbs <mnemonic, RC, ImmOp, MajOp, isHalf>;
2631
2632     // Predicated
2633     def S4_p#NAME#t_abs : T_StoreAbs_Pred<mnemonic, RC, MajOp, isHalf, 0, 0>;
2634     def S4_p#NAME#f_abs : T_StoreAbs_Pred<mnemonic, RC, MajOp, isHalf, 1, 0>;
2635
2636     // .new Predicated
2637     def S4_p#NAME#tnew_abs : T_StoreAbs_Pred<mnemonic, RC, MajOp, isHalf, 0, 1>;
2638     def S4_p#NAME#fnew_abs : T_StoreAbs_Pred<mnemonic, RC, MajOp, isHalf, 1, 1>;
2639   }
2640 }
2641
2642 //===----------------------------------------------------------------------===//
2643 // Template class for non predicated new-value store instructions with
2644 // GP-Relative or absolute addressing.
2645 //===----------------------------------------------------------------------===//
2646 let hasSideEffects = 0, isPredicable = 1, mayStore = 1, isNVStore = 1,
2647     isNewValue = 1, opNewValue = 1 in
2648 class T_StoreAbsGP_NV <string mnemonic, Operand ImmOp, bits<2>MajOp>
2649   : NVInst_V4<(outs), (ins ImmOp:$addr, IntRegs:$src),
2650   mnemonic #"(#$addr) = $src.new",
2651   [], "", V2LDST_tc_st_SLOT0> {
2652     bits<19> addr;
2653     bits<3> src;
2654     bits<16> offsetBits;
2655
2656     string ImmOpStr = !cast<string>(ImmOp);
2657     let offsetBits = !if (!eq(ImmOpStr, "u16_3Imm"), addr{18-3},
2658                      !if (!eq(ImmOpStr, "u16_2Imm"), addr{17-2},
2659                      !if (!eq(ImmOpStr, "u16_1Imm"), addr{16-1},
2660                                       /* u16_0Imm */ addr{15-0})));
2661     let IClass = 0b0100;
2662
2663     let Inst{27} = 1;
2664     let Inst{26-25} = offsetBits{15-14};
2665     let Inst{24-21} = 0b0101;
2666     let Inst{20-16} = offsetBits{13-9};
2667     let Inst{13}    = offsetBits{8};
2668     let Inst{12-11} = MajOp;
2669     let Inst{10-8}  = src;
2670     let Inst{7-0}   = offsetBits{7-0};
2671   }
2672
2673 //===----------------------------------------------------------------------===//
2674 // Template class for predicated new-value store instructions with
2675 // absolute addressing.
2676 //===----------------------------------------------------------------------===//
2677 let hasSideEffects = 0, isPredicated = 1, mayStore = 1, isNVStore = 1,
2678     isNewValue = 1, opNewValue = 2, opExtentBits = 6, opExtendable = 1 in
2679 class T_StoreAbs_NV_Pred <string mnemonic, bits<2> MajOp, bit isNot, bit isNew>
2680   : NVInst_V4<(outs), (ins PredRegs:$src1, u32_0MustExt:$absaddr, IntRegs:$src2),
2681   !if(isNot, "if (!$src1", "if ($src1")#!if(isNew, ".new) ",
2682   ") ")#mnemonic#"(#$absaddr) = $src2.new",
2683   [], "", ST_tc_st_SLOT0>, AddrModeRel {
2684     bits<2> src1;
2685     bits<6> absaddr;
2686     bits<3> src2;
2687
2688     let isPredicatedNew = isNew;
2689     let isPredicatedFalse = isNot;
2690
2691     let IClass = 0b1010;
2692
2693     let Inst{27-24} = 0b1111;
2694     let Inst{23-21} = 0b101;
2695     let Inst{17-16} = absaddr{5-4};
2696     let Inst{13}    = isNew;
2697     let Inst{12-11} = MajOp;
2698     let Inst{10-8}  = src2;
2699     let Inst{7}     = 0b1;
2700     let Inst{6-3}   = absaddr{3-0};
2701     let Inst{2}     = isNot;
2702     let Inst{1-0}   = src1;
2703 }
2704
2705 //===----------------------------------------------------------------------===//
2706 // Template class for non-predicated new-value store instructions with
2707 // absolute addressing.
2708 //===----------------------------------------------------------------------===//
2709 class T_StoreAbs_NV <string mnemonic, Operand ImmOp, bits<2> MajOp>
2710   : T_StoreAbsGP_NV <mnemonic, u32_0MustExt, MajOp>, AddrModeRel {
2711
2712   string ImmOpStr = !cast<string>(ImmOp);
2713   let opExtentBits = !if (!eq(ImmOpStr, "u16_3Imm"), 19,
2714                      !if (!eq(ImmOpStr, "u16_2Imm"), 18,
2715                      !if (!eq(ImmOpStr, "u16_1Imm"), 17,
2716                                       /* u16_0Imm */ 16)));
2717
2718   let opExtentAlign = !if (!eq(ImmOpStr, "u16_3Imm"), 3,
2719                       !if (!eq(ImmOpStr, "u16_2Imm"), 2,
2720                       !if (!eq(ImmOpStr, "u16_1Imm"), 1,
2721                                        /* u16_0Imm */ 0)));
2722 }
2723
2724 //===----------------------------------------------------------------------===//
2725 // Multiclass for new-value store instructions with absolute addressing.
2726 //===----------------------------------------------------------------------===//
2727 let addrMode = Absolute, isExtended = 1  in
2728 multiclass ST_Abs_NV <string mnemonic, string CextOp, Operand ImmOp,
2729                    bits<2> MajOp> {
2730   let CextOpcode = CextOp, BaseOpcode = CextOp#_abs in {
2731     let opExtendable = 0, isPredicable = 1 in
2732     def PS_#NAME#newabs : T_StoreAbs_NV <mnemonic, ImmOp, MajOp>;
2733
2734     // Predicated
2735     def S4_p#NAME#newt_abs  : T_StoreAbs_NV_Pred <mnemonic, MajOp, 0, 0>;
2736     def S4_p#NAME#newf_abs  : T_StoreAbs_NV_Pred <mnemonic, MajOp, 1, 0>;
2737
2738     // .new Predicated
2739     def S4_p#NAME#newtnew_abs : T_StoreAbs_NV_Pred <mnemonic, MajOp, 0, 1>;
2740     def S4_p#NAME#newfnew_abs : T_StoreAbs_NV_Pred <mnemonic, MajOp, 1, 1>;
2741   }
2742 }
2743
2744 //===----------------------------------------------------------------------===//
2745 // Stores with absolute addressing
2746 //===----------------------------------------------------------------------===//
2747 let accessSize = ByteAccess in
2748 defm storerb : ST_Abs    <"memb", "STrib", IntRegs, u16_0Imm, 0b00>,
2749                ST_Abs_NV <"memb", "STrib", u16_0Imm, 0b00>;
2750
2751 let accessSize = HalfWordAccess in
2752 defm storerh : ST_Abs    <"memh", "STrih", IntRegs, u16_1Imm, 0b01>,
2753                ST_Abs_NV <"memh", "STrih", u16_1Imm, 0b01>;
2754
2755 let accessSize = WordAccess in
2756 defm storeri : ST_Abs    <"memw", "STriw", IntRegs, u16_2Imm, 0b10>,
2757                ST_Abs_NV <"memw", "STriw", u16_2Imm, 0b10>;
2758
2759 let isNVStorable = 0, accessSize = DoubleWordAccess in
2760 defm storerd : ST_Abs <"memd", "STrid", DoubleRegs, u16_3Imm, 0b11>;
2761
2762 let isNVStorable = 0, accessSize = HalfWordAccess in
2763 defm storerf : ST_Abs <"memh", "STrif", IntRegs, u16_1Imm, 0b01, 1>;
2764
2765 //===----------------------------------------------------------------------===//
2766 // GP-relative stores.
2767 // mem[bhwd](#global)=Rt
2768 // Once predicated, these instructions map to absolute addressing mode.
2769 // if ([!]Pv[.new]) mem[bhwd](##global)=Rt
2770 //===----------------------------------------------------------------------===//
2771
2772 let Uses = [GP], isAsmParserOnly = 1 in
2773 class T_StoreGP <string mnemonic, string BaseOp, RegisterClass RC,
2774                  Operand ImmOp, bits<2> MajOp, bit isHalf = 0>
2775   : T_StoreAbsGP <mnemonic, RC, ImmOp, MajOp, 0, isHalf> {
2776     // Set BaseOpcode same as absolute addressing instructions so that
2777     // non-predicated GP-Rel instructions can have relate with predicated
2778     // Absolute instruction.
2779     let BaseOpcode = BaseOp#_abs;
2780   }
2781
2782 let Uses = [GP], isAsmParserOnly = 1 in
2783 multiclass ST_GP <string mnemonic, string BaseOp, Operand ImmOp,
2784                   bits<2> MajOp, bit isHalf = 0> {
2785   // Set BaseOpcode same as absolute addressing instructions so that
2786   // non-predicated GP-Rel instructions can have relate with predicated
2787   // Absolute instruction.
2788   let BaseOpcode = BaseOp#_abs in {
2789     def NAME#gp : T_StoreAbsGP <mnemonic, IntRegs, ImmOp, MajOp,
2790                                 0, isHalf>;
2791     // New-value store
2792     def NAME#newgp : T_StoreAbsGP_NV <mnemonic, ImmOp, MajOp> ;
2793   }
2794 }
2795
2796 let accessSize = ByteAccess in
2797 defm S2_storerb : ST_GP<"memb", "STrib", u16_0Imm, 0b00>, NewValueRel;
2798
2799 let accessSize = HalfWordAccess in
2800 defm S2_storerh : ST_GP<"memh", "STrih", u16_1Imm, 0b01>, NewValueRel;
2801
2802 let accessSize = WordAccess in
2803 defm S2_storeri : ST_GP<"memw", "STriw", u16_2Imm, 0b10>, NewValueRel;
2804
2805 let isNVStorable = 0, accessSize = DoubleWordAccess in
2806 def S2_storerdgp : T_StoreGP <"memd", "STrid", DoubleRegs,
2807                               u16_3Imm, 0b11>, PredNewRel;
2808
2809 let isNVStorable = 0, accessSize = HalfWordAccess in
2810 def S2_storerfgp : T_StoreGP <"memh", "STrif", IntRegs,
2811                               u16_1Imm, 0b01, 1>, PredNewRel;
2812
2813 //===----------------------------------------------------------------------===//
2814 // Template class for non predicated load instructions with
2815 // absolute addressing mode.
2816 //===----------------------------------------------------------------------===//
2817 let isPredicable = 1, hasSideEffects = 0 in
2818 class T_LoadAbsGP <string mnemonic, RegisterClass RC, Operand ImmOp,
2819                    bits<3> MajOp>
2820   : LDInst <(outs RC:$dst), (ins ImmOp:$addr),
2821   "$dst = "#mnemonic# "(#$addr)",
2822   [], "", V2LDST_tc_ld_SLOT01> {
2823     bits<5> dst;
2824     bits<19> addr;
2825     bits<16> offsetBits;
2826
2827     string ImmOpStr = !cast<string>(ImmOp);
2828     let offsetBits = !if (!eq(ImmOpStr, "u16_3Imm"), addr{18-3},
2829                      !if (!eq(ImmOpStr, "u16_2Imm"), addr{17-2},
2830                      !if (!eq(ImmOpStr, "u16_1Imm"), addr{16-1},
2831                                       /* u16_0Imm */ addr{15-0})));
2832
2833     let IClass = 0b0100;
2834
2835     let Inst{27}    = 0b1;
2836     let Inst{26-25} = offsetBits{15-14};
2837     let Inst{24}    = 0b1;
2838     let Inst{23-21} = MajOp;
2839     let Inst{20-16} = offsetBits{13-9};
2840     let Inst{13-5}  = offsetBits{8-0};
2841     let Inst{4-0}   = dst;
2842   }
2843
2844 class T_LoadAbs <string mnemonic, RegisterClass RC, Operand ImmOp,
2845                  bits<3> MajOp>
2846   : T_LoadAbsGP <mnemonic, RC, u32_0MustExt, MajOp>, AddrModeRel {
2847
2848     string ImmOpStr = !cast<string>(ImmOp);
2849     let opExtentBits = !if (!eq(ImmOpStr, "u16_3Imm"), 19,
2850                        !if (!eq(ImmOpStr, "u16_2Imm"), 18,
2851                        !if (!eq(ImmOpStr, "u16_1Imm"), 17,
2852                                         /* u16_0Imm */ 16)));
2853
2854     let opExtentAlign = !if (!eq(ImmOpStr, "u16_3Imm"), 3,
2855                         !if (!eq(ImmOpStr, "u16_2Imm"), 2,
2856                         !if (!eq(ImmOpStr, "u16_1Imm"), 1,
2857                                         /* u16_0Imm */ 0)));
2858   }
2859
2860 //===----------------------------------------------------------------------===//
2861 // Template class for predicated load instructions with
2862 // absolute addressing mode.
2863 //===----------------------------------------------------------------------===//
2864 let isPredicated = 1, hasSideEffects = 0, hasNewValue = 1, opExtentBits = 6,
2865     opExtendable = 2 in
2866 class T_LoadAbs_Pred <string mnemonic, RegisterClass RC, bits<3> MajOp,
2867                       bit isPredNot, bit isPredNew>
2868   : LDInst <(outs RC:$dst), (ins PredRegs:$src1, u32_0MustExt:$absaddr),
2869   !if(isPredNot, "if (!$src1", "if ($src1")#!if(isPredNew, ".new) ",
2870   ") ")#"$dst = "#mnemonic#"(#$absaddr)">, AddrModeRel {
2871     bits<5> dst;
2872     bits<2> src1;
2873     bits<6> absaddr;
2874
2875     let isPredicatedNew = isPredNew;
2876     let isPredicatedFalse = isPredNot;
2877     let hasNewValue = !if (!eq(!cast<string>(RC), "DoubleRegs"), 0, 1);
2878
2879     let IClass = 0b1001;
2880
2881     let Inst{27-24} = 0b1111;
2882     let Inst{23-21} = MajOp;
2883     let Inst{20-16} = absaddr{5-1};
2884     let Inst{13} = 0b1;
2885     let Inst{12} = isPredNew;
2886     let Inst{11} = isPredNot;
2887     let Inst{10-9} = src1;
2888     let Inst{8} = absaddr{0};
2889     let Inst{7} = 0b1;
2890     let Inst{4-0} = dst;
2891   }
2892
2893 //===----------------------------------------------------------------------===//
2894 // Multiclass for the load instructions with absolute addressing mode.
2895 //===----------------------------------------------------------------------===//
2896 multiclass LD_Abs_Pred<string mnemonic, RegisterClass RC, bits<3> MajOp,
2897                        bit PredNot> {
2898   def _abs : T_LoadAbs_Pred <mnemonic, RC, MajOp, PredNot, 0>;
2899   // Predicate new
2900   def new_abs : T_LoadAbs_Pred <mnemonic, RC, MajOp, PredNot, 1>;
2901 }
2902
2903 let addrMode = Absolute, isExtended = 1 in
2904 multiclass LD_Abs<string mnemonic, string CextOp, RegisterClass RC,
2905                   Operand ImmOp, bits<3> MajOp> {
2906   let CextOpcode = CextOp, BaseOpcode = CextOp#_abs in {
2907     let opExtendable = 1, isPredicable = 1 in
2908     def PS_#NAME#abs: T_LoadAbs <mnemonic, RC, ImmOp, MajOp>;
2909
2910     // Predicated
2911     defm L4_p#NAME#t : LD_Abs_Pred<mnemonic, RC, MajOp, 0>;
2912     defm L4_p#NAME#f : LD_Abs_Pred<mnemonic, RC, MajOp, 1>;
2913   }
2914 }
2915
2916 let accessSize = ByteAccess, hasNewValue = 1 in {
2917   defm loadrb  : LD_Abs<"memb",  "LDrib",  IntRegs, u16_0Imm, 0b000>;
2918   defm loadrub : LD_Abs<"memub", "LDriub", IntRegs, u16_0Imm, 0b001>;
2919 }
2920
2921 let accessSize = HalfWordAccess, hasNewValue = 1 in {
2922   defm loadrh  : LD_Abs<"memh",  "LDrih",  IntRegs, u16_1Imm, 0b010>;
2923   defm loadruh : LD_Abs<"memuh", "LDriuh", IntRegs, u16_1Imm, 0b011>;
2924 }
2925
2926 let accessSize = WordAccess, hasNewValue = 1 in
2927 defm loadri  : LD_Abs<"memw",  "LDriw",  IntRegs, u16_2Imm, 0b100>;
2928
2929 let accessSize = DoubleWordAccess in
2930 defm loadrd  : LD_Abs<"memd",  "LDrid", DoubleRegs, u16_3Imm, 0b110>;
2931
2932 //===----------------------------------------------------------------------===//
2933 // multiclass for load instructions with GP-relative addressing mode.
2934 // Rx=mem[bhwd](##global)
2935 // Once predicated, these instructions map to absolute addressing mode.
2936 // if ([!]Pv[.new]) Rx=mem[bhwd](##global)
2937 //===----------------------------------------------------------------------===//
2938
2939 let isAsmParserOnly = 1, Uses = [GP] in
2940 class T_LoadGP <string mnemonic, string BaseOp, RegisterClass RC, Operand ImmOp,
2941                 bits<3> MajOp>
2942   : T_LoadAbsGP <mnemonic, RC, ImmOp, MajOp>, PredNewRel {
2943     let BaseOpcode = BaseOp#_abs;
2944   }
2945
2946 let accessSize = ByteAccess, hasNewValue = 1 in {
2947   def L2_loadrbgp  : T_LoadGP<"memb",  "LDrib",  IntRegs, u16_0Imm, 0b000>;
2948   def L2_loadrubgp : T_LoadGP<"memub", "LDriub", IntRegs, u16_0Imm, 0b001>;
2949 }
2950
2951 let accessSize = HalfWordAccess, hasNewValue = 1 in {
2952   def L2_loadrhgp  : T_LoadGP<"memh",  "LDrih",  IntRegs, u16_1Imm, 0b010>;
2953   def L2_loadruhgp : T_LoadGP<"memuh", "LDriuh", IntRegs, u16_1Imm, 0b011>;
2954 }
2955
2956 let accessSize = WordAccess, hasNewValue = 1 in
2957 def L2_loadrigp  : T_LoadGP<"memw",  "LDriw",  IntRegs, u16_2Imm, 0b100>;
2958
2959 let accessSize = DoubleWordAccess in
2960 def L2_loadrdgp  : T_LoadGP<"memd", "LDrid", DoubleRegs, u16_3Imm, 0b110>;
2961
2962 //===----------------------------------------------------------------------===//
2963 // :raw for of boundscheck:hi:lo insns
2964 //===----------------------------------------------------------------------===//
2965
2966 // A4_boundscheck_lo: Detect if a register is within bounds.
2967 let hasSideEffects = 0 in
2968 def A4_boundscheck_lo: ALU64Inst <
2969   (outs PredRegs:$Pd),
2970   (ins DoubleRegs:$Rss, DoubleRegs:$Rtt),
2971   "$Pd = boundscheck($Rss, $Rtt):raw:lo"> {
2972     bits<2> Pd;
2973     bits<5> Rss;
2974     bits<5> Rtt;
2975
2976     let IClass = 0b1101;
2977
2978     let Inst{27-23} = 0b00100;
2979     let Inst{13} = 0b1;
2980     let Inst{7-5} = 0b100;
2981     let Inst{1-0} = Pd;
2982     let Inst{20-16} = Rss;
2983     let Inst{12-8} = Rtt;
2984   }
2985
2986 // A4_boundscheck_hi: Detect if a register is within bounds.
2987 let hasSideEffects = 0 in
2988 def A4_boundscheck_hi: ALU64Inst <
2989   (outs PredRegs:$Pd),
2990   (ins DoubleRegs:$Rss, DoubleRegs:$Rtt),
2991   "$Pd = boundscheck($Rss, $Rtt):raw:hi"> {
2992     bits<2> Pd;
2993     bits<5> Rss;
2994     bits<5> Rtt;
2995
2996     let IClass = 0b1101;
2997
2998     let Inst{27-23} = 0b00100;
2999     let Inst{13} = 0b1;
3000     let Inst{7-5} = 0b101;
3001     let Inst{1-0} = Pd;
3002     let Inst{20-16} = Rss;
3003     let Inst{12-8} = Rtt;
3004   }
3005
3006 let hasSideEffects = 0, isAsmParserOnly = 1 in
3007 def A4_boundscheck : MInst <
3008   (outs PredRegs:$Pd), (ins IntRegs:$Rs, DoubleRegs:$Rtt),
3009   "$Pd=boundscheck($Rs,$Rtt)">;
3010
3011 // A4_tlbmatch: Detect if a VA/ASID matches a TLB entry.
3012 let isPredicateLate = 1, hasSideEffects = 0 in
3013 def A4_tlbmatch : ALU64Inst<(outs PredRegs:$Pd),
3014   (ins DoubleRegs:$Rs, IntRegs:$Rt),
3015   "$Pd = tlbmatch($Rs, $Rt)",
3016   [], "", ALU64_tc_2early_SLOT23> {
3017     bits<2> Pd;
3018     bits<5> Rs;
3019     bits<5> Rt;
3020
3021     let IClass = 0b1101;
3022     let Inst{27-23} = 0b00100;
3023     let Inst{20-16} = Rs;
3024     let Inst{13} = 0b1;
3025     let Inst{12-8} = Rt;
3026     let Inst{7-5} = 0b011;
3027     let Inst{1-0} = Pd;
3028   }
3029
3030 // Use LD0Inst for dcfetch, but set "mayLoad" to 0 because this doesn't
3031 // really do a load.
3032 let hasSideEffects = 1, mayLoad = 0 in
3033 def Y2_dcfetchbo : LD0Inst<(outs), (ins IntRegs:$Rs, u11_3Imm:$u11_3),
3034       "dcfetch($Rs + #$u11_3)",
3035       [], "", LD_tc_ld_SLOT0> {
3036   bits<5> Rs;
3037   bits<14> u11_3;
3038
3039   let IClass = 0b1001;
3040   let Inst{27-21} = 0b0100000;
3041   let Inst{20-16} = Rs;
3042   let Inst{13} = 0b0;
3043   let Inst{10-0} = u11_3{13-3};
3044 }
3045
3046
3047 //===----------------------------------------------------------------------===//
3048 // Compound instructions
3049 //===----------------------------------------------------------------------===//
3050
3051 let isBranch = 1, hasSideEffects = 0, isExtentSigned = 1,
3052     isPredicated = 1, isPredicatedNew = 1, isExtendable = 1,
3053     opExtentBits = 11, opExtentAlign = 2, opExtendable = 1,
3054     isTerminator = 1 in
3055 class CJInst_tstbit_R0<string px, bit np, string tnt>
3056   : InstHexagon<(outs), (ins IntRegs:$Rs, brtarget:$r9_2),
3057   ""#px#" = tstbit($Rs, #0); if ("
3058     #!if(np, "!","")#""#px#".new) jump:"#tnt#" $r9_2",
3059   [], "", COMPOUND_CJ_ARCHDEPSLOT, TypeCOMPOUND>, OpcodeHexagon {
3060   bits<4> Rs;
3061   bits<11> r9_2;
3062
3063   // np: !p[01]
3064   let isPredicatedFalse = np;
3065   // tnt: Taken/Not Taken
3066   let isBrTaken = !if (!eq(tnt, "t"), "true", "false");
3067   let isTaken   = !if (!eq(tnt, "t"), 1, 0);
3068
3069   let IClass = 0b0001;
3070   let Inst{27-26} = 0b00;
3071   let Inst{25} = !if (!eq(px, "!p1"), 1,
3072                  !if (!eq(px,  "p1"), 1, 0));
3073   let Inst{24-23} = 0b11;
3074   let Inst{22} = np;
3075   let Inst{21-20} = r9_2{10-9};
3076   let Inst{19-16} = Rs;
3077   let Inst{13} = !if (!eq(tnt, "t"), 1, 0);
3078   let Inst{9-8} = 0b11;
3079   let Inst{7-1} = r9_2{8-2};
3080 }
3081
3082 let Defs = [PC, P0], Uses = [P0] in {
3083   def J4_tstbit0_tp0_jump_nt : CJInst_tstbit_R0<"p0", 0, "nt">;
3084   def J4_tstbit0_tp0_jump_t : CJInst_tstbit_R0<"p0", 0, "t">;
3085   def J4_tstbit0_fp0_jump_nt : CJInst_tstbit_R0<"p0", 1, "nt">;
3086   def J4_tstbit0_fp0_jump_t : CJInst_tstbit_R0<"p0", 1, "t">;
3087 }
3088
3089 let Defs = [PC, P1], Uses = [P1] in {
3090   def J4_tstbit0_tp1_jump_nt : CJInst_tstbit_R0<"p1", 0, "nt">;
3091   def J4_tstbit0_tp1_jump_t : CJInst_tstbit_R0<"p1", 0, "t">;
3092   def J4_tstbit0_fp1_jump_nt : CJInst_tstbit_R0<"p1", 1, "nt">;
3093   def J4_tstbit0_fp1_jump_t : CJInst_tstbit_R0<"p1", 1, "t">;
3094 }
3095
3096
3097 let isBranch = 1, hasSideEffects = 0,
3098     isExtentSigned = 1, isPredicated = 1, isPredicatedNew = 1,
3099     isExtendable = 1, opExtentBits = 11, opExtentAlign = 2,
3100     opExtendable = 2, isTerminator = 1 in
3101 class CJInst_RR<string px, string op, bit np, string tnt>
3102   : InstHexagon<(outs), (ins IntRegs:$Rs, IntRegs:$Rt, brtarget:$r9_2),
3103   ""#px#" = cmp."#op#"($Rs, $Rt); if ("
3104    #!if(np, "!","")#""#px#".new) jump:"#tnt#" $r9_2",
3105   [], "", COMPOUND_CJ_ARCHDEPSLOT, TypeCOMPOUND>, OpcodeHexagon {
3106   bits<4> Rs;
3107   bits<4> Rt;
3108   bits<11> r9_2;
3109
3110   // np: !p[01]
3111   let isPredicatedFalse = np;
3112   // tnt: Taken/Not Taken
3113   let isBrTaken = !if (!eq(tnt, "t"), "true", "false");
3114   let isTaken   = !if (!eq(tnt, "t"), 1, 0);
3115
3116   let IClass = 0b0001;
3117   let Inst{27-23} = !if (!eq(op, "eq"),  0b01000,
3118                     !if (!eq(op, "gt"),  0b01001,
3119                     !if (!eq(op, "gtu"), 0b01010, 0)));
3120   let Inst{22} = np;
3121   let Inst{21-20} = r9_2{10-9};
3122   let Inst{19-16} = Rs;
3123   let Inst{13} = !if (!eq(tnt, "t"), 1, 0);
3124   // px: Predicate reg 0/1
3125   let Inst{12} = !if (!eq(px, "!p1"), 1,
3126                  !if (!eq(px,  "p1"), 1, 0));
3127   let Inst{11-8} = Rt;
3128   let Inst{7-1} = r9_2{8-2};
3129 }
3130
3131 // P[10] taken/not taken.
3132 multiclass T_tnt_CJInst_RR<string op, bit np> {
3133   let Defs = [PC, P0], Uses = [P0] in {
3134     def NAME#p0_jump_nt : CJInst_RR<"p0", op, np, "nt">;
3135     def NAME#p0_jump_t : CJInst_RR<"p0", op, np, "t">;
3136   }
3137   let Defs = [PC, P1], Uses = [P1] in {
3138     def NAME#p1_jump_nt : CJInst_RR<"p1", op, np, "nt">;
3139     def NAME#p1_jump_t : CJInst_RR<"p1", op, np, "t">;
3140   }
3141 }
3142 // Predicate / !Predicate
3143 multiclass T_pnp_CJInst_RR<string op>{
3144   defm J4_cmp#NAME#_t : T_tnt_CJInst_RR<op, 0>;
3145   defm J4_cmp#NAME#_f : T_tnt_CJInst_RR<op, 1>;
3146 }
3147 // TypeCJ Instructions compare RR and jump
3148 defm eq : T_pnp_CJInst_RR<"eq">;
3149 defm gt : T_pnp_CJInst_RR<"gt">;
3150 defm gtu : T_pnp_CJInst_RR<"gtu">;
3151
3152 let isBranch = 1, hasSideEffects = 0, isExtentSigned = 1,
3153     isPredicated = 1, isPredicatedNew = 1, isExtendable = 1, opExtentBits = 11,
3154     opExtentAlign = 2, opExtendable = 2, isTerminator = 1 in
3155 class CJInst_RU5<string px, string op, bit np, string tnt>
3156   : InstHexagon<(outs), (ins IntRegs:$Rs, u5_0Imm:$U5, brtarget:$r9_2),
3157   ""#px#" = cmp."#op#"($Rs, #$U5); if ("
3158     #!if(np, "!","")#""#px#".new) jump:"#tnt#" $r9_2",
3159   [], "", COMPOUND_CJ_ARCHDEPSLOT, TypeCOMPOUND>, OpcodeHexagon {
3160   bits<4> Rs;
3161   bits<5> U5;
3162   bits<11> r9_2;
3163
3164   // np: !p[01]
3165   let isPredicatedFalse = np;
3166   // tnt: Taken/Not Taken
3167   let isBrTaken = !if (!eq(tnt, "t"), "true", "false");
3168   let isTaken   = !if (!eq(tnt, "t"), 1, 0);
3169
3170   let IClass = 0b0001;
3171   let Inst{27-26} = 0b00;
3172   // px: Predicate reg 0/1
3173   let Inst{25} = !if (!eq(px, "!p1"), 1,
3174                  !if (!eq(px,  "p1"), 1, 0));
3175   let Inst{24-23} = !if (!eq(op, "eq"),  0b00,
3176                     !if (!eq(op, "gt"),  0b01,
3177                     !if (!eq(op, "gtu"), 0b10, 0)));
3178   let Inst{22} = np;
3179   let Inst{21-20} = r9_2{10-9};
3180   let Inst{19-16} = Rs;
3181   let Inst{13} = !if (!eq(tnt, "t"), 1, 0);
3182   let Inst{12-8} = U5;
3183   let Inst{7-1} = r9_2{8-2};
3184 }
3185 // P[10] taken/not taken.
3186 multiclass T_tnt_CJInst_RU5<string op, bit np> {
3187   let Defs = [PC, P0], Uses = [P0] in {
3188     def NAME#p0_jump_nt : CJInst_RU5<"p0", op, np, "nt">;
3189     def NAME#p0_jump_t : CJInst_RU5<"p0", op, np, "t">;
3190   }
3191   let Defs = [PC, P1], Uses = [P1] in {
3192     def NAME#p1_jump_nt : CJInst_RU5<"p1", op, np, "nt">;
3193     def NAME#p1_jump_t : CJInst_RU5<"p1", op, np, "t">;
3194   }
3195 }
3196 // Predicate / !Predicate
3197 multiclass T_pnp_CJInst_RU5<string op>{
3198   defm J4_cmp#NAME#i_t : T_tnt_CJInst_RU5<op, 0>;
3199   defm J4_cmp#NAME#i_f : T_tnt_CJInst_RU5<op, 1>;
3200 }
3201 // TypeCJ Instructions compare RI and jump
3202 defm eq : T_pnp_CJInst_RU5<"eq">;
3203 defm gt : T_pnp_CJInst_RU5<"gt">;
3204 defm gtu : T_pnp_CJInst_RU5<"gtu">;
3205
3206 let isBranch = 1, hasSideEffects = 0, isExtentSigned = 1,
3207     isPredicated = 1, isPredicatedFalse = 1, isPredicatedNew = 1,
3208     isExtendable = 1, opExtentBits = 11, opExtentAlign = 2, opExtendable = 2,
3209     isTerminator = 1 in
3210 class CJInst_Rn1<string px, string op, bit np, string tnt>
3211   : InstHexagon<(outs), (ins IntRegs:$Rs, n1Const:$n1, brtarget:$r9_2),
3212   ""#px#" = cmp."#op#"($Rs,#$n1); if ("
3213   #!if(np, "!","")#""#px#".new) jump:"#tnt#" $r9_2",
3214   [], "", COMPOUND_CJ_ARCHDEPSLOT, TypeCOMPOUND>, OpcodeHexagon {
3215   bits<4> Rs;
3216   bits<11> r9_2;
3217
3218   // np: !p[01]
3219   let isPredicatedFalse = np;
3220   // tnt: Taken/Not Taken
3221   let isBrTaken = !if (!eq(tnt, "t"), "true", "false");
3222   let isTaken   = !if (!eq(tnt, "t"), 1, 0);
3223
3224   let IClass = 0b0001;
3225   let Inst{27-26} = 0b00;
3226   let Inst{25} = !if (!eq(px, "!p1"), 1,
3227                  !if (!eq(px,  "p1"), 1, 0));
3228
3229   let Inst{24-23} = 0b11;
3230   let Inst{22} = np;
3231   let Inst{21-20} = r9_2{10-9};
3232   let Inst{19-16} = Rs;
3233   let Inst{13} = !if (!eq(tnt, "t"), 1, 0);
3234   let Inst{9-8} = !if (!eq(op, "eq"),  0b00,
3235                   !if (!eq(op, "gt"),  0b01, 0));
3236   let Inst{7-1} = r9_2{8-2};
3237 }
3238
3239 // P[10] taken/not taken.
3240 multiclass T_tnt_CJInst_Rn1<string op, bit np> {
3241   let Defs = [PC, P0], Uses = [P0] in {
3242     def NAME#p0_jump_nt : CJInst_Rn1<"p0", op, np, "nt">;
3243     def NAME#p0_jump_t : CJInst_Rn1<"p0", op, np, "t">;
3244   }
3245   let Defs = [PC, P1], Uses = [P1] in {
3246     def NAME#p1_jump_nt : CJInst_Rn1<"p1", op, np, "nt">;
3247     def NAME#p1_jump_t : CJInst_Rn1<"p1", op, np, "t">;
3248   }
3249 }
3250 // Predicate / !Predicate
3251 multiclass T_pnp_CJInst_Rn1<string op>{
3252   defm J4_cmp#NAME#n1_t : T_tnt_CJInst_Rn1<op, 0>;
3253   defm J4_cmp#NAME#n1_f : T_tnt_CJInst_Rn1<op, 1>;
3254 }
3255 // TypeCJ Instructions compare -1 and jump
3256 defm eq : T_pnp_CJInst_Rn1<"eq">;
3257 defm gt : T_pnp_CJInst_Rn1<"gt">;
3258
3259 // J4_jumpseti: Direct unconditional jump and set register to immediate.
3260 let Defs = [PC], isBranch = 1, hasSideEffects = 0, hasNewValue = 1,
3261     isExtentSigned = 1, opNewValue = 0, isExtendable = 1, opExtentBits = 11,
3262     opExtentAlign = 2, opExtendable = 2 in
3263 def J4_jumpseti: CJInst_JMPSET <
3264   (outs IntRegs:$Rd),
3265   (ins u6_0Imm:$U6, brtarget:$r9_2),
3266   "$Rd = #$U6 ; jump $r9_2"> {
3267     bits<4> Rd;
3268     bits<6> U6;
3269     bits<11> r9_2;
3270
3271     let IClass = 0b0001;
3272     let Inst{27-24} = 0b0110;
3273     let Inst{21-20} = r9_2{10-9};
3274     let Inst{19-16} = Rd;
3275     let Inst{13-8} = U6;
3276     let Inst{7-1} = r9_2{8-2};
3277   }
3278
3279 // J4_jumpsetr: Direct unconditional jump and transfer register.
3280 let Defs = [PC], isBranch = 1, hasSideEffects = 0, hasNewValue = 1,
3281     isExtentSigned = 1, opNewValue = 0, isExtendable = 1, opExtentBits = 11,
3282     opExtentAlign = 2, opExtendable = 2 in
3283 def J4_jumpsetr: CJInst_JMPSET <
3284   (outs IntRegs:$Rd),
3285   (ins IntRegs:$Rs, brtarget:$r9_2),
3286   "$Rd = $Rs ; jump $r9_2"> {
3287     bits<4> Rd;
3288     bits<4> Rs;
3289     bits<11> r9_2;
3290
3291     let IClass = 0b0001;
3292     let Inst{27-24} = 0b0111;
3293     let Inst{21-20} = r9_2{10-9};
3294     let Inst{11-8} = Rd;
3295     let Inst{19-16} = Rs;
3296     let Inst{7-1} = r9_2{8-2};
3297   }
3298
3299 // Duplex instructions
3300 //===----------------------------------------------------------------------===//
3301 include "HexagonIsetDx.td"