a2cf7d
From 8353881ede286045dc5bdc00af6407560ca5d05b 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 09/28] Use GCC builtins for floor functions if desired.
a2cf7d
a2cf7d
This patch is using the corresponding GCC builtin for floorf, floor,
a2cf7d
floorl and floorf128 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 6c1b6a5e8cd91e0e1965509ad91e627e60eb00a3)
a2cf7d
---
a2cf7d
 sysdeps/generic/math-use-builtins.h         |  5 +++++
a2cf7d
 sysdeps/ieee754/dbl-64/s_floor.c            |  6 ++++++
a2cf7d
 sysdeps/ieee754/float128/float128_private.h |  3 +++
a2cf7d
 sysdeps/ieee754/flt-32/s_floorf.c           |  6 ++++++
a2cf7d
 sysdeps/ieee754/ldbl-128/s_floorl.c         |  6 ++++++
a2cf7d
 sysdeps/s390/fpu/math-use-builtins.h        | 11 +++++++++++
a2cf7d
 6 files changed, 37 insertions(+)
a2cf7d
a2cf7d
diff --git a/sysdeps/generic/math-use-builtins.h b/sysdeps/generic/math-use-builtins.h
a2cf7d
index 64b4a4bb5b..e1c5df62e4 100644
a2cf7d
--- a/sysdeps/generic/math-use-builtins.h
a2cf7d
+++ b/sysdeps/generic/math-use-builtins.h
a2cf7d
@@ -31,4 +31,9 @@
a2cf7d
 #define USE_RINTL_BUILTIN 0
a2cf7d
 #define USE_RINTF128_BUILTIN 0
a2cf7d
 
a2cf7d
+#define USE_FLOOR_BUILTIN 0
a2cf7d
+#define USE_FLOORF_BUILTIN 0
a2cf7d
+#define USE_FLOORL_BUILTIN 0
a2cf7d
+#define USE_FLOORF128_BUILTIN 0
a2cf7d
+
a2cf7d
 #endif /* math-use-builtins.h */
a2cf7d
diff --git a/sysdeps/ieee754/dbl-64/s_floor.c b/sysdeps/ieee754/dbl-64/s_floor.c
a2cf7d
index b551a1aafa..693938b708 100644
a2cf7d
--- a/sysdeps/ieee754/dbl-64/s_floor.c
a2cf7d
+++ b/sysdeps/ieee754/dbl-64/s_floor.c
a2cf7d
@@ -34,6 +34,7 @@
a2cf7d
 #include <math_private.h>
a2cf7d
 #include <stdint.h>
a2cf7d
 #include <libm-alias-double.h>
a2cf7d
+#include <math-use-builtins.h>
a2cf7d
 
a2cf7d
 /*
a2cf7d
  * floor(x)
a2cf7d
@@ -45,6 +46,10 @@
a2cf7d
 double
a2cf7d
 __floor (double x)
a2cf7d
 {
a2cf7d
+#if USE_FLOOR_BUILTIN
a2cf7d
+  return __builtin_floor (x);
a2cf7d
+#else
a2cf7d
+  /* Use generic implementation.  */
a2cf7d
   int64_t i0;
a2cf7d
   EXTRACT_WORDS64 (i0, x);
a2cf7d
   int32_t j0 = ((i0 >> 52) & 0x7ff) - 0x3ff;
a2cf7d
@@ -72,6 +77,7 @@ __floor (double x)
a2cf7d
   else if (j0 == 0x400)
a2cf7d
     return x + x;			/* inf or NaN */
a2cf7d
   return x;
a2cf7d
+#endif /* ! USE_FLOOR_BUILTIN  */
a2cf7d
 }
a2cf7d
 #ifndef __floor
a2cf7d
 libm_alias_double (__floor, floor)
a2cf7d
diff --git a/sysdeps/ieee754/float128/float128_private.h b/sysdeps/ieee754/float128/float128_private.h
a2cf7d
index b872aefbfd..667030ab06 100644
a2cf7d
--- a/sysdeps/ieee754/float128/float128_private.h
a2cf7d
+++ b/sysdeps/ieee754/float128/float128_private.h
a2cf7d
@@ -143,6 +143,8 @@
a2cf7d
 #define USE_NEARBYINTL_BUILTIN USE_NEARBYINTF128_BUILTIN
a2cf7d
 #undef USE_RINTL_BUILTIN
a2cf7d
 #define USE_RINTL_BUILTIN USE_RINTF128_BUILTIN
a2cf7d
+#undef USE_FLOORL_BUILTIN
a2cf7d
+#define USE_FLOORL_BUILTIN USE_FLOORF128_BUILTIN
a2cf7d
 
a2cf7d
 /* IEEE function renames.  */
a2cf7d
 #define __ieee754_acoshl __ieee754_acoshf128
a2cf7d
@@ -346,6 +348,7 @@
a2cf7d
 #define __builtin_signbitl __builtin_signbit
a2cf7d
 #define __builtin_nearbyintl __builtin_nearbyintf128
a2cf7d
 #define __builtin_rintl __builtin_rintf128
a2cf7d
+#define __builtin_floorl __builtin_floorf128
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_floorf.c b/sysdeps/ieee754/flt-32/s_floorf.c
a2cf7d
index 12aed343a0..6d37ab90a1 100644
a2cf7d
--- a/sysdeps/ieee754/flt-32/s_floorf.c
a2cf7d
+++ b/sysdeps/ieee754/flt-32/s_floorf.c
a2cf7d
@@ -23,10 +23,15 @@
a2cf7d
 #include <math.h>
a2cf7d
 #include <math_private.h>
a2cf7d
 #include <libm-alias-float.h>
a2cf7d
+#include <math-use-builtins.h>
a2cf7d
 
a2cf7d
 float
a2cf7d
 __floorf(float x)
a2cf7d
 {
a2cf7d
+#if USE_FLOORF_BUILTIN
a2cf7d
+  return __builtin_floorf (x);
a2cf7d
+#else
a2cf7d
+  /* Use generic implementation.  */
a2cf7d
 	int32_t i0,j0;
a2cf7d
 	uint32_t i;
a2cf7d
 	GET_FLOAT_WORD(i0,x);
a2cf7d
@@ -49,6 +54,7 @@ __floorf(float x)
a2cf7d
 	}
a2cf7d
 	SET_FLOAT_WORD(x,i0);
a2cf7d
 	return x;
a2cf7d
+#endif /* ! USE_FLOORF_BUILTIN  */
a2cf7d
 }
a2cf7d
 #ifndef __floorf
a2cf7d
 libm_alias_float (__floor, floor)
a2cf7d
diff --git a/sysdeps/ieee754/ldbl-128/s_floorl.c b/sysdeps/ieee754/ldbl-128/s_floorl.c
a2cf7d
index f9c5e014f9..6143fe6ec5 100644
a2cf7d
--- a/sysdeps/ieee754/ldbl-128/s_floorl.c
a2cf7d
+++ b/sysdeps/ieee754/ldbl-128/s_floorl.c
a2cf7d
@@ -27,9 +27,14 @@ static char rcsid[] = "$NetBSD: $";
a2cf7d
 #include <math.h>
a2cf7d
 #include <math_private.h>
a2cf7d
 #include <libm-alias-ldouble.h>
a2cf7d
+#include <math-use-builtins.h>
a2cf7d
 
a2cf7d
 _Float128 __floorl(_Float128 x)
a2cf7d
 {
a2cf7d
+#if USE_FLOORL_BUILTIN
a2cf7d
+  return __builtin_floorl (x);
a2cf7d
+#else
a2cf7d
+  /* Use generic implementation.  */
a2cf7d
 	int64_t i0,i1,j0;
a2cf7d
 	uint64_t i,j;
a2cf7d
 	GET_LDOUBLE_WORDS64(i0,i1,x);
a2cf7d
@@ -64,5 +69,6 @@ _Float128 __floorl(_Float128 x)
a2cf7d
 	}
a2cf7d
 	SET_LDOUBLE_WORDS64(x,i0,i1);
a2cf7d
 	return x;
a2cf7d
+#endif /* ! USE_FLOORL_BUILTIN  */
a2cf7d
 }
a2cf7d
 libm_alias_ldouble (__floor, floor)
a2cf7d
diff --git a/sysdeps/s390/fpu/math-use-builtins.h b/sysdeps/s390/fpu/math-use-builtins.h
a2cf7d
index 8b702a6a90..c213c16c6f 100644
a2cf7d
--- a/sysdeps/s390/fpu/math-use-builtins.h
a2cf7d
+++ b/sysdeps/s390/fpu/math-use-builtins.h
a2cf7d
@@ -34,12 +34,18 @@
a2cf7d
 # define USE_RINTF_BUILTIN 1
a2cf7d
 # define USE_RINTL_BUILTIN 1
a2cf7d
 
a2cf7d
+# define USE_FLOOR_BUILTIN 1
a2cf7d
+# define USE_FLOORF_BUILTIN 1
a2cf7d
+# define USE_FLOORL_BUILTIN 1
a2cf7d
+
a2cf7d
 # if __GNUC_PREREQ (8, 0)
a2cf7d
 #  define USE_NEARBYINTF128_BUILTIN 1
a2cf7d
 #  define USE_RINTF128_BUILTIN 1
a2cf7d
+#  define USE_FLOORF128_BUILTIN 1
a2cf7d
 # else
a2cf7d
 #  define USE_NEARBYINTF128_BUILTIN 0
a2cf7d
 #  define USE_RINTF128_BUILTIN 0
a2cf7d
+#  define USE_FLOORF128_BUILTIN 0
a2cf7d
 # endif
a2cf7d
 
a2cf7d
 #else
a2cf7d
@@ -55,6 +61,11 @@
a2cf7d
 # define USE_RINTL_BUILTIN 0
a2cf7d
 # define USE_RINTF128_BUILTIN 0
a2cf7d
 
a2cf7d
+# define USE_FLOOR_BUILTIN 0
a2cf7d
+# define USE_FLOORF_BUILTIN 0
a2cf7d
+# define USE_FLOORL_BUILTIN 0
a2cf7d
+# define USE_FLOORF128_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