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), [{
47 // simm11 predicate - True if the imm fits in a 11-bit sign extended field.
48 return (((int)N->getZExtValue() << (32-11)) >> (32-11)) ==
49 (int)N->getZExtValue();
52 def simm13 : PatLeaf<(imm), [{
53 // simm13 predicate - True if the imm fits in a 13-bit sign extended field.
54 return (((int)N->getZExtValue() << (32-13)) >> (32-13)) ==
55 (int)N->getZExtValue();
58 def LO10 : SDNodeXForm<imm, [{
59 return CurDAG->getTargetConstant((unsigned)N->getZExtValue() & 1023,
63 def HI22 : SDNodeXForm<imm, [{
64 // Transformation function: shift the immediate value down into the low bits.
65 return CurDAG->getTargetConstant((unsigned)N->getZExtValue() >> 10, MVT::i32);
68 def SETHIimm : PatLeaf<(imm), [{
69 return (((unsigned)N->getZExtValue() >> 10) << 10) ==
70 (unsigned)N->getZExtValue();
74 def ADDRrr : ComplexPattern<i32, 2, "SelectADDRrr", [], []>;
75 def ADDRri : ComplexPattern<i32, 2, "SelectADDRri", [frameindex], []>;
78 def MEMrr : Operand<i32> {
79 let PrintMethod = "printMemOperand";
80 let MIOperandInfo = (ops IntRegs, IntRegs);
82 def MEMri : Operand<i32> {
83 let PrintMethod = "printMemOperand";
84 let MIOperandInfo = (ops IntRegs, i32imm);
87 // Branch targets have OtherVT type.
88 def brtarget : Operand<OtherVT>;
89 def calltarget : Operand<i32>;
91 // Operand for printing out a condition code.
92 let PrintMethod = "printCCOperand" in
93 def CCOp : Operand<i32>;
96 SDTypeProfile<0, 2, [SDTCisFP<0>, SDTCisSameAs<0, 1>]>;
98 SDTypeProfile<0, 2, [SDTCisVT<0, OtherVT>, SDTCisVT<1, i32>]>;
100 SDTypeProfile<1, 3, [SDTCisSameAs<0, 1>, SDTCisSameAs<1, 2>, SDTCisVT<3, i32>]>;
102 SDTypeProfile<1, 1, [SDTCisVT<0, f32>, SDTCisFP<1>]>;
104 SDTypeProfile<1, 1, [SDTCisFP<0>, SDTCisVT<1, f32>]>;
106 def SPcmpicc : SDNode<"SPISD::CMPICC", SDTIntBinOp, [SDNPOutFlag]>;
107 def SPcmpfcc : SDNode<"SPISD::CMPFCC", SDTSPcmpfcc, [SDNPOutFlag]>;
108 def SPbricc : SDNode<"SPISD::BRICC", SDTSPbrcc, [SDNPHasChain, SDNPInFlag]>;
109 def SPbrfcc : SDNode<"SPISD::BRFCC", SDTSPbrcc, [SDNPHasChain, SDNPInFlag]>;
111 def SPhi : SDNode<"SPISD::Hi", SDTIntUnaryOp>;
112 def SPlo : SDNode<"SPISD::Lo", SDTIntUnaryOp>;
114 def SPftoi : SDNode<"SPISD::FTOI", SDTSPFTOI>;
115 def SPitof : SDNode<"SPISD::ITOF", SDTSPITOF>;
117 def SPselecticc : SDNode<"SPISD::SELECT_ICC", SDTSPselectcc, [SDNPInFlag]>;
118 def SPselectfcc : SDNode<"SPISD::SELECT_FCC", SDTSPselectcc, [SDNPInFlag]>;
120 // These are target-independent nodes, but have target-specific formats.
121 def SDT_SPCallSeqStart : SDCallSeqStart<[ SDTCisVT<0, i32> ]>;
122 def SDT_SPCallSeqEnd : SDCallSeqEnd<[ SDTCisVT<0, i32>,
125 def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_SPCallSeqStart,
126 [SDNPHasChain, SDNPOutFlag]>;
127 def callseq_end : SDNode<"ISD::CALLSEQ_END", SDT_SPCallSeqEnd,
128 [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
130 def SDT_SPCall : SDTypeProfile<0, 1, [SDTCisVT<0, i32>]>;
131 def call : SDNode<"SPISD::CALL", SDT_SPCall,
132 [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
134 def retflag : SDNode<"SPISD::RET_FLAG", SDTNone,
135 [SDNPHasChain, SDNPOptInFlag]>;
137 //===----------------------------------------------------------------------===//
138 // SPARC Flag Conditions
139 //===----------------------------------------------------------------------===//
141 // Note that these values must be kept in sync with the CCOp::CondCode enum
143 class ICC_VAL<int N> : PatLeaf<(i32 N)>;
144 def ICC_NE : ICC_VAL< 9>; // Not Equal
145 def ICC_E : ICC_VAL< 1>; // Equal
146 def ICC_G : ICC_VAL<10>; // Greater
147 def ICC_LE : ICC_VAL< 2>; // Less or Equal
148 def ICC_GE : ICC_VAL<11>; // Greater or Equal
149 def ICC_L : ICC_VAL< 3>; // Less
150 def ICC_GU : ICC_VAL<12>; // Greater Unsigned
151 def ICC_LEU : ICC_VAL< 4>; // Less or Equal Unsigned
152 def ICC_CC : ICC_VAL<13>; // Carry Clear/Great or Equal Unsigned
153 def ICC_CS : ICC_VAL< 5>; // Carry Set/Less Unsigned
154 def ICC_POS : ICC_VAL<14>; // Positive
155 def ICC_NEG : ICC_VAL< 6>; // Negative
156 def ICC_VC : ICC_VAL<15>; // Overflow Clear
157 def ICC_VS : ICC_VAL< 7>; // Overflow Set
159 class FCC_VAL<int N> : PatLeaf<(i32 N)>;
160 def FCC_U : FCC_VAL<23>; // Unordered
161 def FCC_G : FCC_VAL<22>; // Greater
162 def FCC_UG : FCC_VAL<21>; // Unordered or Greater
163 def FCC_L : FCC_VAL<20>; // Less
164 def FCC_UL : FCC_VAL<19>; // Unordered or Less
165 def FCC_LG : FCC_VAL<18>; // Less or Greater
166 def FCC_NE : FCC_VAL<17>; // Not Equal
167 def FCC_E : FCC_VAL<25>; // Equal
168 def FCC_UE : FCC_VAL<24>; // Unordered or Equal
169 def FCC_GE : FCC_VAL<25>; // Greater or Equal
170 def FCC_UGE : FCC_VAL<26>; // Unordered or Greater or Equal
171 def FCC_LE : FCC_VAL<27>; // Less or Equal
172 def FCC_ULE : FCC_VAL<28>; // Unordered or Less or Equal
173 def FCC_O : FCC_VAL<29>; // Ordered
175 //===----------------------------------------------------------------------===//
176 // Instruction Class Templates
177 //===----------------------------------------------------------------------===//
179 /// F3_12 multiclass - Define a normal F3_1/F3_2 pattern in one shot.
180 multiclass F3_12<string OpcStr, bits<6> Op3Val, SDNode OpNode> {
181 def rr : F3_1<2, Op3Val,
182 (outs IntRegs:$dst), (ins IntRegs:$b, IntRegs:$c),
183 !strconcat(OpcStr, " $b, $c, $dst"),
184 [(set IntRegs:$dst, (OpNode IntRegs:$b, IntRegs:$c))]>;
185 def ri : F3_2<2, Op3Val,
186 (outs IntRegs:$dst), (ins IntRegs:$b, i32imm:$c),
187 !strconcat(OpcStr, " $b, $c, $dst"),
188 [(set IntRegs:$dst, (OpNode IntRegs:$b, simm13:$c))]>;
191 /// F3_12np multiclass - Define a normal F3_1/F3_2 pattern in one shot, with no
193 multiclass F3_12np<string OpcStr, bits<6> Op3Val> {
194 def rr : F3_1<2, Op3Val,
195 (outs IntRegs:$dst), (ins IntRegs:$b, IntRegs:$c),
196 !strconcat(OpcStr, " $b, $c, $dst"), []>;
197 def ri : F3_2<2, Op3Val,
198 (outs IntRegs:$dst), (ins IntRegs:$b, i32imm:$c),
199 !strconcat(OpcStr, " $b, $c, $dst"), []>;
202 //===----------------------------------------------------------------------===//
204 //===----------------------------------------------------------------------===//
206 // Pseudo instructions.
207 class Pseudo<dag outs, dag ins, string asmstr, list<dag> pattern>
208 : InstSP<outs, ins, asmstr, pattern>;
210 let Defs = [O6], Uses = [O6] in {
211 def ADJCALLSTACKDOWN : Pseudo<(outs), (ins i32imm:$amt),
212 "!ADJCALLSTACKDOWN $amt",
213 [(callseq_start timm:$amt)]>;
214 def ADJCALLSTACKUP : Pseudo<(outs), (ins i32imm:$amt1, i32imm:$amt2),
215 "!ADJCALLSTACKUP $amt1",
216 [(callseq_end timm:$amt1, timm:$amt2)]>;
219 // FpMOVD/FpNEGD/FpABSD - These are lowered to single-precision ops by the
221 let Predicates = [HasNoV9] in { // Only emit these in V8 mode.
222 def FpMOVD : Pseudo<(outs DFPRegs:$dst), (ins DFPRegs:$src),
223 "!FpMOVD $src, $dst", []>;
224 def FpNEGD : Pseudo<(outs DFPRegs:$dst), (ins DFPRegs:$src),
225 "!FpNEGD $src, $dst",
226 [(set DFPRegs:$dst, (fneg DFPRegs:$src))]>;
227 def FpABSD : Pseudo<(outs DFPRegs:$dst), (ins DFPRegs:$src),
228 "!FpABSD $src, $dst",
229 [(set DFPRegs:$dst, (fabs DFPRegs:$src))]>;
232 // SELECT_CC_* - Used to implement the SELECT_CC DAG operation. Expanded by the
233 // scheduler into a branch sequence. This has to handle all permutations of
234 // selection between i32/f32/f64 on ICC and FCC.
235 let usesCustomDAGSchedInserter = 1 in { // Expanded by the scheduler.
236 def SELECT_CC_Int_ICC
237 : Pseudo<(outs IntRegs:$dst), (ins IntRegs:$T, IntRegs:$F, i32imm:$Cond),
238 "; SELECT_CC_Int_ICC PSEUDO!",
239 [(set IntRegs:$dst, (SPselecticc IntRegs:$T, IntRegs:$F,
241 def SELECT_CC_Int_FCC
242 : Pseudo<(outs IntRegs:$dst), (ins IntRegs:$T, IntRegs:$F, i32imm:$Cond),
243 "; SELECT_CC_Int_FCC PSEUDO!",
244 [(set IntRegs:$dst, (SPselectfcc IntRegs:$T, IntRegs:$F,
247 : Pseudo<(outs FPRegs:$dst), (ins FPRegs:$T, FPRegs:$F, i32imm:$Cond),
248 "; SELECT_CC_FP_ICC PSEUDO!",
249 [(set FPRegs:$dst, (SPselecticc FPRegs:$T, FPRegs:$F,
252 : Pseudo<(outs FPRegs:$dst), (ins FPRegs:$T, FPRegs:$F, i32imm:$Cond),
253 "; SELECT_CC_FP_FCC PSEUDO!",
254 [(set FPRegs:$dst, (SPselectfcc FPRegs:$T, FPRegs:$F,
256 def SELECT_CC_DFP_ICC
257 : Pseudo<(outs DFPRegs:$dst), (ins DFPRegs:$T, DFPRegs:$F, i32imm:$Cond),
258 "; SELECT_CC_DFP_ICC PSEUDO!",
259 [(set DFPRegs:$dst, (SPselecticc DFPRegs:$T, DFPRegs:$F,
261 def SELECT_CC_DFP_FCC
262 : Pseudo<(outs DFPRegs:$dst), (ins DFPRegs:$T, DFPRegs:$F, i32imm:$Cond),
263 "; SELECT_CC_DFP_FCC PSEUDO!",
264 [(set DFPRegs:$dst, (SPselectfcc DFPRegs:$T, DFPRegs:$F,
269 // Section A.3 - Synthetic Instructions, p. 85
270 // special cases of JMPL:
271 let isReturn = 1, isTerminator = 1, hasDelaySlot = 1 in {
272 let rd = O7.Num, rs1 = G0.Num, simm13 = 8 in
273 def RETL: F3_2<2, 0b111000, (outs), (ins), "retl", [(retflag)]>;
276 // Section B.1 - Load Integer Instructions, p. 90
277 def LDSBrr : F3_1<3, 0b001001,
278 (outs IntRegs:$dst), (ins MEMrr:$addr),
279 "ldsb [$addr], $dst",
280 [(set IntRegs:$dst, (sextloadi8 ADDRrr:$addr))]>;
281 def LDSBri : F3_2<3, 0b001001,
282 (outs IntRegs:$dst), (ins MEMri:$addr),
283 "ldsb [$addr], $dst",
284 [(set IntRegs:$dst, (sextloadi8 ADDRri:$addr))]>;
285 def LDSHrr : F3_1<3, 0b001010,
286 (outs IntRegs:$dst), (ins MEMrr:$addr),
287 "ldsh [$addr], $dst",
288 [(set IntRegs:$dst, (sextloadi16 ADDRrr:$addr))]>;
289 def LDSHri : F3_2<3, 0b001010,
290 (outs IntRegs:$dst), (ins MEMri:$addr),
291 "ldsh [$addr], $dst",
292 [(set IntRegs:$dst, (sextloadi16 ADDRri:$addr))]>;
293 def LDUBrr : F3_1<3, 0b000001,
294 (outs IntRegs:$dst), (ins MEMrr:$addr),
295 "ldub [$addr], $dst",
296 [(set IntRegs:$dst, (zextloadi8 ADDRrr:$addr))]>;
297 def LDUBri : F3_2<3, 0b000001,
298 (outs IntRegs:$dst), (ins MEMri:$addr),
299 "ldub [$addr], $dst",
300 [(set IntRegs:$dst, (zextloadi8 ADDRri:$addr))]>;
301 def LDUHrr : F3_1<3, 0b000010,
302 (outs IntRegs:$dst), (ins MEMrr:$addr),
303 "lduh [$addr], $dst",
304 [(set IntRegs:$dst, (zextloadi16 ADDRrr:$addr))]>;
305 def LDUHri : F3_2<3, 0b000010,
306 (outs IntRegs:$dst), (ins MEMri:$addr),
307 "lduh [$addr], $dst",
308 [(set IntRegs:$dst, (zextloadi16 ADDRri:$addr))]>;
309 def LDrr : F3_1<3, 0b000000,
310 (outs IntRegs:$dst), (ins MEMrr:$addr),
312 [(set IntRegs:$dst, (load ADDRrr:$addr))]>;
313 def LDri : F3_2<3, 0b000000,
314 (outs IntRegs:$dst), (ins MEMri:$addr),
316 [(set IntRegs:$dst, (load ADDRri:$addr))]>;
318 // Section B.2 - Load Floating-point Instructions, p. 92
319 def LDFrr : F3_1<3, 0b100000,
320 (outs FPRegs:$dst), (ins MEMrr:$addr),
322 [(set FPRegs:$dst, (load ADDRrr:$addr))]>;
323 def LDFri : F3_2<3, 0b100000,
324 (outs FPRegs:$dst), (ins MEMri:$addr),
326 [(set FPRegs:$dst, (load ADDRri:$addr))]>;
327 def LDDFrr : F3_1<3, 0b100011,
328 (outs DFPRegs:$dst), (ins MEMrr:$addr),
330 [(set DFPRegs:$dst, (load ADDRrr:$addr))]>;
331 def LDDFri : F3_2<3, 0b100011,
332 (outs DFPRegs:$dst), (ins MEMri:$addr),
334 [(set DFPRegs:$dst, (load ADDRri:$addr))]>;
336 // Section B.4 - Store Integer Instructions, p. 95
337 def STBrr : F3_1<3, 0b000101,
338 (outs), (ins MEMrr:$addr, IntRegs:$src),
340 [(truncstorei8 IntRegs:$src, ADDRrr:$addr)]>;
341 def STBri : F3_2<3, 0b000101,
342 (outs), (ins MEMri:$addr, IntRegs:$src),
344 [(truncstorei8 IntRegs:$src, ADDRri:$addr)]>;
345 def STHrr : F3_1<3, 0b000110,
346 (outs), (ins MEMrr:$addr, IntRegs:$src),
348 [(truncstorei16 IntRegs:$src, ADDRrr:$addr)]>;
349 def STHri : F3_2<3, 0b000110,
350 (outs), (ins MEMri:$addr, IntRegs:$src),
352 [(truncstorei16 IntRegs:$src, ADDRri:$addr)]>;
353 def STrr : F3_1<3, 0b000100,
354 (outs), (ins MEMrr:$addr, IntRegs:$src),
356 [(store IntRegs:$src, ADDRrr:$addr)]>;
357 def STri : F3_2<3, 0b000100,
358 (outs), (ins MEMri:$addr, IntRegs:$src),
360 [(store IntRegs:$src, ADDRri:$addr)]>;
362 // Section B.5 - Store Floating-point Instructions, p. 97
363 def STFrr : F3_1<3, 0b100100,
364 (outs), (ins MEMrr:$addr, FPRegs:$src),
366 [(store FPRegs:$src, ADDRrr:$addr)]>;
367 def STFri : F3_2<3, 0b100100,
368 (outs), (ins MEMri:$addr, FPRegs:$src),
370 [(store FPRegs:$src, ADDRri:$addr)]>;
371 def STDFrr : F3_1<3, 0b100111,
372 (outs), (ins MEMrr:$addr, DFPRegs:$src),
374 [(store DFPRegs:$src, ADDRrr:$addr)]>;
375 def STDFri : F3_2<3, 0b100111,
376 (outs), (ins MEMri:$addr, DFPRegs:$src),
378 [(store DFPRegs:$src, ADDRri:$addr)]>;
380 // Section B.9 - SETHI Instruction, p. 104
381 def SETHIi: F2_1<0b100,
382 (outs IntRegs:$dst), (ins i32imm:$src),
384 [(set IntRegs:$dst, SETHIimm:$src)]>;
386 // Section B.10 - NOP Instruction, p. 105
387 // (It's a special case of SETHI)
388 let rd = 0, imm22 = 0 in
389 def NOP : F2_1<0b100, (outs), (ins), "nop", []>;
391 // Section B.11 - Logical Instructions, p. 106
392 defm AND : F3_12<"and", 0b000001, and>;
394 def ANDNrr : F3_1<2, 0b000101,
395 (outs IntRegs:$dst), (ins IntRegs:$b, IntRegs:$c),
397 [(set IntRegs:$dst, (and IntRegs:$b, (not IntRegs:$c)))]>;
398 def ANDNri : F3_2<2, 0b000101,
399 (outs IntRegs:$dst), (ins IntRegs:$b, i32imm:$c),
400 "andn $b, $c, $dst", []>;
402 defm OR : F3_12<"or", 0b000010, or>;
404 def ORNrr : F3_1<2, 0b000110,
405 (outs IntRegs:$dst), (ins IntRegs:$b, IntRegs:$c),
407 [(set IntRegs:$dst, (or IntRegs:$b, (not IntRegs:$c)))]>;
408 def ORNri : F3_2<2, 0b000110,
409 (outs IntRegs:$dst), (ins IntRegs:$b, i32imm:$c),
410 "orn $b, $c, $dst", []>;
411 defm XOR : F3_12<"xor", 0b000011, xor>;
413 def XNORrr : F3_1<2, 0b000111,
414 (outs IntRegs:$dst), (ins IntRegs:$b, IntRegs:$c),
416 [(set IntRegs:$dst, (not (xor IntRegs:$b, IntRegs:$c)))]>;
417 def XNORri : F3_2<2, 0b000111,
418 (outs IntRegs:$dst), (ins IntRegs:$b, i32imm:$c),
419 "xnor $b, $c, $dst", []>;
421 // Section B.12 - Shift Instructions, p. 107
422 defm SLL : F3_12<"sll", 0b100101, shl>;
423 defm SRL : F3_12<"srl", 0b100110, srl>;
424 defm SRA : F3_12<"sra", 0b100111, sra>;
426 // Section B.13 - Add Instructions, p. 108
427 defm ADD : F3_12<"add", 0b000000, add>;
429 // "LEA" forms of add (patterns to make tblgen happy)
430 def LEA_ADDri : F3_2<2, 0b000000,
431 (outs IntRegs:$dst), (ins MEMri:$addr),
432 "add ${addr:arith}, $dst",
433 [(set IntRegs:$dst, ADDRri:$addr)]>;
435 defm ADDCC : F3_12<"addcc", 0b010000, addc>;
436 defm ADDX : F3_12<"addx", 0b001000, adde>;
438 // Section B.15 - Subtract Instructions, p. 110
439 defm SUB : F3_12 <"sub" , 0b000100, sub>;
440 defm SUBX : F3_12 <"subx" , 0b001100, sube>;
441 defm SUBCC : F3_12 <"subcc", 0b010100, SPcmpicc>;
443 def SUBXCCrr: F3_1<2, 0b011100,
444 (outs IntRegs:$dst), (ins IntRegs:$b, IntRegs:$c),
445 "subxcc $b, $c, $dst", []>;
447 // Section B.18 - Multiply Instructions, p. 113
448 defm UMUL : F3_12np<"umul", 0b001010>;
449 defm SMUL : F3_12 <"smul", 0b001011, mul>;
452 // Section B.19 - Divide Instructions, p. 115
453 defm UDIV : F3_12np<"udiv", 0b001110>;
454 defm SDIV : F3_12np<"sdiv", 0b001111>;
456 // Section B.20 - SAVE and RESTORE, p. 117
457 defm SAVE : F3_12np<"save" , 0b111100>;
458 defm RESTORE : F3_12np<"restore", 0b111101>;
460 // Section B.21 - Branch on Integer Condition Codes Instructions, p. 119
462 // conditional branch class:
463 class BranchSP<bits<4> cc, dag ins, string asmstr, list<dag> pattern>
464 : F2_2<cc, 0b010, (outs), ins, asmstr, pattern> {
466 let isTerminator = 1;
467 let hasDelaySlot = 1;
471 def BA : BranchSP<0b1000, (ins brtarget:$dst),
475 // FIXME: the encoding for the JIT should look at the condition field.
476 def BCOND : BranchSP<0, (ins brtarget:$dst, CCOp:$cc),
478 [(SPbricc bb:$dst, imm:$cc)]>;
481 // Section B.22 - Branch on Floating-point Condition Codes Instructions, p. 121
483 // floating-point conditional branch class:
484 class FPBranchSP<bits<4> cc, dag ins, string asmstr, list<dag> pattern>
485 : F2_2<cc, 0b110, (outs), ins, asmstr, pattern> {
487 let isTerminator = 1;
488 let hasDelaySlot = 1;
491 // FIXME: the encoding for the JIT should look at the condition field.
492 def FBCOND : FPBranchSP<0, (ins brtarget:$dst, CCOp:$cc),
494 [(SPbrfcc bb:$dst, imm:$cc)]>;
497 // Section B.24 - Call and Link Instruction, p. 125
498 // This is the only Format 1 instruction
499 let Uses = [O0, O1, O2, O3, O4, O5],
500 hasDelaySlot = 1, isCall = 1,
501 Defs = [O0, O1, O2, O3, O4, O5, O7, G1, G2, G3, G4, G5, G6, G7,
502 D0, D1, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11, D12, D13, D14, D15] in {
503 def CALL : InstSP<(outs), (ins calltarget:$dst),
507 let Inst{29-0} = disp;
511 def JMPLrr : F3_1<2, 0b111000,
512 (outs), (ins MEMrr:$ptr),
514 [(call ADDRrr:$ptr)]>;
515 def JMPLri : F3_2<2, 0b111000,
516 (outs), (ins MEMri:$ptr),
518 [(call ADDRri:$ptr)]>;
521 // Section B.28 - Read State Register Instructions
522 def RDY : F3_1<2, 0b101000,
523 (outs IntRegs:$dst), (ins),
526 // Section B.29 - Write State Register Instructions
527 def WRYrr : F3_1<2, 0b110000,
528 (outs), (ins IntRegs:$b, IntRegs:$c),
529 "wr $b, $c, %y", []>;
530 def WRYri : F3_2<2, 0b110000,
531 (outs), (ins IntRegs:$b, i32imm:$c),
532 "wr $b, $c, %y", []>;
534 // Convert Integer to Floating-point Instructions, p. 141
535 def FITOS : F3_3<2, 0b110100, 0b011000100,
536 (outs FPRegs:$dst), (ins FPRegs:$src),
538 [(set FPRegs:$dst, (SPitof FPRegs:$src))]>;
539 def FITOD : F3_3<2, 0b110100, 0b011001000,
540 (outs DFPRegs:$dst), (ins FPRegs:$src),
542 [(set DFPRegs:$dst, (SPitof FPRegs:$src))]>;
544 // Convert Floating-point to Integer Instructions, p. 142
545 def FSTOI : F3_3<2, 0b110100, 0b011010001,
546 (outs FPRegs:$dst), (ins FPRegs:$src),
548 [(set FPRegs:$dst, (SPftoi FPRegs:$src))]>;
549 def FDTOI : F3_3<2, 0b110100, 0b011010010,
550 (outs FPRegs:$dst), (ins DFPRegs:$src),
552 [(set FPRegs:$dst, (SPftoi DFPRegs:$src))]>;
554 // Convert between Floating-point Formats Instructions, p. 143
555 def FSTOD : F3_3<2, 0b110100, 0b011001001,
556 (outs DFPRegs:$dst), (ins FPRegs:$src),
558 [(set DFPRegs:$dst, (fextend FPRegs:$src))]>;
559 def FDTOS : F3_3<2, 0b110100, 0b011000110,
560 (outs FPRegs:$dst), (ins DFPRegs:$src),
562 [(set FPRegs:$dst, (fround DFPRegs:$src))]>;
564 // Floating-point Move Instructions, p. 144
565 def FMOVS : F3_3<2, 0b110100, 0b000000001,
566 (outs FPRegs:$dst), (ins FPRegs:$src),
567 "fmovs $src, $dst", []>;
568 def FNEGS : F3_3<2, 0b110100, 0b000000101,
569 (outs FPRegs:$dst), (ins FPRegs:$src),
571 [(set FPRegs:$dst, (fneg FPRegs:$src))]>;
572 def FABSS : F3_3<2, 0b110100, 0b000001001,
573 (outs FPRegs:$dst), (ins FPRegs:$src),
575 [(set FPRegs:$dst, (fabs FPRegs:$src))]>;
578 // Floating-point Square Root Instructions, p.145
579 def FSQRTS : F3_3<2, 0b110100, 0b000101001,
580 (outs FPRegs:$dst), (ins FPRegs:$src),
582 [(set FPRegs:$dst, (fsqrt FPRegs:$src))]>;
583 def FSQRTD : F3_3<2, 0b110100, 0b000101010,
584 (outs DFPRegs:$dst), (ins DFPRegs:$src),
586 [(set DFPRegs:$dst, (fsqrt DFPRegs:$src))]>;
590 // Floating-point Add and Subtract Instructions, p. 146
591 def FADDS : F3_3<2, 0b110100, 0b001000001,
592 (outs FPRegs:$dst), (ins FPRegs:$src1, FPRegs:$src2),
593 "fadds $src1, $src2, $dst",
594 [(set FPRegs:$dst, (fadd FPRegs:$src1, FPRegs:$src2))]>;
595 def FADDD : F3_3<2, 0b110100, 0b001000010,
596 (outs DFPRegs:$dst), (ins DFPRegs:$src1, DFPRegs:$src2),
597 "faddd $src1, $src2, $dst",
598 [(set DFPRegs:$dst, (fadd DFPRegs:$src1, DFPRegs:$src2))]>;
599 def FSUBS : F3_3<2, 0b110100, 0b001000101,
600 (outs FPRegs:$dst), (ins FPRegs:$src1, FPRegs:$src2),
601 "fsubs $src1, $src2, $dst",
602 [(set FPRegs:$dst, (fsub FPRegs:$src1, FPRegs:$src2))]>;
603 def FSUBD : F3_3<2, 0b110100, 0b001000110,
604 (outs DFPRegs:$dst), (ins DFPRegs:$src1, DFPRegs:$src2),
605 "fsubd $src1, $src2, $dst",
606 [(set DFPRegs:$dst, (fsub DFPRegs:$src1, DFPRegs:$src2))]>;
608 // Floating-point Multiply and Divide Instructions, p. 147
609 def FMULS : F3_3<2, 0b110100, 0b001001001,
610 (outs FPRegs:$dst), (ins FPRegs:$src1, FPRegs:$src2),
611 "fmuls $src1, $src2, $dst",
612 [(set FPRegs:$dst, (fmul FPRegs:$src1, FPRegs:$src2))]>;
613 def FMULD : F3_3<2, 0b110100, 0b001001010,
614 (outs DFPRegs:$dst), (ins DFPRegs:$src1, DFPRegs:$src2),
615 "fmuld $src1, $src2, $dst",
616 [(set DFPRegs:$dst, (fmul DFPRegs:$src1, DFPRegs:$src2))]>;
617 def FSMULD : F3_3<2, 0b110100, 0b001101001,
618 (outs DFPRegs:$dst), (ins FPRegs:$src1, FPRegs:$src2),
619 "fsmuld $src1, $src2, $dst",
620 [(set DFPRegs:$dst, (fmul (fextend FPRegs:$src1),
621 (fextend FPRegs:$src2)))]>;
622 def FDIVS : F3_3<2, 0b110100, 0b001001101,
623 (outs FPRegs:$dst), (ins FPRegs:$src1, FPRegs:$src2),
624 "fdivs $src1, $src2, $dst",
625 [(set FPRegs:$dst, (fdiv FPRegs:$src1, FPRegs:$src2))]>;
626 def FDIVD : F3_3<2, 0b110100, 0b001001110,
627 (outs DFPRegs:$dst), (ins DFPRegs:$src1, DFPRegs:$src2),
628 "fdivd $src1, $src2, $dst",
629 [(set DFPRegs:$dst, (fdiv DFPRegs:$src1, DFPRegs:$src2))]>;
631 // Floating-point Compare Instructions, p. 148
632 // Note: the 2nd template arg is different for these guys.
633 // Note 2: the result of a FCMP is not available until the 2nd cycle
634 // after the instr is retired, but there is no interlock. This behavior
635 // is modelled with a forced noop after the instruction.
636 def FCMPS : F3_3<2, 0b110101, 0b001010001,
637 (outs), (ins FPRegs:$src1, FPRegs:$src2),
638 "fcmps $src1, $src2\n\tnop",
639 [(SPcmpfcc FPRegs:$src1, FPRegs:$src2)]>;
640 def FCMPD : F3_3<2, 0b110101, 0b001010010,
641 (outs), (ins DFPRegs:$src1, DFPRegs:$src2),
642 "fcmpd $src1, $src2\n\tnop",
643 [(SPcmpfcc DFPRegs:$src1, DFPRegs:$src2)]>;
646 //===----------------------------------------------------------------------===//
648 //===----------------------------------------------------------------------===//
650 // V9 Conditional Moves.
651 let Predicates = [HasV9], isTwoAddress = 1 in {
652 // Move Integer Register on Condition (MOVcc) p. 194 of the V9 manual.
653 // FIXME: Add instruction encodings for the JIT some day.
655 : Pseudo<(outs IntRegs:$dst), (ins IntRegs:$T, IntRegs:$F, CCOp:$cc),
656 "mov$cc %icc, $F, $dst",
658 (SPselecticc IntRegs:$F, IntRegs:$T, imm:$cc))]>;
660 : Pseudo<(outs IntRegs:$dst), (ins IntRegs:$T, i32imm:$F, CCOp:$cc),
661 "mov$cc %icc, $F, $dst",
663 (SPselecticc simm11:$F, IntRegs:$T, imm:$cc))]>;
666 : Pseudo<(outs IntRegs:$dst), (ins IntRegs:$T, IntRegs:$F, CCOp:$cc),
667 "mov$cc %fcc0, $F, $dst",
669 (SPselectfcc IntRegs:$F, IntRegs:$T, imm:$cc))]>;
671 : Pseudo<(outs IntRegs:$dst), (ins IntRegs:$T, i32imm:$F, CCOp:$cc),
672 "mov$cc %fcc0, $F, $dst",
674 (SPselectfcc simm11:$F, IntRegs:$T, imm:$cc))]>;
677 : Pseudo<(outs FPRegs:$dst), (ins FPRegs:$T, FPRegs:$F, CCOp:$cc),
678 "fmovs$cc %icc, $F, $dst",
680 (SPselecticc FPRegs:$F, FPRegs:$T, imm:$cc))]>;
682 : Pseudo<(outs DFPRegs:$dst), (ins DFPRegs:$T, DFPRegs:$F, CCOp:$cc),
683 "fmovd$cc %icc, $F, $dst",
685 (SPselecticc DFPRegs:$F, DFPRegs:$T, imm:$cc))]>;
687 : Pseudo<(outs FPRegs:$dst), (ins FPRegs:$T, FPRegs:$F, CCOp:$cc),
688 "fmovs$cc %fcc0, $F, $dst",
690 (SPselectfcc FPRegs:$F, FPRegs:$T, imm:$cc))]>;
692 : Pseudo<(outs DFPRegs:$dst), (ins DFPRegs:$T, DFPRegs:$F, CCOp:$cc),
693 "fmovd$cc %fcc0, $F, $dst",
695 (SPselectfcc DFPRegs:$F, DFPRegs:$T, imm:$cc))]>;
699 // Floating-Point Move Instructions, p. 164 of the V9 manual.
700 let Predicates = [HasV9] in {
701 def FMOVD : F3_3<2, 0b110100, 0b000000010,
702 (outs DFPRegs:$dst), (ins DFPRegs:$src),
703 "fmovd $src, $dst", []>;
704 def FNEGD : F3_3<2, 0b110100, 0b000000110,
705 (outs DFPRegs:$dst), (ins DFPRegs:$src),
707 [(set DFPRegs:$dst, (fneg DFPRegs:$src))]>;
708 def FABSD : F3_3<2, 0b110100, 0b000001010,
709 (outs DFPRegs:$dst), (ins DFPRegs:$src),
711 [(set DFPRegs:$dst, (fabs DFPRegs:$src))]>;
714 // POPCrr - This does a ctpop of a 64-bit register. As such, we have to clear
715 // the top 32-bits before using it. To do this clearing, we use a SLLri X,0.
716 def POPCrr : F3_1<2, 0b101110,
717 (outs IntRegs:$dst), (ins IntRegs:$src),
718 "popc $src, $dst", []>, Requires<[HasV9]>;
719 def : Pat<(ctpop IntRegs:$src),
720 (POPCrr (SLLri IntRegs:$src, 0))>;
722 //===----------------------------------------------------------------------===//
723 // Non-Instruction Patterns
724 //===----------------------------------------------------------------------===//
727 def : Pat<(i32 simm13:$val),
728 (ORri G0, imm:$val)>;
729 // Arbitrary immediates.
730 def : Pat<(i32 imm:$val),
731 (ORri (SETHIi (HI22 imm:$val)), (LO10 imm:$val))>;
734 def : Pat<(subc IntRegs:$b, IntRegs:$c),
735 (SUBCCrr IntRegs:$b, IntRegs:$c)>;
736 def : Pat<(subc IntRegs:$b, simm13:$val),
737 (SUBCCri IntRegs:$b, imm:$val)>;
739 // Global addresses, constant pool entries
740 def : Pat<(SPhi tglobaladdr:$in), (SETHIi tglobaladdr:$in)>;
741 def : Pat<(SPlo tglobaladdr:$in), (ORri G0, tglobaladdr:$in)>;
742 def : Pat<(SPhi tconstpool:$in), (SETHIi tconstpool:$in)>;
743 def : Pat<(SPlo tconstpool:$in), (ORri G0, tconstpool:$in)>;
745 // Add reg, lo. This is used when taking the addr of a global/constpool entry.
746 def : Pat<(add IntRegs:$r, (SPlo tglobaladdr:$in)),
747 (ADDri IntRegs:$r, tglobaladdr:$in)>;
748 def : Pat<(add IntRegs:$r, (SPlo tconstpool:$in)),
749 (ADDri IntRegs:$r, tconstpool:$in)>;
752 def : Pat<(call tglobaladdr:$dst),
753 (CALL tglobaladdr:$dst)>;
754 def : Pat<(call texternalsym:$dst),
755 (CALL texternalsym:$dst)>;
757 def : Pat<(ret), (RETL)>;
759 // Map integer extload's to zextloads.
760 def : Pat<(i32 (extloadi1 ADDRrr:$src)), (LDUBrr ADDRrr:$src)>;
761 def : Pat<(i32 (extloadi1 ADDRri:$src)), (LDUBri ADDRri:$src)>;
762 def : Pat<(i32 (extloadi8 ADDRrr:$src)), (LDUBrr ADDRrr:$src)>;
763 def : Pat<(i32 (extloadi8 ADDRri:$src)), (LDUBri ADDRri:$src)>;
764 def : Pat<(i32 (extloadi16 ADDRrr:$src)), (LDUHrr ADDRrr:$src)>;
765 def : Pat<(i32 (extloadi16 ADDRri:$src)), (LDUHri ADDRri:$src)>;
767 // zextload bool -> zextload byte
768 def : Pat<(i32 (zextloadi1 ADDRrr:$src)), (LDUBrr ADDRrr:$src)>;
769 def : Pat<(i32 (zextloadi1 ADDRri:$src)), (LDUBri ADDRri:$src)>;