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