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