create the raddr addressing mode that matches any register and the frame index
[oota-llvm.git] / lib / Target / IA64 / IA64InstrInfo.td
1 //===- IA64InstrInfo.td - Describe the IA64 Instruction Set -----*- C++ -*-===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by Duraid Madina and is distributed under the
6 // University of Illinois Open Source License. See LICENSE.TXT for details.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
10 // This file describes the IA64 instruction set, defining the instructions, and
11 // properties of the instructions which are needed for code generation, machine
12 // code emission, and analysis.
13 //
14 //===----------------------------------------------------------------------===//
15
16 include "IA64InstrFormats.td"
17
18 //===----------------------------------------------------------------------===//
19 // IA-64 specific DAG Nodes.
20 //
21
22 def IA64getfd : SDNode<"IA64ISD::GETFD", SDTFPToIntOp, []>;
23
24 def SDT_IA64RetFlag : SDTypeProfile<0, 0, []>;
25 def retflag         : SDNode<"IA64ISD::RET_FLAG", SDT_IA64RetFlag,
26                            [SDNPHasChain, SDNPOptInFlag]>;
27
28 //===---------
29 // Instruction types
30
31 class isA { bit A=1; } // I or M unit
32 class isM { bit M=1; } // M unit
33 class isI { bit I=1; } // I unit
34 class isB { bit B=1; } // B unit
35 class isF { bit F=1; } // F unit
36 class isLX { bit LX=1; } // I/B
37
38 //===---------
39
40 def u2imm : Operand<i8>;
41 def u6imm : Operand<i8>;
42 def s8imm : Operand<i8> {
43   let PrintMethod = "printS8ImmOperand";
44 }
45 def s14imm  : Operand<i64> {
46   let PrintMethod = "printS14ImmOperand";
47 }
48 def s22imm  : Operand<i64> {
49   let PrintMethod = "printS22ImmOperand";
50 }
51 def u64imm  : Operand<i64> {
52   let PrintMethod = "printU64ImmOperand";
53 }
54 def s64imm  : Operand<i64> {
55   let PrintMethod = "printS64ImmOperand";
56 }
57
58 let PrintMethod = "printGlobalOperand" in
59   def globaladdress : Operand<i64>;
60
61 // the asmprinter needs to know about calls
62 let PrintMethod = "printCallOperand" in
63   def calltarget : Operand<i64>;
64   
65 /* new daggy action!!! */
66
67 def is32ones : PatLeaf<(i64 imm), [{
68   // is32ones predicate - True if the immediate is 0x00000000FFFFFFFF 
69   // Used to create ZXT4s appropriately 
70   uint64_t v = (uint64_t)N->getValue();
71   return (v == 0x00000000FFFFFFFFLL);
72 }]>;
73
74 // isMIXable predicates - True if the immediate is
75 // 0xFF00FF00FF00FF00, 0x00FF00FF00FF00FF
76 // etc, through 0x00000000FFFFFFFF
77 // Used to test for the suitability of mix* 
78 def isMIX1Lable: PatLeaf<(i64 imm), [{
79   return((uint64_t)N->getValue()==0xFF00FF00FF00FF00LL);
80 }]>;
81 def isMIX1Rable: PatLeaf<(i64 imm), [{
82   return((uint64_t)N->getValue()==0x00FF00FF00FF00FFLL);
83 }]>;
84 def isMIX2Lable: PatLeaf<(i64 imm), [{
85   return((uint64_t)N->getValue()==0xFFFF0000FFFF0000LL);
86 }]>;
87 def isMIX2Rable: PatLeaf<(i64 imm), [{
88   return((uint64_t)N->getValue()==0x0000FFFF0000FFFFLL);
89 }]>;
90 def isMIX4Lable: PatLeaf<(i64 imm), [{
91   return((uint64_t)N->getValue()==0xFFFFFFFF00000000LL);
92 }]>;
93 def isMIX4Rable: PatLeaf<(i64 imm), [{
94   return((uint64_t)N->getValue()==0x00000000FFFFFFFFLL);
95 }]>;
96
97 def isSHLADDimm: PatLeaf<(i64 imm), [{
98   // isSHLADDimm predicate - True if the immediate is exactly 1, 2, 3 or 4
99   // - 0 is *not* okay.
100   // Used to create shladd instructions appropriately
101   int64_t v = (int64_t)N->getValue();
102   return (v >= 1 && v <= 4);
103 }]>;
104
105 def immSExt14  : PatLeaf<(i64 imm), [{
106   // immSExt14 predicate - True if the immediate fits in a 14-bit sign extended
107   // field.  Used by instructions like 'adds'.
108   int64_t v = (int64_t)N->getValue();
109   return (v <= 8191 && v >= -8192);
110 }]>;
111
112 // imm64 predicate - True if the immediate fits in a 64-bit 
113 // field - i.e., true. used to keep movl happy
114 def imm64  : PatLeaf<(i64 imm)>; 
115
116 def ADD  : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src1, GR:$src2),
117            "add $dst = $src1, $src2",
118            [(set GR:$dst, (add GR:$src1, GR:$src2))]>, isA;
119
120 def ADD1 : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src1, GR:$src2),
121            "add $dst = $src1, $src2, 1",
122            [(set GR:$dst, (add (add GR:$src1, GR:$src2), 1))]>, isA;
123
124 def ADDS : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src1, s14imm:$imm),
125            "adds $dst = $imm, $src1",
126            [(set GR:$dst, (add GR:$src1, immSExt14:$imm))]>, isA;
127  
128 def MOVL : AForm_DAG<0x03, 0x0b, (ops GR:$dst, s64imm:$imm),
129            "movl $dst = $imm",
130            [(set GR:$dst, imm64:$imm)]>, isLX;
131
132 def ADDL_GA : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src1, globaladdress:$imm),
133            "addl $dst = $imm, $src1",
134            []>, isA;
135
136 // hmm 
137 def ADDL_EA : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src1, calltarget:$imm),
138            "addl $dst = $imm, $src1",
139            []>, isA;
140  
141 def SUB  : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src1, GR:$src2),
142            "sub $dst = $src1, $src2",
143            [(set GR:$dst, (sub GR:$src1, GR:$src2))]>, isA;
144
145 def SUB1 : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src1, GR:$src2),
146            "sub $dst = $src1, $src2, 1",
147            [(set GR:$dst, (add (sub GR: $src1, GR:$src2), -1))]>, isA;
148
149 let isTwoAddress = 1 in {
150 def TPCADDIMM22 : AForm<0x03, 0x0b,
151   (ops GR:$dst, GR:$src1, s22imm:$imm, PR:$qp),
152     "($qp) add $dst = $imm, $dst">, isA;
153 def TPCADDS : AForm_DAG<0x03, 0x0b,
154   (ops GR:$dst, GR:$src1, s14imm:$imm, PR:$qp),
155     "($qp) adds $dst = $imm, $dst",
156     []>, isA;
157 def TPCMPIMM8NE : AForm<0x03, 0x0b,
158   (ops PR:$dst, PR:$src1, s22imm:$imm, GR:$src2, PR:$qp),
159     "($qp) cmp.ne $dst , p0 = $imm, $src2">, isA;
160 }
161
162 // zero extend a bool (predicate reg) into an integer reg
163 def ZXTb : Pat<(zext PR:$src),
164           (TPCADDIMM22 (ADDS r0, 0), 1, PR:$src)>;
165
166 // normal sign/zero-extends
167 def SXT1 : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src), "sxt1 $dst = $src",
168            [(set GR:$dst, (sext_inreg GR:$src, i8))]>, isI;
169 def ZXT1 : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src), "zxt1 $dst = $src",
170            [(set GR:$dst, (and GR:$src, 255))]>, isI;
171 def SXT2 : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src), "sxt2 $dst = $src",
172            [(set GR:$dst, (sext_inreg GR:$src, i16))]>, isI;
173 def ZXT2 : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src), "zxt2 $dst = $src",
174            [(set GR:$dst, (and GR:$src, 65535))]>, isI;
175 def SXT4 : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src), "sxt4 $dst = $src",
176            [(set GR:$dst, (sext_inreg GR:$src, i32))]>, isI;
177 def ZXT4 : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src), "zxt4 $dst = $src",
178            [(set GR:$dst, (and GR:$src, is32ones))]>, isI;
179
180 // fixme: shrs vs shru?
181 def MIX1L : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src1, GR:$src2),
182           "mix1.l $dst = $src1, $src2",
183           [(set GR:$dst, (or (and GR:$src1, isMIX1Lable),
184                              (and (srl GR:$src2, (i64 8)), isMIX1Lable)))]>, isI;
185
186 def MIX2L : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src1, GR:$src2),
187           "mix2.l $dst = $src1, $src2",
188           [(set GR:$dst, (or (and GR:$src1, isMIX2Lable),
189                              (and (srl GR:$src2, (i64 16)), isMIX2Lable)))]>, isI;
190
191 def MIX4L : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src1, GR:$src2),
192           "mix4.l $dst = $src1, $src2",
193           [(set GR:$dst, (or (and GR:$src1, isMIX4Lable),
194                              (and (srl GR:$src2, (i64 32)), isMIX4Lable)))]>, isI;
195
196 def MIX1R : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src1, GR:$src2),
197           "mix1.r $dst = $src1, $src2",
198           [(set GR:$dst, (or (and (shl GR:$src1, (i64 8)), isMIX1Rable),
199                              (and GR:$src2, isMIX1Rable)))]>, isI;
200
201 def MIX2R : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src1, GR:$src2),
202           "mix2.r $dst = $src1, $src2",
203           [(set GR:$dst, (or (and (shl GR:$src1, (i64 16)), isMIX2Rable),
204                              (and GR:$src2, isMIX2Rable)))]>, isI;
205
206 def MIX4R : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src1, GR:$src2),
207           "mix4.r $dst = $src1, $src2",
208           [(set GR:$dst, (or (and (shl GR:$src1, (i64 32)), isMIX4Rable),
209                              (and GR:$src2, isMIX4Rable)))]>, isI;
210
211 def GETFSIGD : AForm_DAG<0x03, 0x0b, (ops GR:$dst, FP:$src),
212   "getf.sig $dst = $src",
213   []>, isM;
214
215 def SETFSIGD : AForm_DAG<0x03, 0x0b, (ops FP:$dst, GR:$src),
216   "setf.sig $dst = $src",
217   []>, isM;
218
219 def XMALD : AForm_DAG<0x03, 0x0b, (ops FP:$dst, FP:$src1, FP:$src2, FP:$src3),
220   "xma.l $dst = $src1, $src2, $src3",
221   []>, isF;
222 def XMAHD : AForm_DAG<0x03, 0x0b, (ops FP:$dst, FP:$src1, FP:$src2, FP:$src3),
223   "xma.h $dst = $src1, $src2, $src3",
224   []>, isF;
225 def XMAHUD : AForm_DAG<0x03, 0x0b, (ops FP:$dst, FP:$src1, FP:$src2, FP:$src3),
226   "xma.hu $dst = $src1, $src2, $src3",
227   []>, isF;
228
229 // pseudocode for integer multiplication 
230 def : Pat<(mul GR:$src1, GR:$src2),
231            (GETFSIGD (XMALD (SETFSIGD GR:$src1), (SETFSIGD GR:$src2), F0))>;
232 def : Pat<(mulhs GR:$src1, GR:$src2),
233            (GETFSIGD (XMAHD (SETFSIGD GR:$src1), (SETFSIGD GR:$src2), F0))>;
234 def : Pat<(mulhu GR:$src1, GR:$src2),
235            (GETFSIGD (XMAHUD (SETFSIGD GR:$src1), (SETFSIGD GR:$src2), F0))>;
236
237 // TODO: addp4 (addp4 dst = src, r0 is a 32-bit add)
238 // has imm form, too
239
240 // def ADDS : AForm<0x03, 0x0b, (ops GR:$dst, GR:$src1, s14imm:$imm),
241 //   "adds $dst = $imm, $src1">;
242
243 def AND   : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src1, GR:$src2),
244           "and $dst = $src1, $src2",
245           [(set GR:$dst, (and GR:$src1, GR:$src2))]>, isA;
246 def ANDCM : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src1, GR:$src2),
247           "andcm $dst = $src1, $src2",
248           [(set GR:$dst, (and GR:$src1, (not GR:$src2)))]>, isA;
249 // TODO: and/andcm/or/xor/add/sub/shift immediate forms
250 def OR    : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src1, GR:$src2),
251           "or $dst = $src1, $src2",
252           [(set GR:$dst, (or GR:$src1, GR:$src2))]>, isA;
253
254 def pOR   : AForm<0x03, 0x0b, (ops GR:$dst, GR:$src1, GR:$src2, PR:$qp),
255           "($qp) or $dst = $src1, $src2">, isA;
256
257 // the following are all a bit unfortunate: we throw away the complement
258 // of the compare!
259 def CMPEQ : AForm_DAG<0x03, 0x0b, (ops PR:$dst, GR:$src1, GR:$src2),
260           "cmp.eq $dst, p0 = $src1, $src2",
261           [(set PR:$dst, (seteq GR:$src1, GR:$src2))]>, isA;
262 def CMPGT : AForm_DAG<0x03, 0x0b, (ops PR:$dst, GR:$src1, GR:$src2),
263           "cmp.gt $dst, p0 = $src1, $src2",
264           [(set PR:$dst, (setgt GR:$src1, GR:$src2))]>, isA;
265 def CMPGE : AForm_DAG<0x03, 0x0b, (ops PR:$dst, GR:$src1, GR:$src2),
266           "cmp.ge $dst, p0 = $src1, $src2",
267           [(set PR:$dst, (setge GR:$src1, GR:$src2))]>, isA;
268 def CMPLT : AForm_DAG<0x03, 0x0b, (ops PR:$dst, GR:$src1, GR:$src2),
269           "cmp.lt $dst, p0 = $src1, $src2",
270           [(set PR:$dst, (setlt GR:$src1, GR:$src2))]>, isA;
271 def CMPLE : AForm_DAG<0x03, 0x0b, (ops PR:$dst, GR:$src1, GR:$src2),
272           "cmp.le $dst, p0 = $src1, $src2",
273           [(set PR:$dst, (setle GR:$src1, GR:$src2))]>, isA;
274 def CMPNE : AForm_DAG<0x03, 0x0b, (ops PR:$dst, GR:$src1, GR:$src2),
275           "cmp.ne $dst, p0 = $src1, $src2",
276           [(set PR:$dst, (setne GR:$src1, GR:$src2))]>, isA;
277 def CMPLTU: AForm_DAG<0x03, 0x0b, (ops PR:$dst, GR:$src1, GR:$src2),
278           "cmp.ltu $dst, p0 = $src1, $src2",
279           [(set PR:$dst, (setult GR:$src1, GR:$src2))]>, isA;
280 def CMPGTU: AForm_DAG<0x03, 0x0b, (ops PR:$dst, GR:$src1, GR:$src2),
281           "cmp.gtu $dst, p0 = $src1, $src2",
282           [(set PR:$dst, (setugt GR:$src1, GR:$src2))]>, isA;
283 def CMPLEU: AForm_DAG<0x03, 0x0b, (ops PR:$dst, GR:$src1, GR:$src2),
284           "cmp.leu $dst, p0 = $src1, $src2",
285           [(set PR:$dst, (setule GR:$src1, GR:$src2))]>, isA;
286 def CMPGEU: AForm_DAG<0x03, 0x0b, (ops PR:$dst, GR:$src1, GR:$src2),
287           "cmp.geu $dst, p0 = $src1, $src2",
288           [(set PR:$dst, (setuge GR:$src1, GR:$src2))]>, isA;
289
290 // and we do the whole thing again for FP compares!
291 def FCMPEQ : AForm_DAG<0x03, 0x0b, (ops PR:$dst, FP:$src1, FP:$src2),
292           "fcmp.eq $dst, p0 = $src1, $src2",
293           [(set PR:$dst, (seteq FP:$src1, FP:$src2))]>, isF;
294 def FCMPGT : AForm_DAG<0x03, 0x0b, (ops PR:$dst, FP:$src1, FP:$src2),
295           "fcmp.gt $dst, p0 = $src1, $src2",
296           [(set PR:$dst, (setgt FP:$src1, FP:$src2))]>, isF;
297 def FCMPGE : AForm_DAG<0x03, 0x0b, (ops PR:$dst, FP:$src1, FP:$src2),
298           "fcmp.ge $dst, p0 = $src1, $src2",
299           [(set PR:$dst, (setge FP:$src1, FP:$src2))]>, isF;
300 def FCMPLT : AForm_DAG<0x03, 0x0b, (ops PR:$dst, FP:$src1, FP:$src2),
301           "fcmp.lt $dst, p0 = $src1, $src2",
302           [(set PR:$dst, (setlt FP:$src1, FP:$src2))]>, isF;
303 def FCMPLE : AForm_DAG<0x03, 0x0b, (ops PR:$dst, FP:$src1, FP:$src2),
304           "fcmp.le $dst, p0 = $src1, $src2",
305           [(set PR:$dst, (setle FP:$src1, FP:$src2))]>, isF;
306 def FCMPNE : AForm_DAG<0x03, 0x0b, (ops PR:$dst, FP:$src1, FP:$src2),
307           "fcmp.neq $dst, p0 = $src1, $src2",
308           [(set PR:$dst, (setne FP:$src1, FP:$src2))]>, isF;
309 def FCMPLTU: AForm_DAG<0x03, 0x0b, (ops PR:$dst, FP:$src1, FP:$src2),
310           "fcmp.ltu $dst, p0 = $src1, $src2",
311           [(set PR:$dst, (setult FP:$src1, FP:$src2))]>, isF;
312 def FCMPGTU: AForm_DAG<0x03, 0x0b, (ops PR:$dst, FP:$src1, FP:$src2),
313           "fcmp.gtu $dst, p0 = $src1, $src2",
314           [(set PR:$dst, (setugt FP:$src1, FP:$src2))]>, isF;
315 def FCMPLEU: AForm_DAG<0x03, 0x0b, (ops PR:$dst, FP:$src1, FP:$src2),
316           "fcmp.leu $dst, p0 = $src1, $src2",
317           [(set PR:$dst, (setule FP:$src1, FP:$src2))]>, isF;
318 def FCMPGEU: AForm_DAG<0x03, 0x0b, (ops PR:$dst, FP:$src1, FP:$src2),
319           "fcmp.geu $dst, p0 = $src1, $src2",
320           [(set PR:$dst, (setuge FP:$src1, FP:$src2))]>, isF;
321
322 def PCMPEQUNCR0R0 : AForm<0x03, 0x0b, (ops PR:$dst, PR:$qp),
323     "($qp) cmp.eq.unc $dst, p0 = r0, r0">, isA;
324
325 def : Pat<(trunc GR:$src),  // truncate i64 to i1
326           (CMPNE GR:$src, r0)>; // $src!=0? If so, PR:$dst=true
327           
328 let isTwoAddress=1 in {
329   def TPCMPEQR0R0 : AForm<0x03, 0x0b, (ops PR:$dst, PR:$bogus, PR:$qp),
330     "($qp) cmp.eq $dst, p0 = r0, r0">, isA;
331   def TPCMPNER0R0 : AForm<0x03, 0x0b, (ops PR:$dst, PR:$bogus, PR:$qp),
332     "($qp) cmp.ne $dst, p0 = r0, r0">, isA;
333 }
334
335 /* our pseudocode for OR on predicates is:
336 pC = pA OR pB
337 -------------
338 (pA) cmp.eq.unc pC,p0 = r0,r0  // pC = pA
339  ;;
340 (pB) cmp.eq pC,p0 = r0,r0 // if (pB) pC = 1 */
341
342 def bOR   : Pat<(or PR:$src1, PR:$src2),
343           (TPCMPEQR0R0 (PCMPEQUNCR0R0 PR:$src1), PR:$src2)>;
344
345 /* our pseudocode for AND on predicates is:
346  *
347 (pA) cmp.eq.unc pC,p0 = r0,r0   // pC = pA
348      cmp.eq pTemp,p0 = r0,r0    // pTemp = NOT pB
349      ;;
350 (pB) cmp.ne pTemp,p0 = r0,r0
351      ;;
352 (pTemp)cmp.ne pC,p0 = r0,r0    // if (NOT pB) pC = 0  */
353
354 def bAND  : Pat<(and PR:$src1, PR:$src2),
355           ( TPCMPNER0R0 (PCMPEQUNCR0R0 PR:$src1),
356             (TPCMPNER0R0 (CMPEQ r0, r0), PR:$src2) )>;
357
358 /* one possible routine for XOR on predicates is:
359
360       // Compute px = py ^ pz
361         // using sum of products: px = (py & !pz) | (pz & !py)
362         // Uses 5 instructions in 3 cycles.
363         // cycle 1
364 (pz)    cmp.eq.unc      px = r0, r0     // px = pz
365 (py)    cmp.eq.unc      pt = r0, r0     // pt = py
366         ;;
367         // cycle 2
368 (pt)    cmp.ne.and      px = r0, r0     // px = px & !pt (px = pz & !pt)
369 (pz)    cmp.ne.and      pt = r0, r0     // pt = pt & !pz
370         ;;
371         } { .mmi
372         // cycle 3
373 (pt)    cmp.eq.or       px = r0, r0     // px = px | pt
374
375 *** Another, which we use here, requires one scratch GR. it is:
376
377         mov             rt = 0          // initialize rt off critical path
378         ;;
379
380         // cycle 1
381 (pz)    cmp.eq.unc      px = r0, r0     // px = pz
382 (pz)    mov             rt = 1          // rt = pz
383         ;;
384         // cycle 2
385 (py)    cmp.ne          px = 1, rt      // if (py) px = !pz
386
387 .. these routines kindly provided by Jim Hull
388 */
389   
390 def bXOR  : Pat<(xor PR:$src1, PR:$src2),
391           (TPCMPIMM8NE (PCMPEQUNCR0R0 PR:$src2), 1,
392                        (TPCADDS (ADDS r0, 0), 1, PR:$src2),
393                         PR:$src1)>;
394
395 def XOR   : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src1, GR:$src2),
396           "xor $dst = $src1, $src2",
397           [(set GR:$dst, (xor GR:$src1, GR:$src2))]>, isA;
398
399 def SHLADD: AForm_DAG<0x03, 0x0b, (ops GR:$dst,GR:$src1,s64imm:$imm,GR:$src2),
400           "shladd $dst = $src1, $imm, $src2",
401           [(set GR:$dst, (add GR:$src2, (shl GR:$src1, isSHLADDimm:$imm)))]>, isA;
402
403 def SHL   : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src1, GR:$src2),
404           "shl $dst = $src1, $src2",
405           [(set GR:$dst, (shl GR:$src1, GR:$src2))]>, isI;
406
407 def SHRU  : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src1, GR:$src2),
408           "shr.u $dst = $src1, $src2",
409           [(set GR:$dst, (srl GR:$src1, GR:$src2))]>, isI;
410
411 def SHRS  : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src1, GR:$src2),
412           "shr $dst = $src1, $src2",
413           [(set GR:$dst, (sra GR:$src1, GR:$src2))]>, isI;
414
415 def MOV : AForm<0x03, 0x0b, (ops GR:$dst, GR:$src), "mov $dst = $src">, isA;
416 def FMOV : AForm<0x03, 0x0b, (ops FP:$dst, FP:$src),
417   "mov $dst = $src">, isF; // XXX: there _is_ no fmov
418 def PMOV : AForm<0x03, 0x0b, (ops GR:$dst, GR:$src, PR:$qp),
419   "($qp) mov $dst = $src">, isA;
420
421 def SPILL_ALL_PREDICATES_TO_GR : AForm<0x03, 0x0b, (ops GR:$dst),
422   "mov $dst = pr">, isI;
423 def FILL_ALL_PREDICATES_FROM_GR : AForm<0x03, 0x0b, (ops GR:$src),
424   "mov pr = $src">, isI;
425
426 let isTwoAddress = 1 in {
427   def CMOV : AForm<0x03, 0x0b, (ops GR:$dst, GR:$src2, GR:$src, PR:$qp),
428     "($qp) mov $dst = $src">, isA;
429 }
430
431 def PFMOV : AForm<0x03, 0x0b, (ops FP:$dst, FP:$src, PR:$qp),
432   "($qp) mov $dst = $src">, isF;
433
434 let isTwoAddress = 1 in {
435   def CFMOV : AForm<0x03, 0x0b, (ops FP:$dst, FP:$src2, FP:$src, PR:$qp),
436     "($qp) mov $dst = $src">, isF;
437 }
438
439 def SELECTINT : Pat<(select PR:$which, GR:$src1, GR:$src2),
440           (CMOV (MOV GR:$src2), GR:$src1, PR:$which)>; // note order!
441 def SELECTFP : Pat<(select PR:$which, FP:$src1, FP:$src2),
442           (CFMOV (FMOV FP:$src2), FP:$src1, PR:$which)>; // note order!
443 // TODO: can do this faster, w/o using any integer regs (see pattern isel)
444 def SELECTBOOL : Pat<(select PR:$which, PR:$src1, PR:$src2), // note order!
445           (CMPNE (CMOV
446             (MOV (TPCADDIMM22 (ADDS r0, 0), 1, PR:$src2)),
447             (TPCADDIMM22 (ADDS r0, 0), 1, PR:$src1), PR:$which), r0)>;
448
449 // load constants of various sizes // FIXME: prettyprint -ve constants
450 def : Pat<(i64 immSExt14:$imm), (ADDS r0, immSExt14:$imm)>;
451 def : Pat<(i64 imm64:$imm), (MOVL imm64:$imm)>;
452 def : Pat<(i1 -1), (CMPEQ r0, r0)>; // TODO: this should just be a ref to p0
453 def : Pat<(i1  0), (CMPNE r0, r0)>; // TODO: any instruction actually *using*
454                                     //       this predicate should be killed!
455
456 // TODO: support postincrement (reg, imm9) loads+stores - this needs more
457 // tablegen support
458
459 def IDEF : PseudoInstIA64<(ops variable_ops), "// IDEF">;
460
461 def IDEF_GR_D : PseudoInstIA64_DAG<(ops GR:$reg), "// $reg = IDEF",
462     [(set GR:$reg, (undef))]>;
463 def IDEF_FP_D : PseudoInstIA64_DAG<(ops FP:$reg), "// $reg = IDEF",
464     [(set FP:$reg, (undef))]>;
465 def IDEF_PR_D : PseudoInstIA64_DAG<(ops PR:$reg), "// $reg = IDEF",
466     [(set PR:$reg, (undef))]>;
467
468 def IUSE : PseudoInstIA64<(ops variable_ops), "// IUSE">;
469 def ADJUSTCALLSTACKUP : PseudoInstIA64<(ops variable_ops),
470                                         "// ADJUSTCALLSTACKUP">;
471 def ADJUSTCALLSTACKDOWN : PseudoInstIA64<(ops variable_ops),
472                                          "// ADJUSTCALLSTACKDOWN">;
473 def PSEUDO_ALLOC : PseudoInstIA64<(ops GR:$foo), "// PSEUDO_ALLOC">;
474
475 def ALLOC : AForm<0x03, 0x0b,
476   (ops GR:$dst, i8imm:$inputs, i8imm:$locals, i8imm:$outputs, i8imm:$rotating),
477     "alloc $dst = ar.pfs,$inputs,$locals,$outputs,$rotating">, isM;
478
479 let isTwoAddress = 1 in {
480   def TCMPNE : AForm<0x03, 0x0b,
481   (ops PR:$dst, PR:$src2, GR:$src3, GR:$src4),
482     "cmp.ne $dst, p0 = $src3, $src4">, isA;
483   
484   def TPCMPEQOR : AForm<0x03, 0x0b,
485   (ops PR:$dst, PR:$src2, GR:$src3, GR:$src4, PR:$qp),
486     "($qp) cmp.eq.or $dst, p0 = $src3, $src4">, isA;
487   
488   def TPCMPNE : AForm<0x03, 0x0b,
489   (ops PR:$dst, PR:$src2, GR:$src3, GR:$src4, PR:$qp),
490     "($qp) cmp.ne $dst, p0 = $src3, $src4">, isA;
491   
492   def TPCMPEQ : AForm<0x03, 0x0b,
493   (ops PR:$dst, PR:$src2, GR:$src3, GR:$src4, PR:$qp),
494     "($qp) cmp.eq $dst, p0 = $src3, $src4">, isA;
495 }
496
497 def MOVSIMM14 : AForm<0x03, 0x0b, (ops GR:$dst, s14imm:$imm),
498   "mov $dst = $imm">, isA;
499 def MOVSIMM22 : AForm<0x03, 0x0b, (ops GR:$dst, s22imm:$imm),
500   "mov $dst = $imm">, isA;
501 def MOVLIMM64 : AForm<0x03, 0x0b, (ops GR:$dst, s64imm:$imm),
502   "movl $dst = $imm">, isLX;
503
504 def SHLI : AForm<0x03, 0x0b, (ops GR:$dst, GR:$src1, u6imm:$imm), 
505   "shl $dst = $src1, $imm">, isI;
506 def SHRUI : AForm<0x03, 0x0b, (ops GR:$dst, GR:$src1, u6imm:$imm),
507   "shr.u $dst = $src1, $imm">, isI;
508 def SHRSI : AForm<0x03, 0x0b, (ops GR:$dst, GR:$src1, u6imm:$imm),
509   "shr $dst = $src1, $imm">, isI;
510
511 def EXTRU : AForm<0x03, 0x0b,
512   (ops GR:$dst, GR:$src1, u6imm:$imm1, u6imm:$imm2),
513   "extr.u $dst = $src1, $imm1, $imm2">, isI;
514
515 def DEPZ : AForm<0x03, 0x0b,
516   (ops GR:$dst, GR:$src1, u6imm:$imm1, u6imm:$imm2),
517   "dep.z $dst = $src1, $imm1, $imm2">, isI;
518
519 def PCMPEQOR : AForm<0x03, 0x0b, (ops PR:$dst, GR:$src1, GR:$src2, PR:$qp),
520   "($qp) cmp.eq.or $dst, p0 = $src1, $src2">, isA;
521 def PCMPEQUNC : AForm<0x03, 0x0b, (ops PR:$dst, GR:$src1, GR:$src2, PR:$qp),
522   "($qp) cmp.eq.unc $dst, p0 = $src1, $src2">, isA;
523 def PCMPNE : AForm<0x03, 0x0b, (ops PR:$dst, GR:$src1, GR:$src2, PR:$qp),
524   "($qp) cmp.ne $dst, p0 = $src1, $src2">, isA;
525
526 // two destinations! 
527 def BCMPEQ : AForm<0x03, 0x0b, (ops PR:$dst1, PR:$dst2, GR:$src1, GR:$src2),
528   "cmp.eq $dst1, dst2 = $src1, $src2">, isA;
529
530 def ADDIMM14 : AForm<0x03, 0x0b, (ops GR:$dst, GR:$src1, s14imm:$imm),
531   "adds $dst = $imm, $src1">, isA;
532
533 def ADDIMM22 : AForm<0x03, 0x0b, (ops GR:$dst, GR:$src1, s22imm:$imm),
534   "add $dst = $imm, $src1">, isA;
535 def CADDIMM22 : AForm<0x03, 0x0b, (ops GR:$dst, GR:$src1, s22imm:$imm, PR:$qp),
536   "($qp) add $dst = $imm, $src1">, isA;
537
538 def SUBIMM8 : AForm<0x03, 0x0b, (ops GR:$dst, s8imm:$imm, GR:$src2),
539   "sub $dst = $imm, $src2">, isA;
540
541 let isStore = 1, noResults = 1 in {
542   def ST1 : AForm<0x03, 0x0b, (ops GR:$dstPtr, GR:$value),
543     "st1 [$dstPtr] = $value">, isM;
544   def ST2 : AForm<0x03, 0x0b, (ops GR:$dstPtr, GR:$value),
545     "st2 [$dstPtr] = $value">, isM;
546   def ST4 : AForm<0x03, 0x0b, (ops GR:$dstPtr, GR:$value),
547     "st4 [$dstPtr] = $value">, isM;
548   def ST8 : AForm<0x03, 0x0b, (ops GR:$dstPtr, GR:$value),
549     "st8 [$dstPtr] = $value">, isM;
550   def STF4 : AForm<0x03, 0x0b, (ops GR:$dstPtr, FP:$value),
551     "stfs [$dstPtr] = $value">, isM;
552   def STF8 : AForm<0x03, 0x0b, (ops GR:$dstPtr, FP:$value),
553     "stfd [$dstPtr] = $value">, isM;
554   def STF_SPILL : AForm<0x03, 0x0b, (ops GR:$dstPtr, FP:$value),
555     "stf.spill [$dstPtr] = $value">, isM;
556 }
557
558 let isLoad = 1 in {
559   def LD1 : AForm<0x03, 0x0b, (ops GR:$dst, GR:$srcPtr),
560     "ld1 $dst = [$srcPtr]">, isM;
561   def LD2 : AForm<0x03, 0x0b, (ops GR:$dst, GR:$srcPtr),
562     "ld2 $dst = [$srcPtr]">, isM;
563   def LD4 : AForm<0x03, 0x0b, (ops GR:$dst, GR:$srcPtr),
564     "ld4 $dst = [$srcPtr]">, isM;
565   def LD8 : AForm<0x03, 0x0b, (ops GR:$dst, GR:$srcPtr),
566     "ld8 $dst = [$srcPtr]">, isM;
567   def LDF4 : AForm<0x03, 0x0b, (ops FP:$dst, GR:$srcPtr),
568     "ldfs $dst = [$srcPtr]">, isM;
569   def LDF8 : AForm<0x03, 0x0b, (ops FP:$dst, GR:$srcPtr),
570     "ldfd $dst = [$srcPtr]">, isM;
571   def LDF_FILL : AForm<0x03, 0x0b, (ops FP:$dst, GR:$srcPtr),
572     "ldf.fill $dst = [$srcPtr]">, isM;
573 }
574
575 def POPCNT : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src),
576   "popcnt $dst = $src",
577   [(set GR:$dst, (ctpop GR:$src))]>, isI;
578
579 // some FP stuff:  // TODO: single-precision stuff?
580 def FADD : AForm_DAG<0x03, 0x0b, (ops FP:$dst, FP:$src1, FP:$src2),
581   "fadd $dst = $src1, $src2",
582   [(set FP:$dst, (fadd FP:$src1, FP:$src2))]>, isF;
583 def FADDS: AForm<0x03, 0x0b, (ops FP:$dst, FP:$src1, FP:$src2),
584   "fadd.s $dst = $src1, $src2">, isF;
585 def FSUB : AForm_DAG<0x03, 0x0b, (ops FP:$dst, FP:$src1, FP:$src2),
586   "fsub $dst = $src1, $src2",
587   [(set FP:$dst, (fsub FP:$src1, FP:$src2))]>, isF;
588 def FMPY : AForm_DAG<0x03, 0x0b, (ops FP:$dst, FP:$src1, FP:$src2),
589   "fmpy $dst = $src1, $src2",
590   [(set FP:$dst, (fmul FP:$src1, FP:$src2))]>, isF;
591 def FMA : AForm_DAG<0x03, 0x0b, (ops FP:$dst, FP:$src1, FP:$src2, FP:$src3),
592   "fma $dst = $src1, $src2, $src3",
593   [(set FP:$dst, (fadd (fmul FP:$src1, FP:$src2), FP:$src3))]>, isF;
594 def FMS : AForm_DAG<0x03, 0x0b, (ops FP:$dst, FP:$src1, FP:$src2, FP:$src3),
595   "fms $dst = $src1, $src2, $src3",
596   [(set FP:$dst, (fsub (fmul FP:$src1, FP:$src2), FP:$src3))]>, isF;
597 def FNMA : AForm_DAG<0x03, 0x0b, (ops FP:$dst, FP:$src1, FP:$src2, FP:$src3),
598   "fnma $dst = $src1, $src2, $src3",
599   [(set FP:$dst, (fneg (fadd (fmul FP:$src1, FP:$src2), FP:$src3)))]>, isF;
600 def FABS : AForm_DAG<0x03, 0x0b, (ops FP:$dst, FP:$src),
601   "fabs $dst = $src",
602   [(set FP:$dst, (fabs FP:$src))]>, isF;
603 def FNEG : AForm_DAG<0x03, 0x0b, (ops FP:$dst, FP:$src),
604   "fneg $dst = $src",
605   [(set FP:$dst, (fneg FP:$src))]>, isF;
606 def FNEGABS : AForm_DAG<0x03, 0x0b, (ops FP:$dst, FP:$src),
607   "fnegabs $dst = $src",
608   [(set FP:$dst, (fneg (fabs FP:$src)))]>, isF;
609
610 let isTwoAddress=1 in {
611 def TCFMAS1 : AForm<0x03, 0x0b,
612   (ops FP:$dst, FP:$bogussrc, FP:$src1, FP:$src2, FP:$src3, PR:$qp),
613     "($qp) fma.s1 $dst = $src1, $src2, $src3">, isF;
614 def TCFMADS0 : AForm<0x03, 0x0b,
615   (ops FP:$dst, FP:$bogussrc, FP:$src1, FP:$src2, FP:$src3, PR:$qp),
616     "($qp) fma.d.s0 $dst = $src1, $src2, $src3">, isF;
617 }
618
619 def CFMAS1 : AForm<0x03, 0x0b,
620   (ops FP:$dst, FP:$src1, FP:$src2, FP:$src3, PR:$qp),
621     "($qp) fma.s1 $dst = $src1, $src2, $src3">, isF;
622 def CFNMAS1 : AForm<0x03, 0x0b,
623   (ops FP:$dst, FP:$src1, FP:$src2, FP:$src3, PR:$qp),
624     "($qp) fnma.s1 $dst = $src1, $src2, $src3">, isF;
625
626 def CFMADS1 : AForm<0x03, 0x0b,
627   (ops FP:$dst, FP:$src1, FP:$src2, FP:$src3, PR:$qp),
628     "($qp) fma.d.s1 $dst = $src1, $src2, $src3">, isF;
629 def CFMADS0 : AForm<0x03, 0x0b,
630   (ops FP:$dst, FP:$src1, FP:$src2, FP:$src3, PR:$qp),
631     "($qp) fma.d.s0 $dst = $src1, $src2, $src3">, isF;
632 def CFNMADS1 : AForm<0x03, 0x0b,
633   (ops FP:$dst, FP:$src1, FP:$src2, FP:$src3, PR:$qp),
634     "($qp) fnma.d.s1 $dst = $src1, $src2, $src3">, isF;
635
636 def FRCPAS0 : AForm<0x03, 0x0b, (ops FP:$dstFR, PR:$dstPR, FP:$src1, FP:$src2),
637   "frcpa.s0 $dstFR, $dstPR = $src1, $src2">, isF;
638 def FRCPAS1 : AForm<0x03, 0x0b, (ops FP:$dstFR, PR:$dstPR, FP:$src1, FP:$src2),
639   "frcpa.s1 $dstFR, $dstPR = $src1, $src2">, isF;
640
641 def XMAL : AForm<0x03, 0x0b, (ops FP:$dst, FP:$src1, FP:$src2, FP:$src3),
642   "xma.l $dst = $src1, $src2, $src3">, isF;
643
644 def FCVTXF : AForm<0x03, 0x0b, (ops FP:$dst, FP:$src),
645   "fcvt.xf $dst = $src">, isF;
646 def FCVTXUF : AForm<0x03, 0x0b, (ops FP:$dst, FP:$src),
647   "fcvt.xuf $dst = $src">, isF;
648 def FCVTXUFS1 : AForm<0x03, 0x0b, (ops FP:$dst, FP:$src),
649   "fcvt.xuf.s1 $dst = $src">, isF;
650 def FCVTFX : AForm<0x03, 0x0b, (ops FP:$dst, FP:$src),
651   "fcvt.fx $dst = $src">, isF;
652 def FCVTFXU : AForm<0x03, 0x0b, (ops FP:$dst, FP:$src),
653   "fcvt.fxu $dst = $src">, isF;
654
655 def FCVTFXTRUNC : AForm<0x03, 0x0b, (ops FP:$dst, FP:$src),
656   "fcvt.fx.trunc $dst = $src">, isF;
657 def FCVTFXUTRUNC : AForm<0x03, 0x0b, (ops FP:$dst, FP:$src),
658   "fcvt.fxu.trunc $dst = $src">, isF;
659
660 def FCVTFXTRUNCS1 : AForm<0x03, 0x0b, (ops FP:$dst, FP:$src),
661   "fcvt.fx.trunc.s1 $dst = $src">, isF;
662 def FCVTFXUTRUNCS1 : AForm<0x03, 0x0b, (ops FP:$dst, FP:$src),
663   "fcvt.fxu.trunc.s1 $dst = $src">, isF;
664
665 def FNORMD : AForm<0x03, 0x0b, (ops FP:$dst, FP:$src),
666   "fnorm.d $dst = $src">, isF;
667
668 def GETFD : AForm<0x03, 0x0b, (ops GR:$dst, FP:$src),
669   "getf.d $dst = $src">, isM;
670 def SETFD : AForm<0x03, 0x0b, (ops FP:$dst, GR:$src),
671   "setf.d $dst = $src">, isM;
672
673 def GETFSIG : AForm<0x03, 0x0b, (ops GR:$dst, FP:$src),
674   "getf.sig $dst = $src">, isM;
675 def SETFSIG : AForm<0x03, 0x0b, (ops FP:$dst, GR:$src),
676   "setf.sig $dst = $src">, isM;
677
678 // these four FP<->int conversion patterns need checking/cleaning
679 def SINT_TO_FP : Pat<(sint_to_fp GR:$src),
680   (FNORMD (FCVTXF (SETFSIG GR:$src)))>;
681 def UINT_TO_FP : Pat<(uint_to_fp GR:$src),
682   (FNORMD (FCVTXUF (SETFSIG GR:$src)))>;
683 def FP_TO_SINT : Pat<(i64 (fp_to_sint FP:$src)),
684   (GETFSIG (FCVTFXTRUNC FP:$src))>;
685 def FP_TO_UINT : Pat<(i64 (fp_to_uint FP:$src)),
686   (GETFSIG (FCVTFXUTRUNC FP:$src))>;
687
688
689 let isTerminator = 1, isBranch = 1, noResults = 1 in {
690   def BRL_NOTCALL : RawForm<0x03, 0xb0, (ops i64imm:$dst),
691     "(p0) brl.cond.sptk $dst">, isB;
692   def BRLCOND_NOTCALL : RawForm<0x03, 0xb0, (ops PR:$qp, i64imm:$dst),
693     "($qp) brl.cond.sptk $dst">, isB;
694   def BRCOND_NOTCALL : RawForm<0x03, 0xb0, (ops PR:$qp, GR:$dst),
695     "($qp) br.cond.sptk $dst">, isB;
696 }
697
698 let isCall = 1, noResults = 1, /* isTerminator = 1, isBranch = 1, */
699   Uses = [out0,out1,out2,out3,out4,out5,out6,out7],
700 // all calls clobber non-callee-saved registers, and for now, they are these:
701   Defs = [r2,r3,r8,r9,r10,r11,r14,r15,r16,r17,r18,r19,r20,r21,r22,r23,r24,
702   r25,r26,r27,r28,r29,r30,r31,
703   p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,
704   F6,F7,F8,F9,F10,F11,F12,F13,F14,F15,
705   F32,F33,F34,F35,F36,F37,F38,F39,F40,F41,F42,F43,F44,F45,F46,F47,F48,F49,
706   F50,F51,F52,F53,F54,F55,F56,
707   F57,F58,F59,F60,F61,F62,F63,F64,F65,F66,F67,F68,F69,F70,F71,F72,F73,F74,
708   F75,F76,F77,F78,F79,F80,F81,
709   F82,F83,F84,F85,F86,F87,F88,F89,F90,F91,F92,F93,F94,F95,F96,F97,F98,F99,
710   F100,F101,F102,F103,F104,F105,
711   F106,F107,F108,F109,F110,F111,F112,F113,F114,F115,F116,F117,F118,F119,
712   F120,F121,F122,F123,F124,F125,F126,F127,
713   out0,out1,out2,out3,out4,out5,out6,out7] in {
714 // old pattern call
715   def BRCALL: RawForm<0x03, 0xb0, (ops calltarget:$dst),
716   "br.call.sptk rp = $dst">, isB;   // FIXME: teach llvm about branch regs?
717 // new daggy stuff!  
718
719 // calls a globaladdress
720   def BRCALL_IPREL_GA : RawForm<0x03, 0xb0, (ops calltarget:$dst),
721   "br.call.sptk rp = $dst">, isB;       // FIXME: teach llvm about branch regs?
722 // calls an externalsymbol
723   def BRCALL_IPREL_ES : RawForm<0x03, 0xb0, (ops calltarget:$dst),
724   "br.call.sptk rp = $dst">, isB;       // FIXME: teach llvm about branch regs?
725 // calls through a function descriptor
726   def BRCALL_INDIRECT : RawForm<0x03, 0xb0, (ops GR:$branchreg),
727   "br.call.sptk rp = $branchreg">, isB; // FIXME: teach llvm about branch regs?
728   def BRLCOND_CALL : RawForm<0x03, 0xb0, (ops PR:$qp, i64imm:$dst),
729     "($qp) brl.cond.call.sptk $dst">, isB;
730   def BRCOND_CALL : RawForm<0x03, 0xb0, (ops PR:$qp, GR:$dst),
731     "($qp) br.cond.call.sptk $dst">, isB;
732 }
733
734 // Return branch:
735 let isTerminator = 1, isReturn = 1, noResults = 1 in
736   def RET : AForm_DAG<0x03, 0x0b, (ops),
737             "br.ret.sptk.many rp",
738             [(retflag)]>, isB; // return
739 def : Pat<(ret), (RET)>;
740
741 // the evil stop bit of despair
742 def STOP : PseudoInstIA64<(ops variable_ops), ";;">;
743