ptx: add integer div and rem instruction
[oota-llvm.git] / 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().use64BitAddresses()">;
26 def Use64BitAddresses : Predicate<"getSubtarget().use64BitAddresses()">;
27
28 // Shader Model Support
29 def SupportsSM13       : Predicate<"getSubtarget().supportsSM13()">;
30 def DoesNotSupportSM13 : Predicate<"!getSubtarget().supportsSM13()">;
31 def SupportsSM20       : Predicate<"getSubtarget().supportsSM20()">;
32 def DoesNotSupportSM20 : Predicate<"!getSubtarget().supportsSM20()">;
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
40 //===----------------------------------------------------------------------===//
41 // Instruction Pattern Stuff
42 //===----------------------------------------------------------------------===//
43
44 def load_global : PatFrag<(ops node:$ptr), (load node:$ptr), [{
45   const Value *Src;
46   const PointerType *PT;
47   if ((Src = cast<LoadSDNode>(N)->getSrcValue()) &&
48       (PT = dyn_cast<PointerType>(Src->getType())))
49     return PT->getAddressSpace() == PTX::GLOBAL;
50   return false;
51 }]>;
52
53 def load_constant : PatFrag<(ops node:$ptr), (load node:$ptr), [{
54   const Value *Src;
55   const PointerType *PT;
56   if ((Src = cast<LoadSDNode>(N)->getSrcValue()) &&
57       (PT = dyn_cast<PointerType>(Src->getType())))
58     return PT->getAddressSpace() == PTX::CONSTANT;
59   return false;
60 }]>;
61
62 def load_local : PatFrag<(ops node:$ptr), (load node:$ptr), [{
63   const Value *Src;
64   const PointerType *PT;
65   if ((Src = cast<LoadSDNode>(N)->getSrcValue()) &&
66       (PT = dyn_cast<PointerType>(Src->getType())))
67     return PT->getAddressSpace() == PTX::LOCAL;
68   return false;
69 }]>;
70
71 def load_parameter : PatFrag<(ops node:$ptr), (load node:$ptr), [{
72   const Value *Src;
73   const PointerType *PT;
74   if ((Src = cast<LoadSDNode>(N)->getSrcValue()) &&
75       (PT = dyn_cast<PointerType>(Src->getType())))
76     return PT->getAddressSpace() == PTX::PARAMETER;
77   return false;
78 }]>;
79
80 def load_shared : PatFrag<(ops node:$ptr), (load node:$ptr), [{
81   const Value *Src;
82   const PointerType *PT;
83   if ((Src = cast<LoadSDNode>(N)->getSrcValue()) &&
84       (PT = dyn_cast<PointerType>(Src->getType())))
85     return PT->getAddressSpace() == PTX::SHARED;
86   return false;
87 }]>;
88
89 def store_global
90   : PatFrag<(ops node:$d, node:$ptr), (store node:$d, node:$ptr), [{
91   const Value *Src;
92   const PointerType *PT;
93   if ((Src = cast<StoreSDNode>(N)->getSrcValue()) &&
94       (PT = dyn_cast<PointerType>(Src->getType())))
95     return PT->getAddressSpace() == PTX::GLOBAL;
96   return false;
97 }]>;
98
99 def store_local
100   : PatFrag<(ops node:$d, node:$ptr), (store node:$d, node:$ptr), [{
101   const Value *Src;
102   const PointerType *PT;
103   if ((Src = cast<StoreSDNode>(N)->getSrcValue()) &&
104       (PT = dyn_cast<PointerType>(Src->getType())))
105     return PT->getAddressSpace() == PTX::LOCAL;
106   return false;
107 }]>;
108
109 def store_parameter
110   : PatFrag<(ops node:$d, node:$ptr), (store node:$d, node:$ptr), [{
111   const Value *Src;
112   const PointerType *PT;
113   if ((Src = cast<StoreSDNode>(N)->getSrcValue()) &&
114       (PT = dyn_cast<PointerType>(Src->getType())))
115     return PT->getAddressSpace() == PTX::PARAMETER;
116   return false;
117 }]>;
118
119 def store_shared
120   : PatFrag<(ops node:$d, node:$ptr), (store node:$d, node:$ptr), [{
121   const Value *Src;
122   const PointerType *PT;
123   if ((Src = cast<StoreSDNode>(N)->getSrcValue()) &&
124       (PT = dyn_cast<PointerType>(Src->getType())))
125     return PT->getAddressSpace() == PTX::SHARED;
126   return false;
127 }]>;
128
129 // Addressing modes.
130 def ADDRrr32 : ComplexPattern<i32, 2, "SelectADDRrr", [], []>;
131 def ADDRrr64 : ComplexPattern<i64, 2, "SelectADDRrr", [], []>;
132 def ADDRri32 : ComplexPattern<i32, 2, "SelectADDRri", [], []>;
133 def ADDRri64 : ComplexPattern<i64, 2, "SelectADDRri", [], []>;
134 def ADDRii32 : ComplexPattern<i32, 2, "SelectADDRii", [], []>;
135 def ADDRii64 : ComplexPattern<i64, 2, "SelectADDRii", [], []>;
136
137 // Address operands
138 def MEMri32 : Operand<i32> {
139   let PrintMethod = "printMemOperand";
140   let MIOperandInfo = (ops RRegu32, i32imm);
141 }
142 def MEMri64 : Operand<i64> {
143   let PrintMethod = "printMemOperand";
144   let MIOperandInfo = (ops RRegu64, i64imm);
145 }
146 def MEMii32 : Operand<i32> {
147   let PrintMethod = "printMemOperand";
148   let MIOperandInfo = (ops i32imm, i32imm);
149 }
150 def MEMii64 : Operand<i64> {
151   let PrintMethod = "printMemOperand";
152   let MIOperandInfo = (ops i64imm, i64imm);
153 }
154 // The operand here does not correspond to an actual address, so we
155 // can use i32 in 64-bit address modes.
156 def MEMpi : Operand<i32> {
157   let PrintMethod = "printParamOperand";
158   let MIOperandInfo = (ops i32imm);
159 }
160
161 // Branch & call targets have OtherVT type.
162 def brtarget   : Operand<OtherVT>;
163 def calltarget : Operand<i32>;
164
165 //===----------------------------------------------------------------------===//
166 // PTX Specific Node Definitions
167 //===----------------------------------------------------------------------===//
168
169 // PTX allow generic 3-reg shifts like shl r0, r1, r2
170 def PTXshl : SDNode<"ISD::SHL", SDTIntBinOp>;
171 def PTXsrl : SDNode<"ISD::SRL", SDTIntBinOp>;
172 def PTXsra : SDNode<"ISD::SRA", SDTIntBinOp>;
173
174 def PTXexit
175   : SDNode<"PTXISD::EXIT", SDTNone, [SDNPHasChain]>;
176 def PTXret
177   : SDNode<"PTXISD::RET",  SDTNone, [SDNPHasChain]>;
178 def PTXcopyaddress
179   : SDNode<"PTXISD::COPY_ADDRESS", SDTypeProfile<1, 1, []>, []>;
180
181 //===----------------------------------------------------------------------===//
182 // Instruction Class Templates
183 //===----------------------------------------------------------------------===//
184
185 //===- Floating-Point Instructions - 3 Operand Form -----------------------===//
186 multiclass PTX_FLOAT_3OP<string opcstr, SDNode opnode> {
187   def rr32 : InstPTX<(outs RRegf32:$d),
188                      (ins RRegf32:$a, RRegf32:$b),
189                      !strconcat(opcstr, ".f32\t$d, $a, $b"),
190                      [(set RRegf32:$d, (opnode RRegf32:$a, RRegf32:$b))]>;
191   def ri32 : InstPTX<(outs RRegf32:$d),
192                      (ins RRegf32:$a, f32imm:$b),
193                      !strconcat(opcstr, ".f32\t$d, $a, $b"),
194                      [(set RRegf32:$d, (opnode RRegf32:$a, fpimm:$b))]>;
195   def rr64 : InstPTX<(outs RRegf64:$d),
196                      (ins RRegf64:$a, RRegf64:$b),
197                      !strconcat(opcstr, ".f64\t$d, $a, $b"),
198                      [(set RRegf64:$d, (opnode RRegf64:$a, RRegf64:$b))]>;
199   def ri64 : InstPTX<(outs RRegf64:$d),
200                      (ins RRegf64:$a, f64imm:$b),
201                      !strconcat(opcstr, ".f64\t$d, $a, $b"),
202                      [(set RRegf64:$d, (opnode RRegf64:$a, fpimm:$b))]>;
203 }
204
205 //===- Floating-Point Instructions - 4 Operand Form -----------------------===//
206 multiclass PTX_FLOAT_4OP<string opcstr, SDNode opnode1, SDNode opnode2> {
207   def rrr32 : InstPTX<(outs RRegf32:$d),
208                       (ins RRegf32:$a, RRegf32:$b, RRegf32:$c),
209                       !strconcat(opcstr, ".f32\t$d, $a, $b, $c"),
210                       [(set RRegf32:$d, (opnode2 (opnode1 RRegf32:$a,
211                                                           RRegf32:$b),
212                                                  RRegf32:$c))]>;
213   def rri32 : InstPTX<(outs RRegf32:$d),
214                       (ins RRegf32:$a, RRegf32:$b, f32imm:$c),
215                       !strconcat(opcstr, ".f32\t$d, $a, $b, $c"),
216                       [(set RRegf32:$d, (opnode2 (opnode1 RRegf32:$a,
217                                                           RRegf32:$b),
218                                                  fpimm:$c))]>;
219   def rrr64 : InstPTX<(outs RRegf64:$d),
220                       (ins RRegf64:$a, RRegf64:$b, RRegf64:$c),
221                       !strconcat(opcstr, ".f64\t$d, $a, $b, $c"),
222                       [(set RRegf64:$d, (opnode2 (opnode1 RRegf64:$a,
223                                                           RRegf64:$b),
224                                                  RRegf64:$c))]>;
225   def rri64 : InstPTX<(outs RRegf64:$d),
226                       (ins RRegf64:$a, RRegf64:$b, f64imm:$c),
227                       !strconcat(opcstr, ".f64\t$d, $a, $b, $c"),
228                       [(set RRegf64:$d, (opnode2 (opnode1 RRegf64:$a,
229                                                           RRegf64:$b),
230                                                  fpimm:$c))]>;
231 }
232
233 multiclass INT3<string opcstr, SDNode opnode> {
234   def rr16 : InstPTX<(outs RRegu16:$d),
235                      (ins RRegu16:$a, RRegu16:$b),
236                      !strconcat(opcstr, ".u16\t$d, $a, $b"),
237                      [(set RRegu16:$d, (opnode RRegu16:$a, RRegu16:$b))]>;
238   def ri16 : InstPTX<(outs RRegu16:$d),
239                      (ins RRegu16:$a, i16imm:$b),
240                      !strconcat(opcstr, ".u16\t$d, $a, $b"),
241                      [(set RRegu16:$d, (opnode RRegu16:$a, imm:$b))]>;
242   def rr32 : InstPTX<(outs RRegu32:$d),
243                      (ins RRegu32:$a, RRegu32:$b),
244                      !strconcat(opcstr, ".u32\t$d, $a, $b"),
245                      [(set RRegu32:$d, (opnode RRegu32:$a, RRegu32:$b))]>;
246   def ri32 : InstPTX<(outs RRegu32:$d),
247                      (ins RRegu32:$a, i32imm:$b),
248                      !strconcat(opcstr, ".u32\t$d, $a, $b"),
249                      [(set RRegu32:$d, (opnode RRegu32:$a, imm:$b))]>;
250   def rr64 : InstPTX<(outs RRegu64:$d),
251                      (ins RRegu64:$a, RRegu64:$b),
252                      !strconcat(opcstr, ".u64\t$d, $a, $b"),
253                      [(set RRegu64:$d, (opnode RRegu64:$a, RRegu64:$b))]>;
254   def ri64 : InstPTX<(outs RRegu64:$d),
255                      (ins RRegu64:$a, i64imm:$b),
256                      !strconcat(opcstr, ".u64\t$d, $a, $b"),
257                      [(set RRegu64:$d, (opnode RRegu64:$a, imm:$b))]>;
258 }
259
260 multiclass PTX_LOGIC<string opcstr, SDNode opnode> {
261   def rr16 : InstPTX<(outs RRegu16:$d),
262                      (ins RRegu16:$a, RRegu16:$b),
263                      !strconcat(opcstr, ".b16\t$d, $a, $b"),
264                      [(set RRegu16:$d, (opnode RRegu16:$a, RRegu16:$b))]>;
265   def ri16 : InstPTX<(outs RRegu16:$d),
266                      (ins RRegu16:$a, i16imm:$b),
267                      !strconcat(opcstr, ".b16\t$d, $a, $b"),
268                      [(set RRegu16:$d, (opnode RRegu16:$a, imm:$b))]>;
269   def rr32 : InstPTX<(outs RRegu32:$d),
270                      (ins RRegu32:$a, RRegu32:$b),
271                      !strconcat(opcstr, ".b32\t$d, $a, $b"),
272                      [(set RRegu32:$d, (opnode RRegu32:$a, RRegu32:$b))]>;
273   def ri32 : InstPTX<(outs RRegu32:$d),
274                      (ins RRegu32:$a, i32imm:$b),
275                      !strconcat(opcstr, ".b32\t$d, $a, $b"),
276                      [(set RRegu32:$d, (opnode RRegu32:$a, imm:$b))]>;
277   def rr64 : InstPTX<(outs RRegu64:$d),
278                      (ins RRegu64:$a, RRegu64:$b),
279                      !strconcat(opcstr, ".b64\t$d, $a, $b"),
280                      [(set RRegu64:$d, (opnode RRegu64:$a, RRegu64:$b))]>;
281   def ri64 : InstPTX<(outs RRegu64:$d),
282                      (ins RRegu64:$a, i64imm:$b),
283                      !strconcat(opcstr, ".b64\t$d, $a, $b"),
284                      [(set RRegu64:$d, (opnode RRegu64:$a, imm:$b))]>;
285 }
286
287 multiclass INT3ntnc<string opcstr, SDNode opnode> {
288   def rr16 : InstPTX<(outs RRegu16:$d),
289                      (ins RRegu16:$a, RRegu16:$b),
290                      !strconcat(opcstr, "16\t$d, $a, $b"),
291                      [(set RRegu16:$d, (opnode RRegu16:$a, RRegu16:$b))]>;
292   def rr32 : InstPTX<(outs RRegu32:$d),
293                      (ins RRegu32:$a, RRegu32:$b),
294                      !strconcat(opcstr, "32\t$d, $a, $b"),
295                      [(set RRegu32:$d, (opnode RRegu32:$a, RRegu32:$b))]>;
296   def rr64 : InstPTX<(outs RRegu64:$d),
297                      (ins RRegu64:$a, RRegu64:$b),
298                      !strconcat(opcstr, "64\t$d, $a, $b"),
299                      [(set RRegu64:$d, (opnode RRegu64:$a, RRegu64:$b))]>;
300   def ri16 : InstPTX<(outs RRegu16:$d),
301                      (ins RRegu16:$a, i16imm:$b),
302                      !strconcat(opcstr, "16\t$d, $a, $b"),
303                      [(set RRegu16:$d, (opnode RRegu16:$a, imm:$b))]>;
304   def ri32 : InstPTX<(outs RRegu32:$d),
305                      (ins RRegu32:$a, i32imm:$b),
306                      !strconcat(opcstr, "32\t$d, $a, $b"),
307                      [(set RRegu32:$d, (opnode RRegu32:$a, imm:$b))]>;
308   def ri64 : InstPTX<(outs RRegu64:$d),
309                      (ins RRegu64:$a, i64imm:$b),
310                      !strconcat(opcstr, "64\t$d, $a, $b"),
311                      [(set RRegu64:$d, (opnode RRegu64:$a, imm:$b))]>;
312   def ir16 : InstPTX<(outs RRegu16:$d),
313                      (ins i16imm:$a, RRegu16:$b),
314                      !strconcat(opcstr, "16\t$d, $a, $b"),
315                      [(set RRegu16:$d, (opnode imm:$a, RRegu16:$b))]>;
316   def ir32 : InstPTX<(outs RRegu32:$d),
317                      (ins i32imm:$a, RRegu32:$b),
318                      !strconcat(opcstr, "32\t$d, $a, $b"),
319                      [(set RRegu32:$d, (opnode imm:$a, RRegu32:$b))]>;
320   def ir64 : InstPTX<(outs RRegu64:$d),
321                      (ins i64imm:$a, RRegu64:$b),
322                      !strconcat(opcstr, "64\t$d, $a, $b"),
323                      [(set RRegu64:$d, (opnode imm:$a, RRegu64:$b))]>;
324 }
325
326 multiclass PTX_SETP_I<RegisterClass RC, string regclsname, Operand immcls,
327                         CondCode cmp, string cmpstr> {
328   // TODO support 5-operand format: p|q, a, b, c
329
330   def rr
331     : InstPTX<(outs Preds:$p), (ins RC:$a, RC:$b),
332               !strconcat("setp.", cmpstr, ".", regclsname, "\t$p, $a, $b"),
333               [(set Preds:$p, (setcc RC:$a, RC:$b, cmp))]>;
334   def ri
335     : InstPTX<(outs Preds:$p), (ins RC:$a, immcls:$b),
336               !strconcat("setp.", cmpstr, ".", regclsname, "\t$p, $a, $b"),
337               [(set Preds:$p, (setcc RC:$a, imm:$b, cmp))]>;
338
339   def rr_and_r
340     : InstPTX<(outs Preds:$p), (ins RC:$a, RC:$b, Preds:$c),
341               !strconcat("setp.", cmpstr, ".and.", regclsname, "\t$p, $a, $b, $c"),
342               [(set Preds:$p, (and (setcc RC:$a, RC:$b, cmp), Preds:$c))]>;
343   def ri_and_r
344     : InstPTX<(outs Preds:$p), (ins RC:$a, immcls:$b, Preds:$c),
345               !strconcat("setp.", cmpstr, ".and.", regclsname, "\t$p, $a, $b, $c"),
346               [(set Preds:$p, (and (setcc RC:$a, imm:$b, cmp), Preds:$c))]>;
347   def rr_or_r
348     : InstPTX<(outs Preds:$p), (ins RC:$a, RC:$b, Preds:$c),
349               !strconcat("setp.", cmpstr, ".or.", regclsname, "\t$p, $a, $b, $c"),
350               [(set Preds:$p, (or (setcc RC:$a, RC:$b, cmp), Preds:$c))]>;
351   def ri_or_r
352     : InstPTX<(outs Preds:$p), (ins RC:$a, immcls:$b, Preds:$c),
353               !strconcat("setp.", cmpstr, ".or.", regclsname, "\t$p, $a, $b, $c"),
354               [(set Preds:$p, (or (setcc RC:$a, imm:$b, cmp), Preds:$c))]>;
355   def rr_xor_r
356     : InstPTX<(outs Preds:$p), (ins RC:$a, RC:$b, Preds:$c),
357               !strconcat("setp.", cmpstr, ".xor.", regclsname, "\t$p, $a, $b, $c"),
358               [(set Preds:$p, (xor (setcc RC:$a, RC:$b, cmp), Preds:$c))]>;
359   def ri_xor_r
360     : InstPTX<(outs Preds:$p), (ins RC:$a, immcls:$b, Preds:$c),
361               !strconcat("setp.", cmpstr, ".xor.", regclsname, "\t$p, $a, $b, $c"),
362               [(set Preds:$p, (xor (setcc RC:$a, imm:$b, cmp), Preds:$c))]>;
363
364   def rr_and_not_r
365     : InstPTX<(outs Preds:$p), (ins RC:$a, RC:$b, Preds:$c),
366               !strconcat("setp.", cmpstr, ".and.", regclsname, "\t$p, $a, $b, !$c"),
367               [(set Preds:$p, (and (setcc RC:$a, RC:$b, cmp), (not Preds:$c)))]>;
368   def ri_and_not_r
369     : InstPTX<(outs Preds:$p), (ins RC:$a, immcls:$b, Preds:$c),
370               !strconcat("setp.", cmpstr, ".and.", regclsname, "\t$p, $a, $b, !$c"),
371               [(set Preds:$p, (and (setcc RC:$a, imm:$b, cmp), (not Preds:$c)))]>;
372   def rr_or_not_r
373     : InstPTX<(outs Preds:$p), (ins RC:$a, RC:$b, Preds:$c),
374               !strconcat("setp.", cmpstr, ".or.", regclsname, "\t$p, $a, $b, !$c"),
375               [(set Preds:$p, (or (setcc RC:$a, RC:$b, cmp), (not Preds:$c)))]>;
376   def ri_or_not_r
377     : InstPTX<(outs Preds:$p), (ins RC:$a, immcls:$b, Preds:$c),
378               !strconcat("setp.", cmpstr, ".or.", regclsname, "\t$p, $a, $b, !$c"),
379               [(set Preds:$p, (or (setcc RC:$a, imm:$b, cmp), (not Preds:$c)))]>;
380   def rr_xor_not_r
381     : InstPTX<(outs Preds:$p), (ins RC:$a, RC:$b, Preds:$c),
382               !strconcat("setp.", cmpstr, ".xor.", regclsname, "\t$p, $a, $b, !$c"),
383               [(set Preds:$p, (xor (setcc RC:$a, RC:$b, cmp), (not Preds:$c)))]>;
384   def ri_xor_not_r
385     : InstPTX<(outs Preds:$p), (ins RC:$a, immcls:$b, Preds:$c),
386               !strconcat("setp.", cmpstr, ".xor.", regclsname, "\t$p, $a, $b, !$c"),
387               [(set Preds:$p, (xor (setcc RC:$a, imm:$b, cmp), (not Preds:$c)))]>;
388 }
389
390 multiclass PTX_SETP_FP<RegisterClass RC, string regclsname,
391                         CondCode ucmp, CondCode ocmp, string cmpstr> {
392   // TODO support 5-operand format: p|q, a, b, c
393
394   def rr_u
395     : InstPTX<(outs Preds:$p), (ins RC:$a, RC:$b),
396               !strconcat("setp.", cmpstr, "u.", regclsname, "\t$p, $a, $b"),
397               [(set Preds:$p, (setcc RC:$a, RC:$b, ucmp))]>;
398   def rr_o
399     : InstPTX<(outs Preds:$p), (ins RC:$a, RC:$b),
400               !strconcat("setp.", cmpstr, ".", regclsname, "\t$p, $a, $b"),
401               [(set Preds:$p, (setcc RC:$a, RC:$b, ocmp))]>;
402
403   def rr_and_r_u
404     : InstPTX<(outs Preds:$p), (ins RC:$a, RC:$b, Preds:$c),
405               !strconcat("setp.", cmpstr, "u.and.", regclsname, "\t$p, $a, $b, $c"),
406               [(set Preds:$p, (and (setcc RC:$a, RC:$b, ucmp), Preds:$c))]>;
407   def rr_and_r_o
408     : InstPTX<(outs Preds:$p), (ins RC:$a, RC:$b, Preds:$c),
409               !strconcat("setp.", cmpstr, ".and.", regclsname, "\t$p, $a, $b, $c"),
410               [(set Preds:$p, (and (setcc RC:$a, RC:$b, ocmp), Preds:$c))]>;
411
412   def rr_or_r_u
413     : InstPTX<(outs Preds:$p), (ins RC:$a, RC:$b, Preds:$c),
414               !strconcat("setp.", cmpstr, "u.or.", regclsname, "\t$p, $a, $b, $c"),
415               [(set Preds:$p, (or (setcc RC:$a, RC:$b, ucmp), Preds:$c))]>;
416   def rr_or_r_o
417     : InstPTX<(outs Preds:$p), (ins RC:$a, RC:$b, Preds:$c),
418               !strconcat("setp.", cmpstr, ".or.", regclsname, "\t$p, $a, $b, $c"),
419               [(set Preds:$p, (or (setcc RC:$a, RC:$b, ocmp), Preds:$c))]>;
420
421   def rr_xor_r_u
422     : InstPTX<(outs Preds:$p), (ins RC:$a, RC:$b, Preds:$c),
423               !strconcat("setp.", cmpstr, "u.xor.", regclsname, "\t$p, $a, $b, $c"),
424               [(set Preds:$p, (xor (setcc RC:$a, RC:$b, ucmp), Preds:$c))]>;
425   def rr_xor_r_o
426     : InstPTX<(outs Preds:$p), (ins RC:$a, RC:$b, Preds:$c),
427               !strconcat("setp.", cmpstr, ".xor.", regclsname, "\t$p, $a, $b, $c"),
428               [(set Preds:$p, (xor (setcc RC:$a, RC:$b, ocmp), Preds:$c))]>;
429
430   def rr_and_not_r_u
431     : InstPTX<(outs Preds:$p), (ins RC:$a, RC:$b, Preds:$c),
432               !strconcat("setp.", cmpstr, "u.and.", regclsname, "\t$p, $a, $b, !$c"),
433               [(set Preds:$p, (and (setcc RC:$a, RC:$b, ucmp), (not Preds:$c)))]>;
434   def rr_and_not_r_o
435     : InstPTX<(outs Preds:$p), (ins RC:$a, RC:$b, Preds:$c),
436               !strconcat("setp.", cmpstr, ".and.", regclsname, "\t$p, $a, $b, !$c"),
437               [(set Preds:$p, (and (setcc RC:$a, RC:$b, ocmp), (not Preds:$c)))]>;
438
439   def rr_or_not_r_u
440     : InstPTX<(outs Preds:$p), (ins RC:$a, RC:$b, Preds:$c),
441               !strconcat("setp.", cmpstr, "u.or.", regclsname, "\t$p, $a, $b, !$c"),
442               [(set Preds:$p, (or (setcc RC:$a, RC:$b, ucmp), (not Preds:$c)))]>;
443   def rr_or_not_r_o
444     : InstPTX<(outs Preds:$p), (ins RC:$a, RC:$b, Preds:$c),
445               !strconcat("setp.", cmpstr, ".or.", regclsname, "\t$p, $a, $b, !$c"),
446               [(set Preds:$p, (or (setcc RC:$a, RC:$b, ocmp), (not Preds:$c)))]>;
447
448   def rr_xor_not_r_u
449     : InstPTX<(outs Preds:$p), (ins RC:$a, RC:$b, Preds:$c),
450               !strconcat("setp.", cmpstr, "u.xor.", regclsname, "\t$p, $a, $b, !$c"),
451               [(set Preds:$p, (xor (setcc RC:$a, RC:$b, ucmp), (not Preds:$c)))]>;
452   def rr_xor_not_r_o
453     : InstPTX<(outs Preds:$p), (ins RC:$a, RC:$b, Preds:$c),
454               !strconcat("setp.", cmpstr, ".xor.", regclsname, "\t$p, $a, $b, !$c"),
455               [(set Preds:$p, (xor (setcc RC:$a, RC:$b, ocmp), (not Preds:$c)))]>;
456 }
457
458 multiclass PTX_LD<string opstr, string typestr, RegisterClass RC, PatFrag pat_load> {
459   def rr32 : InstPTX<(outs RC:$d),
460                      (ins MEMri32:$a),
461                      !strconcat(opstr, !strconcat(typestr, "\t$d, [$a]")),
462                      [(set RC:$d, (pat_load ADDRrr32:$a))]>, Requires<[Use32BitAddresses]>;
463   def rr64 : InstPTX<(outs RC:$d),
464                      (ins MEMri64:$a),
465                      !strconcat(opstr, !strconcat(typestr, "\t$d, [$a]")),
466                      [(set RC:$d, (pat_load ADDRrr64:$a))]>, Requires<[Use64BitAddresses]>;
467   def ri32 : InstPTX<(outs RC:$d),
468                      (ins MEMri32:$a),
469                      !strconcat(opstr, !strconcat(typestr, "\t$d, [$a]")),
470                      [(set RC:$d, (pat_load ADDRri32:$a))]>, Requires<[Use32BitAddresses]>;
471   def ri64 : InstPTX<(outs RC:$d),
472                      (ins MEMri64:$a),
473                      !strconcat(opstr, !strconcat(typestr, "\t$d, [$a]")),
474                      [(set RC:$d, (pat_load ADDRri64:$a))]>, Requires<[Use64BitAddresses]>;
475   def ii32 : InstPTX<(outs RC:$d),
476                      (ins MEMii32:$a),
477                      !strconcat(opstr, !strconcat(typestr, "\t$d, [$a]")),
478                      [(set RC:$d, (pat_load ADDRii32:$a))]>, Requires<[Use32BitAddresses]>;
479   def ii64 : InstPTX<(outs RC:$d),
480                      (ins MEMii64:$a),
481                      !strconcat(opstr, !strconcat(typestr, "\t$d, [$a]")),
482                      [(set RC:$d, (pat_load ADDRii64:$a))]>, Requires<[Use64BitAddresses]>;
483 }
484
485 multiclass PTX_LD_ALL<string opstr, PatFrag pat_load> {
486   defm u16 : PTX_LD<opstr, ".u16", RRegu16, pat_load>;
487   defm u32 : PTX_LD<opstr, ".u32", RRegu32, pat_load>;
488   defm u64 : PTX_LD<opstr, ".u64", RRegu64, pat_load>;
489   defm f32 : PTX_LD<opstr, ".f32", RRegf32, pat_load>;
490   defm f64 : PTX_LD<opstr, ".f64", RRegf64, pat_load>;
491 }
492
493 multiclass PTX_ST<string opstr, string typestr, RegisterClass RC, PatFrag pat_store> {
494   def rr32 : InstPTX<(outs),
495                      (ins RC:$d, MEMri32:$a),
496                      !strconcat(opstr, !strconcat(typestr, "\t[$a], $d")),
497                      [(pat_store RC:$d, ADDRrr32:$a)]>, Requires<[Use32BitAddresses]>;
498   def rr64 : InstPTX<(outs),
499                      (ins RC:$d, MEMri64:$a),
500                      !strconcat(opstr, !strconcat(typestr, "\t[$a], $d")),
501                      [(pat_store RC:$d, ADDRrr64:$a)]>, Requires<[Use64BitAddresses]>;
502   def ri32 : InstPTX<(outs),
503                    (ins RC:$d, MEMri32:$a),
504                    !strconcat(opstr, !strconcat(typestr, "\t[$a], $d")),
505                    [(pat_store RC:$d, ADDRri32:$a)]>, Requires<[Use32BitAddresses]>;
506   def ri64 : InstPTX<(outs),
507                    (ins RC:$d, MEMri64:$a),
508                    !strconcat(opstr, !strconcat(typestr, "\t[$a], $d")),
509                    [(pat_store RC:$d, ADDRri64:$a)]>, Requires<[Use64BitAddresses]>;
510   def ii32 : InstPTX<(outs),
511                    (ins RC:$d, MEMii32:$a),
512                    !strconcat(opstr, !strconcat(typestr, "\t[$a], $d")),
513                    [(pat_store RC:$d, ADDRii32:$a)]>, Requires<[Use32BitAddresses]>;
514   def ii64 : InstPTX<(outs),
515                    (ins RC:$d, MEMii64:$a),
516                    !strconcat(opstr, !strconcat(typestr, "\t[$a], $d")),
517                    [(pat_store RC:$d, ADDRii64:$a)]>, Requires<[Use64BitAddresses]>;
518 }
519
520 multiclass PTX_ST_ALL<string opstr, PatFrag pat_store> {
521   defm u16 : PTX_ST<opstr, ".u16", RRegu16, pat_store>;
522   defm u32 : PTX_ST<opstr, ".u32", RRegu32, pat_store>;
523   defm u64 : PTX_ST<opstr, ".u64", RRegu64, pat_store>;
524   defm f32 : PTX_ST<opstr, ".f32", RRegf32, pat_store>;
525   defm f64 : PTX_ST<opstr, ".f64", RRegf64, pat_store>;
526 }
527
528 //===----------------------------------------------------------------------===//
529 // Instructions
530 //===----------------------------------------------------------------------===//
531
532 ///===- Integer Arithmetic Instructions -----------------------------------===//
533
534 defm ADD : INT3<"add", add>;
535 defm SUB : INT3<"sub", sub>;
536 defm MUL : INT3<"mul.lo", mul>; // FIXME: Allow 32x32 -> 64 multiplies
537 defm DIV : INT3<"div", udiv>;
538 defm REM : INT3<"rem", urem>;
539
540 ///===- Floating-Point Arithmetic Instructions ----------------------------===//
541
542 // Standard Binary Operations
543 defm FADD : PTX_FLOAT_3OP<"add", fadd>;
544 defm FSUB : PTX_FLOAT_3OP<"sub", fsub>;
545 defm FMUL : PTX_FLOAT_3OP<"mul", fmul>;
546
547 // TODO: Allow user selection of rounding modes for fdiv.
548 // For division, we need to have f32 and f64 differently.
549 // For f32, we just always use .approx since it is supported on all hardware
550 // for PTX 1.4+, which is our minimum target.
551 def FDIVrr32 : InstPTX<(outs RRegf32:$d),
552                        (ins RRegf32:$a, RRegf32:$b),
553                        "div.approx.f32\t$d, $a, $b",
554                        [(set RRegf32:$d, (fdiv RRegf32:$a, RRegf32:$b))]>;
555 def FDIVri32 : InstPTX<(outs RRegf32:$d),
556                        (ins RRegf32:$a, f32imm:$b),
557                        "div.approx.f32\t$d, $a, $b",
558                        [(set RRegf32:$d, (fdiv RRegf32:$a, fpimm:$b))]>;
559
560 // For f64, we must specify a rounding for sm 1.3+ but *not* for sm 1.0.
561 def FDIVrr64SM13 : InstPTX<(outs RRegf64:$d),
562                            (ins RRegf64:$a, RRegf64:$b),
563                            "div.rn.f64\t$d, $a, $b",
564                            [(set RRegf64:$d, (fdiv RRegf64:$a, RRegf64:$b))]>,
565                    Requires<[SupportsSM13]>;
566 def FDIVri64SM13 : InstPTX<(outs RRegf64:$d),
567                            (ins RRegf64:$a, f64imm:$b),
568                            "div.rn.f64\t$d, $a, $b",
569                            [(set RRegf64:$d, (fdiv RRegf64:$a, fpimm:$b))]>,
570                    Requires<[SupportsSM13]>;
571 def FDIVrr64SM10 : InstPTX<(outs RRegf64:$d),
572                            (ins RRegf64:$a, RRegf64:$b),
573                            "div.f64\t$d, $a, $b",
574                            [(set RRegf64:$d, (fdiv RRegf64:$a, RRegf64:$b))]>,
575                    Requires<[DoesNotSupportSM13]>;
576 def FDIVri64SM10 : InstPTX<(outs RRegf64:$d),
577                            (ins RRegf64:$a, f64imm:$b),
578                            "div.f64\t$d, $a, $b",
579                            [(set RRegf64:$d, (fdiv RRegf64:$a, fpimm:$b))]>,
580                    Requires<[DoesNotSupportSM13]>;
581
582
583
584 // Multi-operation hybrid instructions
585
586 // The selection of mad/fma is tricky.  In some cases, they are the *same*
587 // instruction, but in other cases we may prefer one or the other.  Also,
588 // different PTX versions differ on whether rounding mode flags are required.
589 // In the short term, mad is supported on all PTX versions and we use a
590 // default rounding mode no matter what shader model or PTX version.
591 // TODO: Allow the rounding mode to be selectable through llc.
592 defm FMADSM13 : PTX_FLOAT_4OP<"mad.rn", fmul, fadd>, Requires<[SupportsSM13]>;
593 defm FMAD : PTX_FLOAT_4OP<"mad", fmul, fadd>, Requires<[DoesNotSupportSM13]>;
594
595 ///===- Floating-Point Intrinsic Instructions -----------------------------===//
596
597 def FSQRT32 : InstPTX<(outs RRegf32:$d),
598                       (ins RRegf32:$a),
599                       "sqrt.rn.f32\t$d, $a",
600                       [(set RRegf32:$d, (fsqrt RRegf32:$a))]>;
601
602 def FSQRT64 : InstPTX<(outs RRegf64:$d),
603                       (ins RRegf64:$a),
604                       "sqrt.rn.f64\t$d, $a",
605                       [(set RRegf64:$d, (fsqrt RRegf64:$a))]>;
606
607 def FSIN32 : InstPTX<(outs RRegf32:$d),
608                      (ins RRegf32:$a),
609                      "sin.approx.f32\t$d, $a",
610                      [(set RRegf32:$d, (fsin RRegf32:$a))]>;
611
612 def FSIN64 : InstPTX<(outs RRegf64:$d),
613                      (ins RRegf64:$a),
614                      "sin.approx.f64\t$d, $a",
615                      [(set RRegf64:$d, (fsin RRegf64:$a))]>;
616
617 def FCOS32 : InstPTX<(outs RRegf32:$d),
618                      (ins RRegf32:$a),
619                      "cos.approx.f32\t$d, $a",
620                      [(set RRegf32:$d, (fcos RRegf32:$a))]>;
621
622 def FCOS64 : InstPTX<(outs RRegf64:$d),
623                      (ins RRegf64:$a),
624                      "cos.approx.f64\t$d, $a",
625                      [(set RRegf64:$d, (fcos RRegf64:$a))]>;
626
627
628 ///===- Comparison and Selection Instructions -----------------------------===//
629
630 // Compare u16
631
632 defm SETPEQu16 : PTX_SETP_I<RRegu16, "u16", i16imm, SETEQ,  "eq">;
633 defm SETPNEu16 : PTX_SETP_I<RRegu16, "u16", i16imm, SETNE,  "ne">;
634 defm SETPLTu16 : PTX_SETP_I<RRegu16, "u16", i16imm, SETULT, "lt">;
635 defm SETPLEu16 : PTX_SETP_I<RRegu16, "u16", i16imm, SETULE, "le">;
636 defm SETPGTu16 : PTX_SETP_I<RRegu16, "u16", i16imm, SETUGT, "gt">;
637 defm SETPGEu16 : PTX_SETP_I<RRegu16, "u16", i16imm, SETUGE, "ge">;
638
639 // Compare u32
640
641 defm SETPEQu32 : PTX_SETP_I<RRegu32, "u32", i32imm, SETEQ,  "eq">;
642 defm SETPNEu32 : PTX_SETP_I<RRegu32, "u32", i32imm, SETNE,  "ne">;
643 defm SETPLTu32 : PTX_SETP_I<RRegu32, "u32", i32imm, SETULT, "lt">;
644 defm SETPLEu32 : PTX_SETP_I<RRegu32, "u32", i32imm, SETULE, "le">;
645 defm SETPGTu32 : PTX_SETP_I<RRegu32, "u32", i32imm, SETUGT, "gt">;
646 defm SETPGEu32 : PTX_SETP_I<RRegu32, "u32", i32imm, SETUGE, "ge">;
647
648 // Compare u64
649
650 defm SETPEQu64 : PTX_SETP_I<RRegu64, "u64", i64imm, SETEQ,  "eq">;
651 defm SETPNEu64 : PTX_SETP_I<RRegu64, "u64", i64imm, SETNE,  "ne">;
652 defm SETPLTu64 : PTX_SETP_I<RRegu64, "u64", i64imm, SETULT, "lt">;
653 defm SETPLEu64 : PTX_SETP_I<RRegu64, "u64", i64imm, SETULE, "le">;
654 defm SETPGTu64 : PTX_SETP_I<RRegu64, "u64", i64imm, SETUGT, "gt">;
655 defm SETPGEu64 : PTX_SETP_I<RRegu64, "u64", i64imm, SETUGE, "ge">;
656
657 // Compare f32
658
659 defm SETPEQf32 : PTX_SETP_FP<RRegf32, "f32", SETUEQ, SETOEQ, "eq">;
660 defm SETPNEf32 : PTX_SETP_FP<RRegf32, "f32", SETUNE, SETONE, "ne">;
661 defm SETPLTf32 : PTX_SETP_FP<RRegf32, "f32", SETULT, SETOLT, "lt">;
662 defm SETPLEf32 : PTX_SETP_FP<RRegf32, "f32", SETULE, SETOLE, "le">;
663 defm SETPGTf32 : PTX_SETP_FP<RRegf32, "f32", SETUGT, SETOGT, "gt">;
664 defm SETPGEf32 : PTX_SETP_FP<RRegf32, "f32", SETUGE, SETOGE, "ge">;
665
666 // Compare f64
667
668 defm SETPEQf64 : PTX_SETP_FP<RRegf64, "f64", SETUEQ, SETOEQ, "eq">;
669 defm SETPNEf64 : PTX_SETP_FP<RRegf64, "f64", SETUNE, SETONE, "ne">;
670 defm SETPLTf64 : PTX_SETP_FP<RRegf64, "f64", SETULT, SETOLT, "lt">;
671 defm SETPLEf64 : PTX_SETP_FP<RRegf64, "f64", SETULE, SETOLE, "le">;
672 defm SETPGTf64 : PTX_SETP_FP<RRegf64, "f64", SETUGT, SETOGT, "gt">;
673 defm SETPGEf64 : PTX_SETP_FP<RRegf64, "f64", SETUGE, SETOGE, "ge">;
674
675 ///===- Logic and Shift Instructions --------------------------------------===//
676
677 defm SHL : INT3ntnc<"shl.b", PTXshl>;
678 defm SRL : INT3ntnc<"shr.u", PTXsrl>;
679 defm SRA : INT3ntnc<"shr.s", PTXsra>;
680
681 defm AND : PTX_LOGIC<"and", and>;
682 defm OR  : PTX_LOGIC<"or",  or>;
683 defm XOR : PTX_LOGIC<"xor", xor>;
684
685 ///===- Data Movement and Conversion Instructions -------------------------===//
686
687 let neverHasSideEffects = 1 in {
688   def MOVPREDrr
689     : InstPTX<(outs Preds:$d), (ins Preds:$a), "mov.pred\t$d, $a", []>;
690   def MOVU16rr
691     : InstPTX<(outs RRegu16:$d), (ins RRegu16:$a), "mov.u16\t$d, $a", []>;
692   def MOVU32rr
693     : InstPTX<(outs RRegu32:$d), (ins RRegu32:$a), "mov.u32\t$d, $a", []>;
694   def MOVU64rr
695     : InstPTX<(outs RRegu64:$d), (ins RRegu64:$a), "mov.u64\t$d, $a", []>;
696   def MOVF32rr
697     : InstPTX<(outs RRegf32:$d), (ins RRegf32:$a), "mov.f32\t$d, $a", []>;
698   def MOVF64rr
699     : InstPTX<(outs RRegf64:$d), (ins RRegf64:$a), "mov.f64\t$d, $a", []>;
700 }
701
702 let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
703   def MOVPREDri
704     : InstPTX<(outs Preds:$d), (ins i1imm:$a), "mov.pred\t$d, $a",
705               [(set Preds:$d, imm:$a)]>;
706   def MOVU16ri
707     : InstPTX<(outs RRegu16:$d), (ins i16imm:$a), "mov.u16\t$d, $a",
708               [(set RRegu16:$d, imm:$a)]>;
709   def MOVU32ri
710     : InstPTX<(outs RRegu32:$d), (ins i32imm:$a), "mov.u32\t$d, $a",
711               [(set RRegu32:$d, imm:$a)]>;
712   def MOVU164ri
713     : InstPTX<(outs RRegu64:$d), (ins i64imm:$a), "mov.u64\t$d, $a",
714               [(set RRegu64:$d, imm:$a)]>;
715   def MOVF32ri
716     : InstPTX<(outs RRegf32:$d), (ins f32imm:$a), "mov.f32\t$d, $a",
717               [(set RRegf32:$d, fpimm:$a)]>;
718   def MOVF64ri
719     : InstPTX<(outs RRegf64:$d), (ins f64imm:$a), "mov.f64\t$d, $a",
720               [(set RRegf64:$d, fpimm:$a)]>;
721 }
722
723 let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
724   def MOVaddr32
725     : InstPTX<(outs RRegu32:$d), (ins i32imm:$a), "mov.u32\t$d, $a",
726               [(set RRegu32:$d, (PTXcopyaddress tglobaladdr:$a))]>;
727   def MOVaddr64
728     : InstPTX<(outs RRegu64:$d), (ins i64imm:$a), "mov.u64\t$d, $a",
729               [(set RRegu64:$d, (PTXcopyaddress tglobaladdr:$a))]>;
730 }
731
732 // Loads
733 defm LDg : PTX_LD_ALL<"ld.global", load_global>;
734 defm LDc : PTX_LD_ALL<"ld.const",  load_constant>;
735 defm LDl : PTX_LD_ALL<"ld.local",  load_local>;
736 defm LDs : PTX_LD_ALL<"ld.shared", load_shared>;
737
738 // This is a special instruction that is manually inserted for kernel parameters
739 def LDpiU16 : InstPTX<(outs RRegu16:$d), (ins MEMpi:$a),
740                       "ld.param.u16\t$d, [$a]", []>;
741 def LDpiU32 : InstPTX<(outs RRegu32:$d), (ins MEMpi:$a),
742                       "ld.param.u32\t$d, [$a]", []>;
743 def LDpiU64 : InstPTX<(outs RRegu64:$d), (ins MEMpi:$a),
744                       "ld.param.u64\t$d, [$a]", []>;
745 def LDpiF32 : InstPTX<(outs RRegf32:$d), (ins MEMpi:$a),
746                       "ld.param.f32\t$d, [$a]", []>;
747 def LDpiF64 : InstPTX<(outs RRegf64:$d), (ins MEMpi:$a),
748                       "ld.param.f64\t$d, [$a]", []>;
749
750 // Stores
751 defm STg : PTX_ST_ALL<"st.global", store_global>;
752 defm STl : PTX_ST_ALL<"st.local",  store_local>;
753 defm STs : PTX_ST_ALL<"st.shared", store_shared>;
754
755 // defm STp : PTX_ST_ALL<"st.param",  store_parameter>;
756 // defm LDp : PTX_LD_ALL<"ld.param",  load_parameter>;
757 // TODO: Do something with st.param if/when it is needed.
758
759 // Conversion to pred
760
761 def CVT_pred_u16
762   : InstPTX<(outs Preds:$d), (ins RRegu16:$a), "cvt.pred.u16\t$d, $a",
763             [(set Preds:$d, (trunc RRegu16:$a))]>;
764
765 def CVT_pred_u32
766   : InstPTX<(outs Preds:$d), (ins RRegu32:$a), "cvt.pred.u32\t$d, $a",
767             [(set Preds:$d, (trunc RRegu32:$a))]>;
768
769 def CVT_pred_u64
770   : InstPTX<(outs Preds:$d), (ins RRegu64:$a), "cvt.pred.u64\t$d, $a",
771             [(set Preds:$d, (trunc RRegu64:$a))]>;
772
773 def CVT_pred_f32
774   : InstPTX<(outs Preds:$d), (ins RRegf32:$a), "cvt.pred.f32\t$d, $a",
775             [(set Preds:$d, (fp_to_uint RRegf32:$a))]>;
776
777 def CVT_pred_f64
778   : InstPTX<(outs Preds:$d), (ins RRegf64:$a), "cvt.pred.f64\t$d, $a",
779             [(set Preds:$d, (fp_to_uint RRegf64:$a))]>;
780
781 // Conversion to u16
782
783 def CVT_u16_pred
784   : InstPTX<(outs RRegu16:$d), (ins Preds:$a), "cvt.u16.pred\t$d, $a",
785             [(set RRegu16:$d, (zext Preds:$a))]>;
786
787 def CVT_u16_u32
788   : InstPTX<(outs RRegu16:$d), (ins RRegu32:$a), "cvt.u16.u32\t$d, $a",
789             [(set RRegu16:$d, (trunc RRegu32:$a))]>;
790
791 def CVT_u16_u64
792   : InstPTX<(outs RRegu16:$d), (ins RRegu64:$a), "cvt.u16.u64\t$d, $a",
793             [(set RRegu16:$d, (trunc RRegu64:$a))]>;
794
795 def CVT_u16_f32
796   : InstPTX<(outs RRegu16:$d), (ins RRegf32:$a), "cvt.u16.f32\t$d, $a",
797             [(set RRegu16:$d, (fp_to_uint RRegf32:$a))]>;
798
799 def CVT_u16_f64
800   : InstPTX<(outs RRegu16:$d), (ins RRegf64:$a), "cvt.u16.f64\t$d, $a",
801             [(set RRegu16:$d, (fp_to_uint RRegf64:$a))]>;
802
803 // Conversion to u32
804
805 def CVT_u32_pred
806   : InstPTX<(outs RRegu32:$d), (ins Preds:$a), "cvt.u32.pred\t$d, $a",
807             [(set RRegu32:$d, (zext Preds:$a))]>;
808
809 def CVT_u32_u16
810   : InstPTX<(outs RRegu32:$d), (ins RRegu16:$a), "cvt.u32.u16\t$d, $a",
811             [(set RRegu32:$d, (zext RRegu16:$a))]>;
812
813 def CVT_u32_u64
814   : InstPTX<(outs RRegu32:$d), (ins RRegu64:$a), "cvt.u32.u64\t$d, $a",
815             [(set RRegu32:$d, (trunc RRegu64:$a))]>;
816
817 def CVT_u32_f32
818   : InstPTX<(outs RRegu32:$d), (ins RRegf32:$a), "cvt.u32.f32\t$d, $a",
819             [(set RRegu32:$d, (fp_to_uint RRegf32:$a))]>;
820
821 def CVT_u32_f64
822   : InstPTX<(outs RRegu32:$d), (ins RRegf64:$a), "cvt.u32.f64\t$d, $a",
823             [(set RRegu32:$d, (fp_to_uint RRegf64:$a))]>;
824
825 // Conversion to u64
826
827 def CVT_u64_pred
828   : InstPTX<(outs RRegu64:$d), (ins Preds:$a), "cvt.u64.pred\t$d, $a",
829             [(set RRegu64:$d, (zext Preds:$a))]>;
830
831 def CVT_u64_u16
832   : InstPTX<(outs RRegu64:$d), (ins RRegu16:$a), "cvt.u64.u16\t$d, $a",
833             [(set RRegu64:$d, (zext RRegu16:$a))]>;
834
835 def CVT_u64_u32
836   : InstPTX<(outs RRegu64:$d), (ins RRegu32:$a), "cvt.u64.u32\t$d, $a",
837             [(set RRegu64:$d, (zext RRegu32:$a))]>;
838
839 def CVT_u64_f32
840   : InstPTX<(outs RRegu64:$d), (ins RRegf32:$a), "cvt.u64.f32\t$d, $a",
841             [(set RRegu64:$d, (fp_to_uint RRegf32:$a))]>;
842
843 def CVT_u64_f64
844   : InstPTX<(outs RRegu64:$d), (ins RRegf64:$a), "cvt.u64.f32\t$d, $a",
845             [(set RRegu64:$d, (fp_to_uint RRegf64:$a))]>;
846
847 // Conversion to f32
848
849 def CVT_f32_pred
850   : InstPTX<(outs RRegf32:$d), (ins Preds:$a), "cvt.f32.pred\t$d, $a",
851             [(set RRegf32:$d, (uint_to_fp Preds:$a))]>;
852
853 def CVT_f32_u16
854   : InstPTX<(outs RRegf32:$d), (ins RRegu16:$a), "cvt.f32.u16\t$d, $a",
855             [(set RRegf32:$d, (uint_to_fp RRegu16:$a))]>;
856
857 def CVT_f32_u32
858   : InstPTX<(outs RRegf32:$d), (ins RRegu32:$a), "cvt.f32.u32\t$d, $a",
859             [(set RRegf32:$d, (uint_to_fp RRegu32:$a))]>;
860
861 def CVT_f32_u64
862   : InstPTX<(outs RRegf32:$d), (ins RRegu64:$a), "cvt.f32.u64\t$d, $a",
863             [(set RRegf32:$d, (uint_to_fp RRegu64:$a))]>;
864
865 def CVT_f32_f64
866   : InstPTX<(outs RRegf32:$d), (ins RRegf64:$a), "cvt.f32.f64\t$d, $a",
867             [(set RRegf32:$d, (fround RRegf64:$a))]>;
868
869 // Conversion to f64
870
871 def CVT_f64_pred
872   : InstPTX<(outs RRegf64:$d), (ins Preds:$a), "cvt.f64.pred\t$d, $a",
873             [(set RRegf64:$d, (uint_to_fp Preds:$a))]>;
874
875 def CVT_f64_u16
876   : InstPTX<(outs RRegf64:$d), (ins RRegu16:$a), "cvt.f64.u16\t$d, $a",
877             [(set RRegf64:$d, (uint_to_fp RRegu16:$a))]>;
878
879 def CVT_f64_u32
880   : InstPTX<(outs RRegf64:$d), (ins RRegu32:$a), "cvt.f64.u32\t$d, $a",
881             [(set RRegf64:$d, (uint_to_fp RRegu32:$a))]>;
882
883 def CVT_f64_u64
884   : InstPTX<(outs RRegf64:$d), (ins RRegu64:$a), "cvt.f64.u64\t$d, $a",
885             [(set RRegf64:$d, (uint_to_fp RRegu64:$a))]>;
886
887 def CVT_f64_f32
888   : InstPTX<(outs RRegf64:$d), (ins RRegf32:$a), "cvt.f64.f32\t$d, $a",
889             [(set RRegf64:$d, (fextend RRegf32:$a))]>;
890
891 ///===- Control Flow Instructions -----------------------------------------===//
892
893 let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
894   def BRAd
895     : InstPTX<(outs), (ins brtarget:$d), "bra\t$d", [(br bb:$d)]>;
896 }
897
898 let isBranch = 1, isTerminator = 1 in {
899   // FIXME: The pattern part is blank because I cannot (or do not yet know
900   // how to) use the first operand of PredicateOperand (a Preds register) here
901   def BRAdp
902     : InstPTX<(outs), (ins brtarget:$d), "bra\t$d",
903               [/*(brcond pred:$_p, bb:$d)*/]>;
904 }
905
906 let isReturn = 1, isTerminator = 1, isBarrier = 1 in {
907   def EXIT : InstPTX<(outs), (ins), "exit", [(PTXexit)]>;
908   def RET  : InstPTX<(outs), (ins), "ret",  [(PTXret)]>;
909 }
910
911 ///===- Intrinsic Instructions --------------------------------------------===//
912
913 include "PTXIntrinsicInstrInfo.td"