0b23c67f94b26d0e422417fce262d052419f766f
[oota-llvm.git] / lib / Target / PowerPC / PPCInstr64Bit.td
1 //===- PPCInstr64Bit.td - The PowerPC 64-bit Support -------*- tablegen -*-===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
10 // This file describes the PowerPC 64-bit instructions.  These patterns are used
11 // both when in ppc64 mode and when in "use 64-bit extensions in 32-bit" mode.
12 //
13 //===----------------------------------------------------------------------===//
14
15 //===----------------------------------------------------------------------===//
16 // 64-bit operands.
17 //
18 def s16imm64 : Operand<i64> {
19   let PrintMethod = "printS16ImmOperand";
20 }
21 def u16imm64 : Operand<i64> {
22   let PrintMethod = "printU16ImmOperand";
23 }
24 def symbolHi64 : Operand<i64> {
25   let PrintMethod = "printSymbolHi";
26 }
27 def symbolLo64 : Operand<i64> {
28   let PrintMethod = "printSymbolLo";
29 }
30
31 //===----------------------------------------------------------------------===//
32 // 64-bit transformation functions.
33 //
34
35 def SHL64 : SDNodeXForm<imm, [{
36   // Transformation function: 63 - imm
37   return getI32Imm(63 - N->getValue());
38 }]>;
39
40 def SRL64 : SDNodeXForm<imm, [{
41   // Transformation function: 64 - imm
42   return N->getValue() ? getI32Imm(64 - N->getValue()) : getI32Imm(0);
43 }]>;
44
45 def HI32_48 : SDNodeXForm<imm, [{
46   // Transformation function: shift the immediate value down into the low bits.
47   return getI32Imm((unsigned short)(N->getValue() >> 32));
48 }]>;
49
50 def HI48_64 : SDNodeXForm<imm, [{
51   // Transformation function: shift the immediate value down into the low bits.
52   return getI32Imm((unsigned short)(N->getValue() >> 48));
53 }]>;
54
55
56 //===----------------------------------------------------------------------===//
57 // Calls.
58 //
59
60 let Defs = [LR8] in
61   def MovePCtoLR8 : Pseudo<(outs), (ins piclabel:$label), "bl $label", []>,
62                     PPC970_Unit_BRU;
63
64 // Macho ABI Calls.
65 let isCall = 1, PPC970_Unit = 7, 
66   // All calls clobber the PPC64 non-callee saved registers.
67   Defs = [X0,X2,X3,X4,X5,X6,X7,X8,X9,X10,X11,X12,
68           F0,F1,F2,F3,F4,F5,F6,F7,F8,F9,F10,F11,F12,F13,
69           V0,V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,V13,V14,V15,V16,V17,V18,V19,
70           LR8,CTR8,
71           CR0,CR1,CR5,CR6,CR7] in {
72   // Convenient aliases for call instructions
73   def BL8_Macho  : IForm<18, 0, 1,
74                          (outs), (ins calltarget:$func, variable_ops), 
75                          "bl $func", BrB, []>;  // See Pat patterns below.
76   def BLA8_Macho : IForm<18, 1, 1,
77                          (outs), (ins aaddr:$func, variable_ops),
78                          "bla $func", BrB, [(PPCcall_Macho (i64 imm:$func))]>;
79   def BCTRL8_Macho : XLForm_2_ext<19, 528, 20, 0, 1, 
80                                  (outs), (ins variable_ops),
81                                  "bctrl", BrB,
82                                  [(PPCbctrl_Macho)]>, Requires<[In64BitMode]>;
83 }
84
85 // ELF 64 ABI Calls = Macho ABI Calls
86 // Used to define BL8_ELF and BLA8_ELF
87 let isCall = 1, PPC970_Unit = 7, 
88   // All calls clobber the PPC64 non-callee saved registers.
89   Defs = [X0,X2,X3,X4,X5,X6,X7,X8,X9,X10,X11,X12,
90           F0,F1,F2,F3,F4,F5,F6,F7,F8,F9,F10,F11,F12,F13,
91           V0,V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,V13,V14,V15,V16,V17,V18,V19,
92           LR8,CTR8,
93           CR0,CR1,CR5,CR6,CR7] in {
94   // Convenient aliases for call instructions
95   def BL8_ELF  : IForm<18, 0, 1,
96                        (outs), (ins calltarget:$func, variable_ops), 
97                        "bl $func", BrB, []>;  // See Pat patterns below.                            
98   def BLA8_ELF : IForm<18, 1, 1,
99                        (outs), (ins aaddr:$func, variable_ops),
100                        "bla $func", BrB, [(PPCcall_ELF (i64 imm:$func))]>;
101   def BCTRL8_ELF : XLForm_2_ext<19, 528, 20, 0, 1,
102                                (outs), (ins variable_ops),
103                                "bctrl", BrB,
104                                [(PPCbctrl_ELF)]>, Requires<[In64BitMode]>;
105 }
106
107
108 // Calls
109 def : Pat<(PPCcall_Macho (i64 tglobaladdr:$dst)),
110           (BL8_Macho tglobaladdr:$dst)>;
111 def : Pat<(PPCcall_Macho (i64 texternalsym:$dst)),
112           (BL8_Macho texternalsym:$dst)>;
113
114 def : Pat<(PPCcall_ELF (i64 tglobaladdr:$dst)),
115           (BL8_ELF tglobaladdr:$dst)>;
116 def : Pat<(PPCcall_ELF (i64 texternalsym:$dst)),
117           (BL8_ELF texternalsym:$dst)>;
118
119
120 // Atomic operations.
121 def LDARX : Pseudo<(outs G8RC:$rD), (ins memrr:$ptr, i32imm:$label),
122                    "\nLa${label}_entry:\n\tldarx $rD, $ptr",
123                    [(set G8RC:$rD, (PPClarx xoaddr:$ptr, imm:$label))]>;
124
125 let Defs = [CR0] in {
126 def STDCX : Pseudo<(outs), (ins G8RC:$rS, memrr:$dst, i32imm:$label),
127                   "stdcx. $rS, $dst\n\tbne- La${label}_entry\nLa${label}_exit:",
128                    [(PPCstcx G8RC:$rS, xoaddr:$dst, imm:$label)]>;
129
130 def CMP_UNRESd : Pseudo<(outs), (ins G8RC:$rA, G8RC:$rB, i32imm:$label),
131                          "cmpd $rA, $rB\n\tbne- La${label}_exit",
132                          [(PPCcmp_unres G8RC:$rA, G8RC:$rB, imm:$label)]>;
133 def CMP_UNRESdi : Pseudo<(outs), (ins G8RC:$rA, s16imm64:$imm, i32imm:$label),
134                          "cmpdi $rA, $imm\n\tbne- La${label}_exit",
135                          [(PPCcmp_unres G8RC:$rA, immSExt16:$imm, imm:$label)]>;
136 }
137
138 //===----------------------------------------------------------------------===//
139 // 64-bit SPR manipulation instrs.
140
141 def MFCTR8 : XFXForm_1_ext<31, 339, 9, (outs G8RC:$rT), (ins),
142                            "mfctr $rT", SprMFSPR>,
143              PPC970_DGroup_First, PPC970_Unit_FXU;
144 let Pattern = [(PPCmtctr G8RC:$rS)] in {
145 def MTCTR8 : XFXForm_7_ext<31, 467, 9, (outs), (ins G8RC:$rS),
146                            "mtctr $rS", SprMTSPR>,
147              PPC970_DGroup_First, PPC970_Unit_FXU;
148 }
149
150 let Defs = [X1], Uses = [X1] in
151 def DYNALLOC8 : Pseudo<(outs G8RC:$result), (ins G8RC:$negsize, memri:$fpsi),
152                        "${:comment} DYNALLOC8 $result, $negsize, $fpsi",
153                        [(set G8RC:$result,
154                              (PPCdynalloc G8RC:$negsize, iaddr:$fpsi))]>;
155
156 def MTLR8  : XFXForm_7_ext<31, 467, 8, (outs), (ins G8RC:$rS),
157                            "mtlr $rS", SprMTSPR>,
158              PPC970_DGroup_First, PPC970_Unit_FXU;
159 def MFLR8  : XFXForm_1_ext<31, 339, 8, (outs G8RC:$rT), (ins),
160                            "mflr $rT", SprMFSPR>,
161              PPC970_DGroup_First, PPC970_Unit_FXU;
162
163
164 //===----------------------------------------------------------------------===//
165 // Fixed point instructions.
166 //
167
168 let PPC970_Unit = 1 in {  // FXU Operations.
169
170 // Copies, extends, truncates.
171 def OR4To8  : XForm_6<31, 444, (outs G8RC:$rA), (ins GPRC:$rS, GPRC:$rB),
172                    "or $rA, $rS, $rB", IntGeneral,
173                    []>;
174 def OR8To4  : XForm_6<31, 444, (outs GPRC:$rA), (ins G8RC:$rS, G8RC:$rB),
175                    "or $rA, $rS, $rB", IntGeneral,
176                    []>;
177
178 def LI8  : DForm_2_r0<14, (outs G8RC:$rD), (ins symbolLo64:$imm),
179                       "li $rD, $imm", IntGeneral,
180                       [(set G8RC:$rD, immSExt16:$imm)]>;
181 def LIS8 : DForm_2_r0<15, (outs G8RC:$rD), (ins symbolHi64:$imm),
182                       "lis $rD, $imm", IntGeneral,
183                       [(set G8RC:$rD, imm16ShiftedSExt:$imm)]>;
184
185 // Logical ops.
186 def NAND8: XForm_6<31, 476, (outs G8RC:$rA), (ins G8RC:$rS, G8RC:$rB),
187                    "nand $rA, $rS, $rB", IntGeneral,
188                    [(set G8RC:$rA, (not (and G8RC:$rS, G8RC:$rB)))]>;
189 def AND8 : XForm_6<31,  28, (outs G8RC:$rA), (ins G8RC:$rS, G8RC:$rB),
190                    "and $rA, $rS, $rB", IntGeneral,
191                    [(set G8RC:$rA, (and G8RC:$rS, G8RC:$rB))]>;
192 def ANDC8: XForm_6<31,  60, (outs G8RC:$rA), (ins G8RC:$rS, G8RC:$rB),
193                    "andc $rA, $rS, $rB", IntGeneral,
194                    [(set G8RC:$rA, (and G8RC:$rS, (not G8RC:$rB)))]>;
195 def OR8  : XForm_6<31, 444, (outs G8RC:$rA), (ins G8RC:$rS, G8RC:$rB),
196                    "or $rA, $rS, $rB", IntGeneral,
197                    [(set G8RC:$rA, (or G8RC:$rS, G8RC:$rB))]>;
198 def NOR8 : XForm_6<31, 124, (outs G8RC:$rA), (ins G8RC:$rS, G8RC:$rB),
199                    "nor $rA, $rS, $rB", IntGeneral,
200                    [(set G8RC:$rA, (not (or G8RC:$rS, G8RC:$rB)))]>;
201 def ORC8 : XForm_6<31, 412, (outs G8RC:$rA), (ins G8RC:$rS, G8RC:$rB),
202                    "orc $rA, $rS, $rB", IntGeneral,
203                    [(set G8RC:$rA, (or G8RC:$rS, (not G8RC:$rB)))]>;
204 def EQV8 : XForm_6<31, 284, (outs G8RC:$rA), (ins G8RC:$rS, G8RC:$rB),
205                    "eqv $rA, $rS, $rB", IntGeneral,
206                    [(set G8RC:$rA, (not (xor G8RC:$rS, G8RC:$rB)))]>;
207 def XOR8 : XForm_6<31, 316, (outs G8RC:$rA), (ins G8RC:$rS, G8RC:$rB),
208                    "xor $rA, $rS, $rB", IntGeneral,
209                    [(set G8RC:$rA, (xor G8RC:$rS, G8RC:$rB))]>;
210
211 // Logical ops with immediate.
212 def ANDIo8  : DForm_4<28, (outs G8RC:$dst), (ins G8RC:$src1, u16imm:$src2),
213                       "andi. $dst, $src1, $src2", IntGeneral,
214                       [(set G8RC:$dst, (and G8RC:$src1, immZExt16:$src2))]>,
215                       isDOT;
216 def ANDISo8 : DForm_4<29, (outs G8RC:$dst), (ins G8RC:$src1, u16imm:$src2),
217                      "andis. $dst, $src1, $src2", IntGeneral,
218                     [(set G8RC:$dst, (and G8RC:$src1,imm16ShiftedZExt:$src2))]>,
219                      isDOT;
220 def ORI8    : DForm_4<24, (outs G8RC:$dst), (ins G8RC:$src1, u16imm:$src2),
221                       "ori $dst, $src1, $src2", IntGeneral,
222                       [(set G8RC:$dst, (or G8RC:$src1, immZExt16:$src2))]>;
223 def ORIS8   : DForm_4<25, (outs G8RC:$dst), (ins G8RC:$src1, u16imm:$src2),
224                       "oris $dst, $src1, $src2", IntGeneral,
225                     [(set G8RC:$dst, (or G8RC:$src1, imm16ShiftedZExt:$src2))]>;
226 def XORI8   : DForm_4<26, (outs G8RC:$dst), (ins G8RC:$src1, u16imm:$src2),
227                       "xori $dst, $src1, $src2", IntGeneral,
228                       [(set G8RC:$dst, (xor G8RC:$src1, immZExt16:$src2))]>;
229 def XORIS8  : DForm_4<27, (outs G8RC:$dst), (ins G8RC:$src1, u16imm:$src2),
230                       "xoris $dst, $src1, $src2", IntGeneral,
231                    [(set G8RC:$dst, (xor G8RC:$src1, imm16ShiftedZExt:$src2))]>;
232
233 def ADD8  : XOForm_1<31, 266, 0, (outs G8RC:$rT), (ins G8RC:$rA, G8RC:$rB),
234                      "add $rT, $rA, $rB", IntGeneral,
235                      [(set G8RC:$rT, (add G8RC:$rA, G8RC:$rB))]>;
236                      
237 def ADDC8 : XOForm_1<31, 10, 0, (outs G8RC:$rT), (ins G8RC:$rA, G8RC:$rB),
238                      "addc $rT, $rA, $rB", IntGeneral,
239                      [(set G8RC:$rT, (addc G8RC:$rA, G8RC:$rB))]>,
240                      PPC970_DGroup_Cracked;
241 def ADDE8 : XOForm_1<31, 138, 0, (outs G8RC:$rT), (ins G8RC:$rA, G8RC:$rB),
242                      "adde $rT, $rA, $rB", IntGeneral,
243                      [(set G8RC:$rT, (adde G8RC:$rA, G8RC:$rB))]>;
244                      
245 def ADDI8  : DForm_2<14, (outs G8RC:$rD), (ins G8RC:$rA, s16imm64:$imm),
246                      "addi $rD, $rA, $imm", IntGeneral,
247                      [(set G8RC:$rD, (add G8RC:$rA, immSExt16:$imm))]>;
248 def ADDIS8 : DForm_2<15, (outs G8RC:$rD), (ins G8RC:$rA, symbolHi64:$imm),
249                      "addis $rD, $rA, $imm", IntGeneral,
250                      [(set G8RC:$rD, (add G8RC:$rA, imm16ShiftedSExt:$imm))]>;
251
252 def SUBFIC8: DForm_2< 8, (outs G8RC:$rD), (ins G8RC:$rA, s16imm64:$imm),
253                      "subfic $rD, $rA, $imm", IntGeneral,
254                      [(set G8RC:$rD, (subc immSExt16:$imm, G8RC:$rA))]>;
255 def SUBF8 : XOForm_1<31, 40, 0, (outs G8RC:$rT), (ins G8RC:$rA, G8RC:$rB),
256                      "subf $rT, $rA, $rB", IntGeneral,
257                      [(set G8RC:$rT, (sub G8RC:$rB, G8RC:$rA))]>;
258
259 def SUBFC8 : XOForm_1<31, 8, 0, (outs G8RC:$rT), (ins G8RC:$rA, G8RC:$rB),
260                       "subfc $rT, $rA, $rB", IntGeneral,
261                       [(set G8RC:$rT, (subc G8RC:$rB, G8RC:$rA))]>,
262                       PPC970_DGroup_Cracked;
263
264 def SUBFE8 : XOForm_1<31, 136, 0, (outs G8RC:$rT), (ins G8RC:$rA, G8RC:$rB),
265                       "subfe $rT, $rA, $rB", IntGeneral,
266                       [(set G8RC:$rT, (sube G8RC:$rB, G8RC:$rA))]>;
267 def ADDME8  : XOForm_3<31, 234, 0, (outs G8RC:$rT), (ins G8RC:$rA),
268                        "addme $rT, $rA", IntGeneral,
269                        [(set G8RC:$rT, (adde G8RC:$rA, immAllOnes))]>;
270 def ADDZE8  : XOForm_3<31, 202, 0, (outs G8RC:$rT), (ins G8RC:$rA),
271                        "addze $rT, $rA", IntGeneral,
272                        [(set G8RC:$rT, (adde G8RC:$rA, 0))]>;
273 def NEG8    : XOForm_3<31, 104, 0, (outs G8RC:$rT), (ins G8RC:$rA),
274                        "neg $rT, $rA", IntGeneral,
275                        [(set G8RC:$rT, (ineg G8RC:$rA))]>;
276 def SUBFME8 : XOForm_3<31, 232, 0, (outs G8RC:$rT), (ins G8RC:$rA),
277                        "subfme $rT, $rA", IntGeneral,
278                        [(set G8RC:$rT, (sube immAllOnes, G8RC:$rA))]>;
279 def SUBFZE8 : XOForm_3<31, 200, 0, (outs G8RC:$rT), (ins G8RC:$rA),
280                        "subfze $rT, $rA", IntGeneral,
281                        [(set G8RC:$rT, (sube 0, G8RC:$rA))]>;
282
283
284
285 def MULHD : XOForm_1<31, 73, 0, (outs G8RC:$rT), (ins G8RC:$rA, G8RC:$rB),
286                      "mulhd $rT, $rA, $rB", IntMulHW,
287                      [(set G8RC:$rT, (mulhs G8RC:$rA, G8RC:$rB))]>;
288 def MULHDU : XOForm_1<31, 9, 0, (outs G8RC:$rT), (ins G8RC:$rA, G8RC:$rB),
289                      "mulhdu $rT, $rA, $rB", IntMulHWU,
290                      [(set G8RC:$rT, (mulhu G8RC:$rA, G8RC:$rB))]>;
291
292 def CMPD   : XForm_16_ext<31, 0, (outs CRRC:$crD), (ins G8RC:$rA, G8RC:$rB),
293                           "cmpd $crD, $rA, $rB", IntCompare>, isPPC64;
294 def CMPLD  : XForm_16_ext<31, 32, (outs CRRC:$crD), (ins G8RC:$rA, G8RC:$rB),
295                           "cmpld $crD, $rA, $rB", IntCompare>, isPPC64;
296 def CMPDI  : DForm_5_ext<11, (outs CRRC:$crD), (ins G8RC:$rA, s16imm:$imm),
297                          "cmpdi $crD, $rA, $imm", IntCompare>, isPPC64;
298 def CMPLDI : DForm_6_ext<10, (outs CRRC:$dst), (ins G8RC:$src1, u16imm:$src2),
299                          "cmpldi $dst, $src1, $src2", IntCompare>, isPPC64;
300
301 def SLD  : XForm_6<31,  27, (outs G8RC:$rA), (ins G8RC:$rS, GPRC:$rB),
302                    "sld $rA, $rS, $rB", IntRotateD,
303                    [(set G8RC:$rA, (PPCshl G8RC:$rS, GPRC:$rB))]>, isPPC64;
304 def SRD  : XForm_6<31, 539, (outs G8RC:$rA), (ins G8RC:$rS, GPRC:$rB),
305                    "srd $rA, $rS, $rB", IntRotateD,
306                    [(set G8RC:$rA, (PPCsrl G8RC:$rS, GPRC:$rB))]>, isPPC64;
307 def SRAD : XForm_6<31, 794, (outs G8RC:$rA), (ins G8RC:$rS, GPRC:$rB),
308                    "srad $rA, $rS, $rB", IntRotateD,
309                    [(set G8RC:$rA, (PPCsra G8RC:$rS, GPRC:$rB))]>, isPPC64;
310                    
311 def EXTSB8 : XForm_11<31, 954, (outs G8RC:$rA), (ins G8RC:$rS),
312                       "extsb $rA, $rS", IntGeneral,
313                       [(set G8RC:$rA, (sext_inreg G8RC:$rS, i8))]>;
314 def EXTSH8 : XForm_11<31, 922, (outs G8RC:$rA), (ins G8RC:$rS),
315                       "extsh $rA, $rS", IntGeneral,
316                       [(set G8RC:$rA, (sext_inreg G8RC:$rS, i16))]>;
317
318 def EXTSW  : XForm_11<31, 986, (outs G8RC:$rA), (ins G8RC:$rS),
319                       "extsw $rA, $rS", IntGeneral,
320                       [(set G8RC:$rA, (sext_inreg G8RC:$rS, i32))]>, isPPC64;
321 /// EXTSW_32 - Just like EXTSW, but works on '32-bit' registers.
322 def EXTSW_32 : XForm_11<31, 986, (outs GPRC:$rA), (ins GPRC:$rS),
323                       "extsw $rA, $rS", IntGeneral,
324                       [(set GPRC:$rA, (PPCextsw_32 GPRC:$rS))]>, isPPC64;
325 def EXTSW_32_64 : XForm_11<31, 986, (outs G8RC:$rA), (ins GPRC:$rS),
326                       "extsw $rA, $rS", IntGeneral,
327                       [(set G8RC:$rA, (sext GPRC:$rS))]>, isPPC64;
328
329 def SRADI  : XSForm_1<31, 413, (outs G8RC:$rA), (ins G8RC:$rS, u6imm:$SH),
330                       "sradi $rA, $rS, $SH", IntRotateD,
331                       [(set G8RC:$rA, (sra G8RC:$rS, (i32 imm:$SH)))]>, isPPC64;
332 def CNTLZD : XForm_11<31, 58, (outs G8RC:$rA), (ins G8RC:$rS),
333                       "cntlzd $rA, $rS", IntGeneral,
334                       [(set G8RC:$rA, (ctlz G8RC:$rS))]>;
335
336 def DIVD  : XOForm_1<31, 489, 0, (outs G8RC:$rT), (ins G8RC:$rA, G8RC:$rB),
337                      "divd $rT, $rA, $rB", IntDivD,
338                      [(set G8RC:$rT, (sdiv G8RC:$rA, G8RC:$rB))]>, isPPC64,
339                      PPC970_DGroup_First, PPC970_DGroup_Cracked;
340 def DIVDU : XOForm_1<31, 457, 0, (outs G8RC:$rT), (ins G8RC:$rA, G8RC:$rB),
341                      "divdu $rT, $rA, $rB", IntDivD,
342                      [(set G8RC:$rT, (udiv G8RC:$rA, G8RC:$rB))]>, isPPC64,
343                      PPC970_DGroup_First, PPC970_DGroup_Cracked;
344 def MULLD : XOForm_1<31, 233, 0, (outs G8RC:$rT), (ins G8RC:$rA, G8RC:$rB),
345                      "mulld $rT, $rA, $rB", IntMulHD,
346                      [(set G8RC:$rT, (mul G8RC:$rA, G8RC:$rB))]>, isPPC64;
347
348
349 let isCommutable = 1 in {
350 def RLDIMI : MDForm_1<30, 3,
351                       (outs G8RC:$rA), (ins G8RC:$rSi, G8RC:$rS, u6imm:$SH, u6imm:$MB),
352                       "rldimi $rA, $rS, $SH, $MB", IntRotateD,
353                       []>, isPPC64, RegConstraint<"$rSi = $rA">,
354                       NoEncode<"$rSi">;
355 }
356
357 // Rotate instructions.
358 def RLDCL  : MDForm_1<30, 0,
359                       (outs G8RC:$rA), (ins G8RC:$rS, GPRC:$rB, u6imm:$MB),
360                       "rldcl $rA, $rS, $rB, $MB", IntRotateD,
361                       []>, isPPC64;
362 def RLDICL : MDForm_1<30, 0,
363                       (outs G8RC:$rA), (ins G8RC:$rS, u6imm:$SH, u6imm:$MB),
364                       "rldicl $rA, $rS, $SH, $MB", IntRotateD,
365                       []>, isPPC64;
366 def RLDICR : MDForm_1<30, 1,
367                       (outs G8RC:$rA), (ins G8RC:$rS, u6imm:$SH, u6imm:$ME),
368                       "rldicr $rA, $rS, $SH, $ME", IntRotateD,
369                       []>, isPPC64;
370 }  // End FXU Operations.
371
372
373 //===----------------------------------------------------------------------===//
374 // Load/Store instructions.
375 //
376
377
378 // Sign extending loads.
379 let isSimpleLoad = 1, PPC970_Unit = 2 in {
380 def LHA8: DForm_1<42, (outs G8RC:$rD), (ins memri:$src),
381                   "lha $rD, $src", LdStLHA,
382                   [(set G8RC:$rD, (sextloadi16 iaddr:$src))]>,
383                   PPC970_DGroup_Cracked;
384 def LWA  : DSForm_1<58, 2, (outs G8RC:$rD), (ins memrix:$src),
385                     "lwa $rD, $src", LdStLWA,
386                     [(set G8RC:$rD, (sextloadi32 ixaddr:$src))]>, isPPC64,
387                     PPC970_DGroup_Cracked;
388 def LHAX8: XForm_1<31, 343, (outs G8RC:$rD), (ins memrr:$src),
389                    "lhax $rD, $src", LdStLHA,
390                    [(set G8RC:$rD, (sextloadi16 xaddr:$src))]>,
391                    PPC970_DGroup_Cracked;
392 def LWAX : XForm_1<31, 341, (outs G8RC:$rD), (ins memrr:$src),
393                    "lwax $rD, $src", LdStLHA,
394                    [(set G8RC:$rD, (sextloadi32 xaddr:$src))]>, isPPC64,
395                    PPC970_DGroup_Cracked;
396
397 // Update forms.
398 def LHAU8 : DForm_1<43, (outs G8RC:$rD, ptr_rc:$ea_result), (ins symbolLo:$disp,
399                             ptr_rc:$rA),
400                     "lhau $rD, $disp($rA)", LdStGeneral,
401                     []>, RegConstraint<"$rA = $ea_result">,
402                     NoEncode<"$ea_result">;
403 // NO LWAU!
404
405 }
406
407 // Zero extending loads.
408 let isSimpleLoad = 1, PPC970_Unit = 2 in {
409 def LBZ8 : DForm_1<34, (outs G8RC:$rD), (ins memri:$src),
410                   "lbz $rD, $src", LdStGeneral,
411                   [(set G8RC:$rD, (zextloadi8 iaddr:$src))]>;
412 def LHZ8 : DForm_1<40, (outs G8RC:$rD), (ins memri:$src),
413                   "lhz $rD, $src", LdStGeneral,
414                   [(set G8RC:$rD, (zextloadi16 iaddr:$src))]>;
415 def LWZ8 : DForm_1<32, (outs G8RC:$rD), (ins memri:$src),
416                   "lwz $rD, $src", LdStGeneral,
417                   [(set G8RC:$rD, (zextloadi32 iaddr:$src))]>, isPPC64;
418
419 def LBZX8 : XForm_1<31,  87, (outs G8RC:$rD), (ins memrr:$src),
420                    "lbzx $rD, $src", LdStGeneral,
421                    [(set G8RC:$rD, (zextloadi8 xaddr:$src))]>;
422 def LHZX8 : XForm_1<31, 279, (outs G8RC:$rD), (ins memrr:$src),
423                    "lhzx $rD, $src", LdStGeneral,
424                    [(set G8RC:$rD, (zextloadi16 xaddr:$src))]>;
425 def LWZX8 : XForm_1<31,  23, (outs G8RC:$rD), (ins memrr:$src),
426                    "lwzx $rD, $src", LdStGeneral,
427                    [(set G8RC:$rD, (zextloadi32 xaddr:$src))]>;
428                    
429                    
430 // Update forms.
431 def LBZU8 : DForm_1<35, (outs G8RC:$rD, ptr_rc:$ea_result), (ins memri:$addr),
432                     "lbzu $rD, $addr", LdStGeneral,
433                     []>, RegConstraint<"$addr.reg = $ea_result">,
434                     NoEncode<"$ea_result">;
435 def LHZU8 : DForm_1<41, (outs G8RC:$rD, ptr_rc:$ea_result), (ins memri:$addr),
436                     "lhzu $rD, $addr", LdStGeneral,
437                     []>, RegConstraint<"$addr.reg = $ea_result">,
438                     NoEncode<"$ea_result">;
439 def LWZU8 : DForm_1<33, (outs G8RC:$rD, ptr_rc:$ea_result), (ins memri:$addr),
440                     "lwzu $rD, $addr", LdStGeneral,
441                     []>, RegConstraint<"$addr.reg = $ea_result">,
442                     NoEncode<"$ea_result">;
443 }
444
445
446 // Full 8-byte loads.
447 let isSimpleLoad = 1, PPC970_Unit = 2 in {
448 def LD   : DSForm_1<58, 0, (outs G8RC:$rD), (ins memrix:$src),
449                     "ld $rD, $src", LdStLD,
450                     [(set G8RC:$rD, (load ixaddr:$src))]>, isPPC64;
451 def LDX  : XForm_1<31,  21, (outs G8RC:$rD), (ins memrr:$src),
452                    "ldx $rD, $src", LdStLD,
453                    [(set G8RC:$rD, (load xaddr:$src))]>, isPPC64;
454                    
455 def LDU  : DSForm_1<58, 1, (outs G8RC:$rD, ptr_rc:$ea_result), (ins memrix:$addr),
456                     "ldu $rD, $addr", LdStLD,
457                     []>, RegConstraint<"$addr.reg = $ea_result">, isPPC64,
458                     NoEncode<"$ea_result">;
459
460 }
461
462 let PPC970_Unit = 2 in {
463 // Truncating stores.                       
464 def STB8 : DForm_1<38, (outs), (ins G8RC:$rS, memri:$src),
465                    "stb $rS, $src", LdStGeneral,
466                    [(truncstorei8 G8RC:$rS, iaddr:$src)]>;
467 def STH8 : DForm_1<44, (outs), (ins G8RC:$rS, memri:$src),
468                    "sth $rS, $src", LdStGeneral,
469                    [(truncstorei16 G8RC:$rS, iaddr:$src)]>;
470 def STW8 : DForm_1<36, (outs), (ins G8RC:$rS, memri:$src),
471                    "stw $rS, $src", LdStGeneral,
472                    [(truncstorei32 G8RC:$rS, iaddr:$src)]>;
473 def STBX8 : XForm_8<31, 215, (outs), (ins G8RC:$rS, memrr:$dst),
474                    "stbx $rS, $dst", LdStGeneral,
475                    [(truncstorei8 G8RC:$rS, xaddr:$dst)]>, 
476                    PPC970_DGroup_Cracked;
477 def STHX8 : XForm_8<31, 407, (outs), (ins G8RC:$rS, memrr:$dst),
478                    "sthx $rS, $dst", LdStGeneral,
479                    [(truncstorei16 G8RC:$rS, xaddr:$dst)]>, 
480                    PPC970_DGroup_Cracked;
481 def STWX8 : XForm_8<31, 151, (outs), (ins G8RC:$rS, memrr:$dst),
482                    "stwx $rS, $dst", LdStGeneral,
483                    [(truncstorei32 G8RC:$rS, xaddr:$dst)]>,
484                    PPC970_DGroup_Cracked;
485 // Normal 8-byte stores.
486 def STD  : DSForm_1<62, 0, (outs), (ins G8RC:$rS, memrix:$dst),
487                     "std $rS, $dst", LdStSTD,
488                     [(store G8RC:$rS, ixaddr:$dst)]>, isPPC64;
489 def STDX  : XForm_8<31, 149, (outs), (ins G8RC:$rS, memrr:$dst),
490                    "stdx $rS, $dst", LdStSTD,
491                    [(store G8RC:$rS, xaddr:$dst)]>, isPPC64,
492                    PPC970_DGroup_Cracked;
493 }
494
495 let PPC970_Unit = 2 in {
496
497 def STBU8 : DForm_1<38, (outs ptr_rc:$ea_res), (ins G8RC:$rS,
498                              symbolLo:$ptroff, ptr_rc:$ptrreg),
499                     "stbu $rS, $ptroff($ptrreg)", LdStGeneral,
500                     [(set ptr_rc:$ea_res,
501                           (pre_truncsti8 G8RC:$rS, ptr_rc:$ptrreg, 
502                                          iaddroff:$ptroff))]>,
503                     RegConstraint<"$ptrreg = $ea_res">, NoEncode<"$ea_res">;
504 def STHU8 : DForm_1<45, (outs ptr_rc:$ea_res), (ins G8RC:$rS,
505                              symbolLo:$ptroff, ptr_rc:$ptrreg),
506                     "sthu $rS, $ptroff($ptrreg)", LdStGeneral,
507                     [(set ptr_rc:$ea_res,
508                         (pre_truncsti16 G8RC:$rS, ptr_rc:$ptrreg, 
509                                         iaddroff:$ptroff))]>,
510                     RegConstraint<"$ptrreg = $ea_res">, NoEncode<"$ea_res">;
511 def STWU8 : DForm_1<37, (outs ptr_rc:$ea_res), (ins G8RC:$rS,
512                              symbolLo:$ptroff, ptr_rc:$ptrreg),
513                     "stwu $rS, $ptroff($ptrreg)", LdStGeneral,
514                     [(set ptr_rc:$ea_res, (pre_store G8RC:$rS, ptr_rc:$ptrreg, 
515                                                      iaddroff:$ptroff))]>,
516                     RegConstraint<"$ptrreg = $ea_res">, NoEncode<"$ea_res">;
517
518
519 def STDU : DSForm_1<62, 1, (outs ptr_rc:$ea_res), (ins G8RC:$rS,
520                                 s16immX4:$ptroff, ptr_rc:$ptrreg),
521                     "stdu $rS, $ptroff($ptrreg)", LdStSTD,
522                     [(set ptr_rc:$ea_res, (pre_store G8RC:$rS, ptr_rc:$ptrreg, 
523                                                      iaddroff:$ptroff))]>,
524                     RegConstraint<"$ptrreg = $ea_res">, NoEncode<"$ea_res">,
525                     isPPC64;
526
527 let mayStore = 1 in
528 def STDUX : XForm_8<31, 181, (outs), (ins G8RC:$rS, memrr:$dst),
529                    "stdux $rS, $dst", LdStSTD,
530                    []>, isPPC64;
531
532 // STD_32/STDX_32 - Just like STD/STDX, but uses a '32-bit' input register.
533 def STD_32  : DSForm_1<62, 0, (outs), (ins GPRC:$rT, memrix:$dst),
534                        "std $rT, $dst", LdStSTD,
535                        [(PPCstd_32  GPRC:$rT, ixaddr:$dst)]>, isPPC64;
536 def STDX_32  : XForm_8<31, 149, (outs), (ins GPRC:$rT, memrr:$dst),
537                        "stdx $rT, $dst", LdStSTD,
538                        [(PPCstd_32  GPRC:$rT, xaddr:$dst)]>, isPPC64,
539                        PPC970_DGroup_Cracked;
540 }
541
542
543
544 //===----------------------------------------------------------------------===//
545 // Floating point instructions.
546 //
547
548
549 let PPC970_Unit = 3 in {  // FPU Operations.
550 def FCFID  : XForm_26<63, 846, (outs F8RC:$frD), (ins F8RC:$frB),
551                       "fcfid $frD, $frB", FPGeneral,
552                       [(set F8RC:$frD, (PPCfcfid F8RC:$frB))]>, isPPC64;
553 def FCTIDZ : XForm_26<63, 815, (outs F8RC:$frD), (ins F8RC:$frB),
554                       "fctidz $frD, $frB", FPGeneral,
555                       [(set F8RC:$frD, (PPCfctidz F8RC:$frB))]>, isPPC64;
556 }
557
558
559 //===----------------------------------------------------------------------===//
560 // Instruction Patterns
561 //
562
563 // Extensions and truncates to/from 32-bit regs.
564 def : Pat<(i64 (zext GPRC:$in)),
565           (RLDICL (OR4To8 GPRC:$in, GPRC:$in), 0, 32)>;
566 def : Pat<(i64 (anyext GPRC:$in)),
567           (OR4To8 GPRC:$in, GPRC:$in)>;
568 def : Pat<(i32 (trunc G8RC:$in)),
569           (OR8To4 G8RC:$in, G8RC:$in)>;
570
571 // Extending loads with i64 targets.
572 def : Pat<(zextloadi1 iaddr:$src),
573           (LBZ8 iaddr:$src)>;
574 def : Pat<(zextloadi1 xaddr:$src),
575           (LBZX8 xaddr:$src)>;
576 def : Pat<(extloadi1 iaddr:$src),
577           (LBZ8 iaddr:$src)>;
578 def : Pat<(extloadi1 xaddr:$src),
579           (LBZX8 xaddr:$src)>;
580 def : Pat<(extloadi8 iaddr:$src),
581           (LBZ8 iaddr:$src)>;
582 def : Pat<(extloadi8 xaddr:$src),
583           (LBZX8 xaddr:$src)>;
584 def : Pat<(extloadi16 iaddr:$src),
585           (LHZ8 iaddr:$src)>;
586 def : Pat<(extloadi16 xaddr:$src),
587           (LHZX8 xaddr:$src)>;
588 def : Pat<(extloadi32 iaddr:$src),
589           (LWZ8 iaddr:$src)>;
590 def : Pat<(extloadi32 xaddr:$src),
591           (LWZX8 xaddr:$src)>;
592
593 // Standard shifts.  These are represented separately from the real shifts above
594 // so that we can distinguish between shifts that allow 6-bit and 7-bit shift
595 // amounts.
596 def : Pat<(sra G8RC:$rS, GPRC:$rB),
597           (SRAD G8RC:$rS, GPRC:$rB)>;
598 def : Pat<(srl G8RC:$rS, GPRC:$rB),
599           (SRD G8RC:$rS, GPRC:$rB)>;
600 def : Pat<(shl G8RC:$rS, GPRC:$rB),
601           (SLD G8RC:$rS, GPRC:$rB)>;
602
603 // SHL/SRL
604 def : Pat<(shl G8RC:$in, (i32 imm:$imm)),
605           (RLDICR G8RC:$in, imm:$imm, (SHL64 imm:$imm))>;
606 def : Pat<(srl G8RC:$in, (i32 imm:$imm)),
607           (RLDICL G8RC:$in, (SRL64 imm:$imm), imm:$imm)>;
608
609 // ROTL
610 def : Pat<(rotl G8RC:$in, GPRC:$sh),
611           (RLDCL G8RC:$in, GPRC:$sh, 0)>;
612 def : Pat<(rotl G8RC:$in, (i32 imm:$imm)),
613           (RLDICL G8RC:$in, imm:$imm, 0)>;
614
615 // Hi and Lo for Darwin Global Addresses.
616 def : Pat<(PPChi tglobaladdr:$in, 0), (LIS8 tglobaladdr:$in)>;
617 def : Pat<(PPClo tglobaladdr:$in, 0), (LI8  tglobaladdr:$in)>;
618 def : Pat<(PPChi tconstpool:$in , 0), (LIS8 tconstpool:$in)>;
619 def : Pat<(PPClo tconstpool:$in , 0), (LI8  tconstpool:$in)>;
620 def : Pat<(PPChi tjumptable:$in , 0), (LIS8 tjumptable:$in)>;
621 def : Pat<(PPClo tjumptable:$in , 0), (LI8  tjumptable:$in)>;
622 def : Pat<(add G8RC:$in, (PPChi tglobaladdr:$g, 0)),
623           (ADDIS8 G8RC:$in, tglobaladdr:$g)>;
624 def : Pat<(add G8RC:$in, (PPChi tconstpool:$g, 0)),
625           (ADDIS8 G8RC:$in, tconstpool:$g)>;
626 def : Pat<(add G8RC:$in, (PPChi tjumptable:$g, 0)),
627           (ADDIS8 G8RC:$in, tjumptable:$g)>;