From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: libc-alpha@sourceware.org
Subject: Re: [PATCH 10/13] Use GCC builtins for ceil functions if desired.
Date: Thu, 5 Dec 2019 17:40:43 -0300 [thread overview]
Message-ID: <0fa6cb32-f6c0-b80b-d955-3c8907a0c672@linaro.org> (raw)
In-Reply-To: <1575297977-2589-11-git-send-email-stli@linux.ibm.com>
On 02/12/2019 11:46, Stefan Liebler wrote:
> This patch is using the corresponding GCC builtin for ceilf, ceil,
> ceill and ceilf128 if the USE_FUNCTION_BUILTIN macros are defined to one
> in math-use-builtins.h.
>
> This is the case for s390 if build with at least --march=z196 --mzarch.
> Otherwise the generic implementation is used. The code of the generic
> implementation is not changed except changes in code style.
LGTM with some changes below.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
> ---
> sysdeps/generic/math-use-builtins.h | 5 ++
> sysdeps/ieee754/dbl-64/s_ceil.c | 7 +-
> sysdeps/ieee754/float128/float128_private.h | 3 +
> sysdeps/ieee754/flt-32/s_ceilf.c | 60 ++++++++-----
> sysdeps/ieee754/ldbl-128/s_ceill.c | 97 ++++++++++++++-------
> sysdeps/s390/fpu/math-use-builtins.h | 6 ++
> 6 files changed, 123 insertions(+), 55 deletions(-)
>
> diff --git a/sysdeps/generic/math-use-builtins.h b/sysdeps/generic/math-use-builtins.h
> index e1c5df62e4..076ec661b0 100644
> --- a/sysdeps/generic/math-use-builtins.h
> +++ b/sysdeps/generic/math-use-builtins.h
> @@ -36,4 +36,9 @@
> #define USE_FLOORL_BUILTIN 0
> #define USE_FLOORF128_BUILTIN 0
>
> +#define USE_CEIL_BUILTIN 0
> +#define USE_CEILF_BUILTIN 0
> +#define USE_CEILL_BUILTIN 0
> +#define USE_CEILF128_BUILTIN 0
> +
> #endif /* math-use-builtins.h */
Ok.
> diff --git a/sysdeps/ieee754/dbl-64/s_ceil.c b/sysdeps/ieee754/dbl-64/s_ceil.c
> index 9d214eac81..c0ba9e8a73 100644
> --- a/sysdeps/ieee754/dbl-64/s_ceil.c
> +++ b/sysdeps/ieee754/dbl-64/s_ceil.c
> @@ -21,10 +21,14 @@
> #include <math.h>
> #include <math_private.h>
> #include <libm-alias-double.h>
> +#include <math-use-builtins.h>
>
> double
> -__ceil(double x)
> +__ceil (double x)
> {
> +#if USE_CEIL_BUILTIN
> + return __builtin_ceil (x);
> +#else
> int64_t i0, i;
> int32_t j0;
> EXTRACT_WORDS64 (i0, x);
> @@ -58,6 +62,7 @@ __ceil(double x)
> }
> INSERT_WORDS64 (x, i0);
> return x;
> +#endif /* USE_CEIL_BUILTIN */
> }
> #ifndef __ceil
> libm_alias_double (__ceil, ceil)
Ok.
> diff --git a/sysdeps/ieee754/float128/float128_private.h b/sysdeps/ieee754/float128/float128_private.h
> index 8c8a74a12c..01881b574a 100644
> --- a/sysdeps/ieee754/float128/float128_private.h
> +++ b/sysdeps/ieee754/float128/float128_private.h
> @@ -146,6 +146,8 @@
> #define USE_RINTL_BUILTIN USE_RINTF128_BUILTIN
> #undef USE_FLOORL_BUILTIN
> #define USE_FLOORL_BUILTIN USE_FLOORF128_BUILTIN
> +#undef USE_CEILL_BUILTIN
> +#define USE_CEILL_BUILTIN USE_CEILF128_BUILTIN
>
> /* IEEE function renames. */
> #define __ieee754_acoshl __ieee754_acoshf128
> @@ -352,6 +354,7 @@
> #define __builtin_nearbyintl __builtin_nearbyintf128
> #define __builtin_rintl __builtin_rintf128
> #define __builtin_floorl __builtin_floorf128
> +#define __builtin_ceill __builtin_ceilf128
>
> /* Get the constant suffix from bits/floatn-compat.h. */
> #define L(x) __f128 (x)
Ok.
> diff --git a/sysdeps/ieee754/flt-32/s_ceilf.c b/sysdeps/ieee754/flt-32/s_ceilf.c
> index 25cba0807c..4a7ce45800 100644
> --- a/sysdeps/ieee754/flt-32/s_ceilf.c
> +++ b/sysdeps/ieee754/flt-32/s_ceilf.c
> @@ -17,33 +17,49 @@
> #include <math.h>
> #include <math_private.h>
> #include <libm-alias-float.h>
> -
> +#include <math-use-builtins.h>
>
> float
> -__ceilf(float x)
> +__ceilf (float x)
> {
> - int32_t i0,j0;
> - uint32_t i;
> +#if USE_CEILF_BUILTIN
> + return __builtin_ceilf (x);
> +#else
> + int32_t i0, j0;
> + uint32_t i;
>
> - GET_FLOAT_WORD(i0,x);
> - j0 = ((i0>>23)&0xff)-0x7f;
> - if(j0<23) {
> - if(j0<0) {
> - /* return 0*sign(x) if |x|<1 */
> - if(i0<0) {i0=0x80000000;}
> - else if(i0!=0) { i0=0x3f800000;}
> - } else {
> - i = (0x007fffff)>>j0;
> - if((i0&i)==0) return x; /* x is integral */
> - if(i0>0) i0 += (0x00800000)>>j0;
> - i0 &= (~i);
> - }
> - } else {
> - if(__builtin_expect(j0==0x80, 0)) return x+x; /* inf or NaN */
> - else return x; /* x is integral */
> + GET_FLOAT_WORD (i0, x);
> + j0 = ((i0 >> 23) & 0xff) - 0x7f;
> + if (j0 < 23)
> + {
> + if (j0 < 0)
> + {
> + /* return 0 * sign (x) if |x| < 1 */
> + if (i0 < 0)
> + i0 = 0x80000000;
> + else if (i0 != 0)
> + i0 = 0x3f800000;
> + }
> + else
> + {
> + i = (0x007fffff) >> j0;
> + if ((i0 & i) == 0)
> + return x; /* x is integral */
> + if (i0 > 0)
> + i0 += (0x00800000) >> j0;
> + i0 &= (~i);
> }
> - SET_FLOAT_WORD(x,i0);
> - return x;
> + }
> + else
> + {
> + if (__glibc_unlikely (j0 == 0x80))
> + return x + x; /* inf or NaN */
> + else
> + return x; /* x is integral */
> + }
> + SET_FLOAT_WORD (x, i0);
> + return x;
> +#endif /* USE_CEILF_BUILTIN */
> }
> #ifndef __ceilf
> libm_alias_float (__ceil, ceil)
Ok, but fix the indentation in a separated patch.
> diff --git a/sysdeps/ieee754/ldbl-128/s_ceill.c b/sysdeps/ieee754/ldbl-128/s_ceill.c
> index 2ec55de25a..019f9fd950 100644
> --- a/sysdeps/ieee754/ldbl-128/s_ceill.c
> +++ b/sysdeps/ieee754/ldbl-128/s_ceill.c
> @@ -13,7 +13,9 @@
> * ====================================================
> */
>
> -#if defined(LIBM_SCCS) && !defined(lint)
> +#include <math-use-builtins.h>
> +
> +#if ! USE_CEILL_BUILTIN && defined (LIBM_SCCS) && ! defined (lint)
> static char rcsid[] = "$NetBSD: $";
> #endif
>
> @@ -29,40 +31,71 @@ static char rcsid[] = "$NetBSD: $";
> #include <math_private.h>
> #include <libm-alias-ldouble.h>
>
> -_Float128 __ceill(_Float128 x)
> +_Float128
> +__ceill (_Float128 x)
> {
> - int64_t i0,i1,j0;
> - uint64_t i,j;
> - GET_LDOUBLE_WORDS64(i0,i1,x);
> - j0 = ((i0>>48)&0x7fff)-0x3fff;
> - if(j0<48) {
> - if(j0<0) {
> - /* return 0*sign(x) if |x|<1 */
> - if(i0<0) {i0=0x8000000000000000ULL;i1=0;}
> - else if((i0|i1)!=0) { i0=0x3fff000000000000ULL;i1=0;}
> - } else {
> - i = (0x0000ffffffffffffULL)>>j0;
> - if(((i0&i)|i1)==0) return x; /* x is integral */
> - if(i0>0) i0 += (0x0001000000000000LL)>>j0;
> - i0 &= (~i); i1=0;
> +#if USE_CEILL_BUILTIN
> + return __builtin_ceill (x);
> +#else
> + int64_t i0, i1, j0;
> + uint64_t i, j;
> + GET_LDOUBLE_WORDS64 (i0, i1, x);
> + j0 = ((i0 >> 48) & 0x7fff) - 0x3fff;
> + if (j0 < 48)
> + {
> + if (j0 < 0)
> + {
> + /* return 0 * sign (x) if |x| < 1 */
> + if (i0 < 0)
> + {
> + i0 = 0x8000000000000000ULL;
> + i1 = 0;
> + }
> + else if ((i0 | i1) != 0)
> + {
> + i0 = 0x3fff000000000000ULL;
> + i1 = 0;
> }
> - } else if (j0>111) {
> - if(j0==0x4000) return x+x; /* inf or NaN */
> - else return x; /* x is integral */
> - } else {
> - i = -1ULL>>(j0-48);
> - if((i1&i)==0) return x; /* x is integral */
> - if(i0>0) {
> - if(j0==48) i0+=1;
> - else {
> - j = i1+(1LL<<(112-j0));
> - if(j<i1) i0 +=1 ; /* got a carry */
> - i1=j;
> - }
> + }
> + else
> + {
> + i = (0x0000ffffffffffffULL) >> j0;
> + if (((i0 & i) | i1) == 0)
> + return x; /* x is integral */
> + if (i0 > 0)
> + i0 += (0x0001000000000000LL) >> j0;
> + i0 &= (~i);
> + i1 = 0;
> + }
> + }
> + else if (j0 > 111)
> + {
> + if (j0 == 0x4000)
> + return x + x; /* inf or NaN */
> + else
> + return x; /* x is integral */
> + }
> + else
> + {
> + i = -1ULL >> (j0 - 48);
> + if ((i1 & i) == 0)
> + return x; /* x is integral */
> + if (i0 > 0)
> + {
> + if (j0 == 48)
> + i0 += 1;
> + else
> + {
> + j = i1 + (1LL << (112 - j0));
> + if (j < i1)
> + i0 += 1; /* got a carry */
> + i1 = j;
> }
> - i1 &= (~i);
> }
> - SET_LDOUBLE_WORDS64(x,i0,i1);
> - return x;
> + i1 &= (~i);
> + }
> + SET_LDOUBLE_WORDS64 (x, i0, i1);
> + return x;
> +#endif /* USE_CEILL_BUILTIN */
> }
> libm_alias_ldouble (__ceil, ceil)
Ok, but fix the indentation in a separated patch.
> diff --git a/sysdeps/s390/fpu/math-use-builtins.h b/sysdeps/s390/fpu/math-use-builtins.h
> index 63cc9d7a23..dc364edaa8 100644
> --- a/sysdeps/s390/fpu/math-use-builtins.h
> +++ b/sysdeps/s390/fpu/math-use-builtins.h
> @@ -38,14 +38,20 @@
> # define USE_FLOORF_BUILTIN 1
> # define USE_FLOORL_BUILTIN 1
>
> +# define USE_CEIL_BUILTIN 1
> +# define USE_CEILF_BUILTIN 1
> +# define USE_CEILL_BUILTIN 1
> +
> # if __GNUC_PREREQ (8, 1)
> # define USE_NEARBYINTF128_BUILTIN 1
> # define USE_RINTF128_BUILTIN 1
> # define USE_FLOORF128_BUILTIN 1
> +# define USE_CEILF128_BUILTIN 1
> # else
> # define USE_NEARBYINTF128_BUILTIN 0
> # define USE_RINTF128_BUILTIN 0
> # define USE_FLOORF128_BUILTIN 0
> +# define USE_CEILF128_BUILTIN 0
> # endif
>
> #else
>
Ok.
next prev parent reply other threads:[~2019-12-05 20:41 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-02 14:46 [PATCH 00/13] Use GCC builtins for some math functions if desired Stefan Liebler
2019-12-02 14:46 ` [PATCH 01/13] Always use wordsize-64 version of s_nearbyint.c Stefan Liebler
2019-12-05 20:40 ` Adhemerval Zanella
2019-12-02 14:46 ` [PATCH 02/13] Always use wordsize-64 version of s_rint.c Stefan Liebler
2019-12-05 20:40 ` Adhemerval Zanella
2019-12-02 14:46 ` [PATCH 03/13] Always use wordsize-64 version of s_floor.c Stefan Liebler
2019-12-05 20:40 ` Adhemerval Zanella
2019-12-02 14:46 ` [PATCH 04/13] Always use wordsize-64 version of s_ceil.c Stefan Liebler
2019-12-05 20:40 ` Adhemerval Zanella
2019-12-02 14:46 ` [PATCH 05/13] Always use wordsize-64 version of s_trunc.c Stefan Liebler
2019-12-05 20:40 ` Adhemerval Zanella
2019-12-02 14:46 ` [PATCH 06/13] Always use wordsize-64 version of s_round.c Stefan Liebler
2019-12-05 20:40 ` Adhemerval Zanella
2019-12-02 14:46 ` [PATCH 07/13] Use GCC builtins for nearbyint functions if desired Stefan Liebler
2019-12-05 20:40 ` Adhemerval Zanella
2019-12-02 14:46 ` [PATCH 08/13] Use GCC builtins for rint " Stefan Liebler
2019-12-05 20:40 ` Adhemerval Zanella
2019-12-02 14:46 ` [PATCH 09/13] Use GCC builtins for floor " Stefan Liebler
2019-12-05 20:40 ` Adhemerval Zanella
2019-12-02 14:46 ` [PATCH 10/13] Use GCC builtins for ceil " Stefan Liebler
2019-12-05 20:40 ` Adhemerval Zanella [this message]
2019-12-02 14:46 ` [PATCH 11/13] Use GCC builtins for trunc " Stefan Liebler
2019-12-05 20:40 ` Adhemerval Zanella
2019-12-02 14:46 ` [PATCH 12/13] Use GCC builtins for round " Stefan Liebler
2019-12-05 20:40 ` Adhemerval Zanella
2019-12-02 14:46 ` [PATCH 13/13] Use GCC builtins for copysign " Stefan Liebler
2019-12-02 21:00 ` Joseph Myers
2019-12-03 8:27 ` Stefan Liebler
2019-12-03 16:50 ` Joseph Myers
2019-12-04 13:15 ` Stefan Liebler
2019-12-04 13:20 ` Joseph Myers
2019-12-04 16:34 ` Stefan Liebler
2019-12-04 20:43 ` Joseph Myers
2019-12-05 15:40 ` Stefan Liebler
2019-12-09 12:57 ` [PATCH 00/13] Use GCC builtins for some math " Stefan Liebler
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/libc/involved.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0fa6cb32-f6c0-b80b-d955-3c8907a0c672@linaro.org \
--to=adhemerval.zanella@linaro.org \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).