1 ;; Machine description for NVPTX.
2 ;; Copyright (C) 2014-2019 Free Software Foundation, Inc.
3 ;; Contributed by Bernd Schmidt <bernds@codesourcery.com>
5 ;; This file is part of GCC.
7 ;; GCC is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 3, or (at your option)
12 ;; GCC is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GCC; see the file COPYING3. If not see
19 ;; <http://www.gnu.org/licenses/>.
21 (define_c_enum "unspec" [
33 UNSPEC_FPINT_NEARBYINT
53 (define_c_enum "unspecv" [
75 (define_attr "subregs_ok" "false,true"
76 (const_string "false"))
78 (define_attr "atomic" "false,true"
79 (const_string "false"))
81 ;; The nvptx operand predicates, in general, don't permit subregs and
82 ;; only literal constants, which differ from the generic ones, which
83 ;; permit subregs and symbolc constants (as appropriate)
84 (define_predicate "nvptx_register_operand"
87 return register_operand (op, mode);
90 (define_predicate "nvptx_nonimmediate_operand"
91 (match_code "mem,reg")
93 return (REG_P (op) ? register_operand (op, mode)
94 : memory_operand (op, mode));
97 (define_predicate "nvptx_nonmemory_operand"
98 (match_code "reg,const_int,const_double")
100 return (REG_P (op) ? register_operand (op, mode)
101 : immediate_operand (op, mode));
104 (define_predicate "const0_operand"
105 (and (match_code "const_int")
106 (match_test "op == const0_rtx")))
108 ;; True if this operator is valid for predication.
109 (define_predicate "predicate_operator"
110 (match_code "eq,ne"))
112 (define_predicate "ne_operator"
115 (define_predicate "nvptx_comparison_operator"
116 (match_code "eq,ne,le,ge,lt,gt,leu,geu,ltu,gtu"))
118 (define_predicate "nvptx_float_comparison_operator"
119 (match_code "eq,ne,le,ge,lt,gt,uneq,unle,unge,unlt,ungt,unordered,ordered"))
121 ;; Test for a valid operand for a call instruction.
122 (define_predicate "call_insn_operand"
123 (match_code "symbol_ref,reg")
125 return REG_P (op) || SYMBOL_REF_FUNCTION_P (op);
128 ;; Return true if OP is a call with parallel USEs of the argument
130 (define_predicate "call_operation"
131 (match_code "parallel")
133 int arg_end = XVECLEN (op, 0);
135 for (int i = 1; i < arg_end; i++)
137 rtx elt = XVECEXP (op, 0, i);
139 if (GET_CODE (elt) != USE || !REG_P (XEXP (elt, 0)))
145 (define_attr "predicable" "false,true"
146 (const_string "true"))
149 [(match_operator 0 "predicate_operator"
150 [(match_operand:BI 1 "nvptx_register_operand" "")
151 (match_operand:BI 2 "const0_operand" "")])]
156 (define_constraint "P0"
157 "An integer with the value 0."
158 (and (match_code "const_int")
159 (match_test "ival == 0")))
161 (define_constraint "P1"
162 "An integer with the value 1."
163 (and (match_code "const_int")
164 (match_test "ival == 1")))
166 (define_constraint "Pn"
167 "An integer with the value -1."
168 (and (match_code "const_int")
169 (match_test "ival == -1")))
171 (define_constraint "R"
175 (define_constraint "Ia"
176 "Any integer constant."
177 (and (match_code "const_int") (match_test "true")))
179 (define_mode_iterator QHSDISDFM [QI HI SI DI SF DF])
180 (define_mode_iterator QHSDIM [QI HI SI DI])
181 (define_mode_iterator HSDIM [HI SI DI])
182 (define_mode_iterator BHSDIM [BI HI SI DI])
183 (define_mode_iterator SDIM [SI DI])
184 (define_mode_iterator SDISDFM [SI DI SF DF])
185 (define_mode_iterator QHIM [QI HI])
186 (define_mode_iterator QHSIM [QI HI SI])
187 (define_mode_iterator SDFM [SF DF])
188 (define_mode_iterator SDCM [SC DC])
189 (define_mode_iterator BITS [SI SF])
190 (define_mode_iterator BITD [DI DF])
191 (define_mode_iterator VECIM [V2SI V2DI])
193 ;; This mode iterator allows :P to be used for patterns that operate on
194 ;; pointer-sized quantities. Exactly one of the two alternatives will match.
195 (define_mode_iterator P [(SI "Pmode == SImode") (DI "Pmode == DImode")])
197 ;; We should get away with not defining memory alternatives, since we don't
198 ;; get variables in this mode and pseudos are never spilled.
200 [(set (match_operand:BI 0 "nvptx_register_operand" "=R,R,R")
201 (match_operand:BI 1 "nvptx_nonmemory_operand" "R,P0,Pn"))]
204 %.\\tmov%t0\\t%0, %1;
205 %.\\tsetp.eq.u32\\t%0, 1, 0;
206 %.\\tsetp.eq.u32\\t%0, 1, 1;")
208 (define_insn "*mov<mode>_insn"
209 [(set (match_operand:VECIM 0 "nonimmediate_operand" "=R,R,m")
210 (match_operand:VECIM 1 "general_operand" "Ri,m,R"))]
211 "!MEM_P (operands[0]) || REG_P (operands[1])"
213 if (which_alternative == 1)
214 return "%.\\tld%A1%u1\\t%0, %1;";
215 if (which_alternative == 2)
216 return "%.\\tst%A0%u0\\t%0, %1;";
218 return nvptx_output_mov_insn (operands[0], operands[1]);
220 [(set_attr "subregs_ok" "true")])
222 (define_insn "*mov<mode>_insn"
223 [(set (match_operand:QHSDIM 0 "nonimmediate_operand" "=R,R,m")
224 (match_operand:QHSDIM 1 "general_operand" "Ri,m,R"))]
225 "!MEM_P (operands[0]) || REG_P (operands[1])"
227 if (which_alternative == 1)
228 return "%.\\tld%A1%u1\\t%0, %1;";
229 if (which_alternative == 2)
230 return "%.\\tst%A0%u0\\t%0, %1;";
232 return nvptx_output_mov_insn (operands[0], operands[1]);
234 [(set_attr "subregs_ok" "true")])
236 (define_insn "*mov<mode>_insn"
237 [(set (match_operand:SDFM 0 "nonimmediate_operand" "=R,R,m")
238 (match_operand:SDFM 1 "general_operand" "RF,m,R"))]
239 "!MEM_P (operands[0]) || REG_P (operands[1])"
241 if (which_alternative == 1)
242 return "%.\\tld%A1%u0\\t%0, %1;";
243 if (which_alternative == 2)
244 return "%.\\tst%A0%u1\\t%0, %1;";
246 return nvptx_output_mov_insn (operands[0], operands[1]);
248 [(set_attr "subregs_ok" "true")])
250 (define_insn "load_arg_reg<mode>"
251 [(set (match_operand:QHIM 0 "nvptx_register_operand" "=R")
252 (unspec:QHIM [(match_operand 1 "const_int_operand" "n")]
255 "%.\\tcvt%t0.u32\\t%0, %%ar%1;")
257 (define_insn "load_arg_reg<mode>"
258 [(set (match_operand:SDISDFM 0 "nvptx_register_operand" "=R")
259 (unspec:SDISDFM [(match_operand 1 "const_int_operand" "n")]
262 "%.\\tmov%t0\\t%0, %%ar%1;")
264 (define_expand "mov<mode>"
265 [(set (match_operand:VECIM 0 "nonimmediate_operand" "")
266 (match_operand:VECIM 1 "general_operand" ""))]
269 if (MEM_P (operands[0]) && !REG_P (operands[1]))
271 rtx tmp = gen_reg_rtx (<MODE>mode);
272 emit_move_insn (tmp, operands[1]);
273 emit_move_insn (operands[0], tmp);
278 (define_expand "mov<mode>"
279 [(set (match_operand:QHSDISDFM 0 "nonimmediate_operand" "")
280 (match_operand:QHSDISDFM 1 "general_operand" ""))]
283 if (MEM_P (operands[0]) && !REG_P (operands[1]))
285 rtx tmp = gen_reg_rtx (<MODE>mode);
286 emit_move_insn (tmp, operands[1]);
287 emit_move_insn (operands[0], tmp);
291 if (GET_CODE (operands[1]) == LABEL_REF)
292 sorry ("target cannot support label values");
295 (define_insn "zero_extendqihi2"
296 [(set (match_operand:HI 0 "nvptx_register_operand" "=R,R")
297 (zero_extend:HI (match_operand:QI 1 "nvptx_nonimmediate_operand" "R,m")))]
300 %.\\tcvt.u16.u%T1\\t%0, %1;
301 %.\\tld%A1.u8\\t%0, %1;"
302 [(set_attr "subregs_ok" "true")])
304 (define_insn "zero_extend<mode>si2"
305 [(set (match_operand:SI 0 "nvptx_register_operand" "=R,R")
306 (zero_extend:SI (match_operand:QHIM 1 "nvptx_nonimmediate_operand" "R,m")))]
309 %.\\tcvt.u32.u%T1\\t%0, %1;
310 %.\\tld%A1.u%T1\\t%0, %1;"
311 [(set_attr "subregs_ok" "true")])
313 (define_insn "zero_extend<mode>di2"
314 [(set (match_operand:DI 0 "nvptx_register_operand" "=R,R")
315 (zero_extend:DI (match_operand:QHSIM 1 "nvptx_nonimmediate_operand" "R,m")))]
318 %.\\tcvt.u64.u%T1\\t%0, %1;
319 %.\\tld%A1%u1\\t%0, %1;"
320 [(set_attr "subregs_ok" "true")])
322 (define_insn "extend<mode>si2"
323 [(set (match_operand:SI 0 "nvptx_register_operand" "=R,R")
324 (sign_extend:SI (match_operand:QHIM 1 "nvptx_nonimmediate_operand" "R,m")))]
327 %.\\tcvt.s32.s%T1\\t%0, %1;
328 %.\\tld%A1.s%T1\\t%0, %1;"
329 [(set_attr "subregs_ok" "true")])
331 (define_insn "extend<mode>di2"
332 [(set (match_operand:DI 0 "nvptx_register_operand" "=R,R")
333 (sign_extend:DI (match_operand:QHSIM 1 "nvptx_nonimmediate_operand" "R,m")))]
336 %.\\tcvt.s64.s%T1\\t%0, %1;
337 %.\\tld%A1.s%T1\\t%0, %1;"
338 [(set_attr "subregs_ok" "true")])
340 (define_insn "trunchiqi2"
341 [(set (match_operand:QI 0 "nvptx_nonimmediate_operand" "=R,m")
342 (truncate:QI (match_operand:HI 1 "nvptx_register_operand" "R,R")))]
345 %.\\tcvt%t0.u16\\t%0, %1;
346 %.\\tst%A0.u8\\t%0, %1;"
347 [(set_attr "subregs_ok" "true")])
349 (define_insn "truncsi<mode>2"
350 [(set (match_operand:QHIM 0 "nvptx_nonimmediate_operand" "=R,m")
351 (truncate:QHIM (match_operand:SI 1 "nvptx_register_operand" "R,R")))]
354 %.\\tcvt%t0.u32\\t%0, %1;
355 %.\\tst%A0.u%T0\\t%0, %1;"
356 [(set_attr "subregs_ok" "true")])
358 (define_insn "truncdi<mode>2"
359 [(set (match_operand:QHSIM 0 "nvptx_nonimmediate_operand" "=R,m")
360 (truncate:QHSIM (match_operand:DI 1 "nvptx_register_operand" "R,R")))]
363 %.\\tcvt%t0.u64\\t%0, %1;
364 %.\\tst%A0.u%T0\\t%0, %1;"
365 [(set_attr "subregs_ok" "true")])
367 ;; Integer arithmetic
369 (define_insn "add<mode>3"
370 [(set (match_operand:HSDIM 0 "nvptx_register_operand" "=R")
371 (plus:HSDIM (match_operand:HSDIM 1 "nvptx_register_operand" "R")
372 (match_operand:HSDIM 2 "nvptx_nonmemory_operand" "Ri")))]
374 "%.\\tadd%t0\\t%0, %1, %2;")
376 (define_insn "sub<mode>3"
377 [(set (match_operand:HSDIM 0 "nvptx_register_operand" "=R")
378 (minus:HSDIM (match_operand:HSDIM 1 "nvptx_register_operand" "R")
379 (match_operand:HSDIM 2 "nvptx_register_operand" "R")))]
381 "%.\\tsub%t0\\t%0, %1, %2;")
383 (define_insn "mul<mode>3"
384 [(set (match_operand:HSDIM 0 "nvptx_register_operand" "=R")
385 (mult:HSDIM (match_operand:HSDIM 1 "nvptx_register_operand" "R")
386 (match_operand:HSDIM 2 "nvptx_nonmemory_operand" "Ri")))]
388 "%.\\tmul.lo%t0\\t%0, %1, %2;")
390 (define_insn "*mad<mode>3"
391 [(set (match_operand:HSDIM 0 "nvptx_register_operand" "=R")
392 (plus:HSDIM (mult:HSDIM (match_operand:HSDIM 1 "nvptx_register_operand" "R")
393 (match_operand:HSDIM 2 "nvptx_nonmemory_operand" "Ri"))
394 (match_operand:HSDIM 3 "nvptx_nonmemory_operand" "Ri")))]
396 "%.\\tmad.lo%t0\\t%0, %1, %2, %3;")
398 (define_insn "div<mode>3"
399 [(set (match_operand:HSDIM 0 "nvptx_register_operand" "=R")
400 (div:HSDIM (match_operand:HSDIM 1 "nvptx_register_operand" "R")
401 (match_operand:HSDIM 2 "nvptx_nonmemory_operand" "Ri")))]
403 "%.\\tdiv.s%T0\\t%0, %1, %2;")
405 (define_insn "udiv<mode>3"
406 [(set (match_operand:HSDIM 0 "nvptx_register_operand" "=R")
407 (udiv:HSDIM (match_operand:HSDIM 1 "nvptx_register_operand" "R")
408 (match_operand:HSDIM 2 "nvptx_nonmemory_operand" "Ri")))]
410 "%.\\tdiv.u%T0\\t%0, %1, %2;")
412 (define_insn "mod<mode>3"
413 [(set (match_operand:HSDIM 0 "nvptx_register_operand" "=R")
414 (mod:HSDIM (match_operand:HSDIM 1 "nvptx_register_operand" "Ri")
415 (match_operand:HSDIM 2 "nvptx_nonmemory_operand" "Ri")))]
417 "%.\\trem.s%T0\\t%0, %1, %2;")
419 (define_insn "umod<mode>3"
420 [(set (match_operand:HSDIM 0 "nvptx_register_operand" "=R")
421 (umod:HSDIM (match_operand:HSDIM 1 "nvptx_register_operand" "Ri")
422 (match_operand:HSDIM 2 "nvptx_nonmemory_operand" "Ri")))]
424 "%.\\trem.u%T0\\t%0, %1, %2;")
426 (define_insn "smin<mode>3"
427 [(set (match_operand:HSDIM 0 "nvptx_register_operand" "=R")
428 (smin:HSDIM (match_operand:HSDIM 1 "nvptx_register_operand" "R")
429 (match_operand:HSDIM 2 "nvptx_nonmemory_operand" "Ri")))]
431 "%.\\tmin.s%T0\\t%0, %1, %2;")
433 (define_insn "umin<mode>3"
434 [(set (match_operand:HSDIM 0 "nvptx_register_operand" "=R")
435 (umin:HSDIM (match_operand:HSDIM 1 "nvptx_register_operand" "R")
436 (match_operand:HSDIM 2 "nvptx_nonmemory_operand" "Ri")))]
438 "%.\\tmin.u%T0\\t%0, %1, %2;")
440 (define_insn "smax<mode>3"
441 [(set (match_operand:HSDIM 0 "nvptx_register_operand" "=R")
442 (smax:HSDIM (match_operand:HSDIM 1 "nvptx_register_operand" "R")
443 (match_operand:HSDIM 2 "nvptx_nonmemory_operand" "Ri")))]
445 "%.\\tmax.s%T0\\t%0, %1, %2;")
447 (define_insn "umax<mode>3"
448 [(set (match_operand:HSDIM 0 "nvptx_register_operand" "=R")
449 (umax:HSDIM (match_operand:HSDIM 1 "nvptx_register_operand" "R")
450 (match_operand:HSDIM 2 "nvptx_nonmemory_operand" "Ri")))]
452 "%.\\tmax.u%T0\\t%0, %1, %2;")
454 (define_insn "abs<mode>2"
455 [(set (match_operand:HSDIM 0 "nvptx_register_operand" "=R")
456 (abs:HSDIM (match_operand:HSDIM 1 "nvptx_register_operand" "R")))]
458 "%.\\tabs.s%T0\\t%0, %1;")
460 (define_insn "neg<mode>2"
461 [(set (match_operand:HSDIM 0 "nvptx_register_operand" "=R")
462 (neg:HSDIM (match_operand:HSDIM 1 "nvptx_register_operand" "R")))]
464 "%.\\tneg.s%T0\\t%0, %1;")
466 (define_insn "one_cmpl<mode>2"
467 [(set (match_operand:HSDIM 0 "nvptx_register_operand" "=R")
468 (not:HSDIM (match_operand:HSDIM 1 "nvptx_register_operand" "R")))]
470 "%.\\tnot.b%T0\\t%0, %1;")
472 (define_insn "bitrev<mode>2"
473 [(set (match_operand:SDIM 0 "nvptx_register_operand" "=R")
474 (unspec:SDIM [(match_operand:SDIM 1 "nvptx_register_operand" "R")]
477 "%.\\tbrev.b%T0\\t%0, %1;")
479 (define_insn "clz<mode>2"
480 [(set (match_operand:SI 0 "nvptx_register_operand" "=R")
481 (clz:SI (match_operand:SDIM 1 "nvptx_register_operand" "R")))]
483 "%.\\tclz.b%T1\\t%0, %1;")
485 (define_expand "ctz<mode>2"
486 [(set (match_operand:SI 0 "nvptx_register_operand" "")
487 (ctz:SI (match_operand:SDIM 1 "nvptx_register_operand" "")))]
490 rtx tmpreg = gen_reg_rtx (<MODE>mode);
491 emit_insn (gen_bitrev<mode>2 (tmpreg, operands[1]));
492 emit_insn (gen_clz<mode>2 (operands[0], tmpreg));
498 (define_insn "ashl<mode>3"
499 [(set (match_operand:SDIM 0 "nvptx_register_operand" "=R")
500 (ashift:SDIM (match_operand:SDIM 1 "nvptx_register_operand" "R")
501 (match_operand:SI 2 "nvptx_nonmemory_operand" "Ri")))]
503 "%.\\tshl.b%T0\\t%0, %1, %2;")
505 (define_insn "ashr<mode>3"
506 [(set (match_operand:SDIM 0 "nvptx_register_operand" "=R")
507 (ashiftrt:SDIM (match_operand:SDIM 1 "nvptx_register_operand" "R")
508 (match_operand:SI 2 "nvptx_nonmemory_operand" "Ri")))]
510 "%.\\tshr.s%T0\\t%0, %1, %2;")
512 (define_insn "lshr<mode>3"
513 [(set (match_operand:SDIM 0 "nvptx_register_operand" "=R")
514 (lshiftrt:SDIM (match_operand:SDIM 1 "nvptx_register_operand" "R")
515 (match_operand:SI 2 "nvptx_nonmemory_operand" "Ri")))]
517 "%.\\tshr.u%T0\\t%0, %1, %2;")
519 ;; Logical operations
521 (define_insn "and<mode>3"
522 [(set (match_operand:BHSDIM 0 "nvptx_register_operand" "=R")
523 (and:BHSDIM (match_operand:BHSDIM 1 "nvptx_register_operand" "R")
524 (match_operand:BHSDIM 2 "nvptx_nonmemory_operand" "Ri")))]
526 "%.\\tand.b%T0\\t%0, %1, %2;")
528 (define_insn "ior<mode>3"
529 [(set (match_operand:BHSDIM 0 "nvptx_register_operand" "=R")
530 (ior:BHSDIM (match_operand:BHSDIM 1 "nvptx_register_operand" "R")
531 (match_operand:BHSDIM 2 "nvptx_nonmemory_operand" "Ri")))]
533 "%.\\tor.b%T0\\t%0, %1, %2;")
535 (define_insn "xor<mode>3"
536 [(set (match_operand:BHSDIM 0 "nvptx_register_operand" "=R")
537 (xor:BHSDIM (match_operand:BHSDIM 1 "nvptx_register_operand" "R")
538 (match_operand:BHSDIM 2 "nvptx_nonmemory_operand" "Ri")))]
540 "%.\\txor.b%T0\\t%0, %1, %2;")
542 ;; Comparisons and branches
544 (define_insn "*cmp<mode>"
545 [(set (match_operand:BI 0 "nvptx_register_operand" "=R")
546 (match_operator:BI 1 "nvptx_comparison_operator"
547 [(match_operand:HSDIM 2 "nvptx_register_operand" "R")
548 (match_operand:HSDIM 3 "nvptx_nonmemory_operand" "Ri")]))]
550 "%.\\tsetp%c1\\t%0, %2, %3;")
552 (define_insn "*cmp<mode>"
553 [(set (match_operand:BI 0 "nvptx_register_operand" "=R")
554 (match_operator:BI 1 "nvptx_float_comparison_operator"
555 [(match_operand:SDFM 2 "nvptx_register_operand" "R")
556 (match_operand:SDFM 3 "nvptx_nonmemory_operand" "RF")]))]
558 "%.\\tsetp%c1\\t%0, %2, %3;")
562 (label_ref (match_operand 0 "" "")))]
566 (define_insn "br_true"
568 (if_then_else (ne (match_operand:BI 0 "nvptx_register_operand" "R")
570 (label_ref (match_operand 1 "" ""))
574 [(set_attr "predicable" "false")])
576 (define_insn "br_false"
578 (if_then_else (eq (match_operand:BI 0 "nvptx_register_operand" "R")
580 (label_ref (match_operand 1 "" ""))
584 [(set_attr "predicable" "false")])
586 ;; unified conditional branch
587 (define_insn "br_true_uni"
588 [(set (pc) (if_then_else
589 (ne (unspec:BI [(match_operand:BI 0 "nvptx_register_operand" "R")]
590 UNSPEC_BR_UNIFIED) (const_int 0))
591 (label_ref (match_operand 1 "" "")) (pc)))]
593 "%j0\\tbra.uni\\t%l1;"
594 [(set_attr "predicable" "false")])
596 (define_insn "br_false_uni"
597 [(set (pc) (if_then_else
598 (eq (unspec:BI [(match_operand:BI 0 "nvptx_register_operand" "R")]
599 UNSPEC_BR_UNIFIED) (const_int 0))
600 (label_ref (match_operand 1 "" "")) (pc)))]
602 "%J0\\tbra.uni\\t%l1;"
603 [(set_attr "predicable" "false")])
605 (define_expand "cbranch<mode>4"
607 (if_then_else (match_operator 0 "nvptx_comparison_operator"
608 [(match_operand:HSDIM 1 "nvptx_register_operand" "")
609 (match_operand:HSDIM 2 "nvptx_nonmemory_operand" "")])
610 (label_ref (match_operand 3 "" ""))
614 rtx t = nvptx_expand_compare (operands[0]);
616 operands[1] = XEXP (t, 0);
617 operands[2] = XEXP (t, 1);
620 (define_expand "cbranch<mode>4"
622 (if_then_else (match_operator 0 "nvptx_float_comparison_operator"
623 [(match_operand:SDFM 1 "nvptx_register_operand" "")
624 (match_operand:SDFM 2 "nvptx_nonmemory_operand" "")])
625 (label_ref (match_operand 3 "" ""))
629 rtx t = nvptx_expand_compare (operands[0]);
631 operands[1] = XEXP (t, 0);
632 operands[2] = XEXP (t, 1);
635 (define_expand "cbranchbi4"
637 (if_then_else (match_operator 0 "predicate_operator"
638 [(match_operand:BI 1 "nvptx_register_operand" "")
639 (match_operand:BI 2 "const0_operand" "")])
640 (label_ref (match_operand 3 "" ""))
645 ;; Conditional stores
647 (define_insn "setcc_from_bi"
648 [(set (match_operand:SI 0 "nvptx_register_operand" "=R")
649 (ne:SI (match_operand:BI 1 "nvptx_register_operand" "R")
652 "%.\\tselp%t0 %0,-1,0,%1;")
654 (define_insn "sel_true<mode>"
655 [(set (match_operand:HSDIM 0 "nvptx_register_operand" "=R")
657 (ne (match_operand:BI 1 "nvptx_register_operand" "R") (const_int 0))
658 (match_operand:HSDIM 2 "nvptx_nonmemory_operand" "Ri")
659 (match_operand:HSDIM 3 "nvptx_nonmemory_operand" "Ri")))]
661 "%.\\tselp%t0\\t%0, %2, %3, %1;")
663 (define_insn "sel_true<mode>"
664 [(set (match_operand:SDFM 0 "nvptx_register_operand" "=R")
666 (ne (match_operand:BI 1 "nvptx_register_operand" "R") (const_int 0))
667 (match_operand:SDFM 2 "nvptx_nonmemory_operand" "RF")
668 (match_operand:SDFM 3 "nvptx_nonmemory_operand" "RF")))]
670 "%.\\tselp%t0\\t%0, %2, %3, %1;")
672 (define_insn "sel_false<mode>"
673 [(set (match_operand:HSDIM 0 "nvptx_register_operand" "=R")
675 (eq (match_operand:BI 1 "nvptx_register_operand" "R") (const_int 0))
676 (match_operand:HSDIM 2 "nvptx_nonmemory_operand" "Ri")
677 (match_operand:HSDIM 3 "nvptx_nonmemory_operand" "Ri")))]
679 "%.\\tselp%t0\\t%0, %3, %2, %1;")
681 (define_insn "sel_false<mode>"
682 [(set (match_operand:SDFM 0 "nvptx_register_operand" "=R")
684 (eq (match_operand:BI 1 "nvptx_register_operand" "R") (const_int 0))
685 (match_operand:SDFM 2 "nvptx_nonmemory_operand" "RF")
686 (match_operand:SDFM 3 "nvptx_nonmemory_operand" "RF")))]
688 "%.\\tselp%t0\\t%0, %3, %2, %1;")
690 (define_insn "setcc_int<mode>"
691 [(set (match_operand:SI 0 "nvptx_register_operand" "=R")
692 (match_operator:SI 1 "nvptx_comparison_operator"
693 [(match_operand:HSDIM 2 "nvptx_register_operand" "R")
694 (match_operand:HSDIM 3 "nvptx_nonmemory_operand" "Ri")]))]
696 "%.\\tset%t0%c1\\t%0, %2, %3;")
698 (define_insn "setcc_int<mode>"
699 [(set (match_operand:SI 0 "nvptx_register_operand" "=R")
700 (match_operator:SI 1 "nvptx_float_comparison_operator"
701 [(match_operand:SDFM 2 "nvptx_register_operand" "R")
702 (match_operand:SDFM 3 "nvptx_nonmemory_operand" "RF")]))]
704 "%.\\tset%t0%c1\\t%0, %2, %3;")
706 (define_insn "setcc_float<mode>"
707 [(set (match_operand:SF 0 "nvptx_register_operand" "=R")
708 (match_operator:SF 1 "nvptx_comparison_operator"
709 [(match_operand:HSDIM 2 "nvptx_register_operand" "R")
710 (match_operand:HSDIM 3 "nvptx_nonmemory_operand" "Ri")]))]
712 "%.\\tset%t0%c1\\t%0, %2, %3;")
714 (define_insn "setcc_float<mode>"
715 [(set (match_operand:SF 0 "nvptx_register_operand" "=R")
716 (match_operator:SF 1 "nvptx_float_comparison_operator"
717 [(match_operand:SDFM 2 "nvptx_register_operand" "R")
718 (match_operand:SDFM 3 "nvptx_nonmemory_operand" "RF")]))]
720 "%.\\tset%t0%c1\\t%0, %2, %3;")
722 (define_expand "cstorebi4"
723 [(set (match_operand:SI 0 "nvptx_register_operand")
724 (match_operator:SI 1 "ne_operator"
725 [(match_operand:BI 2 "nvptx_register_operand")
726 (match_operand:BI 3 "const0_operand")]))]
730 (define_expand "cstore<mode>4"
731 [(set (match_operand:SI 0 "nvptx_register_operand")
732 (match_operator:SI 1 "nvptx_comparison_operator"
733 [(match_operand:HSDIM 2 "nvptx_register_operand")
734 (match_operand:HSDIM 3 "nvptx_nonmemory_operand")]))]
738 (define_expand "cstore<mode>4"
739 [(set (match_operand:SI 0 "nvptx_register_operand")
740 (match_operator:SI 1 "nvptx_float_comparison_operator"
741 [(match_operand:SDFM 2 "nvptx_register_operand")
742 (match_operand:SDFM 3 "nvptx_nonmemory_operand")]))]
748 (define_insn "call_insn"
749 [(match_parallel 2 "call_operation"
750 [(call (mem:QI (match_operand 0 "call_insn_operand" "Rs"))
751 (match_operand 1))])]
754 return nvptx_output_call_insn (insn, NULL_RTX, operands[0]);
757 (define_insn "call_value_insn"
758 [(match_parallel 3 "call_operation"
759 [(set (match_operand 0 "nvptx_register_operand" "=R")
760 (call (mem:QI (match_operand 1 "call_insn_operand" "Rs"))
761 (match_operand 2)))])]
764 return nvptx_output_call_insn (insn, operands[0], operands[1]);
767 (define_expand "call"
768 [(match_operand 0 "" "")]
771 nvptx_expand_call (NULL_RTX, operands[0]);
775 (define_expand "call_value"
776 [(match_operand 0 "" "")
777 (match_operand 1 "" "")]
780 nvptx_expand_call (operands[0], operands[1]);
784 ;; Floating point arithmetic.
786 (define_insn "add<mode>3"
787 [(set (match_operand:SDFM 0 "nvptx_register_operand" "=R")
788 (plus:SDFM (match_operand:SDFM 1 "nvptx_register_operand" "R")
789 (match_operand:SDFM 2 "nvptx_nonmemory_operand" "RF")))]
791 "%.\\tadd%t0\\t%0, %1, %2;")
793 (define_insn "sub<mode>3"
794 [(set (match_operand:SDFM 0 "nvptx_register_operand" "=R")
795 (minus:SDFM (match_operand:SDFM 1 "nvptx_register_operand" "R")
796 (match_operand:SDFM 2 "nvptx_register_operand" "R")))]
798 "%.\\tsub%t0\\t%0, %1, %2;")
800 (define_insn "mul<mode>3"
801 [(set (match_operand:SDFM 0 "nvptx_register_operand" "=R")
802 (mult:SDFM (match_operand:SDFM 1 "nvptx_register_operand" "R")
803 (match_operand:SDFM 2 "nvptx_nonmemory_operand" "RF")))]
805 "%.\\tmul%t0\\t%0, %1, %2;")
807 (define_insn "fma<mode>4"
808 [(set (match_operand:SDFM 0 "nvptx_register_operand" "=R")
809 (fma:SDFM (match_operand:SDFM 1 "nvptx_register_operand" "R")
810 (match_operand:SDFM 2 "nvptx_nonmemory_operand" "RF")
811 (match_operand:SDFM 3 "nvptx_nonmemory_operand" "RF")))]
813 "%.\\tfma%#%t0\\t%0, %1, %2, %3;")
815 (define_insn "div<mode>3"
816 [(set (match_operand:SDFM 0 "nvptx_register_operand" "=R")
817 (div:SDFM (match_operand:SDFM 1 "nvptx_register_operand" "R")
818 (match_operand:SDFM 2 "nvptx_nonmemory_operand" "RF")))]
820 "%.\\tdiv%#%t0\\t%0, %1, %2;")
822 (define_insn "copysign<mode>3"
823 [(set (match_operand:SDFM 0 "nvptx_register_operand" "=R")
824 (unspec:SDFM [(match_operand:SDFM 1 "nvptx_register_operand" "R")
825 (match_operand:SDFM 2 "nvptx_register_operand" "R")]
828 "%.\\tcopysign%t0\\t%0, %2, %1;")
830 (define_insn "smin<mode>3"
831 [(set (match_operand:SDFM 0 "nvptx_register_operand" "=R")
832 (smin:SDFM (match_operand:SDFM 1 "nvptx_register_operand" "R")
833 (match_operand:SDFM 2 "nvptx_nonmemory_operand" "RF")))]
835 "%.\\tmin%t0\\t%0, %1, %2;")
837 (define_insn "smax<mode>3"
838 [(set (match_operand:SDFM 0 "nvptx_register_operand" "=R")
839 (smax:SDFM (match_operand:SDFM 1 "nvptx_register_operand" "R")
840 (match_operand:SDFM 2 "nvptx_nonmemory_operand" "RF")))]
842 "%.\\tmax%t0\\t%0, %1, %2;")
844 (define_insn "abs<mode>2"
845 [(set (match_operand:SDFM 0 "nvptx_register_operand" "=R")
846 (abs:SDFM (match_operand:SDFM 1 "nvptx_register_operand" "R")))]
848 "%.\\tabs%t0\\t%0, %1;")
850 (define_insn "neg<mode>2"
851 [(set (match_operand:SDFM 0 "nvptx_register_operand" "=R")
852 (neg:SDFM (match_operand:SDFM 1 "nvptx_register_operand" "R")))]
854 "%.\\tneg%t0\\t%0, %1;")
856 (define_insn "sqrt<mode>2"
857 [(set (match_operand:SDFM 0 "nvptx_register_operand" "=R")
858 (sqrt:SDFM (match_operand:SDFM 1 "nvptx_register_operand" "R")))]
860 "%.\\tsqrt%#%t0\\t%0, %1;")
862 (define_expand "sincossf3"
863 [(set (match_operand:SF 0 "nvptx_register_operand" "=R")
864 (unspec:SF [(match_operand:SF 2 "nvptx_register_operand" "R")]
866 (set (match_operand:SF 1 "nvptx_register_operand" "=R")
867 (unspec:SF [(match_dup 2)] UNSPEC_SIN))]
868 "flag_unsafe_math_optimizations"
870 operands[2] = make_safe_from (operands[2], operands[0]);
873 (define_insn "sinsf2"
874 [(set (match_operand:SF 0 "nvptx_register_operand" "=R")
875 (unspec:SF [(match_operand:SF 1 "nvptx_register_operand" "R")]
877 "flag_unsafe_math_optimizations"
878 "%.\\tsin.approx%t0\\t%0, %1;")
880 (define_insn "cossf2"
881 [(set (match_operand:SF 0 "nvptx_register_operand" "=R")
882 (unspec:SF [(match_operand:SF 1 "nvptx_register_operand" "R")]
884 "flag_unsafe_math_optimizations"
885 "%.\\tcos.approx%t0\\t%0, %1;")
887 (define_insn "log2sf2"
888 [(set (match_operand:SF 0 "nvptx_register_operand" "=R")
889 (unspec:SF [(match_operand:SF 1 "nvptx_register_operand" "R")]
891 "flag_unsafe_math_optimizations"
892 "%.\\tlg2.approx%t0\\t%0, %1;")
894 (define_insn "exp2sf2"
895 [(set (match_operand:SF 0 "nvptx_register_operand" "=R")
896 (unspec:SF [(match_operand:SF 1 "nvptx_register_operand" "R")]
898 "flag_unsafe_math_optimizations"
899 "%.\\tex2.approx%t0\\t%0, %1;")
901 ;; Conversions involving floating point
903 (define_insn "extendsfdf2"
904 [(set (match_operand:DF 0 "nvptx_register_operand" "=R")
905 (float_extend:DF (match_operand:SF 1 "nvptx_register_operand" "R")))]
907 "%.\\tcvt%t0%t1\\t%0, %1;")
909 (define_insn "truncdfsf2"
910 [(set (match_operand:SF 0 "nvptx_register_operand" "=R")
911 (float_truncate:SF (match_operand:DF 1 "nvptx_register_operand" "R")))]
913 "%.\\tcvt%#%t0%t1\\t%0, %1;")
915 (define_insn "floatunssi<mode>2"
916 [(set (match_operand:SDFM 0 "nvptx_register_operand" "=R")
917 (unsigned_float:SDFM (match_operand:SI 1 "nvptx_register_operand" "R")))]
919 "%.\\tcvt%#%t0.u%T1\\t%0, %1;")
921 (define_insn "floatsi<mode>2"
922 [(set (match_operand:SDFM 0 "nvptx_register_operand" "=R")
923 (float:SDFM (match_operand:SI 1 "nvptx_register_operand" "R")))]
925 "%.\\tcvt%#%t0.s%T1\\t%0, %1;")
927 (define_insn "floatunsdi<mode>2"
928 [(set (match_operand:SDFM 0 "nvptx_register_operand" "=R")
929 (unsigned_float:SDFM (match_operand:DI 1 "nvptx_register_operand" "R")))]
931 "%.\\tcvt%#%t0.u%T1\\t%0, %1;")
933 (define_insn "floatdi<mode>2"
934 [(set (match_operand:SDFM 0 "nvptx_register_operand" "=R")
935 (float:SDFM (match_operand:DI 1 "nvptx_register_operand" "R")))]
937 "%.\\tcvt%#%t0.s%T1\\t%0, %1;")
939 (define_insn "fixuns_trunc<mode>si2"
940 [(set (match_operand:SI 0 "nvptx_register_operand" "=R")
941 (unsigned_fix:SI (match_operand:SDFM 1 "nvptx_register_operand" "R")))]
943 "%.\\tcvt.rzi.u%T0%t1\\t%0, %1;")
945 (define_insn "fix_trunc<mode>si2"
946 [(set (match_operand:SI 0 "nvptx_register_operand" "=R")
947 (fix:SI (match_operand:SDFM 1 "nvptx_register_operand" "R")))]
949 "%.\\tcvt.rzi.s%T0%t1\\t%0, %1;")
951 (define_insn "fixuns_trunc<mode>di2"
952 [(set (match_operand:DI 0 "nvptx_register_operand" "=R")
953 (unsigned_fix:DI (match_operand:SDFM 1 "nvptx_register_operand" "R")))]
955 "%.\\tcvt.rzi.u%T0%t1\\t%0, %1;")
957 (define_insn "fix_trunc<mode>di2"
958 [(set (match_operand:DI 0 "nvptx_register_operand" "=R")
959 (fix:DI (match_operand:SDFM 1 "nvptx_register_operand" "R")))]
961 "%.\\tcvt.rzi.s%T0%t1\\t%0, %1;")
963 (define_int_iterator FPINT [UNSPEC_FPINT_FLOOR UNSPEC_FPINT_BTRUNC
964 UNSPEC_FPINT_CEIL UNSPEC_FPINT_NEARBYINT])
965 (define_int_attr fpint_name [(UNSPEC_FPINT_FLOOR "floor")
966 (UNSPEC_FPINT_BTRUNC "btrunc")
967 (UNSPEC_FPINT_CEIL "ceil")
968 (UNSPEC_FPINT_NEARBYINT "nearbyint")])
969 (define_int_attr fpint_roundingmode [(UNSPEC_FPINT_FLOOR ".rmi")
970 (UNSPEC_FPINT_BTRUNC ".rzi")
971 (UNSPEC_FPINT_CEIL ".rpi")
972 (UNSPEC_FPINT_NEARBYINT "%#i")])
974 (define_insn "<FPINT:fpint_name><SDFM:mode>2"
975 [(set (match_operand:SDFM 0 "nvptx_register_operand" "=R")
976 (unspec:SDFM [(match_operand:SDFM 1 "nvptx_register_operand" "R")]
979 "%.\\tcvt<FPINT:fpint_roundingmode>%t0%t1\\t%0, %1;")
981 (define_int_iterator FPINT2 [UNSPEC_FPINT_FLOOR UNSPEC_FPINT_CEIL])
982 (define_int_attr fpint2_name [(UNSPEC_FPINT_FLOOR "lfloor")
983 (UNSPEC_FPINT_CEIL "lceil")])
984 (define_int_attr fpint2_roundingmode [(UNSPEC_FPINT_FLOOR ".rmi")
985 (UNSPEC_FPINT_CEIL ".rpi")])
987 (define_insn "<FPINT2:fpint2_name><SDFM:mode><SDIM:mode>2"
988 [(set (match_operand:SDIM 0 "nvptx_register_operand" "=R")
989 (unspec:SDIM [(match_operand:SDFM 1 "nvptx_register_operand" "R")]
992 "%.\\tcvt<FPINT2:fpint2_roundingmode>.s%T0%t1\\t%0, %1;")
1006 (define_insn "fake_nop"
1010 .reg .u32 %%nop_src;
1011 .reg .u32 %%nop_dst;
1012 mov.u32 %%nop_dst, %%nop_src;
1015 (define_insn "return"
1019 return nvptx_output_return ();
1021 [(set_attr "predicable" "false")])
1023 (define_expand "epilogue"
1024 [(clobber (const_int 0))]
1027 if (TARGET_SOFT_STACK)
1028 emit_insn (gen_set_softstack_insn (gen_rtx_REG (Pmode,
1029 SOFTSTACK_PREV_REGNUM)));
1030 emit_jump_insn (gen_return ());
1034 (define_expand "nonlocal_goto"
1035 [(match_operand 0 "" "")
1036 (match_operand 1 "" "")
1037 (match_operand 2 "" "")
1038 (match_operand 3 "" "")]
1041 sorry ("target cannot support nonlocal goto.");
1042 emit_insn (gen_nop ());
1046 (define_expand "nonlocal_goto_receiver"
1050 sorry ("target cannot support nonlocal goto.");
1053 (define_expand "allocate_stack"
1054 [(match_operand 0 "nvptx_register_operand")
1055 (match_operand 1 "nvptx_register_operand")]
1058 if (TARGET_SOFT_STACK)
1060 emit_move_insn (stack_pointer_rtx,
1061 gen_rtx_MINUS (Pmode, stack_pointer_rtx, operands[1]));
1062 emit_insn (gen_set_softstack_insn (stack_pointer_rtx));
1063 emit_move_insn (operands[0], virtual_stack_dynamic_rtx);
1066 /* The ptx documentation specifies an alloca intrinsic (for 32 bit
1067 only) but notes it is not implemented. The assembler emits a
1068 confused error message. Issue a blunt one now instead. */
1069 sorry ("target cannot support alloca.");
1070 emit_insn (gen_nop ());
1074 (define_insn "set_softstack_insn"
1075 [(unspec [(match_operand 0 "nvptx_register_operand" "R")]
1076 UNSPEC_SET_SOFTSTACK)]
1079 return nvptx_output_set_softstack (REGNO (operands[0]));
1082 (define_expand "restore_stack_block"
1083 [(match_operand 0 "register_operand" "")
1084 (match_operand 1 "register_operand" "")]
1087 if (TARGET_SOFT_STACK)
1089 emit_move_insn (operands[0], operands[1]);
1090 emit_insn (gen_set_softstack_insn (operands[0]));
1095 (define_expand "restore_stack_function"
1096 [(match_operand 0 "register_operand" "")
1097 (match_operand 1 "register_operand" "")]
1104 [(trap_if (const_int 1) (const_int 0))]
1108 (define_insn "trap_if_true"
1109 [(trap_if (ne (match_operand:BI 0 "nvptx_register_operand" "R")
1113 "%j0 trap; %j0 exit;"
1114 [(set_attr "predicable" "false")])
1116 (define_insn "trap_if_false"
1117 [(trap_if (eq (match_operand:BI 0 "nvptx_register_operand" "R")
1121 "%J0 trap; %J0 exit;"
1122 [(set_attr "predicable" "false")])
1124 (define_expand "ctrap<mode>4"
1125 [(trap_if (match_operator 0 "nvptx_comparison_operator"
1126 [(match_operand:SDIM 1 "nvptx_register_operand")
1127 (match_operand:SDIM 2 "nvptx_nonmemory_operand")])
1128 (match_operand 3 "const0_operand"))]
1131 rtx t = nvptx_expand_compare (operands[0]);
1132 emit_insn (gen_trap_if_true (t));
1136 (define_insn "oacc_dim_size"
1137 [(set (match_operand:SI 0 "nvptx_register_operand" "")
1138 (unspec:SI [(match_operand:SI 1 "const_int_operand" "")]
1142 static const char *const asms[] =
1143 { /* Must match oacc_loop_levels ordering. */
1144 "%.\\tmov.u32\\t%0, %%nctaid.x;", /* gang */
1145 "%.\\tmov.u32\\t%0, %%ntid.y;", /* worker */
1146 "%.\\tmov.u32\\t%0, %%ntid.x;", /* vector */
1148 return asms[INTVAL (operands[1])];
1151 (define_insn "oacc_dim_pos"
1152 [(set (match_operand:SI 0 "nvptx_register_operand" "")
1153 (unspec_volatile:SI [(match_operand:SI 1 "const_int_operand" "")]
1157 static const char *const asms[] =
1158 { /* Must match oacc_loop_levels ordering. */
1159 "%.\\tmov.u32\\t%0, %%ctaid.x;", /* gang */
1160 "%.\\tmov.u32\\t%0, %%tid.y;", /* worker */
1161 "%.\\tmov.u32\\t%0, %%tid.x;", /* vector */
1163 return asms[INTVAL (operands[1])];
1166 (define_insn "nvptx_fork"
1167 [(unspec_volatile:SI [(match_operand:SI 0 "const_int_operand" "")]
1171 [(set_attr "predicable" "false")])
1173 (define_insn "nvptx_forked"
1174 [(unspec_volatile:SI [(match_operand:SI 0 "const_int_operand" "")]
1178 [(set_attr "predicable" "false")])
1180 (define_insn "nvptx_joining"
1181 [(unspec_volatile:SI [(match_operand:SI 0 "const_int_operand" "")]
1185 [(set_attr "predicable" "false")])
1187 (define_insn "nvptx_join"
1188 [(unspec_volatile:SI [(match_operand:SI 0 "const_int_operand" "")]
1192 [(set_attr "predicable" "false")])
1194 (define_expand "oacc_fork"
1195 [(set (match_operand:SI 0 "nvptx_nonmemory_operand" "")
1196 (match_operand:SI 1 "general_operand" ""))
1197 (unspec_volatile:SI [(match_operand:SI 2 "const_int_operand" "")]
1201 if (operands[0] != const0_rtx)
1202 emit_move_insn (operands[0], operands[1]);
1203 nvptx_expand_oacc_fork (INTVAL (operands[2]));
1207 (define_expand "oacc_join"
1208 [(set (match_operand:SI 0 "nvptx_nonmemory_operand" "")
1209 (match_operand:SI 1 "general_operand" ""))
1210 (unspec_volatile:SI [(match_operand:SI 2 "const_int_operand" "")]
1214 if (operands[0] != const0_rtx)
1215 emit_move_insn (operands[0], operands[1]);
1216 nvptx_expand_oacc_join (INTVAL (operands[2]));
1220 ;; only 32-bit shuffles exist.
1221 (define_insn "nvptx_shuffle<mode>"
1222 [(set (match_operand:BITS 0 "nvptx_register_operand" "=R")
1224 [(match_operand:BITS 1 "nvptx_register_operand" "R")
1225 (match_operand:SI 2 "nvptx_nonmemory_operand" "Ri")
1226 (match_operand:SI 3 "const_int_operand" "n")]
1229 "%.\\tshfl%S3.b32\\t%0, %1, %2, 31;")
1231 (define_insn "nvptx_vote_ballot"
1232 [(set (match_operand:SI 0 "nvptx_register_operand" "=R")
1233 (unspec:SI [(match_operand:BI 1 "nvptx_register_operand" "R")]
1234 UNSPEC_VOTE_BALLOT))]
1236 "%.\\tvote.ballot.b32\\t%0, %1;")
1238 ;; Patterns for OpenMP SIMD-via-SIMT lowering
1240 (define_insn "omp_simt_enter_insn"
1241 [(set (match_operand 0 "nvptx_register_operand" "=R")
1242 (unspec_volatile [(match_operand 1 "nvptx_nonmemory_operand" "Ri")
1243 (match_operand 2 "nvptx_nonmemory_operand" "Ri")]
1244 UNSPECV_SIMT_ENTER))]
1247 return nvptx_output_simt_enter (operands[0], operands[1], operands[2]);
1250 (define_expand "omp_simt_enter"
1251 [(match_operand 0 "nvptx_register_operand" "=R")
1252 (match_operand 1 "nvptx_nonmemory_operand" "Ri")
1253 (match_operand 2 "const_int_operand" "n")]
1256 if (!CONST_INT_P (operands[1]))
1257 cfun->machine->simt_stack_size = HOST_WIDE_INT_M1U;
1259 cfun->machine->simt_stack_size = MAX (UINTVAL (operands[1]),
1260 cfun->machine->simt_stack_size);
1261 cfun->machine->simt_stack_align = MAX (UINTVAL (operands[2]),
1262 cfun->machine->simt_stack_align);
1263 cfun->machine->has_simtreg = true;
1264 emit_insn (gen_omp_simt_enter_insn (operands[0], operands[1], operands[2]));
1268 (define_insn "omp_simt_exit"
1269 [(unspec_volatile [(match_operand 0 "nvptx_register_operand" "R")]
1273 return nvptx_output_simt_exit (operands[0]);
1276 ;; Implement IFN_GOMP_SIMT_LANE: set operand 0 to lane index
1277 (define_insn "omp_simt_lane"
1278 [(set (match_operand:SI 0 "nvptx_register_operand" "")
1279 (unspec:SI [(const_int 0)] UNSPEC_LANEID))]
1281 "%.\\tmov.u32\\t%0, %%laneid;")
1283 ;; Implement IFN_GOMP_SIMT_ORDERED: copy operand 1 to operand 0 and
1284 ;; place a compiler barrier to disallow unrolling/peeling the containing loop
1285 (define_expand "omp_simt_ordered"
1286 [(match_operand:SI 0 "nvptx_register_operand" "=R")
1287 (match_operand:SI 1 "nvptx_register_operand" "R")]
1290 emit_move_insn (operands[0], operands[1]);
1291 emit_insn (gen_nvptx_nounroll ());
1295 ;; Implement IFN_GOMP_SIMT_XCHG_BFLY: perform a "butterfly" exchange
1297 (define_expand "omp_simt_xchg_bfly"
1298 [(match_operand 0 "nvptx_register_operand" "=R")
1299 (match_operand 1 "nvptx_register_operand" "R")
1300 (match_operand:SI 2 "nvptx_nonmemory_operand" "Ri")]
1303 emit_insn (nvptx_gen_shuffle (operands[0], operands[1], operands[2],
1308 ;; Implement IFN_GOMP_SIMT_XCHG_IDX: broadcast value in operand 1
1309 ;; from lane given by index in operand 2 to operand 0 in all lanes
1310 (define_expand "omp_simt_xchg_idx"
1311 [(match_operand 0 "nvptx_register_operand" "=R")
1312 (match_operand 1 "nvptx_register_operand" "R")
1313 (match_operand:SI 2 "nvptx_nonmemory_operand" "Ri")]
1316 emit_insn (nvptx_gen_shuffle (operands[0], operands[1], operands[2],
1321 ;; Implement IFN_GOMP_SIMT_VOTE_ANY:
1322 ;; set operand 0 to zero iff all lanes supply zero in operand 1
1323 (define_expand "omp_simt_vote_any"
1324 [(match_operand:SI 0 "nvptx_register_operand" "=R")
1325 (match_operand:SI 1 "nvptx_register_operand" "R")]
1328 rtx pred = gen_reg_rtx (BImode);
1329 emit_move_insn (pred, gen_rtx_NE (BImode, operands[1], const0_rtx));
1330 emit_insn (gen_nvptx_vote_ballot (operands[0], pred));
1334 ;; Implement IFN_GOMP_SIMT_LAST_LANE:
1335 ;; set operand 0 to the lowest lane index that passed non-zero in operand 1
1336 (define_expand "omp_simt_last_lane"
1337 [(match_operand:SI 0 "nvptx_register_operand" "=R")
1338 (match_operand:SI 1 "nvptx_register_operand" "R")]
1341 rtx pred = gen_reg_rtx (BImode);
1342 rtx tmp = gen_reg_rtx (SImode);
1343 emit_move_insn (pred, gen_rtx_NE (BImode, operands[1], const0_rtx));
1344 emit_insn (gen_nvptx_vote_ballot (tmp, pred));
1345 emit_insn (gen_ctzsi2 (operands[0], tmp));
1349 ;; extract parts of a 64 bit object into 2 32-bit ints
1350 (define_insn "unpack<mode>si2"
1351 [(set (match_operand:SI 0 "nvptx_register_operand" "=R")
1352 (unspec:SI [(match_operand:BITD 2 "nvptx_register_operand" "R")
1353 (const_int 0)] UNSPEC_BIT_CONV))
1354 (set (match_operand:SI 1 "nvptx_register_operand" "=R")
1355 (unspec:SI [(match_dup 2) (const_int 1)] UNSPEC_BIT_CONV))]
1357 "%.\\tmov.b64\\t{%0,%1}, %2;")
1359 ;; pack 2 32-bit ints into a 64 bit object
1360 (define_insn "packsi<mode>2"
1361 [(set (match_operand:BITD 0 "nvptx_register_operand" "=R")
1362 (unspec:BITD [(match_operand:SI 1 "nvptx_register_operand" "R")
1363 (match_operand:SI 2 "nvptx_register_operand" "R")]
1366 "%.\\tmov.b64\\t%0, {%1,%2};")
1370 (define_expand "atomic_compare_and_swap<mode>"
1371 [(match_operand:SI 0 "nvptx_register_operand") ;; bool success output
1372 (match_operand:SDIM 1 "nvptx_register_operand") ;; oldval output
1373 (match_operand:SDIM 2 "memory_operand") ;; memory
1374 (match_operand:SDIM 3 "nvptx_register_operand") ;; expected input
1375 (match_operand:SDIM 4 "nvptx_register_operand") ;; newval input
1376 (match_operand:SI 5 "const_int_operand") ;; is_weak
1377 (match_operand:SI 6 "const_int_operand") ;; success model
1378 (match_operand:SI 7 "const_int_operand")] ;; failure model
1381 emit_insn (gen_atomic_compare_and_swap<mode>_1
1382 (operands[1], operands[2], operands[3], operands[4], operands[6]));
1384 rtx cond = gen_reg_rtx (BImode);
1385 emit_move_insn (cond, gen_rtx_EQ (BImode, operands[1], operands[3]));
1386 emit_insn (gen_sel_truesi (operands[0], cond, GEN_INT (1), GEN_INT (0)));
1390 (define_insn "atomic_compare_and_swap<mode>_1"
1391 [(set (match_operand:SDIM 0 "nvptx_register_operand" "=R")
1392 (unspec_volatile:SDIM
1393 [(match_operand:SDIM 1 "memory_operand" "+m")
1394 (match_operand:SDIM 2 "nvptx_nonmemory_operand" "Ri")
1395 (match_operand:SDIM 3 "nvptx_nonmemory_operand" "Ri")
1396 (match_operand:SI 4 "const_int_operand")]
1399 (unspec_volatile:SDIM [(const_int 0)] UNSPECV_CAS))]
1401 "%.\\tatom%A1.cas.b%T0\\t%0, %1, %2, %3;"
1402 [(set_attr "atomic" "true")])
1404 (define_insn "atomic_exchange<mode>"
1405 [(set (match_operand:SDIM 0 "nvptx_register_operand" "=R") ;; output
1406 (unspec_volatile:SDIM
1407 [(match_operand:SDIM 1 "memory_operand" "+m") ;; memory
1408 (match_operand:SI 3 "const_int_operand")] ;; model
1411 (match_operand:SDIM 2 "nvptx_nonmemory_operand" "Ri"))] ;; input
1413 "%.\\tatom%A1.exch.b%T0\\t%0, %1, %2;"
1414 [(set_attr "atomic" "true")])
1416 (define_insn "atomic_fetch_add<mode>"
1417 [(set (match_operand:SDIM 1 "memory_operand" "+m")
1418 (unspec_volatile:SDIM
1419 [(plus:SDIM (match_dup 1)
1420 (match_operand:SDIM 2 "nvptx_nonmemory_operand" "Ri"))
1421 (match_operand:SI 3 "const_int_operand")] ;; model
1423 (set (match_operand:SDIM 0 "nvptx_register_operand" "=R")
1426 "%.\\tatom%A1.add%t0\\t%0, %1, %2;"
1427 [(set_attr "atomic" "true")])
1429 (define_insn "atomic_fetch_addsf"
1430 [(set (match_operand:SF 1 "memory_operand" "+m")
1432 [(plus:SF (match_dup 1)
1433 (match_operand:SF 2 "nvptx_nonmemory_operand" "RF"))
1434 (match_operand:SI 3 "const_int_operand")] ;; model
1436 (set (match_operand:SF 0 "nvptx_register_operand" "=R")
1439 "%.\\tatom%A1.add%t0\\t%0, %1, %2;"
1440 [(set_attr "atomic" "true")])
1442 (define_code_iterator any_logic [and ior xor])
1443 (define_code_attr logic [(and "and") (ior "or") (xor "xor")])
1445 (define_insn "atomic_fetch_<logic><mode>"
1446 [(set (match_operand:SDIM 1 "memory_operand" "+m")
1447 (unspec_volatile:SDIM
1448 [(any_logic:SDIM (match_dup 1)
1449 (match_operand:SDIM 2 "nvptx_nonmemory_operand" "Ri"))
1450 (match_operand:SI 3 "const_int_operand")] ;; model
1452 (set (match_operand:SDIM 0 "nvptx_register_operand" "=R")
1454 "<MODE>mode == SImode || TARGET_SM35"
1455 "%.\\tatom%A1.b%T0.<logic>\\t%0, %1, %2;"
1456 [(set_attr "atomic" "true")])
1458 (define_insn "nvptx_barsync"
1459 [(unspec_volatile [(match_operand:SI 0 "nvptx_nonmemory_operand" "Ri")
1460 (match_operand:SI 1 "const_int_operand")]
1464 if (INTVAL (operands[1]) == 0)
1465 return "\\tbar.sync\\t%0;";
1467 return "\\tbar.sync\\t%0, %1;";
1469 [(set_attr "predicable" "false")])
1471 (define_expand "memory_barrier"
1473 (unspec_volatile:BLK [(match_dup 0)] UNSPECV_MEMBAR))]
1476 operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
1477 MEM_VOLATILE_P (operands[0]) = 1;
1480 ;; Ptx defines the memory barriers membar.cta, membar.gl and membar.sys
1481 ;; (corresponding to cuda functions threadfence_block, threadfence and
1482 ;; threadfence_system). For the insn memory_barrier we use membar.sys. This
1483 ;; may be overconservative, but before using membar.gl instead we'll need to
1484 ;; explain in detail why it's safe to use. For now, use membar.sys.
1485 (define_insn "*memory_barrier"
1486 [(set (match_operand:BLK 0 "" "")
1487 (unspec_volatile:BLK [(match_dup 0)] UNSPECV_MEMBAR))]
1490 [(set_attr "predicable" "false")])
1492 (define_expand "nvptx_membar_cta"
1494 (unspec_volatile:BLK [(match_dup 0)] UNSPECV_MEMBAR_CTA))]
1497 operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
1498 MEM_VOLATILE_P (operands[0]) = 1;
1501 (define_insn "*nvptx_membar_cta"
1502 [(set (match_operand:BLK 0 "" "")
1503 (unspec_volatile:BLK [(match_dup 0)] UNSPECV_MEMBAR_CTA))]
1506 [(set_attr "predicable" "false")])
1508 (define_insn "nvptx_nounroll"
1509 [(unspec_volatile [(const_int 0)] UNSPECV_NOUNROLL)]
1511 "\\t.pragma \\\"nounroll\\\";"
1512 [(set_attr "predicable" "false")])
1514 (define_insn "nvptx_red_partition"
1515 [(set (match_operand:DI 0 "nonimmediate_operand" "=R")
1516 (unspec_volatile [(match_operand:DI 1 "const_int_operand")]
1520 return nvptx_output_red_partition (operands[0], operands[1]);
1522 [(set_attr "predicable" "false")])