]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/blob - contrib/llvm/lib/Target/PTX/PTXInstrInfo.td
Copy head to stable/9 as part of 9.0-RELEASE release cycle.
[FreeBSD/stable/9.git] / contrib / llvm / lib / Target / PTX / PTXInstrInfo.td
1 //===- PTXInstrInfo.td - PTX Instruction defs -----------------*- tblgen-*-===//
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 PTX instructions in TableGen format.
11 //
12 //===----------------------------------------------------------------------===//
13
14 //===----------------------------------------------------------------------===//
15 // Instruction format superclass
16 //===----------------------------------------------------------------------===//
17
18 include "PTXInstrFormats.td"
19
20 //===----------------------------------------------------------------------===//
21 // Code Generation Predicates
22 //===----------------------------------------------------------------------===//
23
24 // Addressing
25 def Use32BitAddresses : Predicate<"!getSubtarget().is64Bit()">;
26 def Use64BitAddresses : Predicate<"getSubtarget().is64Bit()">;
27
28 // Shader Model Support
29 def FDivNeedsRoundingMode : Predicate<"getSubtarget().fdivNeedsRoundingMode()">;
30 def FDivNoRoundingMode : Predicate<"!getSubtarget().fdivNeedsRoundingMode()">;
31 def FMadNeedsRoundingMode : Predicate<"getSubtarget().fmadNeedsRoundingMode()">;
32 def FMadNoRoundingMode : Predicate<"!getSubtarget().fmadNeedsRoundingMode()">;
33
34 // PTX Version Support
35 def SupportsPTX21       : Predicate<"getSubtarget().supportsPTX21()">;
36 def DoesNotSupportPTX21 : Predicate<"!getSubtarget().supportsPTX21()">;
37 def SupportsPTX22       : Predicate<"getSubtarget().supportsPTX22()">;
38 def DoesNotSupportPTX22 : Predicate<"!getSubtarget().supportsPTX22()">;
39 def SupportsPTX23       : Predicate<"getSubtarget().supportsPTX23()">;
40 def DoesNotSupportPTX23 : Predicate<"!getSubtarget().supportsPTX23()">;
41
42 // Fused-Multiply Add
43 def SupportsFMA         : Predicate<"getSubtarget().supportsFMA()">;
44 def DoesNotSupportFMA   : Predicate<"!getSubtarget().supportsFMA()">;
45
46 //===----------------------------------------------------------------------===//
47 // Instruction Pattern Stuff
48 //===----------------------------------------------------------------------===//
49
50 def load_global : PatFrag<(ops node:$ptr), (load node:$ptr), [{
51   const Value *Src;
52   const PointerType *PT;
53   if ((Src = cast<LoadSDNode>(N)->getSrcValue()) &&
54       (PT = dyn_cast<PointerType>(Src->getType())))
55     return PT->getAddressSpace() == PTX::GLOBAL;
56   return false;
57 }]>;
58
59 def load_constant : PatFrag<(ops node:$ptr), (load node:$ptr), [{
60   const Value *Src;
61   const PointerType *PT;
62   if ((Src = cast<LoadSDNode>(N)->getSrcValue()) &&
63       (PT = dyn_cast<PointerType>(Src->getType())))
64     return PT->getAddressSpace() == PTX::CONSTANT;
65   return false;
66 }]>;
67
68 def load_local : PatFrag<(ops node:$ptr), (load node:$ptr), [{
69   const Value *Src;
70   const PointerType *PT;
71   if ((Src = cast<LoadSDNode>(N)->getSrcValue()) &&
72       (PT = dyn_cast<PointerType>(Src->getType())))
73     return PT->getAddressSpace() == PTX::LOCAL;
74   return false;
75 }]>;
76
77 def load_parameter : PatFrag<(ops node:$ptr), (load node:$ptr), [{
78   const Value *Src;
79   const PointerType *PT;
80   if ((Src = cast<LoadSDNode>(N)->getSrcValue()) &&
81       (PT = dyn_cast<PointerType>(Src->getType())))
82     return PT->getAddressSpace() == PTX::PARAMETER;
83   return false;
84 }]>;
85
86 def load_shared : PatFrag<(ops node:$ptr), (load node:$ptr), [{
87   const Value *Src;
88   const PointerType *PT;
89   if ((Src = cast<LoadSDNode>(N)->getSrcValue()) &&
90       (PT = dyn_cast<PointerType>(Src->getType())))
91     return PT->getAddressSpace() == PTX::SHARED;
92   return false;
93 }]>;
94
95 def store_global
96   : PatFrag<(ops node:$d, node:$ptr), (store node:$d, node:$ptr), [{
97   const Value *Src;
98   const PointerType *PT;
99   if ((Src = cast<StoreSDNode>(N)->getSrcValue()) &&
100       (PT = dyn_cast<PointerType>(Src->getType())))
101     return PT->getAddressSpace() == PTX::GLOBAL;
102   return false;
103 }]>;
104
105 def store_local
106   : PatFrag<(ops node:$d, node:$ptr), (store node:$d, node:$ptr), [{
107   const Value *Src;
108   const PointerType *PT;
109   if ((Src = cast<StoreSDNode>(N)->getSrcValue()) &&
110       (PT = dyn_cast<PointerType>(Src->getType())))
111     return PT->getAddressSpace() == PTX::LOCAL;
112   return false;
113 }]>;
114
115 def store_parameter
116   : PatFrag<(ops node:$d, node:$ptr), (store node:$d, node:$ptr), [{
117   const Value *Src;
118   const PointerType *PT;
119   if ((Src = cast<StoreSDNode>(N)->getSrcValue()) &&
120       (PT = dyn_cast<PointerType>(Src->getType())))
121     return PT->getAddressSpace() == PTX::PARAMETER;
122   return false;
123 }]>;
124
125 def store_shared
126   : PatFrag<(ops node:$d, node:$ptr), (store node:$d, node:$ptr), [{
127   const Value *Src;
128   const PointerType *PT;
129   if ((Src = cast<StoreSDNode>(N)->getSrcValue()) &&
130       (PT = dyn_cast<PointerType>(Src->getType())))
131     return PT->getAddressSpace() == PTX::SHARED;
132   return false;
133 }]>;
134
135 // Addressing modes.
136 def ADDRrr32 : ComplexPattern<i32, 2, "SelectADDRrr", [], []>;
137 def ADDRrr64 : ComplexPattern<i64, 2, "SelectADDRrr", [], []>;
138 def ADDRri32 : ComplexPattern<i32, 2, "SelectADDRri", [], []>;
139 def ADDRri64 : ComplexPattern<i64, 2, "SelectADDRri", [], []>;
140 def ADDRii32 : ComplexPattern<i32, 2, "SelectADDRii", [], []>;
141 def ADDRii64 : ComplexPattern<i64, 2, "SelectADDRii", [], []>;
142
143 // Address operands
144 def MEMri32 : Operand<i32> {
145   let PrintMethod = "printMemOperand";
146   let MIOperandInfo = (ops RegI32, i32imm);
147 }
148 def MEMri64 : Operand<i64> {
149   let PrintMethod = "printMemOperand";
150   let MIOperandInfo = (ops RegI64, i64imm);
151 }
152 def MEMii32 : Operand<i32> {
153   let PrintMethod = "printMemOperand";
154   let MIOperandInfo = (ops i32imm, i32imm);
155 }
156 def MEMii64 : Operand<i64> {
157   let PrintMethod = "printMemOperand";
158   let MIOperandInfo = (ops i64imm, i64imm);
159 }
160 // The operand here does not correspond to an actual address, so we
161 // can use i32 in 64-bit address modes.
162 def MEMpi : Operand<i32> {
163   let PrintMethod = "printParamOperand";
164   let MIOperandInfo = (ops i32imm);
165 }
166 def MEMret : Operand<i32> {
167   let PrintMethod = "printReturnOperand";
168   let MIOperandInfo = (ops i32imm);
169 }
170
171 // Branch & call targets have OtherVT type.
172 def brtarget   : Operand<OtherVT>;
173 def calltarget : Operand<i32>;
174
175 //===----------------------------------------------------------------------===//
176 // PTX Specific Node Definitions
177 //===----------------------------------------------------------------------===//
178
179 // PTX allow generic 3-reg shifts like shl r0, r1, r2
180 def PTXshl : SDNode<"ISD::SHL", SDTIntBinOp>;
181 def PTXsrl : SDNode<"ISD::SRL", SDTIntBinOp>;
182 def PTXsra : SDNode<"ISD::SRA", SDTIntBinOp>;
183
184 def PTXexit
185   : SDNode<"PTXISD::EXIT", SDTNone, [SDNPHasChain]>;
186 def PTXret
187   : SDNode<"PTXISD::RET",  SDTNone,
188            [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>;
189 def PTXcopyaddress
190   : SDNode<"PTXISD::COPY_ADDRESS", SDTypeProfile<1, 1, []>, []>;
191
192 // Load/store .param space
193 def PTXloadparam
194   : SDNode<"PTXISD::LOAD_PARAM", SDTypeProfile<1, 1, [SDTCisVT<1, i32>]>,
195            [SDNPHasChain, SDNPOutGlue, SDNPOptInGlue]>;
196 def PTXstoreparam
197   : SDNode<"PTXISD::STORE_PARAM", SDTypeProfile<0, 2, [SDTCisVT<0, i32>]>,
198            [SDNPHasChain, SDNPOutGlue, SDNPOptInGlue]>;
199
200 //===----------------------------------------------------------------------===//
201 // Instruction Class Templates
202 //===----------------------------------------------------------------------===//
203
204 //===- Floating-Point Instructions - 2 Operand Form -----------------------===//
205 multiclass PTX_FLOAT_2OP<string opcstr, SDNode opnode> {
206   def rr32 : InstPTX<(outs RegF32:$d),
207                      (ins RegF32:$a),
208                      !strconcat(opcstr, ".f32\t$d, $a"),
209                      [(set RegF32:$d, (opnode RegF32:$a))]>;
210   def ri32 : InstPTX<(outs RegF32:$d),
211                      (ins f32imm:$a),
212                      !strconcat(opcstr, ".f32\t$d, $a"),
213                      [(set RegF32:$d, (opnode fpimm:$a))]>;
214   def rr64 : InstPTX<(outs RegF64:$d),
215                      (ins RegF64:$a),
216                      !strconcat(opcstr, ".f64\t$d, $a"),
217                      [(set RegF64:$d, (opnode RegF64:$a))]>;
218   def ri64 : InstPTX<(outs RegF64:$d),
219                      (ins f64imm:$a),
220                      !strconcat(opcstr, ".f64\t$d, $a"),
221                      [(set RegF64:$d, (opnode fpimm:$a))]>;
222 }
223
224 //===- Floating-Point Instructions - 3 Operand Form -----------------------===//
225 multiclass PTX_FLOAT_3OP<string opcstr, SDNode opnode> {
226   def rr32 : InstPTX<(outs RegF32:$d),
227                      (ins RegF32:$a, RegF32:$b),
228                      !strconcat(opcstr, ".f32\t$d, $a, $b"),
229                      [(set RegF32:$d, (opnode RegF32:$a, RegF32:$b))]>;
230   def ri32 : InstPTX<(outs RegF32:$d),
231                      (ins RegF32:$a, f32imm:$b),
232                      !strconcat(opcstr, ".f32\t$d, $a, $b"),
233                      [(set RegF32:$d, (opnode RegF32:$a, fpimm:$b))]>;
234   def rr64 : InstPTX<(outs RegF64:$d),
235                      (ins RegF64:$a, RegF64:$b),
236                      !strconcat(opcstr, ".f64\t$d, $a, $b"),
237                      [(set RegF64:$d, (opnode RegF64:$a, RegF64:$b))]>;
238   def ri64 : InstPTX<(outs RegF64:$d),
239                      (ins RegF64:$a, f64imm:$b),
240                      !strconcat(opcstr, ".f64\t$d, $a, $b"),
241                      [(set RegF64:$d, (opnode RegF64:$a, fpimm:$b))]>;
242 }
243
244 //===- Floating-Point Instructions - 4 Operand Form -----------------------===//
245 multiclass PTX_FLOAT_4OP<string opcstr, SDNode opnode1, SDNode opnode2> {
246   def rrr32 : InstPTX<(outs RegF32:$d),
247                       (ins RegF32:$a, RegF32:$b, RegF32:$c),
248                       !strconcat(opcstr, ".f32\t$d, $a, $b, $c"),
249                       [(set RegF32:$d, (opnode2 (opnode1 RegF32:$a,
250                                                           RegF32:$b),
251                                                  RegF32:$c))]>;
252   def rri32 : InstPTX<(outs RegF32:$d),
253                       (ins RegF32:$a, RegF32:$b, f32imm:$c),
254                       !strconcat(opcstr, ".f32\t$d, $a, $b, $c"),
255                       [(set RegF32:$d, (opnode2 (opnode1 RegF32:$a,
256                                                           RegF32:$b),
257                                                  fpimm:$c))]>;
258   def rrr64 : InstPTX<(outs RegF64:$d),
259                       (ins RegF64:$a, RegF64:$b, RegF64:$c),
260                       !strconcat(opcstr, ".f64\t$d, $a, $b, $c"),
261                       [(set RegF64:$d, (opnode2 (opnode1 RegF64:$a,
262                                                           RegF64:$b),
263                                                  RegF64:$c))]>;
264   def rri64 : InstPTX<(outs RegF64:$d),
265                       (ins RegF64:$a, RegF64:$b, f64imm:$c),
266                       !strconcat(opcstr, ".f64\t$d, $a, $b, $c"),
267                       [(set RegF64:$d, (opnode2 (opnode1 RegF64:$a,
268                                                           RegF64:$b),
269                                                  fpimm:$c))]>;
270 }
271
272 multiclass INT3<string opcstr, SDNode opnode> {
273   def rr16 : InstPTX<(outs RegI16:$d),
274                      (ins RegI16:$a, RegI16:$b),
275                      !strconcat(opcstr, ".u16\t$d, $a, $b"),
276                      [(set RegI16:$d, (opnode RegI16:$a, RegI16:$b))]>;
277   def ri16 : InstPTX<(outs RegI16:$d),
278                      (ins RegI16:$a, i16imm:$b),
279                      !strconcat(opcstr, ".u16\t$d, $a, $b"),
280                      [(set RegI16:$d, (opnode RegI16:$a, imm:$b))]>;
281   def rr32 : InstPTX<(outs RegI32:$d),
282                      (ins RegI32:$a, RegI32:$b),
283                      !strconcat(opcstr, ".u32\t$d, $a, $b"),
284                      [(set RegI32:$d, (opnode RegI32:$a, RegI32:$b))]>;
285   def ri32 : InstPTX<(outs RegI32:$d),
286                      (ins RegI32:$a, i32imm:$b),
287                      !strconcat(opcstr, ".u32\t$d, $a, $b"),
288                      [(set RegI32:$d, (opnode RegI32:$a, imm:$b))]>;
289   def rr64 : InstPTX<(outs RegI64:$d),
290                      (ins RegI64:$a, RegI64:$b),
291                      !strconcat(opcstr, ".u64\t$d, $a, $b"),
292                      [(set RegI64:$d, (opnode RegI64:$a, RegI64:$b))]>;
293   def ri64 : InstPTX<(outs RegI64:$d),
294                      (ins RegI64:$a, i64imm:$b),
295                      !strconcat(opcstr, ".u64\t$d, $a, $b"),
296                      [(set RegI64:$d, (opnode RegI64:$a, imm:$b))]>;
297 }
298
299 multiclass PTX_LOGIC<string opcstr, SDNode opnode> {
300   def ripreds : InstPTX<(outs RegPred:$d),
301                      (ins RegPred:$a, i1imm:$b),
302                      !strconcat(opcstr, ".pred\t$d, $a, $b"),
303                      [(set RegPred:$d, (opnode RegPred:$a, imm:$b))]>;
304   def rrpreds : InstPTX<(outs RegPred:$d),
305                      (ins RegPred:$a, RegPred:$b),
306                      !strconcat(opcstr, ".pred\t$d, $a, $b"),
307                      [(set RegPred:$d, (opnode RegPred:$a, RegPred:$b))]>;
308   def rr16 : InstPTX<(outs RegI16:$d),
309                      (ins RegI16:$a, RegI16:$b),
310                      !strconcat(opcstr, ".b16\t$d, $a, $b"),
311                      [(set RegI16:$d, (opnode RegI16:$a, RegI16:$b))]>;
312   def ri16 : InstPTX<(outs RegI16:$d),
313                      (ins RegI16:$a, i16imm:$b),
314                      !strconcat(opcstr, ".b16\t$d, $a, $b"),
315                      [(set RegI16:$d, (opnode RegI16:$a, imm:$b))]>;
316   def rr32 : InstPTX<(outs RegI32:$d),
317                      (ins RegI32:$a, RegI32:$b),
318                      !strconcat(opcstr, ".b32\t$d, $a, $b"),
319                      [(set RegI32:$d, (opnode RegI32:$a, RegI32:$b))]>;
320   def ri32 : InstPTX<(outs RegI32:$d),
321                      (ins RegI32:$a, i32imm:$b),
322                      !strconcat(opcstr, ".b32\t$d, $a, $b"),
323                      [(set RegI32:$d, (opnode RegI32:$a, imm:$b))]>;
324   def rr64 : InstPTX<(outs RegI64:$d),
325                      (ins RegI64:$a, RegI64:$b),
326                      !strconcat(opcstr, ".b64\t$d, $a, $b"),
327                      [(set RegI64:$d, (opnode RegI64:$a, RegI64:$b))]>;
328   def ri64 : InstPTX<(outs RegI64:$d),
329                      (ins RegI64:$a, i64imm:$b),
330                      !strconcat(opcstr, ".b64\t$d, $a, $b"),
331                      [(set RegI64:$d, (opnode RegI64:$a, imm:$b))]>;
332 }
333
334 multiclass INT3ntnc<string opcstr, SDNode opnode> {
335   def rr16 : InstPTX<(outs RegI16:$d),
336                      (ins RegI16:$a, RegI16:$b),
337                      !strconcat(opcstr, "16\t$d, $a, $b"),
338                      [(set RegI16:$d, (opnode RegI16:$a, RegI16:$b))]>;
339   def rr32 : InstPTX<(outs RegI32:$d),
340                      (ins RegI32:$a, RegI32:$b),
341                      !strconcat(opcstr, "32\t$d, $a, $b"),
342                      [(set RegI32:$d, (opnode RegI32:$a, RegI32:$b))]>;
343   def rr64 : InstPTX<(outs RegI64:$d),
344                      (ins RegI64:$a, RegI64:$b),
345                      !strconcat(opcstr, "64\t$d, $a, $b"),
346                      [(set RegI64:$d, (opnode RegI64:$a, RegI64:$b))]>;
347   def ri16 : InstPTX<(outs RegI16:$d),
348                      (ins RegI16:$a, i16imm:$b),
349                      !strconcat(opcstr, "16\t$d, $a, $b"),
350                      [(set RegI16:$d, (opnode RegI16:$a, imm:$b))]>;
351   def ri32 : InstPTX<(outs RegI32:$d),
352                      (ins RegI32:$a, i32imm:$b),
353                      !strconcat(opcstr, "32\t$d, $a, $b"),
354                      [(set RegI32:$d, (opnode RegI32:$a, imm:$b))]>;
355   def ri64 : InstPTX<(outs RegI64:$d),
356                      (ins RegI64:$a, i64imm:$b),
357                      !strconcat(opcstr, "64\t$d, $a, $b"),
358                      [(set RegI64:$d, (opnode RegI64:$a, imm:$b))]>;
359   def ir16 : InstPTX<(outs RegI16:$d),
360                      (ins i16imm:$a, RegI16:$b),
361                      !strconcat(opcstr, "16\t$d, $a, $b"),
362                      [(set RegI16:$d, (opnode imm:$a, RegI16:$b))]>;
363   def ir32 : InstPTX<(outs RegI32:$d),
364                      (ins i32imm:$a, RegI32:$b),
365                      !strconcat(opcstr, "32\t$d, $a, $b"),
366                      [(set RegI32:$d, (opnode imm:$a, RegI32:$b))]>;
367   def ir64 : InstPTX<(outs RegI64:$d),
368                      (ins i64imm:$a, RegI64:$b),
369                      !strconcat(opcstr, "64\t$d, $a, $b"),
370                      [(set RegI64:$d, (opnode imm:$a, RegI64:$b))]>;
371 }
372
373 multiclass PTX_SETP_I<RegisterClass RC, string regclsname, Operand immcls,
374                         CondCode cmp, string cmpstr> {
375   // TODO support 5-operand format: p|q, a, b, c
376
377   def rr
378     : InstPTX<(outs RegPred:$p), (ins RC:$a, RC:$b),
379               !strconcat("setp.", cmpstr, ".", regclsname, "\t$p, $a, $b"),
380               [(set RegPred:$p, (setcc RC:$a, RC:$b, cmp))]>;
381   def ri
382     : InstPTX<(outs RegPred:$p), (ins RC:$a, immcls:$b),
383               !strconcat("setp.", cmpstr, ".", regclsname, "\t$p, $a, $b"),
384               [(set RegPred:$p, (setcc RC:$a, imm:$b, cmp))]>;
385
386   def rr_and_r
387     : InstPTX<(outs RegPred:$p), (ins RC:$a, RC:$b, RegPred:$c),
388               !strconcat("setp.", cmpstr, ".and.", regclsname, "\t$p, $a, $b, $c"),
389               [(set RegPred:$p, (and (setcc RC:$a, RC:$b, cmp), RegPred:$c))]>;
390   def ri_and_r
391     : InstPTX<(outs RegPred:$p), (ins RC:$a, immcls:$b, RegPred:$c),
392               !strconcat("setp.", cmpstr, ".and.", regclsname, "\t$p, $a, $b, $c"),
393               [(set RegPred:$p, (and (setcc RC:$a, imm:$b, cmp), RegPred:$c))]>;
394   def rr_or_r
395     : InstPTX<(outs RegPred:$p), (ins RC:$a, RC:$b, RegPred:$c),
396               !strconcat("setp.", cmpstr, ".or.", regclsname, "\t$p, $a, $b, $c"),
397               [(set RegPred:$p, (or (setcc RC:$a, RC:$b, cmp), RegPred:$c))]>;
398   def ri_or_r
399     : InstPTX<(outs RegPred:$p), (ins RC:$a, immcls:$b, RegPred:$c),
400               !strconcat("setp.", cmpstr, ".or.", regclsname, "\t$p, $a, $b, $c"),
401               [(set RegPred:$p, (or (setcc RC:$a, imm:$b, cmp), RegPred:$c))]>;
402   def rr_xor_r
403     : InstPTX<(outs RegPred:$p), (ins RC:$a, RC:$b, RegPred:$c),
404               !strconcat("setp.", cmpstr, ".xor.", regclsname, "\t$p, $a, $b, $c"),
405               [(set RegPred:$p, (xor (setcc RC:$a, RC:$b, cmp), RegPred:$c))]>;
406   def ri_xor_r
407     : InstPTX<(outs RegPred:$p), (ins RC:$a, immcls:$b, RegPred:$c),
408               !strconcat("setp.", cmpstr, ".xor.", regclsname, "\t$p, $a, $b, $c"),
409               [(set RegPred:$p, (xor (setcc RC:$a, imm:$b, cmp), RegPred:$c))]>;
410
411   def rr_and_not_r
412     : InstPTX<(outs RegPred:$p), (ins RC:$a, RC:$b, RegPred:$c),
413               !strconcat("setp.", cmpstr, ".and.", regclsname, "\t$p, $a, $b, !$c"),
414               [(set RegPred:$p, (and (setcc RC:$a, RC:$b, cmp), (not RegPred:$c)))]>;
415   def ri_and_not_r
416     : InstPTX<(outs RegPred:$p), (ins RC:$a, immcls:$b, RegPred:$c),
417               !strconcat("setp.", cmpstr, ".and.", regclsname, "\t$p, $a, $b, !$c"),
418               [(set RegPred:$p, (and (setcc RC:$a, imm:$b, cmp), (not RegPred:$c)))]>;
419   def rr_or_not_r
420     : InstPTX<(outs RegPred:$p), (ins RC:$a, RC:$b, RegPred:$c),
421               !strconcat("setp.", cmpstr, ".or.", regclsname, "\t$p, $a, $b, !$c"),
422               [(set RegPred:$p, (or (setcc RC:$a, RC:$b, cmp), (not RegPred:$c)))]>;
423   def ri_or_not_r
424     : InstPTX<(outs RegPred:$p), (ins RC:$a, immcls:$b, RegPred:$c),
425               !strconcat("setp.", cmpstr, ".or.", regclsname, "\t$p, $a, $b, !$c"),
426               [(set RegPred:$p, (or (setcc RC:$a, imm:$b, cmp), (not RegPred:$c)))]>;
427   def rr_xor_not_r
428     : InstPTX<(outs RegPred:$p), (ins RC:$a, RC:$b, RegPred:$c),
429               !strconcat("setp.", cmpstr, ".xor.", regclsname, "\t$p, $a, $b, !$c"),
430               [(set RegPred:$p, (xor (setcc RC:$a, RC:$b, cmp), (not RegPred:$c)))]>;
431   def ri_xor_not_r
432     : InstPTX<(outs RegPred:$p), (ins RC:$a, immcls:$b, RegPred:$c),
433               !strconcat("setp.", cmpstr, ".xor.", regclsname, "\t$p, $a, $b, !$c"),
434               [(set RegPred:$p, (xor (setcc RC:$a, imm:$b, cmp), (not RegPred:$c)))]>;
435 }
436
437 multiclass PTX_SETP_FP<RegisterClass RC, string regclsname,
438                         CondCode ucmp, CondCode ocmp, string cmpstr> {
439   // TODO support 5-operand format: p|q, a, b, c
440
441   def rr_u
442     : InstPTX<(outs RegPred:$p), (ins RC:$a, RC:$b),
443               !strconcat("setp.", cmpstr, "u.", regclsname, "\t$p, $a, $b"),
444               [(set RegPred:$p, (setcc RC:$a, RC:$b, ucmp))]>;
445   def rr_o
446     : InstPTX<(outs RegPred:$p), (ins RC:$a, RC:$b),
447               !strconcat("setp.", cmpstr, ".", regclsname, "\t$p, $a, $b"),
448               [(set RegPred:$p, (setcc RC:$a, RC:$b, ocmp))]>;
449
450   def rr_and_r_u
451     : InstPTX<(outs RegPred:$p), (ins RC:$a, RC:$b, RegPred:$c),
452               !strconcat("setp.", cmpstr, "u.and.", regclsname, "\t$p, $a, $b, $c"),
453               [(set RegPred:$p, (and (setcc RC:$a, RC:$b, ucmp), RegPred:$c))]>;
454   def rr_and_r_o
455     : InstPTX<(outs RegPred:$p), (ins RC:$a, RC:$b, RegPred:$c),
456               !strconcat("setp.", cmpstr, ".and.", regclsname, "\t$p, $a, $b, $c"),
457               [(set RegPred:$p, (and (setcc RC:$a, RC:$b, ocmp), RegPred:$c))]>;
458
459   def rr_or_r_u
460     : InstPTX<(outs RegPred:$p), (ins RC:$a, RC:$b, RegPred:$c),
461               !strconcat("setp.", cmpstr, "u.or.", regclsname, "\t$p, $a, $b, $c"),
462               [(set RegPred:$p, (or (setcc RC:$a, RC:$b, ucmp), RegPred:$c))]>;
463   def rr_or_r_o
464     : InstPTX<(outs RegPred:$p), (ins RC:$a, RC:$b, RegPred:$c),
465               !strconcat("setp.", cmpstr, ".or.", regclsname, "\t$p, $a, $b, $c"),
466               [(set RegPred:$p, (or (setcc RC:$a, RC:$b, ocmp), RegPred:$c))]>;
467
468   def rr_xor_r_u
469     : InstPTX<(outs RegPred:$p), (ins RC:$a, RC:$b, RegPred:$c),
470               !strconcat("setp.", cmpstr, "u.xor.", regclsname, "\t$p, $a, $b, $c"),
471               [(set RegPred:$p, (xor (setcc RC:$a, RC:$b, ucmp), RegPred:$c))]>;
472   def rr_xor_r_o
473     : InstPTX<(outs RegPred:$p), (ins RC:$a, RC:$b, RegPred:$c),
474               !strconcat("setp.", cmpstr, ".xor.", regclsname, "\t$p, $a, $b, $c"),
475               [(set RegPred:$p, (xor (setcc RC:$a, RC:$b, ocmp), RegPred:$c))]>;
476
477   def rr_and_not_r_u
478     : InstPTX<(outs RegPred:$p), (ins RC:$a, RC:$b, RegPred:$c),
479               !strconcat("setp.", cmpstr, "u.and.", regclsname, "\t$p, $a, $b, !$c"),
480               [(set RegPred:$p, (and (setcc RC:$a, RC:$b, ucmp), (not RegPred:$c)))]>;
481   def rr_and_not_r_o
482     : InstPTX<(outs RegPred:$p), (ins RC:$a, RC:$b, RegPred:$c),
483               !strconcat("setp.", cmpstr, ".and.", regclsname, "\t$p, $a, $b, !$c"),
484               [(set RegPred:$p, (and (setcc RC:$a, RC:$b, ocmp), (not RegPred:$c)))]>;
485
486   def rr_or_not_r_u
487     : InstPTX<(outs RegPred:$p), (ins RC:$a, RC:$b, RegPred:$c),
488               !strconcat("setp.", cmpstr, "u.or.", regclsname, "\t$p, $a, $b, !$c"),
489               [(set RegPred:$p, (or (setcc RC:$a, RC:$b, ucmp), (not RegPred:$c)))]>;
490   def rr_or_not_r_o
491     : InstPTX<(outs RegPred:$p), (ins RC:$a, RC:$b, RegPred:$c),
492               !strconcat("setp.", cmpstr, ".or.", regclsname, "\t$p, $a, $b, !$c"),
493               [(set RegPred:$p, (or (setcc RC:$a, RC:$b, ocmp), (not RegPred:$c)))]>;
494
495   def rr_xor_not_r_u
496     : InstPTX<(outs RegPred:$p), (ins RC:$a, RC:$b, RegPred:$c),
497               !strconcat("setp.", cmpstr, "u.xor.", regclsname, "\t$p, $a, $b, !$c"),
498               [(set RegPred:$p, (xor (setcc RC:$a, RC:$b, ucmp), (not RegPred:$c)))]>;
499   def rr_xor_not_r_o
500     : InstPTX<(outs RegPred:$p), (ins RC:$a, RC:$b, RegPred:$c),
501               !strconcat("setp.", cmpstr, ".xor.", regclsname, "\t$p, $a, $b, !$c"),
502               [(set RegPred:$p, (xor (setcc RC:$a, RC:$b, ocmp), (not RegPred:$c)))]>;
503 }
504
505 multiclass PTX_SELP<RegisterClass RC, string regclsname> {
506   def rr
507     : InstPTX<(outs RC:$r), (ins RegPred:$a, RC:$b, RC:$c),
508               !strconcat("selp.", regclsname, "\t$r, $b, $c, $a"),
509               [(set RC:$r, (select RegPred:$a, RC:$b, RC:$c))]>;
510 }
511
512 multiclass PTX_LD<string opstr, string typestr, RegisterClass RC, PatFrag pat_load> {
513   def rr32 : InstPTX<(outs RC:$d),
514                      (ins MEMri32:$a),
515                      !strconcat(opstr, !strconcat(typestr, "\t$d, [$a]")),
516                      [(set RC:$d, (pat_load ADDRrr32:$a))]>, Requires<[Use32BitAddresses]>;
517   def rr64 : InstPTX<(outs RC:$d),
518                      (ins MEMri64:$a),
519                      !strconcat(opstr, !strconcat(typestr, "\t$d, [$a]")),
520                      [(set RC:$d, (pat_load ADDRrr64:$a))]>, Requires<[Use64BitAddresses]>;
521   def ri32 : InstPTX<(outs RC:$d),
522                      (ins MEMri32:$a),
523                      !strconcat(opstr, !strconcat(typestr, "\t$d, [$a]")),
524                      [(set RC:$d, (pat_load ADDRri32:$a))]>, Requires<[Use32BitAddresses]>;
525   def ri64 : InstPTX<(outs RC:$d),
526                      (ins MEMri64:$a),
527                      !strconcat(opstr, !strconcat(typestr, "\t$d, [$a]")),
528                      [(set RC:$d, (pat_load ADDRri64:$a))]>, Requires<[Use64BitAddresses]>;
529   def ii32 : InstPTX<(outs RC:$d),
530                      (ins MEMii32:$a),
531                      !strconcat(opstr, !strconcat(typestr, "\t$d, [$a]")),
532                      [(set RC:$d, (pat_load ADDRii32:$a))]>, Requires<[Use32BitAddresses]>;
533   def ii64 : InstPTX<(outs RC:$d),
534                      (ins MEMii64:$a),
535                      !strconcat(opstr, !strconcat(typestr, "\t$d, [$a]")),
536                      [(set RC:$d, (pat_load ADDRii64:$a))]>, Requires<[Use64BitAddresses]>;
537 }
538
539 multiclass PTX_LD_ALL<string opstr, PatFrag pat_load> {
540   defm u16 : PTX_LD<opstr, ".u16", RegI16, pat_load>;
541   defm u32 : PTX_LD<opstr, ".u32", RegI32, pat_load>;
542   defm u64 : PTX_LD<opstr, ".u64", RegI64, pat_load>;
543   defm f32 : PTX_LD<opstr, ".f32", RegF32, pat_load>;
544   defm f64 : PTX_LD<opstr, ".f64", RegF64, pat_load>;
545 }
546
547 multiclass PTX_ST<string opstr, string typestr, RegisterClass RC, PatFrag pat_store> {
548   def rr32 : InstPTX<(outs),
549                      (ins RC:$d, MEMri32:$a),
550                      !strconcat(opstr, !strconcat(typestr, "\t[$a], $d")),
551                      [(pat_store RC:$d, ADDRrr32:$a)]>, Requires<[Use32BitAddresses]>;
552   def rr64 : InstPTX<(outs),
553                      (ins RC:$d, MEMri64:$a),
554                      !strconcat(opstr, !strconcat(typestr, "\t[$a], $d")),
555                      [(pat_store RC:$d, ADDRrr64:$a)]>, Requires<[Use64BitAddresses]>;
556   def ri32 : InstPTX<(outs),
557                    (ins RC:$d, MEMri32:$a),
558                    !strconcat(opstr, !strconcat(typestr, "\t[$a], $d")),
559                    [(pat_store RC:$d, ADDRri32:$a)]>, Requires<[Use32BitAddresses]>;
560   def ri64 : InstPTX<(outs),
561                    (ins RC:$d, MEMri64:$a),
562                    !strconcat(opstr, !strconcat(typestr, "\t[$a], $d")),
563                    [(pat_store RC:$d, ADDRri64:$a)]>, Requires<[Use64BitAddresses]>;
564   def ii32 : InstPTX<(outs),
565                    (ins RC:$d, MEMii32:$a),
566                    !strconcat(opstr, !strconcat(typestr, "\t[$a], $d")),
567                    [(pat_store RC:$d, ADDRii32:$a)]>, Requires<[Use32BitAddresses]>;
568   def ii64 : InstPTX<(outs),
569                    (ins RC:$d, MEMii64:$a),
570                    !strconcat(opstr, !strconcat(typestr, "\t[$a], $d")),
571                    [(pat_store RC:$d, ADDRii64:$a)]>, Requires<[Use64BitAddresses]>;
572 }
573
574 multiclass PTX_ST_ALL<string opstr, PatFrag pat_store> {
575   defm u16 : PTX_ST<opstr, ".u16", RegI16, pat_store>;
576   defm u32 : PTX_ST<opstr, ".u32", RegI32, pat_store>;
577   defm u64 : PTX_ST<opstr, ".u64", RegI64, pat_store>;
578   defm f32 : PTX_ST<opstr, ".f32", RegF32, pat_store>;
579   defm f64 : PTX_ST<opstr, ".f64", RegF64, pat_store>;
580 }
581
582 //===----------------------------------------------------------------------===//
583 // Instructions
584 //===----------------------------------------------------------------------===//
585
586 ///===- Integer Arithmetic Instructions -----------------------------------===//
587
588 defm ADD : INT3<"add", add>;
589 defm SUB : INT3<"sub", sub>;
590 defm MUL : INT3<"mul.lo", mul>; // FIXME: Allow 32x32 -> 64 multiplies
591 defm DIV : INT3<"div", udiv>;
592 defm REM : INT3<"rem", urem>;
593
594 ///===- Floating-Point Arithmetic Instructions ----------------------------===//
595
596 // Standard Unary Operations
597 defm FNEG : PTX_FLOAT_2OP<"neg", fneg>;
598
599 // Standard Binary Operations
600 defm FADD : PTX_FLOAT_3OP<"add.rn", fadd>;
601 defm FSUB : PTX_FLOAT_3OP<"sub.rn", fsub>;
602 defm FMUL : PTX_FLOAT_3OP<"mul.rn", fmul>;
603
604 // For floating-point division:
605 // SM_13+ defaults to .rn for f32 and f64,
606 // SM10 must *not* provide a rounding
607
608 // TODO: 
609 //     - Allow user selection of rounding modes for fdiv
610 //     - Add support for -prec-div=false (.approx)
611
612 def FDIVrr32SM13 : InstPTX<(outs RegF32:$d),
613                        (ins RegF32:$a, RegF32:$b),
614                        "div.rn.f32\t$d, $a, $b",
615                        [(set RegF32:$d, (fdiv RegF32:$a, RegF32:$b))]>,
616                    Requires<[FDivNeedsRoundingMode]>;
617 def FDIVri32SM13 : InstPTX<(outs RegF32:$d),
618                        (ins RegF32:$a, f32imm:$b),
619                        "div.rn.f32\t$d, $a, $b",
620                        [(set RegF32:$d, (fdiv RegF32:$a, fpimm:$b))]>,
621                    Requires<[FDivNeedsRoundingMode]>;
622 def FDIVrr32SM10 : InstPTX<(outs RegF32:$d),
623                        (ins RegF32:$a, RegF32:$b),
624                        "div.f32\t$d, $a, $b",
625                        [(set RegF32:$d, (fdiv RegF32:$a, RegF32:$b))]>,
626                    Requires<[FDivNoRoundingMode]>;
627 def FDIVri32SM10 : InstPTX<(outs RegF32:$d),
628                        (ins RegF32:$a, f32imm:$b),
629                        "div.f32\t$d, $a, $b",
630                        [(set RegF32:$d, (fdiv RegF32:$a, fpimm:$b))]>,
631                    Requires<[FDivNoRoundingMode]>;
632
633 def FDIVrr64SM13 : InstPTX<(outs RegF64:$d),
634                            (ins RegF64:$a, RegF64:$b),
635                            "div.rn.f64\t$d, $a, $b",
636                            [(set RegF64:$d, (fdiv RegF64:$a, RegF64:$b))]>,
637                    Requires<[FDivNeedsRoundingMode]>;
638 def FDIVri64SM13 : InstPTX<(outs RegF64:$d),
639                            (ins RegF64:$a, f64imm:$b),
640                            "div.rn.f64\t$d, $a, $b",
641                            [(set RegF64:$d, (fdiv RegF64:$a, fpimm:$b))]>,
642                    Requires<[FDivNeedsRoundingMode]>;
643 def FDIVrr64SM10 : InstPTX<(outs RegF64:$d),
644                            (ins RegF64:$a, RegF64:$b),
645                            "div.f64\t$d, $a, $b",
646                            [(set RegF64:$d, (fdiv RegF64:$a, RegF64:$b))]>,
647                    Requires<[FDivNoRoundingMode]>;
648 def FDIVri64SM10 : InstPTX<(outs RegF64:$d),
649                            (ins RegF64:$a, f64imm:$b),
650                            "div.f64\t$d, $a, $b",
651                            [(set RegF64:$d, (fdiv RegF64:$a, fpimm:$b))]>,
652                    Requires<[FDivNoRoundingMode]>;
653
654
655
656 // Multi-operation hybrid instructions
657
658 // The selection of mad/fma is tricky.  In some cases, they are the *same*
659 // instruction, but in other cases we may prefer one or the other.  Also,
660 // different PTX versions differ on whether rounding mode flags are required.
661 // In the short term, mad is supported on all PTX versions and we use a
662 // default rounding mode no matter what shader model or PTX version.
663 // TODO: Allow the rounding mode to be selectable through llc.
664 defm FMADSM13 : PTX_FLOAT_4OP<"mad.rn", fmul, fadd>,
665                 Requires<[FMadNeedsRoundingMode, SupportsFMA]>;
666 defm FMAD : PTX_FLOAT_4OP<"mad", fmul, fadd>,
667             Requires<[FMadNoRoundingMode, SupportsFMA]>;
668
669 ///===- Floating-Point Intrinsic Instructions -----------------------------===//
670
671 def FSQRT32 : InstPTX<(outs RegF32:$d),
672                       (ins RegF32:$a),
673                       "sqrt.rn.f32\t$d, $a",
674                       [(set RegF32:$d, (fsqrt RegF32:$a))]>;
675
676 def FSQRT64 : InstPTX<(outs RegF64:$d),
677                       (ins RegF64:$a),
678                       "sqrt.rn.f64\t$d, $a",
679                       [(set RegF64:$d, (fsqrt RegF64:$a))]>;
680
681 def FSIN32 : InstPTX<(outs RegF32:$d),
682                      (ins RegF32:$a),
683                      "sin.approx.f32\t$d, $a",
684                      [(set RegF32:$d, (fsin RegF32:$a))]>;
685
686 def FSIN64 : InstPTX<(outs RegF64:$d),
687                      (ins RegF64:$a),
688                      "sin.approx.f64\t$d, $a",
689                      [(set RegF64:$d, (fsin RegF64:$a))]>;
690
691 def FCOS32 : InstPTX<(outs RegF32:$d),
692                      (ins RegF32:$a),
693                      "cos.approx.f32\t$d, $a",
694                      [(set RegF32:$d, (fcos RegF32:$a))]>;
695
696 def FCOS64 : InstPTX<(outs RegF64:$d),
697                      (ins RegF64:$a),
698                      "cos.approx.f64\t$d, $a",
699                      [(set RegF64:$d, (fcos RegF64:$a))]>;
700
701
702 ///===- Comparison and Selection Instructions -----------------------------===//
703
704 // .setp
705
706 // Compare u16
707
708 defm SETPEQu16 : PTX_SETP_I<RegI16, "u16", i16imm, SETEQ,  "eq">;
709 defm SETPNEu16 : PTX_SETP_I<RegI16, "u16", i16imm, SETNE,  "ne">;
710 defm SETPLTu16 : PTX_SETP_I<RegI16, "u16", i16imm, SETULT, "lt">;
711 defm SETPLEu16 : PTX_SETP_I<RegI16, "u16", i16imm, SETULE, "le">;
712 defm SETPGTu16 : PTX_SETP_I<RegI16, "u16", i16imm, SETUGT, "gt">;
713 defm SETPGEu16 : PTX_SETP_I<RegI16, "u16", i16imm, SETUGE, "ge">;
714 defm SETPLTs16 : PTX_SETP_I<RegI16, "s16", i16imm, SETLT,  "lt">;
715 defm SETPLEs16 : PTX_SETP_I<RegI16, "s16", i16imm, SETLE,  "le">;
716 defm SETPGTs16 : PTX_SETP_I<RegI16, "s16", i16imm, SETGT,  "gt">;
717 defm SETPGEs16 : PTX_SETP_I<RegI16, "s16", i16imm, SETGE,  "ge">;
718
719 // Compare u32
720
721 defm SETPEQu32 : PTX_SETP_I<RegI32, "u32", i32imm, SETEQ,  "eq">;
722 defm SETPNEu32 : PTX_SETP_I<RegI32, "u32", i32imm, SETNE,  "ne">;
723 defm SETPLTu32 : PTX_SETP_I<RegI32, "u32", i32imm, SETULT, "lt">;
724 defm SETPLEu32 : PTX_SETP_I<RegI32, "u32", i32imm, SETULE, "le">;
725 defm SETPGTu32 : PTX_SETP_I<RegI32, "u32", i32imm, SETUGT, "gt">;
726 defm SETPGEu32 : PTX_SETP_I<RegI32, "u32", i32imm, SETUGE, "ge">;
727 defm SETPLTs32 : PTX_SETP_I<RegI32, "s32", i32imm, SETLT,  "lt">;
728 defm SETPLEs32 : PTX_SETP_I<RegI32, "s32", i32imm, SETLE,  "le">;
729 defm SETPGTs32 : PTX_SETP_I<RegI32, "s32", i32imm, SETGT,  "gt">;
730 defm SETPGEs32 : PTX_SETP_I<RegI32, "s32", i32imm, SETGE,  "ge">;
731
732 // Compare u64
733
734 defm SETPEQu64 : PTX_SETP_I<RegI64, "u64", i64imm, SETEQ,  "eq">;
735 defm SETPNEu64 : PTX_SETP_I<RegI64, "u64", i64imm, SETNE,  "ne">;
736 defm SETPLTu64 : PTX_SETP_I<RegI64, "u64", i64imm, SETULT, "lt">;
737 defm SETPLEu64 : PTX_SETP_I<RegI64, "u64", i64imm, SETULE, "le">;
738 defm SETPGTu64 : PTX_SETP_I<RegI64, "u64", i64imm, SETUGT, "gt">;
739 defm SETPGEu64 : PTX_SETP_I<RegI64, "u64", i64imm, SETUGE, "ge">;
740 defm SETPLTs64 : PTX_SETP_I<RegI64, "s64", i64imm, SETLT,  "lt">;
741 defm SETPLEs64 : PTX_SETP_I<RegI64, "s64", i64imm, SETLE,  "le">;
742 defm SETPGTs64 : PTX_SETP_I<RegI64, "s64", i64imm, SETGT,  "gt">;
743 defm SETPGEs64 : PTX_SETP_I<RegI64, "s64", i64imm, SETGE,  "ge">;
744
745 // Compare f32
746
747 defm SETPEQf32 : PTX_SETP_FP<RegF32, "f32", SETUEQ, SETOEQ, "eq">;
748 defm SETPNEf32 : PTX_SETP_FP<RegF32, "f32", SETUNE, SETONE, "ne">;
749 defm SETPLTf32 : PTX_SETP_FP<RegF32, "f32", SETULT, SETOLT, "lt">;
750 defm SETPLEf32 : PTX_SETP_FP<RegF32, "f32", SETULE, SETOLE, "le">;
751 defm SETPGTf32 : PTX_SETP_FP<RegF32, "f32", SETUGT, SETOGT, "gt">;
752 defm SETPGEf32 : PTX_SETP_FP<RegF32, "f32", SETUGE, SETOGE, "ge">;
753
754 // Compare f64
755
756 defm SETPEQf64 : PTX_SETP_FP<RegF64, "f64", SETUEQ, SETOEQ, "eq">;
757 defm SETPNEf64 : PTX_SETP_FP<RegF64, "f64", SETUNE, SETONE, "ne">;
758 defm SETPLTf64 : PTX_SETP_FP<RegF64, "f64", SETULT, SETOLT, "lt">;
759 defm SETPLEf64 : PTX_SETP_FP<RegF64, "f64", SETULE, SETOLE, "le">;
760 defm SETPGTf64 : PTX_SETP_FP<RegF64, "f64", SETUGT, SETOGT, "gt">;
761 defm SETPGEf64 : PTX_SETP_FP<RegF64, "f64", SETUGE, SETOGE, "ge">;
762
763 // .selp
764
765 defm PTX_SELPu16 : PTX_SELP<RegI16, "u16">;
766 defm PTX_SELPu32 : PTX_SELP<RegI32, "u32">;
767 defm PTX_SELPu64 : PTX_SELP<RegI64, "u64">;
768 defm PTX_SELPf32 : PTX_SELP<RegF32, "f32">;
769 defm PTX_SELPf64 : PTX_SELP<RegF64, "f64">;
770
771 ///===- Logic and Shift Instructions --------------------------------------===//
772
773 defm SHL : INT3ntnc<"shl.b", PTXshl>;
774 defm SRL : INT3ntnc<"shr.u", PTXsrl>;
775 defm SRA : INT3ntnc<"shr.s", PTXsra>;
776
777 defm AND : PTX_LOGIC<"and", and>;
778 defm OR  : PTX_LOGIC<"or",  or>;
779 defm XOR : PTX_LOGIC<"xor", xor>;
780
781 ///===- Data Movement and Conversion Instructions -------------------------===//
782
783 let neverHasSideEffects = 1 in {
784   def MOVPREDrr
785     : InstPTX<(outs RegPred:$d), (ins RegPred:$a), "mov.pred\t$d, $a", []>;
786   def MOVU16rr
787     : InstPTX<(outs RegI16:$d), (ins RegI16:$a), "mov.u16\t$d, $a", []>;
788   def MOVU32rr
789     : InstPTX<(outs RegI32:$d), (ins RegI32:$a), "mov.u32\t$d, $a", []>;
790   def MOVU64rr
791     : InstPTX<(outs RegI64:$d), (ins RegI64:$a), "mov.u64\t$d, $a", []>;
792   def MOVF32rr
793     : InstPTX<(outs RegF32:$d), (ins RegF32:$a), "mov.f32\t$d, $a", []>;
794   def MOVF64rr
795     : InstPTX<(outs RegF64:$d), (ins RegF64:$a), "mov.f64\t$d, $a", []>;
796 }
797
798 let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
799   def MOVPREDri
800     : InstPTX<(outs RegPred:$d), (ins i1imm:$a), "mov.pred\t$d, $a",
801               [(set RegPred:$d, imm:$a)]>;
802   def MOVU16ri
803     : InstPTX<(outs RegI16:$d), (ins i16imm:$a), "mov.u16\t$d, $a",
804               [(set RegI16:$d, imm:$a)]>;
805   def MOVU32ri
806     : InstPTX<(outs RegI32:$d), (ins i32imm:$a), "mov.u32\t$d, $a",
807               [(set RegI32:$d, imm:$a)]>;
808   def MOVU64ri
809     : InstPTX<(outs RegI64:$d), (ins i64imm:$a), "mov.u64\t$d, $a",
810               [(set RegI64:$d, imm:$a)]>;
811   def MOVF32ri
812     : InstPTX<(outs RegF32:$d), (ins f32imm:$a), "mov.f32\t$d, $a",
813               [(set RegF32:$d, fpimm:$a)]>;
814   def MOVF64ri
815     : InstPTX<(outs RegF64:$d), (ins f64imm:$a), "mov.f64\t$d, $a",
816               [(set RegF64:$d, fpimm:$a)]>;
817 }
818
819 let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
820   def MOVaddr32
821     : InstPTX<(outs RegI32:$d), (ins i32imm:$a), "mov.u32\t$d, $a",
822               [(set RegI32:$d, (PTXcopyaddress tglobaladdr:$a))]>;
823   def MOVaddr64
824     : InstPTX<(outs RegI64:$d), (ins i64imm:$a), "mov.u64\t$d, $a",
825               [(set RegI64:$d, (PTXcopyaddress tglobaladdr:$a))]>;
826 }
827
828 // Loads
829 defm LDg : PTX_LD_ALL<"ld.global", load_global>;
830 defm LDc : PTX_LD_ALL<"ld.const",  load_constant>;
831 defm LDl : PTX_LD_ALL<"ld.local",  load_local>;
832 defm LDs : PTX_LD_ALL<"ld.shared", load_shared>;
833
834 // These instructions are used to load/store from the .param space for
835 // device and kernel parameters
836
837 let hasSideEffects = 1 in {
838   def LDpiPred : InstPTX<(outs RegPred:$d), (ins MEMpi:$a),
839                          "ld.param.pred\t$d, [$a]",
840                          [(set RegPred:$d, (PTXloadparam timm:$a))]>;
841   def LDpiU16  : InstPTX<(outs RegI16:$d), (ins MEMpi:$a),
842                          "ld.param.u16\t$d, [$a]",
843                          [(set RegI16:$d, (PTXloadparam timm:$a))]>;
844   def LDpiU32  : InstPTX<(outs RegI32:$d), (ins MEMpi:$a),
845                          "ld.param.u32\t$d, [$a]",
846                          [(set RegI32:$d, (PTXloadparam timm:$a))]>;
847   def LDpiU64  : InstPTX<(outs RegI64:$d), (ins MEMpi:$a),
848                          "ld.param.u64\t$d, [$a]",
849                          [(set RegI64:$d, (PTXloadparam timm:$a))]>;
850   def LDpiF32  : InstPTX<(outs RegF32:$d), (ins MEMpi:$a),
851                          "ld.param.f32\t$d, [$a]",
852                          [(set RegF32:$d, (PTXloadparam timm:$a))]>;
853   def LDpiF64  : InstPTX<(outs RegF64:$d), (ins MEMpi:$a),
854                          "ld.param.f64\t$d, [$a]",
855                          [(set RegF64:$d, (PTXloadparam timm:$a))]>;
856
857   def STpiPred : InstPTX<(outs), (ins MEMret:$d, RegPred:$a),
858                          "st.param.pred\t[$d], $a",
859                          [(PTXstoreparam timm:$d, RegPred:$a)]>;
860   def STpiU16  : InstPTX<(outs), (ins MEMret:$d, RegI16:$a),
861                          "st.param.u16\t[$d], $a",
862                          [(PTXstoreparam timm:$d, RegI16:$a)]>;
863   def STpiU32  : InstPTX<(outs), (ins MEMret:$d, RegI32:$a),
864                          "st.param.u32\t[$d], $a",
865                          [(PTXstoreparam timm:$d, RegI32:$a)]>;
866   def STpiU64  : InstPTX<(outs), (ins MEMret:$d, RegI64:$a),
867                          "st.param.u64\t[$d], $a",
868                          [(PTXstoreparam timm:$d, RegI64:$a)]>;
869   def STpiF32  : InstPTX<(outs), (ins MEMret:$d, RegF32:$a),
870                          "st.param.f32\t[$d], $a",
871                          [(PTXstoreparam timm:$d, RegF32:$a)]>;
872   def STpiF64  : InstPTX<(outs), (ins MEMret:$d, RegF64:$a),
873                          "st.param.f64\t[$d], $a",
874                          [(PTXstoreparam timm:$d, RegF64:$a)]>;
875 }
876
877 // Stores
878 defm STg : PTX_ST_ALL<"st.global", store_global>;
879 defm STl : PTX_ST_ALL<"st.local",  store_local>;
880 defm STs : PTX_ST_ALL<"st.shared", store_shared>;
881
882 // defm STp : PTX_ST_ALL<"st.param",  store_parameter>;
883 // defm LDp : PTX_LD_ALL<"ld.param",  load_parameter>;
884 // TODO: Do something with st.param if/when it is needed.
885
886 // Conversion to pred
887 // PTX does not directly support converting to a predicate type, so we fake it
888 // by performing a greater-than test between the value and zero.  This follows
889 // the C convention that any non-zero value is equivalent to 'true'.
890 def CVT_pred_u16
891   : InstPTX<(outs RegPred:$d), (ins RegI16:$a), "setp.gt.u16\t$d, $a, 0",
892             [(set RegPred:$d, (trunc RegI16:$a))]>;
893
894 def CVT_pred_u32
895   : InstPTX<(outs RegPred:$d), (ins RegI32:$a), "setp.gt.u32\t$d, $a, 0",
896             [(set RegPred:$d, (trunc RegI32:$a))]>;
897
898 def CVT_pred_u64
899   : InstPTX<(outs RegPred:$d), (ins RegI64:$a), "setp.gt.u64\t$d, $a, 0",
900             [(set RegPred:$d, (trunc RegI64:$a))]>;
901
902 def CVT_pred_f32
903   : InstPTX<(outs RegPred:$d), (ins RegF32:$a), "setp.gt.f32\t$d, $a, 0",
904             [(set RegPred:$d, (fp_to_uint RegF32:$a))]>;
905
906 def CVT_pred_f64
907   : InstPTX<(outs RegPred:$d), (ins RegF64:$a), "setp.gt.f64\t$d, $a, 0",
908             [(set RegPred:$d, (fp_to_uint RegF64:$a))]>;
909
910 // Conversion to u16
911 // PTX does not directly support converting a predicate to a value, so we
912 // use a select instruction to select either 0 or 1 (integer or fp) based
913 // on the truth value of the predicate.
914 def CVT_u16_preda
915   : InstPTX<(outs RegI16:$d), (ins RegPred:$a), "selp.u16\t$d, 1, 0, $a",
916             [(set RegI16:$d, (anyext RegPred:$a))]>;
917
918 def CVT_u16_pred
919   : InstPTX<(outs RegI16:$d), (ins RegPred:$a), "selp.u16\t$d, 1, 0, $a",
920             [(set RegI16:$d, (zext RegPred:$a))]>;
921
922 def CVT_u16_preds
923   : InstPTX<(outs RegI16:$d), (ins RegPred:$a), "selp.u16\t$d, 1, 0, $a",
924             [(set RegI16:$d, (sext RegPred:$a))]>;
925
926 def CVT_u16_u32
927   : InstPTX<(outs RegI16:$d), (ins RegI32:$a), "cvt.u16.u32\t$d, $a",
928             [(set RegI16:$d, (trunc RegI32:$a))]>;
929
930 def CVT_u16_u64
931   : InstPTX<(outs RegI16:$d), (ins RegI64:$a), "cvt.u16.u64\t$d, $a",
932             [(set RegI16:$d, (trunc RegI64:$a))]>;
933
934 def CVT_u16_f32
935   : InstPTX<(outs RegI16:$d), (ins RegF32:$a), "cvt.rzi.u16.f32\t$d, $a",
936             [(set RegI16:$d, (fp_to_uint RegF32:$a))]>;
937
938 def CVT_u16_f64
939   : InstPTX<(outs RegI16:$d), (ins RegF64:$a), "cvt.rzi.u16.f64\t$d, $a",
940             [(set RegI16:$d, (fp_to_uint RegF64:$a))]>;
941
942 // Conversion to u32
943
944 def CVT_u32_pred
945   : InstPTX<(outs RegI32:$d), (ins RegPred:$a), "selp.u32\t$d, 1, 0, $a",
946             [(set RegI32:$d, (zext RegPred:$a))]>;
947
948 def CVT_u32_b16
949   : InstPTX<(outs RegI32:$d), (ins RegI16:$a), "cvt.u32.u16\t$d, $a",
950             [(set RegI32:$d, (anyext RegI16:$a))]>;
951
952 def CVT_u32_u16
953   : InstPTX<(outs RegI32:$d), (ins RegI16:$a), "cvt.u32.u16\t$d, $a",
954             [(set RegI32:$d, (zext RegI16:$a))]>;
955
956 def CVT_u32_preds
957   : InstPTX<(outs RegI32:$d), (ins RegPred:$a), "selp.u32\t$d, 1, 0, $a",
958             [(set RegI32:$d, (sext RegPred:$a))]>;
959
960 def CVT_u32_s16
961   : InstPTX<(outs RegI32:$d), (ins RegI16:$a), "cvt.u32.s16\t$d, $a",
962             [(set RegI32:$d, (sext RegI16:$a))]>;
963
964 def CVT_u32_u64
965   : InstPTX<(outs RegI32:$d), (ins RegI64:$a), "cvt.u32.u64\t$d, $a",
966             [(set RegI32:$d, (trunc RegI64:$a))]>;
967
968 def CVT_u32_f32
969   : InstPTX<(outs RegI32:$d), (ins RegF32:$a), "cvt.rzi.u32.f32\t$d, $a",
970             [(set RegI32:$d, (fp_to_uint RegF32:$a))]>;
971
972 def CVT_u32_f64
973   : InstPTX<(outs RegI32:$d), (ins RegF64:$a), "cvt.rzi.u32.f64\t$d, $a",
974             [(set RegI32:$d, (fp_to_uint RegF64:$a))]>;
975
976 // Conversion to u64
977
978 def CVT_u64_pred
979   : InstPTX<(outs RegI64:$d), (ins RegPred:$a), "selp.u64\t$d, 1, 0, $a",
980             [(set RegI64:$d, (zext RegPred:$a))]>;
981
982 def CVT_u64_preds
983   : InstPTX<(outs RegI64:$d), (ins RegPred:$a), "selp.u64\t$d, 1, 0, $a",
984             [(set RegI64:$d, (sext RegPred:$a))]>;
985
986 def CVT_u64_u16
987   : InstPTX<(outs RegI64:$d), (ins RegI16:$a), "cvt.u64.u16\t$d, $a",
988             [(set RegI64:$d, (zext RegI16:$a))]>;
989
990 def CVT_u64_s16
991   : InstPTX<(outs RegI64:$d), (ins RegI16:$a), "cvt.u64.s16\t$d, $a",
992             [(set RegI64:$d, (sext RegI16:$a))]>;
993
994 def CVT_u64_u32
995   : InstPTX<(outs RegI64:$d), (ins RegI32:$a), "cvt.u64.u32\t$d, $a",
996             [(set RegI64:$d, (zext RegI32:$a))]>;
997
998 def CVT_u64_s32
999   : InstPTX<(outs RegI64:$d), (ins RegI32:$a), "cvt.u64.s32\t$d, $a",
1000             [(set RegI64:$d, (sext RegI32:$a))]>;
1001
1002 def CVT_u64_f32
1003   : InstPTX<(outs RegI64:$d), (ins RegF32:$a), "cvt.rzi.u64.f32\t$d, $a",
1004             [(set RegI64:$d, (fp_to_uint RegF32:$a))]>;
1005
1006 def CVT_u64_f64
1007   : InstPTX<(outs RegI64:$d), (ins RegF64:$a), "cvt.rzi.u64.f64\t$d, $a",
1008             [(set RegI64:$d, (fp_to_uint RegF64:$a))]>;
1009
1010 // Conversion to f32
1011
1012 def CVT_f32_pred
1013   : InstPTX<(outs RegF32:$d), (ins RegPred:$a),
1014             "selp.f32\t$d, 0F3F800000, 0F00000000, $a",  // 1.0
1015             [(set RegF32:$d, (uint_to_fp RegPred:$a))]>;
1016
1017 def CVT_f32_u16
1018   : InstPTX<(outs RegF32:$d), (ins RegI16:$a), "cvt.rn.f32.u16\t$d, $a",
1019             [(set RegF32:$d, (uint_to_fp RegI16:$a))]>;
1020
1021 def CVT_f32_u32
1022   : InstPTX<(outs RegF32:$d), (ins RegI32:$a), "cvt.rn.f32.u32\t$d, $a",
1023             [(set RegF32:$d, (uint_to_fp RegI32:$a))]>;
1024
1025 def CVT_f32_u64
1026   : InstPTX<(outs RegF32:$d), (ins RegI64:$a), "cvt.rn.f32.u64\t$d, $a",
1027             [(set RegF32:$d, (uint_to_fp RegI64:$a))]>;
1028
1029 def CVT_f32_f64
1030   : InstPTX<(outs RegF32:$d), (ins RegF64:$a), "cvt.rn.f32.f64\t$d, $a",
1031             [(set RegF32:$d, (fround RegF64:$a))]>;
1032
1033 // Conversion to f64
1034
1035 def CVT_f64_pred
1036   : InstPTX<(outs RegF64:$d), (ins RegPred:$a), 
1037             "selp.f64\t$d, 0D3F80000000000000, 0D0000000000000000, $a",  // 1.0
1038             [(set RegF64:$d, (uint_to_fp RegPred:$a))]>;
1039
1040 def CVT_f64_u16
1041   : InstPTX<(outs RegF64:$d), (ins RegI16:$a), "cvt.rn.f64.u16\t$d, $a",
1042             [(set RegF64:$d, (uint_to_fp RegI16:$a))]>;
1043
1044 def CVT_f64_u32
1045   : InstPTX<(outs RegF64:$d), (ins RegI32:$a), "cvt.rn.f64.u32\t$d, $a",
1046             [(set RegF64:$d, (uint_to_fp RegI32:$a))]>;
1047
1048 def CVT_f64_u64
1049   : InstPTX<(outs RegF64:$d), (ins RegI64:$a), "cvt.rn.f64.u64\t$d, $a",
1050             [(set RegF64:$d, (uint_to_fp RegI64:$a))]>;
1051
1052 def CVT_f64_f32
1053   : InstPTX<(outs RegF64:$d), (ins RegF32:$a), "cvt.f64.f32\t$d, $a",
1054             [(set RegF64:$d, (fextend RegF32:$a))]>;
1055
1056 ///===- Control Flow Instructions -----------------------------------------===//
1057
1058 let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
1059   def BRAd
1060     : InstPTX<(outs), (ins brtarget:$d), "bra\t$d", [(br bb:$d)]>;
1061 }
1062
1063 let isBranch = 1, isTerminator = 1 in {
1064   // FIXME: The pattern part is blank because I cannot (or do not yet know
1065   // how to) use the first operand of PredicateOperand (a RegPred register) here
1066   def BRAdp
1067     : InstPTX<(outs), (ins brtarget:$d), "bra\t$d",
1068               [/*(brcond pred:$_p, bb:$d)*/]>;
1069 }
1070
1071 let isReturn = 1, isTerminator = 1, isBarrier = 1 in {
1072   def EXIT : InstPTX<(outs), (ins), "exit", [(PTXexit)]>;
1073   def RET  : InstPTX<(outs), (ins), "ret",  [(PTXret)]>;
1074 }
1075
1076 ///===- Spill Instructions ------------------------------------------------===//
1077 // Special instructions used for stack spilling
1078 def STACKSTOREI16 : InstPTX<(outs), (ins i32imm:$d, RegI16:$a),
1079                             "mov.u16\ts$d, $a", []>;
1080 def STACKSTOREI32 : InstPTX<(outs), (ins i32imm:$d, RegI32:$a),
1081                             "mov.u32\ts$d, $a", []>;
1082 def STACKSTOREI64 : InstPTX<(outs), (ins i32imm:$d, RegI64:$a),
1083                             "mov.u64\ts$d, $a", []>;
1084 def STACKSTOREF32 : InstPTX<(outs), (ins i32imm:$d, RegF32:$a),
1085                             "mov.f32\ts$d, $a", []>;
1086 def STACKSTOREF64 : InstPTX<(outs), (ins i32imm:$d, RegF64:$a),
1087                             "mov.f64\ts$d, $a", []>;
1088
1089 def STACKLOADI16 : InstPTX<(outs), (ins RegI16:$d, i32imm:$a),
1090                            "mov.u16\t$d, s$a", []>;
1091 def STACKLOADI32 : InstPTX<(outs), (ins RegI32:$d, i32imm:$a),
1092                            "mov.u32\t$d, s$a", []>;
1093 def STACKLOADI64 : InstPTX<(outs), (ins RegI64:$d, i32imm:$a),
1094                            "mov.u64\t$d, s$a", []>;
1095 def STACKLOADF32 : InstPTX<(outs), (ins RegF32:$d, i32imm:$a),
1096                            "mov.f32\t$d, s$a", []>;
1097 def STACKLOADF64 : InstPTX<(outs), (ins RegF64:$d, i32imm:$a),
1098                            "mov.f64\t$d, s$a", []>;
1099
1100 ///===- Intrinsic Instructions --------------------------------------------===//
1101
1102 include "PTXIntrinsicInstrInfo.td"