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