1 //===- PTXInstrInfo.td - PTX Instruction defs -----------------*- tblgen-*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file describes the PTX instructions in TableGen format.
12 //===----------------------------------------------------------------------===//
14 //===----------------------------------------------------------------------===//
15 // Instruction format superclass
16 //===----------------------------------------------------------------------===//
18 include "PTXInstrFormats.td"
20 //===----------------------------------------------------------------------===//
21 // Code Generation Predicates
22 //===----------------------------------------------------------------------===//
25 def Use32BitAddresses : Predicate<"!getSubtarget().is64Bit()">;
26 def Use64BitAddresses : Predicate<"getSubtarget().is64Bit()">;
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()">;
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()">;
43 def SupportsFMA : Predicate<"getSubtarget().supportsFMA()">;
44 def DoesNotSupportFMA : Predicate<"!getSubtarget().supportsFMA()">;
46 //===----------------------------------------------------------------------===//
47 // Instruction Pattern Stuff
48 //===----------------------------------------------------------------------===//
50 def load_global : PatFrag<(ops node:$ptr), (load node:$ptr), [{
52 const PointerType *PT;
53 if ((Src = cast<LoadSDNode>(N)->getSrcValue()) &&
54 (PT = dyn_cast<PointerType>(Src->getType())))
55 return PT->getAddressSpace() == PTX::GLOBAL;
59 def load_constant : PatFrag<(ops node:$ptr), (load node:$ptr), [{
61 const PointerType *PT;
62 if ((Src = cast<LoadSDNode>(N)->getSrcValue()) &&
63 (PT = dyn_cast<PointerType>(Src->getType())))
64 return PT->getAddressSpace() == PTX::CONSTANT;
68 def load_local : PatFrag<(ops node:$ptr), (load node:$ptr), [{
70 const PointerType *PT;
71 if ((Src = cast<LoadSDNode>(N)->getSrcValue()) &&
72 (PT = dyn_cast<PointerType>(Src->getType())))
73 return PT->getAddressSpace() == PTX::LOCAL;
77 def load_parameter : PatFrag<(ops node:$ptr), (load node:$ptr), [{
79 const PointerType *PT;
80 if ((Src = cast<LoadSDNode>(N)->getSrcValue()) &&
81 (PT = dyn_cast<PointerType>(Src->getType())))
82 return PT->getAddressSpace() == PTX::PARAMETER;
86 def load_shared : PatFrag<(ops node:$ptr), (load node:$ptr), [{
88 const PointerType *PT;
89 if ((Src = cast<LoadSDNode>(N)->getSrcValue()) &&
90 (PT = dyn_cast<PointerType>(Src->getType())))
91 return PT->getAddressSpace() == PTX::SHARED;
96 : PatFrag<(ops node:$d, node:$ptr), (store node:$d, node:$ptr), [{
98 const PointerType *PT;
99 if ((Src = cast<StoreSDNode>(N)->getSrcValue()) &&
100 (PT = dyn_cast<PointerType>(Src->getType())))
101 return PT->getAddressSpace() == PTX::GLOBAL;
106 : PatFrag<(ops node:$d, node:$ptr), (store node:$d, node:$ptr), [{
108 const PointerType *PT;
109 if ((Src = cast<StoreSDNode>(N)->getSrcValue()) &&
110 (PT = dyn_cast<PointerType>(Src->getType())))
111 return PT->getAddressSpace() == PTX::LOCAL;
116 : PatFrag<(ops node:$d, node:$ptr), (store node:$d, node:$ptr), [{
118 const PointerType *PT;
119 if ((Src = cast<StoreSDNode>(N)->getSrcValue()) &&
120 (PT = dyn_cast<PointerType>(Src->getType())))
121 return PT->getAddressSpace() == PTX::PARAMETER;
126 : PatFrag<(ops node:$d, node:$ptr), (store node:$d, node:$ptr), [{
128 const PointerType *PT;
129 if ((Src = cast<StoreSDNode>(N)->getSrcValue()) &&
130 (PT = dyn_cast<PointerType>(Src->getType())))
131 return PT->getAddressSpace() == PTX::SHARED;
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", [], []>;
144 def MEMri32 : Operand<i32> {
145 let PrintMethod = "printMemOperand";
146 let MIOperandInfo = (ops RegI32, i32imm);
148 def MEMri64 : Operand<i64> {
149 let PrintMethod = "printMemOperand";
150 let MIOperandInfo = (ops RegI64, i64imm);
152 def MEMii32 : Operand<i32> {
153 let PrintMethod = "printMemOperand";
154 let MIOperandInfo = (ops i32imm, i32imm);
156 def MEMii64 : Operand<i64> {
157 let PrintMethod = "printMemOperand";
158 let MIOperandInfo = (ops i64imm, i64imm);
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);
166 def MEMret : Operand<i32> {
167 let PrintMethod = "printReturnOperand";
168 let MIOperandInfo = (ops i32imm);
171 // Branch & call targets have OtherVT type.
172 def brtarget : Operand<OtherVT>;
173 def calltarget : Operand<i32>;
175 //===----------------------------------------------------------------------===//
176 // PTX Specific Node Definitions
177 //===----------------------------------------------------------------------===//
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>;
185 : SDNode<"PTXISD::EXIT", SDTNone, [SDNPHasChain]>;
187 : SDNode<"PTXISD::RET", SDTNone,
188 [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>;
190 : SDNode<"PTXISD::COPY_ADDRESS", SDTypeProfile<1, 1, []>, []>;
192 // Load/store .param space
194 : SDNode<"PTXISD::LOAD_PARAM", SDTypeProfile<1, 1, [SDTCisVT<1, i32>]>,
195 [SDNPHasChain, SDNPOutGlue, SDNPOptInGlue]>;
197 : SDNode<"PTXISD::STORE_PARAM", SDTypeProfile<0, 2, [SDTCisVT<0, i32>]>,
198 [SDNPHasChain, SDNPOutGlue, SDNPOptInGlue]>;
200 //===----------------------------------------------------------------------===//
201 // Instruction Class Templates
202 //===----------------------------------------------------------------------===//
204 //===- Floating-Point Instructions - 2 Operand Form -----------------------===//
205 multiclass PTX_FLOAT_2OP<string opcstr, SDNode opnode> {
206 def rr32 : InstPTX<(outs RegF32:$d),
208 !strconcat(opcstr, ".f32\t$d, $a"),
209 [(set RegF32:$d, (opnode RegF32:$a))]>;
210 def ri32 : InstPTX<(outs RegF32:$d),
212 !strconcat(opcstr, ".f32\t$d, $a"),
213 [(set RegF32:$d, (opnode fpimm:$a))]>;
214 def rr64 : InstPTX<(outs RegF64:$d),
216 !strconcat(opcstr, ".f64\t$d, $a"),
217 [(set RegF64:$d, (opnode RegF64:$a))]>;
218 def ri64 : InstPTX<(outs RegF64:$d),
220 !strconcat(opcstr, ".f64\t$d, $a"),
221 [(set RegF64:$d, (opnode fpimm:$a))]>;
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))]>;
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,
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,
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,
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,
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))]>;
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))]>;
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))]>;
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
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))]>;
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))]>;
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))]>;
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))]>;
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))]>;
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))]>;
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))]>;
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))]>;
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)))]>;
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)))]>;
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)))]>;
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)))]>;
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)))]>;
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)))]>;
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
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))]>;
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))]>;
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))]>;
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))]>;
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))]>;
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))]>;
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))]>;
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))]>;
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)))]>;
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)))]>;
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)))]>;
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)))]>;
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)))]>;
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)))]>;
505 multiclass PTX_SELP<RegisterClass RC, string regclsname> {
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))]>;
512 multiclass PTX_LD<string opstr, string typestr, RegisterClass RC, PatFrag pat_load> {
513 def rr32 : InstPTX<(outs RC:$d),
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),
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),
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),
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),
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),
535 !strconcat(opstr, !strconcat(typestr, "\t$d, [$a]")),
536 [(set RC:$d, (pat_load ADDRii64:$a))]>, Requires<[Use64BitAddresses]>;
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>;
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]>;
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>;
582 //===----------------------------------------------------------------------===//
584 //===----------------------------------------------------------------------===//
586 ///===- Integer Arithmetic Instructions -----------------------------------===//
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>;
594 ///===- Floating-Point Arithmetic Instructions ----------------------------===//
596 // Standard Unary Operations
597 defm FNEG : PTX_FLOAT_2OP<"neg", fneg>;
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>;
604 // For floating-point division:
605 // SM_13+ defaults to .rn for f32 and f64,
606 // SM10 must *not* provide a rounding
609 // - Allow user selection of rounding modes for fdiv
610 // - Add support for -prec-div=false (.approx)
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]>;
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]>;
656 // Multi-operation hybrid instructions
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]>;
669 ///===- Floating-Point Intrinsic Instructions -----------------------------===//
671 def FSQRT32 : InstPTX<(outs RegF32:$d),
673 "sqrt.rn.f32\t$d, $a",
674 [(set RegF32:$d, (fsqrt RegF32:$a))]>;
676 def FSQRT64 : InstPTX<(outs RegF64:$d),
678 "sqrt.rn.f64\t$d, $a",
679 [(set RegF64:$d, (fsqrt RegF64:$a))]>;
681 def FSIN32 : InstPTX<(outs RegF32:$d),
683 "sin.approx.f32\t$d, $a",
684 [(set RegF32:$d, (fsin RegF32:$a))]>;
686 def FSIN64 : InstPTX<(outs RegF64:$d),
688 "sin.approx.f64\t$d, $a",
689 [(set RegF64:$d, (fsin RegF64:$a))]>;
691 def FCOS32 : InstPTX<(outs RegF32:$d),
693 "cos.approx.f32\t$d, $a",
694 [(set RegF32:$d, (fcos RegF32:$a))]>;
696 def FCOS64 : InstPTX<(outs RegF64:$d),
698 "cos.approx.f64\t$d, $a",
699 [(set RegF64:$d, (fcos RegF64:$a))]>;
702 ///===- Comparison and Selection Instructions -----------------------------===//
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">;
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">;
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">;
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">;
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">;
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">;
771 ///===- Logic and Shift Instructions --------------------------------------===//
773 defm SHL : INT3ntnc<"shl.b", PTXshl>;
774 defm SRL : INT3ntnc<"shr.u", PTXsrl>;
775 defm SRA : INT3ntnc<"shr.s", PTXsra>;
777 defm AND : PTX_LOGIC<"and", and>;
778 defm OR : PTX_LOGIC<"or", or>;
779 defm XOR : PTX_LOGIC<"xor", xor>;
781 ///===- Data Movement and Conversion Instructions -------------------------===//
783 let neverHasSideEffects = 1 in {
785 : InstPTX<(outs RegPred:$d), (ins RegPred:$a), "mov.pred\t$d, $a", []>;
787 : InstPTX<(outs RegI16:$d), (ins RegI16:$a), "mov.u16\t$d, $a", []>;
789 : InstPTX<(outs RegI32:$d), (ins RegI32:$a), "mov.u32\t$d, $a", []>;
791 : InstPTX<(outs RegI64:$d), (ins RegI64:$a), "mov.u64\t$d, $a", []>;
793 : InstPTX<(outs RegF32:$d), (ins RegF32:$a), "mov.f32\t$d, $a", []>;
795 : InstPTX<(outs RegF64:$d), (ins RegF64:$a), "mov.f64\t$d, $a", []>;
798 let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
800 : InstPTX<(outs RegPred:$d), (ins i1imm:$a), "mov.pred\t$d, $a",
801 [(set RegPred:$d, imm:$a)]>;
803 : InstPTX<(outs RegI16:$d), (ins i16imm:$a), "mov.u16\t$d, $a",
804 [(set RegI16:$d, imm:$a)]>;
806 : InstPTX<(outs RegI32:$d), (ins i32imm:$a), "mov.u32\t$d, $a",
807 [(set RegI32:$d, imm:$a)]>;
809 : InstPTX<(outs RegI64:$d), (ins i64imm:$a), "mov.u64\t$d, $a",
810 [(set RegI64:$d, imm:$a)]>;
812 : InstPTX<(outs RegF32:$d), (ins f32imm:$a), "mov.f32\t$d, $a",
813 [(set RegF32:$d, fpimm:$a)]>;
815 : InstPTX<(outs RegF64:$d), (ins f64imm:$a), "mov.f64\t$d, $a",
816 [(set RegF64:$d, fpimm:$a)]>;
819 let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
821 : InstPTX<(outs RegI32:$d), (ins i32imm:$a), "mov.u32\t$d, $a",
822 [(set RegI32:$d, (PTXcopyaddress tglobaladdr:$a))]>;
824 : InstPTX<(outs RegI64:$d), (ins i64imm:$a), "mov.u64\t$d, $a",
825 [(set RegI64:$d, (PTXcopyaddress tglobaladdr:$a))]>;
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>;
834 // These instructions are used to load/store from the .param space for
835 // device and kernel parameters
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))]>;
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)]>;
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>;
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.
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'.
891 : InstPTX<(outs RegPred:$d), (ins RegI16:$a), "setp.gt.u16\t$d, $a, 0",
892 [(set RegPred:$d, (trunc RegI16:$a))]>;
895 : InstPTX<(outs RegPred:$d), (ins RegI32:$a), "setp.gt.u32\t$d, $a, 0",
896 [(set RegPred:$d, (trunc RegI32:$a))]>;
899 : InstPTX<(outs RegPred:$d), (ins RegI64:$a), "setp.gt.u64\t$d, $a, 0",
900 [(set RegPred:$d, (trunc RegI64:$a))]>;
903 : InstPTX<(outs RegPred:$d), (ins RegF32:$a), "setp.gt.f32\t$d, $a, 0",
904 [(set RegPred:$d, (fp_to_uint RegF32:$a))]>;
907 : InstPTX<(outs RegPred:$d), (ins RegF64:$a), "setp.gt.f64\t$d, $a, 0",
908 [(set RegPred:$d, (fp_to_uint RegF64:$a))]>;
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.
915 : InstPTX<(outs RegI16:$d), (ins RegPred:$a), "selp.u16\t$d, 1, 0, $a",
916 [(set RegI16:$d, (anyext RegPred:$a))]>;
919 : InstPTX<(outs RegI16:$d), (ins RegPred:$a), "selp.u16\t$d, 1, 0, $a",
920 [(set RegI16:$d, (zext RegPred:$a))]>;
923 : InstPTX<(outs RegI16:$d), (ins RegPred:$a), "selp.u16\t$d, 1, 0, $a",
924 [(set RegI16:$d, (sext RegPred:$a))]>;
927 : InstPTX<(outs RegI16:$d), (ins RegI32:$a), "cvt.u16.u32\t$d, $a",
928 [(set RegI16:$d, (trunc RegI32:$a))]>;
931 : InstPTX<(outs RegI16:$d), (ins RegI64:$a), "cvt.u16.u64\t$d, $a",
932 [(set RegI16:$d, (trunc RegI64:$a))]>;
935 : InstPTX<(outs RegI16:$d), (ins RegF32:$a), "cvt.rzi.u16.f32\t$d, $a",
936 [(set RegI16:$d, (fp_to_uint RegF32:$a))]>;
939 : InstPTX<(outs RegI16:$d), (ins RegF64:$a), "cvt.rzi.u16.f64\t$d, $a",
940 [(set RegI16:$d, (fp_to_uint RegF64:$a))]>;
945 : InstPTX<(outs RegI32:$d), (ins RegPred:$a), "selp.u32\t$d, 1, 0, $a",
946 [(set RegI32:$d, (zext RegPred:$a))]>;
949 : InstPTX<(outs RegI32:$d), (ins RegI16:$a), "cvt.u32.u16\t$d, $a",
950 [(set RegI32:$d, (anyext RegI16:$a))]>;
953 : InstPTX<(outs RegI32:$d), (ins RegI16:$a), "cvt.u32.u16\t$d, $a",
954 [(set RegI32:$d, (zext RegI16:$a))]>;
957 : InstPTX<(outs RegI32:$d), (ins RegPred:$a), "selp.u32\t$d, 1, 0, $a",
958 [(set RegI32:$d, (sext RegPred:$a))]>;
961 : InstPTX<(outs RegI32:$d), (ins RegI16:$a), "cvt.u32.s16\t$d, $a",
962 [(set RegI32:$d, (sext RegI16:$a))]>;
965 : InstPTX<(outs RegI32:$d), (ins RegI64:$a), "cvt.u32.u64\t$d, $a",
966 [(set RegI32:$d, (trunc RegI64:$a))]>;
969 : InstPTX<(outs RegI32:$d), (ins RegF32:$a), "cvt.rzi.u32.f32\t$d, $a",
970 [(set RegI32:$d, (fp_to_uint RegF32:$a))]>;
973 : InstPTX<(outs RegI32:$d), (ins RegF64:$a), "cvt.rzi.u32.f64\t$d, $a",
974 [(set RegI32:$d, (fp_to_uint RegF64:$a))]>;
979 : InstPTX<(outs RegI64:$d), (ins RegPred:$a), "selp.u64\t$d, 1, 0, $a",
980 [(set RegI64:$d, (zext RegPred:$a))]>;
983 : InstPTX<(outs RegI64:$d), (ins RegPred:$a), "selp.u64\t$d, 1, 0, $a",
984 [(set RegI64:$d, (sext RegPred:$a))]>;
987 : InstPTX<(outs RegI64:$d), (ins RegI16:$a), "cvt.u64.u16\t$d, $a",
988 [(set RegI64:$d, (zext RegI16:$a))]>;
991 : InstPTX<(outs RegI64:$d), (ins RegI16:$a), "cvt.u64.s16\t$d, $a",
992 [(set RegI64:$d, (sext RegI16:$a))]>;
995 : InstPTX<(outs RegI64:$d), (ins RegI32:$a), "cvt.u64.u32\t$d, $a",
996 [(set RegI64:$d, (zext RegI32:$a))]>;
999 : InstPTX<(outs RegI64:$d), (ins RegI32:$a), "cvt.u64.s32\t$d, $a",
1000 [(set RegI64:$d, (sext RegI32:$a))]>;
1003 : InstPTX<(outs RegI64:$d), (ins RegF32:$a), "cvt.rzi.u64.f32\t$d, $a",
1004 [(set RegI64:$d, (fp_to_uint RegF32:$a))]>;
1007 : InstPTX<(outs RegI64:$d), (ins RegF64:$a), "cvt.rzi.u64.f64\t$d, $a",
1008 [(set RegI64:$d, (fp_to_uint RegF64:$a))]>;
1010 // Conversion to f32
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))]>;
1018 : InstPTX<(outs RegF32:$d), (ins RegI16:$a), "cvt.rn.f32.u16\t$d, $a",
1019 [(set RegF32:$d, (uint_to_fp RegI16:$a))]>;
1022 : InstPTX<(outs RegF32:$d), (ins RegI32:$a), "cvt.rn.f32.u32\t$d, $a",
1023 [(set RegF32:$d, (uint_to_fp RegI32:$a))]>;
1026 : InstPTX<(outs RegF32:$d), (ins RegI64:$a), "cvt.rn.f32.u64\t$d, $a",
1027 [(set RegF32:$d, (uint_to_fp RegI64:$a))]>;
1030 : InstPTX<(outs RegF32:$d), (ins RegF64:$a), "cvt.rn.f32.f64\t$d, $a",
1031 [(set RegF32:$d, (fround RegF64:$a))]>;
1033 // Conversion to f64
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))]>;
1041 : InstPTX<(outs RegF64:$d), (ins RegI16:$a), "cvt.rn.f64.u16\t$d, $a",
1042 [(set RegF64:$d, (uint_to_fp RegI16:$a))]>;
1045 : InstPTX<(outs RegF64:$d), (ins RegI32:$a), "cvt.rn.f64.u32\t$d, $a",
1046 [(set RegF64:$d, (uint_to_fp RegI32:$a))]>;
1049 : InstPTX<(outs RegF64:$d), (ins RegI64:$a), "cvt.rn.f64.u64\t$d, $a",
1050 [(set RegF64:$d, (uint_to_fp RegI64:$a))]>;
1053 : InstPTX<(outs RegF64:$d), (ins RegF32:$a), "cvt.f64.f32\t$d, $a",
1054 [(set RegF64:$d, (fextend RegF32:$a))]>;
1056 ///===- Control Flow Instructions -----------------------------------------===//
1058 let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
1060 : InstPTX<(outs), (ins brtarget:$d), "bra\t$d", [(br bb:$d)]>;
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
1067 : InstPTX<(outs), (ins brtarget:$d), "bra\t$d",
1068 [/*(brcond pred:$_p, bb:$d)*/]>;
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)]>;
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", []>;
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", []>;
1100 ///===- Intrinsic Instructions --------------------------------------------===//
1102 include "PTXIntrinsicInstrInfo.td"