Add a comment.
[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 was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source 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_PPCShiftOp : SDTypeProfile<1, 2, [   // PPCshl, PPCsra, PPCsrl
24   SDTCisVT<0, i32>, SDTCisVT<1, i32>, SDTCisVT<2, i32>
25 ]>;
26 def SDT_PPCCallSeq : SDTypeProfile<0, 1, [ SDTCisVT<0, i32> ]>;
27
28 def SDT_PPCvperm   : SDTypeProfile<1, 3, [
29   SDTCisVT<3, v16i8>, SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>
30 ]>;
31
32 def SDT_PPCvcmp : SDTypeProfile<1, 3, [
33   SDTCisSameAs<0, 1>, SDTCisSameAs<1, 2>, SDTCisVT<3, i32>
34 ]>;
35
36 def SDT_PPCcondbr : SDTypeProfile<0, 3, [
37   SDTCisVT<1, i32>, SDTCisVT<2, OtherVT>
38 ]>;
39
40 def SDT_PPClbrx : SDTypeProfile<1, 3, [
41   SDTCisVT<0, i32>, SDTCisPtrTy<1>, SDTCisVT<2, OtherVT>, SDTCisVT<3, OtherVT>
42 ]>;
43 def SDT_PPCstbrx : SDTypeProfile<0, 4, [
44   SDTCisVT<0, i32>, SDTCisPtrTy<1>, SDTCisVT<2, OtherVT>, SDTCisVT<3, OtherVT>
45 ]>;
46
47 //===----------------------------------------------------------------------===//
48 // PowerPC specific DAG Nodes.
49 //
50
51 def PPCfcfid  : SDNode<"PPCISD::FCFID" , SDTFPUnaryOp, []>;
52 def PPCfctidz : SDNode<"PPCISD::FCTIDZ", SDTFPUnaryOp, []>;
53 def PPCfctiwz : SDNode<"PPCISD::FCTIWZ", SDTFPUnaryOp, []>;
54 def PPCstfiwx : SDNode<"PPCISD::STFIWX", SDT_PPCstfiwx, [SDNPHasChain]>;
55
56 def PPCfsel   : SDNode<"PPCISD::FSEL",  
57    // Type constraint for fsel.
58    SDTypeProfile<1, 3, [SDTCisSameAs<0, 2>, SDTCisSameAs<0, 3>, 
59                         SDTCisFP<0>, SDTCisVT<1, f64>]>, []>;
60
61 def PPChi       : SDNode<"PPCISD::Hi", SDTIntBinOp, []>;
62 def PPClo       : SDNode<"PPCISD::Lo", SDTIntBinOp, []>;
63 def PPCvmaddfp  : SDNode<"PPCISD::VMADDFP", SDTFPTernaryOp, []>;
64 def PPCvnmsubfp : SDNode<"PPCISD::VNMSUBFP", SDTFPTernaryOp, []>;
65
66 def PPCvperm    : SDNode<"PPCISD::VPERM", SDT_PPCvperm, []>;
67
68 // These nodes represent the 32-bit PPC shifts that operate on 6-bit shift
69 // amounts.  These nodes are generated by the multi-precision shift code.
70 def PPCsrl        : SDNode<"PPCISD::SRL"       , SDT_PPCShiftOp>;
71 def PPCsra        : SDNode<"PPCISD::SRA"       , SDT_PPCShiftOp>;
72 def PPCshl        : SDNode<"PPCISD::SHL"       , SDT_PPCShiftOp>;
73
74 def PPCextsw_32   : SDNode<"PPCISD::EXTSW_32"  , SDTIntUnaryOp>;
75 def PPCstd_32     : SDNode<"PPCISD::STD_32"    , SDTStore, [SDNPHasChain]>;
76
77 // These are target-independent nodes, but have target-specific formats.
78 def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_PPCCallSeq,
79                            [SDNPHasChain, SDNPOutFlag]>;
80 def callseq_end   : SDNode<"ISD::CALLSEQ_END",   SDT_PPCCallSeq,
81                            [SDNPHasChain, SDNPOutFlag]>;
82
83 def SDT_PPCCall   : SDTypeProfile<0, -1, [SDTCisInt<0>]>;
84 def PPCcall       : SDNode<"PPCISD::CALL", SDT_PPCCall,
85                            [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
86 def PPCmtctr      : SDNode<"PPCISD::MTCTR", SDT_PPCCall,
87                            [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
88 def PPCbctrl      : SDNode<"PPCISD::BCTRL", SDTRet,
89                            [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
90
91 def retflag       : SDNode<"PPCISD::RET_FLAG", SDTRet,
92                            [SDNPHasChain, SDNPOptInFlag]>;
93
94 def PPCvcmp       : SDNode<"PPCISD::VCMP" , SDT_PPCvcmp, []>;
95 def PPCvcmp_o     : SDNode<"PPCISD::VCMPo", SDT_PPCvcmp, [SDNPOutFlag]>;
96
97 def PPCcondbranch : SDNode<"PPCISD::COND_BRANCH", SDT_PPCcondbr,
98                            [SDNPHasChain, SDNPOptInFlag]>;
99
100 def PPClbrx       : SDNode<"PPCISD::LBRX", SDT_PPClbrx, [SDNPHasChain]>;
101 def PPCstbrx      : SDNode<"PPCISD::STBRX", SDT_PPCstbrx, [SDNPHasChain]>;
102
103 //===----------------------------------------------------------------------===//
104 // PowerPC specific transformation functions and pattern fragments.
105 //
106
107 def SHL32 : SDNodeXForm<imm, [{
108   // Transformation function: 31 - imm
109   return getI32Imm(31 - N->getValue());
110 }]>;
111
112 def SRL32 : SDNodeXForm<imm, [{
113   // Transformation function: 32 - imm
114   return N->getValue() ? getI32Imm(32 - N->getValue()) : getI32Imm(0);
115 }]>;
116
117 def LO16 : SDNodeXForm<imm, [{
118   // Transformation function: get the low 16 bits.
119   return getI32Imm((unsigned short)N->getValue());
120 }]>;
121
122 def HI16 : SDNodeXForm<imm, [{
123   // Transformation function: shift the immediate value down into the low bits.
124   return getI32Imm((unsigned)N->getValue() >> 16);
125 }]>;
126
127 def HA16 : SDNodeXForm<imm, [{
128   // Transformation function: shift the immediate value down into the low bits.
129   signed int Val = N->getValue();
130   return getI32Imm((Val - (signed short)Val) >> 16);
131 }]>;
132
133
134 def immSExt16  : PatLeaf<(imm), [{
135   // immSExt16 predicate - True if the immediate fits in a 16-bit sign extended
136   // field.  Used by instructions like 'addi'.
137   if (N->getValueType(0) == MVT::i32)
138     return (int32_t)N->getValue() == (short)N->getValue();
139   else
140     return (int64_t)N->getValue() == (short)N->getValue();
141 }]>;
142 def immZExt16  : PatLeaf<(imm), [{
143   // immZExt16 predicate - True if the immediate fits in a 16-bit zero extended
144   // field.  Used by instructions like 'ori'.
145   return (uint64_t)N->getValue() == (unsigned short)N->getValue();
146 }], LO16>;
147
148 // imm16Shifted* - These match immediates where the low 16-bits are zero.  There
149 // are two forms: imm16ShiftedSExt and imm16ShiftedZExt.  These two forms are
150 // identical in 32-bit mode, but in 64-bit mode, they return true if the
151 // immediate fits into a sign/zero extended 32-bit immediate (with the low bits
152 // clear).
153 def imm16ShiftedZExt : PatLeaf<(imm), [{
154   // imm16ShiftedZExt predicate - True if only bits in the top 16-bits of the
155   // immediate are set.  Used by instructions like 'xoris'.
156   return (N->getValue() & ~uint64_t(0xFFFF0000)) == 0;
157 }], HI16>;
158
159 def imm16ShiftedSExt : PatLeaf<(imm), [{
160   // imm16ShiftedSExt predicate - True if only bits in the top 16-bits of the
161   // immediate are set.  Used by instructions like 'addis'.  Identical to 
162   // imm16ShiftedZExt in 32-bit mode.
163   if (N->getValue() & 0xFFFF) return false;
164   if (N->getValueType(0) == MVT::i32)
165     return true;
166   // For 64-bit, make sure it is sext right.
167   return N->getValue() == (uint64_t)(int)N->getValue();
168 }], HI16>;
169
170
171 //===----------------------------------------------------------------------===//
172 // PowerPC Flag Definitions.
173
174 class isPPC64 { bit PPC64 = 1; }
175 class isDOT   {
176   list<Register> Defs = [CR0];
177   bit RC  = 1;
178 }
179
180
181
182 //===----------------------------------------------------------------------===//
183 // PowerPC Operand Definitions.
184
185 def s5imm   : Operand<i32> {
186   let PrintMethod = "printS5ImmOperand";
187 }
188 def u5imm   : Operand<i32> {
189   let PrintMethod = "printU5ImmOperand";
190 }
191 def u6imm   : Operand<i32> {
192   let PrintMethod = "printU6ImmOperand";
193 }
194 def s16imm  : Operand<i32> {
195   let PrintMethod = "printS16ImmOperand";
196 }
197 def u16imm  : Operand<i32> {
198   let PrintMethod = "printU16ImmOperand";
199 }
200 def s16immX4  : Operand<i32> {   // Multiply imm by 4 before printing.
201   let PrintMethod = "printS16X4ImmOperand";
202 }
203 def target : Operand<OtherVT> {
204   let PrintMethod = "printBranchOperand";
205 }
206 def calltarget : Operand<iPTR> {
207   let PrintMethod = "printCallOperand";
208 }
209 def aaddr : Operand<iPTR> {
210   let PrintMethod = "printAbsAddrOperand";
211 }
212 def piclabel: Operand<iPTR> {
213   let PrintMethod = "printPICLabel";
214 }
215 def symbolHi: Operand<i32> {
216   let PrintMethod = "printSymbolHi";
217 }
218 def symbolLo: Operand<i32> {
219   let PrintMethod = "printSymbolLo";
220 }
221 def crbitm: Operand<i8> {
222   let PrintMethod = "printcrbitm";
223 }
224 // Address operands
225 def memri : Operand<iPTR> {
226   let PrintMethod = "printMemRegImm";
227   let NumMIOperands = 2;
228   let MIOperandInfo = (ops i32imm, ptr_rc);
229 }
230 def memrr : Operand<iPTR> {
231   let PrintMethod = "printMemRegReg";
232   let NumMIOperands = 2;
233   let MIOperandInfo = (ops ptr_rc, ptr_rc);
234 }
235 def memrix : Operand<iPTR> {   // memri where the imm is shifted 2 bits.
236   let PrintMethod = "printMemRegImmShifted";
237   let NumMIOperands = 2;
238   let MIOperandInfo = (ops i32imm, ptr_rc);
239 }
240
241 // Define PowerPC specific addressing mode.
242 def iaddr  : ComplexPattern<iPTR, 2, "SelectAddrImm",    []>;
243 def xaddr  : ComplexPattern<iPTR, 2, "SelectAddrIdx",    []>;
244 def xoaddr : ComplexPattern<iPTR, 2, "SelectAddrIdxOnly",[]>;
245 def ixaddr : ComplexPattern<iPTR, 2, "SelectAddrImmShift", []>; // "std"
246
247 //===----------------------------------------------------------------------===//
248 // PowerPC Instruction Predicate Definitions.
249 def FPContractions : Predicate<"!NoExcessFPPrecision">;
250
251 //===----------------------------------------------------------------------===//
252 // PowerPC Instruction Definitions.
253
254 // Pseudo-instructions:
255
256 let hasCtrlDep = 1 in {
257 def ADJCALLSTACKDOWN : Pseudo<(ops u16imm:$amt),
258                               "; ADJCALLSTACKDOWN",
259                               [(callseq_start imm:$amt)]>;
260 def ADJCALLSTACKUP   : Pseudo<(ops u16imm:$amt),
261                               "; ADJCALLSTACKUP",
262                               [(callseq_end imm:$amt)]>;
263
264 def UPDATE_VRSAVE    : Pseudo<(ops GPRC:$rD, GPRC:$rS),
265                               "UPDATE_VRSAVE $rD, $rS", []>;
266 }
267 def IMPLICIT_DEF_GPRC: Pseudo<(ops GPRC:$rD), "; IMPLICIT_DEF_GPRC $rD",
268                               [(set GPRC:$rD, (undef))]>;
269 def IMPLICIT_DEF_F8  : Pseudo<(ops F8RC:$rD), "; IMPLICIT_DEF_F8 $rD",
270                               [(set F8RC:$rD, (undef))]>;
271 def IMPLICIT_DEF_F4  : Pseudo<(ops F4RC:$rD), "; IMPLICIT_DEF_F4 $rD",
272                               [(set F4RC:$rD, (undef))]>;
273
274 // SELECT_CC_* - Used to implement the SELECT_CC DAG operation.  Expanded by the
275 // scheduler into a branch sequence.
276 let usesCustomDAGSchedInserter = 1,    // Expanded by the scheduler.
277     PPC970_Single = 1 in {
278   def SELECT_CC_I4 : Pseudo<(ops GPRC:$dst, CRRC:$cond, GPRC:$T, GPRC:$F,
279                               i32imm:$BROPC), "; SELECT_CC PSEUDO!", []>;
280   def SELECT_CC_I8 : Pseudo<(ops G8RC:$dst, CRRC:$cond, G8RC:$T, G8RC:$F,
281                               i32imm:$BROPC), "; SELECT_CC PSEUDO!", []>;
282   def SELECT_CC_F4  : Pseudo<(ops F4RC:$dst, CRRC:$cond, F4RC:$T, F4RC:$F,
283                               i32imm:$BROPC), "; SELECT_CC PSEUDO!", []>;
284   def SELECT_CC_F8  : Pseudo<(ops F8RC:$dst, CRRC:$cond, F8RC:$T, F8RC:$F,
285                               i32imm:$BROPC), "; SELECT_CC PSEUDO!", []>;
286   def SELECT_CC_VRRC: Pseudo<(ops VRRC:$dst, CRRC:$cond, VRRC:$T, VRRC:$F,
287                               i32imm:$BROPC), "; SELECT_CC PSEUDO!", []>;
288 }
289
290 let isTerminator = 1, noResults = 1, PPC970_Unit = 7 in {
291   let isReturn = 1 in
292     def BLR : XLForm_2_ext<19, 16, 20, 0, 0, (ops), "blr", BrB, [(retflag)]>;
293   def BCTR : XLForm_2_ext<19, 528, 20, 0, 0, (ops), "bctr", BrB, []>;
294 }
295
296 let Defs = [LR] in
297   def MovePCtoLR : Pseudo<(ops piclabel:$label), "bl $label", []>,
298                    PPC970_Unit_BRU;
299
300 let isBranch = 1, isTerminator = 1, hasCtrlDep = 1, 
301     noResults = 1, PPC970_Unit = 7 in {
302   def COND_BRANCH : Pseudo<(ops CRRC:$crS, u16imm:$opc, target:$dst),
303                            "; COND_BRANCH $crS, $opc, $dst",
304                            [(PPCcondbranch CRRC:$crS, imm:$opc, bb:$dst)]>;
305   def B   : IForm<18, 0, 0, (ops target:$dst),
306                   "b $dst", BrB,
307                   [(br bb:$dst)]>;
308
309   def BLT : BForm<16, 0, 0, 12, 0, (ops CRRC:$crS, target:$block),
310                   "blt $crS, $block", BrB>;
311   def BLE : BForm<16, 0, 0, 4,  1, (ops CRRC:$crS, target:$block),
312                   "ble $crS, $block", BrB>;
313   def BEQ : BForm<16, 0, 0, 12, 2, (ops CRRC:$crS, target:$block),
314                   "beq $crS, $block", BrB>;
315   def BGE : BForm<16, 0, 0, 4,  0, (ops CRRC:$crS, target:$block),
316                   "bge $crS, $block", BrB>;
317   def BGT : BForm<16, 0, 0, 12, 1, (ops CRRC:$crS, target:$block),
318                   "bgt $crS, $block", BrB>;
319   def BNE : BForm<16, 0, 0, 4,  2, (ops CRRC:$crS, target:$block),
320                   "bne $crS, $block", BrB>;
321   def BUN : BForm<16, 0, 0, 12, 3, (ops CRRC:$crS, target:$block),
322                   "bun $crS, $block", BrB>;
323   def BNU : BForm<16, 0, 0, 4,  3, (ops CRRC:$crS, target:$block),
324                   "bnu $crS, $block", BrB>;
325 }
326
327 let isCall = 1, noResults = 1, PPC970_Unit = 7, 
328   // All calls clobber the non-callee saved registers...
329   Defs = [R0,R2,R3,R4,R5,R6,R7,R8,R9,R10,R11,R12,
330           F0,F1,F2,F3,F4,F5,F6,F7,F8,F9,F10,F11,F12,F13,
331           V0,V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,V13,V14,V15,V16,V17,V18,V19,
332           LR,CTR,
333           CR0,CR1,CR5,CR6,CR7] in {
334   // Convenient aliases for call instructions
335   def BL  : IForm<18, 0, 1, (ops calltarget:$func, variable_ops), 
336                             "bl $func", BrB, []>;  // See Pat patterns below.
337   def BLA : IForm<18, 1, 1, (ops aaddr:$func, variable_ops),
338                             "bla $func", BrB, [(PPCcall (i32 imm:$func))]>;
339   def BCTRL : XLForm_2_ext<19, 528, 20, 0, 1, (ops variable_ops), "bctrl", BrB,
340                            [(PPCbctrl)]>;
341 }
342
343 // DCB* instructions.
344 def DCBZ : DCB_Form<1014, 0, (ops memrr:$dst),
345                     "dcbz $dst", LdStDCBF, [(int_ppc_dcbz xoaddr:$dst)]>,
346                     PPC970_DGroup_Single;
347 def DCBZL : DCB_Form<1014, 1, (ops memrr:$dst),
348                      "dcbzl $dst", LdStDCBF, [(int_ppc_dcbzl xoaddr:$dst)]>,
349                      PPC970_DGroup_Single;
350                        
351 // D-Form instructions.  Most instructions that perform an operation on a
352 // register and an immediate are of this type.
353 //
354 let isLoad = 1, PPC970_Unit = 2 in {
355 def LBZ : DForm_1<34, (ops GPRC:$rD, memri:$src),
356                   "lbz $rD, $src", LdStGeneral,
357                   [(set GPRC:$rD, (zextload iaddr:$src, i8))]>;
358 def LHA : DForm_1<42, (ops GPRC:$rD, memri:$src),
359                   "lha $rD, $src", LdStLHA,
360                   [(set GPRC:$rD, (sextload iaddr:$src, i16))]>,
361                   PPC970_DGroup_Cracked;
362 def LHZ : DForm_1<40, (ops GPRC:$rD, memri:$src),
363                   "lhz $rD, $src", LdStGeneral,
364                   [(set GPRC:$rD, (zextload iaddr:$src, i16))]>;
365 def LWZ : DForm_1<32, (ops GPRC:$rD, memri:$src),
366                   "lwz $rD, $src", LdStGeneral,
367                   [(set GPRC:$rD, (load iaddr:$src))]>;
368 def LWZU : DForm_1<35, (ops GPRC:$rD, s16imm:$disp, GPRC:$rA),
369                    "lwzu $rD, $disp($rA)", LdStGeneral,
370                    []>;
371 }
372 let PPC970_Unit = 1 in {  // FXU Operations.
373 def ADDI   : DForm_2<14, (ops GPRC:$rD, GPRC:$rA, s16imm:$imm),
374                      "addi $rD, $rA, $imm", IntGeneral,
375                      [(set GPRC:$rD, (add GPRC:$rA, immSExt16:$imm))]>;
376 def ADDIC  : DForm_2<12, (ops GPRC:$rD, GPRC:$rA, s16imm:$imm),
377                      "addic $rD, $rA, $imm", IntGeneral,
378                      [(set GPRC:$rD, (addc GPRC:$rA, immSExt16:$imm))]>,
379                      PPC970_DGroup_Cracked;
380 def ADDICo : DForm_2<13, (ops GPRC:$rD, GPRC:$rA, s16imm:$imm),
381                      "addic. $rD, $rA, $imm", IntGeneral,
382                      []>;
383 def ADDIS  : DForm_2<15, (ops GPRC:$rD, GPRC:$rA, symbolHi:$imm),
384                      "addis $rD, $rA, $imm", IntGeneral,
385                      [(set GPRC:$rD, (add GPRC:$rA, imm16ShiftedSExt:$imm))]>;
386 def LA     : DForm_2<14, (ops GPRC:$rD, GPRC:$rA, symbolLo:$sym),
387                      "la $rD, $sym($rA)", IntGeneral,
388                      [(set GPRC:$rD, (add GPRC:$rA,
389                                           (PPClo tglobaladdr:$sym, 0)))]>;
390 def MULLI  : DForm_2< 7, (ops GPRC:$rD, GPRC:$rA, s16imm:$imm),
391                      "mulli $rD, $rA, $imm", IntMulLI,
392                      [(set GPRC:$rD, (mul GPRC:$rA, immSExt16:$imm))]>;
393 def SUBFIC : DForm_2< 8, (ops GPRC:$rD, GPRC:$rA, s16imm:$imm),
394                      "subfic $rD, $rA, $imm", IntGeneral,
395                      [(set GPRC:$rD, (subc immSExt16:$imm, GPRC:$rA))]>;
396 def LI  : DForm_2_r0<14, (ops GPRC:$rD, symbolLo:$imm),
397                      "li $rD, $imm", IntGeneral,
398                      [(set GPRC:$rD, immSExt16:$imm)]>;
399 def LIS : DForm_2_r0<15, (ops GPRC:$rD, symbolHi:$imm),
400                      "lis $rD, $imm", IntGeneral,
401                      [(set GPRC:$rD, imm16ShiftedSExt:$imm)]>;
402 }
403 let isStore = 1, noResults = 1, PPC970_Unit = 2 in {
404 def STB  : DForm_3<38, (ops GPRC:$rS, memri:$src),
405                    "stb $rS, $src", LdStGeneral,
406                    [(truncstore GPRC:$rS, iaddr:$src, i8)]>;
407 def STH  : DForm_3<44, (ops GPRC:$rS, memri:$src),
408                    "sth $rS, $src", LdStGeneral,
409                    [(truncstore GPRC:$rS, iaddr:$src, i16)]>;
410 def STW  : DForm_3<36, (ops GPRC:$rS, memri:$src),
411                    "stw $rS, $src", LdStGeneral,
412                    [(store GPRC:$rS, iaddr:$src)]>;
413 def STWU : DForm_3<37, (ops GPRC:$rS, s16imm:$disp, GPRC:$rA),
414                    "stwu $rS, $disp($rA)", LdStGeneral,
415                    []>;
416 }
417 let PPC970_Unit = 1 in {  // FXU Operations.
418 def ANDIo : DForm_4<28, (ops GPRC:$dst, GPRC:$src1, u16imm:$src2),
419                     "andi. $dst, $src1, $src2", IntGeneral,
420                     [(set GPRC:$dst, (and GPRC:$src1, immZExt16:$src2))]>,
421                     isDOT;
422 def ANDISo : DForm_4<29, (ops GPRC:$dst, GPRC:$src1, u16imm:$src2),
423                     "andis. $dst, $src1, $src2", IntGeneral,
424                     [(set GPRC:$dst, (and GPRC:$src1,imm16ShiftedZExt:$src2))]>,
425                     isDOT;
426 def ORI   : DForm_4<24, (ops GPRC:$dst, GPRC:$src1, u16imm:$src2),
427                     "ori $dst, $src1, $src2", IntGeneral,
428                     [(set GPRC:$dst, (or GPRC:$src1, immZExt16:$src2))]>;
429 def ORIS  : DForm_4<25, (ops GPRC:$dst, GPRC:$src1, u16imm:$src2),
430                     "oris $dst, $src1, $src2", IntGeneral,
431                     [(set GPRC:$dst, (or GPRC:$src1, imm16ShiftedZExt:$src2))]>;
432 def XORI  : DForm_4<26, (ops GPRC:$dst, GPRC:$src1, u16imm:$src2),
433                     "xori $dst, $src1, $src2", IntGeneral,
434                     [(set GPRC:$dst, (xor GPRC:$src1, immZExt16:$src2))]>;
435 def XORIS : DForm_4<27, (ops GPRC:$dst, GPRC:$src1, u16imm:$src2),
436                     "xoris $dst, $src1, $src2", IntGeneral,
437                     [(set GPRC:$dst, (xor GPRC:$src1,imm16ShiftedZExt:$src2))]>;
438 def NOP   : DForm_4_zero<24, (ops), "nop", IntGeneral,
439                          []>;
440 def CMPWI : DForm_5_ext<11, (ops CRRC:$crD, GPRC:$rA, s16imm:$imm),
441                         "cmpwi $crD, $rA, $imm", IntCompare>;
442 def CMPLWI : DForm_6_ext<10, (ops CRRC:$dst, GPRC:$src1, u16imm:$src2),
443                          "cmplwi $dst, $src1, $src2", IntCompare>;
444 }
445 let isLoad = 1, PPC970_Unit = 2 in {
446 def LFS : DForm_8<48, (ops F4RC:$rD, memri:$src),
447                   "lfs $rD, $src", LdStLFDU,
448                   [(set F4RC:$rD, (load iaddr:$src))]>;
449 def LFD : DForm_8<50, (ops F8RC:$rD, memri:$src),
450                   "lfd $rD, $src", LdStLFD,
451                   [(set F8RC:$rD, (load iaddr:$src))]>;
452 }
453 let isStore = 1, noResults = 1, PPC970_Unit = 2 in {
454 def STFS : DForm_9<52, (ops F4RC:$rS, memri:$dst),
455                    "stfs $rS, $dst", LdStUX,
456                    [(store F4RC:$rS, iaddr:$dst)]>;
457 def STFD : DForm_9<54, (ops F8RC:$rS, memri:$dst),
458                    "stfd $rS, $dst", LdStUX,
459                    [(store F8RC:$rS, iaddr:$dst)]>;
460 }
461
462 // X-Form instructions.  Most instructions that perform an operation on a
463 // register and another register are of this type.
464 //
465 let isLoad = 1, PPC970_Unit = 2 in {
466 def LBZX : XForm_1<31,  87, (ops GPRC:$rD, memrr:$src),
467                    "lbzx $rD, $src", LdStGeneral,
468                    [(set GPRC:$rD, (zextload xaddr:$src, i8))]>;
469 def LHAX : XForm_1<31, 343, (ops GPRC:$rD, memrr:$src),
470                    "lhax $rD, $src", LdStLHA,
471                    [(set GPRC:$rD, (sextload xaddr:$src, i16))]>,
472                    PPC970_DGroup_Cracked;
473 def LHZX : XForm_1<31, 279, (ops GPRC:$rD, memrr:$src),
474                    "lhzx $rD, $src", LdStGeneral,
475                    [(set GPRC:$rD, (zextload xaddr:$src, i16))]>;
476 def LWZX : XForm_1<31,  23, (ops GPRC:$rD, memrr:$src),
477                    "lwzx $rD, $src", LdStGeneral,
478                    [(set GPRC:$rD, (load xaddr:$src))]>;
479                    
480                    
481 def LHBRX : XForm_1<31, 790, (ops GPRC:$rD, memrr:$src),
482                    "lhbrx $rD, $src", LdStGeneral,
483                    [(set GPRC:$rD, (PPClbrx xoaddr:$src, srcvalue:$sv, i16))]>;
484 def LWBRX : XForm_1<31,  534, (ops GPRC:$rD, memrr:$src),
485                    "lwbrx $rD, $src", LdStGeneral,
486                    [(set GPRC:$rD, (PPClbrx xoaddr:$src, srcvalue:$sv, i32))]>;
487
488 }
489
490 let PPC970_Unit = 1 in {  // FXU Operations.
491 def NAND : XForm_6<31, 476, (ops GPRC:$rA, GPRC:$rS, GPRC:$rB),
492                    "nand $rA, $rS, $rB", IntGeneral,
493                    [(set GPRC:$rA, (not (and GPRC:$rS, GPRC:$rB)))]>;
494 def AND  : XForm_6<31,  28, (ops GPRC:$rA, GPRC:$rS, GPRC:$rB),
495                    "and $rA, $rS, $rB", IntGeneral,
496                    [(set GPRC:$rA, (and GPRC:$rS, GPRC:$rB))]>;
497 def ANDC : XForm_6<31,  60, (ops GPRC:$rA, GPRC:$rS, GPRC:$rB),
498                    "andc $rA, $rS, $rB", IntGeneral,
499                    [(set GPRC:$rA, (and GPRC:$rS, (not GPRC:$rB)))]>;
500 def OR   : XForm_6<31, 444, (ops GPRC:$rA, GPRC:$rS, GPRC:$rB),
501                    "or $rA, $rS, $rB", IntGeneral,
502                    [(set GPRC:$rA, (or GPRC:$rS, GPRC:$rB))]>;
503 def NOR  : XForm_6<31, 124, (ops GPRC:$rA, GPRC:$rS, GPRC:$rB),
504                    "nor $rA, $rS, $rB", IntGeneral,
505                    [(set GPRC:$rA, (not (or GPRC:$rS, GPRC:$rB)))]>;
506 def ORC  : XForm_6<31, 412, (ops GPRC:$rA, GPRC:$rS, GPRC:$rB),
507                    "orc $rA, $rS, $rB", IntGeneral,
508                    [(set GPRC:$rA, (or GPRC:$rS, (not GPRC:$rB)))]>;
509 def EQV  : XForm_6<31, 284, (ops GPRC:$rA, GPRC:$rS, GPRC:$rB),
510                    "eqv $rA, $rS, $rB", IntGeneral,
511                    [(set GPRC:$rA, (not (xor GPRC:$rS, GPRC:$rB)))]>;
512 def XOR  : XForm_6<31, 316, (ops GPRC:$rA, GPRC:$rS, GPRC:$rB),
513                    "xor $rA, $rS, $rB", IntGeneral,
514                    [(set GPRC:$rA, (xor GPRC:$rS, GPRC:$rB))]>;
515 def SLW  : XForm_6<31,  24, (ops GPRC:$rA, GPRC:$rS, GPRC:$rB),
516                    "slw $rA, $rS, $rB", IntGeneral,
517                    [(set GPRC:$rA, (PPCshl GPRC:$rS, GPRC:$rB))]>;
518 def SRW  : XForm_6<31, 536, (ops GPRC:$rA, GPRC:$rS, GPRC:$rB),
519                    "srw $rA, $rS, $rB", IntGeneral,
520                    [(set GPRC:$rA, (PPCsrl GPRC:$rS, GPRC:$rB))]>;
521 def SRAW : XForm_6<31, 792, (ops GPRC:$rA, GPRC:$rS, GPRC:$rB),
522                    "sraw $rA, $rS, $rB", IntShift,
523                    [(set GPRC:$rA, (PPCsra GPRC:$rS, GPRC:$rB))]>;
524 }
525 let isStore = 1, noResults = 1, PPC970_Unit = 2 in {
526 def STBX  : XForm_8<31, 215, (ops GPRC:$rS, memrr:$dst),
527                    "stbx $rS, $dst", LdStGeneral,
528                    [(truncstore GPRC:$rS, xaddr:$dst, i8)]>, 
529                    PPC970_DGroup_Cracked;
530 def STHX  : XForm_8<31, 407, (ops GPRC:$rS, memrr:$dst),
531                    "sthx $rS, $dst", LdStGeneral,
532                    [(truncstore GPRC:$rS, xaddr:$dst, i16)]>, 
533                    PPC970_DGroup_Cracked;
534 def STWX  : XForm_8<31, 151, (ops GPRC:$rS, memrr:$dst),
535                    "stwx $rS, $dst", LdStGeneral,
536                    [(store GPRC:$rS, xaddr:$dst)]>,
537                    PPC970_DGroup_Cracked;
538 def STWUX : XForm_8<31, 183, (ops GPRC:$rS, GPRC:$rA, GPRC:$rB),
539                    "stwux $rS, $rA, $rB", LdStGeneral,
540                    []>;
541 def STHBRX: XForm_8<31, 918, (ops GPRC:$rS, memrr:$dst),
542                    "sthbrx $rS, $dst", LdStGeneral,
543                    [(PPCstbrx GPRC:$rS, xoaddr:$dst, srcvalue:$dummy, i16)]>, 
544                    PPC970_DGroup_Cracked;
545 def STWBRX: XForm_8<31, 662, (ops GPRC:$rS, memrr:$dst),
546                    "stwbrx $rS, $dst", LdStGeneral,
547                    [(PPCstbrx GPRC:$rS, xoaddr:$dst, srcvalue:$dummy, i32)]>,
548                    PPC970_DGroup_Cracked;
549 }
550 let PPC970_Unit = 1 in {  // FXU Operations.
551 def SRAWI : XForm_10<31, 824, (ops GPRC:$rA, GPRC:$rS, u5imm:$SH), 
552                      "srawi $rA, $rS, $SH", IntShift,
553                      [(set GPRC:$rA, (sra GPRC:$rS, (i32 imm:$SH)))]>;
554 def CNTLZW : XForm_11<31,  26, (ops GPRC:$rA, GPRC:$rS),
555                       "cntlzw $rA, $rS", IntGeneral,
556                       [(set GPRC:$rA, (ctlz GPRC:$rS))]>;
557 def EXTSB  : XForm_11<31, 954, (ops GPRC:$rA, GPRC:$rS),
558                       "extsb $rA, $rS", IntGeneral,
559                       [(set GPRC:$rA, (sext_inreg GPRC:$rS, i8))]>;
560 def EXTSH  : XForm_11<31, 922, (ops GPRC:$rA, GPRC:$rS),
561                       "extsh $rA, $rS", IntGeneral,
562                       [(set GPRC:$rA, (sext_inreg GPRC:$rS, i16))]>;
563
564 def CMPW   : XForm_16_ext<31, 0, (ops CRRC:$crD, GPRC:$rA, GPRC:$rB),
565                           "cmpw $crD, $rA, $rB", IntCompare>;
566 def CMPLW  : XForm_16_ext<31, 32, (ops CRRC:$crD, GPRC:$rA, GPRC:$rB),
567                           "cmplw $crD, $rA, $rB", IntCompare>;
568 }
569 let PPC970_Unit = 3 in {  // FPU Operations.
570 //def FCMPO  : XForm_17<63, 32, (ops CRRC:$crD, FPRC:$fA, FPRC:$fB),
571 //                      "fcmpo $crD, $fA, $fB", FPCompare>;
572 def FCMPUS : XForm_17<63, 0, (ops CRRC:$crD, F4RC:$fA, F4RC:$fB),
573                       "fcmpu $crD, $fA, $fB", FPCompare>;
574 def FCMPUD : XForm_17<63, 0, (ops CRRC:$crD, F8RC:$fA, F8RC:$fB),
575                       "fcmpu $crD, $fA, $fB", FPCompare>;
576 }
577 let isLoad = 1, PPC970_Unit = 2 in {
578 def LFSX   : XForm_25<31, 535, (ops F4RC:$frD, memrr:$src),
579                       "lfsx $frD, $src", LdStLFDU,
580                       [(set F4RC:$frD, (load xaddr:$src))]>;
581 def LFDX   : XForm_25<31, 599, (ops F8RC:$frD, memrr:$src),
582                       "lfdx $frD, $src", LdStLFDU,
583                       [(set F8RC:$frD, (load xaddr:$src))]>;
584 }
585 let PPC970_Unit = 3 in {  // FPU Operations.
586 def FCTIWZ : XForm_26<63, 15, (ops F8RC:$frD, F8RC:$frB),
587                       "fctiwz $frD, $frB", FPGeneral,
588                       [(set F8RC:$frD, (PPCfctiwz F8RC:$frB))]>;
589 def FRSP   : XForm_26<63, 12, (ops F4RC:$frD, F8RC:$frB),
590                       "frsp $frD, $frB", FPGeneral,
591                       [(set F4RC:$frD, (fround F8RC:$frB))]>;
592 def FSQRT  : XForm_26<63, 22, (ops F8RC:$frD, F8RC:$frB),
593                       "fsqrt $frD, $frB", FPSqrt,
594                       [(set F8RC:$frD, (fsqrt F8RC:$frB))]>;
595 def FSQRTS : XForm_26<59, 22, (ops F4RC:$frD, F4RC:$frB),
596                       "fsqrts $frD, $frB", FPSqrt,
597                       [(set F4RC:$frD, (fsqrt F4RC:$frB))]>;
598 }
599
600 /// FMR is split into 3 versions, one for 4/8 byte FP, and one for extending.
601 ///
602 /// Note that these are defined as pseudo-ops on the PPC970 because they are
603 /// often coalesced away and we don't want the dispatch group builder to think
604 /// that they will fill slots (which could cause the load of a LSU reject to
605 /// sneak into a d-group with a store).
606 def FMRS   : XForm_26<63, 72, (ops F4RC:$frD, F4RC:$frB),
607                       "fmr $frD, $frB", FPGeneral,
608                       []>,  // (set F4RC:$frD, F4RC:$frB)
609                       PPC970_Unit_Pseudo;
610 def FMRD   : XForm_26<63, 72, (ops F8RC:$frD, F8RC:$frB),
611                       "fmr $frD, $frB", FPGeneral,
612                       []>,  // (set F8RC:$frD, F8RC:$frB)
613                       PPC970_Unit_Pseudo;
614 def FMRSD  : XForm_26<63, 72, (ops F8RC:$frD, F4RC:$frB),
615                       "fmr $frD, $frB", FPGeneral,
616                       [(set F8RC:$frD, (fextend F4RC:$frB))]>,
617                       PPC970_Unit_Pseudo;
618
619 let PPC970_Unit = 3 in {  // FPU Operations.
620 // These are artificially split into two different forms, for 4/8 byte FP.
621 def FABSS  : XForm_26<63, 264, (ops F4RC:$frD, F4RC:$frB),
622                       "fabs $frD, $frB", FPGeneral,
623                       [(set F4RC:$frD, (fabs F4RC:$frB))]>;
624 def FABSD  : XForm_26<63, 264, (ops F8RC:$frD, F8RC:$frB),
625                       "fabs $frD, $frB", FPGeneral,
626                       [(set F8RC:$frD, (fabs F8RC:$frB))]>;
627 def FNABSS : XForm_26<63, 136, (ops F4RC:$frD, F4RC:$frB),
628                       "fnabs $frD, $frB", FPGeneral,
629                       [(set F4RC:$frD, (fneg (fabs F4RC:$frB)))]>;
630 def FNABSD : XForm_26<63, 136, (ops F8RC:$frD, F8RC:$frB),
631                       "fnabs $frD, $frB", FPGeneral,
632                       [(set F8RC:$frD, (fneg (fabs F8RC:$frB)))]>;
633 def FNEGS  : XForm_26<63, 40, (ops F4RC:$frD, F4RC:$frB),
634                       "fneg $frD, $frB", FPGeneral,
635                       [(set F4RC:$frD, (fneg F4RC:$frB))]>;
636 def FNEGD  : XForm_26<63, 40, (ops F8RC:$frD, F8RC:$frB),
637                       "fneg $frD, $frB", FPGeneral,
638                       [(set F8RC:$frD, (fneg F8RC:$frB))]>;
639 }
640                       
641 let isStore = 1, noResults = 1, PPC970_Unit = 2 in {
642 def STFIWX: XForm_28<31, 983, (ops F8RC:$frS, memrr:$dst),
643                      "stfiwx $frS, $dst", LdStUX,
644                      [(PPCstfiwx F8RC:$frS, xoaddr:$dst)]>;
645 def STFSX : XForm_28<31, 663, (ops F4RC:$frS, memrr:$dst),
646                      "stfsx $frS, $dst", LdStUX,
647                      [(store F4RC:$frS, xaddr:$dst)]>;
648 def STFDX : XForm_28<31, 727, (ops F8RC:$frS, memrr:$dst),
649                      "stfdx $frS, $dst", LdStUX,
650                      [(store F8RC:$frS, xaddr:$dst)]>;
651 }
652
653 // XL-Form instructions.  condition register logical ops.
654 //
655 def MCRF   : XLForm_3<19, 0, (ops CRRC:$BF, CRRC:$BFA),
656                       "mcrf $BF, $BFA", BrMCR>,
657              PPC970_DGroup_First, PPC970_Unit_CRU;
658
659 // XFX-Form instructions.  Instructions that deal with SPRs.
660 //
661 def MFCTR : XFXForm_1_ext<31, 339, 9, (ops GPRC:$rT), "mfctr $rT", SprMFSPR>,
662             PPC970_DGroup_First, PPC970_Unit_FXU;
663 let Pattern = [(PPCmtctr GPRC:$rS)] in {
664 def MTCTR : XFXForm_7_ext<31, 467, 9, (ops GPRC:$rS), "mtctr $rS", SprMTSPR>,
665             PPC970_DGroup_First, PPC970_Unit_FXU;
666 }
667
668 def MTLR  : XFXForm_7_ext<31, 467, 8, (ops GPRC:$rS), "mtlr $rS", SprMTSPR>,
669             PPC970_DGroup_First, PPC970_Unit_FXU;
670 def MFLR  : XFXForm_1_ext<31, 339, 8, (ops GPRC:$rT), "mflr $rT", SprMFSPR>,
671             PPC970_DGroup_First, PPC970_Unit_FXU;
672
673 // Move to/from VRSAVE: despite being a SPR, the VRSAVE register is renamed like
674 // a GPR on the PPC970.  As such, copies in and out have the same performance
675 // characteristics as an OR instruction.
676 def MTVRSAVE : XFXForm_7_ext<31, 467, 256, (ops GPRC:$rS),
677                              "mtspr 256, $rS", IntGeneral>,
678                PPC970_DGroup_Single, PPC970_Unit_FXU;
679 def MFVRSAVE : XFXForm_1_ext<31, 339, 256, (ops GPRC:$rT),
680                              "mfspr $rT, 256", IntGeneral>,
681                PPC970_DGroup_First, PPC970_Unit_FXU;
682
683 def MTCRF : XFXForm_5<31, 144, (ops crbitm:$FXM, GPRC:$rS),
684                       "mtcrf $FXM, $rS", BrMCRX>,
685             PPC970_MicroCode, PPC970_Unit_CRU;
686 def MFCR  : XFXForm_3<31, 19, (ops GPRC:$rT), "mfcr $rT", SprMFCR>,
687             PPC970_MicroCode, PPC970_Unit_CRU;
688 def MFOCRF: XFXForm_5a<31, 19, (ops GPRC:$rT, crbitm:$FXM),
689                        "mfcr $rT, $FXM", SprMFCR>,
690             PPC970_DGroup_First, PPC970_Unit_CRU;
691
692 let PPC970_Unit = 1 in {  // FXU Operations.
693
694 // XO-Form instructions.  Arithmetic instructions that can set overflow bit
695 //
696 def ADD4  : XOForm_1<31, 266, 0, (ops GPRC:$rT, GPRC:$rA, GPRC:$rB),
697                      "add $rT, $rA, $rB", IntGeneral,
698                      [(set GPRC:$rT, (add GPRC:$rA, GPRC:$rB))]>;
699 def ADDC  : XOForm_1<31, 10, 0, (ops GPRC:$rT, GPRC:$rA, GPRC:$rB),
700                      "addc $rT, $rA, $rB", IntGeneral,
701                      [(set GPRC:$rT, (addc GPRC:$rA, GPRC:$rB))]>,
702                      PPC970_DGroup_Cracked;
703 def ADDE  : XOForm_1<31, 138, 0, (ops GPRC:$rT, GPRC:$rA, GPRC:$rB),
704                      "adde $rT, $rA, $rB", IntGeneral,
705                      [(set GPRC:$rT, (adde GPRC:$rA, GPRC:$rB))]>;
706 def DIVW  : XOForm_1<31, 491, 0, (ops GPRC:$rT, GPRC:$rA, GPRC:$rB),
707                      "divw $rT, $rA, $rB", IntDivW,
708                      [(set GPRC:$rT, (sdiv GPRC:$rA, GPRC:$rB))]>,
709                      PPC970_DGroup_First, PPC970_DGroup_Cracked;
710 def DIVWU : XOForm_1<31, 459, 0, (ops GPRC:$rT, GPRC:$rA, GPRC:$rB),
711                      "divwu $rT, $rA, $rB", IntDivW,
712                      [(set GPRC:$rT, (udiv GPRC:$rA, GPRC:$rB))]>,
713                      PPC970_DGroup_First, PPC970_DGroup_Cracked;
714 def MULHW : XOForm_1<31, 75, 0, (ops GPRC:$rT, GPRC:$rA, GPRC:$rB),
715                      "mulhw $rT, $rA, $rB", IntMulHW,
716                      [(set GPRC:$rT, (mulhs GPRC:$rA, GPRC:$rB))]>;
717 def MULHWU : XOForm_1<31, 11, 0, (ops GPRC:$rT, GPRC:$rA, GPRC:$rB),
718                      "mulhwu $rT, $rA, $rB", IntMulHWU,
719                      [(set GPRC:$rT, (mulhu GPRC:$rA, GPRC:$rB))]>;
720 def MULLW : XOForm_1<31, 235, 0, (ops GPRC:$rT, GPRC:$rA, GPRC:$rB),
721                      "mullw $rT, $rA, $rB", IntMulHW,
722                      [(set GPRC:$rT, (mul GPRC:$rA, GPRC:$rB))]>;
723 def SUBF  : XOForm_1<31, 40, 0, (ops GPRC:$rT, GPRC:$rA, GPRC:$rB),
724                      "subf $rT, $rA, $rB", IntGeneral,
725                      [(set GPRC:$rT, (sub GPRC:$rB, GPRC:$rA))]>;
726 def SUBFC : XOForm_1<31, 8, 0, (ops GPRC:$rT, GPRC:$rA, GPRC:$rB),
727                      "subfc $rT, $rA, $rB", IntGeneral,
728                      [(set GPRC:$rT, (subc GPRC:$rB, GPRC:$rA))]>,
729                      PPC970_DGroup_Cracked;
730 def SUBFE : XOForm_1<31, 136, 0, (ops GPRC:$rT, GPRC:$rA, GPRC:$rB),
731                      "subfe $rT, $rA, $rB", IntGeneral,
732                      [(set GPRC:$rT, (sube GPRC:$rB, GPRC:$rA))]>;
733 def ADDME  : XOForm_3<31, 234, 0, (ops GPRC:$rT, GPRC:$rA),
734                       "addme $rT, $rA", IntGeneral,
735                       [(set GPRC:$rT, (adde GPRC:$rA, immAllOnes))]>;
736 def ADDZE  : XOForm_3<31, 202, 0, (ops GPRC:$rT, GPRC:$rA),
737                       "addze $rT, $rA", IntGeneral,
738                       [(set GPRC:$rT, (adde GPRC:$rA, 0))]>;
739 def NEG    : XOForm_3<31, 104, 0, (ops GPRC:$rT, GPRC:$rA),
740                       "neg $rT, $rA", IntGeneral,
741                       [(set GPRC:$rT, (ineg GPRC:$rA))]>;
742 def SUBFME : XOForm_3<31, 232, 0, (ops GPRC:$rT, GPRC:$rA),
743                       "subfme $rT, $rA", IntGeneral,
744                       [(set GPRC:$rT, (sube immAllOnes, GPRC:$rA))]>;
745 def SUBFZE : XOForm_3<31, 200, 0, (ops GPRC:$rT, GPRC:$rA),
746                       "subfze $rT, $rA", IntGeneral,
747                       [(set GPRC:$rT, (sube 0, GPRC:$rA))]>;
748 }
749
750 // A-Form instructions.  Most of the instructions executed in the FPU are of
751 // this type.
752 //
753 let PPC970_Unit = 3 in {  // FPU Operations.
754 def FMADD : AForm_1<63, 29, 
755                     (ops F8RC:$FRT, F8RC:$FRA, F8RC:$FRC, F8RC:$FRB),
756                     "fmadd $FRT, $FRA, $FRC, $FRB", FPFused,
757                     [(set F8RC:$FRT, (fadd (fmul F8RC:$FRA, F8RC:$FRC),
758                                            F8RC:$FRB))]>,
759                     Requires<[FPContractions]>;
760 def FMADDS : AForm_1<59, 29,
761                     (ops F4RC:$FRT, F4RC:$FRA, F4RC:$FRC, F4RC:$FRB),
762                     "fmadds $FRT, $FRA, $FRC, $FRB", FPGeneral,
763                     [(set F4RC:$FRT, (fadd (fmul F4RC:$FRA, F4RC:$FRC),
764                                            F4RC:$FRB))]>,
765                     Requires<[FPContractions]>;
766 def FMSUB : AForm_1<63, 28,
767                     (ops F8RC:$FRT, F8RC:$FRA, F8RC:$FRC, F8RC:$FRB),
768                     "fmsub $FRT, $FRA, $FRC, $FRB", FPFused,
769                     [(set F8RC:$FRT, (fsub (fmul F8RC:$FRA, F8RC:$FRC),
770                                            F8RC:$FRB))]>,
771                     Requires<[FPContractions]>;
772 def FMSUBS : AForm_1<59, 28,
773                     (ops F4RC:$FRT, F4RC:$FRA, F4RC:$FRC, F4RC:$FRB),
774                     "fmsubs $FRT, $FRA, $FRC, $FRB", FPGeneral,
775                     [(set F4RC:$FRT, (fsub (fmul F4RC:$FRA, F4RC:$FRC),
776                                            F4RC:$FRB))]>,
777                     Requires<[FPContractions]>;
778 def FNMADD : AForm_1<63, 31,
779                     (ops F8RC:$FRT, F8RC:$FRA, F8RC:$FRC, F8RC:$FRB),
780                     "fnmadd $FRT, $FRA, $FRC, $FRB", FPFused,
781                     [(set F8RC:$FRT, (fneg (fadd (fmul F8RC:$FRA, F8RC:$FRC),
782                                                  F8RC:$FRB)))]>,
783                     Requires<[FPContractions]>;
784 def FNMADDS : AForm_1<59, 31,
785                     (ops F4RC:$FRT, F4RC:$FRA, F4RC:$FRC, F4RC:$FRB),
786                     "fnmadds $FRT, $FRA, $FRC, $FRB", FPGeneral,
787                     [(set F4RC:$FRT, (fneg (fadd (fmul F4RC:$FRA, F4RC:$FRC),
788                                                  F4RC:$FRB)))]>,
789                     Requires<[FPContractions]>;
790 def FNMSUB : AForm_1<63, 30,
791                     (ops F8RC:$FRT, F8RC:$FRA, F8RC:$FRC, F8RC:$FRB),
792                     "fnmsub $FRT, $FRA, $FRC, $FRB", FPFused,
793                     [(set F8RC:$FRT, (fneg (fsub (fmul F8RC:$FRA, F8RC:$FRC),
794                                                  F8RC:$FRB)))]>,
795                     Requires<[FPContractions]>;
796 def FNMSUBS : AForm_1<59, 30,
797                     (ops F4RC:$FRT, F4RC:$FRA, F4RC:$FRC, F4RC:$FRB),
798                     "fnmsubs $FRT, $FRA, $FRC, $FRB", FPGeneral,
799                     [(set F4RC:$FRT, (fneg (fsub (fmul F4RC:$FRA, F4RC:$FRC),
800                                                  F4RC:$FRB)))]>,
801                     Requires<[FPContractions]>;
802 // FSEL is artificially split into 4 and 8-byte forms for the result.  To avoid
803 // having 4 of these, force the comparison to always be an 8-byte double (code
804 // should use an FMRSD if the input comparison value really wants to be a float)
805 // and 4/8 byte forms for the result and operand type..
806 def FSELD : AForm_1<63, 23,
807                     (ops F8RC:$FRT, F8RC:$FRA, F8RC:$FRC, F8RC:$FRB),
808                     "fsel $FRT, $FRA, $FRC, $FRB", FPGeneral,
809                     [(set F8RC:$FRT, (PPCfsel F8RC:$FRA,F8RC:$FRC,F8RC:$FRB))]>;
810 def FSELS : AForm_1<63, 23,
811                      (ops F4RC:$FRT, F8RC:$FRA, F4RC:$FRC, F4RC:$FRB),
812                      "fsel $FRT, $FRA, $FRC, $FRB", FPGeneral,
813                     [(set F4RC:$FRT, (PPCfsel F8RC:$FRA,F4RC:$FRC,F4RC:$FRB))]>;
814 def FADD  : AForm_2<63, 21,
815                     (ops F8RC:$FRT, F8RC:$FRA, F8RC:$FRB),
816                     "fadd $FRT, $FRA, $FRB", FPGeneral,
817                     [(set F8RC:$FRT, (fadd F8RC:$FRA, F8RC:$FRB))]>;
818 def FADDS : AForm_2<59, 21,
819                     (ops F4RC:$FRT, F4RC:$FRA, F4RC:$FRB),
820                     "fadds $FRT, $FRA, $FRB", FPGeneral,
821                     [(set F4RC:$FRT, (fadd F4RC:$FRA, F4RC:$FRB))]>;
822 def FDIV  : AForm_2<63, 18,
823                     (ops F8RC:$FRT, F8RC:$FRA, F8RC:$FRB),
824                     "fdiv $FRT, $FRA, $FRB", FPDivD,
825                     [(set F8RC:$FRT, (fdiv F8RC:$FRA, F8RC:$FRB))]>;
826 def FDIVS : AForm_2<59, 18,
827                     (ops F4RC:$FRT, F4RC:$FRA, F4RC:$FRB),
828                     "fdivs $FRT, $FRA, $FRB", FPDivS,
829                     [(set F4RC:$FRT, (fdiv F4RC:$FRA, F4RC:$FRB))]>;
830 def FMUL  : AForm_3<63, 25,
831                     (ops F8RC:$FRT, F8RC:$FRA, F8RC:$FRB),
832                     "fmul $FRT, $FRA, $FRB", FPFused,
833                     [(set F8RC:$FRT, (fmul F8RC:$FRA, F8RC:$FRB))]>;
834 def FMULS : AForm_3<59, 25,
835                     (ops F4RC:$FRT, F4RC:$FRA, F4RC:$FRB),
836                     "fmuls $FRT, $FRA, $FRB", FPGeneral,
837                     [(set F4RC:$FRT, (fmul F4RC:$FRA, F4RC:$FRB))]>;
838 def FSUB  : AForm_2<63, 20,
839                     (ops F8RC:$FRT, F8RC:$FRA, F8RC:$FRB),
840                     "fsub $FRT, $FRA, $FRB", FPGeneral,
841                     [(set F8RC:$FRT, (fsub F8RC:$FRA, F8RC:$FRB))]>;
842 def FSUBS : AForm_2<59, 20,
843                     (ops F4RC:$FRT, F4RC:$FRA, F4RC:$FRB),
844                     "fsubs $FRT, $FRA, $FRB", FPGeneral,
845                     [(set F4RC:$FRT, (fsub F4RC:$FRA, F4RC:$FRB))]>;
846 }
847
848 let PPC970_Unit = 1 in {  // FXU Operations.
849 // M-Form instructions.  rotate and mask instructions.
850 //
851 let isTwoAddress = 1, isCommutable = 1 in {
852 // RLWIMI can be commuted if the rotate amount is zero.
853 def RLWIMI : MForm_2<20,
854                      (ops GPRC:$rA, GPRC:$rSi, GPRC:$rS, u5imm:$SH, u5imm:$MB, 
855                       u5imm:$ME), "rlwimi $rA, $rS, $SH, $MB, $ME", IntRotate,
856                       []>, PPC970_DGroup_Cracked;
857 }
858 def RLWINM : MForm_2<21,
859                      (ops GPRC:$rA, GPRC:$rS, u5imm:$SH, u5imm:$MB, u5imm:$ME),
860                      "rlwinm $rA, $rS, $SH, $MB, $ME", IntGeneral,
861                      []>;
862 def RLWINMo : MForm_2<21,
863                      (ops GPRC:$rA, GPRC:$rS, u5imm:$SH, u5imm:$MB, u5imm:$ME),
864                      "rlwinm. $rA, $rS, $SH, $MB, $ME", IntGeneral,
865                      []>, isDOT, PPC970_DGroup_Cracked;
866 def RLWNM  : MForm_2<23,
867                      (ops GPRC:$rA, GPRC:$rS, GPRC:$rB, u5imm:$MB, u5imm:$ME),
868                      "rlwnm $rA, $rS, $rB, $MB, $ME", IntGeneral,
869                      []>;
870 }
871
872
873 //===----------------------------------------------------------------------===//
874 // DWARF Pseudo Instructions
875 //
876
877 def DWARF_LOC        : Pseudo<(ops i32imm:$line, i32imm:$col, i32imm:$file),
878                               "; .loc $file, $line, $col",
879                       [(dwarf_loc (i32 imm:$line), (i32 imm:$col),
880                                   (i32 imm:$file))]>;
881
882 def DWARF_LABEL      : Pseudo<(ops i32imm:$id),
883                               "\nLdebug_loc$id:",
884                       [(dwarf_label (i32 imm:$id))]>;
885
886 //===----------------------------------------------------------------------===//
887 // PowerPC Instruction Patterns
888 //
889
890 // Arbitrary immediate support.  Implement in terms of LIS/ORI.
891 def : Pat<(i32 imm:$imm),
892           (ORI (LIS (HI16 imm:$imm)), (LO16 imm:$imm))>;
893
894 // Implement the 'not' operation with the NOR instruction.
895 def NOT : Pat<(not GPRC:$in),
896               (NOR GPRC:$in, GPRC:$in)>;
897
898 // ADD an arbitrary immediate.
899 def : Pat<(add GPRC:$in, imm:$imm),
900           (ADDIS (ADDI GPRC:$in, (LO16 imm:$imm)), (HA16 imm:$imm))>;
901 // OR an arbitrary immediate.
902 def : Pat<(or GPRC:$in, imm:$imm),
903           (ORIS (ORI GPRC:$in, (LO16 imm:$imm)), (HI16 imm:$imm))>;
904 // XOR an arbitrary immediate.
905 def : Pat<(xor GPRC:$in, imm:$imm),
906           (XORIS (XORI GPRC:$in, (LO16 imm:$imm)), (HI16 imm:$imm))>;
907 // SUBFIC
908 def : Pat<(sub  immSExt16:$imm, GPRC:$in),
909           (SUBFIC GPRC:$in, imm:$imm)>;
910
911 // Return void support.
912 def : Pat<(ret), (BLR)>;
913
914 // SHL/SRL
915 def : Pat<(shl GPRC:$in, (i32 imm:$imm)),
916           (RLWINM GPRC:$in, imm:$imm, 0, (SHL32 imm:$imm))>;
917 def : Pat<(srl GPRC:$in, (i32 imm:$imm)),
918           (RLWINM GPRC:$in, (SRL32 imm:$imm), imm:$imm, 31)>;
919
920 // ROTL
921 def : Pat<(rotl GPRC:$in, GPRC:$sh),
922           (RLWNM GPRC:$in, GPRC:$sh, 0, 31)>;
923 def : Pat<(rotl GPRC:$in, (i32 imm:$imm)),
924           (RLWINM GPRC:$in, imm:$imm, 0, 31)>;
925
926 // Calls
927 def : Pat<(PPCcall tglobaladdr:$dst),
928           (BL tglobaladdr:$dst)>;
929 def : Pat<(PPCcall texternalsym:$dst),
930           (BL texternalsym:$dst)>;
931
932 // Hi and Lo for Darwin Global Addresses.
933 def : Pat<(PPChi tglobaladdr:$in, 0), (LIS tglobaladdr:$in)>;
934 def : Pat<(PPClo tglobaladdr:$in, 0), (LI tglobaladdr:$in)>;
935 def : Pat<(PPChi tconstpool:$in, 0), (LIS tconstpool:$in)>;
936 def : Pat<(PPClo tconstpool:$in, 0), (LI tconstpool:$in)>;
937 def : Pat<(PPChi tjumptable:$in, 0), (LIS tjumptable:$in)>;
938 def : Pat<(PPClo tjumptable:$in, 0), (LI tjumptable:$in)>;
939 def : Pat<(add GPRC:$in, (PPChi tglobaladdr:$g, 0)),
940           (ADDIS GPRC:$in, tglobaladdr:$g)>;
941 def : Pat<(add GPRC:$in, (PPChi tconstpool:$g, 0)),
942           (ADDIS GPRC:$in, tconstpool:$g)>;
943 def : Pat<(add GPRC:$in, (PPChi tjumptable:$g, 0)),
944           (ADDIS GPRC:$in, tjumptable:$g)>;
945
946 // Fused negative multiply subtract, alternate pattern
947 def : Pat<(fsub F8RC:$B, (fmul F8RC:$A, F8RC:$C)),
948           (FNMSUB F8RC:$A, F8RC:$C, F8RC:$B)>,
949           Requires<[FPContractions]>;
950 def : Pat<(fsub F4RC:$B, (fmul F4RC:$A, F4RC:$C)),
951           (FNMSUBS F4RC:$A, F4RC:$C, F4RC:$B)>,
952           Requires<[FPContractions]>;
953
954 // Standard shifts.  These are represented separately from the real shifts above
955 // so that we can distinguish between shifts that allow 5-bit and 6-bit shift
956 // amounts.
957 def : Pat<(sra GPRC:$rS, GPRC:$rB),
958           (SRAW GPRC:$rS, GPRC:$rB)>;
959 def : Pat<(srl GPRC:$rS, GPRC:$rB),
960           (SRW GPRC:$rS, GPRC:$rB)>;
961 def : Pat<(shl GPRC:$rS, GPRC:$rB),
962           (SLW GPRC:$rS, GPRC:$rB)>;
963
964 def : Pat<(zextload iaddr:$src, i1),
965           (LBZ iaddr:$src)>;
966 def : Pat<(zextload xaddr:$src, i1),
967           (LBZX xaddr:$src)>;
968 def : Pat<(extload iaddr:$src, i1),
969           (LBZ iaddr:$src)>;
970 def : Pat<(extload xaddr:$src, i1),
971           (LBZX xaddr:$src)>;
972 def : Pat<(extload iaddr:$src, i8),
973           (LBZ iaddr:$src)>;
974 def : Pat<(extload xaddr:$src, i8),
975           (LBZX xaddr:$src)>;
976 def : Pat<(extload iaddr:$src, i16),
977           (LHZ iaddr:$src)>;
978 def : Pat<(extload xaddr:$src, i16),
979           (LHZX xaddr:$src)>;
980 def : Pat<(extload iaddr:$src, f32),
981           (FMRSD (LFS iaddr:$src))>;
982 def : Pat<(extload xaddr:$src, f32),
983           (FMRSD (LFSX xaddr:$src))>;
984
985 include "PPCInstrAltivec.td"
986 include "PPCInstr64Bit.td"