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 def getPCX : Operand<i32> {
138 let PrintMethod = "printGetPCX";
141 //===----------------------------------------------------------------------===//
142 // SPARC Flag Conditions
143 //===----------------------------------------------------------------------===//
145 // Note that these values must be kept in sync with the CCOp::CondCode enum
147 class ICC_VAL<int N> : PatLeaf<(i32 N)>;
148 def ICC_NE : ICC_VAL< 9>; // Not Equal
149 def ICC_E : ICC_VAL< 1>; // Equal
150 def ICC_G : ICC_VAL<10>; // Greater
151 def ICC_LE : ICC_VAL< 2>; // Less or Equal
152 def ICC_GE : ICC_VAL<11>; // Greater or Equal
153 def ICC_L : ICC_VAL< 3>; // Less
154 def ICC_GU : ICC_VAL<12>; // Greater Unsigned
155 def ICC_LEU : ICC_VAL< 4>; // Less or Equal Unsigned
156 def ICC_CC : ICC_VAL<13>; // Carry Clear/Great or Equal Unsigned
157 def ICC_CS : ICC_VAL< 5>; // Carry Set/Less Unsigned
158 def ICC_POS : ICC_VAL<14>; // Positive
159 def ICC_NEG : ICC_VAL< 6>; // Negative
160 def ICC_VC : ICC_VAL<15>; // Overflow Clear
161 def ICC_VS : ICC_VAL< 7>; // Overflow Set
163 class FCC_VAL<int N> : PatLeaf<(i32 N)>;
164 def FCC_U : FCC_VAL<23>; // Unordered
165 def FCC_G : FCC_VAL<22>; // Greater
166 def FCC_UG : FCC_VAL<21>; // Unordered or Greater
167 def FCC_L : FCC_VAL<20>; // Less
168 def FCC_UL : FCC_VAL<19>; // Unordered or Less
169 def FCC_LG : FCC_VAL<18>; // Less or Greater
170 def FCC_NE : FCC_VAL<17>; // Not Equal
171 def FCC_E : FCC_VAL<25>; // Equal
172 def FCC_UE : FCC_VAL<24>; // Unordered or Equal
173 def FCC_GE : FCC_VAL<25>; // Greater or Equal
174 def FCC_UGE : FCC_VAL<26>; // Unordered or Greater or Equal
175 def FCC_LE : FCC_VAL<27>; // Less or Equal
176 def FCC_ULE : FCC_VAL<28>; // Unordered or Less or Equal
177 def FCC_O : FCC_VAL<29>; // Ordered
179 //===----------------------------------------------------------------------===//
180 // Instruction Class Templates
181 //===----------------------------------------------------------------------===//
183 /// F3_12 multiclass - Define a normal F3_1/F3_2 pattern in one shot.
184 multiclass F3_12<string OpcStr, bits<6> Op3Val, SDNode OpNode> {
185 def rr : F3_1<2, Op3Val,
186 (outs IntRegs:$dst), (ins IntRegs:$b, IntRegs:$c),
187 !strconcat(OpcStr, " $b, $c, $dst"),
188 [(set IntRegs:$dst, (OpNode IntRegs:$b, IntRegs:$c))]>;
189 def ri : F3_2<2, Op3Val,
190 (outs IntRegs:$dst), (ins IntRegs:$b, i32imm:$c),
191 !strconcat(OpcStr, " $b, $c, $dst"),
192 [(set IntRegs:$dst, (OpNode IntRegs:$b, simm13:$c))]>;
195 /// F3_12np multiclass - Define a normal F3_1/F3_2 pattern in one shot, with no
197 multiclass F3_12np<string OpcStr, bits<6> Op3Val> {
198 def rr : F3_1<2, Op3Val,
199 (outs IntRegs:$dst), (ins IntRegs:$b, IntRegs:$c),
200 !strconcat(OpcStr, " $b, $c, $dst"), []>;
201 def ri : F3_2<2, Op3Val,
202 (outs IntRegs:$dst), (ins IntRegs:$b, i32imm:$c),
203 !strconcat(OpcStr, " $b, $c, $dst"), []>;
206 //===----------------------------------------------------------------------===//
208 //===----------------------------------------------------------------------===//
210 // Pseudo instructions.
211 class Pseudo<dag outs, dag ins, string asmstr, list<dag> pattern>
212 : InstSP<outs, ins, asmstr, pattern>;
215 let Defs = [O7], Uses = [O7] in {
216 def GETPCX : Pseudo<(outs getPCX:$getpcseq), (ins), "$getpcseq", [] >;
219 let Defs = [O6], Uses = [O6] in {
220 def ADJCALLSTACKDOWN : Pseudo<(outs), (ins i32imm:$amt),
221 "!ADJCALLSTACKDOWN $amt",
222 [(callseq_start timm:$amt)]>;
223 def ADJCALLSTACKUP : Pseudo<(outs), (ins i32imm:$amt1, i32imm:$amt2),
224 "!ADJCALLSTACKUP $amt1",
225 [(callseq_end timm:$amt1, timm:$amt2)]>;
228 // FpMOVD/FpNEGD/FpABSD - These are lowered to single-precision ops by the
230 let Predicates = [HasNoV9] in { // Only emit these in V8 mode.
231 def FpMOVD : Pseudo<(outs DFPRegs:$dst), (ins DFPRegs:$src),
232 "!FpMOVD $src, $dst", []>;
233 def FpNEGD : Pseudo<(outs DFPRegs:$dst), (ins DFPRegs:$src),
234 "!FpNEGD $src, $dst",
235 [(set DFPRegs:$dst, (fneg DFPRegs:$src))]>;
236 def FpABSD : Pseudo<(outs DFPRegs:$dst), (ins DFPRegs:$src),
237 "!FpABSD $src, $dst",
238 [(set DFPRegs:$dst, (fabs DFPRegs:$src))]>;
241 // SELECT_CC_* - Used to implement the SELECT_CC DAG operation. Expanded by the
242 // scheduler into a branch sequence. This has to handle all permutations of
243 // selection between i32/f32/f64 on ICC and FCC.
244 let usesCustomDAGSchedInserter = 1 in { // Expanded by the scheduler.
245 def SELECT_CC_Int_ICC
246 : Pseudo<(outs IntRegs:$dst), (ins IntRegs:$T, IntRegs:$F, i32imm:$Cond),
247 "; SELECT_CC_Int_ICC PSEUDO!",
248 [(set IntRegs:$dst, (SPselecticc IntRegs:$T, IntRegs:$F,
250 def SELECT_CC_Int_FCC
251 : Pseudo<(outs IntRegs:$dst), (ins IntRegs:$T, IntRegs:$F, i32imm:$Cond),
252 "; SELECT_CC_Int_FCC PSEUDO!",
253 [(set IntRegs:$dst, (SPselectfcc IntRegs:$T, IntRegs:$F,
256 : Pseudo<(outs FPRegs:$dst), (ins FPRegs:$T, FPRegs:$F, i32imm:$Cond),
257 "; SELECT_CC_FP_ICC PSEUDO!",
258 [(set FPRegs:$dst, (SPselecticc FPRegs:$T, FPRegs:$F,
261 : Pseudo<(outs FPRegs:$dst), (ins FPRegs:$T, FPRegs:$F, i32imm:$Cond),
262 "; SELECT_CC_FP_FCC PSEUDO!",
263 [(set FPRegs:$dst, (SPselectfcc FPRegs:$T, FPRegs:$F,
265 def SELECT_CC_DFP_ICC
266 : Pseudo<(outs DFPRegs:$dst), (ins DFPRegs:$T, DFPRegs:$F, i32imm:$Cond),
267 "; SELECT_CC_DFP_ICC PSEUDO!",
268 [(set DFPRegs:$dst, (SPselecticc DFPRegs:$T, DFPRegs:$F,
270 def SELECT_CC_DFP_FCC
271 : Pseudo<(outs DFPRegs:$dst), (ins DFPRegs:$T, DFPRegs:$F, i32imm:$Cond),
272 "; SELECT_CC_DFP_FCC PSEUDO!",
273 [(set DFPRegs:$dst, (SPselectfcc DFPRegs:$T, DFPRegs:$F,
278 // Section A.3 - Synthetic Instructions, p. 85
279 // special cases of JMPL:
280 let isReturn = 1, isTerminator = 1, hasDelaySlot = 1 in {
281 let rd = O7.Num, rs1 = G0.Num, simm13 = 8 in
282 def RETL: F3_2<2, 0b111000, (outs), (ins), "retl", [(retflag)]>;
285 // Section B.1 - Load Integer Instructions, p. 90
286 def LDSBrr : F3_1<3, 0b001001,
287 (outs IntRegs:$dst), (ins MEMrr:$addr),
288 "ldsb [$addr], $dst",
289 [(set IntRegs:$dst, (sextloadi8 ADDRrr:$addr))]>;
290 def LDSBri : F3_2<3, 0b001001,
291 (outs IntRegs:$dst), (ins MEMri:$addr),
292 "ldsb [$addr], $dst",
293 [(set IntRegs:$dst, (sextloadi8 ADDRri:$addr))]>;
294 def LDSHrr : F3_1<3, 0b001010,
295 (outs IntRegs:$dst), (ins MEMrr:$addr),
296 "ldsh [$addr], $dst",
297 [(set IntRegs:$dst, (sextloadi16 ADDRrr:$addr))]>;
298 def LDSHri : F3_2<3, 0b001010,
299 (outs IntRegs:$dst), (ins MEMri:$addr),
300 "ldsh [$addr], $dst",
301 [(set IntRegs:$dst, (sextloadi16 ADDRri:$addr))]>;
302 def LDUBrr : F3_1<3, 0b000001,
303 (outs IntRegs:$dst), (ins MEMrr:$addr),
304 "ldub [$addr], $dst",
305 [(set IntRegs:$dst, (zextloadi8 ADDRrr:$addr))]>;
306 def LDUBri : F3_2<3, 0b000001,
307 (outs IntRegs:$dst), (ins MEMri:$addr),
308 "ldub [$addr], $dst",
309 [(set IntRegs:$dst, (zextloadi8 ADDRri:$addr))]>;
310 def LDUHrr : F3_1<3, 0b000010,
311 (outs IntRegs:$dst), (ins MEMrr:$addr),
312 "lduh [$addr], $dst",
313 [(set IntRegs:$dst, (zextloadi16 ADDRrr:$addr))]>;
314 def LDUHri : F3_2<3, 0b000010,
315 (outs IntRegs:$dst), (ins MEMri:$addr),
316 "lduh [$addr], $dst",
317 [(set IntRegs:$dst, (zextloadi16 ADDRri:$addr))]>;
318 def LDrr : F3_1<3, 0b000000,
319 (outs IntRegs:$dst), (ins MEMrr:$addr),
321 [(set IntRegs:$dst, (load ADDRrr:$addr))]>;
322 def LDri : F3_2<3, 0b000000,
323 (outs IntRegs:$dst), (ins MEMri:$addr),
325 [(set IntRegs:$dst, (load ADDRri:$addr))]>;
327 // Section B.2 - Load Floating-point Instructions, p. 92
328 def LDFrr : F3_1<3, 0b100000,
329 (outs FPRegs:$dst), (ins MEMrr:$addr),
331 [(set FPRegs:$dst, (load ADDRrr:$addr))]>;
332 def LDFri : F3_2<3, 0b100000,
333 (outs FPRegs:$dst), (ins MEMri:$addr),
335 [(set FPRegs:$dst, (load ADDRri:$addr))]>;
336 def LDDFrr : F3_1<3, 0b100011,
337 (outs DFPRegs:$dst), (ins MEMrr:$addr),
339 [(set DFPRegs:$dst, (load ADDRrr:$addr))]>;
340 def LDDFri : F3_2<3, 0b100011,
341 (outs DFPRegs:$dst), (ins MEMri:$addr),
343 [(set DFPRegs:$dst, (load ADDRri:$addr))]>;
345 // Section B.4 - Store Integer Instructions, p. 95
346 def STBrr : F3_1<3, 0b000101,
347 (outs), (ins MEMrr:$addr, IntRegs:$src),
349 [(truncstorei8 IntRegs:$src, ADDRrr:$addr)]>;
350 def STBri : F3_2<3, 0b000101,
351 (outs), (ins MEMri:$addr, IntRegs:$src),
353 [(truncstorei8 IntRegs:$src, ADDRri:$addr)]>;
354 def STHrr : F3_1<3, 0b000110,
355 (outs), (ins MEMrr:$addr, IntRegs:$src),
357 [(truncstorei16 IntRegs:$src, ADDRrr:$addr)]>;
358 def STHri : F3_2<3, 0b000110,
359 (outs), (ins MEMri:$addr, IntRegs:$src),
361 [(truncstorei16 IntRegs:$src, ADDRri:$addr)]>;
362 def STrr : F3_1<3, 0b000100,
363 (outs), (ins MEMrr:$addr, IntRegs:$src),
365 [(store IntRegs:$src, ADDRrr:$addr)]>;
366 def STri : F3_2<3, 0b000100,
367 (outs), (ins MEMri:$addr, IntRegs:$src),
369 [(store IntRegs:$src, ADDRri:$addr)]>;
371 // Section B.5 - Store Floating-point Instructions, p. 97
372 def STFrr : F3_1<3, 0b100100,
373 (outs), (ins MEMrr:$addr, FPRegs:$src),
375 [(store FPRegs:$src, ADDRrr:$addr)]>;
376 def STFri : F3_2<3, 0b100100,
377 (outs), (ins MEMri:$addr, FPRegs:$src),
379 [(store FPRegs:$src, ADDRri:$addr)]>;
380 def STDFrr : F3_1<3, 0b100111,
381 (outs), (ins MEMrr:$addr, DFPRegs:$src),
383 [(store DFPRegs:$src, ADDRrr:$addr)]>;
384 def STDFri : F3_2<3, 0b100111,
385 (outs), (ins MEMri:$addr, DFPRegs:$src),
387 [(store DFPRegs:$src, ADDRri:$addr)]>;
389 // Section B.9 - SETHI Instruction, p. 104
390 def SETHIi: F2_1<0b100,
391 (outs IntRegs:$dst), (ins i32imm:$src),
393 [(set IntRegs:$dst, SETHIimm:$src)]>;
395 // Section B.10 - NOP Instruction, p. 105
396 // (It's a special case of SETHI)
397 let rd = 0, imm22 = 0 in
398 def NOP : F2_1<0b100, (outs), (ins), "nop", []>;
400 // Section B.11 - Logical Instructions, p. 106
401 defm AND : F3_12<"and", 0b000001, and>;
403 def ANDNrr : F3_1<2, 0b000101,
404 (outs IntRegs:$dst), (ins IntRegs:$b, IntRegs:$c),
406 [(set IntRegs:$dst, (and IntRegs:$b, (not IntRegs:$c)))]>;
407 def ANDNri : F3_2<2, 0b000101,
408 (outs IntRegs:$dst), (ins IntRegs:$b, i32imm:$c),
409 "andn $b, $c, $dst", []>;
411 defm OR : F3_12<"or", 0b000010, or>;
413 def ORNrr : F3_1<2, 0b000110,
414 (outs IntRegs:$dst), (ins IntRegs:$b, IntRegs:$c),
416 [(set IntRegs:$dst, (or IntRegs:$b, (not IntRegs:$c)))]>;
417 def ORNri : F3_2<2, 0b000110,
418 (outs IntRegs:$dst), (ins IntRegs:$b, i32imm:$c),
419 "orn $b, $c, $dst", []>;
420 defm XOR : F3_12<"xor", 0b000011, xor>;
422 def XNORrr : F3_1<2, 0b000111,
423 (outs IntRegs:$dst), (ins IntRegs:$b, IntRegs:$c),
425 [(set IntRegs:$dst, (not (xor IntRegs:$b, IntRegs:$c)))]>;
426 def XNORri : F3_2<2, 0b000111,
427 (outs IntRegs:$dst), (ins IntRegs:$b, i32imm:$c),
428 "xnor $b, $c, $dst", []>;
430 // Section B.12 - Shift Instructions, p. 107
431 defm SLL : F3_12<"sll", 0b100101, shl>;
432 defm SRL : F3_12<"srl", 0b100110, srl>;
433 defm SRA : F3_12<"sra", 0b100111, sra>;
435 // Section B.13 - Add Instructions, p. 108
436 defm ADD : F3_12<"add", 0b000000, add>;
438 // "LEA" forms of add (patterns to make tblgen happy)
439 def LEA_ADDri : F3_2<2, 0b000000,
440 (outs IntRegs:$dst), (ins MEMri:$addr),
441 "add ${addr:arith}, $dst",
442 [(set IntRegs:$dst, ADDRri:$addr)]>;
445 defm ADDCC : F3_12<"addcc", 0b010000, addc>;
447 defm ADDX : F3_12<"addx", 0b001000, adde>;
449 // Section B.15 - Subtract Instructions, p. 110
450 defm SUB : F3_12 <"sub" , 0b000100, sub>;
451 defm SUBX : F3_12 <"subx" , 0b001100, sube>;
453 let Defs = [ICC] in {
454 defm SUBCC : F3_12 <"subcc", 0b010100, SPcmpicc>;
456 def SUBXCCrr: F3_1<2, 0b011100,
457 (outs IntRegs:$dst), (ins IntRegs:$b, IntRegs:$c),
458 "subxcc $b, $c, $dst", []>;
461 // Section B.18 - Multiply Instructions, p. 113
462 defm UMUL : F3_12np<"umul", 0b001010>;
463 defm SMUL : F3_12 <"smul", 0b001011, mul>;
466 // Section B.19 - Divide Instructions, p. 115
467 defm UDIV : F3_12np<"udiv", 0b001110>;
468 defm SDIV : F3_12np<"sdiv", 0b001111>;
470 // Section B.20 - SAVE and RESTORE, p. 117
471 defm SAVE : F3_12np<"save" , 0b111100>;
472 defm RESTORE : F3_12np<"restore", 0b111101>;
474 // Section B.21 - Branch on Integer Condition Codes Instructions, p. 119
476 // conditional branch class:
477 class BranchSP<bits<4> cc, dag ins, string asmstr, list<dag> pattern>
478 : F2_2<cc, 0b010, (outs), ins, asmstr, pattern> {
480 let isTerminator = 1;
481 let hasDelaySlot = 1;
485 def BA : BranchSP<0b1000, (ins brtarget:$dst),
489 // FIXME: the encoding for the JIT should look at the condition field.
491 def BCOND : BranchSP<0, (ins brtarget:$dst, CCOp:$cc),
493 [(SPbricc bb:$dst, imm:$cc)]>;
496 // Section B.22 - Branch on Floating-point Condition Codes Instructions, p. 121
498 // floating-point conditional branch class:
499 class FPBranchSP<bits<4> cc, dag ins, string asmstr, list<dag> pattern>
500 : F2_2<cc, 0b110, (outs), ins, asmstr, pattern> {
502 let isTerminator = 1;
503 let hasDelaySlot = 1;
506 // FIXME: the encoding for the JIT should look at the condition field.
508 def FBCOND : FPBranchSP<0, (ins brtarget:$dst, CCOp:$cc),
510 [(SPbrfcc bb:$dst, imm:$cc)]>;
513 // Section B.24 - Call and Link Instruction, p. 125
514 // This is the only Format 1 instruction
515 let Uses = [O0, O1, O2, O3, O4, O5],
516 hasDelaySlot = 1, isCall = 1,
517 Defs = [O0, O1, O2, O3, O4, O5, O7, G1, G2, G3, G4, G5, G6, G7,
518 D0, D1, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11, D12, D13, D14, D15] in {
519 def CALL : InstSP<(outs), (ins calltarget:$dst),
523 let Inst{29-0} = disp;
527 def JMPLrr : F3_1<2, 0b111000,
528 (outs), (ins MEMrr:$ptr),
530 [(call ADDRrr:$ptr)]>;
531 def JMPLri : F3_2<2, 0b111000,
532 (outs), (ins MEMri:$ptr),
534 [(call ADDRri:$ptr)]>;
537 // Section B.28 - Read State Register Instructions
538 def RDY : F3_1<2, 0b101000,
539 (outs IntRegs:$dst), (ins),
542 // Section B.29 - Write State Register Instructions
543 def WRYrr : F3_1<2, 0b110000,
544 (outs), (ins IntRegs:$b, IntRegs:$c),
545 "wr $b, $c, %y", []>;
546 def WRYri : F3_2<2, 0b110000,
547 (outs), (ins IntRegs:$b, i32imm:$c),
548 "wr $b, $c, %y", []>;
550 // Convert Integer to Floating-point Instructions, p. 141
551 def FITOS : F3_3<2, 0b110100, 0b011000100,
552 (outs FPRegs:$dst), (ins FPRegs:$src),
554 [(set FPRegs:$dst, (SPitof FPRegs:$src))]>;
555 def FITOD : F3_3<2, 0b110100, 0b011001000,
556 (outs DFPRegs:$dst), (ins FPRegs:$src),
558 [(set DFPRegs:$dst, (SPitof FPRegs:$src))]>;
560 // Convert Floating-point to Integer Instructions, p. 142
561 def FSTOI : F3_3<2, 0b110100, 0b011010001,
562 (outs FPRegs:$dst), (ins FPRegs:$src),
564 [(set FPRegs:$dst, (SPftoi FPRegs:$src))]>;
565 def FDTOI : F3_3<2, 0b110100, 0b011010010,
566 (outs FPRegs:$dst), (ins DFPRegs:$src),
568 [(set FPRegs:$dst, (SPftoi DFPRegs:$src))]>;
570 // Convert between Floating-point Formats Instructions, p. 143
571 def FSTOD : F3_3<2, 0b110100, 0b011001001,
572 (outs DFPRegs:$dst), (ins FPRegs:$src),
574 [(set DFPRegs:$dst, (fextend FPRegs:$src))]>;
575 def FDTOS : F3_3<2, 0b110100, 0b011000110,
576 (outs FPRegs:$dst), (ins DFPRegs:$src),
578 [(set FPRegs:$dst, (fround DFPRegs:$src))]>;
580 // Floating-point Move Instructions, p. 144
581 def FMOVS : F3_3<2, 0b110100, 0b000000001,
582 (outs FPRegs:$dst), (ins FPRegs:$src),
583 "fmovs $src, $dst", []>;
584 def FNEGS : F3_3<2, 0b110100, 0b000000101,
585 (outs FPRegs:$dst), (ins FPRegs:$src),
587 [(set FPRegs:$dst, (fneg FPRegs:$src))]>;
588 def FABSS : F3_3<2, 0b110100, 0b000001001,
589 (outs FPRegs:$dst), (ins FPRegs:$src),
591 [(set FPRegs:$dst, (fabs FPRegs:$src))]>;
594 // Floating-point Square Root Instructions, p.145
595 def FSQRTS : F3_3<2, 0b110100, 0b000101001,
596 (outs FPRegs:$dst), (ins FPRegs:$src),
598 [(set FPRegs:$dst, (fsqrt FPRegs:$src))]>;
599 def FSQRTD : F3_3<2, 0b110100, 0b000101010,
600 (outs DFPRegs:$dst), (ins DFPRegs:$src),
602 [(set DFPRegs:$dst, (fsqrt DFPRegs:$src))]>;
606 // Floating-point Add and Subtract Instructions, p. 146
607 def FADDS : F3_3<2, 0b110100, 0b001000001,
608 (outs FPRegs:$dst), (ins FPRegs:$src1, FPRegs:$src2),
609 "fadds $src1, $src2, $dst",
610 [(set FPRegs:$dst, (fadd FPRegs:$src1, FPRegs:$src2))]>;
611 def FADDD : F3_3<2, 0b110100, 0b001000010,
612 (outs DFPRegs:$dst), (ins DFPRegs:$src1, DFPRegs:$src2),
613 "faddd $src1, $src2, $dst",
614 [(set DFPRegs:$dst, (fadd DFPRegs:$src1, DFPRegs:$src2))]>;
615 def FSUBS : F3_3<2, 0b110100, 0b001000101,
616 (outs FPRegs:$dst), (ins FPRegs:$src1, FPRegs:$src2),
617 "fsubs $src1, $src2, $dst",
618 [(set FPRegs:$dst, (fsub FPRegs:$src1, FPRegs:$src2))]>;
619 def FSUBD : F3_3<2, 0b110100, 0b001000110,
620 (outs DFPRegs:$dst), (ins DFPRegs:$src1, DFPRegs:$src2),
621 "fsubd $src1, $src2, $dst",
622 [(set DFPRegs:$dst, (fsub DFPRegs:$src1, DFPRegs:$src2))]>;
624 // Floating-point Multiply and Divide Instructions, p. 147
625 def FMULS : F3_3<2, 0b110100, 0b001001001,
626 (outs FPRegs:$dst), (ins FPRegs:$src1, FPRegs:$src2),
627 "fmuls $src1, $src2, $dst",
628 [(set FPRegs:$dst, (fmul FPRegs:$src1, FPRegs:$src2))]>;
629 def FMULD : F3_3<2, 0b110100, 0b001001010,
630 (outs DFPRegs:$dst), (ins DFPRegs:$src1, DFPRegs:$src2),
631 "fmuld $src1, $src2, $dst",
632 [(set DFPRegs:$dst, (fmul DFPRegs:$src1, DFPRegs:$src2))]>;
633 def FSMULD : F3_3<2, 0b110100, 0b001101001,
634 (outs DFPRegs:$dst), (ins FPRegs:$src1, FPRegs:$src2),
635 "fsmuld $src1, $src2, $dst",
636 [(set DFPRegs:$dst, (fmul (fextend FPRegs:$src1),
637 (fextend FPRegs:$src2)))]>;
638 def FDIVS : F3_3<2, 0b110100, 0b001001101,
639 (outs FPRegs:$dst), (ins FPRegs:$src1, FPRegs:$src2),
640 "fdivs $src1, $src2, $dst",
641 [(set FPRegs:$dst, (fdiv FPRegs:$src1, FPRegs:$src2))]>;
642 def FDIVD : F3_3<2, 0b110100, 0b001001110,
643 (outs DFPRegs:$dst), (ins DFPRegs:$src1, DFPRegs:$src2),
644 "fdivd $src1, $src2, $dst",
645 [(set DFPRegs:$dst, (fdiv DFPRegs:$src1, DFPRegs:$src2))]>;
647 // Floating-point Compare Instructions, p. 148
648 // Note: the 2nd template arg is different for these guys.
649 // Note 2: the result of a FCMP is not available until the 2nd cycle
650 // after the instr is retired, but there is no interlock. This behavior
651 // is modelled with a forced noop after the instruction.
652 let Defs = [FCC] in {
653 def FCMPS : F3_3<2, 0b110101, 0b001010001,
654 (outs), (ins FPRegs:$src1, FPRegs:$src2),
655 "fcmps $src1, $src2\n\tnop",
656 [(SPcmpfcc FPRegs:$src1, FPRegs:$src2)]>;
657 def FCMPD : F3_3<2, 0b110101, 0b001010010,
658 (outs), (ins DFPRegs:$src1, DFPRegs:$src2),
659 "fcmpd $src1, $src2\n\tnop",
660 [(SPcmpfcc DFPRegs:$src1, DFPRegs:$src2)]>;
663 //===----------------------------------------------------------------------===//
665 //===----------------------------------------------------------------------===//
667 // V9 Conditional Moves.
668 let Predicates = [HasV9], isTwoAddress = 1 in {
669 // Move Integer Register on Condition (MOVcc) p. 194 of the V9 manual.
670 // FIXME: Add instruction encodings for the JIT some day.
672 : Pseudo<(outs IntRegs:$dst), (ins IntRegs:$T, IntRegs:$F, CCOp:$cc),
673 "mov$cc %icc, $F, $dst",
675 (SPselecticc IntRegs:$F, IntRegs:$T, imm:$cc))]>;
677 : Pseudo<(outs IntRegs:$dst), (ins IntRegs:$T, i32imm:$F, CCOp:$cc),
678 "mov$cc %icc, $F, $dst",
680 (SPselecticc simm11:$F, IntRegs:$T, imm:$cc))]>;
683 : Pseudo<(outs IntRegs:$dst), (ins IntRegs:$T, IntRegs:$F, CCOp:$cc),
684 "mov$cc %fcc0, $F, $dst",
686 (SPselectfcc IntRegs:$F, IntRegs:$T, imm:$cc))]>;
688 : Pseudo<(outs IntRegs:$dst), (ins IntRegs:$T, i32imm:$F, CCOp:$cc),
689 "mov$cc %fcc0, $F, $dst",
691 (SPselectfcc simm11:$F, IntRegs:$T, imm:$cc))]>;
694 : Pseudo<(outs FPRegs:$dst), (ins FPRegs:$T, FPRegs:$F, CCOp:$cc),
695 "fmovs$cc %icc, $F, $dst",
697 (SPselecticc FPRegs:$F, FPRegs:$T, imm:$cc))]>;
699 : Pseudo<(outs DFPRegs:$dst), (ins DFPRegs:$T, DFPRegs:$F, CCOp:$cc),
700 "fmovd$cc %icc, $F, $dst",
702 (SPselecticc DFPRegs:$F, DFPRegs:$T, imm:$cc))]>;
704 : Pseudo<(outs FPRegs:$dst), (ins FPRegs:$T, FPRegs:$F, CCOp:$cc),
705 "fmovs$cc %fcc0, $F, $dst",
707 (SPselectfcc FPRegs:$F, FPRegs:$T, imm:$cc))]>;
709 : Pseudo<(outs DFPRegs:$dst), (ins DFPRegs:$T, DFPRegs:$F, CCOp:$cc),
710 "fmovd$cc %fcc0, $F, $dst",
712 (SPselectfcc DFPRegs:$F, DFPRegs:$T, imm:$cc))]>;
716 // Floating-Point Move Instructions, p. 164 of the V9 manual.
717 let Predicates = [HasV9] in {
718 def FMOVD : F3_3<2, 0b110100, 0b000000010,
719 (outs DFPRegs:$dst), (ins DFPRegs:$src),
720 "fmovd $src, $dst", []>;
721 def FNEGD : F3_3<2, 0b110100, 0b000000110,
722 (outs DFPRegs:$dst), (ins DFPRegs:$src),
724 [(set DFPRegs:$dst, (fneg DFPRegs:$src))]>;
725 def FABSD : F3_3<2, 0b110100, 0b000001010,
726 (outs DFPRegs:$dst), (ins DFPRegs:$src),
728 [(set DFPRegs:$dst, (fabs DFPRegs:$src))]>;
731 // POPCrr - This does a ctpop of a 64-bit register. As such, we have to clear
732 // the top 32-bits before using it. To do this clearing, we use a SLLri X,0.
733 def POPCrr : F3_1<2, 0b101110,
734 (outs IntRegs:$dst), (ins IntRegs:$src),
735 "popc $src, $dst", []>, Requires<[HasV9]>;
736 def : Pat<(ctpop IntRegs:$src),
737 (POPCrr (SLLri IntRegs:$src, 0))>;
739 //===----------------------------------------------------------------------===//
740 // Non-Instruction Patterns
741 //===----------------------------------------------------------------------===//
744 def : Pat<(i32 simm13:$val),
745 (ORri G0, imm:$val)>;
746 // Arbitrary immediates.
747 def : Pat<(i32 imm:$val),
748 (ORri (SETHIi (HI22 imm:$val)), (LO10 imm:$val))>;
751 def : Pat<(subc IntRegs:$b, IntRegs:$c),
752 (SUBCCrr IntRegs:$b, IntRegs:$c)>;
753 def : Pat<(subc IntRegs:$b, simm13:$val),
754 (SUBCCri IntRegs:$b, imm:$val)>;
756 // Global addresses, constant pool entries
757 def : Pat<(SPhi tglobaladdr:$in), (SETHIi tglobaladdr:$in)>;
758 def : Pat<(SPlo tglobaladdr:$in), (ORri G0, tglobaladdr:$in)>;
759 def : Pat<(SPhi tconstpool:$in), (SETHIi tconstpool:$in)>;
760 def : Pat<(SPlo tconstpool:$in), (ORri G0, tconstpool:$in)>;
762 // Add reg, lo. This is used when taking the addr of a global/constpool entry.
763 def : Pat<(add IntRegs:$r, (SPlo tglobaladdr:$in)),
764 (ADDri IntRegs:$r, tglobaladdr:$in)>;
765 def : Pat<(add IntRegs:$r, (SPlo tconstpool:$in)),
766 (ADDri IntRegs:$r, tconstpool:$in)>;
769 def : Pat<(call tglobaladdr:$dst),
770 (CALL tglobaladdr:$dst)>;
771 def : Pat<(call texternalsym:$dst),
772 (CALL texternalsym:$dst)>;
774 // Map integer extload's to zextloads.
775 def : Pat<(i32 (extloadi1 ADDRrr:$src)), (LDUBrr ADDRrr:$src)>;
776 def : Pat<(i32 (extloadi1 ADDRri:$src)), (LDUBri ADDRri:$src)>;
777 def : Pat<(i32 (extloadi8 ADDRrr:$src)), (LDUBrr ADDRrr:$src)>;
778 def : Pat<(i32 (extloadi8 ADDRri:$src)), (LDUBri ADDRri:$src)>;
779 def : Pat<(i32 (extloadi16 ADDRrr:$src)), (LDUHrr ADDRrr:$src)>;
780 def : Pat<(i32 (extloadi16 ADDRri:$src)), (LDUHri ADDRri:$src)>;
782 // zextload bool -> zextload byte
783 def : Pat<(i32 (zextloadi1 ADDRrr:$src)), (LDUBrr ADDRrr:$src)>;
784 def : Pat<(i32 (zextloadi1 ADDRri:$src)), (LDUBri ADDRri:$src)>;