public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH], Add rounding built-ins to the _Float<N> and _Float<N>X built-in functions
@ 2017-10-28  1:11 Michael Meissner
  2017-11-01 18:32 ` Segher Boessenkool
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Michael Meissner @ 2017-10-28  1:11 UTC (permalink / raw)
  To: GCC Patches, Segher Boessenkool, David Edelsohn, Bill Schmidt

[-- Attachment #1: Type: text/plain, Size: 2001 bytes --]

The power9 (running PowerPC ISA 3.0) has a round to integer instruction
(XSRQPI) that does various flavors of round an IEEE 128-bit floating point to
integeral values.  This patch adds the support to the machine independent
portion of the compiler, and adds the necessary support for ceilf128,
roundf128, truncf128, and roundf128 to the PowerPC backend when you use
-mcpu=power9.

I have done bootstrap builds on both x86-64 and a little endian power8 system.
Can I install these patches to the trunk?

[gcc]
2017-10-27  Michael Meissner  <meissner@linux.vnet.ibm.com>

	* builtins.def: (_Float<N> and _Float<N>X BUILT_IN_CEIL): Add
	_Float<N> and _Float<N>X variants for rounding built-in
	functions.
	(_Float<N> and _Float<N>X BUILT_IN_FLOOR): Likewise.
	(_Float<N> and _Float<N>X BUILT_IN_NEARBYINT): Likewise.
	(_Float<N> and _Float<N>X BUILT_IN_RINT): Likewise.
	(_Float<N> and _Float<N>X BUILT_IN_ROUND): Likewise.
	(_Float<N> and _Float<N>X BUILT_IN_TRUNC): Likewise.
	* builtins.c (mathfn_built_in_2): Likewise.
	* internal-fn.def (CEIL): Likewise.
	(FLOOR): Likewise.
	(NEARBYINT): Likewise.
	(RINT): Likewise.
	(ROUND): Likewise.
	(TRUNC): Likewise.
	* fold-const.c (tree_call_nonnegative_warnv_p): Likewise.
	(integer_valued_real_call_p): Likewise.
	* fold-const-call.c (fold_const_call_ss): Likewise.
	* config/rs6000/rs6000.md (floor<mode>2): Add support for IEEE
	128-bit round to integer instructions.
	(ceil<mode>2): Likewise.
	(btrunc<mode>2): Likewise.
	(round<mode>2): Likewise.

[gcc/c]
2017-10-27  Michael Meissner  <meissner@linux.vnet.ibm.com>

	* c-decl.c (header_for_builtin_fn): Add integer rounding _Float<N>
	and _Float<N>X built-in functions.

[gcc/testsuite]
2017-10-27  Michael Meissner  <meissner@linux.vnet.ibm.com>

	* gcc.target/powerpc/float128-hw2.c: Add tests for ceilf128,
	floorf128, truncf128, and roundf128.

-- 
Michael Meissner, IBM
IBM, M/S 2506R, 550 King Street, Littleton, MA 01460-6245, USA
email: meissner@linux.vnet.ibm.com, phone: +1 (978) 899-4797

[-- Attachment #2: ieee128-patch49b --]
[-- Type: text/plain, Size: 17015 bytes --]

Index: gcc/builtins.def
===================================================================
--- gcc/builtins.def	(revision 254172)
+++ gcc/builtins.def	(working copy)
@@ -335,6 +335,9 @@ DEF_C99_BUILTIN        (BUILT_IN_CBRTL, 
 DEF_LIB_BUILTIN        (BUILT_IN_CEIL, "ceil", BT_FN_DOUBLE_DOUBLE, ATTR_CONST_NOTHROW_LEAF_LIST)
 DEF_C99_C90RES_BUILTIN (BUILT_IN_CEILF, "ceilf", BT_FN_FLOAT_FLOAT, ATTR_CONST_NOTHROW_LEAF_LIST)
 DEF_C99_C90RES_BUILTIN (BUILT_IN_CEILL, "ceill", BT_FN_LONGDOUBLE_LONGDOUBLE, ATTR_CONST_NOTHROW_LEAF_LIST)
+#define CEIL_TYPE(F) BT_FN_##F##_##F
+DEF_EXT_LIB_FLOATN_NX_BUILTINS (BUILT_IN_CEIL, "ceil", CEIL_TYPE, ATTR_CONST_NOTHROW_LEAF_LIST)
+#undef CEIL_TYPE
 DEF_C99_BUILTIN        (BUILT_IN_COPYSIGN, "copysign", BT_FN_DOUBLE_DOUBLE_DOUBLE, ATTR_CONST_NOTHROW_LEAF_LIST)
 DEF_C99_BUILTIN        (BUILT_IN_COPYSIGNF, "copysignf", BT_FN_FLOAT_FLOAT_FLOAT, ATTR_CONST_NOTHROW_LEAF_LIST)
 DEF_C99_BUILTIN        (BUILT_IN_COPYSIGNL, "copysignl", BT_FN_LONGDOUBLE_LONGDOUBLE_LONGDOUBLE, ATTR_CONST_NOTHROW_LEAF_LIST)
@@ -394,6 +397,9 @@ DEF_C99_BUILTIN        (BUILT_IN_FEUPDAT
 DEF_LIB_BUILTIN        (BUILT_IN_FLOOR, "floor", BT_FN_DOUBLE_DOUBLE, ATTR_CONST_NOTHROW_LEAF_LIST)
 DEF_C99_C90RES_BUILTIN (BUILT_IN_FLOORF, "floorf", BT_FN_FLOAT_FLOAT, ATTR_CONST_NOTHROW_LEAF_LIST)
 DEF_C99_C90RES_BUILTIN (BUILT_IN_FLOORL, "floorl", BT_FN_LONGDOUBLE_LONGDOUBLE, ATTR_CONST_NOTHROW_LEAF_LIST)
+#define FLOOR_TYPE(F) BT_FN_##F##_##F
+DEF_EXT_LIB_FLOATN_NX_BUILTINS (BUILT_IN_FLOOR, "floor", FLOOR_TYPE, ATTR_CONST_NOTHROW_LEAF_LIST)
+#undef FLOOR_TYPE
 DEF_C99_BUILTIN        (BUILT_IN_FMA, "fma", BT_FN_DOUBLE_DOUBLE_DOUBLE_DOUBLE, ATTR_MATHFN_FPROUNDING)
 DEF_C99_BUILTIN        (BUILT_IN_FMAF, "fmaf", BT_FN_FLOAT_FLOAT_FLOAT_FLOAT, ATTR_MATHFN_FPROUNDING)
 DEF_C99_BUILTIN        (BUILT_IN_FMAL, "fmal", BT_FN_LONGDOUBLE_LONGDOUBLE_LONGDOUBLE_LONGDOUBLE, ATTR_MATHFN_FPROUNDING)
@@ -531,6 +537,9 @@ DEF_GCC_FLOATN_NX_BUILTINS (BUILT_IN_NAN
 DEF_C99_BUILTIN        (BUILT_IN_NEARBYINT, "nearbyint", BT_FN_DOUBLE_DOUBLE, ATTR_CONST_NOTHROW_LEAF_LIST)
 DEF_C99_BUILTIN        (BUILT_IN_NEARBYINTF, "nearbyintf", BT_FN_FLOAT_FLOAT, ATTR_CONST_NOTHROW_LEAF_LIST)
 DEF_C99_BUILTIN        (BUILT_IN_NEARBYINTL, "nearbyintl", BT_FN_LONGDOUBLE_LONGDOUBLE, ATTR_CONST_NOTHROW_LEAF_LIST)
+#define NEARBYINT_TYPE(F) BT_FN_##F##_##F
+DEF_EXT_LIB_FLOATN_NX_BUILTINS (BUILT_IN_NEARBYINT, "nearbyint", NEARBYINT_TYPE, ATTR_CONST_NOTHROW_LEAF_LIST)
+#undef NEARBYINT_TYPE
 DEF_C99_BUILTIN        (BUILT_IN_NEXTAFTER, "nextafter", BT_FN_DOUBLE_DOUBLE_DOUBLE, ATTR_MATHFN_FPROUNDING_ERRNO)
 DEF_C99_BUILTIN        (BUILT_IN_NEXTAFTERF, "nextafterf", BT_FN_FLOAT_FLOAT_FLOAT, ATTR_MATHFN_FPROUNDING_ERRNO)
 DEF_C99_BUILTIN        (BUILT_IN_NEXTAFTERL, "nextafterl", BT_FN_LONGDOUBLE_LONGDOUBLE_LONGDOUBLE, ATTR_MATHFN_FPROUNDING_ERRNO)
@@ -555,9 +564,15 @@ DEF_C99_BUILTIN        (BUILT_IN_REMQUOL
 DEF_C99_BUILTIN        (BUILT_IN_RINT, "rint", BT_FN_DOUBLE_DOUBLE, ATTR_MATHFN_FPROUNDING)
 DEF_C99_BUILTIN        (BUILT_IN_RINTF, "rintf", BT_FN_FLOAT_FLOAT, ATTR_MATHFN_FPROUNDING)
 DEF_C99_BUILTIN        (BUILT_IN_RINTL, "rintl", BT_FN_LONGDOUBLE_LONGDOUBLE, ATTR_MATHFN_FPROUNDING)
+#define RINT_TYPE(F) BT_FN_##F##_##F
+DEF_EXT_LIB_FLOATN_NX_BUILTINS (BUILT_IN_RINT, "rint", RINT_TYPE, ATTR_CONST_NOTHROW_LEAF_LIST)
+#undef RINT_TYPE
 DEF_C99_BUILTIN        (BUILT_IN_ROUND, "round", BT_FN_DOUBLE_DOUBLE, ATTR_CONST_NOTHROW_LEAF_LIST)
 DEF_C99_BUILTIN        (BUILT_IN_ROUNDF, "roundf", BT_FN_FLOAT_FLOAT, ATTR_CONST_NOTHROW_LEAF_LIST)
 DEF_C99_BUILTIN        (BUILT_IN_ROUNDL, "roundl", BT_FN_LONGDOUBLE_LONGDOUBLE, ATTR_CONST_NOTHROW_LEAF_LIST)
+#define ROUND_TYPE(F) BT_FN_##F##_##F
+DEF_EXT_LIB_FLOATN_NX_BUILTINS (BUILT_IN_ROUND, "round", ROUND_TYPE, ATTR_CONST_NOTHROW_LEAF_LIST)
+#undef ROUND_TYPE
 DEF_EXT_LIB_BUILTIN    (BUILT_IN_SCALB, "scalb", BT_FN_DOUBLE_DOUBLE_DOUBLE, ATTR_MATHFN_FPROUNDING_ERRNO)
 DEF_EXT_LIB_BUILTIN    (BUILT_IN_SCALBF, "scalbf", BT_FN_FLOAT_FLOAT_FLOAT, ATTR_MATHFN_FPROUNDING_ERRNO)
 DEF_EXT_LIB_BUILTIN    (BUILT_IN_SCALBL, "scalbl", BT_FN_LONGDOUBLE_LONGDOUBLE_LONGDOUBLE, ATTR_MATHFN_FPROUNDING_ERRNO)
@@ -603,6 +618,9 @@ DEF_C99_BUILTIN        (BUILT_IN_TGAMMAL
 DEF_C99_BUILTIN        (BUILT_IN_TRUNC, "trunc", BT_FN_DOUBLE_DOUBLE, ATTR_CONST_NOTHROW_LEAF_LIST)
 DEF_C99_BUILTIN        (BUILT_IN_TRUNCF, "truncf", BT_FN_FLOAT_FLOAT, ATTR_CONST_NOTHROW_LEAF_LIST)
 DEF_C99_BUILTIN        (BUILT_IN_TRUNCL, "truncl", BT_FN_LONGDOUBLE_LONGDOUBLE, ATTR_CONST_NOTHROW_LEAF_LIST)
+#define TRUNC_TYPE(F) BT_FN_##F##_##F
+DEF_EXT_LIB_FLOATN_NX_BUILTINS (BUILT_IN_TRUNC, "trunc", TRUNC_TYPE, ATTR_CONST_NOTHROW_LEAF_LIST)
+#undef TRUNC_TYPE
 DEF_EXT_LIB_BUILTIN    (BUILT_IN_Y0, "y0", BT_FN_DOUBLE_DOUBLE, ATTR_MATHFN_FPROUNDING_ERRNO)
 DEF_EXT_LIB_BUILTIN    (BUILT_IN_Y0F, "y0f", BT_FN_FLOAT_FLOAT, ATTR_MATHFN_FPROUNDING_ERRNO)
 DEF_EXT_LIB_BUILTIN    (BUILT_IN_Y0L, "y0l", BT_FN_LONGDOUBLE_LONGDOUBLE, ATTR_MATHFN_FPROUNDING_ERRNO)
Index: gcc/builtins.c
===================================================================
--- gcc/builtins.c	(revision 254172)
+++ gcc/builtins.c	(working copy)
@@ -1872,7 +1872,7 @@ mathfn_built_in_2 (tree type, combined_f
     CASE_MATHFN (ATAN2)
     CASE_MATHFN (ATANH)
     CASE_MATHFN (CBRT)
-    CASE_MATHFN (CEIL)
+    CASE_MATHFN_FLOATN (CEIL)
     CASE_MATHFN (CEXPI)
     CASE_MATHFN_FLOATN (COPYSIGN)
     CASE_MATHFN (COS)
@@ -1886,7 +1886,7 @@ mathfn_built_in_2 (tree type, combined_f
     CASE_MATHFN (EXPM1)
     CASE_MATHFN (FABS)
     CASE_MATHFN (FDIM)
-    CASE_MATHFN (FLOOR)
+    CASE_MATHFN_FLOATN (FLOOR)
     CASE_MATHFN_FLOATN (FMA)
     CASE_MATHFN_FLOATN (FMAX)
     CASE_MATHFN_FLOATN (FMIN)
@@ -1925,7 +1925,7 @@ mathfn_built_in_2 (tree type, combined_f
     CASE_MATHFN (MODF)
     CASE_MATHFN (NAN)
     CASE_MATHFN (NANS)
-    CASE_MATHFN (NEARBYINT)
+    CASE_MATHFN_FLOATN (NEARBYINT)
     CASE_MATHFN (NEXTAFTER)
     CASE_MATHFN (NEXTTOWARD)
     CASE_MATHFN (POW)
@@ -1933,8 +1933,8 @@ mathfn_built_in_2 (tree type, combined_f
     CASE_MATHFN (POW10)
     CASE_MATHFN (REMAINDER)
     CASE_MATHFN (REMQUO)
-    CASE_MATHFN (RINT)
-    CASE_MATHFN (ROUND)
+    CASE_MATHFN_FLOATN (RINT)
+    CASE_MATHFN_FLOATN (ROUND)
     CASE_MATHFN (SCALB)
     CASE_MATHFN (SCALBLN)
     CASE_MATHFN (SCALBN)
@@ -1947,7 +1947,7 @@ mathfn_built_in_2 (tree type, combined_f
     CASE_MATHFN (TAN)
     CASE_MATHFN (TANH)
     CASE_MATHFN (TGAMMA)
-    CASE_MATHFN (TRUNC)
+    CASE_MATHFN_FLOATN (TRUNC)
     CASE_MATHFN (Y0)
     CASE_MATHFN (Y1)
     CASE_MATHFN (YN)
Index: gcc/internal-fn.def
===================================================================
--- gcc/internal-fn.def	(revision 254172)
+++ gcc/internal-fn.def	(working copy)
@@ -118,12 +118,12 @@ DEF_INTERNAL_FLT_FLOATN_FN (SQRT, ECF_CO
 DEF_INTERNAL_FLT_FN (TAN, ECF_CONST, tan, unary)
 
 /* FP rounding.  */
-DEF_INTERNAL_FLT_FN (CEIL, ECF_CONST, ceil, unary)
-DEF_INTERNAL_FLT_FN (FLOOR, ECF_CONST, floor, unary)
-DEF_INTERNAL_FLT_FN (NEARBYINT, ECF_CONST, nearbyint, unary)
-DEF_INTERNAL_FLT_FN (RINT, ECF_CONST, rint, unary)
-DEF_INTERNAL_FLT_FN (ROUND, ECF_CONST, round, unary)
-DEF_INTERNAL_FLT_FN (TRUNC, ECF_CONST, btrunc, unary)
+DEF_INTERNAL_FLT_FLOATN_FN (CEIL, ECF_CONST, ceil, unary)
+DEF_INTERNAL_FLT_FLOATN_FN (FLOOR, ECF_CONST, floor, unary)
+DEF_INTERNAL_FLT_FLOATN_FN (NEARBYINT, ECF_CONST, nearbyint, unary)
+DEF_INTERNAL_FLT_FLOATN_FN (RINT, ECF_CONST, rint, unary)
+DEF_INTERNAL_FLT_FLOATN_FN (ROUND, ECF_CONST, round, unary)
+DEF_INTERNAL_FLT_FLOATN_FN (TRUNC, ECF_CONST, btrunc, unary)
 
 /* Binary math functions.  */
 DEF_INTERNAL_FLT_FN (ATAN2, ECF_CONST, atan2, binary)
Index: gcc/convert.c
===================================================================
--- gcc/convert.c	(revision 254172)
+++ gcc/convert.c	(working copy)
@@ -554,6 +554,7 @@ convert_to_integer_1 (tree type, tree ex
       switch (fcode)
         {
 	CASE_FLT_FN (BUILT_IN_CEIL):
+	CASE_FLT_FN_FLOATN_NX (BUILT_IN_CEIL):
 	  /* Only convert in ISO C99 mode.  */
 	  if (!targetm.libc_has_function (function_c99_misc))
 	    break;
@@ -570,6 +571,7 @@ convert_to_integer_1 (tree type, tree ex
 	  break;
 
 	CASE_FLT_FN (BUILT_IN_FLOOR):
+	CASE_FLT_FN_FLOATN_NX (BUILT_IN_FLOOR):
 	  /* Only convert in ISO C99 mode.  */
 	  if (!targetm.libc_has_function (function_c99_misc))
 	    break;
@@ -586,6 +588,7 @@ convert_to_integer_1 (tree type, tree ex
 	  break;
 
 	CASE_FLT_FN (BUILT_IN_ROUND):
+	CASE_FLT_FN_FLOATN_NX (BUILT_IN_ROUND):
 	  /* Only convert in ISO C99 mode and with -fno-math-errno.  */
 	  if (!targetm.libc_has_function (function_c99_misc) || flag_errno_math)
 	    break;
@@ -602,11 +605,13 @@ convert_to_integer_1 (tree type, tree ex
 	  break;
 
 	CASE_FLT_FN (BUILT_IN_NEARBYINT):
+	CASE_FLT_FN_FLOATN_NX (BUILT_IN_NEARBYINT):
 	  /* Only convert nearbyint* if we can ignore math exceptions.  */
 	  if (flag_trapping_math)
 	    break;
 	  gcc_fallthrough ();
 	CASE_FLT_FN (BUILT_IN_RINT):
+	CASE_FLT_FN_FLOATN_NX (BUILT_IN_RINT):
 	  /* Only convert in ISO C99 mode and with -fno-math-errno.  */
 	  if (!targetm.libc_has_function (function_c99_misc) || flag_errno_math)
 	    break;
@@ -623,6 +628,7 @@ convert_to_integer_1 (tree type, tree ex
 	  break;
 
 	CASE_FLT_FN (BUILT_IN_TRUNC):
+	CASE_FLT_FN_FLOATN_NX (BUILT_IN_TRUNC):
 	  return convert_to_integer_1 (type, CALL_EXPR_ARG (s_expr, 0), dofold);
 
 	default:
Index: gcc/fold-const.c
===================================================================
--- gcc/fold-const.c	(revision 254172)
+++ gcc/fold-const.c	(working copy)
@@ -12784,9 +12784,11 @@ tree_call_nonnegative_warnv_p (tree type
     CASE_CFN_ATANH:
     CASE_CFN_CBRT:
     CASE_CFN_CEIL:
+    CASE_CFN_CEIL_FN:
     CASE_CFN_ERF:
     CASE_CFN_EXPM1:
     CASE_CFN_FLOOR:
+    CASE_CFN_FLOOR_FN:
     CASE_CFN_FMOD:
     CASE_CFN_FREXP:
     CASE_CFN_ICEIL:
@@ -12804,8 +12806,11 @@ tree_call_nonnegative_warnv_p (tree type
     CASE_CFN_LROUND:
     CASE_CFN_MODF:
     CASE_CFN_NEARBYINT:
+    CASE_CFN_NEARBYINT_FN:
     CASE_CFN_RINT:
+    CASE_CFN_RINT_FN:
     CASE_CFN_ROUND:
+    CASE_CFN_ROUND_FN:
     CASE_CFN_SCALB:
     CASE_CFN_SCALBLN:
     CASE_CFN_SCALBN:
@@ -12814,6 +12819,7 @@ tree_call_nonnegative_warnv_p (tree type
     CASE_CFN_SINH:
     CASE_CFN_TANH:
     CASE_CFN_TRUNC:
+    CASE_CFN_TRUNC_FN:
       /* True if the 1st argument is nonnegative.  */
       return RECURSE (arg0);
 
@@ -13319,11 +13325,17 @@ integer_valued_real_call_p (combined_fn 
   switch (fn)
     {
     CASE_CFN_CEIL:
+    CASE_CFN_CEIL_FN:
     CASE_CFN_FLOOR:
+    CASE_CFN_FLOOR_FN:
     CASE_CFN_NEARBYINT:
+    CASE_CFN_NEARBYINT_FN:
     CASE_CFN_RINT:
+    CASE_CFN_RINT_FN:
     CASE_CFN_ROUND:
+    CASE_CFN_ROUND_FN:
     CASE_CFN_TRUNC:
+    CASE_CFN_TRUNC_FN:
       return true;
 
     CASE_CFN_FMIN:
Index: gcc/fold-const-call.c
===================================================================
--- gcc/fold-const-call.c	(revision 254172)
+++ gcc/fold-const-call.c	(working copy)
@@ -699,6 +699,7 @@ fold_const_call_ss (real_value *result, 
 	      && do_mpfr_arg1 (result, mpfr_y1, arg, format));
 
     CASE_CFN_FLOOR:
+    CASE_CFN_FLOOR_FN:
       if (!REAL_VALUE_ISNAN (*arg) || !flag_errno_math)
 	{
 	  real_floor (result, format, arg);
@@ -707,6 +708,7 @@ fold_const_call_ss (real_value *result, 
       return false;
 
     CASE_CFN_CEIL:
+    CASE_CFN_CEIL_FN:
       if (!REAL_VALUE_ISNAN (*arg) || !flag_errno_math)
 	{
 	  real_ceil (result, format, arg);
@@ -715,10 +717,12 @@ fold_const_call_ss (real_value *result, 
       return false;
 
     CASE_CFN_TRUNC:
+    CASE_CFN_TRUNC_FN:
       real_trunc (result, format, arg);
       return true;
 
     CASE_CFN_ROUND:
+    CASE_CFN_ROUND_FN:
       if (!REAL_VALUE_ISNAN (*arg) || !flag_errno_math)
 	{
 	  real_round (result, format, arg);
Index: gcc/config/rs6000/rs6000.md
===================================================================
--- gcc/config/rs6000/rs6000.md	(revision 254172)
+++ gcc/config/rs6000/rs6000.md	(working copy)
@@ -14604,6 +14604,47 @@ (define_insn_and_split "floatuns<QHI:mod
    (set_attr "type" "vecfloat")
    (set_attr "size" "128")])
 
+;; IEEE 128-bit round to integer built-in functions
+(define_insn "floor<mode>2"
+  [(set (match_operand:IEEE128 0 "altivec_register_operand" "=v")
+	(unspec:IEEE128
+	 [(match_operand:IEEE128 1 "altivec_register_operand" "v")]
+	 UNSPEC_FRIM))]
+  "TARGET_FLOAT128_HW && FLOAT128_IEEE_P (<MODE>mode)"
+  "xsrqpi 1,%0,%1,3"
+  [(set_attr "type" "vecfloat")
+   (set_attr "size" "128")])
+
+(define_insn "ceil<mode>2"
+  [(set (match_operand:IEEE128 0 "altivec_register_operand" "=v")
+	(unspec:IEEE128
+	 [(match_operand:IEEE128 1 "altivec_register_operand" "v")]
+	 UNSPEC_FRIP))]
+  "TARGET_FLOAT128_HW && FLOAT128_IEEE_P (<MODE>mode)"
+  "xsrqpi 1,%0,%1,2"
+  [(set_attr "type" "vecfloat")
+   (set_attr "size" "128")])
+
+(define_insn "btrunc<mode>2"
+  [(set (match_operand:IEEE128 0 "altivec_register_operand" "=v")
+	(unspec:IEEE128
+	 [(match_operand:IEEE128 1 "altivec_register_operand" "v")]
+	 UNSPEC_FRIZ))]
+  "TARGET_FLOAT128_HW && FLOAT128_IEEE_P (<MODE>mode)"
+  "xsrqpi 1,%0,%1,0"
+  [(set_attr "type" "vecfloat")
+   (set_attr "size" "128")])
+
+(define_insn "round<mode>2"
+  [(set (match_operand:IEEE128 0 "altivec_register_operand" "=v")
+	(unspec:IEEE128
+	 [(match_operand:IEEE128 1 "altivec_register_operand" "v")]
+	 UNSPEC_FRIN))]
+  "TARGET_FLOAT128_HW && FLOAT128_IEEE_P (<MODE>mode)"
+  "xsrqpi 0,%0,%1,3"
+  [(set_attr "type" "vecfloat")
+   (set_attr "size" "128")])
+
 ;; IEEE 128-bit instructions with round to odd semantics
 (define_insn "add<mode>3_odd"
   [(set (match_operand:IEEE128 0 "altivec_register_operand" "=v")
Index: gcc/c/c-decl.c
===================================================================
--- gcc/c/c-decl.c	(revision 254172)
+++ gcc/c/c-decl.c	(working copy)
@@ -3162,6 +3162,7 @@ header_for_builtin_fn (enum built_in_fun
     CASE_FLT_FN (BUILT_IN_ATAN2):
     CASE_FLT_FN (BUILT_IN_CBRT):
     CASE_FLT_FN (BUILT_IN_CEIL):
+    CASE_FLT_FN_FLOATN_NX (BUILT_IN_CEIL):
     CASE_FLT_FN (BUILT_IN_COPYSIGN):
     CASE_FLT_FN_FLOATN_NX (BUILT_IN_COPYSIGN):
     CASE_FLT_FN (BUILT_IN_COS):
@@ -3175,6 +3176,7 @@ header_for_builtin_fn (enum built_in_fun
     CASE_FLT_FN_FLOATN_NX (BUILT_IN_FABS):
     CASE_FLT_FN (BUILT_IN_FDIM):
     CASE_FLT_FN (BUILT_IN_FLOOR):
+    CASE_FLT_FN_FLOATN_NX (BUILT_IN_FLOOR):
     CASE_FLT_FN (BUILT_IN_FMA):
     CASE_FLT_FN_FLOATN_NX (BUILT_IN_FMA):
     CASE_FLT_FN (BUILT_IN_FMAX):
@@ -3199,13 +3201,16 @@ header_for_builtin_fn (enum built_in_fun
     CASE_FLT_FN (BUILT_IN_MODF):
     CASE_FLT_FN (BUILT_IN_NAN):
     CASE_FLT_FN (BUILT_IN_NEARBYINT):
+    CASE_FLT_FN_FLOATN_NX (BUILT_IN_NEARBYINT):
     CASE_FLT_FN (BUILT_IN_NEXTAFTER):
     CASE_FLT_FN (BUILT_IN_NEXTTOWARD):
     CASE_FLT_FN (BUILT_IN_POW):
     CASE_FLT_FN (BUILT_IN_REMAINDER):
     CASE_FLT_FN (BUILT_IN_REMQUO):
     CASE_FLT_FN (BUILT_IN_RINT):
+    CASE_FLT_FN_FLOATN_NX (BUILT_IN_RINT):
     CASE_FLT_FN (BUILT_IN_ROUND):
+    CASE_FLT_FN_FLOATN_NX (BUILT_IN_ROUND):
     CASE_FLT_FN (BUILT_IN_SCALBLN):
     CASE_FLT_FN (BUILT_IN_SCALBN):
     CASE_FLT_FN (BUILT_IN_SIN):
@@ -3217,6 +3222,7 @@ header_for_builtin_fn (enum built_in_fun
     CASE_FLT_FN (BUILT_IN_TANH):
     CASE_FLT_FN (BUILT_IN_TGAMMA):
     CASE_FLT_FN (BUILT_IN_TRUNC):
+    CASE_FLT_FN_FLOATN_NX (BUILT_IN_TRUNC):
     case BUILT_IN_ISINF:
     case BUILT_IN_ISNAN:
       return "<math.h>";
Index: gcc/testsuite/gcc.target/powerpc/float128-hw2.c
===================================================================
--- gcc/testsuite/gcc.target/powerpc/float128-hw2.c	(revision 254172)
+++ gcc/testsuite/gcc.target/powerpc/float128-hw2.c	(working copy)
@@ -14,6 +14,10 @@
 extern _Float128 copysignf128 (_Float128, _Float128);
 extern _Float128 sqrtf128 (_Float128);
 extern _Float128 fmaf128 (_Float128, _Float128, _Float128);
+extern _Float128 ceilf128 (_Float128);
+extern _Float128 floorf128 (_Float128);
+extern _Float128 truncf128 (_Float128);
+extern _Float128 roundf128 (_Float128);
 
 _Float128
 do_copysign (_Float128 a, _Float128 b)
@@ -51,10 +55,35 @@ do_nfms (_Float128 a, _Float128 b, _Floa
   return -fmaf128 (a, b, -c);
 }
 
+_Float128
+do_ceil (_Float128 a)
+{
+  return ceilf128 (a);
+}
+
+_Float128
+do_floor (_Float128 a)
+{
+  return floorf128 (a);
+}
+
+_Float128
+do_trunc (_Float128 a)
+{
+  return truncf128 (a);
+}
+
+_Float128
+do_round (_Float128 a)
+{
+  return roundf128 (a);
+}
+
 /* { dg-final { scan-assembler     {\mxscpsgnqp\M} } } */
 /* { dg-final { scan-assembler     {\mxssqrtqp\M}  } } */
 /* { dg-final { scan-assembler     {\mxsmaddqp\M}  } } */
 /* { dg-final { scan-assembler     {\mxsmsubqp\M}  } } */
 /* { dg-final { scan-assembler     {\mxsnmaddqp\M} } } */
 /* { dg-final { scan-assembler     {\mxsnmsubqp\M} } } */
+/* { dg-final { scan-assembler     {\mxsrqpi\M}    } } */
 /* { dg-final { scan-assembler-not {\mbl\M}        } } */

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH], Add rounding built-ins to the _Float<N> and _Float<N>X built-in functions
  2017-10-28  1:11 [PATCH], Add rounding built-ins to the _Float<N> and _Float<N>X built-in functions Michael Meissner
@ 2017-11-01 18:32 ` Segher Boessenkool
  2017-11-01 20:02   ` Michael Meissner
  2017-11-09  7:28 ` Ping: " Michael Meissner
  2017-12-11 21:20 ` Ping ^2 " Michael Meissner
  2 siblings, 1 reply; 5+ messages in thread
From: Segher Boessenkool @ 2017-11-01 18:32 UTC (permalink / raw)
  To: Michael Meissner, GCC Patches, David Edelsohn, Bill Schmidt

Hi Mike,

On Fri, Oct 27, 2017 at 06:39:21PM -0400, Michael Meissner wrote:
> The power9 (running PowerPC ISA 3.0) has a round to integer instruction
> (XSRQPI) that does various flavors of round an IEEE 128-bit floating point to
> integeral values.  This patch adds the support to the machine independent
> portion of the compiler, and adds the necessary support for ceilf128,
> roundf128, truncf128, and roundf128 to the PowerPC backend when you use
> -mcpu=power9.
> 
> I have done bootstrap builds on both x86-64 and a little endian power8 system.
> Can I install these patches to the trunk?

Do you really need to duplicate everything?  Other than that the generic
parts look fine to me (but someone else will have to approve it).

The rs6000 parts are okay for trunk.

Thanks,


Segher


> 2017-10-27  Michael Meissner  <meissner@linux.vnet.ibm.com>
> 
> 	* builtins.def: (_Float<N> and _Float<N>X BUILT_IN_CEIL): Add
> 	_Float<N> and _Float<N>X variants for rounding built-in
> 	functions.
> 	(_Float<N> and _Float<N>X BUILT_IN_FLOOR): Likewise.
> 	(_Float<N> and _Float<N>X BUILT_IN_NEARBYINT): Likewise.
> 	(_Float<N> and _Float<N>X BUILT_IN_RINT): Likewise.
> 	(_Float<N> and _Float<N>X BUILT_IN_ROUND): Likewise.
> 	(_Float<N> and _Float<N>X BUILT_IN_TRUNC): Likewise.
> 	* builtins.c (mathfn_built_in_2): Likewise.
> 	* internal-fn.def (CEIL): Likewise.
> 	(FLOOR): Likewise.
> 	(NEARBYINT): Likewise.
> 	(RINT): Likewise.
> 	(ROUND): Likewise.
> 	(TRUNC): Likewise.
> 	* fold-const.c (tree_call_nonnegative_warnv_p): Likewise.
> 	(integer_valued_real_call_p): Likewise.
> 	* fold-const-call.c (fold_const_call_ss): Likewise.
> 	* config/rs6000/rs6000.md (floor<mode>2): Add support for IEEE
> 	128-bit round to integer instructions.
> 	(ceil<mode>2): Likewise.
> 	(btrunc<mode>2): Likewise.
> 	(round<mode>2): Likewise.
> 
> [gcc/c]
> 2017-10-27  Michael Meissner  <meissner@linux.vnet.ibm.com>
> 
> 	* c-decl.c (header_for_builtin_fn): Add integer rounding _Float<N>
> 	and _Float<N>X built-in functions.
> 
> [gcc/testsuite]
> 2017-10-27  Michael Meissner  <meissner@linux.vnet.ibm.com>
> 
> 	* gcc.target/powerpc/float128-hw2.c: Add tests for ceilf128,
> 	floorf128, truncf128, and roundf128.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH], Add rounding built-ins to the _Float<N> and _Float<N>X built-in functions
  2017-11-01 18:32 ` Segher Boessenkool
@ 2017-11-01 20:02   ` Michael Meissner
  0 siblings, 0 replies; 5+ messages in thread
From: Michael Meissner @ 2017-11-01 20:02 UTC (permalink / raw)
  To: Segher Boessenkool
  Cc: Michael Meissner, GCC Patches, David Edelsohn, Bill Schmidt

On Wed, Nov 01, 2017 at 01:31:57PM -0500, Segher Boessenkool wrote:
> Hi Mike,
> 
> On Fri, Oct 27, 2017 at 06:39:21PM -0400, Michael Meissner wrote:
> > The power9 (running PowerPC ISA 3.0) has a round to integer instruction
> > (XSRQPI) that does various flavors of round an IEEE 128-bit floating point to
> > integeral values.  This patch adds the support to the machine independent
> > portion of the compiler, and adds the necessary support for ceilf128,
> > roundf128, truncf128, and roundf128 to the PowerPC backend when you use
> > -mcpu=power9.
> > 
> > I have done bootstrap builds on both x86-64 and a little endian power8 system.
> > Can I install these patches to the trunk?
> 
> Do you really need to duplicate everything?  Other than that the generic
> parts look fine to me (but someone else will have to approve it).
> 
> The rs6000 parts are okay for trunk.

Yes, right now you have to do the duplication.

-- 
Michael Meissner, IBM
IBM, M/S 2506R, 550 King Street, Littleton, MA 01460-6245, USA
email: meissner@linux.vnet.ibm.com, phone: +1 (978) 899-4797

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Ping: [PATCH], Add rounding built-ins to the _Float<N> and _Float<N>X built-in functions
  2017-10-28  1:11 [PATCH], Add rounding built-ins to the _Float<N> and _Float<N>X built-in functions Michael Meissner
  2017-11-01 18:32 ` Segher Boessenkool
@ 2017-11-09  7:28 ` Michael Meissner
  2017-12-11 21:20 ` Ping ^2 " Michael Meissner
  2 siblings, 0 replies; 5+ messages in thread
From: Michael Meissner @ 2017-11-09  7:28 UTC (permalink / raw)
  To: Michael Meissner, GCC Patches, Segher Boessenkool,
	David Edelsohn, Bill Schmidt

I suspect this patch got lost among the FMA patches at the same time.  This
patch enables the rounding functions.  Segher has already approved the rs6000
bits.

https://gcc.gnu.org/ml/gcc-patches/2017-10/msg02124.html

On Fri, Oct 27, 2017 at 06:39:21PM -0400, Michael Meissner wrote:
> The power9 (running PowerPC ISA 3.0) has a round to integer instruction
> (XSRQPI) that does various flavors of round an IEEE 128-bit floating point to
> integeral values.  This patch adds the support to the machine independent
> portion of the compiler, and adds the necessary support for ceilf128,
> roundf128, truncf128, and roundf128 to the PowerPC backend when you use
> -mcpu=power9.
> 
> I have done bootstrap builds on both x86-64 and a little endian power8 system.
> Can I install these patches to the trunk?
> 
> [gcc]
> 2017-10-27  Michael Meissner  <meissner@linux.vnet.ibm.com>
> 
> 	* builtins.def: (_Float<N> and _Float<N>X BUILT_IN_CEIL): Add
> 	_Float<N> and _Float<N>X variants for rounding built-in
> 	functions.
> 	(_Float<N> and _Float<N>X BUILT_IN_FLOOR): Likewise.
> 	(_Float<N> and _Float<N>X BUILT_IN_NEARBYINT): Likewise.
> 	(_Float<N> and _Float<N>X BUILT_IN_RINT): Likewise.
> 	(_Float<N> and _Float<N>X BUILT_IN_ROUND): Likewise.
> 	(_Float<N> and _Float<N>X BUILT_IN_TRUNC): Likewise.
> 	* builtins.c (mathfn_built_in_2): Likewise.
> 	* internal-fn.def (CEIL): Likewise.
> 	(FLOOR): Likewise.
> 	(NEARBYINT): Likewise.
> 	(RINT): Likewise.
> 	(ROUND): Likewise.
> 	(TRUNC): Likewise.
> 	* fold-const.c (tree_call_nonnegative_warnv_p): Likewise.
> 	(integer_valued_real_call_p): Likewise.
> 	* fold-const-call.c (fold_const_call_ss): Likewise.
> 	* config/rs6000/rs6000.md (floor<mode>2): Add support for IEEE
> 	128-bit round to integer instructions.
> 	(ceil<mode>2): Likewise.
> 	(btrunc<mode>2): Likewise.
> 	(round<mode>2): Likewise.
> 
> [gcc/c]
> 2017-10-27  Michael Meissner  <meissner@linux.vnet.ibm.com>
> 
> 	* c-decl.c (header_for_builtin_fn): Add integer rounding _Float<N>
> 	and _Float<N>X built-in functions.
> 
> [gcc/testsuite]
> 2017-10-27  Michael Meissner  <meissner@linux.vnet.ibm.com>
> 
> 	* gcc.target/powerpc/float128-hw2.c: Add tests for ceilf128,
> 	floorf128, truncf128, and roundf128.

-- 
Michael Meissner, IBM
IBM, M/S 2506R, 550 King Street, Littleton, MA 01460-6245, USA
email: meissner@linux.vnet.ibm.com, phone: +1 (978) 899-4797

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Ping ^2 [PATCH], Add rounding built-ins to the _Float<N> and _Float<N>X built-in functions
  2017-10-28  1:11 [PATCH], Add rounding built-ins to the _Float<N> and _Float<N>X built-in functions Michael Meissner
  2017-11-01 18:32 ` Segher Boessenkool
  2017-11-09  7:28 ` Ping: " Michael Meissner
@ 2017-12-11 21:20 ` Michael Meissner
  2 siblings, 0 replies; 5+ messages in thread
From: Michael Meissner @ 2017-12-11 21:20 UTC (permalink / raw)
  To: Michael Meissner, GCC Patches, Segher Boessenkool,
	David Edelsohn, Bill Schmidt, Joseph Myers, Jakub Jelinek,
	Aldy Hernandez, Jason Merrill

On Fri, Oct 27, 2017 at 06:39:21PM -0400, Michael Meissner wrote:
> The power9 (running PowerPC ISA 3.0) has a round to integer instruction
> (XSRQPI) that does various flavors of round an IEEE 128-bit floating point to
> integeral values.  This patch adds the support to the machine independent
> portion of the compiler, and adds the necessary support for ceilf128,
> roundf128, truncf128, and roundf128 to the PowerPC backend when you use
> -mcpu=power9.
> 
> I have done bootstrap builds on both x86-64 and a little endian power8 system.
> Can I install these patches to the trunk?
> 
> [gcc]
> 2017-10-27  Michael Meissner  <meissner@linux.vnet.ibm.com>
> 
> 	* builtins.def: (_Float<N> and _Float<N>X BUILT_IN_CEIL): Add
> 	_Float<N> and _Float<N>X variants for rounding built-in
> 	functions.
> 	(_Float<N> and _Float<N>X BUILT_IN_FLOOR): Likewise.
> 	(_Float<N> and _Float<N>X BUILT_IN_NEARBYINT): Likewise.
> 	(_Float<N> and _Float<N>X BUILT_IN_RINT): Likewise.
> 	(_Float<N> and _Float<N>X BUILT_IN_ROUND): Likewise.
> 	(_Float<N> and _Float<N>X BUILT_IN_TRUNC): Likewise.
> 	* builtins.c (mathfn_built_in_2): Likewise.
> 	* internal-fn.def (CEIL): Likewise.
> 	(FLOOR): Likewise.
> 	(NEARBYINT): Likewise.
> 	(RINT): Likewise.
> 	(ROUND): Likewise.
> 	(TRUNC): Likewise.
> 	* fold-const.c (tree_call_nonnegative_warnv_p): Likewise.
> 	(integer_valued_real_call_p): Likewise.
> 	* fold-const-call.c (fold_const_call_ss): Likewise.
> 	* config/rs6000/rs6000.md (floor<mode>2): Add support for IEEE
> 	128-bit round to integer instructions.
> 	(ceil<mode>2): Likewise.
> 	(btrunc<mode>2): Likewise.
> 	(round<mode>2): Likewise.
> 
> [gcc/c]
> 2017-10-27  Michael Meissner  <meissner@linux.vnet.ibm.com>
> 
> 	* c-decl.c (header_for_builtin_fn): Add integer rounding _Float<N>
> 	and _Float<N>X built-in functions.
> 
> [gcc/testsuite]
> 2017-10-27  Michael Meissner  <meissner@linux.vnet.ibm.com>
> 
> 	* gcc.target/powerpc/float128-hw2.c: Add tests for ceilf128,
> 	floorf128, truncf128, and roundf128.


Originally posted as:
https://gcc.gnu.org/ml/gcc-patches/2017-11/msg01421.html

I posted this in October and ping'ed it the first time in November.  Could a
global or gimple maintainer look at the patch and either approve it or tell me
what I need to do to improve it?  In theory it should be similar to my
previoius patch to add square root, fma, and absolute value _Float<N> and
_Float<N>X support to the infrastructure.

-- 
Michael Meissner, IBM
IBM, M/S 2506R, 550 King Street, Littleton, MA 01460-6245, USA
email: meissner@linux.vnet.ibm.com, phone: +1 (978) 899-4797

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-12-11 21:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-28  1:11 [PATCH], Add rounding built-ins to the _Float<N> and _Float<N>X built-in functions Michael Meissner
2017-11-01 18:32 ` Segher Boessenkool
2017-11-01 20:02   ` Michael Meissner
2017-11-09  7:28 ` Ping: " Michael Meissner
2017-12-11 21:20 ` Ping ^2 " Michael Meissner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).