[Sparc] Add VIS instructions to sparc backend.
[oota-llvm.git] / lib / Target / Sparc / SparcInstrInfo.td
1 //===-- SparcInstrInfo.td - Target Description for Sparc Target -----------===//
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 Sparc instructions in TableGen format.
11 //
12 //===----------------------------------------------------------------------===//
13
14 //===----------------------------------------------------------------------===//
15 // Instruction format superclass
16 //===----------------------------------------------------------------------===//
17
18 include "SparcInstrFormats.td"
19
20 //===----------------------------------------------------------------------===//
21 // Feature predicates.
22 //===----------------------------------------------------------------------===//
23
24 // True when generating 32-bit code.
25 def Is32Bit : Predicate<"!Subtarget.is64Bit()">;
26
27 // True when generating 64-bit code. This also implies HasV9.
28 def Is64Bit : Predicate<"Subtarget.is64Bit()">;
29
30 // HasV9 - This predicate is true when the target processor supports V9
31 // instructions.  Note that the machine may be running in 32-bit mode.
32 def HasV9   : Predicate<"Subtarget.isV9()">,
33               AssemblerPredicate<"FeatureV9">;
34
35 // HasNoV9 - This predicate is true when the target doesn't have V9
36 // instructions.  Use of this is just a hack for the isel not having proper
37 // costs for V8 instructions that are more expensive than their V9 ones.
38 def HasNoV9 : Predicate<"!Subtarget.isV9()">;
39
40 // HasVIS - This is true when the target processor has VIS extensions.
41 def HasVIS : Predicate<"Subtarget.isVIS()">,
42              AssemblerPredicate<"FeatureVIS">;
43 def HasVIS2 : Predicate<"Subtarget.isVIS2()">,
44              AssemblerPredicate<"FeatureVIS2">;
45 def HasVIS3 : Predicate<"Subtarget.isVIS3()">,
46              AssemblerPredicate<"FeatureVIS3">;
47
48 // HasHardQuad - This is true when the target processor supports quad floating
49 // point instructions.
50 def HasHardQuad : Predicate<"Subtarget.hasHardQuad()">;
51
52 // UseDeprecatedInsts - This predicate is true when the target processor is a
53 // V8, or when it is V9 but the V8 deprecated instructions are efficient enough
54 // to use when appropriate.  In either of these cases, the instruction selector
55 // will pick deprecated instructions.
56 def UseDeprecatedInsts : Predicate<"Subtarget.useDeprecatedV8Instructions()">;
57
58 //===----------------------------------------------------------------------===//
59 // Instruction Pattern Stuff
60 //===----------------------------------------------------------------------===//
61
62 def simm11  : PatLeaf<(imm), [{ return isInt<11>(N->getSExtValue()); }]>;
63
64 def simm13  : PatLeaf<(imm), [{ return isInt<13>(N->getSExtValue()); }]>;
65
66 def LO10 : SDNodeXForm<imm, [{
67   return CurDAG->getTargetConstant((unsigned)N->getZExtValue() & 1023,
68                                    MVT::i32);
69 }]>;
70
71 def HI22 : SDNodeXForm<imm, [{
72   // Transformation function: shift the immediate value down into the low bits.
73   return CurDAG->getTargetConstant((unsigned)N->getZExtValue() >> 10, MVT::i32);
74 }]>;
75
76 def SETHIimm : PatLeaf<(imm), [{
77   return isShiftedUInt<22, 10>(N->getZExtValue());
78 }], HI22>;
79
80 // Addressing modes.
81 def ADDRrr : ComplexPattern<iPTR, 2, "SelectADDRrr", [], []>;
82 def ADDRri : ComplexPattern<iPTR, 2, "SelectADDRri", [frameindex], []>;
83
84 // Address operands
85 def SparcMEMrrAsmOperand : AsmOperandClass {
86   let Name = "MEMrr";
87   let ParserMethod = "parseMEMOperand";
88 }
89
90 def SparcMEMriAsmOperand : AsmOperandClass {
91   let Name = "MEMri";
92   let ParserMethod = "parseMEMOperand";
93 }
94
95 def MEMrr : Operand<iPTR> {
96   let PrintMethod = "printMemOperand";
97   let MIOperandInfo = (ops ptr_rc, ptr_rc);
98   let ParserMatchClass = SparcMEMrrAsmOperand;
99 }
100 def MEMri : Operand<iPTR> {
101   let PrintMethod = "printMemOperand";
102   let MIOperandInfo = (ops ptr_rc, i32imm);
103   let ParserMatchClass = SparcMEMriAsmOperand;
104 }
105
106 def TLSSym : Operand<iPTR>;
107
108 // Branch targets have OtherVT type.
109 def brtarget : Operand<OtherVT> {
110   let EncoderMethod = "getBranchTargetOpValue";
111 }
112
113 def bprtarget : Operand<OtherVT> {
114   let EncoderMethod = "getBranchPredTargetOpValue";
115 }
116
117 def bprtarget16 : Operand<OtherVT> {
118   let EncoderMethod = "getBranchOnRegTargetOpValue";
119 }
120
121 def calltarget : Operand<i32> {
122   let EncoderMethod = "getCallTargetOpValue";
123   let DecoderMethod = "DecodeCall";
124 }
125
126 def simm13Op : Operand<i32> {
127   let DecoderMethod = "DecodeSIMM13";
128 }
129
130 // Operand for printing out a condition code.
131 let PrintMethod = "printCCOperand" in
132   def CCOp : Operand<i32>;
133
134 def SDTSPcmpicc :
135 SDTypeProfile<0, 2, [SDTCisInt<0>, SDTCisSameAs<0, 1>]>;
136 def SDTSPcmpfcc :
137 SDTypeProfile<0, 2, [SDTCisFP<0>, SDTCisSameAs<0, 1>]>;
138 def SDTSPbrcc :
139 SDTypeProfile<0, 2, [SDTCisVT<0, OtherVT>, SDTCisVT<1, i32>]>;
140 def SDTSPselectcc :
141 SDTypeProfile<1, 3, [SDTCisSameAs<0, 1>, SDTCisSameAs<1, 2>, SDTCisVT<3, i32>]>;
142 def SDTSPFTOI :
143 SDTypeProfile<1, 1, [SDTCisVT<0, f32>, SDTCisFP<1>]>;
144 def SDTSPITOF :
145 SDTypeProfile<1, 1, [SDTCisFP<0>, SDTCisVT<1, f32>]>;
146 def SDTSPFTOX :
147 SDTypeProfile<1, 1, [SDTCisVT<0, f64>, SDTCisFP<1>]>;
148 def SDTSPXTOF :
149 SDTypeProfile<1, 1, [SDTCisFP<0>, SDTCisVT<1, f64>]>;
150
151 def SDTSPtlsadd :
152 SDTypeProfile<1, 3, [SDTCisInt<0>, SDTCisSameAs<0, 1>, SDTCisPtrTy<2>]>;
153 def SDTSPtlsld :
154 SDTypeProfile<1, 2, [SDTCisPtrTy<0>, SDTCisPtrTy<1>]>;
155
156 def SPcmpicc : SDNode<"SPISD::CMPICC", SDTSPcmpicc, [SDNPOutGlue]>;
157 def SPcmpfcc : SDNode<"SPISD::CMPFCC", SDTSPcmpfcc, [SDNPOutGlue]>;
158 def SPbricc : SDNode<"SPISD::BRICC", SDTSPbrcc, [SDNPHasChain, SDNPInGlue]>;
159 def SPbrxcc : SDNode<"SPISD::BRXCC", SDTSPbrcc, [SDNPHasChain, SDNPInGlue]>;
160 def SPbrfcc : SDNode<"SPISD::BRFCC", SDTSPbrcc, [SDNPHasChain, SDNPInGlue]>;
161
162 def SPhi    : SDNode<"SPISD::Hi", SDTIntUnaryOp>;
163 def SPlo    : SDNode<"SPISD::Lo", SDTIntUnaryOp>;
164
165 def SPftoi  : SDNode<"SPISD::FTOI", SDTSPFTOI>;
166 def SPitof  : SDNode<"SPISD::ITOF", SDTSPITOF>;
167 def SPftox  : SDNode<"SPISD::FTOX", SDTSPFTOX>;
168 def SPxtof  : SDNode<"SPISD::XTOF", SDTSPXTOF>;
169
170 def SPselecticc : SDNode<"SPISD::SELECT_ICC", SDTSPselectcc, [SDNPInGlue]>;
171 def SPselectxcc : SDNode<"SPISD::SELECT_XCC", SDTSPselectcc, [SDNPInGlue]>;
172 def SPselectfcc : SDNode<"SPISD::SELECT_FCC", SDTSPselectcc, [SDNPInGlue]>;
173
174 //  These are target-independent nodes, but have target-specific formats.
175 def SDT_SPCallSeqStart : SDCallSeqStart<[ SDTCisVT<0, i32> ]>;
176 def SDT_SPCallSeqEnd   : SDCallSeqEnd<[ SDTCisVT<0, i32>,
177                                         SDTCisVT<1, i32> ]>;
178
179 def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_SPCallSeqStart,
180                            [SDNPHasChain, SDNPOutGlue]>;
181 def callseq_end   : SDNode<"ISD::CALLSEQ_END",   SDT_SPCallSeqEnd,
182                            [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
183
184 def SDT_SPCall    : SDTypeProfile<0, -1, [SDTCisVT<0, i32>]>;
185 def call          : SDNode<"SPISD::CALL", SDT_SPCall,
186                            [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue,
187                             SDNPVariadic]>;
188
189 def SDT_SPRet     : SDTypeProfile<0, 1, [SDTCisVT<0, i32>]>;
190 def retflag       : SDNode<"SPISD::RET_FLAG", SDT_SPRet,
191                            [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>;
192
193 def flushw        : SDNode<"SPISD::FLUSHW", SDTNone,
194                            [SDNPHasChain, SDNPSideEffect, SDNPMayStore]>;
195
196 def tlsadd        : SDNode<"SPISD::TLS_ADD", SDTSPtlsadd>;
197 def tlsld         : SDNode<"SPISD::TLS_LD",  SDTSPtlsld>;
198 def tlscall       : SDNode<"SPISD::TLS_CALL", SDT_SPCall,
199                             [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue,
200                              SDNPVariadic]>;
201
202 def getPCX        : Operand<iPTR> {
203   let PrintMethod = "printGetPCX";
204 }
205
206 //===----------------------------------------------------------------------===//
207 // SPARC Flag Conditions
208 //===----------------------------------------------------------------------===//
209
210 // Note that these values must be kept in sync with the CCOp::CondCode enum
211 // values.
212 class ICC_VAL<int N> : PatLeaf<(i32 N)>;
213 def ICC_NE  : ICC_VAL< 9>;  // Not Equal
214 def ICC_E   : ICC_VAL< 1>;  // Equal
215 def ICC_G   : ICC_VAL<10>;  // Greater
216 def ICC_LE  : ICC_VAL< 2>;  // Less or Equal
217 def ICC_GE  : ICC_VAL<11>;  // Greater or Equal
218 def ICC_L   : ICC_VAL< 3>;  // Less
219 def ICC_GU  : ICC_VAL<12>;  // Greater Unsigned
220 def ICC_LEU : ICC_VAL< 4>;  // Less or Equal Unsigned
221 def ICC_CC  : ICC_VAL<13>;  // Carry Clear/Great or Equal Unsigned
222 def ICC_CS  : ICC_VAL< 5>;  // Carry Set/Less Unsigned
223 def ICC_POS : ICC_VAL<14>;  // Positive
224 def ICC_NEG : ICC_VAL< 6>;  // Negative
225 def ICC_VC  : ICC_VAL<15>;  // Overflow Clear
226 def ICC_VS  : ICC_VAL< 7>;  // Overflow Set
227
228 class FCC_VAL<int N> : PatLeaf<(i32 N)>;
229 def FCC_U   : FCC_VAL<23>;  // Unordered
230 def FCC_G   : FCC_VAL<22>;  // Greater
231 def FCC_UG  : FCC_VAL<21>;  // Unordered or Greater
232 def FCC_L   : FCC_VAL<20>;  // Less
233 def FCC_UL  : FCC_VAL<19>;  // Unordered or Less
234 def FCC_LG  : FCC_VAL<18>;  // Less or Greater
235 def FCC_NE  : FCC_VAL<17>;  // Not Equal
236 def FCC_E   : FCC_VAL<25>;  // Equal
237 def FCC_UE  : FCC_VAL<24>;  // Unordered or Equal
238 def FCC_GE  : FCC_VAL<25>;  // Greater or Equal
239 def FCC_UGE : FCC_VAL<26>;  // Unordered or Greater or Equal
240 def FCC_LE  : FCC_VAL<27>;  // Less or Equal
241 def FCC_ULE : FCC_VAL<28>;  // Unordered or Less or Equal
242 def FCC_O   : FCC_VAL<29>;  // Ordered
243
244 //===----------------------------------------------------------------------===//
245 // Instruction Class Templates
246 //===----------------------------------------------------------------------===//
247
248 /// F3_12 multiclass - Define a normal F3_1/F3_2 pattern in one shot.
249 multiclass F3_12<string OpcStr, bits<6> Op3Val, SDNode OpNode,
250                  RegisterClass RC, ValueType Ty, Operand immOp> {
251   def rr  : F3_1<2, Op3Val,
252                  (outs RC:$rd), (ins RC:$rs1, RC:$rs2),
253                  !strconcat(OpcStr, " $rs1, $rs2, $rd"),
254                  [(set Ty:$rd, (OpNode Ty:$rs1, Ty:$rs2))]>;
255   def ri  : F3_2<2, Op3Val,
256                  (outs RC:$rd), (ins RC:$rs1, immOp:$simm13),
257                  !strconcat(OpcStr, " $rs1, $simm13, $rd"),
258                  [(set Ty:$rd, (OpNode Ty:$rs1, (Ty simm13:$simm13)))]>;
259 }
260
261 /// F3_12np multiclass - Define a normal F3_1/F3_2 pattern in one shot, with no
262 /// pattern.
263 multiclass F3_12np<string OpcStr, bits<6> Op3Val> {
264   def rr  : F3_1<2, Op3Val,
265                  (outs IntRegs:$rd), (ins IntRegs:$rs1, IntRegs:$rs2),
266                  !strconcat(OpcStr, " $rs1, $rs2, $rd"), []>;
267   def ri  : F3_2<2, Op3Val,
268                  (outs IntRegs:$rd), (ins IntRegs:$rs1, simm13Op:$simm13),
269                  !strconcat(OpcStr, " $rs1, $simm13, $rd"), []>;
270 }
271
272 // Load multiclass - Define both Reg+Reg/Reg+Imm patterns in one shot.
273 multiclass Load<string OpcStr, bits<6> Op3Val, SDPatternOperator OpNode,
274            RegisterClass RC, ValueType Ty> {
275   def rr  : F3_1<3, Op3Val,
276                  (outs RC:$dst), (ins MEMrr:$addr),
277                  !strconcat(OpcStr, " [$addr], $dst"),
278                  [(set Ty:$dst, (OpNode ADDRrr:$addr))]>;
279   def ri  : F3_2<3, Op3Val,
280                  (outs RC:$dst), (ins MEMri:$addr),
281                  !strconcat(OpcStr, " [$addr], $dst"),
282                  [(set Ty:$dst, (OpNode ADDRri:$addr))]>;
283 }
284
285 // Store multiclass - Define both Reg+Reg/Reg+Imm patterns in one shot.
286 multiclass Store<string OpcStr, bits<6> Op3Val, SDPatternOperator OpNode,
287            RegisterClass RC, ValueType Ty> {
288   def rr  : F3_1<3, Op3Val,
289                  (outs), (ins MEMrr:$addr, RC:$rd),
290                  !strconcat(OpcStr, " $rd, [$addr]"),
291                  [(OpNode Ty:$rd, ADDRrr:$addr)]>;
292   def ri  : F3_2<3, Op3Val,
293                  (outs), (ins MEMri:$addr, RC:$rd),
294                  !strconcat(OpcStr, " $rd, [$addr]"),
295                  [(OpNode Ty:$rd, ADDRri:$addr)]>;
296 }
297
298 //===----------------------------------------------------------------------===//
299 // Instructions
300 //===----------------------------------------------------------------------===//
301
302 // Pseudo instructions.
303 class Pseudo<dag outs, dag ins, string asmstr, list<dag> pattern>
304    : InstSP<outs, ins, asmstr, pattern> {
305   let isCodeGenOnly = 1;
306   let isPseudo = 1;
307 }
308
309 // GETPCX for PIC
310 let Defs = [O7] in {
311   def GETPCX : Pseudo<(outs getPCX:$getpcseq), (ins), "$getpcseq", [] >;
312 }
313
314 let Defs = [O6], Uses = [O6] in {
315 def ADJCALLSTACKDOWN : Pseudo<(outs), (ins i32imm:$amt),
316                                "!ADJCALLSTACKDOWN $amt",
317                                [(callseq_start timm:$amt)]>;
318 def ADJCALLSTACKUP : Pseudo<(outs), (ins i32imm:$amt1, i32imm:$amt2),
319                             "!ADJCALLSTACKUP $amt1",
320                             [(callseq_end timm:$amt1, timm:$amt2)]>;
321 }
322
323 let hasSideEffects = 1, mayStore = 1 in {
324   let rd = 0, rs1 = 0, rs2 = 0 in
325     def FLUSHW : F3_1<0b10, 0b101011, (outs), (ins),
326                       "flushw",
327                       [(flushw)]>, Requires<[HasV9]>;
328   let rd = 0, rs1 = 1, simm13 = 3 in
329     def TA3 : F3_2<0b10, 0b111010, (outs), (ins),
330                    "ta 3",
331                    [(flushw)]>;
332 }
333
334 let isBarrier = 1, isTerminator = 1, rd = 0b1000, rs1 = 0, simm13 = 5 in
335   def TA5 : F3_2<0b10, 0b111010, (outs), (ins), "ta 5", [(trap)]>;
336
337 let rd = 0 in
338   def UNIMP : F2_1<0b000, (outs), (ins i32imm:$imm22),
339                   "unimp $imm22", []>;
340
341 // SELECT_CC_* - Used to implement the SELECT_CC DAG operation.  Expanded after
342 // instruction selection into a branch sequence.  This has to handle all
343 // permutations of selection between i32/f32/f64 on ICC and FCC.
344 // Expanded after instruction selection.
345 let Uses = [ICC], usesCustomInserter = 1 in {
346   def SELECT_CC_Int_ICC
347    : Pseudo<(outs IntRegs:$dst), (ins IntRegs:$T, IntRegs:$F, i32imm:$Cond),
348             "; SELECT_CC_Int_ICC PSEUDO!",
349             [(set i32:$dst, (SPselecticc i32:$T, i32:$F, imm:$Cond))]>;
350   def SELECT_CC_FP_ICC
351    : Pseudo<(outs FPRegs:$dst), (ins FPRegs:$T, FPRegs:$F, i32imm:$Cond),
352             "; SELECT_CC_FP_ICC PSEUDO!",
353             [(set f32:$dst, (SPselecticc f32:$T, f32:$F, imm:$Cond))]>;
354
355   def SELECT_CC_DFP_ICC
356    : Pseudo<(outs DFPRegs:$dst), (ins DFPRegs:$T, DFPRegs:$F, i32imm:$Cond),
357             "; SELECT_CC_DFP_ICC PSEUDO!",
358             [(set f64:$dst, (SPselecticc f64:$T, f64:$F, imm:$Cond))]>;
359
360   def SELECT_CC_QFP_ICC
361    : Pseudo<(outs QFPRegs:$dst), (ins QFPRegs:$T, QFPRegs:$F, i32imm:$Cond),
362             "; SELECT_CC_QFP_ICC PSEUDO!",
363             [(set f128:$dst, (SPselecticc f128:$T, f128:$F, imm:$Cond))]>;
364 }
365
366 let usesCustomInserter = 1, Uses = [FCC0] in {
367
368   def SELECT_CC_Int_FCC
369    : Pseudo<(outs IntRegs:$dst), (ins IntRegs:$T, IntRegs:$F, i32imm:$Cond),
370             "; SELECT_CC_Int_FCC PSEUDO!",
371             [(set i32:$dst, (SPselectfcc i32:$T, i32:$F, imm:$Cond))]>;
372
373   def SELECT_CC_FP_FCC
374    : Pseudo<(outs FPRegs:$dst), (ins FPRegs:$T, FPRegs:$F, i32imm:$Cond),
375             "; SELECT_CC_FP_FCC PSEUDO!",
376             [(set f32:$dst, (SPselectfcc f32:$T, f32:$F, imm:$Cond))]>;
377   def SELECT_CC_DFP_FCC
378    : Pseudo<(outs DFPRegs:$dst), (ins DFPRegs:$T, DFPRegs:$F, i32imm:$Cond),
379             "; SELECT_CC_DFP_FCC PSEUDO!",
380             [(set f64:$dst, (SPselectfcc f64:$T, f64:$F, imm:$Cond))]>;
381   def SELECT_CC_QFP_FCC
382    : Pseudo<(outs QFPRegs:$dst), (ins QFPRegs:$T, QFPRegs:$F, i32imm:$Cond),
383             "; SELECT_CC_QFP_FCC PSEUDO!",
384             [(set f128:$dst, (SPselectfcc f128:$T, f128:$F, imm:$Cond))]>;
385 }
386
387 // JMPL Instruction.
388 let isTerminator = 1, hasDelaySlot = 1, isBarrier = 1 in {
389   def JMPLrr: F3_1<2, 0b111000, (outs IntRegs:$dst), (ins MEMrr:$addr),
390                   "jmpl $addr, $dst", []>;
391   def JMPLri: F3_2<2, 0b111000, (outs IntRegs:$dst), (ins MEMri:$addr),
392                   "jmpl $addr, $dst", []>;
393 }
394
395 // Section A.3 - Synthetic Instructions, p. 85
396 // special cases of JMPL:
397 let isReturn = 1, isTerminator = 1, hasDelaySlot = 1, isBarrier = 1,
398     isCodeGenOnly = 1 in {
399   let rd = 0, rs1 = 15 in
400     def RETL: F3_2<2, 0b111000, (outs), (ins i32imm:$val),
401                    "jmp %o7+$val", [(retflag simm13:$val)]>;
402
403   let rd = 0, rs1 = 31 in
404     def RET: F3_2<2, 0b111000, (outs), (ins i32imm:$val),
405                   "jmp %i7+$val", []>;
406 }
407
408 // Section B.1 - Load Integer Instructions, p. 90
409 let DecoderMethod = "DecodeLoadInt" in {
410   defm LDSB : Load<"ldsb", 0b001001, sextloadi8,  IntRegs, i32>;
411   defm LDSH : Load<"ldsh", 0b001010, sextloadi16, IntRegs, i32>;
412   defm LDUB : Load<"ldub", 0b000001, zextloadi8,  IntRegs, i32>;
413   defm LDUH : Load<"lduh", 0b000010, zextloadi16, IntRegs, i32>;
414   defm LD   : Load<"ld",   0b000000, load,        IntRegs, i32>;
415 }
416
417 // Section B.2 - Load Floating-point Instructions, p. 92
418 let DecoderMethod = "DecodeLoadFP" in
419   defm LDF   : Load<"ld",  0b100000, load, FPRegs,  f32>;
420 let DecoderMethod = "DecodeLoadDFP" in
421   defm LDDF  : Load<"ldd", 0b100011, load, DFPRegs, f64>;
422 let DecoderMethod = "DecodeLoadQFP" in
423   defm LDQF  : Load<"ldq", 0b100010, load, QFPRegs, f128>,
424                Requires<[HasV9, HasHardQuad]>;
425
426 // Section B.4 - Store Integer Instructions, p. 95
427 let DecoderMethod = "DecodeStoreInt" in {
428   defm STB   : Store<"stb", 0b000101, truncstorei8,  IntRegs, i32>;
429   defm STH   : Store<"sth", 0b000110, truncstorei16, IntRegs, i32>;
430   defm ST    : Store<"st",  0b000100, store,         IntRegs, i32>;
431 }
432
433 // Section B.5 - Store Floating-point Instructions, p. 97
434 let DecoderMethod = "DecodeStoreFP" in
435   defm STF   : Store<"st",  0b100100, store,         FPRegs,  f32>;
436 let DecoderMethod = "DecodeStoreDFP" in
437   defm STDF  : Store<"std", 0b100111, store,         DFPRegs, f64>;
438 let DecoderMethod = "DecodeStoreQFP" in
439   defm STQF  : Store<"stq", 0b100110, store,         QFPRegs, f128>,
440                Requires<[HasV9, HasHardQuad]>;
441
442 // Section B.9 - SETHI Instruction, p. 104
443 def SETHIi: F2_1<0b100,
444                  (outs IntRegs:$rd), (ins i32imm:$imm22),
445                  "sethi $imm22, $rd",
446                  [(set i32:$rd, SETHIimm:$imm22)]>;
447
448 // Section B.10 - NOP Instruction, p. 105
449 // (It's a special case of SETHI)
450 let rd = 0, imm22 = 0 in
451   def NOP : F2_1<0b100, (outs), (ins), "nop", []>;
452
453 // Section B.11 - Logical Instructions, p. 106
454 defm AND    : F3_12<"and", 0b000001, and, IntRegs, i32, simm13Op>;
455
456 def ANDNrr  : F3_1<2, 0b000101,
457                    (outs IntRegs:$rd), (ins IntRegs:$rs1, IntRegs:$rs2),
458                    "andn $rs1, $rs2, $rd",
459                    [(set i32:$rd, (and i32:$rs1, (not i32:$rs2)))]>;
460 def ANDNri  : F3_2<2, 0b000101,
461                    (outs IntRegs:$rd), (ins IntRegs:$rs1, simm13Op:$simm13),
462                    "andn $rs1, $simm13, $rd", []>;
463
464 defm OR     : F3_12<"or", 0b000010, or, IntRegs, i32, simm13Op>;
465
466 def ORNrr   : F3_1<2, 0b000110,
467                    (outs IntRegs:$rd), (ins IntRegs:$rs1, IntRegs:$rs2),
468                    "orn $rs1, $rs2, $rd",
469                    [(set i32:$rd, (or i32:$rs1, (not i32:$rs2)))]>;
470 def ORNri   : F3_2<2, 0b000110,
471                    (outs IntRegs:$rd), (ins IntRegs:$rs1, simm13Op:$simm13),
472                    "orn $rs1, $simm13, $rd", []>;
473 defm XOR    : F3_12<"xor", 0b000011, xor, IntRegs, i32, simm13Op>;
474
475 def XNORrr  : F3_1<2, 0b000111,
476                    (outs IntRegs:$rd), (ins IntRegs:$rs1, IntRegs:$rs2),
477                    "xnor $rs1, $rs2, $rd",
478                    [(set i32:$rd, (not (xor i32:$rs1, i32:$rs2)))]>;
479 def XNORri  : F3_2<2, 0b000111,
480                    (outs IntRegs:$rd), (ins IntRegs:$rs1, simm13Op:$simm13),
481                    "xnor $rs1, $simm13, $rd", []>;
482
483 let Defs = [ICC] in {
484   defm ANDCC  : F3_12np<"andcc",  0b010001>;
485   defm ANDNCC : F3_12np<"andncc", 0b010101>;
486   defm ORCC   : F3_12np<"orcc",   0b010010>;
487   defm ORNCC  : F3_12np<"orncc",  0b010110>;
488   defm XORCC  : F3_12np<"xorcc",  0b010011>;
489   defm XNORCC : F3_12np<"xnorcc", 0b010111>;
490 }
491
492 // Section B.12 - Shift Instructions, p. 107
493 defm SLL : F3_12<"sll", 0b100101, shl, IntRegs, i32, simm13Op>;
494 defm SRL : F3_12<"srl", 0b100110, srl, IntRegs, i32, simm13Op>;
495 defm SRA : F3_12<"sra", 0b100111, sra, IntRegs, i32, simm13Op>;
496
497 // Section B.13 - Add Instructions, p. 108
498 defm ADD   : F3_12<"add", 0b000000, add, IntRegs, i32, simm13Op>;
499
500 // "LEA" forms of add (patterns to make tblgen happy)
501 let Predicates = [Is32Bit], isCodeGenOnly = 1 in
502   def LEA_ADDri   : F3_2<2, 0b000000,
503                      (outs IntRegs:$dst), (ins MEMri:$addr),
504                      "add ${addr:arith}, $dst",
505                      [(set iPTR:$dst, ADDRri:$addr)]>;
506
507 let Defs = [ICC] in
508   defm ADDCC  : F3_12<"addcc", 0b010000, addc, IntRegs, i32, simm13Op>;
509
510 let Uses = [ICC] in
511   defm ADDC   : F3_12np<"addx", 0b001000>;
512
513 let Uses = [ICC], Defs = [ICC] in
514   defm ADDE  : F3_12<"addxcc", 0b011000, adde, IntRegs, i32, simm13Op>;
515
516 // Section B.15 - Subtract Instructions, p. 110
517 defm SUB    : F3_12  <"sub"  , 0b000100, sub, IntRegs, i32, simm13Op>;
518 let Uses = [ICC], Defs = [ICC] in
519   defm SUBE   : F3_12  <"subxcc" , 0b011100, sube, IntRegs, i32, simm13Op>;
520
521 let Defs = [ICC] in
522   defm SUBCC  : F3_12  <"subcc", 0b010100, subc, IntRegs, i32, simm13Op>;
523
524 let Uses = [ICC] in
525   defm SUBC   : F3_12np <"subx", 0b001100>;
526
527 let Defs = [ICC], rd = 0 in {
528   def CMPrr   : F3_1<2, 0b010100,
529                      (outs), (ins IntRegs:$rs1, IntRegs:$rs2),
530                      "cmp $rs1, $rs2",
531                      [(SPcmpicc i32:$rs1, i32:$rs2)]>;
532   def CMPri   : F3_2<2, 0b010100,
533                      (outs), (ins IntRegs:$rs1, simm13Op:$simm13),
534                      "cmp $rs1, $simm13",
535                      [(SPcmpicc i32:$rs1, (i32 simm13:$simm13))]>;
536 }
537
538 // Section B.18 - Multiply Instructions, p. 113
539 let Defs = [Y] in {
540   defm UMUL : F3_12np<"umul", 0b001010>;
541   defm SMUL : F3_12  <"smul", 0b001011, mul, IntRegs, i32, simm13Op>;
542 }
543
544 let Defs = [Y, ICC] in {
545   defm UMULCC : F3_12np<"umulcc", 0b011010>;
546   defm SMULCC : F3_12np<"smulcc", 0b011011>;
547 }
548
549 // Section B.19 - Divide Instructions, p. 115
550 let Defs = [Y] in {
551   defm UDIV : F3_12np<"udiv", 0b001110>;
552   defm SDIV : F3_12np<"sdiv", 0b001111>;
553 }
554
555 let Defs = [Y, ICC] in {
556   defm UDIVCC : F3_12np<"udivcc", 0b011110>;
557   defm SDIVCC : F3_12np<"sdivcc", 0b011111>;
558 }
559
560 // Section B.20 - SAVE and RESTORE, p. 117
561 defm SAVE    : F3_12np<"save"   , 0b111100>;
562 defm RESTORE : F3_12np<"restore", 0b111101>;
563
564 // Section B.21 - Branch on Integer Condition Codes Instructions, p. 119
565
566 // unconditional branch class.
567 class BranchAlways<dag ins, string asmstr, list<dag> pattern>
568   : F2_2<0b010, 0, (outs), ins, asmstr, pattern> {
569   let isBranch     = 1;
570   let isTerminator = 1;
571   let hasDelaySlot = 1;
572   let isBarrier    = 1;
573 }
574
575 let cond = 8 in
576   def BA : BranchAlways<(ins brtarget:$imm22), "ba $imm22", [(br bb:$imm22)]>;
577
578
579 let isBranch = 1, isTerminator = 1, hasDelaySlot = 1 in {
580
581 // conditional branch class:
582 class BranchSP<dag ins, string asmstr, list<dag> pattern>
583  : F2_2<0b010, 0, (outs), ins, asmstr, pattern>;
584
585 // conditional branch with annul class:
586 class BranchSPA<dag ins, string asmstr, list<dag> pattern>
587  : F2_2<0b010, 1, (outs), ins, asmstr, pattern>;
588
589 // Conditional branch class on %icc|%xcc with predication:
590 multiclass IPredBranch<string regstr, list<dag> CCPattern> {
591   def CC    : F2_3<0b001, 0, 1, (outs), (ins bprtarget:$imm19, CCOp:$cond),
592                   !strconcat("b$cond ", !strconcat(regstr, ", $imm19")),
593                    CCPattern>;
594   def CCA   : F2_3<0b001, 1, 1, (outs), (ins bprtarget:$imm19, CCOp:$cond),
595                   !strconcat("b$cond,a ", !strconcat(regstr, ", $imm19")),
596                    []>;
597   def CCNT  : F2_3<0b001, 0, 0, (outs), (ins bprtarget:$imm19, CCOp:$cond),
598                    !strconcat("b$cond,pn ", !strconcat(regstr, ", $imm19")),
599                    []>;
600   def CCANT : F2_3<0b001, 1, 0, (outs), (ins bprtarget:$imm19, CCOp:$cond),
601                    !strconcat("b$cond,a,pn ", !strconcat(regstr, ", $imm19")),
602                    []>;
603 }
604
605 } // let isBranch = 1, isTerminator = 1, hasDelaySlot = 1
606
607
608 // Indirect branch instructions.
609 let isTerminator = 1, isBarrier = 1,  hasDelaySlot = 1, isBranch =1,
610      isIndirectBranch = 1, rd = 0, isCodeGenOnly = 1 in {
611   def BINDrr  : F3_1<2, 0b111000,
612                    (outs), (ins MEMrr:$ptr),
613                    "jmp $ptr",
614                    [(brind ADDRrr:$ptr)]>;
615   def BINDri  : F3_2<2, 0b111000,
616                    (outs), (ins MEMri:$ptr),
617                    "jmp $ptr",
618                    [(brind ADDRri:$ptr)]>;
619 }
620
621 let Uses = [ICC] in {
622   def BCOND : BranchSP<(ins brtarget:$imm22, CCOp:$cond),
623                          "b$cond $imm22",
624                         [(SPbricc bb:$imm22, imm:$cond)]>;
625   def BCONDA : BranchSPA<(ins brtarget:$imm22, CCOp:$cond),
626                          "b$cond,a $imm22", []>;
627
628   let Predicates = [HasV9], cc = 0b00 in
629     defm BPI : IPredBranch<"%icc", []>;
630 }
631
632 // Section B.22 - Branch on Floating-point Condition Codes Instructions, p. 121
633
634 let isBranch = 1, isTerminator = 1, hasDelaySlot = 1 in {
635
636 // floating-point conditional branch class:
637 class FPBranchSP<dag ins, string asmstr, list<dag> pattern>
638  : F2_2<0b110, 0, (outs), ins, asmstr, pattern>;
639
640 // floating-point conditional branch with annul class:
641 class FPBranchSPA<dag ins, string asmstr, list<dag> pattern>
642  : F2_2<0b110, 1, (outs), ins, asmstr, pattern>;
643
644 // Conditional branch class on %fcc0-%fcc3 with predication:
645 multiclass FPredBranch {
646   def CC    : F2_3<0b101, 0, 1, (outs), (ins bprtarget:$imm19, CCOp:$cond,
647                                          FCCRegs:$cc),
648                   "fb$cond $cc, $imm19", []>;
649   def CCA   : F2_3<0b101, 1, 1, (outs), (ins bprtarget:$imm19, CCOp:$cond,
650                                          FCCRegs:$cc),
651                   "fb$cond,a $cc, $imm19", []>;
652   def CCNT  : F2_3<0b101, 0, 0, (outs), (ins bprtarget:$imm19, CCOp:$cond,
653                                          FCCRegs:$cc),
654                   "fb$cond,pn $cc, $imm19", []>;
655   def CCANT : F2_3<0b101, 1, 0, (outs), (ins bprtarget:$imm19, CCOp:$cond,
656                                          FCCRegs:$cc),
657                   "fb$cond,a,pn $cc, $imm19", []>;
658 }
659 } // let isBranch = 1, isTerminator = 1, hasDelaySlot = 1
660
661 let Uses = [FCC0] in {
662   def FBCOND  : FPBranchSP<(ins brtarget:$imm22, CCOp:$cond),
663                               "fb$cond $imm22",
664                               [(SPbrfcc bb:$imm22, imm:$cond)]>;
665   def FBCONDA : FPBranchSPA<(ins brtarget:$imm22, CCOp:$cond),
666                              "fb$cond,a $imm22", []>;
667 }
668
669 let Predicates = [HasV9] in
670   defm BPF : FPredBranch;
671
672
673 // Section B.24 - Call and Link Instruction, p. 125
674 // This is the only Format 1 instruction
675 let Uses = [O6],
676     hasDelaySlot = 1, isCall = 1 in {
677   def CALL : InstSP<(outs), (ins calltarget:$disp, variable_ops),
678                     "call $disp", []> {
679     bits<30> disp;
680     let op = 1;
681     let Inst{29-0} = disp;
682   }
683
684   // indirect calls: special cases of JMPL.
685   let isCodeGenOnly = 1, rd = 15 in {
686     def CALLrr : F3_1<2, 0b111000,
687                       (outs), (ins MEMrr:$ptr, variable_ops),
688                       "call $ptr",
689                       [(call ADDRrr:$ptr)]>;
690     def CALLri : F3_2<2, 0b111000,
691                       (outs), (ins MEMri:$ptr, variable_ops),
692                       "call $ptr",
693                       [(call ADDRri:$ptr)]>;
694   }
695 }
696
697 // Section B.28 - Read State Register Instructions
698 let Uses = [Y], rs1 = 0, rs2 = 0 in
699   def RDY : F3_1<2, 0b101000,
700                  (outs IntRegs:$dst), (ins),
701                  "rd %y, $dst", []>;
702
703 // Section B.29 - Write State Register Instructions
704 let Defs = [Y], rd = 0 in {
705   def WRYrr : F3_1<2, 0b110000,
706                    (outs), (ins IntRegs:$rs1, IntRegs:$rs2),
707                    "wr $rs1, $rs2, %y", []>;
708   def WRYri : F3_2<2, 0b110000,
709                    (outs), (ins IntRegs:$rs1, simm13Op:$simm13),
710                    "wr $rs1, $simm13, %y", []>;
711 }
712 // Convert Integer to Floating-point Instructions, p. 141
713 def FITOS : F3_3u<2, 0b110100, 0b011000100,
714                  (outs FPRegs:$rd), (ins FPRegs:$rs2),
715                  "fitos $rs2, $rd",
716                  [(set FPRegs:$rd, (SPitof FPRegs:$rs2))]>;
717 def FITOD : F3_3u<2, 0b110100, 0b011001000,
718                  (outs DFPRegs:$rd), (ins FPRegs:$rs2),
719                  "fitod $rs2, $rd",
720                  [(set DFPRegs:$rd, (SPitof FPRegs:$rs2))]>;
721 def FITOQ : F3_3u<2, 0b110100, 0b011001100,
722                  (outs QFPRegs:$rd), (ins FPRegs:$rs2),
723                  "fitoq $rs2, $rd",
724                  [(set QFPRegs:$rd, (SPitof FPRegs:$rs2))]>,
725                  Requires<[HasHardQuad]>;
726
727 // Convert Floating-point to Integer Instructions, p. 142
728 def FSTOI : F3_3u<2, 0b110100, 0b011010001,
729                  (outs FPRegs:$rd), (ins FPRegs:$rs2),
730                  "fstoi $rs2, $rd",
731                  [(set FPRegs:$rd, (SPftoi FPRegs:$rs2))]>;
732 def FDTOI : F3_3u<2, 0b110100, 0b011010010,
733                  (outs FPRegs:$rd), (ins DFPRegs:$rs2),
734                  "fdtoi $rs2, $rd",
735                  [(set FPRegs:$rd, (SPftoi DFPRegs:$rs2))]>;
736 def FQTOI : F3_3u<2, 0b110100, 0b011010011,
737                  (outs FPRegs:$rd), (ins QFPRegs:$rs2),
738                  "fqtoi $rs2, $rd",
739                  [(set FPRegs:$rd, (SPftoi QFPRegs:$rs2))]>,
740                  Requires<[HasHardQuad]>;
741
742 // Convert between Floating-point Formats Instructions, p. 143
743 def FSTOD : F3_3u<2, 0b110100, 0b011001001,
744                  (outs DFPRegs:$rd), (ins FPRegs:$rs2),
745                  "fstod $rs2, $rd",
746                  [(set f64:$rd, (fextend f32:$rs2))]>;
747 def FSTOQ : F3_3u<2, 0b110100, 0b011001101,
748                  (outs QFPRegs:$rd), (ins FPRegs:$rs2),
749                  "fstoq $rs2, $rd",
750                  [(set f128:$rd, (fextend f32:$rs2))]>,
751                  Requires<[HasHardQuad]>;
752 def FDTOS : F3_3u<2, 0b110100, 0b011000110,
753                  (outs FPRegs:$rd), (ins DFPRegs:$rs2),
754                  "fdtos $rs2, $rd",
755                  [(set f32:$rd, (fround f64:$rs2))]>;
756 def FDTOQ : F3_3u<2, 0b110100, 0b011001110,
757                  (outs QFPRegs:$rd), (ins DFPRegs:$rs2),
758                  "fdtoq $rs2, $rd",
759                  [(set f128:$rd, (fextend f64:$rs2))]>,
760                  Requires<[HasHardQuad]>;
761 def FQTOS : F3_3u<2, 0b110100, 0b011000111,
762                  (outs FPRegs:$rd), (ins QFPRegs:$rs2),
763                  "fqtos $rs2, $rd",
764                  [(set f32:$rd, (fround f128:$rs2))]>,
765                  Requires<[HasHardQuad]>;
766 def FQTOD : F3_3u<2, 0b110100, 0b011001011,
767                  (outs DFPRegs:$rd), (ins QFPRegs:$rs2),
768                  "fqtod $rs2, $rd",
769                  [(set f64:$rd, (fround f128:$rs2))]>,
770                  Requires<[HasHardQuad]>;
771
772 // Floating-point Move Instructions, p. 144
773 def FMOVS : F3_3u<2, 0b110100, 0b000000001,
774                  (outs FPRegs:$rd), (ins FPRegs:$rs2),
775                  "fmovs $rs2, $rd", []>;
776 def FNEGS : F3_3u<2, 0b110100, 0b000000101,
777                  (outs FPRegs:$rd), (ins FPRegs:$rs2),
778                  "fnegs $rs2, $rd",
779                  [(set f32:$rd, (fneg f32:$rs2))]>;
780 def FABSS : F3_3u<2, 0b110100, 0b000001001,
781                  (outs FPRegs:$rd), (ins FPRegs:$rs2),
782                  "fabss $rs2, $rd",
783                  [(set f32:$rd, (fabs f32:$rs2))]>;
784
785
786 // Floating-point Square Root Instructions, p.145
787 def FSQRTS : F3_3u<2, 0b110100, 0b000101001,
788                   (outs FPRegs:$rd), (ins FPRegs:$rs2),
789                   "fsqrts $rs2, $rd",
790                   [(set f32:$rd, (fsqrt f32:$rs2))]>;
791 def FSQRTD : F3_3u<2, 0b110100, 0b000101010,
792                   (outs DFPRegs:$rd), (ins DFPRegs:$rs2),
793                   "fsqrtd $rs2, $rd",
794                   [(set f64:$rd, (fsqrt f64:$rs2))]>;
795 def FSQRTQ : F3_3u<2, 0b110100, 0b000101011,
796                   (outs QFPRegs:$rd), (ins QFPRegs:$rs2),
797                   "fsqrtq $rs2, $rd",
798                   [(set f128:$rd, (fsqrt f128:$rs2))]>,
799                   Requires<[HasHardQuad]>;
800
801
802
803 // Floating-point Add and Subtract Instructions, p. 146
804 def FADDS  : F3_3<2, 0b110100, 0b001000001,
805                   (outs FPRegs:$rd), (ins FPRegs:$rs1, FPRegs:$rs2),
806                   "fadds $rs1, $rs2, $rd",
807                   [(set f32:$rd, (fadd f32:$rs1, f32:$rs2))]>;
808 def FADDD  : F3_3<2, 0b110100, 0b001000010,
809                   (outs DFPRegs:$rd), (ins DFPRegs:$rs1, DFPRegs:$rs2),
810                   "faddd $rs1, $rs2, $rd",
811                   [(set f64:$rd, (fadd f64:$rs1, f64:$rs2))]>;
812 def FADDQ  : F3_3<2, 0b110100, 0b001000011,
813                   (outs QFPRegs:$rd), (ins QFPRegs:$rs1, QFPRegs:$rs2),
814                   "faddq $rs1, $rs2, $rd",
815                   [(set f128:$rd, (fadd f128:$rs1, f128:$rs2))]>,
816                   Requires<[HasHardQuad]>;
817
818 def FSUBS  : F3_3<2, 0b110100, 0b001000101,
819                   (outs FPRegs:$rd), (ins FPRegs:$rs1, FPRegs:$rs2),
820                   "fsubs $rs1, $rs2, $rd",
821                   [(set f32:$rd, (fsub f32:$rs1, f32:$rs2))]>;
822 def FSUBD  : F3_3<2, 0b110100, 0b001000110,
823                   (outs DFPRegs:$rd), (ins DFPRegs:$rs1, DFPRegs:$rs2),
824                   "fsubd $rs1, $rs2, $rd",
825                   [(set f64:$rd, (fsub f64:$rs1, f64:$rs2))]>;
826 def FSUBQ  : F3_3<2, 0b110100, 0b001000111,
827                   (outs QFPRegs:$rd), (ins QFPRegs:$rs1, QFPRegs:$rs2),
828                   "fsubq $rs1, $rs2, $rd",
829                   [(set f128:$rd, (fsub f128:$rs1, f128:$rs2))]>,
830                   Requires<[HasHardQuad]>;
831
832
833 // Floating-point Multiply and Divide Instructions, p. 147
834 def FMULS  : F3_3<2, 0b110100, 0b001001001,
835                   (outs FPRegs:$rd), (ins FPRegs:$rs1, FPRegs:$rs2),
836                   "fmuls $rs1, $rs2, $rd",
837                   [(set f32:$rd, (fmul f32:$rs1, f32:$rs2))]>;
838 def FMULD  : F3_3<2, 0b110100, 0b001001010,
839                   (outs DFPRegs:$rd), (ins DFPRegs:$rs1, DFPRegs:$rs2),
840                   "fmuld $rs1, $rs2, $rd",
841                   [(set f64:$rd, (fmul f64:$rs1, f64:$rs2))]>;
842 def FMULQ  : F3_3<2, 0b110100, 0b001001011,
843                   (outs QFPRegs:$rd), (ins QFPRegs:$rs1, QFPRegs:$rs2),
844                   "fmulq $rs1, $rs2, $rd",
845                   [(set f128:$rd, (fmul f128:$rs1, f128:$rs2))]>,
846                   Requires<[HasHardQuad]>;
847
848 def FSMULD : F3_3<2, 0b110100, 0b001101001,
849                   (outs DFPRegs:$rd), (ins FPRegs:$rs1, FPRegs:$rs2),
850                   "fsmuld $rs1, $rs2, $rd",
851                   [(set f64:$rd, (fmul (fextend f32:$rs1),
852                                         (fextend f32:$rs2)))]>;
853 def FDMULQ : F3_3<2, 0b110100, 0b001101110,
854                   (outs QFPRegs:$rd), (ins DFPRegs:$rs1, DFPRegs:$rs2),
855                   "fdmulq $rs1, $rs2, $rd",
856                   [(set f128:$rd, (fmul (fextend f64:$rs1),
857                                          (fextend f64:$rs2)))]>,
858                   Requires<[HasHardQuad]>;
859
860 def FDIVS  : F3_3<2, 0b110100, 0b001001101,
861                  (outs FPRegs:$rd), (ins FPRegs:$rs1, FPRegs:$rs2),
862                  "fdivs $rs1, $rs2, $rd",
863                  [(set f32:$rd, (fdiv f32:$rs1, f32:$rs2))]>;
864 def FDIVD  : F3_3<2, 0b110100, 0b001001110,
865                  (outs DFPRegs:$rd), (ins DFPRegs:$rs1, DFPRegs:$rs2),
866                  "fdivd $rs1, $rs2, $rd",
867                  [(set f64:$rd, (fdiv f64:$rs1, f64:$rs2))]>;
868 def FDIVQ  : F3_3<2, 0b110100, 0b001001111,
869                  (outs QFPRegs:$rd), (ins QFPRegs:$rs1, QFPRegs:$rs2),
870                  "fdivq $rs1, $rs2, $rd",
871                  [(set f128:$rd, (fdiv f128:$rs1, f128:$rs2))]>,
872                  Requires<[HasHardQuad]>;
873
874 // Floating-point Compare Instructions, p. 148
875 // Note: the 2nd template arg is different for these guys.
876 // Note 2: the result of a FCMP is not available until the 2nd cycle
877 // after the instr is retired, but there is no interlock in Sparc V8.
878 // This behavior is modeled with a forced noop after the instruction in
879 // DelaySlotFiller.
880
881 let Defs = [FCC0], rd = 0, isCodeGenOnly = 1 in {
882   def FCMPS  : F3_3c<2, 0b110101, 0b001010001,
883                    (outs), (ins FPRegs:$rs1, FPRegs:$rs2),
884                    "fcmps $rs1, $rs2",
885                    [(SPcmpfcc f32:$rs1, f32:$rs2)]>;
886   def FCMPD  : F3_3c<2, 0b110101, 0b001010010,
887                    (outs), (ins DFPRegs:$rs1, DFPRegs:$rs2),
888                    "fcmpd $rs1, $rs2",
889                    [(SPcmpfcc f64:$rs1, f64:$rs2)]>;
890   def FCMPQ  : F3_3c<2, 0b110101, 0b001010011,
891                    (outs), (ins QFPRegs:$rs1, QFPRegs:$rs2),
892                    "fcmpq $rs1, $rs2",
893                    [(SPcmpfcc f128:$rs1, f128:$rs2)]>,
894                    Requires<[HasHardQuad]>;
895 }
896
897 //===----------------------------------------------------------------------===//
898 // Instructions for Thread Local Storage(TLS).
899 //===----------------------------------------------------------------------===//
900 let isCodeGenOnly = 1, isAsmParserOnly = 1 in {
901 def TLS_ADDrr : F3_1<2, 0b000000,
902                     (outs IntRegs:$rd),
903                     (ins IntRegs:$rs1, IntRegs:$rs2, TLSSym:$sym),
904                     "add $rs1, $rs2, $rd, $sym",
905                     [(set i32:$rd,
906                         (tlsadd i32:$rs1, i32:$rs2, tglobaltlsaddr:$sym))]>;
907
908 let mayLoad = 1 in
909   def TLS_LDrr : F3_1<3, 0b000000,
910                       (outs IntRegs:$dst), (ins MEMrr:$addr, TLSSym:$sym),
911                       "ld [$addr], $dst, $sym",
912                       [(set i32:$dst,
913                           (tlsld ADDRrr:$addr, tglobaltlsaddr:$sym))]>;
914
915 let Uses = [O6], isCall = 1, hasDelaySlot = 1 in
916   def TLS_CALL : InstSP<(outs),
917                         (ins calltarget:$disp, TLSSym:$sym, variable_ops),
918                         "call $disp, $sym",
919                         [(tlscall texternalsym:$disp, tglobaltlsaddr:$sym)]> {
920   bits<30> disp;
921   let op = 1;
922   let Inst{29-0} = disp;
923 }
924 }
925
926 //===----------------------------------------------------------------------===//
927 // V9 Instructions
928 //===----------------------------------------------------------------------===//
929
930 // V9 Conditional Moves.
931 let Predicates = [HasV9], Constraints = "$f = $rd" in {
932   // Move Integer Register on Condition (MOVcc) p. 194 of the V9 manual.
933   let Uses = [ICC], intcc = 1, cc = 0b00 in {
934     def MOVICCrr
935       : F4_1<0b101100, (outs IntRegs:$rd),
936              (ins IntRegs:$rs2, IntRegs:$f, CCOp:$cond),
937              "mov$cond %icc, $rs2, $rd",
938              [(set i32:$rd, (SPselecticc i32:$rs2, i32:$f, imm:$cond))]>;
939
940     def MOVICCri
941       : F4_2<0b101100, (outs IntRegs:$rd),
942              (ins i32imm:$simm11, IntRegs:$f, CCOp:$cond),
943              "mov$cond %icc, $simm11, $rd",
944              [(set i32:$rd,
945                     (SPselecticc simm11:$simm11, i32:$f, imm:$cond))]>;
946   }
947
948   let Uses = [FCC0], intcc = 0, cc = 0b00 in {
949     def MOVFCCrr
950       : F4_1<0b101100, (outs IntRegs:$rd),
951              (ins IntRegs:$rs2, IntRegs:$f, CCOp:$cond),
952              "mov$cond %fcc0, $rs2, $rd",
953              [(set i32:$rd, (SPselectfcc i32:$rs2, i32:$f, imm:$cond))]>;
954     def MOVFCCri
955       : F4_2<0b101100, (outs IntRegs:$rd),
956              (ins i32imm:$simm11, IntRegs:$f, CCOp:$cond),
957              "mov$cond %fcc0, $simm11, $rd",
958              [(set i32:$rd,
959                     (SPselectfcc simm11:$simm11, i32:$f, imm:$cond))]>;
960   }
961
962   let Uses = [ICC], intcc = 1, opf_cc = 0b00 in {
963     def FMOVS_ICC
964       : F4_3<0b110101, 0b000001, (outs FPRegs:$rd),
965              (ins FPRegs:$rs2, FPRegs:$f, CCOp:$cond),
966              "fmovs$cond %icc, $rs2, $rd",
967              [(set f32:$rd, (SPselecticc f32:$rs2, f32:$f, imm:$cond))]>;
968     def FMOVD_ICC
969       : F4_3<0b110101, 0b000010, (outs DFPRegs:$rd),
970                (ins DFPRegs:$rs2, DFPRegs:$f, CCOp:$cond),
971                "fmovd$cond %icc, $rs2, $rd",
972                [(set f64:$rd, (SPselecticc f64:$rs2, f64:$f, imm:$cond))]>;
973     def FMOVQ_ICC
974       : F4_3<0b110101, 0b000011, (outs QFPRegs:$rd),
975                (ins QFPRegs:$rs2, QFPRegs:$f, CCOp:$cond),
976                "fmovq$cond %icc, $rs2, $rd",
977                [(set f128:$rd, (SPselecticc f128:$rs2, f128:$f, imm:$cond))]>,
978                Requires<[HasHardQuad]>;
979   }
980
981   let Uses = [FCC0], intcc = 0, opf_cc = 0b00 in {
982     def FMOVS_FCC
983       : F4_3<0b110101, 0b000001, (outs FPRegs:$rd),
984              (ins FPRegs:$rs2, FPRegs:$f, CCOp:$cond),
985              "fmovs$cond %fcc0, $rs2, $rd",
986              [(set f32:$rd, (SPselectfcc f32:$rs2, f32:$f, imm:$cond))]>;
987     def FMOVD_FCC
988       : F4_3<0b110101, 0b000010, (outs DFPRegs:$rd),
989              (ins DFPRegs:$rs2, DFPRegs:$f, CCOp:$cond),
990              "fmovd$cond %fcc0, $rs2, $rd",
991              [(set f64:$rd, (SPselectfcc f64:$rs2, f64:$f, imm:$cond))]>;
992     def FMOVQ_FCC
993       : F4_3<0b110101, 0b000011, (outs QFPRegs:$rd),
994              (ins QFPRegs:$rs2, QFPRegs:$f, CCOp:$cond),
995              "fmovq$cond %fcc0, $rs2, $rd",
996              [(set f128:$rd, (SPselectfcc f128:$rs2, f128:$f, imm:$cond))]>,
997              Requires<[HasHardQuad]>;
998   }
999
1000 }
1001
1002 // Floating-Point Move Instructions, p. 164 of the V9 manual.
1003 let Predicates = [HasV9] in {
1004   def FMOVD : F3_3u<2, 0b110100, 0b000000010,
1005                    (outs DFPRegs:$rd), (ins DFPRegs:$rs2),
1006                    "fmovd $rs2, $rd", []>;
1007   def FMOVQ : F3_3u<2, 0b110100, 0b000000011,
1008                    (outs QFPRegs:$rd), (ins QFPRegs:$rs2),
1009                    "fmovq $rs2, $rd", []>,
1010                    Requires<[HasHardQuad]>;
1011   def FNEGD : F3_3u<2, 0b110100, 0b000000110,
1012                    (outs DFPRegs:$rd), (ins DFPRegs:$rs2),
1013                    "fnegd $rs2, $rd",
1014                    [(set f64:$rd, (fneg f64:$rs2))]>;
1015   def FNEGQ : F3_3u<2, 0b110100, 0b000000111,
1016                    (outs QFPRegs:$rd), (ins QFPRegs:$rs2),
1017                    "fnegq $rs2, $rd",
1018                    [(set f128:$rd, (fneg f128:$rs2))]>,
1019                    Requires<[HasHardQuad]>;
1020   def FABSD : F3_3u<2, 0b110100, 0b000001010,
1021                    (outs DFPRegs:$rd), (ins DFPRegs:$rs2),
1022                    "fabsd $rs2, $rd",
1023                    [(set f64:$rd, (fabs f64:$rs2))]>;
1024   def FABSQ : F3_3u<2, 0b110100, 0b000001011,
1025                    (outs QFPRegs:$rd), (ins QFPRegs:$rs2),
1026                    "fabsq $rs2, $rd",
1027                    [(set f128:$rd, (fabs f128:$rs2))]>,
1028                    Requires<[HasHardQuad]>;
1029 }
1030
1031 // Floating-point compare instruction with %fcc0-%fcc3.
1032 def V9FCMPS  : F3_3c<2, 0b110101, 0b001010001,
1033                (outs FCCRegs:$rd), (ins FPRegs:$rs1, FPRegs:$rs2),
1034                "fcmps $rd, $rs1, $rs2", []>;
1035 def V9FCMPD  : F3_3c<2, 0b110101, 0b001010010,
1036                 (outs FCCRegs:$rd), (ins DFPRegs:$rs1, DFPRegs:$rs2),
1037                 "fcmpd $rd, $rs1, $rs2", []>;
1038 def V9FCMPQ  : F3_3c<2, 0b110101, 0b001010011,
1039                 (outs FCCRegs:$rd), (ins QFPRegs:$rs1, QFPRegs:$rs2),
1040                 "fcmpq $rd, $rs1, $rs2", []>,
1041                  Requires<[HasHardQuad]>;
1042
1043 // Floating point conditional move instrucitons with %fcc0-%fcc3.
1044 let Predicates = [HasV9] in {
1045   let Constraints = "$f = $rd", intcc = 0 in {
1046     def V9MOVFCCrr
1047       : F4_1<0b101100, (outs IntRegs:$rd),
1048              (ins FCCRegs:$cc, IntRegs:$rs2, IntRegs:$f, CCOp:$cond),
1049              "mov$cond $cc, $rs2, $rd", []>;
1050     def V9MOVFCCri
1051       : F4_2<0b101100, (outs IntRegs:$rd),
1052              (ins FCCRegs:$cc, i32imm:$simm11, IntRegs:$f, CCOp:$cond),
1053              "mov$cond $cc, $simm11, $rd", []>;
1054     def V9FMOVS_FCC
1055       : F4_3<0b110101, 0b000001, (outs FPRegs:$rd),
1056              (ins FCCRegs:$opf_cc, FPRegs:$rs2, FPRegs:$f, CCOp:$cond),
1057              "fmovs$cond $opf_cc, $rs2, $rd", []>;
1058     def V9FMOVD_FCC
1059       : F4_3<0b110101, 0b000010, (outs DFPRegs:$rd),
1060              (ins FCCRegs:$opf_cc, DFPRegs:$rs2, DFPRegs:$f, CCOp:$cond),
1061              "fmovd$cond $opf_cc, $rs2, $rd", []>;
1062     def V9FMOVQ_FCC
1063       : F4_3<0b110101, 0b000011, (outs QFPRegs:$rd),
1064              (ins FCCRegs:$opf_cc, QFPRegs:$rs2, QFPRegs:$f, CCOp:$cond),
1065              "fmovq$cond $opf_cc, $rs2, $rd", []>,
1066              Requires<[HasHardQuad]>;
1067   } // Constraints = "$f = $rd", ...
1068 } // let Predicates = [hasV9]
1069
1070
1071 // POPCrr - This does a ctpop of a 64-bit register.  As such, we have to clear
1072 // the top 32-bits before using it.  To do this clearing, we use a SRLri X,0.
1073 let rs1 = 0 in
1074   def POPCrr : F3_1<2, 0b101110,
1075                     (outs IntRegs:$dst), (ins IntRegs:$src),
1076                     "popc $src, $dst", []>, Requires<[HasV9]>;
1077 def : Pat<(ctpop i32:$src),
1078           (POPCrr (SRLri $src, 0))>;
1079
1080 // Atomic swap.
1081 let hasSideEffects =1, rd = 0, rs1 = 0b01111, rs2 = 0 in
1082   def STBAR : F3_1<2, 0b101000, (outs), (ins), "stbar", []>;
1083
1084 let Predicates = [HasV9], hasSideEffects = 1, rd = 0, rs1 = 0b01111 in
1085  def MEMBARi : F3_2<2, 0b101000, (outs), (ins simm13Op:$simm13),
1086                     "membar $simm13", []>;
1087
1088 let Constraints = "$val = $dst" in {
1089   def SWAPrr : F3_1<3, 0b001111,
1090                  (outs IntRegs:$dst), (ins MEMrr:$addr, IntRegs:$val),
1091                  "swap [$addr], $dst",
1092                  [(set i32:$dst, (atomic_swap_32 ADDRrr:$addr, i32:$val))]>;
1093   def SWAPri : F3_2<3, 0b001111,
1094                  (outs IntRegs:$dst), (ins MEMri:$addr, IntRegs:$val),
1095                  "swap [$addr], $dst",
1096                  [(set i32:$dst, (atomic_swap_32 ADDRri:$addr, i32:$val))]>;
1097 }
1098
1099 let Predicates = [HasV9], Constraints = "$swap = $rd" in
1100   def CASrr: F3_1_asi<3, 0b111100, 0b10000000,
1101                 (outs IntRegs:$rd), (ins IntRegs:$rs1, IntRegs:$rs2,
1102                                      IntRegs:$swap),
1103                  "cas [$rs1], $rs2, $rd",
1104                  [(set i32:$rd,
1105                      (atomic_cmp_swap iPTR:$rs1, i32:$rs2, i32:$swap))]>;
1106
1107 let Defs = [ICC] in {
1108 defm TADDCC   : F3_12np<"taddcc",   0b100000>;
1109 defm TSUBCC   : F3_12np<"tsubcc",   0b100001>;
1110
1111 let hasSideEffects = 1 in {
1112   defm TADDCCTV : F3_12np<"taddcctv", 0b100010>;
1113   defm TSUBCCTV : F3_12np<"tsubcctv", 0b100011>;
1114 }
1115 }
1116
1117 //===----------------------------------------------------------------------===//
1118 // Non-Instruction Patterns
1119 //===----------------------------------------------------------------------===//
1120
1121 // Small immediates.
1122 def : Pat<(i32 simm13:$val),
1123           (ORri (i32 G0), imm:$val)>;
1124 // Arbitrary immediates.
1125 def : Pat<(i32 imm:$val),
1126           (ORri (SETHIi (HI22 imm:$val)), (LO10 imm:$val))>;
1127
1128
1129 // Global addresses, constant pool entries
1130 let Predicates = [Is32Bit] in {
1131
1132 def : Pat<(SPhi tglobaladdr:$in), (SETHIi tglobaladdr:$in)>;
1133 def : Pat<(SPlo tglobaladdr:$in), (ORri (i32 G0), tglobaladdr:$in)>;
1134 def : Pat<(SPhi tconstpool:$in), (SETHIi tconstpool:$in)>;
1135 def : Pat<(SPlo tconstpool:$in), (ORri (i32 G0), tconstpool:$in)>;
1136
1137 // GlobalTLS addresses
1138 def : Pat<(SPhi tglobaltlsaddr:$in), (SETHIi tglobaltlsaddr:$in)>;
1139 def : Pat<(SPlo tglobaltlsaddr:$in), (ORri (i32 G0), tglobaltlsaddr:$in)>;
1140 def : Pat<(add (SPhi tglobaltlsaddr:$in1), (SPlo tglobaltlsaddr:$in2)),
1141           (ADDri (SETHIi tglobaltlsaddr:$in1), (tglobaltlsaddr:$in2))>;
1142 def : Pat<(xor (SPhi tglobaltlsaddr:$in1), (SPlo tglobaltlsaddr:$in2)),
1143           (XORri (SETHIi tglobaltlsaddr:$in1), (tglobaltlsaddr:$in2))>;
1144
1145 // Blockaddress
1146 def : Pat<(SPhi tblockaddress:$in), (SETHIi tblockaddress:$in)>;
1147 def : Pat<(SPlo tblockaddress:$in), (ORri (i32 G0), tblockaddress:$in)>;
1148
1149 // Add reg, lo.  This is used when taking the addr of a global/constpool entry.
1150 def : Pat<(add iPTR:$r, (SPlo tglobaladdr:$in)), (ADDri $r, tglobaladdr:$in)>;
1151 def : Pat<(add iPTR:$r, (SPlo tconstpool:$in)),  (ADDri $r, tconstpool:$in)>;
1152 def : Pat<(add iPTR:$r, (SPlo tblockaddress:$in)),
1153                         (ADDri $r, tblockaddress:$in)>;
1154 }
1155
1156 // Calls:
1157 def : Pat<(call tglobaladdr:$dst),
1158           (CALL tglobaladdr:$dst)>;
1159 def : Pat<(call texternalsym:$dst),
1160           (CALL texternalsym:$dst)>;
1161
1162 // Map integer extload's to zextloads.
1163 def : Pat<(i32 (extloadi1 ADDRrr:$src)), (LDUBrr ADDRrr:$src)>;
1164 def : Pat<(i32 (extloadi1 ADDRri:$src)), (LDUBri ADDRri:$src)>;
1165 def : Pat<(i32 (extloadi8 ADDRrr:$src)), (LDUBrr ADDRrr:$src)>;
1166 def : Pat<(i32 (extloadi8 ADDRri:$src)), (LDUBri ADDRri:$src)>;
1167 def : Pat<(i32 (extloadi16 ADDRrr:$src)), (LDUHrr ADDRrr:$src)>;
1168 def : Pat<(i32 (extloadi16 ADDRri:$src)), (LDUHri ADDRri:$src)>;
1169
1170 // zextload bool -> zextload byte
1171 def : Pat<(i32 (zextloadi1 ADDRrr:$src)), (LDUBrr ADDRrr:$src)>;
1172 def : Pat<(i32 (zextloadi1 ADDRri:$src)), (LDUBri ADDRri:$src)>;
1173
1174 // store 0, addr -> store %g0, addr
1175 def : Pat<(store (i32 0), ADDRrr:$dst), (STrr ADDRrr:$dst, (i32 G0))>;
1176 def : Pat<(store (i32 0), ADDRri:$dst), (STri ADDRri:$dst, (i32 G0))>;
1177
1178 // store bar for all atomic_fence in V8.
1179 let Predicates = [HasNoV9] in
1180   def : Pat<(atomic_fence imm, imm), (STBAR)>;
1181
1182 // atomic_load_32 addr -> load addr
1183 def : Pat<(i32 (atomic_load ADDRrr:$src)), (LDrr ADDRrr:$src)>;
1184 def : Pat<(i32 (atomic_load ADDRri:$src)), (LDri ADDRri:$src)>;
1185
1186 // atomic_store_32 val, addr -> store val, addr
1187 def : Pat<(atomic_store ADDRrr:$dst, i32:$val), (STrr ADDRrr:$dst, $val)>;
1188 def : Pat<(atomic_store ADDRri:$dst, i32:$val), (STri ADDRri:$dst, $val)>;
1189
1190
1191 include "SparcInstr64Bit.td"
1192 include "SparcInstrVIS.td"
1193 include "SparcInstrAliases.td"