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