3e0e6055e67fe0ddb9653b896c25711477c5ab10
[oota-llvm.git] / lib / Target / PowerPC / PPCInstrInfo.td
1 //===- PPCInstrInfo.td - The PowerPC Instruction Set -------*- tablegen -*-===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
10 // This file describes the subset of the 32-bit PowerPC instruction set, as used
11 // by the PowerPC instruction selector.
12 //
13 //===----------------------------------------------------------------------===//
14
15 include "PPCInstrFormats.td"
16
17 //===----------------------------------------------------------------------===//
18 // PowerPC specific type constraints.
19 //
20 def SDT_PPCstfiwx : SDTypeProfile<0, 2, [ // stfiwx
21   SDTCisVT<0, f64>, SDTCisPtrTy<1>
22 ]>;
23 def SDT_PPCCallSeqStart : SDCallSeqStart<[ SDTCisVT<0, i32> ]>;
24 def SDT_PPCCallSeqEnd   : SDCallSeqEnd<[ SDTCisVT<0, i32>,
25                                          SDTCisVT<1, i32> ]>;
26 def SDT_PPCvperm   : SDTypeProfile<1, 3, [
27   SDTCisVT<3, v16i8>, SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>
28 ]>;
29
30 def SDT_PPCvcmp : SDTypeProfile<1, 3, [
31   SDTCisSameAs<0, 1>, SDTCisSameAs<1, 2>, SDTCisVT<3, i32>
32 ]>;
33
34 def SDT_PPCcondbr : SDTypeProfile<0, 3, [
35   SDTCisVT<0, i32>, SDTCisVT<2, OtherVT>
36 ]>;
37
38 def SDT_PPClbrx : SDTypeProfile<1, 3, [
39   SDTCisVT<0, i32>, SDTCisPtrTy<1>, SDTCisVT<2, OtherVT>, SDTCisVT<3, OtherVT>
40 ]>;
41 def SDT_PPCstbrx : SDTypeProfile<0, 4, [
42   SDTCisVT<0, i32>, SDTCisPtrTy<1>, SDTCisVT<2, OtherVT>, SDTCisVT<3, OtherVT>
43 ]>;
44
45 def SDT_PPCatomic_load_add : SDTypeProfile<1, 2, [
46   SDTCisInt<0>, SDTCisPtrTy<1>, SDTCisInt<2>
47 ]>;
48 def SDT_PPCatomic_cmp_swap : SDTypeProfile<1, 3, [
49   SDTCisInt<0>, SDTCisPtrTy<1>, SDTCisInt<2>, SDTCisInt<3>
50 ]>;
51 def SDT_PPCatomic_swap : SDTypeProfile<1, 2, [
52   SDTCisInt<0>, SDTCisPtrTy<1>, SDTCisInt<2>
53 ]>;
54
55 def SDT_PPClarx : SDTypeProfile<1, 1, [
56   SDTCisInt<0>, SDTCisPtrTy<1>
57 ]>;
58 def SDT_PPCstcx : SDTypeProfile<0, 2, [
59   SDTCisInt<0>, SDTCisPtrTy<1>
60 ]>;
61
62 def SDT_PPCTC_ret : SDTypeProfile<0, 2, [
63   SDTCisPtrTy<0>, SDTCisVT<1, i32>
64 ]>;
65
66 //===----------------------------------------------------------------------===//
67 // PowerPC specific DAG Nodes.
68 //
69
70 def PPCfcfid  : SDNode<"PPCISD::FCFID" , SDTFPUnaryOp, []>;
71 def PPCfctidz : SDNode<"PPCISD::FCTIDZ", SDTFPUnaryOp, []>;
72 def PPCfctiwz : SDNode<"PPCISD::FCTIWZ", SDTFPUnaryOp, []>;
73 def PPCstfiwx : SDNode<"PPCISD::STFIWX", SDT_PPCstfiwx,
74                        [SDNPHasChain, SDNPMayStore]>;
75
76 // This sequence is used for long double->int conversions.  It changes the
77 // bits in the FPSCR which is not modelled.  
78 def PPCmffs   : SDNode<"PPCISD::MFFS", SDTypeProfile<1, 0, [SDTCisVT<0, f64>]>,
79                         [SDNPOutFlag]>;
80 def PPCmtfsb0 : SDNode<"PPCISD::MTFSB0", SDTypeProfile<0, 1, [SDTCisInt<0>]>,
81                        [SDNPInFlag, SDNPOutFlag]>;
82 def PPCmtfsb1 : SDNode<"PPCISD::MTFSB1", SDTypeProfile<0, 1, [SDTCisInt<0>]>,
83                        [SDNPInFlag, SDNPOutFlag]>;
84 def PPCfaddrtz: SDNode<"PPCISD::FADDRTZ", SDTFPBinOp,
85                        [SDNPInFlag, SDNPOutFlag]>;
86 def PPCmtfsf  : SDNode<"PPCISD::MTFSF", SDTypeProfile<1, 3, 
87                        [SDTCisVT<0, f64>, SDTCisInt<1>, SDTCisVT<2, f64>,
88                         SDTCisVT<3, f64>]>,
89                        [SDNPInFlag]>;
90
91 def PPCfsel   : SDNode<"PPCISD::FSEL",  
92    // Type constraint for fsel.
93    SDTypeProfile<1, 3, [SDTCisSameAs<0, 2>, SDTCisSameAs<0, 3>, 
94                         SDTCisFP<0>, SDTCisVT<1, f64>]>, []>;
95
96 def PPChi       : SDNode<"PPCISD::Hi", SDTIntBinOp, []>;
97 def PPClo       : SDNode<"PPCISD::Lo", SDTIntBinOp, []>;
98 def PPCvmaddfp  : SDNode<"PPCISD::VMADDFP", SDTFPTernaryOp, []>;
99 def PPCvnmsubfp : SDNode<"PPCISD::VNMSUBFP", SDTFPTernaryOp, []>;
100
101 def PPCvperm    : SDNode<"PPCISD::VPERM", SDT_PPCvperm, []>;
102
103 // These nodes represent the 32-bit PPC shifts that operate on 6-bit shift
104 // amounts.  These nodes are generated by the multi-precision shift code.
105 def PPCsrl        : SDNode<"PPCISD::SRL"       , SDTIntShiftOp>;
106 def PPCsra        : SDNode<"PPCISD::SRA"       , SDTIntShiftOp>;
107 def PPCshl        : SDNode<"PPCISD::SHL"       , SDTIntShiftOp>;
108
109 def PPCextsw_32   : SDNode<"PPCISD::EXTSW_32"  , SDTIntUnaryOp>;
110 def PPCstd_32     : SDNode<"PPCISD::STD_32"    , SDTStore,
111                            [SDNPHasChain, SDNPMayStore]>;
112
113 // These are target-independent nodes, but have target-specific formats.
114 def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_PPCCallSeqStart,
115                            [SDNPHasChain, SDNPOutFlag]>;
116 def callseq_end   : SDNode<"ISD::CALLSEQ_END",   SDT_PPCCallSeqEnd,
117                            [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
118
119 def SDT_PPCCall   : SDTypeProfile<0, -1, [SDTCisInt<0>]>;
120 def PPCcall_Macho : SDNode<"PPCISD::CALL_Macho", SDT_PPCCall,
121                            [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
122 def PPCcall_ELF   : SDNode<"PPCISD::CALL_ELF", SDT_PPCCall,
123                            [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
124 def PPCmtctr      : SDNode<"PPCISD::MTCTR", SDT_PPCCall,
125                            [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
126 def PPCbctrl_Macho  : SDNode<"PPCISD::BCTRL_Macho", SDTNone,
127                            [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
128
129 def PPCbctrl_ELF  : SDNode<"PPCISD::BCTRL_ELF", SDTNone,
130                            [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
131
132 def retflag       : SDNode<"PPCISD::RET_FLAG", SDTNone,
133                            [SDNPHasChain, SDNPOptInFlag]>;
134
135 def PPCtc_return : SDNode<"PPCISD::TC_RETURN", SDT_PPCTC_ret,
136                         [SDNPHasChain,  SDNPOptInFlag]>;
137
138 def PPCtailcall : SDNode<"PPCISD::TAILCALL",     SDT_PPCCall,
139                         [SDNPHasChain, SDNPOutFlag, SDNPOptInFlag]>;
140
141 def PPCvcmp       : SDNode<"PPCISD::VCMP" , SDT_PPCvcmp, []>;
142 def PPCvcmp_o     : SDNode<"PPCISD::VCMPo", SDT_PPCvcmp, [SDNPOutFlag]>;
143
144 def PPCcondbranch : SDNode<"PPCISD::COND_BRANCH", SDT_PPCcondbr,
145                            [SDNPHasChain, SDNPOptInFlag]>;
146
147 def PPClbrx       : SDNode<"PPCISD::LBRX", SDT_PPClbrx,
148                            [SDNPHasChain, SDNPMayLoad]>;
149 def PPCstbrx      : SDNode<"PPCISD::STBRX", SDT_PPCstbrx,
150                            [SDNPHasChain, SDNPMayStore]>;
151
152 // Atomic operations
153 def PPCatomic_load_add : SDNode<"PPCISD::ATOMIC_LOAD_ADD",
154                                 SDT_PPCatomic_load_add,
155                                 [SDNPHasChain, SDNPMayLoad, SDNPMayStore]>;
156 def PPCatomic_cmp_swap : SDNode<"PPCISD::ATOMIC_CMP_SWAP",
157                                 SDT_PPCatomic_cmp_swap,
158                                 [SDNPHasChain, SDNPMayLoad, SDNPMayStore]>;
159 def PPCatomic_swap : SDNode<"PPCISD::ATOMIC_SWAP",
160                             SDT_PPCatomic_swap,
161                             [SDNPHasChain, SDNPMayLoad, SDNPMayStore]>;
162
163 // Instructions to support atomic operations
164 def PPClarx      : SDNode<"PPCISD::LARX", SDT_PPClarx,
165                           [SDNPHasChain, SDNPMayLoad]>;
166 def PPCstcx      : SDNode<"PPCISD::STCX", SDT_PPCstcx,
167                           [SDNPHasChain, SDNPMayStore]>;
168
169 // Instructions to support dynamic alloca.
170 def SDTDynOp  : SDTypeProfile<1, 2, []>;
171 def PPCdynalloc   : SDNode<"PPCISD::DYNALLOC", SDTDynOp, [SDNPHasChain]>;
172
173 //===----------------------------------------------------------------------===//
174 // PowerPC specific transformation functions and pattern fragments.
175 //
176
177 def SHL32 : SDNodeXForm<imm, [{
178   // Transformation function: 31 - imm
179   return getI32Imm(31 - N->getValue());
180 }]>;
181
182 def SRL32 : SDNodeXForm<imm, [{
183   // Transformation function: 32 - imm
184   return N->getValue() ? getI32Imm(32 - N->getValue()) : getI32Imm(0);
185 }]>;
186
187 def LO16 : SDNodeXForm<imm, [{
188   // Transformation function: get the low 16 bits.
189   return getI32Imm((unsigned short)N->getValue());
190 }]>;
191
192 def HI16 : SDNodeXForm<imm, [{
193   // Transformation function: shift the immediate value down into the low bits.
194   return getI32Imm((unsigned)N->getValue() >> 16);
195 }]>;
196
197 def HA16 : SDNodeXForm<imm, [{
198   // Transformation function: shift the immediate value down into the low bits.
199   signed int Val = N->getValue();
200   return getI32Imm((Val - (signed short)Val) >> 16);
201 }]>;
202 def MB : SDNodeXForm<imm, [{
203   // Transformation function: get the start bit of a mask
204   unsigned mb, me;
205   (void)isRunOfOnes((unsigned)N->getValue(), mb, me);
206   return getI32Imm(mb);
207 }]>;
208
209 def ME : SDNodeXForm<imm, [{
210   // Transformation function: get the end bit of a mask
211   unsigned mb, me;
212   (void)isRunOfOnes((unsigned)N->getValue(), mb, me);
213   return getI32Imm(me);
214 }]>;
215 def maskimm32 : PatLeaf<(imm), [{
216   // maskImm predicate - True if immediate is a run of ones.
217   unsigned mb, me;
218   if (N->getValueType(0) == MVT::i32)
219     return isRunOfOnes((unsigned)N->getValue(), mb, me);
220   else
221     return false;
222 }]>;
223
224 def immSExt16  : PatLeaf<(imm), [{
225   // immSExt16 predicate - True if the immediate fits in a 16-bit sign extended
226   // field.  Used by instructions like 'addi'.
227   if (N->getValueType(0) == MVT::i32)
228     return (int32_t)N->getValue() == (short)N->getValue();
229   else
230     return (int64_t)N->getValue() == (short)N->getValue();
231 }]>;
232 def immZExt16  : PatLeaf<(imm), [{
233   // immZExt16 predicate - True if the immediate fits in a 16-bit zero extended
234   // field.  Used by instructions like 'ori'.
235   return (uint64_t)N->getValue() == (unsigned short)N->getValue();
236 }], LO16>;
237
238 // imm16Shifted* - These match immediates where the low 16-bits are zero.  There
239 // are two forms: imm16ShiftedSExt and imm16ShiftedZExt.  These two forms are
240 // identical in 32-bit mode, but in 64-bit mode, they return true if the
241 // immediate fits into a sign/zero extended 32-bit immediate (with the low bits
242 // clear).
243 def imm16ShiftedZExt : PatLeaf<(imm), [{
244   // imm16ShiftedZExt predicate - True if only bits in the top 16-bits of the
245   // immediate are set.  Used by instructions like 'xoris'.
246   return (N->getValue() & ~uint64_t(0xFFFF0000)) == 0;
247 }], HI16>;
248
249 def imm16ShiftedSExt : PatLeaf<(imm), [{
250   // imm16ShiftedSExt predicate - True if only bits in the top 16-bits of the
251   // immediate are set.  Used by instructions like 'addis'.  Identical to 
252   // imm16ShiftedZExt in 32-bit mode.
253   if (N->getValue() & 0xFFFF) return false;
254   if (N->getValueType(0) == MVT::i32)
255     return true;
256   // For 64-bit, make sure it is sext right.
257   return N->getValue() == (uint64_t)(int)N->getValue();
258 }], HI16>;
259
260
261 //===----------------------------------------------------------------------===//
262 // PowerPC Flag Definitions.
263
264 class isPPC64 { bit PPC64 = 1; }
265 class isDOT   {
266   list<Register> Defs = [CR0];
267   bit RC  = 1;
268 }
269
270 class RegConstraint<string C> {
271   string Constraints = C;
272 }
273 class NoEncode<string E> {
274   string DisableEncoding = E;
275 }
276
277
278 //===----------------------------------------------------------------------===//
279 // PowerPC Operand Definitions.
280
281 def s5imm   : Operand<i32> {
282   let PrintMethod = "printS5ImmOperand";
283 }
284 def u5imm   : Operand<i32> {
285   let PrintMethod = "printU5ImmOperand";
286 }
287 def u6imm   : Operand<i32> {
288   let PrintMethod = "printU6ImmOperand";
289 }
290 def s16imm  : Operand<i32> {
291   let PrintMethod = "printS16ImmOperand";
292 }
293 def u16imm  : Operand<i32> {
294   let PrintMethod = "printU16ImmOperand";
295 }
296 def s16immX4  : Operand<i32> {   // Multiply imm by 4 before printing.
297   let PrintMethod = "printS16X4ImmOperand";
298 }
299 def target : Operand<OtherVT> {
300   let PrintMethod = "printBranchOperand";
301 }
302 def calltarget : Operand<iPTR> {
303   let PrintMethod = "printCallOperand";
304 }
305 def aaddr : Operand<iPTR> {
306   let PrintMethod = "printAbsAddrOperand";
307 }
308 def piclabel: Operand<iPTR> {
309   let PrintMethod = "printPICLabel";
310 }
311 def symbolHi: Operand<i32> {
312   let PrintMethod = "printSymbolHi";
313 }
314 def symbolLo: Operand<i32> {
315   let PrintMethod = "printSymbolLo";
316 }
317 def crbitm: Operand<i8> {
318   let PrintMethod = "printcrbitm";
319 }
320 // Address operands
321 def memri : Operand<iPTR> {
322   let PrintMethod = "printMemRegImm";
323   let MIOperandInfo = (ops i32imm:$imm, ptr_rc:$reg);
324 }
325 def memrr : Operand<iPTR> {
326   let PrintMethod = "printMemRegReg";
327   let MIOperandInfo = (ops ptr_rc, ptr_rc);
328 }
329 def memrix : Operand<iPTR> {   // memri where the imm is shifted 2 bits.
330   let PrintMethod = "printMemRegImmShifted";
331   let MIOperandInfo = (ops i32imm:$imm, ptr_rc:$reg);
332 }
333
334 // PowerPC Predicate operand.  20 = (0<<5)|20 = always, CR0 is a dummy reg
335 // that doesn't matter.
336 def pred : PredicateOperand<OtherVT, (ops imm, CRRC),
337                                      (ops (i32 20), (i32 zero_reg))> {
338   let PrintMethod = "printPredicateOperand";
339 }
340
341 // Define PowerPC specific addressing mode.
342 def iaddr  : ComplexPattern<iPTR, 2, "SelectAddrImm",    [], []>;
343 def xaddr  : ComplexPattern<iPTR, 2, "SelectAddrIdx",    [], []>;
344 def xoaddr : ComplexPattern<iPTR, 2, "SelectAddrIdxOnly",[], []>;
345 def ixaddr : ComplexPattern<iPTR, 2, "SelectAddrImmShift", [], []>; // "std"
346
347 /// This is just the offset part of iaddr, used for preinc.
348 def iaddroff : ComplexPattern<iPTR, 1, "SelectAddrImmOffs", [], []>;
349
350 //===----------------------------------------------------------------------===//
351 // PowerPC Instruction Predicate Definitions.
352 def FPContractions : Predicate<"!NoExcessFPPrecision">;
353 def In32BitMode  : Predicate<"!PPCSubTarget.isPPC64()">;
354 def In64BitMode  : Predicate<"PPCSubTarget.isPPC64()">;
355
356
357 //===----------------------------------------------------------------------===//
358 // PowerPC Instruction Definitions.
359
360 // Pseudo-instructions:
361
362 let hasCtrlDep = 1 in {
363 let Defs = [R1], Uses = [R1] in {
364 def ADJCALLSTACKDOWN : Pseudo<(outs), (ins u16imm:$amt),
365                               "${:comment} ADJCALLSTACKDOWN",
366                               [(callseq_start imm:$amt)]>;
367 def ADJCALLSTACKUP   : Pseudo<(outs), (ins u16imm:$amt1, u16imm:$amt2),
368                               "${:comment} ADJCALLSTACKUP",
369                               [(callseq_end imm:$amt1, imm:$amt2)]>;
370 }
371
372 def UPDATE_VRSAVE    : Pseudo<(outs GPRC:$rD), (ins GPRC:$rS),
373                               "UPDATE_VRSAVE $rD, $rS", []>;
374 }
375
376 let Defs = [R1], Uses = [R1] in
377 def DYNALLOC : Pseudo<(outs GPRC:$result), (ins GPRC:$negsize, memri:$fpsi),
378                        "${:comment} DYNALLOC $result, $negsize, $fpsi",
379                        [(set GPRC:$result,
380                              (PPCdynalloc GPRC:$negsize, iaddr:$fpsi))]>;
381                          
382 // SELECT_CC_* - Used to implement the SELECT_CC DAG operation.  Expanded by the
383 // scheduler into a branch sequence.
384 let usesCustomDAGSchedInserter = 1,    // Expanded by the scheduler.
385     PPC970_Single = 1 in {
386   def SELECT_CC_I4 : Pseudo<(outs GPRC:$dst), (ins CRRC:$cond, GPRC:$T, GPRC:$F,
387                               i32imm:$BROPC), "${:comment} SELECT_CC PSEUDO!",
388                               []>;
389   def SELECT_CC_I8 : Pseudo<(outs G8RC:$dst), (ins CRRC:$cond, G8RC:$T, G8RC:$F,
390                               i32imm:$BROPC), "${:comment} SELECT_CC PSEUDO!",
391                               []>;
392   def SELECT_CC_F4  : Pseudo<(outs F4RC:$dst), (ins CRRC:$cond, F4RC:$T, F4RC:$F,
393                               i32imm:$BROPC), "${:comment} SELECT_CC PSEUDO!",
394                               []>;
395   def SELECT_CC_F8  : Pseudo<(outs F8RC:$dst), (ins CRRC:$cond, F8RC:$T, F8RC:$F,
396                               i32imm:$BROPC), "${:comment} SELECT_CC PSEUDO!",
397                               []>;
398   def SELECT_CC_VRRC: Pseudo<(outs VRRC:$dst), (ins CRRC:$cond, VRRC:$T, VRRC:$F,
399                               i32imm:$BROPC), "${:comment} SELECT_CC PSEUDO!",
400                               []>;
401 }
402
403 // SPILL_CR - Indicate that we're dumping the CR register, so we'll need to
404 // scavenge a register for it.
405 def SPILL_CR : Pseudo<(outs), (ins GPRC:$cond, memri:$F),
406                      "${:comment} SPILL_CR $cond $F", []>;
407
408 let isTerminator = 1, isBarrier = 1, PPC970_Unit = 7 in {
409   let isReturn = 1 in
410     def BLR : XLForm_2_br<19, 16, 0, (outs), (ins pred:$p),
411                           "b${p:cc}lr ${p:reg}", BrB, 
412                           [(retflag)]>;
413   let isBranch = 1, isIndirectBranch = 1 in
414     def BCTR : XLForm_2_ext<19, 528, 20, 0, 0, (outs), (ins), "bctr", BrB, []>;
415 }
416
417 let Defs = [LR] in
418   def MovePCtoLR : Pseudo<(outs), (ins piclabel:$label), "bl $label", []>,
419                    PPC970_Unit_BRU;
420
421 let isBranch = 1, isTerminator = 1, hasCtrlDep = 1, PPC970_Unit = 7 in {
422   let isBarrier = 1 in {
423   def B   : IForm<18, 0, 0, (outs), (ins target:$dst),
424                   "b $dst", BrB,
425                   [(br bb:$dst)]>;
426   }
427
428   // BCC represents an arbitrary conditional branch on a predicate.
429   // FIXME: should be able to write a pattern for PPCcondbranch, but can't use
430   // a two-value operand where a dag node expects two operands. :( 
431   def BCC : BForm<16, 0, 0, (outs), (ins pred:$cond, target:$dst),
432                   "b${cond:cc} ${cond:reg}, $dst"
433                   /*[(PPCcondbranch CRRC:$crS, imm:$opc, bb:$dst)]*/>;
434 }
435
436 // Macho ABI Calls.
437 let isCall = 1, PPC970_Unit = 7, 
438   // All calls clobber the non-callee saved registers...
439   Defs = [R0,R2,R3,R4,R5,R6,R7,R8,R9,R10,R11,R12,
440           F0,F1,F2,F3,F4,F5,F6,F7,F8,F9,F10,F11,F12,F13,
441           V0,V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,V13,V14,V15,V16,V17,V18,V19,
442           LR,CTR,
443           CR0,CR1,CR5,CR6,CR7,
444           CR0LT,CR0GT,CR0EQ,CR0UN,CR1LT,CR1GT,CR1EQ,CR1UN,CR5LT,CR5GT,CR5EQ,
445           CR5UN,CR6LT,CR6GT,CR6EQ,CR6UN,CR7LT,CR7GT,CR7EQ,CR7UN] in {
446   // Convenient aliases for call instructions
447   def BL_Macho  : IForm<18, 0, 1,
448                         (outs), (ins calltarget:$func, variable_ops), 
449                         "bl $func", BrB, []>;  // See Pat patterns below.
450   def BLA_Macho : IForm<18, 1, 1, 
451                         (outs), (ins aaddr:$func, variable_ops),
452                         "bla $func", BrB, [(PPCcall_Macho (i32 imm:$func))]>;
453   def BCTRL_Macho : XLForm_2_ext<19, 528, 20, 0, 1, 
454                                  (outs), (ins variable_ops),
455                                  "bctrl", BrB,
456                                  [(PPCbctrl_Macho)]>, Requires<[In32BitMode]>;
457 }
458
459 // ELF ABI Calls.
460 let isCall = 1, PPC970_Unit = 7, 
461   // All calls clobber the non-callee saved registers...
462   Defs = [R0,R2,R3,R4,R5,R6,R7,R8,R9,R10,R11,R12,
463           F0,F1,F2,F3,F4,F5,F6,F7,F8,
464           V0,V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,V13,V14,V15,V16,V17,V18,V19,
465           LR,CTR,
466           CR0,CR1,CR5,CR6,CR7,
467           CR0LT,CR0GT,CR0EQ,CR0UN,CR1LT,CR1GT,CR1EQ,CR1UN,CR5LT,CR5GT,CR5EQ,
468           CR5UN,CR6LT,CR6GT,CR6EQ,CR6UN,CR7LT,CR7GT,CR7EQ,CR7UN] in {
469   // Convenient aliases for call instructions
470   def BL_ELF  : IForm<18, 0, 1,
471                       (outs), (ins calltarget:$func, variable_ops), 
472                       "bl $func", BrB, []>;  // See Pat patterns below.
473   def BLA_ELF : IForm<18, 1, 1,
474                       (outs), (ins aaddr:$func, variable_ops),
475                       "bla $func", BrB,
476                       [(PPCcall_ELF (i32 imm:$func))]>;
477   def BCTRL_ELF : XLForm_2_ext<19, 528, 20, 0, 1,
478                                (outs), (ins variable_ops),
479                                "bctrl", BrB,
480                                [(PPCbctrl_ELF)]>, Requires<[In32BitMode]>;
481 }
482
483
484 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
485 def TCRETURNdi :Pseudo< (outs),
486                         (ins calltarget:$dst, i32imm:$offset, variable_ops),
487                  "#TC_RETURNd $dst $offset",
488                  []>;
489
490
491 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
492 def TCRETURNai :Pseudo<(outs), (ins aaddr:$func, i32imm:$offset, variable_ops),
493                  "#TC_RETURNa $func $offset",
494                  [(PPCtc_return (i32 imm:$func), imm:$offset)]>;
495
496 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
497 def TCRETURNri : Pseudo<(outs), (ins CTRRC:$dst, i32imm:$offset, variable_ops),
498                  "#TC_RETURNr $dst $offset",
499                  []>;
500
501
502 let isTerminator = 1, isBarrier = 1, PPC970_Unit = 7, isBranch = 1,
503     isIndirectBranch = 1, isCall = 1, isReturn = 1  in
504 def TAILBCTR : XLForm_2_ext<19, 528, 20, 0, 0, (outs), (ins), "bctr", BrB, []>,
505      Requires<[In32BitMode]>;
506
507
508
509 let isBranch = 1, isTerminator = 1, hasCtrlDep = 1, PPC970_Unit = 7,
510     isBarrier = 1, isCall = 1, isReturn = 1 in
511 def TAILB   : IForm<18, 0, 0, (outs), (ins calltarget:$dst),
512                   "b $dst", BrB,
513                   []>;
514
515
516 let isBranch = 1, isTerminator = 1, hasCtrlDep = 1, PPC970_Unit = 7,
517     isBarrier = 1, isCall = 1, isReturn = 1 in
518 def TAILBA   : IForm<18, 0, 0, (outs), (ins aaddr:$dst),
519                   "ba $dst", BrB,
520                   []>;
521
522
523 // DCB* instructions.
524 def DCBA   : DCB_Form<758, 0, (outs), (ins memrr:$dst),
525                       "dcba $dst", LdStDCBF, [(int_ppc_dcba xoaddr:$dst)]>,
526                       PPC970_DGroup_Single;
527 def DCBF   : DCB_Form<86, 0, (outs), (ins memrr:$dst),
528                       "dcbf $dst", LdStDCBF, [(int_ppc_dcbf xoaddr:$dst)]>,
529                       PPC970_DGroup_Single;
530 def DCBI   : DCB_Form<470, 0, (outs), (ins memrr:$dst),
531                       "dcbi $dst", LdStDCBF, [(int_ppc_dcbi xoaddr:$dst)]>,
532                       PPC970_DGroup_Single;
533 def DCBST  : DCB_Form<54, 0, (outs), (ins memrr:$dst),
534                       "dcbst $dst", LdStDCBF, [(int_ppc_dcbst xoaddr:$dst)]>,
535                       PPC970_DGroup_Single;
536 def DCBT   : DCB_Form<278, 0, (outs), (ins memrr:$dst),
537                       "dcbt $dst", LdStDCBF, [(int_ppc_dcbt xoaddr:$dst)]>,
538                       PPC970_DGroup_Single;
539 def DCBTST : DCB_Form<246, 0, (outs), (ins memrr:$dst),
540                       "dcbtst $dst", LdStDCBF, [(int_ppc_dcbtst xoaddr:$dst)]>,
541                       PPC970_DGroup_Single;
542 def DCBZ   : DCB_Form<1014, 0, (outs), (ins memrr:$dst),
543                       "dcbz $dst", LdStDCBF, [(int_ppc_dcbz xoaddr:$dst)]>,
544                       PPC970_DGroup_Single;
545 def DCBZL  : DCB_Form<1014, 1, (outs), (ins memrr:$dst),
546                       "dcbzl $dst", LdStDCBF, [(int_ppc_dcbzl xoaddr:$dst)]>,
547                       PPC970_DGroup_Single;
548
549 // Atomic operations
550 let usesCustomDAGSchedInserter = 1 in {
551   let Uses = [CR0] in {
552     def ATOMIC_LOAD_ADD_I32 : Pseudo<
553       (outs GPRC:$dst), (ins memrr:$ptr, GPRC:$incr),
554       "${:comment} ATOMIC_LOAD_ADD_I32 PSEUDO!",
555       [(set GPRC:$dst, (PPCatomic_load_add xoaddr:$ptr, GPRC:$incr))]>;
556     def ATOMIC_CMP_SWAP_I32 : Pseudo<
557       (outs GPRC:$dst), (ins memrr:$ptr, GPRC:$old, GPRC:$new),
558       "${:comment} ATOMIC_CMP_SWAP_I32 PSEUDO!",
559       [(set GPRC:$dst, (PPCatomic_cmp_swap xoaddr:$ptr, GPRC:$old, GPRC:$new))]>;
560     def ATOMIC_SWAP_I32 : Pseudo<
561       (outs GPRC:$dst), (ins memrr:$ptr, GPRC:$new),
562       "${:comment} ATOMIC_SWAP_I32 PSEUDO!",
563       [(set GPRC:$dst, (PPCatomic_swap xoaddr:$ptr, GPRC:$new))]>;
564   }
565 }
566
567 // Instructions to support atomic operations
568 def LWARX : XForm_1<31,  20, (outs GPRC:$rD), (ins memrr:$src),
569                    "lwarx $rD, $src", LdStLWARX,
570                    [(set GPRC:$rD, (PPClarx xoaddr:$src))]>;
571
572 let Defs = [CR0] in
573 def STWCX : XForm_1<31, 150, (outs), (ins GPRC:$rS, memrr:$dst),
574                    "stwcx. $rS, $dst", LdStSTWCX,
575                    [(PPCstcx GPRC:$rS, xoaddr:$dst)]>,
576                    isDOT;
577
578 //===----------------------------------------------------------------------===//
579 // PPC32 Load Instructions.
580 //
581
582 // Unindexed (r+i) Loads. 
583 let isSimpleLoad = 1, PPC970_Unit = 2 in {
584 def LBZ : DForm_1<34, (outs GPRC:$rD), (ins memri:$src),
585                   "lbz $rD, $src", LdStGeneral,
586                   [(set GPRC:$rD, (zextloadi8 iaddr:$src))]>;
587 def LHA : DForm_1<42, (outs GPRC:$rD), (ins memri:$src),
588                   "lha $rD, $src", LdStLHA,
589                   [(set GPRC:$rD, (sextloadi16 iaddr:$src))]>,
590                   PPC970_DGroup_Cracked;
591 def LHZ : DForm_1<40, (outs GPRC:$rD), (ins memri:$src),
592                   "lhz $rD, $src", LdStGeneral,
593                   [(set GPRC:$rD, (zextloadi16 iaddr:$src))]>;
594 def LWZ : DForm_1<32, (outs GPRC:$rD), (ins memri:$src),
595                   "lwz $rD, $src", LdStGeneral,
596                   [(set GPRC:$rD, (load iaddr:$src))]>;
597
598 def LFS : DForm_1<48, (outs F4RC:$rD), (ins memri:$src),
599                   "lfs $rD, $src", LdStLFDU,
600                   [(set F4RC:$rD, (load iaddr:$src))]>;
601 def LFD : DForm_1<50, (outs F8RC:$rD), (ins memri:$src),
602                   "lfd $rD, $src", LdStLFD,
603                   [(set F8RC:$rD, (load iaddr:$src))]>;
604
605
606 // Unindexed (r+i) Loads with Update (preinc).
607 def LBZU : DForm_1<35, (outs GPRC:$rD, ptr_rc:$ea_result), (ins memri:$addr),
608                    "lbzu $rD, $addr", LdStGeneral,
609                    []>, RegConstraint<"$addr.reg = $ea_result">,
610                    NoEncode<"$ea_result">;
611
612 def LHAU : DForm_1<43, (outs GPRC:$rD, ptr_rc:$ea_result), (ins memri:$addr),
613                    "lhau $rD, $addr", LdStGeneral,
614                    []>, RegConstraint<"$addr.reg = $ea_result">,
615                    NoEncode<"$ea_result">;
616
617 def LHZU : DForm_1<41, (outs GPRC:$rD, ptr_rc:$ea_result), (ins memri:$addr),
618                    "lhzu $rD, $addr", LdStGeneral,
619                    []>, RegConstraint<"$addr.reg = $ea_result">,
620                    NoEncode<"$ea_result">;
621
622 def LWZU : DForm_1<33, (outs GPRC:$rD, ptr_rc:$ea_result), (ins memri:$addr),
623                    "lwzu $rD, $addr", LdStGeneral,
624                    []>, RegConstraint<"$addr.reg = $ea_result">,
625                    NoEncode<"$ea_result">;
626
627 def LFSU : DForm_1<49, (outs F4RC:$rD, ptr_rc:$ea_result), (ins memri:$addr),
628                   "lfs $rD, $addr", LdStLFDU,
629                   []>, RegConstraint<"$addr.reg = $ea_result">,
630                    NoEncode<"$ea_result">;
631
632 def LFDU : DForm_1<51, (outs F8RC:$rD, ptr_rc:$ea_result), (ins memri:$addr),
633                   "lfd $rD, $addr", LdStLFD,
634                   []>, RegConstraint<"$addr.reg = $ea_result">,
635                    NoEncode<"$ea_result">;
636 }
637
638 // Indexed (r+r) Loads.
639 //
640 let isSimpleLoad = 1, PPC970_Unit = 2 in {
641 def LBZX : XForm_1<31,  87, (outs GPRC:$rD), (ins memrr:$src),
642                    "lbzx $rD, $src", LdStGeneral,
643                    [(set GPRC:$rD, (zextloadi8 xaddr:$src))]>;
644 def LHAX : XForm_1<31, 343, (outs GPRC:$rD), (ins memrr:$src),
645                    "lhax $rD, $src", LdStLHA,
646                    [(set GPRC:$rD, (sextloadi16 xaddr:$src))]>,
647                    PPC970_DGroup_Cracked;
648 def LHZX : XForm_1<31, 279, (outs GPRC:$rD), (ins memrr:$src),
649                    "lhzx $rD, $src", LdStGeneral,
650                    [(set GPRC:$rD, (zextloadi16 xaddr:$src))]>;
651 def LWZX : XForm_1<31,  23, (outs GPRC:$rD), (ins memrr:$src),
652                    "lwzx $rD, $src", LdStGeneral,
653                    [(set GPRC:$rD, (load xaddr:$src))]>;
654                    
655                    
656 def LHBRX : XForm_1<31, 790, (outs GPRC:$rD), (ins memrr:$src),
657                    "lhbrx $rD, $src", LdStGeneral,
658                    [(set GPRC:$rD, (PPClbrx xoaddr:$src, srcvalue:$sv, i16))]>;
659 def LWBRX : XForm_1<31,  534, (outs GPRC:$rD), (ins memrr:$src),
660                    "lwbrx $rD, $src", LdStGeneral,
661                    [(set GPRC:$rD, (PPClbrx xoaddr:$src, srcvalue:$sv, i32))]>;
662
663 def LFSX   : XForm_25<31, 535, (outs F4RC:$frD), (ins memrr:$src),
664                       "lfsx $frD, $src", LdStLFDU,
665                       [(set F4RC:$frD, (load xaddr:$src))]>;
666 def LFDX   : XForm_25<31, 599, (outs F8RC:$frD), (ins memrr:$src),
667                       "lfdx $frD, $src", LdStLFDU,
668                       [(set F8RC:$frD, (load xaddr:$src))]>;
669 }
670
671 //===----------------------------------------------------------------------===//
672 // PPC32 Store Instructions.
673 //
674
675 // Unindexed (r+i) Stores.
676 let PPC970_Unit = 2 in {
677 def STB  : DForm_1<38, (outs), (ins GPRC:$rS, memri:$src),
678                    "stb $rS, $src", LdStGeneral,
679                    [(truncstorei8 GPRC:$rS, iaddr:$src)]>;
680 def STH  : DForm_1<44, (outs), (ins GPRC:$rS, memri:$src),
681                    "sth $rS, $src", LdStGeneral,
682                    [(truncstorei16 GPRC:$rS, iaddr:$src)]>;
683 def STW  : DForm_1<36, (outs), (ins GPRC:$rS, memri:$src),
684                    "stw $rS, $src", LdStGeneral,
685                    [(store GPRC:$rS, iaddr:$src)]>;
686 def STFS : DForm_1<52, (outs), (ins F4RC:$rS, memri:$dst),
687                    "stfs $rS, $dst", LdStUX,
688                    [(store F4RC:$rS, iaddr:$dst)]>;
689 def STFD : DForm_1<54, (outs), (ins F8RC:$rS, memri:$dst),
690                    "stfd $rS, $dst", LdStUX,
691                    [(store F8RC:$rS, iaddr:$dst)]>;
692 }
693
694 // Unindexed (r+i) Stores with Update (preinc).
695 let PPC970_Unit = 2 in {
696 def STBU  : DForm_1<39, (outs ptr_rc:$ea_res), (ins GPRC:$rS,
697                              symbolLo:$ptroff, ptr_rc:$ptrreg),
698                     "stbu $rS, $ptroff($ptrreg)", LdStGeneral,
699                     [(set ptr_rc:$ea_res,
700                           (pre_truncsti8 GPRC:$rS, ptr_rc:$ptrreg, 
701                                          iaddroff:$ptroff))]>,
702                     RegConstraint<"$ptrreg = $ea_res">, NoEncode<"$ea_res">;
703 def STHU  : DForm_1<45, (outs ptr_rc:$ea_res), (ins GPRC:$rS,
704                              symbolLo:$ptroff, ptr_rc:$ptrreg),
705                     "sthu $rS, $ptroff($ptrreg)", LdStGeneral,
706                     [(set ptr_rc:$ea_res,
707                         (pre_truncsti16 GPRC:$rS, ptr_rc:$ptrreg, 
708                                         iaddroff:$ptroff))]>,
709                     RegConstraint<"$ptrreg = $ea_res">, NoEncode<"$ea_res">;
710 def STWU  : DForm_1<37, (outs ptr_rc:$ea_res), (ins GPRC:$rS,
711                              symbolLo:$ptroff, ptr_rc:$ptrreg),
712                     "stwu $rS, $ptroff($ptrreg)", LdStGeneral,
713                     [(set ptr_rc:$ea_res, (pre_store GPRC:$rS, ptr_rc:$ptrreg, 
714                                                      iaddroff:$ptroff))]>,
715                     RegConstraint<"$ptrreg = $ea_res">, NoEncode<"$ea_res">;
716 def STFSU : DForm_1<37, (outs ptr_rc:$ea_res), (ins F4RC:$rS,
717                              symbolLo:$ptroff, ptr_rc:$ptrreg),
718                     "stfsu $rS, $ptroff($ptrreg)", LdStGeneral,
719                     [(set ptr_rc:$ea_res, (pre_store F4RC:$rS,  ptr_rc:$ptrreg, 
720                                           iaddroff:$ptroff))]>,
721                     RegConstraint<"$ptrreg = $ea_res">, NoEncode<"$ea_res">;
722 def STFDU : DForm_1<37, (outs ptr_rc:$ea_res), (ins F8RC:$rS,
723                              symbolLo:$ptroff, ptr_rc:$ptrreg),
724                     "stfdu $rS, $ptroff($ptrreg)", LdStGeneral,
725                     [(set ptr_rc:$ea_res, (pre_store F8RC:$rS, ptr_rc:$ptrreg, 
726                                           iaddroff:$ptroff))]>,
727                     RegConstraint<"$ptrreg = $ea_res">, NoEncode<"$ea_res">;
728 }
729
730
731 // Indexed (r+r) Stores.
732 //
733 let PPC970_Unit = 2 in {
734 def STBX  : XForm_8<31, 215, (outs), (ins GPRC:$rS, memrr:$dst),
735                    "stbx $rS, $dst", LdStGeneral,
736                    [(truncstorei8 GPRC:$rS, xaddr:$dst)]>, 
737                    PPC970_DGroup_Cracked;
738 def STHX  : XForm_8<31, 407, (outs), (ins GPRC:$rS, memrr:$dst),
739                    "sthx $rS, $dst", LdStGeneral,
740                    [(truncstorei16 GPRC:$rS, xaddr:$dst)]>, 
741                    PPC970_DGroup_Cracked;
742 def STWX  : XForm_8<31, 151, (outs), (ins GPRC:$rS, memrr:$dst),
743                    "stwx $rS, $dst", LdStGeneral,
744                    [(store GPRC:$rS, xaddr:$dst)]>,
745                    PPC970_DGroup_Cracked;
746                    
747 let mayStore = 1 in {
748 def STWUX : XForm_8<31, 183, (outs), (ins GPRC:$rS, GPRC:$rA, GPRC:$rB),
749                    "stwux $rS, $rA, $rB", LdStGeneral,
750                    []>;
751 }
752 def STHBRX: XForm_8<31, 918, (outs), (ins GPRC:$rS, memrr:$dst),
753                    "sthbrx $rS, $dst", LdStGeneral,
754                    [(PPCstbrx GPRC:$rS, xoaddr:$dst, srcvalue:$dummy, i16)]>, 
755                    PPC970_DGroup_Cracked;
756 def STWBRX: XForm_8<31, 662, (outs), (ins GPRC:$rS, memrr:$dst),
757                    "stwbrx $rS, $dst", LdStGeneral,
758                    [(PPCstbrx GPRC:$rS, xoaddr:$dst, srcvalue:$dummy, i32)]>,
759                    PPC970_DGroup_Cracked;
760
761 def STFIWX: XForm_28<31, 983, (outs), (ins F8RC:$frS, memrr:$dst),
762                      "stfiwx $frS, $dst", LdStUX,
763                      [(PPCstfiwx F8RC:$frS, xoaddr:$dst)]>;
764                      
765 def STFSX : XForm_28<31, 663, (outs), (ins F4RC:$frS, memrr:$dst),
766                      "stfsx $frS, $dst", LdStUX,
767                      [(store F4RC:$frS, xaddr:$dst)]>;
768 def STFDX : XForm_28<31, 727, (outs), (ins F8RC:$frS, memrr:$dst),
769                      "stfdx $frS, $dst", LdStUX,
770                      [(store F8RC:$frS, xaddr:$dst)]>;
771 }
772
773
774 //===----------------------------------------------------------------------===//
775 // PPC32 Arithmetic Instructions.
776 //
777
778 let PPC970_Unit = 1 in {  // FXU Operations.
779 def ADDI   : DForm_2<14, (outs GPRC:$rD), (ins GPRC:$rA, s16imm:$imm),
780                      "addi $rD, $rA, $imm", IntGeneral,
781                      [(set GPRC:$rD, (add GPRC:$rA, immSExt16:$imm))]>;
782 def ADDIC  : DForm_2<12, (outs GPRC:$rD), (ins GPRC:$rA, s16imm:$imm),
783                      "addic $rD, $rA, $imm", IntGeneral,
784                      [(set GPRC:$rD, (addc GPRC:$rA, immSExt16:$imm))]>,
785                      PPC970_DGroup_Cracked;
786 def ADDICo : DForm_2<13, (outs GPRC:$rD), (ins GPRC:$rA, s16imm:$imm),
787                      "addic. $rD, $rA, $imm", IntGeneral,
788                      []>;
789 def ADDIS  : DForm_2<15, (outs GPRC:$rD), (ins GPRC:$rA, symbolHi:$imm),
790                      "addis $rD, $rA, $imm", IntGeneral,
791                      [(set GPRC:$rD, (add GPRC:$rA, imm16ShiftedSExt:$imm))]>;
792 def LA     : DForm_2<14, (outs GPRC:$rD), (ins GPRC:$rA, symbolLo:$sym),
793                      "la $rD, $sym($rA)", IntGeneral,
794                      [(set GPRC:$rD, (add GPRC:$rA,
795                                           (PPClo tglobaladdr:$sym, 0)))]>;
796 def MULLI  : DForm_2< 7, (outs GPRC:$rD), (ins GPRC:$rA, s16imm:$imm),
797                      "mulli $rD, $rA, $imm", IntMulLI,
798                      [(set GPRC:$rD, (mul GPRC:$rA, immSExt16:$imm))]>;
799 def SUBFIC : DForm_2< 8, (outs GPRC:$rD), (ins GPRC:$rA, s16imm:$imm),
800                      "subfic $rD, $rA, $imm", IntGeneral,
801                      [(set GPRC:$rD, (subc immSExt16:$imm, GPRC:$rA))]>;
802
803 let isReMaterializable = 1 in {
804   def LI  : DForm_2_r0<14, (outs GPRC:$rD), (ins symbolLo:$imm),
805                        "li $rD, $imm", IntGeneral,
806                        [(set GPRC:$rD, immSExt16:$imm)]>;
807   def LIS : DForm_2_r0<15, (outs GPRC:$rD), (ins symbolHi:$imm),
808                        "lis $rD, $imm", IntGeneral,
809                        [(set GPRC:$rD, imm16ShiftedSExt:$imm)]>;
810 }
811 }
812
813 let PPC970_Unit = 1 in {  // FXU Operations.
814 def ANDIo : DForm_4<28, (outs GPRC:$dst), (ins GPRC:$src1, u16imm:$src2),
815                     "andi. $dst, $src1, $src2", IntGeneral,
816                     [(set GPRC:$dst, (and GPRC:$src1, immZExt16:$src2))]>,
817                     isDOT;
818 def ANDISo : DForm_4<29, (outs GPRC:$dst), (ins GPRC:$src1, u16imm:$src2),
819                     "andis. $dst, $src1, $src2", IntGeneral,
820                     [(set GPRC:$dst, (and GPRC:$src1,imm16ShiftedZExt:$src2))]>,
821                     isDOT;
822 def ORI   : DForm_4<24, (outs GPRC:$dst), (ins GPRC:$src1, u16imm:$src2),
823                     "ori $dst, $src1, $src2", IntGeneral,
824                     [(set GPRC:$dst, (or GPRC:$src1, immZExt16:$src2))]>;
825 def ORIS  : DForm_4<25, (outs GPRC:$dst), (ins GPRC:$src1, u16imm:$src2),
826                     "oris $dst, $src1, $src2", IntGeneral,
827                     [(set GPRC:$dst, (or GPRC:$src1, imm16ShiftedZExt:$src2))]>;
828 def XORI  : DForm_4<26, (outs GPRC:$dst), (ins GPRC:$src1, u16imm:$src2),
829                     "xori $dst, $src1, $src2", IntGeneral,
830                     [(set GPRC:$dst, (xor GPRC:$src1, immZExt16:$src2))]>;
831 def XORIS : DForm_4<27, (outs GPRC:$dst), (ins GPRC:$src1, u16imm:$src2),
832                     "xoris $dst, $src1, $src2", IntGeneral,
833                     [(set GPRC:$dst, (xor GPRC:$src1,imm16ShiftedZExt:$src2))]>;
834 def NOP   : DForm_4_zero<24, (outs), (ins), "nop", IntGeneral,
835                          []>;
836 def CMPWI : DForm_5_ext<11, (outs CRRC:$crD), (ins GPRC:$rA, s16imm:$imm),
837                         "cmpwi $crD, $rA, $imm", IntCompare>;
838 def CMPLWI : DForm_6_ext<10, (outs CRRC:$dst), (ins GPRC:$src1, u16imm:$src2),
839                          "cmplwi $dst, $src1, $src2", IntCompare>;
840 }
841
842
843 let PPC970_Unit = 1 in {  // FXU Operations.
844 def NAND : XForm_6<31, 476, (outs GPRC:$rA), (ins GPRC:$rS, GPRC:$rB),
845                    "nand $rA, $rS, $rB", IntGeneral,
846                    [(set GPRC:$rA, (not (and GPRC:$rS, GPRC:$rB)))]>;
847 def AND  : XForm_6<31,  28, (outs GPRC:$rA), (ins GPRC:$rS, GPRC:$rB),
848                    "and $rA, $rS, $rB", IntGeneral,
849                    [(set GPRC:$rA, (and GPRC:$rS, GPRC:$rB))]>;
850 def ANDC : XForm_6<31,  60, (outs GPRC:$rA), (ins GPRC:$rS, GPRC:$rB),
851                    "andc $rA, $rS, $rB", IntGeneral,
852                    [(set GPRC:$rA, (and GPRC:$rS, (not GPRC:$rB)))]>;
853 def OR   : XForm_6<31, 444, (outs GPRC:$rA), (ins GPRC:$rS, GPRC:$rB),
854                    "or $rA, $rS, $rB", IntGeneral,
855                    [(set GPRC:$rA, (or GPRC:$rS, GPRC:$rB))]>;
856 def NOR  : XForm_6<31, 124, (outs GPRC:$rA), (ins GPRC:$rS, GPRC:$rB),
857                    "nor $rA, $rS, $rB", IntGeneral,
858                    [(set GPRC:$rA, (not (or GPRC:$rS, GPRC:$rB)))]>;
859 def ORC  : XForm_6<31, 412, (outs GPRC:$rA), (ins GPRC:$rS, GPRC:$rB),
860                    "orc $rA, $rS, $rB", IntGeneral,
861                    [(set GPRC:$rA, (or GPRC:$rS, (not GPRC:$rB)))]>;
862 def EQV  : XForm_6<31, 284, (outs GPRC:$rA), (ins GPRC:$rS, GPRC:$rB),
863                    "eqv $rA, $rS, $rB", IntGeneral,
864                    [(set GPRC:$rA, (not (xor GPRC:$rS, GPRC:$rB)))]>;
865 def XOR  : XForm_6<31, 316, (outs GPRC:$rA), (ins GPRC:$rS, GPRC:$rB),
866                    "xor $rA, $rS, $rB", IntGeneral,
867                    [(set GPRC:$rA, (xor GPRC:$rS, GPRC:$rB))]>;
868 def SLW  : XForm_6<31,  24, (outs GPRC:$rA), (ins GPRC:$rS, GPRC:$rB),
869                    "slw $rA, $rS, $rB", IntGeneral,
870                    [(set GPRC:$rA, (PPCshl GPRC:$rS, GPRC:$rB))]>;
871 def SRW  : XForm_6<31, 536, (outs GPRC:$rA), (ins GPRC:$rS, GPRC:$rB),
872                    "srw $rA, $rS, $rB", IntGeneral,
873                    [(set GPRC:$rA, (PPCsrl GPRC:$rS, GPRC:$rB))]>;
874 def SRAW : XForm_6<31, 792, (outs GPRC:$rA), (ins GPRC:$rS, GPRC:$rB),
875                    "sraw $rA, $rS, $rB", IntShift,
876                    [(set GPRC:$rA, (PPCsra GPRC:$rS, GPRC:$rB))]>;
877 }
878
879 let PPC970_Unit = 1 in {  // FXU Operations.
880 def SRAWI : XForm_10<31, 824, (outs GPRC:$rA), (ins GPRC:$rS, u5imm:$SH), 
881                      "srawi $rA, $rS, $SH", IntShift,
882                      [(set GPRC:$rA, (sra GPRC:$rS, (i32 imm:$SH)))]>;
883 def CNTLZW : XForm_11<31,  26, (outs GPRC:$rA), (ins GPRC:$rS),
884                       "cntlzw $rA, $rS", IntGeneral,
885                       [(set GPRC:$rA, (ctlz GPRC:$rS))]>;
886 def EXTSB  : XForm_11<31, 954, (outs GPRC:$rA), (ins GPRC:$rS),
887                       "extsb $rA, $rS", IntGeneral,
888                       [(set GPRC:$rA, (sext_inreg GPRC:$rS, i8))]>;
889 def EXTSH  : XForm_11<31, 922, (outs GPRC:$rA), (ins GPRC:$rS),
890                       "extsh $rA, $rS", IntGeneral,
891                       [(set GPRC:$rA, (sext_inreg GPRC:$rS, i16))]>;
892
893 def CMPW   : XForm_16_ext<31, 0, (outs CRRC:$crD), (ins GPRC:$rA, GPRC:$rB),
894                           "cmpw $crD, $rA, $rB", IntCompare>;
895 def CMPLW  : XForm_16_ext<31, 32, (outs CRRC:$crD), (ins GPRC:$rA, GPRC:$rB),
896                           "cmplw $crD, $rA, $rB", IntCompare>;
897 }
898 let PPC970_Unit = 3 in {  // FPU Operations.
899 //def FCMPO  : XForm_17<63, 32, (outs CRRC:$crD), (ins FPRC:$fA, FPRC:$fB),
900 //                      "fcmpo $crD, $fA, $fB", FPCompare>;
901 def FCMPUS : XForm_17<63, 0, (outs CRRC:$crD), (ins F4RC:$fA, F4RC:$fB),
902                       "fcmpu $crD, $fA, $fB", FPCompare>;
903 def FCMPUD : XForm_17<63, 0, (outs CRRC:$crD), (ins F8RC:$fA, F8RC:$fB),
904                       "fcmpu $crD, $fA, $fB", FPCompare>;
905
906 def FCTIWZ : XForm_26<63, 15, (outs F8RC:$frD), (ins F8RC:$frB),
907                       "fctiwz $frD, $frB", FPGeneral,
908                       [(set F8RC:$frD, (PPCfctiwz F8RC:$frB))]>;
909 def FRSP   : XForm_26<63, 12, (outs F4RC:$frD), (ins F8RC:$frB),
910                       "frsp $frD, $frB", FPGeneral,
911                       [(set F4RC:$frD, (fround F8RC:$frB))]>;
912 def FSQRT  : XForm_26<63, 22, (outs F8RC:$frD), (ins F8RC:$frB),
913                       "fsqrt $frD, $frB", FPSqrt,
914                       [(set F8RC:$frD, (fsqrt F8RC:$frB))]>;
915 def FSQRTS : XForm_26<59, 22, (outs F4RC:$frD), (ins F4RC:$frB),
916                       "fsqrts $frD, $frB", FPSqrt,
917                       [(set F4RC:$frD, (fsqrt F4RC:$frB))]>;
918 }
919
920 /// FMR is split into 3 versions, one for 4/8 byte FP, and one for extending.
921 ///
922 /// Note that these are defined as pseudo-ops on the PPC970 because they are
923 /// often coalesced away and we don't want the dispatch group builder to think
924 /// that they will fill slots (which could cause the load of a LSU reject to
925 /// sneak into a d-group with a store).
926 def FMRS   : XForm_26<63, 72, (outs F4RC:$frD), (ins F4RC:$frB),
927                       "fmr $frD, $frB", FPGeneral,
928                       []>,  // (set F4RC:$frD, F4RC:$frB)
929                       PPC970_Unit_Pseudo;
930 def FMRD   : XForm_26<63, 72, (outs F8RC:$frD), (ins F8RC:$frB),
931                       "fmr $frD, $frB", FPGeneral,
932                       []>,  // (set F8RC:$frD, F8RC:$frB)
933                       PPC970_Unit_Pseudo;
934 def FMRSD  : XForm_26<63, 72, (outs F8RC:$frD), (ins F4RC:$frB),
935                       "fmr $frD, $frB", FPGeneral,
936                       [(set F8RC:$frD, (fextend F4RC:$frB))]>,
937                       PPC970_Unit_Pseudo;
938
939 let PPC970_Unit = 3 in {  // FPU Operations.
940 // These are artificially split into two different forms, for 4/8 byte FP.
941 def FABSS  : XForm_26<63, 264, (outs F4RC:$frD), (ins F4RC:$frB),
942                       "fabs $frD, $frB", FPGeneral,
943                       [(set F4RC:$frD, (fabs F4RC:$frB))]>;
944 def FABSD  : XForm_26<63, 264, (outs F8RC:$frD), (ins F8RC:$frB),
945                       "fabs $frD, $frB", FPGeneral,
946                       [(set F8RC:$frD, (fabs F8RC:$frB))]>;
947 def FNABSS : XForm_26<63, 136, (outs F4RC:$frD), (ins F4RC:$frB),
948                       "fnabs $frD, $frB", FPGeneral,
949                       [(set F4RC:$frD, (fneg (fabs F4RC:$frB)))]>;
950 def FNABSD : XForm_26<63, 136, (outs F8RC:$frD), (ins F8RC:$frB),
951                       "fnabs $frD, $frB", FPGeneral,
952                       [(set F8RC:$frD, (fneg (fabs F8RC:$frB)))]>;
953 def FNEGS  : XForm_26<63, 40, (outs F4RC:$frD), (ins F4RC:$frB),
954                       "fneg $frD, $frB", FPGeneral,
955                       [(set F4RC:$frD, (fneg F4RC:$frB))]>;
956 def FNEGD  : XForm_26<63, 40, (outs F8RC:$frD), (ins F8RC:$frB),
957                       "fneg $frD, $frB", FPGeneral,
958                       [(set F8RC:$frD, (fneg F8RC:$frB))]>;
959 }
960                       
961
962 // XL-Form instructions.  condition register logical ops.
963 //
964 def MCRF   : XLForm_3<19, 0, (outs CRRC:$BF), (ins CRRC:$BFA),
965                       "mcrf $BF, $BFA", BrMCR>,
966              PPC970_DGroup_First, PPC970_Unit_CRU;
967
968 def CREQV  : XLForm_1<19, 289, (outs CRBITRC:$CRD),
969                                (ins CRBITRC:$CRA, CRBITRC:$CRB),
970                       "creqv $CRD, $CRA, $CRB", BrCR,
971                       []>;
972
973 def CROR  : XLForm_1<19, 449, (outs CRBITRC:$CRD),
974                                (ins CRBITRC:$CRA, CRBITRC:$CRB),
975                       "cror $CRD, $CRA, $CRB", BrCR,
976                       []>;
977
978 def CRSET  : XLForm_1_ext<19, 289, (outs CRBITRC:$dst), (ins),
979               "creqv $dst, $dst, $dst", BrCR,
980               []>;
981
982 // XFX-Form instructions.  Instructions that deal with SPRs.
983 //
984 def MFCTR : XFXForm_1_ext<31, 339, 9, (outs GPRC:$rT), (ins),
985                           "mfctr $rT", SprMFSPR>,
986             PPC970_DGroup_First, PPC970_Unit_FXU;
987 let Pattern = [(PPCmtctr GPRC:$rS)] in {
988 def MTCTR : XFXForm_7_ext<31, 467, 9, (outs), (ins GPRC:$rS),
989                           "mtctr $rS", SprMTSPR>,
990             PPC970_DGroup_First, PPC970_Unit_FXU;
991 }
992
993 def MTLR  : XFXForm_7_ext<31, 467, 8, (outs), (ins GPRC:$rS),
994                           "mtlr $rS", SprMTSPR>,
995             PPC970_DGroup_First, PPC970_Unit_FXU;
996 def MFLR  : XFXForm_1_ext<31, 339, 8, (outs GPRC:$rT), (ins),
997                           "mflr $rT", SprMFSPR>,
998             PPC970_DGroup_First, PPC970_Unit_FXU;
999
1000 // Move to/from VRSAVE: despite being a SPR, the VRSAVE register is renamed like
1001 // a GPR on the PPC970.  As such, copies in and out have the same performance
1002 // characteristics as an OR instruction.
1003 def MTVRSAVE : XFXForm_7_ext<31, 467, 256, (outs), (ins GPRC:$rS),
1004                              "mtspr 256, $rS", IntGeneral>,
1005                PPC970_DGroup_Single, PPC970_Unit_FXU;
1006 def MFVRSAVE : XFXForm_1_ext<31, 339, 256, (outs GPRC:$rT), (ins),
1007                              "mfspr $rT, 256", IntGeneral>,
1008                PPC970_DGroup_First, PPC970_Unit_FXU;
1009
1010 def MTCRF : XFXForm_5<31, 144, (outs), (ins crbitm:$FXM, GPRC:$rS),
1011                       "mtcrf $FXM, $rS", BrMCRX>,
1012             PPC970_MicroCode, PPC970_Unit_CRU;
1013 def MFCR  : XFXForm_3<31, 19, (outs GPRC:$rT), (ins), "mfcr $rT", SprMFCR>,
1014             PPC970_MicroCode, PPC970_Unit_CRU;
1015 def MFOCRF: XFXForm_5a<31, 19, (outs GPRC:$rT), (ins crbitm:$FXM),
1016                        "mfcr $rT, $FXM", SprMFCR>,
1017             PPC970_DGroup_First, PPC970_Unit_CRU;
1018
1019 // Instructions to manipulate FPSCR.  Only long double handling uses these.
1020 // FPSCR is not modelled; we use the SDNode Flag to keep things in order.
1021
1022 def MFFS   : XForm_42<63, 583, (outs F8RC:$rT), (ins), 
1023                        "mffs $rT", IntMFFS,
1024                        [(set F8RC:$rT, (PPCmffs))]>,
1025              PPC970_DGroup_Single, PPC970_Unit_FPU;
1026 def MTFSB0 : XForm_43<63, 70, (outs), (ins u5imm:$FM),
1027                        "mtfsb0 $FM", IntMTFSB0,
1028                       [(PPCmtfsb0 (i32 imm:$FM))]>,
1029              PPC970_DGroup_Single, PPC970_Unit_FPU;
1030 def MTFSB1 : XForm_43<63, 38, (outs), (ins u5imm:$FM),
1031                        "mtfsb1 $FM", IntMTFSB0,
1032                       [(PPCmtfsb1 (i32 imm:$FM))]>,
1033              PPC970_DGroup_Single, PPC970_Unit_FPU;
1034 def FADDrtz: AForm_2<63, 21,
1035                     (outs F8RC:$FRT), (ins F8RC:$FRA, F8RC:$FRB),
1036                     "fadd $FRT, $FRA, $FRB", FPGeneral,
1037                     [(set F8RC:$FRT, (PPCfaddrtz F8RC:$FRA, F8RC:$FRB))]>,
1038              PPC970_DGroup_Single, PPC970_Unit_FPU;
1039 // MTFSF does not actually produce an FP result.  We pretend it copies
1040 // input reg B to the output.  If we didn't do this it would look like the
1041 // instruction had no outputs (because we aren't modelling the FPSCR) and
1042 // it would be deleted.
1043 def MTFSF  : XFLForm<63, 711, (outs F8RC:$FRA),
1044                               (ins i32imm:$FM, F8RC:$rT, F8RC:$FRB),
1045                        "mtfsf $FM, $rT", "$FRB = $FRA", IntMTFSB0,
1046                        [(set F8RC:$FRA, (PPCmtfsf (i32 imm:$FM), 
1047                                                    F8RC:$rT, F8RC:$FRB))]>,
1048              PPC970_DGroup_Single, PPC970_Unit_FPU;
1049
1050 let PPC970_Unit = 1 in {  // FXU Operations.
1051
1052 // XO-Form instructions.  Arithmetic instructions that can set overflow bit
1053 //
1054 def ADD4  : XOForm_1<31, 266, 0, (outs GPRC:$rT), (ins GPRC:$rA, GPRC:$rB),
1055                      "add $rT, $rA, $rB", IntGeneral,
1056                      [(set GPRC:$rT, (add GPRC:$rA, GPRC:$rB))]>;
1057 def ADDC  : XOForm_1<31, 10, 0, (outs GPRC:$rT), (ins GPRC:$rA, GPRC:$rB),
1058                      "addc $rT, $rA, $rB", IntGeneral,
1059                      [(set GPRC:$rT, (addc GPRC:$rA, GPRC:$rB))]>,
1060                      PPC970_DGroup_Cracked;
1061 def ADDE  : XOForm_1<31, 138, 0, (outs GPRC:$rT), (ins GPRC:$rA, GPRC:$rB),
1062                      "adde $rT, $rA, $rB", IntGeneral,
1063                      [(set GPRC:$rT, (adde GPRC:$rA, GPRC:$rB))]>;
1064 def DIVW  : XOForm_1<31, 491, 0, (outs GPRC:$rT), (ins GPRC:$rA, GPRC:$rB),
1065                      "divw $rT, $rA, $rB", IntDivW,
1066                      [(set GPRC:$rT, (sdiv GPRC:$rA, GPRC:$rB))]>,
1067                      PPC970_DGroup_First, PPC970_DGroup_Cracked;
1068 def DIVWU : XOForm_1<31, 459, 0, (outs GPRC:$rT), (ins GPRC:$rA, GPRC:$rB),
1069                      "divwu $rT, $rA, $rB", IntDivW,
1070                      [(set GPRC:$rT, (udiv GPRC:$rA, GPRC:$rB))]>,
1071                      PPC970_DGroup_First, PPC970_DGroup_Cracked;
1072 def MULHW : XOForm_1<31, 75, 0, (outs GPRC:$rT), (ins GPRC:$rA, GPRC:$rB),
1073                      "mulhw $rT, $rA, $rB", IntMulHW,
1074                      [(set GPRC:$rT, (mulhs GPRC:$rA, GPRC:$rB))]>;
1075 def MULHWU : XOForm_1<31, 11, 0, (outs GPRC:$rT), (ins GPRC:$rA, GPRC:$rB),
1076                      "mulhwu $rT, $rA, $rB", IntMulHWU,
1077                      [(set GPRC:$rT, (mulhu GPRC:$rA, GPRC:$rB))]>;
1078 def MULLW : XOForm_1<31, 235, 0, (outs GPRC:$rT), (ins GPRC:$rA, GPRC:$rB),
1079                      "mullw $rT, $rA, $rB", IntMulHW,
1080                      [(set GPRC:$rT, (mul GPRC:$rA, GPRC:$rB))]>;
1081 def SUBF  : XOForm_1<31, 40, 0, (outs GPRC:$rT), (ins GPRC:$rA, GPRC:$rB),
1082                      "subf $rT, $rA, $rB", IntGeneral,
1083                      [(set GPRC:$rT, (sub GPRC:$rB, GPRC:$rA))]>;
1084 def SUBFC : XOForm_1<31, 8, 0, (outs GPRC:$rT), (ins GPRC:$rA, GPRC:$rB),
1085                      "subfc $rT, $rA, $rB", IntGeneral,
1086                      [(set GPRC:$rT, (subc GPRC:$rB, GPRC:$rA))]>,
1087                      PPC970_DGroup_Cracked;
1088 def SUBFE : XOForm_1<31, 136, 0, (outs GPRC:$rT), (ins GPRC:$rA, GPRC:$rB),
1089                      "subfe $rT, $rA, $rB", IntGeneral,
1090                      [(set GPRC:$rT, (sube GPRC:$rB, GPRC:$rA))]>;
1091 def ADDME  : XOForm_3<31, 234, 0, (outs GPRC:$rT), (ins GPRC:$rA),
1092                       "addme $rT, $rA", IntGeneral,
1093                       [(set GPRC:$rT, (adde GPRC:$rA, immAllOnes))]>;
1094 def ADDZE  : XOForm_3<31, 202, 0, (outs GPRC:$rT), (ins GPRC:$rA),
1095                       "addze $rT, $rA", IntGeneral,
1096                       [(set GPRC:$rT, (adde GPRC:$rA, 0))]>;
1097 def NEG    : XOForm_3<31, 104, 0, (outs GPRC:$rT), (ins GPRC:$rA),
1098                       "neg $rT, $rA", IntGeneral,
1099                       [(set GPRC:$rT, (ineg GPRC:$rA))]>;
1100 def SUBFME : XOForm_3<31, 232, 0, (outs GPRC:$rT), (ins GPRC:$rA),
1101                       "subfme $rT, $rA", IntGeneral,
1102                       [(set GPRC:$rT, (sube immAllOnes, GPRC:$rA))]>;
1103 def SUBFZE : XOForm_3<31, 200, 0, (outs GPRC:$rT), (ins GPRC:$rA),
1104                       "subfze $rT, $rA", IntGeneral,
1105                       [(set GPRC:$rT, (sube 0, GPRC:$rA))]>;
1106 }
1107
1108 // A-Form instructions.  Most of the instructions executed in the FPU are of
1109 // this type.
1110 //
1111 let PPC970_Unit = 3 in {  // FPU Operations.
1112 def FMADD : AForm_1<63, 29, 
1113                     (outs F8RC:$FRT), (ins F8RC:$FRA, F8RC:$FRC, F8RC:$FRB),
1114                     "fmadd $FRT, $FRA, $FRC, $FRB", FPFused,
1115                     [(set F8RC:$FRT, (fadd (fmul F8RC:$FRA, F8RC:$FRC),
1116                                            F8RC:$FRB))]>,
1117                     Requires<[FPContractions]>;
1118 def FMADDS : AForm_1<59, 29,
1119                     (outs F4RC:$FRT), (ins F4RC:$FRA, F4RC:$FRC, F4RC:$FRB),
1120                     "fmadds $FRT, $FRA, $FRC, $FRB", FPGeneral,
1121                     [(set F4RC:$FRT, (fadd (fmul F4RC:$FRA, F4RC:$FRC),
1122                                            F4RC:$FRB))]>,
1123                     Requires<[FPContractions]>;
1124 def FMSUB : AForm_1<63, 28,
1125                     (outs F8RC:$FRT), (ins F8RC:$FRA, F8RC:$FRC, F8RC:$FRB),
1126                     "fmsub $FRT, $FRA, $FRC, $FRB", FPFused,
1127                     [(set F8RC:$FRT, (fsub (fmul F8RC:$FRA, F8RC:$FRC),
1128                                            F8RC:$FRB))]>,
1129                     Requires<[FPContractions]>;
1130 def FMSUBS : AForm_1<59, 28,
1131                     (outs F4RC:$FRT), (ins F4RC:$FRA, F4RC:$FRC, F4RC:$FRB),
1132                     "fmsubs $FRT, $FRA, $FRC, $FRB", FPGeneral,
1133                     [(set F4RC:$FRT, (fsub (fmul F4RC:$FRA, F4RC:$FRC),
1134                                            F4RC:$FRB))]>,
1135                     Requires<[FPContractions]>;
1136 def FNMADD : AForm_1<63, 31,
1137                     (outs F8RC:$FRT), (ins F8RC:$FRA, F8RC:$FRC, F8RC:$FRB),
1138                     "fnmadd $FRT, $FRA, $FRC, $FRB", FPFused,
1139                     [(set F8RC:$FRT, (fneg (fadd (fmul F8RC:$FRA, F8RC:$FRC),
1140                                                  F8RC:$FRB)))]>,
1141                     Requires<[FPContractions]>;
1142 def FNMADDS : AForm_1<59, 31,
1143                     (outs F4RC:$FRT), (ins F4RC:$FRA, F4RC:$FRC, F4RC:$FRB),
1144                     "fnmadds $FRT, $FRA, $FRC, $FRB", FPGeneral,
1145                     [(set F4RC:$FRT, (fneg (fadd (fmul F4RC:$FRA, F4RC:$FRC),
1146                                                  F4RC:$FRB)))]>,
1147                     Requires<[FPContractions]>;
1148 def FNMSUB : AForm_1<63, 30,
1149                     (outs F8RC:$FRT), (ins F8RC:$FRA, F8RC:$FRC, F8RC:$FRB),
1150                     "fnmsub $FRT, $FRA, $FRC, $FRB", FPFused,
1151                     [(set F8RC:$FRT, (fneg (fsub (fmul F8RC:$FRA, F8RC:$FRC),
1152                                                  F8RC:$FRB)))]>,
1153                     Requires<[FPContractions]>;
1154 def FNMSUBS : AForm_1<59, 30,
1155                     (outs F4RC:$FRT), (ins F4RC:$FRA, F4RC:$FRC, F4RC:$FRB),
1156                     "fnmsubs $FRT, $FRA, $FRC, $FRB", FPGeneral,
1157                     [(set F4RC:$FRT, (fneg (fsub (fmul F4RC:$FRA, F4RC:$FRC),
1158                                                  F4RC:$FRB)))]>,
1159                     Requires<[FPContractions]>;
1160 // FSEL is artificially split into 4 and 8-byte forms for the result.  To avoid
1161 // having 4 of these, force the comparison to always be an 8-byte double (code
1162 // should use an FMRSD if the input comparison value really wants to be a float)
1163 // and 4/8 byte forms for the result and operand type..
1164 def FSELD : AForm_1<63, 23,
1165                     (outs F8RC:$FRT), (ins F8RC:$FRA, F8RC:$FRC, F8RC:$FRB),
1166                     "fsel $FRT, $FRA, $FRC, $FRB", FPGeneral,
1167                     [(set F8RC:$FRT, (PPCfsel F8RC:$FRA,F8RC:$FRC,F8RC:$FRB))]>;
1168 def FSELS : AForm_1<63, 23,
1169                      (outs F4RC:$FRT), (ins F8RC:$FRA, F4RC:$FRC, F4RC:$FRB),
1170                      "fsel $FRT, $FRA, $FRC, $FRB", FPGeneral,
1171                     [(set F4RC:$FRT, (PPCfsel F8RC:$FRA,F4RC:$FRC,F4RC:$FRB))]>;
1172 def FADD  : AForm_2<63, 21,
1173                     (outs F8RC:$FRT), (ins F8RC:$FRA, F8RC:$FRB),
1174                     "fadd $FRT, $FRA, $FRB", FPGeneral,
1175                     [(set F8RC:$FRT, (fadd F8RC:$FRA, F8RC:$FRB))]>;
1176 def FADDS : AForm_2<59, 21,
1177                     (outs F4RC:$FRT), (ins F4RC:$FRA, F4RC:$FRB),
1178                     "fadds $FRT, $FRA, $FRB", FPGeneral,
1179                     [(set F4RC:$FRT, (fadd F4RC:$FRA, F4RC:$FRB))]>;
1180 def FDIV  : AForm_2<63, 18,
1181                     (outs F8RC:$FRT), (ins F8RC:$FRA, F8RC:$FRB),
1182                     "fdiv $FRT, $FRA, $FRB", FPDivD,
1183                     [(set F8RC:$FRT, (fdiv F8RC:$FRA, F8RC:$FRB))]>;
1184 def FDIVS : AForm_2<59, 18,
1185                     (outs F4RC:$FRT), (ins F4RC:$FRA, F4RC:$FRB),
1186                     "fdivs $FRT, $FRA, $FRB", FPDivS,
1187                     [(set F4RC:$FRT, (fdiv F4RC:$FRA, F4RC:$FRB))]>;
1188 def FMUL  : AForm_3<63, 25,
1189                     (outs F8RC:$FRT), (ins F8RC:$FRA, F8RC:$FRB),
1190                     "fmul $FRT, $FRA, $FRB", FPFused,
1191                     [(set F8RC:$FRT, (fmul F8RC:$FRA, F8RC:$FRB))]>;
1192 def FMULS : AForm_3<59, 25,
1193                     (outs F4RC:$FRT), (ins F4RC:$FRA, F4RC:$FRB),
1194                     "fmuls $FRT, $FRA, $FRB", FPGeneral,
1195                     [(set F4RC:$FRT, (fmul F4RC:$FRA, F4RC:$FRB))]>;
1196 def FSUB  : AForm_2<63, 20,
1197                     (outs F8RC:$FRT), (ins F8RC:$FRA, F8RC:$FRB),
1198                     "fsub $FRT, $FRA, $FRB", FPGeneral,
1199                     [(set F8RC:$FRT, (fsub F8RC:$FRA, F8RC:$FRB))]>;
1200 def FSUBS : AForm_2<59, 20,
1201                     (outs F4RC:$FRT), (ins F4RC:$FRA, F4RC:$FRB),
1202                     "fsubs $FRT, $FRA, $FRB", FPGeneral,
1203                     [(set F4RC:$FRT, (fsub F4RC:$FRA, F4RC:$FRB))]>;
1204 }
1205
1206 let PPC970_Unit = 1 in {  // FXU Operations.
1207 // M-Form instructions.  rotate and mask instructions.
1208 //
1209 let isCommutable = 1 in {
1210 // RLWIMI can be commuted if the rotate amount is zero.
1211 def RLWIMI : MForm_2<20,
1212                      (outs GPRC:$rA), (ins GPRC:$rSi, GPRC:$rS, u5imm:$SH, u5imm:$MB, 
1213                       u5imm:$ME), "rlwimi $rA, $rS, $SH, $MB, $ME", IntRotate,
1214                       []>, PPC970_DGroup_Cracked, RegConstraint<"$rSi = $rA">,
1215                       NoEncode<"$rSi">;
1216 }
1217 def RLWINM : MForm_2<21,
1218                      (outs GPRC:$rA), (ins GPRC:$rS, u5imm:$SH, u5imm:$MB, u5imm:$ME),
1219                      "rlwinm $rA, $rS, $SH, $MB, $ME", IntGeneral,
1220                      []>;
1221 def RLWINMo : MForm_2<21,
1222                      (outs GPRC:$rA), (ins GPRC:$rS, u5imm:$SH, u5imm:$MB, u5imm:$ME),
1223                      "rlwinm. $rA, $rS, $SH, $MB, $ME", IntGeneral,
1224                      []>, isDOT, PPC970_DGroup_Cracked;
1225 def RLWNM  : MForm_2<23,
1226                      (outs GPRC:$rA), (ins GPRC:$rS, GPRC:$rB, u5imm:$MB, u5imm:$ME),
1227                      "rlwnm $rA, $rS, $rB, $MB, $ME", IntGeneral,
1228                      []>;
1229 }
1230
1231
1232 //===----------------------------------------------------------------------===//
1233 // DWARF Pseudo Instructions
1234 //
1235
1236 def DWARF_LOC        : Pseudo<(outs), (ins i32imm:$line, i32imm:$col, i32imm:$file),
1237                               "${:comment} .loc $file, $line, $col",
1238                       [(dwarf_loc (i32 imm:$line), (i32 imm:$col),
1239                                   (i32 imm:$file))]>;
1240
1241 //===----------------------------------------------------------------------===//
1242 // PowerPC Instruction Patterns
1243 //
1244
1245 // Arbitrary immediate support.  Implement in terms of LIS/ORI.
1246 def : Pat<(i32 imm:$imm),
1247           (ORI (LIS (HI16 imm:$imm)), (LO16 imm:$imm))>;
1248
1249 // Implement the 'not' operation with the NOR instruction.
1250 def NOT : Pat<(not GPRC:$in),
1251               (NOR GPRC:$in, GPRC:$in)>;
1252
1253 // ADD an arbitrary immediate.
1254 def : Pat<(add GPRC:$in, imm:$imm),
1255           (ADDIS (ADDI GPRC:$in, (LO16 imm:$imm)), (HA16 imm:$imm))>;
1256 // OR an arbitrary immediate.
1257 def : Pat<(or GPRC:$in, imm:$imm),
1258           (ORIS (ORI GPRC:$in, (LO16 imm:$imm)), (HI16 imm:$imm))>;
1259 // XOR an arbitrary immediate.
1260 def : Pat<(xor GPRC:$in, imm:$imm),
1261           (XORIS (XORI GPRC:$in, (LO16 imm:$imm)), (HI16 imm:$imm))>;
1262 // SUBFIC
1263 def : Pat<(sub  immSExt16:$imm, GPRC:$in),
1264           (SUBFIC GPRC:$in, imm:$imm)>;
1265
1266 // SHL/SRL
1267 def : Pat<(shl GPRC:$in, (i32 imm:$imm)),
1268           (RLWINM GPRC:$in, imm:$imm, 0, (SHL32 imm:$imm))>;
1269 def : Pat<(srl GPRC:$in, (i32 imm:$imm)),
1270           (RLWINM GPRC:$in, (SRL32 imm:$imm), imm:$imm, 31)>;
1271
1272 // ROTL
1273 def : Pat<(rotl GPRC:$in, GPRC:$sh),
1274           (RLWNM GPRC:$in, GPRC:$sh, 0, 31)>;
1275 def : Pat<(rotl GPRC:$in, (i32 imm:$imm)),
1276           (RLWINM GPRC:$in, imm:$imm, 0, 31)>;
1277
1278 // RLWNM
1279 def : Pat<(and (rotl GPRC:$in, GPRC:$sh), maskimm32:$imm),
1280           (RLWNM GPRC:$in, GPRC:$sh, (MB maskimm32:$imm), (ME maskimm32:$imm))>;
1281
1282 // Calls
1283 def : Pat<(PPCcall_Macho (i32 tglobaladdr:$dst)),
1284           (BL_Macho tglobaladdr:$dst)>;
1285 def : Pat<(PPCcall_Macho (i32 texternalsym:$dst)),
1286           (BL_Macho texternalsym:$dst)>;
1287 def : Pat<(PPCcall_ELF (i32 tglobaladdr:$dst)),
1288           (BL_ELF tglobaladdr:$dst)>;
1289 def : Pat<(PPCcall_ELF (i32 texternalsym:$dst)),
1290           (BL_ELF texternalsym:$dst)>;
1291
1292
1293 def : Pat<(PPCtc_return (i32 tglobaladdr:$dst),  imm:$imm),
1294           (TCRETURNdi tglobaladdr:$dst, imm:$imm)>;
1295
1296 def : Pat<(PPCtc_return (i32 texternalsym:$dst), imm:$imm),
1297           (TCRETURNdi texternalsym:$dst, imm:$imm)>;
1298
1299 def : Pat<(PPCtc_return CTRRC:$dst, imm:$imm),
1300           (TCRETURNri CTRRC:$dst, imm:$imm)>;
1301
1302
1303
1304 // Hi and Lo for Darwin Global Addresses.
1305 def : Pat<(PPChi tglobaladdr:$in, 0), (LIS tglobaladdr:$in)>;
1306 def : Pat<(PPClo tglobaladdr:$in, 0), (LI tglobaladdr:$in)>;
1307 def : Pat<(PPChi tconstpool:$in, 0), (LIS tconstpool:$in)>;
1308 def : Pat<(PPClo tconstpool:$in, 0), (LI tconstpool:$in)>;
1309 def : Pat<(PPChi tjumptable:$in, 0), (LIS tjumptable:$in)>;
1310 def : Pat<(PPClo tjumptable:$in, 0), (LI tjumptable:$in)>;
1311 def : Pat<(add GPRC:$in, (PPChi tglobaladdr:$g, 0)),
1312           (ADDIS GPRC:$in, tglobaladdr:$g)>;
1313 def : Pat<(add GPRC:$in, (PPChi tconstpool:$g, 0)),
1314           (ADDIS GPRC:$in, tconstpool:$g)>;
1315 def : Pat<(add GPRC:$in, (PPChi tjumptable:$g, 0)),
1316           (ADDIS GPRC:$in, tjumptable:$g)>;
1317
1318 // Fused negative multiply subtract, alternate pattern
1319 def : Pat<(fsub F8RC:$B, (fmul F8RC:$A, F8RC:$C)),
1320           (FNMSUB F8RC:$A, F8RC:$C, F8RC:$B)>,
1321           Requires<[FPContractions]>;
1322 def : Pat<(fsub F4RC:$B, (fmul F4RC:$A, F4RC:$C)),
1323           (FNMSUBS F4RC:$A, F4RC:$C, F4RC:$B)>,
1324           Requires<[FPContractions]>;
1325
1326 // Standard shifts.  These are represented separately from the real shifts above
1327 // so that we can distinguish between shifts that allow 5-bit and 6-bit shift
1328 // amounts.
1329 def : Pat<(sra GPRC:$rS, GPRC:$rB),
1330           (SRAW GPRC:$rS, GPRC:$rB)>;
1331 def : Pat<(srl GPRC:$rS, GPRC:$rB),
1332           (SRW GPRC:$rS, GPRC:$rB)>;
1333 def : Pat<(shl GPRC:$rS, GPRC:$rB),
1334           (SLW GPRC:$rS, GPRC:$rB)>;
1335
1336 def : Pat<(zextloadi1 iaddr:$src),
1337           (LBZ iaddr:$src)>;
1338 def : Pat<(zextloadi1 xaddr:$src),
1339           (LBZX xaddr:$src)>;
1340 def : Pat<(extloadi1 iaddr:$src),
1341           (LBZ iaddr:$src)>;
1342 def : Pat<(extloadi1 xaddr:$src),
1343           (LBZX xaddr:$src)>;
1344 def : Pat<(extloadi8 iaddr:$src),
1345           (LBZ iaddr:$src)>;
1346 def : Pat<(extloadi8 xaddr:$src),
1347           (LBZX xaddr:$src)>;
1348 def : Pat<(extloadi16 iaddr:$src),
1349           (LHZ iaddr:$src)>;
1350 def : Pat<(extloadi16 xaddr:$src),
1351           (LHZX xaddr:$src)>;
1352 def : Pat<(extloadf32 iaddr:$src),
1353           (FMRSD (LFS iaddr:$src))>;
1354 def : Pat<(extloadf32 xaddr:$src),
1355           (FMRSD (LFSX xaddr:$src))>;
1356
1357 include "PPCInstrAltivec.td"
1358 include "PPCInstr64Bit.td"