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 // HasV9 - This predicate is true when the target processor supports V9
25 // instructions. Note that the machine may be running in 32-bit mode.
26 def HasV9 : Predicate<"Subtarget.isV9()">;
28 // HasNoV9 - This predicate is true when the target doesn't have V9
29 // instructions. Use of this is just a hack for the isel not having proper
30 // costs for V8 instructions that are more expensive than their V9 ones.
31 def HasNoV9 : Predicate<"!Subtarget.isV9()">;
33 // HasVIS - This is true when the target processor has VIS extensions.
34 def HasVIS : Predicate<"Subtarget.isVIS()">;
36 // UseDeprecatedInsts - This predicate is true when the target processor is a
37 // V8, or when it is V9 but the V8 deprecated instructions are efficient enough
38 // to use when appropriate. In either of these cases, the instruction selector
39 // will pick deprecated instructions.
40 def UseDeprecatedInsts : Predicate<"Subtarget.useDeprecatedV8Instructions()">;
42 //===----------------------------------------------------------------------===//
43 // Instruction Pattern Stuff
44 //===----------------------------------------------------------------------===//
46 def simm11 : PatLeaf<(imm), [{ return isInt<11>(N->getSExtValue()); }]>;
48 def simm13 : PatLeaf<(imm), [{ return isInt<13>(N->getSExtValue()); }]>;
50 def LO10 : SDNodeXForm<imm, [{
51 return CurDAG->getTargetConstant((unsigned)N->getZExtValue() & 1023,
55 def HI22 : SDNodeXForm<imm, [{
56 // Transformation function: shift the immediate value down into the low bits.
57 return CurDAG->getTargetConstant((unsigned)N->getZExtValue() >> 10, MVT::i32);
60 def SETHIimm : PatLeaf<(imm), [{
61 return (((unsigned)N->getZExtValue() >> 10) << 10) ==
62 (unsigned)N->getZExtValue();
66 def ADDRrr : ComplexPattern<i32, 2, "SelectADDRrr", [], []>;
67 def ADDRri : ComplexPattern<i32, 2, "SelectADDRri", [frameindex], []>;
70 def MEMrr : Operand<i32> {
71 let PrintMethod = "printMemOperand";
72 let MIOperandInfo = (ops IntRegs, IntRegs);
74 def MEMri : Operand<i32> {
75 let PrintMethod = "printMemOperand";
76 let MIOperandInfo = (ops IntRegs, i32imm);
79 // Branch targets have OtherVT type.
80 def brtarget : Operand<OtherVT>;
81 def calltarget : Operand<i32>;
83 // Operand for printing out a condition code.
84 let PrintMethod = "printCCOperand" in
85 def CCOp : Operand<i32>;
88 SDTypeProfile<0, 2, [SDTCisFP<0>, SDTCisSameAs<0, 1>]>;
90 SDTypeProfile<0, 2, [SDTCisVT<0, OtherVT>, SDTCisVT<1, i32>]>;
92 SDTypeProfile<1, 3, [SDTCisSameAs<0, 1>, SDTCisSameAs<1, 2>, SDTCisVT<3, i32>]>;
94 SDTypeProfile<1, 1, [SDTCisVT<0, f32>, SDTCisFP<1>]>;
96 SDTypeProfile<1, 1, [SDTCisFP<0>, SDTCisVT<1, f32>]>;
98 def SPcmpicc : SDNode<"SPISD::CMPICC", SDTIntBinOp, [SDNPOutFlag]>;
99 def SPcmpfcc : SDNode<"SPISD::CMPFCC", SDTSPcmpfcc, [SDNPOutFlag]>;
100 def SPbricc : SDNode<"SPISD::BRICC", SDTSPbrcc, [SDNPHasChain, SDNPInFlag]>;
101 def SPbrfcc : SDNode<"SPISD::BRFCC", SDTSPbrcc, [SDNPHasChain, SDNPInFlag]>;
103 def SPhi : SDNode<"SPISD::Hi", SDTIntUnaryOp>;
104 def SPlo : SDNode<"SPISD::Lo", SDTIntUnaryOp>;
106 def SPftoi : SDNode<"SPISD::FTOI", SDTSPFTOI>;
107 def SPitof : SDNode<"SPISD::ITOF", SDTSPITOF>;
109 def SPselecticc : SDNode<"SPISD::SELECT_ICC", SDTSPselectcc, [SDNPInFlag]>;
110 def SPselectfcc : SDNode<"SPISD::SELECT_FCC", SDTSPselectcc, [SDNPInFlag]>;
112 // These are target-independent nodes, but have target-specific formats.
113 def SDT_SPCallSeqStart : SDCallSeqStart<[ SDTCisVT<0, i32> ]>;
114 def SDT_SPCallSeqEnd : SDCallSeqEnd<[ SDTCisVT<0, i32>,
117 def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_SPCallSeqStart,
118 [SDNPHasChain, SDNPOutFlag]>;
119 def callseq_end : SDNode<"ISD::CALLSEQ_END", SDT_SPCallSeqEnd,
120 [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
122 def SDT_SPCall : SDTypeProfile<0, 1, [SDTCisVT<0, i32>]>;
123 def call : SDNode<"SPISD::CALL", SDT_SPCall,
124 [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
126 def retflag : SDNode<"SPISD::RET_FLAG", SDTNone,
127 [SDNPHasChain, SDNPOptInFlag]>;
129 def getPCX : Operand<i32> {
130 let PrintMethod = "printGetPCX";
133 //===----------------------------------------------------------------------===//
134 // SPARC Flag Conditions
135 //===----------------------------------------------------------------------===//
137 // Note that these values must be kept in sync with the CCOp::CondCode enum
139 class ICC_VAL<int N> : PatLeaf<(i32 N)>;
140 def ICC_NE : ICC_VAL< 9>; // Not Equal
141 def ICC_E : ICC_VAL< 1>; // Equal
142 def ICC_G : ICC_VAL<10>; // Greater
143 def ICC_LE : ICC_VAL< 2>; // Less or Equal
144 def ICC_GE : ICC_VAL<11>; // Greater or Equal
145 def ICC_L : ICC_VAL< 3>; // Less
146 def ICC_GU : ICC_VAL<12>; // Greater Unsigned
147 def ICC_LEU : ICC_VAL< 4>; // Less or Equal Unsigned
148 def ICC_CC : ICC_VAL<13>; // Carry Clear/Great or Equal Unsigned
149 def ICC_CS : ICC_VAL< 5>; // Carry Set/Less Unsigned
150 def ICC_POS : ICC_VAL<14>; // Positive
151 def ICC_NEG : ICC_VAL< 6>; // Negative
152 def ICC_VC : ICC_VAL<15>; // Overflow Clear
153 def ICC_VS : ICC_VAL< 7>; // Overflow Set
155 class FCC_VAL<int N> : PatLeaf<(i32 N)>;
156 def FCC_U : FCC_VAL<23>; // Unordered
157 def FCC_G : FCC_VAL<22>; // Greater
158 def FCC_UG : FCC_VAL<21>; // Unordered or Greater
159 def FCC_L : FCC_VAL<20>; // Less
160 def FCC_UL : FCC_VAL<19>; // Unordered or Less
161 def FCC_LG : FCC_VAL<18>; // Less or Greater
162 def FCC_NE : FCC_VAL<17>; // Not Equal
163 def FCC_E : FCC_VAL<25>; // Equal
164 def FCC_UE : FCC_VAL<24>; // Unordered or Equal
165 def FCC_GE : FCC_VAL<25>; // Greater or Equal
166 def FCC_UGE : FCC_VAL<26>; // Unordered or Greater or Equal
167 def FCC_LE : FCC_VAL<27>; // Less or Equal
168 def FCC_ULE : FCC_VAL<28>; // Unordered or Less or Equal
169 def FCC_O : FCC_VAL<29>; // Ordered
171 //===----------------------------------------------------------------------===//
172 // Instruction Class Templates
173 //===----------------------------------------------------------------------===//
175 /// F3_12 multiclass - Define a normal F3_1/F3_2 pattern in one shot.
176 multiclass F3_12<string OpcStr, bits<6> Op3Val, SDNode OpNode> {
177 def rr : F3_1<2, Op3Val,
178 (outs IntRegs:$dst), (ins IntRegs:$b, IntRegs:$c),
179 !strconcat(OpcStr, " $b, $c, $dst"),
180 [(set IntRegs:$dst, (OpNode IntRegs:$b, IntRegs:$c))]>;
181 def ri : F3_2<2, Op3Val,
182 (outs IntRegs:$dst), (ins IntRegs:$b, i32imm:$c),
183 !strconcat(OpcStr, " $b, $c, $dst"),
184 [(set IntRegs:$dst, (OpNode IntRegs:$b, simm13:$c))]>;
187 /// F3_12np multiclass - Define a normal F3_1/F3_2 pattern in one shot, with no
189 multiclass F3_12np<string OpcStr, bits<6> Op3Val> {
190 def rr : F3_1<2, Op3Val,
191 (outs IntRegs:$dst), (ins IntRegs:$b, IntRegs:$c),
192 !strconcat(OpcStr, " $b, $c, $dst"), []>;
193 def ri : F3_2<2, Op3Val,
194 (outs IntRegs:$dst), (ins IntRegs:$b, i32imm:$c),
195 !strconcat(OpcStr, " $b, $c, $dst"), []>;
198 //===----------------------------------------------------------------------===//
200 //===----------------------------------------------------------------------===//
202 // Pseudo instructions.
203 class Pseudo<dag outs, dag ins, string asmstr, list<dag> pattern>
204 : InstSP<outs, ins, asmstr, pattern>;
207 let Defs = [O7], Uses = [O7] in {
208 def GETPCX : Pseudo<(outs getPCX:$getpcseq), (ins), "$getpcseq", [] >;
211 let Defs = [O6], Uses = [O6] in {
212 def ADJCALLSTACKDOWN : Pseudo<(outs), (ins i32imm:$amt),
213 "!ADJCALLSTACKDOWN $amt",
214 [(callseq_start timm:$amt)]>;
215 def ADJCALLSTACKUP : Pseudo<(outs), (ins i32imm:$amt1, i32imm:$amt2),
216 "!ADJCALLSTACKUP $amt1",
217 [(callseq_end timm:$amt1, timm:$amt2)]>;
220 // FpMOVD/FpNEGD/FpABSD - These are lowered to single-precision ops by the
222 let Predicates = [HasNoV9] in { // Only emit these in V8 mode.
223 def FpMOVD : Pseudo<(outs DFPRegs:$dst), (ins DFPRegs:$src),
224 "!FpMOVD $src, $dst", []>;
225 def FpNEGD : Pseudo<(outs DFPRegs:$dst), (ins DFPRegs:$src),
226 "!FpNEGD $src, $dst",
227 [(set DFPRegs:$dst, (fneg DFPRegs:$src))]>;
228 def FpABSD : Pseudo<(outs DFPRegs:$dst), (ins DFPRegs:$src),
229 "!FpABSD $src, $dst",
230 [(set DFPRegs:$dst, (fabs DFPRegs:$src))]>;
233 // SELECT_CC_* - Used to implement the SELECT_CC DAG operation. Expanded after
234 // instruction selection into a branch sequence. This has to handle all
235 // permutations of selection between i32/f32/f64 on ICC and FCC.
236 let usesCustomInserter = 1 in { // Expanded after instruction selection.
237 def SELECT_CC_Int_ICC
238 : Pseudo<(outs IntRegs:$dst), (ins IntRegs:$T, IntRegs:$F, i32imm:$Cond),
239 "; SELECT_CC_Int_ICC PSEUDO!",
240 [(set IntRegs:$dst, (SPselecticc IntRegs:$T, IntRegs:$F,
242 def SELECT_CC_Int_FCC
243 : Pseudo<(outs IntRegs:$dst), (ins IntRegs:$T, IntRegs:$F, i32imm:$Cond),
244 "; SELECT_CC_Int_FCC PSEUDO!",
245 [(set IntRegs:$dst, (SPselectfcc IntRegs:$T, IntRegs:$F,
248 : Pseudo<(outs FPRegs:$dst), (ins FPRegs:$T, FPRegs:$F, i32imm:$Cond),
249 "; SELECT_CC_FP_ICC PSEUDO!",
250 [(set FPRegs:$dst, (SPselecticc FPRegs:$T, FPRegs:$F,
253 : Pseudo<(outs FPRegs:$dst), (ins FPRegs:$T, FPRegs:$F, i32imm:$Cond),
254 "; SELECT_CC_FP_FCC PSEUDO!",
255 [(set FPRegs:$dst, (SPselectfcc FPRegs:$T, FPRegs:$F,
257 def SELECT_CC_DFP_ICC
258 : Pseudo<(outs DFPRegs:$dst), (ins DFPRegs:$T, DFPRegs:$F, i32imm:$Cond),
259 "; SELECT_CC_DFP_ICC PSEUDO!",
260 [(set DFPRegs:$dst, (SPselecticc DFPRegs:$T, DFPRegs:$F,
262 def SELECT_CC_DFP_FCC
263 : Pseudo<(outs DFPRegs:$dst), (ins DFPRegs:$T, DFPRegs:$F, i32imm:$Cond),
264 "; SELECT_CC_DFP_FCC PSEUDO!",
265 [(set DFPRegs:$dst, (SPselectfcc DFPRegs:$T, DFPRegs:$F,
270 // Section A.3 - Synthetic Instructions, p. 85
271 // special cases of JMPL:
272 let isReturn = 1, isTerminator = 1, hasDelaySlot = 1, isBarrier = 1 in {
273 let rd = O7.Num, rs1 = G0.Num, simm13 = 8 in
274 def RETL: F3_2<2, 0b111000, (outs), (ins), "retl", [(retflag)]>;
277 // Section B.1 - Load Integer Instructions, p. 90
278 def LDSBrr : F3_1<3, 0b001001,
279 (outs IntRegs:$dst), (ins MEMrr:$addr),
280 "ldsb [$addr], $dst",
281 [(set IntRegs:$dst, (sextloadi8 ADDRrr:$addr))]>;
282 def LDSBri : F3_2<3, 0b001001,
283 (outs IntRegs:$dst), (ins MEMri:$addr),
284 "ldsb [$addr], $dst",
285 [(set IntRegs:$dst, (sextloadi8 ADDRri:$addr))]>;
286 def LDSHrr : F3_1<3, 0b001010,
287 (outs IntRegs:$dst), (ins MEMrr:$addr),
288 "ldsh [$addr], $dst",
289 [(set IntRegs:$dst, (sextloadi16 ADDRrr:$addr))]>;
290 def LDSHri : F3_2<3, 0b001010,
291 (outs IntRegs:$dst), (ins MEMri:$addr),
292 "ldsh [$addr], $dst",
293 [(set IntRegs:$dst, (sextloadi16 ADDRri:$addr))]>;
294 def LDUBrr : F3_1<3, 0b000001,
295 (outs IntRegs:$dst), (ins MEMrr:$addr),
296 "ldub [$addr], $dst",
297 [(set IntRegs:$dst, (zextloadi8 ADDRrr:$addr))]>;
298 def LDUBri : F3_2<3, 0b000001,
299 (outs IntRegs:$dst), (ins MEMri:$addr),
300 "ldub [$addr], $dst",
301 [(set IntRegs:$dst, (zextloadi8 ADDRri:$addr))]>;
302 def LDUHrr : F3_1<3, 0b000010,
303 (outs IntRegs:$dst), (ins MEMrr:$addr),
304 "lduh [$addr], $dst",
305 [(set IntRegs:$dst, (zextloadi16 ADDRrr:$addr))]>;
306 def LDUHri : F3_2<3, 0b000010,
307 (outs IntRegs:$dst), (ins MEMri:$addr),
308 "lduh [$addr], $dst",
309 [(set IntRegs:$dst, (zextloadi16 ADDRri:$addr))]>;
310 def LDrr : F3_1<3, 0b000000,
311 (outs IntRegs:$dst), (ins MEMrr:$addr),
313 [(set IntRegs:$dst, (load ADDRrr:$addr))]>;
314 def LDri : F3_2<3, 0b000000,
315 (outs IntRegs:$dst), (ins MEMri:$addr),
317 [(set IntRegs:$dst, (load ADDRri:$addr))]>;
319 // Section B.2 - Load Floating-point Instructions, p. 92
320 def LDFrr : F3_1<3, 0b100000,
321 (outs FPRegs:$dst), (ins MEMrr:$addr),
323 [(set FPRegs:$dst, (load ADDRrr:$addr))]>;
324 def LDFri : F3_2<3, 0b100000,
325 (outs FPRegs:$dst), (ins MEMri:$addr),
327 [(set FPRegs:$dst, (load ADDRri:$addr))]>;
328 def LDDFrr : F3_1<3, 0b100011,
329 (outs DFPRegs:$dst), (ins MEMrr:$addr),
331 [(set DFPRegs:$dst, (load ADDRrr:$addr))]>;
332 def LDDFri : F3_2<3, 0b100011,
333 (outs DFPRegs:$dst), (ins MEMri:$addr),
335 [(set DFPRegs:$dst, (load ADDRri:$addr))]>;
337 // Section B.4 - Store Integer Instructions, p. 95
338 def STBrr : F3_1<3, 0b000101,
339 (outs), (ins MEMrr:$addr, IntRegs:$src),
341 [(truncstorei8 IntRegs:$src, ADDRrr:$addr)]>;
342 def STBri : F3_2<3, 0b000101,
343 (outs), (ins MEMri:$addr, IntRegs:$src),
345 [(truncstorei8 IntRegs:$src, ADDRri:$addr)]>;
346 def STHrr : F3_1<3, 0b000110,
347 (outs), (ins MEMrr:$addr, IntRegs:$src),
349 [(truncstorei16 IntRegs:$src, ADDRrr:$addr)]>;
350 def STHri : F3_2<3, 0b000110,
351 (outs), (ins MEMri:$addr, IntRegs:$src),
353 [(truncstorei16 IntRegs:$src, ADDRri:$addr)]>;
354 def STrr : F3_1<3, 0b000100,
355 (outs), (ins MEMrr:$addr, IntRegs:$src),
357 [(store IntRegs:$src, ADDRrr:$addr)]>;
358 def STri : F3_2<3, 0b000100,
359 (outs), (ins MEMri:$addr, IntRegs:$src),
361 [(store IntRegs:$src, ADDRri:$addr)]>;
363 // Section B.5 - Store Floating-point Instructions, p. 97
364 def STFrr : F3_1<3, 0b100100,
365 (outs), (ins MEMrr:$addr, FPRegs:$src),
367 [(store FPRegs:$src, ADDRrr:$addr)]>;
368 def STFri : F3_2<3, 0b100100,
369 (outs), (ins MEMri:$addr, FPRegs:$src),
371 [(store FPRegs:$src, ADDRri:$addr)]>;
372 def STDFrr : F3_1<3, 0b100111,
373 (outs), (ins MEMrr:$addr, DFPRegs:$src),
375 [(store DFPRegs:$src, ADDRrr:$addr)]>;
376 def STDFri : F3_2<3, 0b100111,
377 (outs), (ins MEMri:$addr, DFPRegs:$src),
379 [(store DFPRegs:$src, ADDRri:$addr)]>;
381 // Section B.9 - SETHI Instruction, p. 104
382 def SETHIi: F2_1<0b100,
383 (outs IntRegs:$dst), (ins i32imm:$src),
385 [(set IntRegs:$dst, SETHIimm:$src)]>;
387 // Section B.10 - NOP Instruction, p. 105
388 // (It's a special case of SETHI)
389 let rd = 0, imm22 = 0 in
390 def NOP : F2_1<0b100, (outs), (ins), "nop", []>;
392 // Section B.11 - Logical Instructions, p. 106
393 defm AND : F3_12<"and", 0b000001, and>;
395 def ANDNrr : F3_1<2, 0b000101,
396 (outs IntRegs:$dst), (ins IntRegs:$b, IntRegs:$c),
398 [(set IntRegs:$dst, (and IntRegs:$b, (not IntRegs:$c)))]>;
399 def ANDNri : F3_2<2, 0b000101,
400 (outs IntRegs:$dst), (ins IntRegs:$b, i32imm:$c),
401 "andn $b, $c, $dst", []>;
403 defm OR : F3_12<"or", 0b000010, or>;
405 def ORNrr : F3_1<2, 0b000110,
406 (outs IntRegs:$dst), (ins IntRegs:$b, IntRegs:$c),
408 [(set IntRegs:$dst, (or IntRegs:$b, (not IntRegs:$c)))]>;
409 def ORNri : F3_2<2, 0b000110,
410 (outs IntRegs:$dst), (ins IntRegs:$b, i32imm:$c),
411 "orn $b, $c, $dst", []>;
412 defm XOR : F3_12<"xor", 0b000011, xor>;
414 def XNORrr : F3_1<2, 0b000111,
415 (outs IntRegs:$dst), (ins IntRegs:$b, IntRegs:$c),
417 [(set IntRegs:$dst, (not (xor IntRegs:$b, IntRegs:$c)))]>;
418 def XNORri : F3_2<2, 0b000111,
419 (outs IntRegs:$dst), (ins IntRegs:$b, i32imm:$c),
420 "xnor $b, $c, $dst", []>;
422 // Section B.12 - Shift Instructions, p. 107
423 defm SLL : F3_12<"sll", 0b100101, shl>;
424 defm SRL : F3_12<"srl", 0b100110, srl>;
425 defm SRA : F3_12<"sra", 0b100111, sra>;
427 // Section B.13 - Add Instructions, p. 108
428 defm ADD : F3_12<"add", 0b000000, add>;
430 // "LEA" forms of add (patterns to make tblgen happy)
431 def LEA_ADDri : F3_2<2, 0b000000,
432 (outs IntRegs:$dst), (ins MEMri:$addr),
433 "add ${addr:arith}, $dst",
434 [(set IntRegs:$dst, ADDRri:$addr)]>;
437 defm ADDCC : F3_12<"addcc", 0b010000, addc>;
439 defm ADDX : F3_12<"addx", 0b001000, adde>;
441 // Section B.15 - Subtract Instructions, p. 110
442 defm SUB : F3_12 <"sub" , 0b000100, sub>;
443 defm SUBX : F3_12 <"subx" , 0b001100, sube>;
445 let Defs = [ICC] in {
446 defm SUBCC : F3_12 <"subcc", 0b010100, SPcmpicc>;
448 def SUBXCCrr: F3_1<2, 0b011100,
449 (outs IntRegs:$dst), (ins IntRegs:$b, IntRegs:$c),
450 "subxcc $b, $c, $dst", []>;
453 // Section B.18 - Multiply Instructions, p. 113
454 defm UMUL : F3_12np<"umul", 0b001010>;
455 defm SMUL : F3_12 <"smul", 0b001011, mul>;
458 // Section B.19 - Divide Instructions, p. 115
459 defm UDIV : F3_12np<"udiv", 0b001110>;
460 defm SDIV : F3_12np<"sdiv", 0b001111>;
462 // Section B.20 - SAVE and RESTORE, p. 117
463 defm SAVE : F3_12np<"save" , 0b111100>;
464 defm RESTORE : F3_12np<"restore", 0b111101>;
466 // Section B.21 - Branch on Integer Condition Codes Instructions, p. 119
468 // conditional branch class:
469 class BranchSP<bits<4> cc, dag ins, string asmstr, list<dag> pattern>
470 : F2_2<cc, 0b010, (outs), ins, asmstr, pattern> {
472 let isTerminator = 1;
473 let hasDelaySlot = 1;
477 def BA : BranchSP<0b1000, (ins brtarget:$dst),
481 // FIXME: the encoding for the JIT should look at the condition field.
483 def BCOND : BranchSP<0, (ins brtarget:$dst, CCOp:$cc),
485 [(SPbricc bb:$dst, imm:$cc)]>;
488 // Section B.22 - Branch on Floating-point Condition Codes Instructions, p. 121
490 // floating-point conditional branch class:
491 class FPBranchSP<bits<4> cc, dag ins, string asmstr, list<dag> pattern>
492 : F2_2<cc, 0b110, (outs), ins, asmstr, pattern> {
494 let isTerminator = 1;
495 let hasDelaySlot = 1;
498 // FIXME: the encoding for the JIT should look at the condition field.
500 def FBCOND : FPBranchSP<0, (ins brtarget:$dst, CCOp:$cc),
502 [(SPbrfcc bb:$dst, imm:$cc)]>;
505 // Section B.24 - Call and Link Instruction, p. 125
506 // This is the only Format 1 instruction
507 let Uses = [O0, O1, O2, O3, O4, O5],
508 hasDelaySlot = 1, isCall = 1,
509 Defs = [O0, O1, O2, O3, O4, O5, O7, G1, G2, G3, G4, G5, G6, G7,
510 D0, D1, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11, D12, D13, D14, D15] in {
511 def CALL : InstSP<(outs), (ins calltarget:$dst),
515 let Inst{29-0} = disp;
519 def JMPLrr : F3_1<2, 0b111000,
520 (outs), (ins MEMrr:$ptr),
522 [(call ADDRrr:$ptr)]>;
523 def JMPLri : F3_2<2, 0b111000,
524 (outs), (ins MEMri:$ptr),
526 [(call ADDRri:$ptr)]>;
529 // Section B.28 - Read State Register Instructions
530 def RDY : F3_1<2, 0b101000,
531 (outs IntRegs:$dst), (ins),
534 // Section B.29 - Write State Register Instructions
535 def WRYrr : F3_1<2, 0b110000,
536 (outs), (ins IntRegs:$b, IntRegs:$c),
537 "wr $b, $c, %y", []>;
538 def WRYri : F3_2<2, 0b110000,
539 (outs), (ins IntRegs:$b, i32imm:$c),
540 "wr $b, $c, %y", []>;
542 // Convert Integer to Floating-point Instructions, p. 141
543 def FITOS : F3_3<2, 0b110100, 0b011000100,
544 (outs FPRegs:$dst), (ins FPRegs:$src),
546 [(set FPRegs:$dst, (SPitof FPRegs:$src))]>;
547 def FITOD : F3_3<2, 0b110100, 0b011001000,
548 (outs DFPRegs:$dst), (ins FPRegs:$src),
550 [(set DFPRegs:$dst, (SPitof FPRegs:$src))]>;
552 // Convert Floating-point to Integer Instructions, p. 142
553 def FSTOI : F3_3<2, 0b110100, 0b011010001,
554 (outs FPRegs:$dst), (ins FPRegs:$src),
556 [(set FPRegs:$dst, (SPftoi FPRegs:$src))]>;
557 def FDTOI : F3_3<2, 0b110100, 0b011010010,
558 (outs FPRegs:$dst), (ins DFPRegs:$src),
560 [(set FPRegs:$dst, (SPftoi DFPRegs:$src))]>;
562 // Convert between Floating-point Formats Instructions, p. 143
563 def FSTOD : F3_3<2, 0b110100, 0b011001001,
564 (outs DFPRegs:$dst), (ins FPRegs:$src),
566 [(set DFPRegs:$dst, (fextend FPRegs:$src))]>;
567 def FDTOS : F3_3<2, 0b110100, 0b011000110,
568 (outs FPRegs:$dst), (ins DFPRegs:$src),
570 [(set FPRegs:$dst, (fround DFPRegs:$src))]>;
572 // Floating-point Move Instructions, p. 144
573 def FMOVS : F3_3<2, 0b110100, 0b000000001,
574 (outs FPRegs:$dst), (ins FPRegs:$src),
575 "fmovs $src, $dst", []>;
576 def FNEGS : F3_3<2, 0b110100, 0b000000101,
577 (outs FPRegs:$dst), (ins FPRegs:$src),
579 [(set FPRegs:$dst, (fneg FPRegs:$src))]>;
580 def FABSS : F3_3<2, 0b110100, 0b000001001,
581 (outs FPRegs:$dst), (ins FPRegs:$src),
583 [(set FPRegs:$dst, (fabs FPRegs:$src))]>;
586 // Floating-point Square Root Instructions, p.145
587 def FSQRTS : F3_3<2, 0b110100, 0b000101001,
588 (outs FPRegs:$dst), (ins FPRegs:$src),
590 [(set FPRegs:$dst, (fsqrt FPRegs:$src))]>;
591 def FSQRTD : F3_3<2, 0b110100, 0b000101010,
592 (outs DFPRegs:$dst), (ins DFPRegs:$src),
594 [(set DFPRegs:$dst, (fsqrt DFPRegs:$src))]>;
598 // Floating-point Add and Subtract Instructions, p. 146
599 def FADDS : F3_3<2, 0b110100, 0b001000001,
600 (outs FPRegs:$dst), (ins FPRegs:$src1, FPRegs:$src2),
601 "fadds $src1, $src2, $dst",
602 [(set FPRegs:$dst, (fadd FPRegs:$src1, FPRegs:$src2))]>;
603 def FADDD : F3_3<2, 0b110100, 0b001000010,
604 (outs DFPRegs:$dst), (ins DFPRegs:$src1, DFPRegs:$src2),
605 "faddd $src1, $src2, $dst",
606 [(set DFPRegs:$dst, (fadd DFPRegs:$src1, DFPRegs:$src2))]>;
607 def FSUBS : F3_3<2, 0b110100, 0b001000101,
608 (outs FPRegs:$dst), (ins FPRegs:$src1, FPRegs:$src2),
609 "fsubs $src1, $src2, $dst",
610 [(set FPRegs:$dst, (fsub FPRegs:$src1, FPRegs:$src2))]>;
611 def FSUBD : F3_3<2, 0b110100, 0b001000110,
612 (outs DFPRegs:$dst), (ins DFPRegs:$src1, DFPRegs:$src2),
613 "fsubd $src1, $src2, $dst",
614 [(set DFPRegs:$dst, (fsub DFPRegs:$src1, DFPRegs:$src2))]>;
616 // Floating-point Multiply and Divide Instructions, p. 147
617 def FMULS : F3_3<2, 0b110100, 0b001001001,
618 (outs FPRegs:$dst), (ins FPRegs:$src1, FPRegs:$src2),
619 "fmuls $src1, $src2, $dst",
620 [(set FPRegs:$dst, (fmul FPRegs:$src1, FPRegs:$src2))]>;
621 def FMULD : F3_3<2, 0b110100, 0b001001010,
622 (outs DFPRegs:$dst), (ins DFPRegs:$src1, DFPRegs:$src2),
623 "fmuld $src1, $src2, $dst",
624 [(set DFPRegs:$dst, (fmul DFPRegs:$src1, DFPRegs:$src2))]>;
625 def FSMULD : F3_3<2, 0b110100, 0b001101001,
626 (outs DFPRegs:$dst), (ins FPRegs:$src1, FPRegs:$src2),
627 "fsmuld $src1, $src2, $dst",
628 [(set DFPRegs:$dst, (fmul (fextend FPRegs:$src1),
629 (fextend FPRegs:$src2)))]>;
630 def FDIVS : F3_3<2, 0b110100, 0b001001101,
631 (outs FPRegs:$dst), (ins FPRegs:$src1, FPRegs:$src2),
632 "fdivs $src1, $src2, $dst",
633 [(set FPRegs:$dst, (fdiv FPRegs:$src1, FPRegs:$src2))]>;
634 def FDIVD : F3_3<2, 0b110100, 0b001001110,
635 (outs DFPRegs:$dst), (ins DFPRegs:$src1, DFPRegs:$src2),
636 "fdivd $src1, $src2, $dst",
637 [(set DFPRegs:$dst, (fdiv DFPRegs:$src1, DFPRegs:$src2))]>;
639 // Floating-point Compare Instructions, p. 148
640 // Note: the 2nd template arg is different for these guys.
641 // Note 2: the result of a FCMP is not available until the 2nd cycle
642 // after the instr is retired, but there is no interlock. This behavior
643 // is modelled with a forced noop after the instruction.
644 let Defs = [FCC] in {
645 def FCMPS : F3_3<2, 0b110101, 0b001010001,
646 (outs), (ins FPRegs:$src1, FPRegs:$src2),
647 "fcmps $src1, $src2\n\tnop",
648 [(SPcmpfcc FPRegs:$src1, FPRegs:$src2)]>;
649 def FCMPD : F3_3<2, 0b110101, 0b001010010,
650 (outs), (ins DFPRegs:$src1, DFPRegs:$src2),
651 "fcmpd $src1, $src2\n\tnop",
652 [(SPcmpfcc DFPRegs:$src1, DFPRegs:$src2)]>;
655 //===----------------------------------------------------------------------===//
657 //===----------------------------------------------------------------------===//
659 // V9 Conditional Moves.
660 let Predicates = [HasV9], Constraints = "$T = $dst" in {
661 // Move Integer Register on Condition (MOVcc) p. 194 of the V9 manual.
662 // FIXME: Add instruction encodings for the JIT some day.
664 : Pseudo<(outs IntRegs:$dst), (ins IntRegs:$T, IntRegs:$F, CCOp:$cc),
665 "mov$cc %icc, $F, $dst",
667 (SPselecticc IntRegs:$F, IntRegs:$T, imm:$cc))]>;
669 : Pseudo<(outs IntRegs:$dst), (ins IntRegs:$T, i32imm:$F, CCOp:$cc),
670 "mov$cc %icc, $F, $dst",
672 (SPselecticc simm11:$F, IntRegs:$T, imm:$cc))]>;
675 : Pseudo<(outs IntRegs:$dst), (ins IntRegs:$T, IntRegs:$F, CCOp:$cc),
676 "mov$cc %fcc0, $F, $dst",
678 (SPselectfcc IntRegs:$F, IntRegs:$T, imm:$cc))]>;
680 : Pseudo<(outs IntRegs:$dst), (ins IntRegs:$T, i32imm:$F, CCOp:$cc),
681 "mov$cc %fcc0, $F, $dst",
683 (SPselectfcc simm11:$F, IntRegs:$T, imm:$cc))]>;
686 : Pseudo<(outs FPRegs:$dst), (ins FPRegs:$T, FPRegs:$F, CCOp:$cc),
687 "fmovs$cc %icc, $F, $dst",
689 (SPselecticc FPRegs:$F, FPRegs:$T, imm:$cc))]>;
691 : Pseudo<(outs DFPRegs:$dst), (ins DFPRegs:$T, DFPRegs:$F, CCOp:$cc),
692 "fmovd$cc %icc, $F, $dst",
694 (SPselecticc DFPRegs:$F, DFPRegs:$T, imm:$cc))]>;
696 : Pseudo<(outs FPRegs:$dst), (ins FPRegs:$T, FPRegs:$F, CCOp:$cc),
697 "fmovs$cc %fcc0, $F, $dst",
699 (SPselectfcc FPRegs:$F, FPRegs:$T, imm:$cc))]>;
701 : Pseudo<(outs DFPRegs:$dst), (ins DFPRegs:$T, DFPRegs:$F, CCOp:$cc),
702 "fmovd$cc %fcc0, $F, $dst",
704 (SPselectfcc DFPRegs:$F, DFPRegs:$T, imm:$cc))]>;
708 // Floating-Point Move Instructions, p. 164 of the V9 manual.
709 let Predicates = [HasV9] in {
710 def FMOVD : F3_3<2, 0b110100, 0b000000010,
711 (outs DFPRegs:$dst), (ins DFPRegs:$src),
712 "fmovd $src, $dst", []>;
713 def FNEGD : F3_3<2, 0b110100, 0b000000110,
714 (outs DFPRegs:$dst), (ins DFPRegs:$src),
716 [(set DFPRegs:$dst, (fneg DFPRegs:$src))]>;
717 def FABSD : F3_3<2, 0b110100, 0b000001010,
718 (outs DFPRegs:$dst), (ins DFPRegs:$src),
720 [(set DFPRegs:$dst, (fabs DFPRegs:$src))]>;
723 // POPCrr - This does a ctpop of a 64-bit register. As such, we have to clear
724 // the top 32-bits before using it. To do this clearing, we use a SLLri X,0.
725 def POPCrr : F3_1<2, 0b101110,
726 (outs IntRegs:$dst), (ins IntRegs:$src),
727 "popc $src, $dst", []>, Requires<[HasV9]>;
728 def : Pat<(ctpop IntRegs:$src),
729 (POPCrr (SLLri IntRegs:$src, 0))>;
731 //===----------------------------------------------------------------------===//
732 // Non-Instruction Patterns
733 //===----------------------------------------------------------------------===//
736 def : Pat<(i32 simm13:$val),
737 (ORri G0, imm:$val)>;
738 // Arbitrary immediates.
739 def : Pat<(i32 imm:$val),
740 (ORri (SETHIi (HI22 imm:$val)), (LO10 imm:$val))>;
743 def : Pat<(subc IntRegs:$b, IntRegs:$c),
744 (SUBCCrr IntRegs:$b, IntRegs:$c)>;
745 def : Pat<(subc IntRegs:$b, simm13:$val),
746 (SUBCCri IntRegs:$b, imm:$val)>;
748 // Global addresses, constant pool entries
749 def : Pat<(SPhi tglobaladdr:$in), (SETHIi tglobaladdr:$in)>;
750 def : Pat<(SPlo tglobaladdr:$in), (ORri G0, tglobaladdr:$in)>;
751 def : Pat<(SPhi tconstpool:$in), (SETHIi tconstpool:$in)>;
752 def : Pat<(SPlo tconstpool:$in), (ORri G0, tconstpool:$in)>;
754 // Add reg, lo. This is used when taking the addr of a global/constpool entry.
755 def : Pat<(add IntRegs:$r, (SPlo tglobaladdr:$in)),
756 (ADDri IntRegs:$r, tglobaladdr:$in)>;
757 def : Pat<(add IntRegs:$r, (SPlo tconstpool:$in)),
758 (ADDri IntRegs:$r, tconstpool:$in)>;
761 def : Pat<(call tglobaladdr:$dst),
762 (CALL tglobaladdr:$dst)>;
763 def : Pat<(call texternalsym:$dst),
764 (CALL texternalsym:$dst)>;
766 // Map integer extload's to zextloads.
767 def : Pat<(i32 (extloadi1 ADDRrr:$src)), (LDUBrr ADDRrr:$src)>;
768 def : Pat<(i32 (extloadi1 ADDRri:$src)), (LDUBri ADDRri:$src)>;
769 def : Pat<(i32 (extloadi8 ADDRrr:$src)), (LDUBrr ADDRrr:$src)>;
770 def : Pat<(i32 (extloadi8 ADDRri:$src)), (LDUBri ADDRri:$src)>;
771 def : Pat<(i32 (extloadi16 ADDRrr:$src)), (LDUHrr ADDRrr:$src)>;
772 def : Pat<(i32 (extloadi16 ADDRri:$src)), (LDUHri ADDRri:$src)>;
774 // zextload bool -> zextload byte
775 def : Pat<(i32 (zextloadi1 ADDRrr:$src)), (LDUBrr ADDRrr:$src)>;
776 def : Pat<(i32 (zextloadi1 ADDRri:$src)), (LDUBri ADDRri:$src)>;