1 //===-- SparcInstrInfo.td - Target Description for Sparc Target -----------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file describes the Sparc instructions in TableGen format.
12 //===----------------------------------------------------------------------===//
14 //===----------------------------------------------------------------------===//
15 // Instruction format superclass
16 //===----------------------------------------------------------------------===//
18 include "SparcInstrFormats.td"
20 //===----------------------------------------------------------------------===//
21 // Feature predicates.
22 //===----------------------------------------------------------------------===//
24 // True when generating 32-bit code.
25 def Is32Bit : Predicate<"!Subtarget->is64Bit()">;
27 // True when generating 64-bit code. This also implies HasV9.
28 def Is64Bit : Predicate<"Subtarget->is64Bit()">;
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">;
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()">;
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">;
48 // HasHardQuad - This is true when the target processor supports quad floating
49 // point instructions.
50 def HasHardQuad : Predicate<"Subtarget->hasHardQuad()">;
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()">;
58 //===----------------------------------------------------------------------===//
59 // Instruction Pattern Stuff
60 //===----------------------------------------------------------------------===//
62 def simm11 : PatLeaf<(imm), [{ return isInt<11>(N->getSExtValue()); }]>;
64 def simm13 : PatLeaf<(imm), [{ return isInt<13>(N->getSExtValue()); }]>;
66 def LO10 : SDNodeXForm<imm, [{
67 return CurDAG->getTargetConstant((unsigned)N->getZExtValue() & 1023, SDLoc(N),
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, SDLoc(N),
77 def SETHIimm : PatLeaf<(imm), [{
78 return isShiftedUInt<22, 10>(N->getZExtValue());
82 def ADDRrr : ComplexPattern<iPTR, 2, "SelectADDRrr", [], []>;
83 def ADDRri : ComplexPattern<iPTR, 2, "SelectADDRri", [frameindex], []>;
86 def SparcMEMrrAsmOperand : AsmOperandClass {
88 let ParserMethod = "parseMEMOperand";
91 def SparcMEMriAsmOperand : AsmOperandClass {
93 let ParserMethod = "parseMEMOperand";
96 def MEMrr : Operand<iPTR> {
97 let PrintMethod = "printMemOperand";
98 let MIOperandInfo = (ops ptr_rc, ptr_rc);
99 let ParserMatchClass = SparcMEMrrAsmOperand;
101 def MEMri : Operand<iPTR> {
102 let PrintMethod = "printMemOperand";
103 let MIOperandInfo = (ops ptr_rc, i32imm);
104 let ParserMatchClass = SparcMEMriAsmOperand;
107 def TLSSym : Operand<iPTR>;
109 // Branch targets have OtherVT type.
110 def brtarget : Operand<OtherVT> {
111 let EncoderMethod = "getBranchTargetOpValue";
114 def bprtarget : Operand<OtherVT> {
115 let EncoderMethod = "getBranchPredTargetOpValue";
118 def bprtarget16 : Operand<OtherVT> {
119 let EncoderMethod = "getBranchOnRegTargetOpValue";
122 def calltarget : Operand<i32> {
123 let EncoderMethod = "getCallTargetOpValue";
124 let DecoderMethod = "DecodeCall";
127 def simm13Op : Operand<i32> {
128 let DecoderMethod = "DecodeSIMM13";
131 // Operand for printing out a condition code.
132 let PrintMethod = "printCCOperand" in
133 def CCOp : Operand<i32>;
136 SDTypeProfile<0, 2, [SDTCisInt<0>, SDTCisSameAs<0, 1>]>;
138 SDTypeProfile<0, 2, [SDTCisFP<0>, SDTCisSameAs<0, 1>]>;
140 SDTypeProfile<0, 2, [SDTCisVT<0, OtherVT>, SDTCisVT<1, i32>]>;
142 SDTypeProfile<1, 3, [SDTCisSameAs<0, 1>, SDTCisSameAs<1, 2>, SDTCisVT<3, i32>]>;
144 SDTypeProfile<1, 1, [SDTCisVT<0, f32>, SDTCisFP<1>]>;
146 SDTypeProfile<1, 1, [SDTCisFP<0>, SDTCisVT<1, f32>]>;
148 SDTypeProfile<1, 1, [SDTCisVT<0, f64>, SDTCisFP<1>]>;
150 SDTypeProfile<1, 1, [SDTCisFP<0>, SDTCisVT<1, f64>]>;
153 SDTypeProfile<1, 3, [SDTCisInt<0>, SDTCisSameAs<0, 1>, SDTCisPtrTy<2>]>;
155 SDTypeProfile<1, 2, [SDTCisPtrTy<0>, SDTCisPtrTy<1>]>;
157 def SPcmpicc : SDNode<"SPISD::CMPICC", SDTSPcmpicc, [SDNPOutGlue]>;
158 def SPcmpfcc : SDNode<"SPISD::CMPFCC", SDTSPcmpfcc, [SDNPOutGlue]>;
159 def SPbricc : SDNode<"SPISD::BRICC", SDTSPbrcc, [SDNPHasChain, SDNPInGlue]>;
160 def SPbrxcc : SDNode<"SPISD::BRXCC", SDTSPbrcc, [SDNPHasChain, SDNPInGlue]>;
161 def SPbrfcc : SDNode<"SPISD::BRFCC", SDTSPbrcc, [SDNPHasChain, SDNPInGlue]>;
163 def SPhi : SDNode<"SPISD::Hi", SDTIntUnaryOp>;
164 def SPlo : SDNode<"SPISD::Lo", SDTIntUnaryOp>;
166 def SPftoi : SDNode<"SPISD::FTOI", SDTSPFTOI>;
167 def SPitof : SDNode<"SPISD::ITOF", SDTSPITOF>;
168 def SPftox : SDNode<"SPISD::FTOX", SDTSPFTOX>;
169 def SPxtof : SDNode<"SPISD::XTOF", SDTSPXTOF>;
171 def SPselecticc : SDNode<"SPISD::SELECT_ICC", SDTSPselectcc, [SDNPInGlue]>;
172 def SPselectxcc : SDNode<"SPISD::SELECT_XCC", SDTSPselectcc, [SDNPInGlue]>;
173 def SPselectfcc : SDNode<"SPISD::SELECT_FCC", SDTSPselectcc, [SDNPInGlue]>;
175 // These are target-independent nodes, but have target-specific formats.
176 def SDT_SPCallSeqStart : SDCallSeqStart<[ SDTCisVT<0, i32> ]>;
177 def SDT_SPCallSeqEnd : SDCallSeqEnd<[ SDTCisVT<0, i32>,
180 def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_SPCallSeqStart,
181 [SDNPHasChain, SDNPOutGlue]>;
182 def callseq_end : SDNode<"ISD::CALLSEQ_END", SDT_SPCallSeqEnd,
183 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
185 def SDT_SPCall : SDTypeProfile<0, -1, [SDTCisVT<0, i32>]>;
186 def call : SDNode<"SPISD::CALL", SDT_SPCall,
187 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue,
190 def SDT_SPRet : SDTypeProfile<0, 1, [SDTCisVT<0, i32>]>;
191 def retflag : SDNode<"SPISD::RET_FLAG", SDT_SPRet,
192 [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>;
194 def flushw : SDNode<"SPISD::FLUSHW", SDTNone,
195 [SDNPHasChain, SDNPSideEffect, SDNPMayStore]>;
197 def tlsadd : SDNode<"SPISD::TLS_ADD", SDTSPtlsadd>;
198 def tlsld : SDNode<"SPISD::TLS_LD", SDTSPtlsld>;
199 def tlscall : SDNode<"SPISD::TLS_CALL", SDT_SPCall,
200 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue,
203 def getPCX : Operand<iPTR> {
204 let PrintMethod = "printGetPCX";
207 //===----------------------------------------------------------------------===//
208 // SPARC Flag Conditions
209 //===----------------------------------------------------------------------===//
211 // Note that these values must be kept in sync with the CCOp::CondCode enum
213 class ICC_VAL<int N> : PatLeaf<(i32 N)>;
214 def ICC_NE : ICC_VAL< 9>; // Not Equal
215 def ICC_E : ICC_VAL< 1>; // Equal
216 def ICC_G : ICC_VAL<10>; // Greater
217 def ICC_LE : ICC_VAL< 2>; // Less or Equal
218 def ICC_GE : ICC_VAL<11>; // Greater or Equal
219 def ICC_L : ICC_VAL< 3>; // Less
220 def ICC_GU : ICC_VAL<12>; // Greater Unsigned
221 def ICC_LEU : ICC_VAL< 4>; // Less or Equal Unsigned
222 def ICC_CC : ICC_VAL<13>; // Carry Clear/Great or Equal Unsigned
223 def ICC_CS : ICC_VAL< 5>; // Carry Set/Less Unsigned
224 def ICC_POS : ICC_VAL<14>; // Positive
225 def ICC_NEG : ICC_VAL< 6>; // Negative
226 def ICC_VC : ICC_VAL<15>; // Overflow Clear
227 def ICC_VS : ICC_VAL< 7>; // Overflow Set
229 class FCC_VAL<int N> : PatLeaf<(i32 N)>;
230 def FCC_U : FCC_VAL<23>; // Unordered
231 def FCC_G : FCC_VAL<22>; // Greater
232 def FCC_UG : FCC_VAL<21>; // Unordered or Greater
233 def FCC_L : FCC_VAL<20>; // Less
234 def FCC_UL : FCC_VAL<19>; // Unordered or Less
235 def FCC_LG : FCC_VAL<18>; // Less or Greater
236 def FCC_NE : FCC_VAL<17>; // Not Equal
237 def FCC_E : FCC_VAL<25>; // Equal
238 def FCC_UE : FCC_VAL<24>; // Unordered or Equal
239 def FCC_GE : FCC_VAL<25>; // Greater or Equal
240 def FCC_UGE : FCC_VAL<26>; // Unordered or Greater or Equal
241 def FCC_LE : FCC_VAL<27>; // Less or Equal
242 def FCC_ULE : FCC_VAL<28>; // Unordered or Less or Equal
243 def FCC_O : FCC_VAL<29>; // Ordered
245 //===----------------------------------------------------------------------===//
246 // Instruction Class Templates
247 //===----------------------------------------------------------------------===//
249 /// F3_12 multiclass - Define a normal F3_1/F3_2 pattern in one shot.
250 multiclass F3_12<string OpcStr, bits<6> Op3Val, SDNode OpNode,
251 RegisterClass RC, ValueType Ty, Operand immOp> {
252 def rr : F3_1<2, Op3Val,
253 (outs RC:$rd), (ins RC:$rs1, RC:$rs2),
254 !strconcat(OpcStr, " $rs1, $rs2, $rd"),
255 [(set Ty:$rd, (OpNode Ty:$rs1, Ty:$rs2))]>;
256 def ri : F3_2<2, Op3Val,
257 (outs RC:$rd), (ins RC:$rs1, immOp:$simm13),
258 !strconcat(OpcStr, " $rs1, $simm13, $rd"),
259 [(set Ty:$rd, (OpNode Ty:$rs1, (Ty simm13:$simm13)))]>;
262 /// F3_12np multiclass - Define a normal F3_1/F3_2 pattern in one shot, with no
264 multiclass F3_12np<string OpcStr, bits<6> Op3Val> {
265 def rr : F3_1<2, Op3Val,
266 (outs IntRegs:$rd), (ins IntRegs:$rs1, IntRegs:$rs2),
267 !strconcat(OpcStr, " $rs1, $rs2, $rd"), []>;
268 def ri : F3_2<2, Op3Val,
269 (outs IntRegs:$rd), (ins IntRegs:$rs1, simm13Op:$simm13),
270 !strconcat(OpcStr, " $rs1, $simm13, $rd"), []>;
273 // Load multiclass - Define both Reg+Reg/Reg+Imm patterns in one shot.
274 multiclass Load<string OpcStr, bits<6> Op3Val, SDPatternOperator OpNode,
275 RegisterClass RC, ValueType Ty> {
276 def rr : F3_1<3, Op3Val,
277 (outs RC:$dst), (ins MEMrr:$addr),
278 !strconcat(OpcStr, " [$addr], $dst"),
279 [(set Ty:$dst, (OpNode ADDRrr:$addr))]>;
280 def ri : F3_2<3, Op3Val,
281 (outs RC:$dst), (ins MEMri:$addr),
282 !strconcat(OpcStr, " [$addr], $dst"),
283 [(set Ty:$dst, (OpNode ADDRri:$addr))]>;
286 // LoadA multiclass - As above, but also define alternate address space variant
287 multiclass LoadA<string OpcStr, bits<6> Op3Val, bits<6> LoadAOp3Val,
288 SDPatternOperator OpNode, RegisterClass RC, ValueType Ty> :
289 Load<OpcStr, Op3Val, OpNode, RC, Ty> {
290 // TODO: The LD*Arr instructions are currently asm only; hooking up
291 // CodeGen's address spaces to use these is a future task.
292 def Arr : F3_1_asi<3, LoadAOp3Val, (outs RC:$dst), (ins MEMrr:$addr, i8imm:$asi),
293 !strconcat(OpcStr, "a [$addr] $asi, $dst"),
297 // Store multiclass - Define both Reg+Reg/Reg+Imm patterns in one shot.
298 multiclass Store<string OpcStr, bits<6> Op3Val, SDPatternOperator OpNode,
299 RegisterClass RC, ValueType Ty> {
300 def rr : F3_1<3, Op3Val,
301 (outs), (ins MEMrr:$addr, RC:$rd),
302 !strconcat(OpcStr, " $rd, [$addr]"),
303 [(OpNode Ty:$rd, ADDRrr:$addr)]>;
304 def ri : F3_2<3, Op3Val,
305 (outs), (ins MEMri:$addr, RC:$rd),
306 !strconcat(OpcStr, " $rd, [$addr]"),
307 [(OpNode Ty:$rd, ADDRri:$addr)]>;
310 multiclass StoreA<string OpcStr, bits<6> Op3Val, bits<6> StoreAOp3Val,
311 SDPatternOperator OpNode, RegisterClass RC, ValueType Ty> :
312 Store<OpcStr, Op3Val, OpNode, RC, Ty> {
313 // TODO: The ST*Arr instructions are currently asm only; hooking up
314 // CodeGen's address spaces to use these is a future task.
315 def Arr : F3_1_asi<3, StoreAOp3Val, (outs), (ins MEMrr:$addr, RC:$rd, i8imm:$asi),
316 !strconcat(OpcStr, "a $rd, [$addr] $asi"),
320 //===----------------------------------------------------------------------===//
322 //===----------------------------------------------------------------------===//
324 // Pseudo instructions.
325 class Pseudo<dag outs, dag ins, string asmstr, list<dag> pattern>
326 : InstSP<outs, ins, asmstr, pattern> {
327 let isCodeGenOnly = 1;
333 def GETPCX : Pseudo<(outs getPCX:$getpcseq), (ins), "$getpcseq", [] >;
336 let Defs = [O6], Uses = [O6] in {
337 def ADJCALLSTACKDOWN : Pseudo<(outs), (ins i32imm:$amt),
338 "!ADJCALLSTACKDOWN $amt",
339 [(callseq_start timm:$amt)]>;
340 def ADJCALLSTACKUP : Pseudo<(outs), (ins i32imm:$amt1, i32imm:$amt2),
341 "!ADJCALLSTACKUP $amt1",
342 [(callseq_end timm:$amt1, timm:$amt2)]>;
345 let hasSideEffects = 1, mayStore = 1 in {
346 let rd = 0, rs1 = 0, rs2 = 0 in
347 def FLUSHW : F3_1<0b10, 0b101011, (outs), (ins),
349 [(flushw)]>, Requires<[HasV9]>;
350 let rd = 0, rs1 = 1, simm13 = 3 in
351 def TA3 : F3_2<0b10, 0b111010, (outs), (ins),
356 let isBarrier = 1, isTerminator = 1, rd = 0b01000, rs1 = 0, simm13 = 5 in
357 def TA5 : F3_2<0b10, 0b111010, (outs), (ins), "ta 5", [(trap)]>;
360 def UNIMP : F2_1<0b000, (outs), (ins i32imm:$imm22),
363 // SELECT_CC_* - Used to implement the SELECT_CC DAG operation. Expanded after
364 // instruction selection into a branch sequence. This has to handle all
365 // permutations of selection between i32/f32/f64 on ICC and FCC.
366 // Expanded after instruction selection.
367 let Uses = [ICC], usesCustomInserter = 1 in {
368 def SELECT_CC_Int_ICC
369 : Pseudo<(outs IntRegs:$dst), (ins IntRegs:$T, IntRegs:$F, i32imm:$Cond),
370 "; SELECT_CC_Int_ICC PSEUDO!",
371 [(set i32:$dst, (SPselecticc i32:$T, i32:$F, imm:$Cond))]>;
373 : Pseudo<(outs FPRegs:$dst), (ins FPRegs:$T, FPRegs:$F, i32imm:$Cond),
374 "; SELECT_CC_FP_ICC PSEUDO!",
375 [(set f32:$dst, (SPselecticc f32:$T, f32:$F, imm:$Cond))]>;
377 def SELECT_CC_DFP_ICC
378 : Pseudo<(outs DFPRegs:$dst), (ins DFPRegs:$T, DFPRegs:$F, i32imm:$Cond),
379 "; SELECT_CC_DFP_ICC PSEUDO!",
380 [(set f64:$dst, (SPselecticc f64:$T, f64:$F, imm:$Cond))]>;
382 def SELECT_CC_QFP_ICC
383 : Pseudo<(outs QFPRegs:$dst), (ins QFPRegs:$T, QFPRegs:$F, i32imm:$Cond),
384 "; SELECT_CC_QFP_ICC PSEUDO!",
385 [(set f128:$dst, (SPselecticc f128:$T, f128:$F, imm:$Cond))]>;
388 let usesCustomInserter = 1, Uses = [FCC0] in {
390 def SELECT_CC_Int_FCC
391 : Pseudo<(outs IntRegs:$dst), (ins IntRegs:$T, IntRegs:$F, i32imm:$Cond),
392 "; SELECT_CC_Int_FCC PSEUDO!",
393 [(set i32:$dst, (SPselectfcc i32:$T, i32:$F, imm:$Cond))]>;
396 : Pseudo<(outs FPRegs:$dst), (ins FPRegs:$T, FPRegs:$F, i32imm:$Cond),
397 "; SELECT_CC_FP_FCC PSEUDO!",
398 [(set f32:$dst, (SPselectfcc f32:$T, f32:$F, imm:$Cond))]>;
399 def SELECT_CC_DFP_FCC
400 : Pseudo<(outs DFPRegs:$dst), (ins DFPRegs:$T, DFPRegs:$F, i32imm:$Cond),
401 "; SELECT_CC_DFP_FCC PSEUDO!",
402 [(set f64:$dst, (SPselectfcc f64:$T, f64:$F, imm:$Cond))]>;
403 def SELECT_CC_QFP_FCC
404 : Pseudo<(outs QFPRegs:$dst), (ins QFPRegs:$T, QFPRegs:$F, i32imm:$Cond),
405 "; SELECT_CC_QFP_FCC PSEUDO!",
406 [(set f128:$dst, (SPselectfcc f128:$T, f128:$F, imm:$Cond))]>;
410 let isTerminator = 1, hasDelaySlot = 1, isBarrier = 1,
411 DecoderMethod = "DecodeJMPL" in {
412 def JMPLrr: F3_1<2, 0b111000, (outs IntRegs:$dst), (ins MEMrr:$addr),
413 "jmpl $addr, $dst", []>;
414 def JMPLri: F3_2<2, 0b111000, (outs IntRegs:$dst), (ins MEMri:$addr),
415 "jmpl $addr, $dst", []>;
418 // Section A.3 - Synthetic Instructions, p. 85
419 // special cases of JMPL:
420 let isReturn = 1, isTerminator = 1, hasDelaySlot = 1, isBarrier = 1,
421 isCodeGenOnly = 1 in {
422 let rd = 0, rs1 = 15 in
423 def RETL: F3_2<2, 0b111000, (outs), (ins i32imm:$val),
424 "jmp %o7+$val", [(retflag simm13:$val)]>;
426 let rd = 0, rs1 = 31 in
427 def RET: F3_2<2, 0b111000, (outs), (ins i32imm:$val),
431 let isReturn = 1, isTerminator = 1, hasDelaySlot = 1,
432 isBarrier = 1, rd = 0, DecoderMethod = "DecodeReturn" in {
433 def RETTrr : F3_1<2, 0b111001, (outs), (ins MEMrr:$addr),
435 def RETTri : F3_2<2, 0b111001, (outs), (ins MEMri:$addr),
439 // Section B.1 - Load Integer Instructions, p. 90
440 let DecoderMethod = "DecodeLoadInt" in {
441 defm LDSB : LoadA<"ldsb", 0b001001, 0b011001, sextloadi8, IntRegs, i32>;
442 defm LDSH : LoadA<"ldsh", 0b001010, 0b011010, sextloadi16, IntRegs, i32>;
443 defm LDUB : LoadA<"ldub", 0b000001, 0b010001, zextloadi8, IntRegs, i32>;
444 defm LDUH : LoadA<"lduh", 0b000010, 0b010010, zextloadi16, IntRegs, i32>;
445 defm LD : LoadA<"ld", 0b000000, 0b010000, load, IntRegs, i32>;
448 // Section B.2 - Load Floating-point Instructions, p. 92
449 let DecoderMethod = "DecodeLoadFP" in
450 defm LDF : Load<"ld", 0b100000, load, FPRegs, f32>;
451 let DecoderMethod = "DecodeLoadDFP" in
452 defm LDDF : Load<"ldd", 0b100011, load, DFPRegs, f64>;
453 let DecoderMethod = "DecodeLoadQFP" in
454 defm LDQF : Load<"ldq", 0b100010, load, QFPRegs, f128>,
455 Requires<[HasV9, HasHardQuad]>;
457 // Section B.4 - Store Integer Instructions, p. 95
458 let DecoderMethod = "DecodeStoreInt" in {
459 defm STB : StoreA<"stb", 0b000101, 0b010101, truncstorei8, IntRegs, i32>;
460 defm STH : StoreA<"sth", 0b000110, 0b010110, truncstorei16, IntRegs, i32>;
461 defm ST : StoreA<"st", 0b000100, 0b010100, store, IntRegs, i32>;
464 // Section B.5 - Store Floating-point Instructions, p. 97
465 let DecoderMethod = "DecodeStoreFP" in
466 defm STF : Store<"st", 0b100100, store, FPRegs, f32>;
467 let DecoderMethod = "DecodeStoreDFP" in
468 defm STDF : Store<"std", 0b100111, store, DFPRegs, f64>;
469 let DecoderMethod = "DecodeStoreQFP" in
470 defm STQF : Store<"stq", 0b100110, store, QFPRegs, f128>,
471 Requires<[HasV9, HasHardQuad]>;
473 // Section B.9 - SETHI Instruction, p. 104
474 def SETHIi: F2_1<0b100,
475 (outs IntRegs:$rd), (ins i32imm:$imm22),
477 [(set i32:$rd, SETHIimm:$imm22)]>;
479 // Section B.10 - NOP Instruction, p. 105
480 // (It's a special case of SETHI)
481 let rd = 0, imm22 = 0 in
482 def NOP : F2_1<0b100, (outs), (ins), "nop", []>;
484 // Section B.11 - Logical Instructions, p. 106
485 defm AND : F3_12<"and", 0b000001, and, IntRegs, i32, simm13Op>;
487 def ANDNrr : F3_1<2, 0b000101,
488 (outs IntRegs:$rd), (ins IntRegs:$rs1, IntRegs:$rs2),
489 "andn $rs1, $rs2, $rd",
490 [(set i32:$rd, (and i32:$rs1, (not i32:$rs2)))]>;
491 def ANDNri : F3_2<2, 0b000101,
492 (outs IntRegs:$rd), (ins IntRegs:$rs1, simm13Op:$simm13),
493 "andn $rs1, $simm13, $rd", []>;
495 defm OR : F3_12<"or", 0b000010, or, IntRegs, i32, simm13Op>;
497 def ORNrr : F3_1<2, 0b000110,
498 (outs IntRegs:$rd), (ins IntRegs:$rs1, IntRegs:$rs2),
499 "orn $rs1, $rs2, $rd",
500 [(set i32:$rd, (or i32:$rs1, (not i32:$rs2)))]>;
501 def ORNri : F3_2<2, 0b000110,
502 (outs IntRegs:$rd), (ins IntRegs:$rs1, simm13Op:$simm13),
503 "orn $rs1, $simm13, $rd", []>;
504 defm XOR : F3_12<"xor", 0b000011, xor, IntRegs, i32, simm13Op>;
506 def XNORrr : F3_1<2, 0b000111,
507 (outs IntRegs:$rd), (ins IntRegs:$rs1, IntRegs:$rs2),
508 "xnor $rs1, $rs2, $rd",
509 [(set i32:$rd, (not (xor i32:$rs1, i32:$rs2)))]>;
510 def XNORri : F3_2<2, 0b000111,
511 (outs IntRegs:$rd), (ins IntRegs:$rs1, simm13Op:$simm13),
512 "xnor $rs1, $simm13, $rd", []>;
514 let Defs = [ICC] in {
515 defm ANDCC : F3_12np<"andcc", 0b010001>;
516 defm ANDNCC : F3_12np<"andncc", 0b010101>;
517 defm ORCC : F3_12np<"orcc", 0b010010>;
518 defm ORNCC : F3_12np<"orncc", 0b010110>;
519 defm XORCC : F3_12np<"xorcc", 0b010011>;
520 defm XNORCC : F3_12np<"xnorcc", 0b010111>;
523 // Section B.12 - Shift Instructions, p. 107
524 defm SLL : F3_12<"sll", 0b100101, shl, IntRegs, i32, simm13Op>;
525 defm SRL : F3_12<"srl", 0b100110, srl, IntRegs, i32, simm13Op>;
526 defm SRA : F3_12<"sra", 0b100111, sra, IntRegs, i32, simm13Op>;
528 // Section B.13 - Add Instructions, p. 108
529 defm ADD : F3_12<"add", 0b000000, add, IntRegs, i32, simm13Op>;
531 // "LEA" forms of add (patterns to make tblgen happy)
532 let Predicates = [Is32Bit], isCodeGenOnly = 1 in
533 def LEA_ADDri : F3_2<2, 0b000000,
534 (outs IntRegs:$dst), (ins MEMri:$addr),
535 "add ${addr:arith}, $dst",
536 [(set iPTR:$dst, ADDRri:$addr)]>;
539 defm ADDCC : F3_12<"addcc", 0b010000, addc, IntRegs, i32, simm13Op>;
542 defm ADDC : F3_12np<"addx", 0b001000>;
544 let Uses = [ICC], Defs = [ICC] in
545 defm ADDE : F3_12<"addxcc", 0b011000, adde, IntRegs, i32, simm13Op>;
547 // Section B.15 - Subtract Instructions, p. 110
548 defm SUB : F3_12 <"sub" , 0b000100, sub, IntRegs, i32, simm13Op>;
549 let Uses = [ICC], Defs = [ICC] in
550 defm SUBE : F3_12 <"subxcc" , 0b011100, sube, IntRegs, i32, simm13Op>;
553 defm SUBCC : F3_12 <"subcc", 0b010100, subc, IntRegs, i32, simm13Op>;
556 defm SUBC : F3_12np <"subx", 0b001100>;
558 let Defs = [ICC], rd = 0 in {
559 def CMPrr : F3_1<2, 0b010100,
560 (outs), (ins IntRegs:$rs1, IntRegs:$rs2),
562 [(SPcmpicc i32:$rs1, i32:$rs2)]>;
563 def CMPri : F3_2<2, 0b010100,
564 (outs), (ins IntRegs:$rs1, simm13Op:$simm13),
566 [(SPcmpicc i32:$rs1, (i32 simm13:$simm13))]>;
569 // Section B.18 - Multiply Instructions, p. 113
571 defm UMUL : F3_12np<"umul", 0b001010>;
572 defm SMUL : F3_12 <"smul", 0b001011, mul, IntRegs, i32, simm13Op>;
575 let Defs = [Y, ICC] in {
576 defm UMULCC : F3_12np<"umulcc", 0b011010>;
577 defm SMULCC : F3_12np<"smulcc", 0b011011>;
580 // Section B.19 - Divide Instructions, p. 115
582 defm UDIV : F3_12np<"udiv", 0b001110>;
583 defm SDIV : F3_12np<"sdiv", 0b001111>;
586 let Defs = [Y, ICC] in {
587 defm UDIVCC : F3_12np<"udivcc", 0b011110>;
588 defm SDIVCC : F3_12np<"sdivcc", 0b011111>;
591 // Section B.20 - SAVE and RESTORE, p. 117
592 defm SAVE : F3_12np<"save" , 0b111100>;
593 defm RESTORE : F3_12np<"restore", 0b111101>;
595 // Section B.21 - Branch on Integer Condition Codes Instructions, p. 119
597 // unconditional branch class.
598 class BranchAlways<dag ins, string asmstr, list<dag> pattern>
599 : F2_2<0b010, 0, (outs), ins, asmstr, pattern> {
601 let isTerminator = 1;
602 let hasDelaySlot = 1;
607 def BA : BranchAlways<(ins brtarget:$imm22), "ba $imm22", [(br bb:$imm22)]>;
610 let isBranch = 1, isTerminator = 1, hasDelaySlot = 1 in {
612 // conditional branch class:
613 class BranchSP<dag ins, string asmstr, list<dag> pattern>
614 : F2_2<0b010, 0, (outs), ins, asmstr, pattern>;
616 // conditional branch with annul class:
617 class BranchSPA<dag ins, string asmstr, list<dag> pattern>
618 : F2_2<0b010, 1, (outs), ins, asmstr, pattern>;
620 // Conditional branch class on %icc|%xcc with predication:
621 multiclass IPredBranch<string regstr, list<dag> CCPattern> {
622 def CC : F2_3<0b001, 0, 1, (outs), (ins bprtarget:$imm19, CCOp:$cond),
623 !strconcat("b$cond ", !strconcat(regstr, ", $imm19")),
625 def CCA : F2_3<0b001, 1, 1, (outs), (ins bprtarget:$imm19, CCOp:$cond),
626 !strconcat("b$cond,a ", !strconcat(regstr, ", $imm19")),
628 def CCNT : F2_3<0b001, 0, 0, (outs), (ins bprtarget:$imm19, CCOp:$cond),
629 !strconcat("b$cond,pn ", !strconcat(regstr, ", $imm19")),
631 def CCANT : F2_3<0b001, 1, 0, (outs), (ins bprtarget:$imm19, CCOp:$cond),
632 !strconcat("b$cond,a,pn ", !strconcat(regstr, ", $imm19")),
636 } // let isBranch = 1, isTerminator = 1, hasDelaySlot = 1
639 // Indirect branch instructions.
640 let isTerminator = 1, isBarrier = 1, hasDelaySlot = 1, isBranch =1,
641 isIndirectBranch = 1, rd = 0, isCodeGenOnly = 1 in {
642 def BINDrr : F3_1<2, 0b111000,
643 (outs), (ins MEMrr:$ptr),
645 [(brind ADDRrr:$ptr)]>;
646 def BINDri : F3_2<2, 0b111000,
647 (outs), (ins MEMri:$ptr),
649 [(brind ADDRri:$ptr)]>;
652 let Uses = [ICC] in {
653 def BCOND : BranchSP<(ins brtarget:$imm22, CCOp:$cond),
655 [(SPbricc bb:$imm22, imm:$cond)]>;
656 def BCONDA : BranchSPA<(ins brtarget:$imm22, CCOp:$cond),
657 "b$cond,a $imm22", []>;
659 let Predicates = [HasV9], cc = 0b00 in
660 defm BPI : IPredBranch<"%icc", []>;
663 // Section B.22 - Branch on Floating-point Condition Codes Instructions, p. 121
665 let isBranch = 1, isTerminator = 1, hasDelaySlot = 1 in {
667 // floating-point conditional branch class:
668 class FPBranchSP<dag ins, string asmstr, list<dag> pattern>
669 : F2_2<0b110, 0, (outs), ins, asmstr, pattern>;
671 // floating-point conditional branch with annul class:
672 class FPBranchSPA<dag ins, string asmstr, list<dag> pattern>
673 : F2_2<0b110, 1, (outs), ins, asmstr, pattern>;
675 // Conditional branch class on %fcc0-%fcc3 with predication:
676 multiclass FPredBranch {
677 def CC : F2_3<0b101, 0, 1, (outs), (ins bprtarget:$imm19, CCOp:$cond,
679 "fb$cond $cc, $imm19", []>;
680 def CCA : F2_3<0b101, 1, 1, (outs), (ins bprtarget:$imm19, CCOp:$cond,
682 "fb$cond,a $cc, $imm19", []>;
683 def CCNT : F2_3<0b101, 0, 0, (outs), (ins bprtarget:$imm19, CCOp:$cond,
685 "fb$cond,pn $cc, $imm19", []>;
686 def CCANT : F2_3<0b101, 1, 0, (outs), (ins bprtarget:$imm19, CCOp:$cond,
688 "fb$cond,a,pn $cc, $imm19", []>;
690 } // let isBranch = 1, isTerminator = 1, hasDelaySlot = 1
692 let Uses = [FCC0] in {
693 def FBCOND : FPBranchSP<(ins brtarget:$imm22, CCOp:$cond),
695 [(SPbrfcc bb:$imm22, imm:$cond)]>;
696 def FBCONDA : FPBranchSPA<(ins brtarget:$imm22, CCOp:$cond),
697 "fb$cond,a $imm22", []>;
700 let Predicates = [HasV9] in
701 defm BPF : FPredBranch;
704 // Section B.24 - Call and Link Instruction, p. 125
705 // This is the only Format 1 instruction
707 hasDelaySlot = 1, isCall = 1 in {
708 def CALL : InstSP<(outs), (ins calltarget:$disp, variable_ops),
712 let Inst{29-0} = disp;
715 // indirect calls: special cases of JMPL.
716 let isCodeGenOnly = 1, rd = 15 in {
717 def CALLrr : F3_1<2, 0b111000,
718 (outs), (ins MEMrr:$ptr, variable_ops),
720 [(call ADDRrr:$ptr)]>;
721 def CALLri : F3_2<2, 0b111000,
722 (outs), (ins MEMri:$ptr, variable_ops),
724 [(call ADDRri:$ptr)]>;
728 // Section B.28 - Read State Register Instructions
730 def RDASR : F3_1<2, 0b101000,
731 (outs IntRegs:$rd), (ins ASRRegs:$rs1),
734 // PSR, WIM, and TBR don't exist on the SparcV9, only the V8.
735 let Predicates = [HasNoV9] in {
736 let rs2 = 0, rs1 = 0, Uses=[PSR] in
737 def RDPSR : F3_1<2, 0b101001,
738 (outs IntRegs:$rd), (ins),
741 let rs2 = 0, rs1 = 0, Uses=[WIM] in
742 def RDWIM : F3_1<2, 0b101010,
743 (outs IntRegs:$rd), (ins),
746 let rs2 = 0, rs1 = 0, Uses=[TBR] in
747 def RDTBR : F3_1<2, 0b101011,
748 (outs IntRegs:$rd), (ins),
752 // Section B.29 - Write State Register Instructions
753 def WRASRrr : F3_1<2, 0b110000,
754 (outs ASRRegs:$rd), (ins IntRegs:$rs1, IntRegs:$rs2),
755 "wr $rs1, $rs2, $rd", []>;
756 def WRASRri : F3_2<2, 0b110000,
757 (outs ASRRegs:$rd), (ins IntRegs:$rs1, simm13Op:$simm13),
758 "wr $rs1, $simm13, $rd", []>;
760 // PSR, WIM, and TBR don't exist on the SparcV9, only the V8.
761 let Predicates = [HasNoV9] in {
762 let Defs = [PSR], rd=0 in {
763 def WRPSRrr : F3_1<2, 0b110001,
764 (outs), (ins IntRegs:$rs1, IntRegs:$rs2),
765 "wr $rs1, $rs2, %psr", []>;
766 def WRPSRri : F3_2<2, 0b110001,
767 (outs), (ins IntRegs:$rs1, simm13Op:$simm13),
768 "wr $rs1, $simm13, %psr", []>;
771 let Defs = [WIM], rd=0 in {
772 def WRWIMrr : F3_1<2, 0b110010,
773 (outs), (ins IntRegs:$rs1, IntRegs:$rs2),
774 "wr $rs1, $rs2, %wim", []>;
775 def WRWIMri : F3_2<2, 0b110010,
776 (outs), (ins IntRegs:$rs1, simm13Op:$simm13),
777 "wr $rs1, $simm13, %wim", []>;
780 let Defs = [TBR], rd=0 in {
781 def WRTBRrr : F3_1<2, 0b110011,
782 (outs), (ins IntRegs:$rs1, IntRegs:$rs2),
783 "wr $rs1, $rs2, %tbr", []>;
784 def WRTBRri : F3_2<2, 0b110011,
785 (outs), (ins IntRegs:$rs1, simm13Op:$simm13),
786 "wr $rs1, $simm13, %tbr", []>;
790 // Convert Integer to Floating-point Instructions, p. 141
791 def FITOS : F3_3u<2, 0b110100, 0b011000100,
792 (outs FPRegs:$rd), (ins FPRegs:$rs2),
794 [(set FPRegs:$rd, (SPitof FPRegs:$rs2))]>;
795 def FITOD : F3_3u<2, 0b110100, 0b011001000,
796 (outs DFPRegs:$rd), (ins FPRegs:$rs2),
798 [(set DFPRegs:$rd, (SPitof FPRegs:$rs2))]>;
799 def FITOQ : F3_3u<2, 0b110100, 0b011001100,
800 (outs QFPRegs:$rd), (ins FPRegs:$rs2),
802 [(set QFPRegs:$rd, (SPitof FPRegs:$rs2))]>,
803 Requires<[HasHardQuad]>;
805 // Convert Floating-point to Integer Instructions, p. 142
806 def FSTOI : F3_3u<2, 0b110100, 0b011010001,
807 (outs FPRegs:$rd), (ins FPRegs:$rs2),
809 [(set FPRegs:$rd, (SPftoi FPRegs:$rs2))]>;
810 def FDTOI : F3_3u<2, 0b110100, 0b011010010,
811 (outs FPRegs:$rd), (ins DFPRegs:$rs2),
813 [(set FPRegs:$rd, (SPftoi DFPRegs:$rs2))]>;
814 def FQTOI : F3_3u<2, 0b110100, 0b011010011,
815 (outs FPRegs:$rd), (ins QFPRegs:$rs2),
817 [(set FPRegs:$rd, (SPftoi QFPRegs:$rs2))]>,
818 Requires<[HasHardQuad]>;
820 // Convert between Floating-point Formats Instructions, p. 143
821 def FSTOD : F3_3u<2, 0b110100, 0b011001001,
822 (outs DFPRegs:$rd), (ins FPRegs:$rs2),
824 [(set f64:$rd, (fextend f32:$rs2))]>;
825 def FSTOQ : F3_3u<2, 0b110100, 0b011001101,
826 (outs QFPRegs:$rd), (ins FPRegs:$rs2),
828 [(set f128:$rd, (fextend f32:$rs2))]>,
829 Requires<[HasHardQuad]>;
830 def FDTOS : F3_3u<2, 0b110100, 0b011000110,
831 (outs FPRegs:$rd), (ins DFPRegs:$rs2),
833 [(set f32:$rd, (fround f64:$rs2))]>;
834 def FDTOQ : F3_3u<2, 0b110100, 0b011001110,
835 (outs QFPRegs:$rd), (ins DFPRegs:$rs2),
837 [(set f128:$rd, (fextend f64:$rs2))]>,
838 Requires<[HasHardQuad]>;
839 def FQTOS : F3_3u<2, 0b110100, 0b011000111,
840 (outs FPRegs:$rd), (ins QFPRegs:$rs2),
842 [(set f32:$rd, (fround f128:$rs2))]>,
843 Requires<[HasHardQuad]>;
844 def FQTOD : F3_3u<2, 0b110100, 0b011001011,
845 (outs DFPRegs:$rd), (ins QFPRegs:$rs2),
847 [(set f64:$rd, (fround f128:$rs2))]>,
848 Requires<[HasHardQuad]>;
850 // Floating-point Move Instructions, p. 144
851 def FMOVS : F3_3u<2, 0b110100, 0b000000001,
852 (outs FPRegs:$rd), (ins FPRegs:$rs2),
853 "fmovs $rs2, $rd", []>;
854 def FNEGS : F3_3u<2, 0b110100, 0b000000101,
855 (outs FPRegs:$rd), (ins FPRegs:$rs2),
857 [(set f32:$rd, (fneg f32:$rs2))]>;
858 def FABSS : F3_3u<2, 0b110100, 0b000001001,
859 (outs FPRegs:$rd), (ins FPRegs:$rs2),
861 [(set f32:$rd, (fabs f32:$rs2))]>;
864 // Floating-point Square Root Instructions, p.145
865 def FSQRTS : F3_3u<2, 0b110100, 0b000101001,
866 (outs FPRegs:$rd), (ins FPRegs:$rs2),
868 [(set f32:$rd, (fsqrt f32:$rs2))]>;
869 def FSQRTD : F3_3u<2, 0b110100, 0b000101010,
870 (outs DFPRegs:$rd), (ins DFPRegs:$rs2),
872 [(set f64:$rd, (fsqrt f64:$rs2))]>;
873 def FSQRTQ : F3_3u<2, 0b110100, 0b000101011,
874 (outs QFPRegs:$rd), (ins QFPRegs:$rs2),
876 [(set f128:$rd, (fsqrt f128:$rs2))]>,
877 Requires<[HasHardQuad]>;
881 // Floating-point Add and Subtract Instructions, p. 146
882 def FADDS : F3_3<2, 0b110100, 0b001000001,
883 (outs FPRegs:$rd), (ins FPRegs:$rs1, FPRegs:$rs2),
884 "fadds $rs1, $rs2, $rd",
885 [(set f32:$rd, (fadd f32:$rs1, f32:$rs2))]>;
886 def FADDD : F3_3<2, 0b110100, 0b001000010,
887 (outs DFPRegs:$rd), (ins DFPRegs:$rs1, DFPRegs:$rs2),
888 "faddd $rs1, $rs2, $rd",
889 [(set f64:$rd, (fadd f64:$rs1, f64:$rs2))]>;
890 def FADDQ : F3_3<2, 0b110100, 0b001000011,
891 (outs QFPRegs:$rd), (ins QFPRegs:$rs1, QFPRegs:$rs2),
892 "faddq $rs1, $rs2, $rd",
893 [(set f128:$rd, (fadd f128:$rs1, f128:$rs2))]>,
894 Requires<[HasHardQuad]>;
896 def FSUBS : F3_3<2, 0b110100, 0b001000101,
897 (outs FPRegs:$rd), (ins FPRegs:$rs1, FPRegs:$rs2),
898 "fsubs $rs1, $rs2, $rd",
899 [(set f32:$rd, (fsub f32:$rs1, f32:$rs2))]>;
900 def FSUBD : F3_3<2, 0b110100, 0b001000110,
901 (outs DFPRegs:$rd), (ins DFPRegs:$rs1, DFPRegs:$rs2),
902 "fsubd $rs1, $rs2, $rd",
903 [(set f64:$rd, (fsub f64:$rs1, f64:$rs2))]>;
904 def FSUBQ : F3_3<2, 0b110100, 0b001000111,
905 (outs QFPRegs:$rd), (ins QFPRegs:$rs1, QFPRegs:$rs2),
906 "fsubq $rs1, $rs2, $rd",
907 [(set f128:$rd, (fsub f128:$rs1, f128:$rs2))]>,
908 Requires<[HasHardQuad]>;
911 // Floating-point Multiply and Divide Instructions, p. 147
912 def FMULS : F3_3<2, 0b110100, 0b001001001,
913 (outs FPRegs:$rd), (ins FPRegs:$rs1, FPRegs:$rs2),
914 "fmuls $rs1, $rs2, $rd",
915 [(set f32:$rd, (fmul f32:$rs1, f32:$rs2))]>;
916 def FMULD : F3_3<2, 0b110100, 0b001001010,
917 (outs DFPRegs:$rd), (ins DFPRegs:$rs1, DFPRegs:$rs2),
918 "fmuld $rs1, $rs2, $rd",
919 [(set f64:$rd, (fmul f64:$rs1, f64:$rs2))]>;
920 def FMULQ : F3_3<2, 0b110100, 0b001001011,
921 (outs QFPRegs:$rd), (ins QFPRegs:$rs1, QFPRegs:$rs2),
922 "fmulq $rs1, $rs2, $rd",
923 [(set f128:$rd, (fmul f128:$rs1, f128:$rs2))]>,
924 Requires<[HasHardQuad]>;
926 def FSMULD : F3_3<2, 0b110100, 0b001101001,
927 (outs DFPRegs:$rd), (ins FPRegs:$rs1, FPRegs:$rs2),
928 "fsmuld $rs1, $rs2, $rd",
929 [(set f64:$rd, (fmul (fextend f32:$rs1),
930 (fextend f32:$rs2)))]>;
931 def FDMULQ : F3_3<2, 0b110100, 0b001101110,
932 (outs QFPRegs:$rd), (ins DFPRegs:$rs1, DFPRegs:$rs2),
933 "fdmulq $rs1, $rs2, $rd",
934 [(set f128:$rd, (fmul (fextend f64:$rs1),
935 (fextend f64:$rs2)))]>,
936 Requires<[HasHardQuad]>;
938 def FDIVS : F3_3<2, 0b110100, 0b001001101,
939 (outs FPRegs:$rd), (ins FPRegs:$rs1, FPRegs:$rs2),
940 "fdivs $rs1, $rs2, $rd",
941 [(set f32:$rd, (fdiv f32:$rs1, f32:$rs2))]>;
942 def FDIVD : F3_3<2, 0b110100, 0b001001110,
943 (outs DFPRegs:$rd), (ins DFPRegs:$rs1, DFPRegs:$rs2),
944 "fdivd $rs1, $rs2, $rd",
945 [(set f64:$rd, (fdiv f64:$rs1, f64:$rs2))]>;
946 def FDIVQ : F3_3<2, 0b110100, 0b001001111,
947 (outs QFPRegs:$rd), (ins QFPRegs:$rs1, QFPRegs:$rs2),
948 "fdivq $rs1, $rs2, $rd",
949 [(set f128:$rd, (fdiv f128:$rs1, f128:$rs2))]>,
950 Requires<[HasHardQuad]>;
952 // Floating-point Compare Instructions, p. 148
953 // Note: the 2nd template arg is different for these guys.
954 // Note 2: the result of a FCMP is not available until the 2nd cycle
955 // after the instr is retired, but there is no interlock in Sparc V8.
956 // This behavior is modeled with a forced noop after the instruction in
959 let Defs = [FCC0], rd = 0, isCodeGenOnly = 1 in {
960 def FCMPS : F3_3c<2, 0b110101, 0b001010001,
961 (outs), (ins FPRegs:$rs1, FPRegs:$rs2),
963 [(SPcmpfcc f32:$rs1, f32:$rs2)]>;
964 def FCMPD : F3_3c<2, 0b110101, 0b001010010,
965 (outs), (ins DFPRegs:$rs1, DFPRegs:$rs2),
967 [(SPcmpfcc f64:$rs1, f64:$rs2)]>;
968 def FCMPQ : F3_3c<2, 0b110101, 0b001010011,
969 (outs), (ins QFPRegs:$rs1, QFPRegs:$rs2),
971 [(SPcmpfcc f128:$rs1, f128:$rs2)]>,
972 Requires<[HasHardQuad]>;
975 //===----------------------------------------------------------------------===//
976 // Instructions for Thread Local Storage(TLS).
977 //===----------------------------------------------------------------------===//
978 let isCodeGenOnly = 1, isAsmParserOnly = 1 in {
979 def TLS_ADDrr : F3_1<2, 0b000000,
981 (ins IntRegs:$rs1, IntRegs:$rs2, TLSSym:$sym),
982 "add $rs1, $rs2, $rd, $sym",
984 (tlsadd i32:$rs1, i32:$rs2, tglobaltlsaddr:$sym))]>;
987 def TLS_LDrr : F3_1<3, 0b000000,
988 (outs IntRegs:$dst), (ins MEMrr:$addr, TLSSym:$sym),
989 "ld [$addr], $dst, $sym",
991 (tlsld ADDRrr:$addr, tglobaltlsaddr:$sym))]>;
993 let Uses = [O6], isCall = 1, hasDelaySlot = 1 in
994 def TLS_CALL : InstSP<(outs),
995 (ins calltarget:$disp, TLSSym:$sym, variable_ops),
997 [(tlscall texternalsym:$disp, tglobaltlsaddr:$sym)]> {
1000 let Inst{29-0} = disp;
1004 //===----------------------------------------------------------------------===//
1006 //===----------------------------------------------------------------------===//
1008 // V9 Conditional Moves.
1009 let Predicates = [HasV9], Constraints = "$f = $rd" in {
1010 // Move Integer Register on Condition (MOVcc) p. 194 of the V9 manual.
1011 let Uses = [ICC], intcc = 1, cc = 0b00 in {
1013 : F4_1<0b101100, (outs IntRegs:$rd),
1014 (ins IntRegs:$rs2, IntRegs:$f, CCOp:$cond),
1015 "mov$cond %icc, $rs2, $rd",
1016 [(set i32:$rd, (SPselecticc i32:$rs2, i32:$f, imm:$cond))]>;
1019 : F4_2<0b101100, (outs IntRegs:$rd),
1020 (ins i32imm:$simm11, IntRegs:$f, CCOp:$cond),
1021 "mov$cond %icc, $simm11, $rd",
1023 (SPselecticc simm11:$simm11, i32:$f, imm:$cond))]>;
1026 let Uses = [FCC0], intcc = 0, cc = 0b00 in {
1028 : F4_1<0b101100, (outs IntRegs:$rd),
1029 (ins IntRegs:$rs2, IntRegs:$f, CCOp:$cond),
1030 "mov$cond %fcc0, $rs2, $rd",
1031 [(set i32:$rd, (SPselectfcc i32:$rs2, i32:$f, imm:$cond))]>;
1033 : F4_2<0b101100, (outs IntRegs:$rd),
1034 (ins i32imm:$simm11, IntRegs:$f, CCOp:$cond),
1035 "mov$cond %fcc0, $simm11, $rd",
1037 (SPselectfcc simm11:$simm11, i32:$f, imm:$cond))]>;
1040 let Uses = [ICC], intcc = 1, opf_cc = 0b00 in {
1042 : F4_3<0b110101, 0b000001, (outs FPRegs:$rd),
1043 (ins FPRegs:$rs2, FPRegs:$f, CCOp:$cond),
1044 "fmovs$cond %icc, $rs2, $rd",
1045 [(set f32:$rd, (SPselecticc f32:$rs2, f32:$f, imm:$cond))]>;
1047 : F4_3<0b110101, 0b000010, (outs DFPRegs:$rd),
1048 (ins DFPRegs:$rs2, DFPRegs:$f, CCOp:$cond),
1049 "fmovd$cond %icc, $rs2, $rd",
1050 [(set f64:$rd, (SPselecticc f64:$rs2, f64:$f, imm:$cond))]>;
1052 : F4_3<0b110101, 0b000011, (outs QFPRegs:$rd),
1053 (ins QFPRegs:$rs2, QFPRegs:$f, CCOp:$cond),
1054 "fmovq$cond %icc, $rs2, $rd",
1055 [(set f128:$rd, (SPselecticc f128:$rs2, f128:$f, imm:$cond))]>,
1056 Requires<[HasHardQuad]>;
1059 let Uses = [FCC0], intcc = 0, opf_cc = 0b00 in {
1061 : F4_3<0b110101, 0b000001, (outs FPRegs:$rd),
1062 (ins FPRegs:$rs2, FPRegs:$f, CCOp:$cond),
1063 "fmovs$cond %fcc0, $rs2, $rd",
1064 [(set f32:$rd, (SPselectfcc f32:$rs2, f32:$f, imm:$cond))]>;
1066 : F4_3<0b110101, 0b000010, (outs DFPRegs:$rd),
1067 (ins DFPRegs:$rs2, DFPRegs:$f, CCOp:$cond),
1068 "fmovd$cond %fcc0, $rs2, $rd",
1069 [(set f64:$rd, (SPselectfcc f64:$rs2, f64:$f, imm:$cond))]>;
1071 : F4_3<0b110101, 0b000011, (outs QFPRegs:$rd),
1072 (ins QFPRegs:$rs2, QFPRegs:$f, CCOp:$cond),
1073 "fmovq$cond %fcc0, $rs2, $rd",
1074 [(set f128:$rd, (SPselectfcc f128:$rs2, f128:$f, imm:$cond))]>,
1075 Requires<[HasHardQuad]>;
1080 // Floating-Point Move Instructions, p. 164 of the V9 manual.
1081 let Predicates = [HasV9] in {
1082 def FMOVD : F3_3u<2, 0b110100, 0b000000010,
1083 (outs DFPRegs:$rd), (ins DFPRegs:$rs2),
1084 "fmovd $rs2, $rd", []>;
1085 def FMOVQ : F3_3u<2, 0b110100, 0b000000011,
1086 (outs QFPRegs:$rd), (ins QFPRegs:$rs2),
1087 "fmovq $rs2, $rd", []>,
1088 Requires<[HasHardQuad]>;
1089 def FNEGD : F3_3u<2, 0b110100, 0b000000110,
1090 (outs DFPRegs:$rd), (ins DFPRegs:$rs2),
1092 [(set f64:$rd, (fneg f64:$rs2))]>;
1093 def FNEGQ : F3_3u<2, 0b110100, 0b000000111,
1094 (outs QFPRegs:$rd), (ins QFPRegs:$rs2),
1096 [(set f128:$rd, (fneg f128:$rs2))]>,
1097 Requires<[HasHardQuad]>;
1098 def FABSD : F3_3u<2, 0b110100, 0b000001010,
1099 (outs DFPRegs:$rd), (ins DFPRegs:$rs2),
1101 [(set f64:$rd, (fabs f64:$rs2))]>;
1102 def FABSQ : F3_3u<2, 0b110100, 0b000001011,
1103 (outs QFPRegs:$rd), (ins QFPRegs:$rs2),
1105 [(set f128:$rd, (fabs f128:$rs2))]>,
1106 Requires<[HasHardQuad]>;
1109 // Floating-point compare instruction with %fcc0-%fcc3.
1110 def V9FCMPS : F3_3c<2, 0b110101, 0b001010001,
1111 (outs FCCRegs:$rd), (ins FPRegs:$rs1, FPRegs:$rs2),
1112 "fcmps $rd, $rs1, $rs2", []>;
1113 def V9FCMPD : F3_3c<2, 0b110101, 0b001010010,
1114 (outs FCCRegs:$rd), (ins DFPRegs:$rs1, DFPRegs:$rs2),
1115 "fcmpd $rd, $rs1, $rs2", []>;
1116 def V9FCMPQ : F3_3c<2, 0b110101, 0b001010011,
1117 (outs FCCRegs:$rd), (ins QFPRegs:$rs1, QFPRegs:$rs2),
1118 "fcmpq $rd, $rs1, $rs2", []>,
1119 Requires<[HasHardQuad]>;
1121 let hasSideEffects = 1 in {
1122 def V9FCMPES : F3_3c<2, 0b110101, 0b001010101,
1123 (outs FCCRegs:$rd), (ins FPRegs:$rs1, FPRegs:$rs2),
1124 "fcmpes $rd, $rs1, $rs2", []>;
1125 def V9FCMPED : F3_3c<2, 0b110101, 0b001010110,
1126 (outs FCCRegs:$rd), (ins DFPRegs:$rs1, DFPRegs:$rs2),
1127 "fcmped $rd, $rs1, $rs2", []>;
1128 def V9FCMPEQ : F3_3c<2, 0b110101, 0b001010111,
1129 (outs FCCRegs:$rd), (ins QFPRegs:$rs1, QFPRegs:$rs2),
1130 "fcmpeq $rd, $rs1, $rs2", []>,
1131 Requires<[HasHardQuad]>;
1134 // Floating point conditional move instrucitons with %fcc0-%fcc3.
1135 let Predicates = [HasV9] in {
1136 let Constraints = "$f = $rd", intcc = 0 in {
1138 : F4_1<0b101100, (outs IntRegs:$rd),
1139 (ins FCCRegs:$cc, IntRegs:$rs2, IntRegs:$f, CCOp:$cond),
1140 "mov$cond $cc, $rs2, $rd", []>;
1142 : F4_2<0b101100, (outs IntRegs:$rd),
1143 (ins FCCRegs:$cc, i32imm:$simm11, IntRegs:$f, CCOp:$cond),
1144 "mov$cond $cc, $simm11, $rd", []>;
1146 : F4_3<0b110101, 0b000001, (outs FPRegs:$rd),
1147 (ins FCCRegs:$opf_cc, FPRegs:$rs2, FPRegs:$f, CCOp:$cond),
1148 "fmovs$cond $opf_cc, $rs2, $rd", []>;
1150 : F4_3<0b110101, 0b000010, (outs DFPRegs:$rd),
1151 (ins FCCRegs:$opf_cc, DFPRegs:$rs2, DFPRegs:$f, CCOp:$cond),
1152 "fmovd$cond $opf_cc, $rs2, $rd", []>;
1154 : F4_3<0b110101, 0b000011, (outs QFPRegs:$rd),
1155 (ins FCCRegs:$opf_cc, QFPRegs:$rs2, QFPRegs:$f, CCOp:$cond),
1156 "fmovq$cond $opf_cc, $rs2, $rd", []>,
1157 Requires<[HasHardQuad]>;
1158 } // Constraints = "$f = $rd", ...
1159 } // let Predicates = [hasV9]
1162 // POPCrr - This does a ctpop of a 64-bit register. As such, we have to clear
1163 // the top 32-bits before using it. To do this clearing, we use a SRLri X,0.
1165 def POPCrr : F3_1<2, 0b101110,
1166 (outs IntRegs:$dst), (ins IntRegs:$src),
1167 "popc $src, $dst", []>, Requires<[HasV9]>;
1168 def : Pat<(ctpop i32:$src),
1169 (POPCrr (SRLri $src, 0))>;
1172 let hasSideEffects =1, rd = 0, rs1 = 0b01111, rs2 = 0 in
1173 def STBAR : F3_1<2, 0b101000, (outs), (ins), "stbar", []>;
1175 let Predicates = [HasV9], hasSideEffects = 1, rd = 0, rs1 = 0b01111 in
1176 def MEMBARi : F3_2<2, 0b101000, (outs), (ins simm13Op:$simm13),
1177 "membar $simm13", []>;
1179 let Constraints = "$val = $dst", DecoderMethod = "DecodeSWAP" in {
1180 def SWAPrr : F3_1<3, 0b001111,
1181 (outs IntRegs:$dst), (ins MEMrr:$addr, IntRegs:$val),
1182 "swap [$addr], $dst",
1183 [(set i32:$dst, (atomic_swap_32 ADDRrr:$addr, i32:$val))]>;
1184 def SWAPri : F3_2<3, 0b001111,
1185 (outs IntRegs:$dst), (ins MEMri:$addr, IntRegs:$val),
1186 "swap [$addr], $dst",
1187 [(set i32:$dst, (atomic_swap_32 ADDRri:$addr, i32:$val))]>;
1188 def SWAPArr : F3_1_asi<3, 0b011111,
1189 (outs IntRegs:$dst), (ins MEMrr:$addr, i8imm:$asi, IntRegs:$val),
1190 "swapa [$addr] $asi, $dst",
1191 [/*FIXME: pattern?*/]>;
1194 // TODO: Should add a CASArr variant. In fact, the CAS instruction,
1195 // unlike other instructions, only comes in a form which requires an
1196 // ASI be provided. The ASI value hardcoded here is ASI_PRIMARY, the
1197 // default unprivileged ASI for SparcV9. (Also of note: some modern
1198 // SparcV8 implementations provide CASA as an extension, but require
1199 // the use of SparcV8's default ASI, 0xA ("User Data") instead.)
1200 let Predicates = [HasV9], Constraints = "$swap = $rd", asi = 0b10000000 in
1201 def CASrr: F3_1_asi<3, 0b111100,
1202 (outs IntRegs:$rd), (ins IntRegs:$rs1, IntRegs:$rs2,
1204 "cas [$rs1], $rs2, $rd",
1206 (atomic_cmp_swap iPTR:$rs1, i32:$rs2, i32:$swap))]>;
1208 let Defs = [ICC] in {
1209 defm TADDCC : F3_12np<"taddcc", 0b100000>;
1210 defm TSUBCC : F3_12np<"tsubcc", 0b100001>;
1212 let hasSideEffects = 1 in {
1213 defm TADDCCTV : F3_12np<"taddcctv", 0b100010>;
1214 defm TSUBCCTV : F3_12np<"tsubcctv", 0b100011>;
1218 multiclass TRAP<string regStr> {
1219 def rr : TRAPSPrr<0b111010, (outs), (ins IntRegs:$rs1, IntRegs:$rs2,
1221 !strconcat(!strconcat("t$cond ", regStr), ", $rs1 + $rs2"), []>;
1222 def ri : TRAPSPri<0b111010, (outs), (ins IntRegs:$rs1, i32imm:$imm,
1224 !strconcat(!strconcat("t$cond ", regStr), ", $rs1 + $imm"), []>;
1227 let hasSideEffects = 1, Uses = [ICC], cc = 0b00 in
1228 defm TICC : TRAP<"%icc">;
1230 //===----------------------------------------------------------------------===//
1231 // Non-Instruction Patterns
1232 //===----------------------------------------------------------------------===//
1234 // Small immediates.
1235 def : Pat<(i32 simm13:$val),
1236 (ORri (i32 G0), imm:$val)>;
1237 // Arbitrary immediates.
1238 def : Pat<(i32 imm:$val),
1239 (ORri (SETHIi (HI22 imm:$val)), (LO10 imm:$val))>;
1242 // Global addresses, constant pool entries
1243 let Predicates = [Is32Bit] in {
1245 def : Pat<(SPhi tglobaladdr:$in), (SETHIi tglobaladdr:$in)>;
1246 def : Pat<(SPlo tglobaladdr:$in), (ORri (i32 G0), tglobaladdr:$in)>;
1247 def : Pat<(SPhi tconstpool:$in), (SETHIi tconstpool:$in)>;
1248 def : Pat<(SPlo tconstpool:$in), (ORri (i32 G0), tconstpool:$in)>;
1250 // GlobalTLS addresses
1251 def : Pat<(SPhi tglobaltlsaddr:$in), (SETHIi tglobaltlsaddr:$in)>;
1252 def : Pat<(SPlo tglobaltlsaddr:$in), (ORri (i32 G0), tglobaltlsaddr:$in)>;
1253 def : Pat<(add (SPhi tglobaltlsaddr:$in1), (SPlo tglobaltlsaddr:$in2)),
1254 (ADDri (SETHIi tglobaltlsaddr:$in1), (tglobaltlsaddr:$in2))>;
1255 def : Pat<(xor (SPhi tglobaltlsaddr:$in1), (SPlo tglobaltlsaddr:$in2)),
1256 (XORri (SETHIi tglobaltlsaddr:$in1), (tglobaltlsaddr:$in2))>;
1259 def : Pat<(SPhi tblockaddress:$in), (SETHIi tblockaddress:$in)>;
1260 def : Pat<(SPlo tblockaddress:$in), (ORri (i32 G0), tblockaddress:$in)>;
1262 // Add reg, lo. This is used when taking the addr of a global/constpool entry.
1263 def : Pat<(add iPTR:$r, (SPlo tglobaladdr:$in)), (ADDri $r, tglobaladdr:$in)>;
1264 def : Pat<(add iPTR:$r, (SPlo tconstpool:$in)), (ADDri $r, tconstpool:$in)>;
1265 def : Pat<(add iPTR:$r, (SPlo tblockaddress:$in)),
1266 (ADDri $r, tblockaddress:$in)>;
1270 def : Pat<(call tglobaladdr:$dst),
1271 (CALL tglobaladdr:$dst)>;
1272 def : Pat<(call texternalsym:$dst),
1273 (CALL texternalsym:$dst)>;
1275 // Map integer extload's to zextloads.
1276 def : Pat<(i32 (extloadi1 ADDRrr:$src)), (LDUBrr ADDRrr:$src)>;
1277 def : Pat<(i32 (extloadi1 ADDRri:$src)), (LDUBri ADDRri:$src)>;
1278 def : Pat<(i32 (extloadi8 ADDRrr:$src)), (LDUBrr ADDRrr:$src)>;
1279 def : Pat<(i32 (extloadi8 ADDRri:$src)), (LDUBri ADDRri:$src)>;
1280 def : Pat<(i32 (extloadi16 ADDRrr:$src)), (LDUHrr ADDRrr:$src)>;
1281 def : Pat<(i32 (extloadi16 ADDRri:$src)), (LDUHri ADDRri:$src)>;
1283 // zextload bool -> zextload byte
1284 def : Pat<(i32 (zextloadi1 ADDRrr:$src)), (LDUBrr ADDRrr:$src)>;
1285 def : Pat<(i32 (zextloadi1 ADDRri:$src)), (LDUBri ADDRri:$src)>;
1287 // store 0, addr -> store %g0, addr
1288 def : Pat<(store (i32 0), ADDRrr:$dst), (STrr ADDRrr:$dst, (i32 G0))>;
1289 def : Pat<(store (i32 0), ADDRri:$dst), (STri ADDRri:$dst, (i32 G0))>;
1291 // store bar for all atomic_fence in V8.
1292 let Predicates = [HasNoV9] in
1293 def : Pat<(atomic_fence imm, imm), (STBAR)>;
1295 // atomic_load_32 addr -> load addr
1296 def : Pat<(i32 (atomic_load ADDRrr:$src)), (LDrr ADDRrr:$src)>;
1297 def : Pat<(i32 (atomic_load ADDRri:$src)), (LDri ADDRri:$src)>;
1299 // atomic_store_32 val, addr -> store val, addr
1300 def : Pat<(atomic_store ADDRrr:$dst, i32:$val), (STrr ADDRrr:$dst, $val)>;
1301 def : Pat<(atomic_store ADDRri:$dst, i32:$val), (STri ADDRri:$dst, $val)>;
1304 include "SparcInstr64Bit.td"
1305 include "SparcInstrVIS.td"
1306 include "SparcInstrAliases.td"