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