case E_DImode:
return ".u64";
+ case E_HFmode:
+ return ".f16";
case E_SFmode:
return ".f32";
case E_DFmode:
fputs ("\t.version\t6.3\n", asm_out_file);
else
fputs ("\t.version\t3.1\n", asm_out_file);
- if (TARGET_SM35)
+ if (TARGET_SM53)
+ fputs ("\t.target\tsm_53\n", asm_out_file);
+ else if (TARGET_SM35)
fputs ("\t.target\tsm_35\n", asm_out_file);
else
fputs ("\t.target\tsm_30\n", asm_out_file);
if (strcmp (name, "sm_30") == 0)
return !TARGET_SM35;
if (strcmp (name, "sm_35") == 0)
- return TARGET_SM35;
+ return TARGET_SM35 && !TARGET_SM53;
+ if (strcmp (name, "sm_53") == 0)
+ return TARGET_SM53;
return 0;
default:
gcc_unreachable ();
return true;
}
+static bool
+nvptx_scalar_mode_supported_p (scalar_mode mode)
+{
+ if (mode == HFmode && TARGET_SM53)
+ return true;
+
+ return default_scalar_mode_supported_p (mode);
+}
+
+static bool
+nvptx_libgcc_floating_mode_supported_p (scalar_float_mode mode)
+{
+ if (mode == HFmode && TARGET_SM53)
+ return true;
+
+ return default_libgcc_floating_mode_supported_p (mode);
+}
+
static bool
nvptx_vector_mode_supported (machine_mode mode)
{
#undef TARGET_CANNOT_FORCE_CONST_MEM
#define TARGET_CANNOT_FORCE_CONST_MEM nvptx_cannot_force_const_mem
+#undef TARGET_SCALAR_MODE_SUPPORTED_P
+#define TARGET_SCALAR_MODE_SUPPORTED_P nvptx_scalar_mode_supported_p
+
+#undef TARGET_LIBGCC_FLOATING_MODE_SUPPORTED_P
+#define TARGET_LIBGCC_FLOATING_MODE_SUPPORTED_P \
+ nvptx_libgcc_floating_mode_supported_p
+
#undef TARGET_VECTOR_MODE_SUPPORTED_P
#define TARGET_VECTOR_MODE_SUPPORTED_P nvptx_vector_mode_supported
}
[(set_attr "subregs_ok" "true")])
+(define_insn "*movhf_insn"
+ [(set (match_operand:HF 0 "nonimmediate_operand" "=R,R,m")
+ (match_operand:HF 1 "nonimmediate_operand" "R,m,R"))]
+ "!MEM_P (operands[0]) || REG_P (operands[1])"
+ "@
+ %.\\tmov.b16\\t%0, %1;
+ %.\\tld.b16\\t%0, %1;
+ %.\\tst.b16\\t%0, %1;")
+
+(define_expand "movhf"
+ [(set (match_operand:HF 0 "nonimmediate_operand" "")
+ (match_operand:HF 1 "nonimmediate_operand" ""))]
+ ""
+{
+ /* Load HFmode constants as SFmode with an explicit FLOAT_TRUNCATE. */
+ if (CONST_DOUBLE_P (operands[1]))
+ {
+ rtx tmp1 = gen_reg_rtx (SFmode);
+ REAL_VALUE_TYPE d = *CONST_DOUBLE_REAL_VALUE (operands[1]);
+ real_convert (&d, SFmode, &d);
+ emit_move_insn (tmp1, const_double_from_real_value (d, SFmode));
+
+ if (!REG_P (operands[0]))
+ {
+ rtx tmp2 = gen_reg_rtx (HFmode);
+ emit_insn (gen_truncsfhf2 (tmp2, tmp1));
+ emit_move_insn (operands[0], tmp2);
+ }
+ else
+ emit_insn (gen_truncsfhf2 (operands[0], tmp1));
+ DONE;
+ }
+
+ if (MEM_P (operands[0]) && !REG_P (operands[1]))
+ {
+ rtx tmp = gen_reg_rtx (HFmode);
+ emit_move_insn (tmp, operands[1]);
+ emit_move_insn (operands[0], tmp);
+ DONE;
+ }
+})
+
(define_insn "load_arg_reg<mode>"
[(set (match_operand:QHIM 0 "nvptx_register_operand" "=R")
(unspec:QHIM [(match_operand 1 "const_int_operand" "n")]
"flag_unsafe_math_optimizations"
"%.\\tex2.approx%t0\\t%0, %1;")
+;; HFmode floating point arithmetic.
+
+(define_insn "addhf3"
+ [(set (match_operand:HF 0 "nvptx_register_operand" "=R")
+ (plus:HF (match_operand:HF 1 "nvptx_register_operand" "R")
+ (match_operand:HF 2 "nvptx_register_operand" "R")))]
+ "TARGET_SM53"
+ "%.\\tadd.f16\\t%0, %1, %2;")
+
+(define_insn "subhf3"
+ [(set (match_operand:HF 0 "nvptx_register_operand" "=R")
+ (minus:HF (match_operand:HF 1 "nvptx_register_operand" "R")
+ (match_operand:HF 2 "nvptx_register_operand" "R")))]
+ "TARGET_SM53"
+ "%.\\tsub.f16\\t%0, %1, %2;")
+
+(define_insn "mulhf3"
+ [(set (match_operand:HF 0 "nvptx_register_operand" "=R")
+ (mult:HF (match_operand:HF 1 "nvptx_register_operand" "R")
+ (match_operand:HF 2 "nvptx_register_operand" "R")))]
+ "TARGET_SM53"
+ "%.\\tmul.f16\\t%0, %1, %2;")
+
;; Conversions involving floating point
(define_insn "extendsfdf2"
""
"%.\\tcvt<FPINT2:fpint2_roundingmode>.s%T0%t1\\t%0, %1;")
+(define_insn "extendhf<mode>2"
+ [(set (match_operand:SDFM 0 "nvptx_register_operand" "=R")
+ (float_extend:SDFM (match_operand:HF 1 "nvptx_register_operand" "R")))]
+ "TARGET_SM53"
+ "%.\\tcvt%t0%t1\\t%0, %1;")
+
+(define_insn "trunc<mode>hf2"
+ [(set (match_operand:HF 0 "nvptx_register_operand" "=R")
+ (float_truncate:HF (match_operand:SDFM 1 "nvptx_register_operand" "R")))]
+ "TARGET_SM53"
+ "%.\\tcvt%#%t0%t1\\t%0, %1;")
+
;; Vector operations
(define_insn "*vec_set<mode>_0"
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -misa=sm_53 -mptx=6.3 -ffast-math" } */
+
+_Float16 var;
+
+float load()
+{
+ return var;
+}
+
+void store(float x)
+{
+ var = x;
+}
+
+void move(_Float16 *dst, _Float16 *src)
+{
+ *dst = *src;
+}
+
+double plus(double x, double y)
+{
+ _Float16 hx = x;
+ _Float16 hy = y;
+ _Float16 hz = hx + hy;
+ return hz;
+}
+
+double minus(double x, double y)
+{
+ _Float16 hx = x;
+ _Float16 hy = y;
+ _Float16 hz = hx - hy;
+ return hz;
+}
+
+double mult(double x, double y)
+{
+ _Float16 hx = x;
+ _Float16 hy = y;
+ _Float16 hz = hx * hy;
+ return hz;
+}
+
+/* { dg-final { scan-assembler-times "ld.b16" 2 } } */
+/* { dg-final { scan-assembler-times "cvt.f32.f16" 1 } } */
+/* { dg-final { scan-assembler-times "cvt.rn.f16.f32" 1 } } */
+/* { dg-final { scan-assembler-times "st.b16" 2 } } */
+/* { dg-final { scan-assembler-times "add.f16" 1 } } */
+/* { dg-final { scan-assembler-times "sub.f16" 1 } } */
+/* { dg-final { scan-assembler-times "mul.f16" 1 } } */
+/* { dg-final { scan-assembler-times "cvt.rn.f16.f64" 6 } } */
+/* { dg-final { scan-assembler-times "cvt.f64.f16" 3 } } */