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