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