a2cf7d
From d37e99de7ab1cd8c3d427f74bf8ceb5774795fe5 Mon Sep 17 00:00:00 2001
a2cf7d
From: Stefan Liebler <stli@linux.ibm.com>
a2cf7d
Date: Wed, 11 Dec 2019 15:09:20 +0100
a2cf7d
Subject: [PATCH 08/28] Use GCC builtins for rint functions if desired.
a2cf7d
a2cf7d
This patch is using the corresponding GCC builtin for rintf, rint,
a2cf7d
rintl and rintf128 if the USE_FUNCTION_BUILTIN macros are defined to one
a2cf7d
in math-use-builtins.h.
a2cf7d
a2cf7d
This is the case for s390 if build with at least --march=z196 --mzarch.
a2cf7d
Otherwise the generic implementation is used.  The code of the generic
a2cf7d
implementation is not changed.
a2cf7d
a2cf7d
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
a2cf7d
(cherry picked from commit a2a9b004297b777758420c952cb6eea5985d37fe)
a2cf7d
---
a2cf7d
 sysdeps/generic/math-use-builtins.h         |  5 +++++
a2cf7d
 sysdeps/ieee754/dbl-64/s_rint.c             | 17 +++++++++++------
a2cf7d
 sysdeps/ieee754/float128/float128_private.h |  3 +++
a2cf7d
 sysdeps/ieee754/flt-32/s_rintf.c            | 17 +++++++++++------
a2cf7d
 sysdeps/ieee754/ldbl-128/s_rintl.c          | 17 +++++++++++------
a2cf7d
 sysdeps/s390/fpu/math-use-builtins.h        | 11 +++++++++++
a2cf7d
 6 files changed, 52 insertions(+), 18 deletions(-)
a2cf7d
a2cf7d
diff --git a/sysdeps/generic/math-use-builtins.h b/sysdeps/generic/math-use-builtins.h
a2cf7d
index e12490ed41..64b4a4bb5b 100644
a2cf7d
--- a/sysdeps/generic/math-use-builtins.h
a2cf7d
+++ b/sysdeps/generic/math-use-builtins.h
a2cf7d
@@ -26,4 +26,9 @@
a2cf7d
 #define USE_NEARBYINTL_BUILTIN 0
a2cf7d
 #define USE_NEARBYINTF128_BUILTIN 0
a2cf7d
 
a2cf7d
+#define USE_RINT_BUILTIN 0
a2cf7d
+#define USE_RINTF_BUILTIN 0
a2cf7d
+#define USE_RINTL_BUILTIN 0
a2cf7d
+#define USE_RINTF128_BUILTIN 0
a2cf7d
+
a2cf7d
 #endif /* math-use-builtins.h */
a2cf7d
diff --git a/sysdeps/ieee754/dbl-64/s_rint.c b/sysdeps/ieee754/dbl-64/s_rint.c
a2cf7d
index 7f3dc87b96..5f4ac7c1e3 100644
a2cf7d
--- a/sysdeps/ieee754/dbl-64/s_rint.c
a2cf7d
+++ b/sysdeps/ieee754/dbl-64/s_rint.c
a2cf7d
@@ -22,16 +22,20 @@
a2cf7d
 #include <math.h>
a2cf7d
 #include <math_private.h>
a2cf7d
 #include <libm-alias-double.h>
a2cf7d
-
a2cf7d
-static const double
a2cf7d
-TWO52[2] = {
a2cf7d
-	    4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
a2cf7d
-	    -4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */
a2cf7d
-};
a2cf7d
+#include <math-use-builtins.h>
a2cf7d
 
a2cf7d
 double
a2cf7d
 __rint (double x)
a2cf7d
 {
a2cf7d
+#if USE_RINT_BUILTIN
a2cf7d
+  return __builtin_rint (x);
a2cf7d
+#else
a2cf7d
+  /* Use generic implementation.  */
a2cf7d
+  static const double
a2cf7d
+    TWO52[2] = {
a2cf7d
+		4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
a2cf7d
+		-4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */
a2cf7d
+  };
a2cf7d
   int64_t i0, sx;
a2cf7d
   int32_t j0;
a2cf7d
   EXTRACT_WORDS64 (i0, x);
a2cf7d
@@ -58,6 +62,7 @@ __rint (double x)
a2cf7d
     }
a2cf7d
   double w = TWO52[sx] + x;
a2cf7d
   return w - TWO52[sx];
a2cf7d
+#endif /* ! USE_RINT_BUILTIN  */
a2cf7d
 }
a2cf7d
 #ifndef __rint
a2cf7d
 libm_alias_double (__rint, rint)
a2cf7d
diff --git a/sysdeps/ieee754/float128/float128_private.h b/sysdeps/ieee754/float128/float128_private.h
a2cf7d
index 0bf6e8dee2..b872aefbfd 100644
a2cf7d
--- a/sysdeps/ieee754/float128/float128_private.h
a2cf7d
+++ b/sysdeps/ieee754/float128/float128_private.h
a2cf7d
@@ -141,6 +141,8 @@
a2cf7d
 #include <math-use-builtins.h>
a2cf7d
 #undef USE_NEARBYINTL_BUILTIN
a2cf7d
 #define USE_NEARBYINTL_BUILTIN USE_NEARBYINTF128_BUILTIN
a2cf7d
+#undef USE_RINTL_BUILTIN
a2cf7d
+#define USE_RINTL_BUILTIN USE_RINTF128_BUILTIN
a2cf7d
 
a2cf7d
 /* IEEE function renames.  */
a2cf7d
 #define __ieee754_acoshl __ieee754_acoshf128
a2cf7d
@@ -343,6 +345,7 @@
a2cf7d
 #define __builtin_copysignl __builtin_copysignf128
a2cf7d
 #define __builtin_signbitl __builtin_signbit
a2cf7d
 #define __builtin_nearbyintl __builtin_nearbyintf128
a2cf7d
+#define __builtin_rintl __builtin_rintf128
a2cf7d
 
a2cf7d
 /* Get the constant suffix from bits/floatn-compat.h.  */
a2cf7d
 #define L(x) __f128 (x)
a2cf7d
diff --git a/sysdeps/ieee754/flt-32/s_rintf.c b/sysdeps/ieee754/flt-32/s_rintf.c
a2cf7d
index db6f260a0b..a266b1999e 100644
a2cf7d
--- a/sysdeps/ieee754/flt-32/s_rintf.c
a2cf7d
+++ b/sysdeps/ieee754/flt-32/s_rintf.c
a2cf7d
@@ -16,16 +16,20 @@
a2cf7d
 #include <math.h>
a2cf7d
 #include <math_private.h>
a2cf7d
 #include <libm-alias-float.h>
a2cf7d
-
a2cf7d
-static const float
a2cf7d
-TWO23[2]={
a2cf7d
-  8.3886080000e+06, /* 0x4b000000 */
a2cf7d
- -8.3886080000e+06, /* 0xcb000000 */
a2cf7d
-};
a2cf7d
+#include <math-use-builtins.h>
a2cf7d
 
a2cf7d
 float
a2cf7d
 __rintf(float x)
a2cf7d
 {
a2cf7d
+#if USE_RINTF_BUILTIN
a2cf7d
+  return __builtin_rintf (x);
a2cf7d
+#else
a2cf7d
+  /* Use generic implementation.  */
a2cf7d
+  static const float
a2cf7d
+    TWO23[2] = {
a2cf7d
+		8.3886080000e+06, /* 0x4b000000 */
a2cf7d
+		-8.3886080000e+06, /* 0xcb000000 */
a2cf7d
+  };
a2cf7d
 	int32_t i0,j0,sx;
a2cf7d
 	float w,t;
a2cf7d
 	GET_FLOAT_WORD(i0,x);
a2cf7d
@@ -45,6 +49,7 @@ __rintf(float x)
a2cf7d
 	}
a2cf7d
 	w = TWO23[sx]+x;
a2cf7d
 	return w-TWO23[sx];
a2cf7d
+#endif /* ! USE_RINTF_BUILTIN  */
a2cf7d
 }
a2cf7d
 #ifndef __rintf
a2cf7d
 libm_alias_float (__rint, rint)
a2cf7d
diff --git a/sysdeps/ieee754/ldbl-128/s_rintl.c b/sysdeps/ieee754/ldbl-128/s_rintl.c
a2cf7d
index 9e6637a225..f060503066 100644
a2cf7d
--- a/sysdeps/ieee754/ldbl-128/s_rintl.c
a2cf7d
+++ b/sysdeps/ieee754/ldbl-128/s_rintl.c
a2cf7d
@@ -30,15 +30,19 @@ static char rcsid[] = "$NetBSD: $";
a2cf7d
 #include <math.h>
a2cf7d
 #include <math_private.h>
a2cf7d
 #include <libm-alias-ldouble.h>
a2cf7d
-
a2cf7d
-static const _Float128
a2cf7d
-TWO112[2]={
a2cf7d
-  5.19229685853482762853049632922009600E+33L, /* 0x406F000000000000, 0 */
a2cf7d
- -5.19229685853482762853049632922009600E+33L  /* 0xC06F000000000000, 0 */
a2cf7d
-};
a2cf7d
+#include <math-use-builtins.h>
a2cf7d
 
a2cf7d
 _Float128 __rintl(_Float128 x)
a2cf7d
 {
a2cf7d
+#if USE_RINTL_BUILTIN
a2cf7d
+  return __builtin_rintl (x);
a2cf7d
+#else
a2cf7d
+  /* Use generic implementation.  */
a2cf7d
+  static const _Float128
a2cf7d
+    TWO112[2] = {
a2cf7d
+		 5.19229685853482762853049632922009600E+33L, /* 0x406F000000000000, 0 */
a2cf7d
+		 -5.19229685853482762853049632922009600E+33L  /* 0xC06F000000000000, 0 */
a2cf7d
+  };
a2cf7d
 	int64_t i0,j0,sx;
a2cf7d
 	uint64_t i1 __attribute__ ((unused));
a2cf7d
 	_Float128 w,t;
a2cf7d
@@ -59,5 +63,6 @@ _Float128 __rintl(_Float128 x)
a2cf7d
 	}
a2cf7d
 	w = TWO112[sx]+x;
a2cf7d
 	return w-TWO112[sx];
a2cf7d
+#endif /* ! USE_RINTL_BUILTIN  */
a2cf7d
 }
a2cf7d
 libm_alias_ldouble (__rint, rint)
a2cf7d
diff --git a/sysdeps/s390/fpu/math-use-builtins.h b/sysdeps/s390/fpu/math-use-builtins.h
a2cf7d
index 7abbfb3b50..8b702a6a90 100644
a2cf7d
--- a/sysdeps/s390/fpu/math-use-builtins.h
a2cf7d
+++ b/sysdeps/s390/fpu/math-use-builtins.h
a2cf7d
@@ -30,10 +30,16 @@
a2cf7d
 # define USE_NEARBYINTF_BUILTIN 1
a2cf7d
 # define USE_NEARBYINTL_BUILTIN 1
a2cf7d
 
a2cf7d
+# define USE_RINT_BUILTIN 1
a2cf7d
+# define USE_RINTF_BUILTIN 1
a2cf7d
+# define USE_RINTL_BUILTIN 1
a2cf7d
+
a2cf7d
 # if __GNUC_PREREQ (8, 0)
a2cf7d
 #  define USE_NEARBYINTF128_BUILTIN 1
a2cf7d
+#  define USE_RINTF128_BUILTIN 1
a2cf7d
 # else
a2cf7d
 #  define USE_NEARBYINTF128_BUILTIN 0
a2cf7d
+#  define USE_RINTF128_BUILTIN 0
a2cf7d
 # endif
a2cf7d
 
a2cf7d
 #else
a2cf7d
@@ -44,6 +50,11 @@
a2cf7d
 # define USE_NEARBYINTL_BUILTIN 0
a2cf7d
 # define USE_NEARBYINTF128_BUILTIN 0
a2cf7d
 
a2cf7d
+# define USE_RINT_BUILTIN 0
a2cf7d
+# define USE_RINTF_BUILTIN 0
a2cf7d
+# define USE_RINTL_BUILTIN 0
a2cf7d
+# define USE_RINTF128_BUILTIN 0
a2cf7d
+
a2cf7d
 #endif /* ! HAVE_S390_MIN_Z196_ZARCH_ASM_SUPPORT  */
a2cf7d
 
a2cf7d
 #endif /* math-use-builtins.h */
a2cf7d
-- 
a2cf7d
2.18.2
a2cf7d