7c0489
From 6c5e5f498cd004b3f42d97997898018df8f798a4 Mon Sep 17 00:00:00 2001
7c0489
From: Stefan Liebler <stli@linux.ibm.com>
7c0489
Date: Wed, 11 Dec 2019 15:09:21 +0100
7c0489
Subject: [PATCH 10/28] Use GCC builtins for ceil functions if desired.
7c0489
7c0489
This patch is using the corresponding GCC builtin for ceilf, ceil,
7c0489
ceill and ceilf128 if the USE_FUNCTION_BUILTIN macros are defined to one
7c0489
in math-use-builtins.h.
7c0489
7c0489
This is the case for s390 if build with at least --march=z196 --mzarch.
7c0489
Otherwise the generic implementation is used.  The code of the generic
7c0489
implementation is not changed.
7c0489
7c0489
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
7c0489
(cherry picked from commit 62560ee84095274bab1050817f42e782df226a17)
7c0489
---
7c0489
 sysdeps/generic/math-use-builtins.h         |  5 +++++
7c0489
 sysdeps/ieee754/dbl-64/s_ceil.c             |  6 ++++++
7c0489
 sysdeps/ieee754/float128/float128_private.h |  3 +++
7c0489
 sysdeps/ieee754/flt-32/s_ceilf.c            |  7 ++++++-
7c0489
 sysdeps/ieee754/ldbl-128/s_ceill.c          |  6 ++++++
7c0489
 sysdeps/s390/fpu/math-use-builtins.h        | 11 +++++++++++
7c0489
 6 files changed, 37 insertions(+), 1 deletion(-)
7c0489
7c0489
diff --git a/sysdeps/generic/math-use-builtins.h b/sysdeps/generic/math-use-builtins.h
7c0489
index e1c5df62e4..076ec661b0 100644
7c0489
--- a/sysdeps/generic/math-use-builtins.h
7c0489
+++ b/sysdeps/generic/math-use-builtins.h
7c0489
@@ -36,4 +36,9 @@
7c0489
 #define USE_FLOORL_BUILTIN 0
7c0489
 #define USE_FLOORF128_BUILTIN 0
7c0489
 
7c0489
+#define USE_CEIL_BUILTIN 0
7c0489
+#define USE_CEILF_BUILTIN 0
7c0489
+#define USE_CEILL_BUILTIN 0
7c0489
+#define USE_CEILF128_BUILTIN 0
7c0489
+
7c0489
 #endif /* math-use-builtins.h */
7c0489
diff --git a/sysdeps/ieee754/dbl-64/s_ceil.c b/sysdeps/ieee754/dbl-64/s_ceil.c
7c0489
index 3becdfc515..ee4a3abc19 100644
7c0489
--- a/sysdeps/ieee754/dbl-64/s_ceil.c
7c0489
+++ b/sysdeps/ieee754/dbl-64/s_ceil.c
7c0489
@@ -20,10 +20,15 @@
7c0489
 #include <math.h>
7c0489
 #include <math_private.h>
7c0489
 #include <libm-alias-double.h>
7c0489
+#include <math-use-builtins.h>
7c0489
 
7c0489
 double
7c0489
 __ceil (double x)
7c0489
 {
7c0489
+#if USE_CEIL_BUILTIN
7c0489
+  return __builtin_ceil (x);
7c0489
+#else
7c0489
+  /* Use generic implementation.  */
7c0489
   int64_t i0, i;
7c0489
   int32_t j0;
7c0489
   EXTRACT_WORDS64 (i0, x);
7c0489
@@ -57,6 +62,7 @@ __ceil (double x)
7c0489
     }
7c0489
   INSERT_WORDS64 (x, i0);
7c0489
   return x;
7c0489
+#endif /* ! USE_CEIL_BUILTIN  */
7c0489
 }
7c0489
 #ifndef __ceil
7c0489
 libm_alias_double (__ceil, ceil)
7c0489
diff --git a/sysdeps/ieee754/float128/float128_private.h b/sysdeps/ieee754/float128/float128_private.h
7c0489
index 667030ab06..19352ca26c 100644
7c0489
--- a/sysdeps/ieee754/float128/float128_private.h
7c0489
+++ b/sysdeps/ieee754/float128/float128_private.h
7c0489
@@ -145,6 +145,8 @@
7c0489
 #define USE_RINTL_BUILTIN USE_RINTF128_BUILTIN
7c0489
 #undef USE_FLOORL_BUILTIN
7c0489
 #define USE_FLOORL_BUILTIN USE_FLOORF128_BUILTIN
7c0489
+#undef USE_CEILL_BUILTIN
7c0489
+#define USE_CEILL_BUILTIN USE_CEILF128_BUILTIN
7c0489
 
7c0489
 /* IEEE function renames.  */
7c0489
 #define __ieee754_acoshl __ieee754_acoshf128
7c0489
@@ -349,6 +351,7 @@
7c0489
 #define __builtin_nearbyintl __builtin_nearbyintf128
7c0489
 #define __builtin_rintl __builtin_rintf128
7c0489
 #define __builtin_floorl __builtin_floorf128
7c0489
+#define __builtin_ceill __builtin_ceilf128
7c0489
 
7c0489
 /* Get the constant suffix from bits/floatn-compat.h.  */
7c0489
 #define L(x) __f128 (x)
7c0489
diff --git a/sysdeps/ieee754/flt-32/s_ceilf.c b/sysdeps/ieee754/flt-32/s_ceilf.c
7c0489
index f289ec2341..6cab7bdd62 100644
7c0489
--- a/sysdeps/ieee754/flt-32/s_ceilf.c
7c0489
+++ b/sysdeps/ieee754/flt-32/s_ceilf.c
7c0489
@@ -16,11 +16,15 @@
7c0489
 #include <math.h>
7c0489
 #include <math_private.h>
7c0489
 #include <libm-alias-float.h>
7c0489
-
7c0489
+#include <math-use-builtins.h>
7c0489
 
7c0489
 float
7c0489
 __ceilf(float x)
7c0489
 {
7c0489
+#if USE_CEILF_BUILTIN
7c0489
+  return __builtin_ceilf (x);
7c0489
+#else
7c0489
+  /* Use generic implementation.  */
7c0489
 	int32_t i0,j0;
7c0489
 	uint32_t i;
7c0489
 
7c0489
@@ -43,6 +47,7 @@ __ceilf(float x)
7c0489
 	}
7c0489
 	SET_FLOAT_WORD(x,i0);
7c0489
 	return x;
7c0489
+#endif /* ! USE_CEILF_BUILTIN  */
7c0489
 }
7c0489
 #ifndef __ceilf
7c0489
 libm_alias_float (__ceil, ceil)
7c0489
diff --git a/sysdeps/ieee754/ldbl-128/s_ceill.c b/sysdeps/ieee754/ldbl-128/s_ceill.c
7c0489
index e6aba5f2af..d212d86179 100644
7c0489
--- a/sysdeps/ieee754/ldbl-128/s_ceill.c
7c0489
+++ b/sysdeps/ieee754/ldbl-128/s_ceill.c
7c0489
@@ -27,9 +27,14 @@ static char rcsid[] = "$NetBSD: $";
7c0489
 #include <math.h>
7c0489
 #include <math_private.h>
7c0489
 #include <libm-alias-ldouble.h>
7c0489
+#include <math-use-builtins.h>
7c0489
 
7c0489
 _Float128 __ceill(_Float128 x)
7c0489
 {
7c0489
+#if USE_CEILL_BUILTIN
7c0489
+  return __builtin_ceill (x);
7c0489
+#else
7c0489
+  /* Use generic implementation.  */
7c0489
 	int64_t i0,i1,j0;
7c0489
 	uint64_t i,j;
7c0489
 	GET_LDOUBLE_WORDS64(i0,i1,x);
7c0489
@@ -63,5 +68,6 @@ _Float128 __ceill(_Float128 x)
7c0489
 	}
7c0489
 	SET_LDOUBLE_WORDS64(x,i0,i1);
7c0489
 	return x;
7c0489
+#endif /* ! USE_CEILL_BUILTIN  */
7c0489
 }
7c0489
 libm_alias_ldouble (__ceil, ceil)
7c0489
diff --git a/sysdeps/s390/fpu/math-use-builtins.h b/sysdeps/s390/fpu/math-use-builtins.h
7c0489
index c213c16c6f..5435cbb65f 100644
7c0489
--- a/sysdeps/s390/fpu/math-use-builtins.h
7c0489
+++ b/sysdeps/s390/fpu/math-use-builtins.h
7c0489
@@ -38,14 +38,20 @@
7c0489
 # define USE_FLOORF_BUILTIN 1
7c0489
 # define USE_FLOORL_BUILTIN 1
7c0489
 
7c0489
+# define USE_CEIL_BUILTIN 1
7c0489
+# define USE_CEILF_BUILTIN 1
7c0489
+# define USE_CEILL_BUILTIN 1
7c0489
+
7c0489
 # if __GNUC_PREREQ (8, 0)
7c0489
 #  define USE_NEARBYINTF128_BUILTIN 1
7c0489
 #  define USE_RINTF128_BUILTIN 1
7c0489
 #  define USE_FLOORF128_BUILTIN 1
7c0489
+#  define USE_CEILF128_BUILTIN 1
7c0489
 # else
7c0489
 #  define USE_NEARBYINTF128_BUILTIN 0
7c0489
 #  define USE_RINTF128_BUILTIN 0
7c0489
 #  define USE_FLOORF128_BUILTIN 0
7c0489
+#  define USE_CEILF128_BUILTIN 0
7c0489
 # endif
7c0489
 
7c0489
 #else
7c0489
@@ -66,6 +72,11 @@
7c0489
 # define USE_FLOORL_BUILTIN 0
7c0489
 # define USE_FLOORF128_BUILTIN 0
7c0489
 
7c0489
+# define USE_CEIL_BUILTIN 0
7c0489
+# define USE_CEILF_BUILTIN 0
7c0489
+# define USE_CEILL_BUILTIN 0
7c0489
+# define USE_CEILF128_BUILTIN 0
7c0489
+
7c0489
 #endif /* ! HAVE_S390_MIN_Z196_ZARCH_ASM_SUPPORT  */
7c0489
 
7c0489
 #endif /* math-use-builtins.h */
7c0489
-- 
7c0489
2.18.2
7c0489