[PATCH 00/13] Use GCC builtins for some math functions if desired.

classic Classic list List threaded Threaded
35 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 13/13] Use GCC builtins for copysign functions if desired.

Joseph Myers
On Wed, 4 Dec 2019, Stefan Liebler wrote:

> Okay. Then I've removed the macros for float and double and call the builtins
> unconditionally.
> But I still need the long double version as the f128 builtin is not available
> with every GCC version.

I think the _Float128 version could be defined to 1 for GCC 7 and later
(so both long double and _Float128 versions could be removed once we
require GCC 7 or later to build glibc).

--
Joseph S. Myers
[hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 13/13] Use GCC builtins for copysign functions if desired.

Stefan Liebler-2
On 12/4/19 9:43 PM, Joseph Myers wrote:

> On Wed, 4 Dec 2019, Stefan Liebler wrote:
>
>> Okay. Then I've removed the macros for float and double and call the builtins
>> unconditionally.
>> But I still need the long double version as the f128 builtin is not available
>> with every GCC version.
>
> I think the _Float128 version could be defined to 1 for GCC 7 and later
> (so both long double and _Float128 versions could be removed once we
> require GCC 7 or later to build glibc).
>
Okay. I've defined it to 1 for GCC 7 and later.

Bye
Stefan

20191205_1630_copysign.patch (6K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 01/13] Always use wordsize-64 version of s_nearbyint.c.

Adhemerval Zanella-2
In reply to this post by Stefan Liebler-2


On 02/12/2019 11:46, Stefan Liebler wrote:
> This patch replaces s_nearbyint.c in sysdeps/dbl-64 with the one in
> sysdeps/dbl-64/wordsize-64 and removes the latter one.
> The code is not changed except changes in code style.
>
> Also adjusted the include path in x86_64 file.

LGTM, thanks.

Reviewed-by: Adhemerval Zanella <[hidden email]>

> ---
>  sysdeps/ieee754/dbl-64/s_nearbyint.c          | 38 +++++------
>  .../ieee754/dbl-64/wordsize-64/s_nearbyint.c  | 65 -------------------
>  sysdeps/x86_64/fpu/multiarch/s_nearbyint-c.c  |  2 +-
>  3 files changed, 17 insertions(+), 88 deletions(-)
>  delete mode 100644 sysdeps/ieee754/dbl-64/wordsize-64/s_nearbyint.c
>
> diff --git a/sysdeps/ieee754/dbl-64/s_nearbyint.c b/sysdeps/ieee754/dbl-64/s_nearbyint.c
> index 4ce570ac7f..c261885c5a 100644
> --- a/sysdeps/ieee754/dbl-64/s_nearbyint.c
> +++ b/sysdeps/ieee754/dbl-64/s_nearbyint.c
> @@ -10,10 +10,6 @@
>   * ====================================================
>   */
>  
> -#if defined(LIBM_SCCS) && !defined(lint)
> -static char rcsid[] = "$NetBSD: s_rint.c,v 1.8 1995/05/10 20:48:04 jtc Exp $";
> -#endif
> -
>  /*
>   * rint(x)
>   * Return x rounded to integral value according to the prevailing
> @@ -32,44 +28,42 @@ static char rcsid[] = "$NetBSD: s_rint.c,v 1.8 1995/05/10 20:48:04 jtc Exp $";
>  #include <libm-alias-double.h>
>  
>  static const double
> -  TWO52[2] = {
> -  4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
> - -4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */
> +TWO52[2] = {
> +    4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
> +    -4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */
>  };
>  
>  double
>  __nearbyint (double x)
>  {
>    fenv_t env;
> -  int32_t i0, j0, sx;
> -  double w, t;
> -  GET_HIGH_WORD (i0, x);
> -  sx = (i0 >> 31) & 1;
> -  j0 = ((i0 >> 20) & 0x7ff) - 0x3ff;
> -  if (j0 < 52)
> +  int64_t i0, sx;
> +  int32_t j0;
> +  EXTRACT_WORDS64 (i0, x);
> +  sx = (i0 >> 63) & 1;
> +  j0 = ((i0 >> 52) & 0x7ff) - 0x3ff;
> +  if (__glibc_likely (j0 < 52))
>      {
>        if (j0 < 0)
>   {
>    libc_feholdexcept (&env);
> -  w = TWO52[sx] + math_opt_barrier (x);
> -  t = w - TWO52[sx];
> +  double w = TWO52[sx] + math_opt_barrier (x);
> +  double t =  w - TWO52[sx];
>    math_force_eval (t);
>    libc_fesetenv (&env);
> -  GET_HIGH_WORD (i0, t);
> -  SET_HIGH_WORD (t, (i0 & 0x7fffffff) | (sx << 31));
> -  return t;
> +  return copysign (t, x);
>   }
>      }
>    else
>      {
>        if (j0 == 0x400)
> - return x + x;                   /* inf or NaN */
> + return x + x; /* inf or NaN  */
>        else
> - return x;                       /* x is integral */
> + return x; /* x is integral  */
>      }
>    libc_feholdexcept (&env);
> -  w = TWO52[sx] + math_opt_barrier (x);
> -  t = w - TWO52[sx];
> +  double w = TWO52[sx] + math_opt_barrier (x);
> +  double t = w - TWO52[sx];
>    math_force_eval (t);
>    libc_fesetenv (&env);
>    return t;

Ok.

> diff --git a/sysdeps/ieee754/dbl-64/wordsize-64/s_nearbyint.c b/sysdeps/ieee754/dbl-64/wordsize-64/s_nearbyint.c
> deleted file mode 100644
> index 92fa72af59..0000000000
> --- a/sysdeps/ieee754/dbl-64/wordsize-64/s_nearbyint.c
> +++ /dev/null
> @@ -1,65 +0,0 @@
> -/* Adapted for use as nearbyint by Ulrich Drepper <[hidden email]>.  */
> -/*
> - * ====================================================
> - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
> - *
> - * Developed at SunPro, a Sun Microsystems, Inc. business.
> - * Permission to use, copy, modify, and distribute this
> - * software is freely granted, provided that this notice
> - * is preserved.
> - * ====================================================
> - */
> -
> -/*
> - * rint(x)
> - * Return x rounded to integral value according to the prevailing
> - * rounding mode.
> - * Method:
> - * Using floating addition.
> - * Exception:
> - * Inexact flag raised if x not equal to rint(x).
> - */
> -
> -#include <fenv.h>
> -#include <math.h>
> -#include <math-barriers.h>
> -#include <math_private.h>
> -#include <fenv_private.h>
> -#include <libm-alias-double.h>
> -
> -static const double
> -TWO52[2]={
> -  4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
> - -4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */
> -};
> -
> -double
> -__nearbyint(double x)
> -{
> - fenv_t env;
> - int64_t i0,sx;
> - int32_t j0;
> - EXTRACT_WORDS64(i0,x);
> - sx = (i0>>63)&1;
> - j0 = ((i0>>52)&0x7ff)-0x3ff;
> - if(__builtin_expect(j0<52, 1)) {
> -    if(j0<0) {
> - libc_feholdexcept (&env);
> - double w = TWO52[sx] + math_opt_barrier (x);
> - double t =  w-TWO52[sx];
> - math_force_eval (t);
> - libc_fesetenv (&env);
> - return copysign (t, x);
> -    }
> - } else {
> -    if(j0==0x400) return x+x; /* inf or NaN */
> -    else return x; /* x is integral */
> - }
> - libc_feholdexcept (&env);
> - double w = TWO52[sx] + math_opt_barrier (x);
> - double t = w-TWO52[sx];
> - math_force_eval (t);
> - libc_fesetenv (&env);
> - return t;
> -}
> -libm_alias_double (__nearbyint, nearbyint)

Ok.

> diff --git a/sysdeps/x86_64/fpu/multiarch/s_nearbyint-c.c b/sysdeps/x86_64/fpu/multiarch/s_nearbyint-c.c
> index f897a2a6a6..4fdeb11291 100644
> --- a/sysdeps/x86_64/fpu/multiarch/s_nearbyint-c.c
> +++ b/sysdeps/x86_64/fpu/multiarch/s_nearbyint-c.c
> @@ -1,3 +1,3 @@
>  #undef __nearbyint
>  #define __nearbyint __nearbyint_c
> -#include <sysdeps/ieee754/dbl-64/wordsize-64/s_nearbyint.c>
> +#include <sysdeps/ieee754/dbl-64/s_nearbyint.c>
>

Ok.
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 02/13] Always use wordsize-64 version of s_rint.c.

Adhemerval Zanella-2
In reply to this post by Stefan Liebler-2


On 02/12/2019 11:46, Stefan Liebler wrote:
> This patch replaces s_rint.c in sysdeps/dbl-64 with the one in
> sysdeps/dbl-64/wordsize-64 and removes the latter one.
> The code is not changed except changes in code style.
>
> Also adjusted the include path in x86_64 file.

LGTM, thanks.

Reviewed-by: Adhemerval Zanella <[hidden email]>

> ---
>  sysdeps/ieee754/dbl-64/s_rint.c             | 36 ++++++-------
>  sysdeps/ieee754/dbl-64/wordsize-64/s_rint.c | 58 ---------------------
>  sysdeps/x86_64/fpu/multiarch/s_rint-c.c     |  2 +-
>  3 files changed, 19 insertions(+), 77 deletions(-)
>  delete mode 100644 sysdeps/ieee754/dbl-64/wordsize-64/s_rint.c
>
> diff --git a/sysdeps/ieee754/dbl-64/s_rint.c b/sysdeps/ieee754/dbl-64/s_rint.c
> index dd01a84176..f96078c405 100644
> --- a/sysdeps/ieee754/dbl-64/s_rint.c
> +++ b/sysdeps/ieee754/dbl-64/s_rint.c
> @@ -1,4 +1,3 @@
> -/* @(#)s_rint.c 5.1 93/09/24 */
>  /*
>   * ====================================================
>   * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
> @@ -26,38 +25,39 @@
>  #include <libm-alias-double.h>
>  
>  static const double
> -  TWO52[2] = {
> -  4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
> - -4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */
> +TWO52[2] = {
> +    4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
> +    -4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */
>  };
>  
>  double
>  __rint (double x)
>  {
> -  int32_t i0, j0, sx;
> -  double w, t;
> -  GET_HIGH_WORD (i0, x);
> -  sx = (i0 >> 31) & 1;
> -  j0 = ((i0 >> 20) & 0x7ff) - 0x3ff;
> +  int64_t i0, sx;
> +  int32_t j0;
> +  EXTRACT_WORDS64 (i0, x);
> +  sx = (i0 >> 63) & 1;
> +  j0 = ((i0 >> 52) & 0x7ff) - 0x3ff;
>    if (j0 < 52)
>      {
>        if (j0 < 0)
>   {
> -  w = TWO52[sx] + x;
> -  t = w - TWO52[sx];
> -  GET_HIGH_WORD (i0, t);
> -  SET_HIGH_WORD (t, (i0 & 0x7fffffff) | (sx << 31));
> -  return t;
> +  double w = TWO52[sx] + x;
> +  double t =  w - TWO52[sx];
> +  EXTRACT_WORDS64 (i0, t);
> +  INSERT_WORDS64 (t, (i0 & UINT64_C (0x7fffffffffffffff))
> +  | (sx << 63));
> +      return t;
>   }
>      }
>    else
>      {
>        if (j0 == 0x400)
> - return x + x;                   /* inf or NaN */
> + return x + x; /* inf or NaN  */
>        else
> - return x;                       /* x is integral */
> -    }
> -  w = TWO52[sx] + x;
> + return x; /* x is integral  */
> +  }
> +  double w = TWO52[sx] + x;
>    return w - TWO52[sx];
>  }
>  #ifndef __rint

Ok.

> diff --git a/sysdeps/ieee754/dbl-64/wordsize-64/s_rint.c b/sysdeps/ieee754/dbl-64/wordsize-64/s_rint.c
> deleted file mode 100644
> index 378b73a544..0000000000
> --- a/sysdeps/ieee754/dbl-64/wordsize-64/s_rint.c
> +++ /dev/null
> @@ -1,58 +0,0 @@
> -/*
> - * ====================================================
> - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
> - *
> - * Developed at SunPro, a Sun Microsystems, Inc. business.
> - * Permission to use, copy, modify, and distribute this
> - * software is freely granted, provided that this notice
> - * is preserved.
> - * ====================================================
> - */
> -
> -/*
> - * rint(x)
> - * Return x rounded to integral value according to the prevailing
> - * rounding mode.
> - * Method:
> - * Using floating addition.
> - * Exception:
> - * Inexact flag raised if x not equal to rint(x).
> - */
> -
> -#define NO_MATH_REDIRECT
> -#include <math.h>
> -#include <math_private.h>
> -#include <libm-alias-double.h>
> -
> -static const double
> -TWO52[2]={
> -  4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
> - -4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */
> -};
> -
> -double
> -__rint(double x)
> -{
> - int64_t i0,sx;
> - int32_t j0;
> - EXTRACT_WORDS64(i0,x);
> - sx = (i0>>63)&1;
> - j0 = ((i0>>52)&0x7ff)-0x3ff;
> - if(j0<52) {
> -    if(j0<0) {
> - double w = TWO52[sx]+x;
> - double t =  w-TWO52[sx];
> - EXTRACT_WORDS64(i0,t);
> - INSERT_WORDS64(t,(i0&UINT64_C(0x7fffffffffffffff))|(sx<<63));
> - return t;
> -    }
> - } else {
> -    if(j0==0x400) return x+x; /* inf or NaN */
> -    else return x; /* x is integral */
> - }
> - double w = TWO52[sx]+x;
> - return w-TWO52[sx];
> -}
> -#ifndef __rint
> -libm_alias_double (__rint, rint)
> -#endif

Ok.

> diff --git a/sysdeps/x86_64/fpu/multiarch/s_rint-c.c b/sysdeps/x86_64/fpu/multiarch/s_rint-c.c
> index 162a630ff9..b010150f52 100644
> --- a/sysdeps/x86_64/fpu/multiarch/s_rint-c.c
> +++ b/sysdeps/x86_64/fpu/multiarch/s_rint-c.c
> @@ -1,3 +1,3 @@
>  #undef __rint
>  #define __rint __rint_c
> -#include <sysdeps/ieee754/dbl-64/wordsize-64/s_rint.c>
> +#include <sysdeps/ieee754/dbl-64/s_rint.c>
>

Ok.
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 03/13] Always use wordsize-64 version of s_floor.c.

Adhemerval Zanella-2
In reply to this post by Stefan Liebler-2


On 02/12/2019 11:46, Stefan Liebler wrote:
> This patch replaces s_floor.c in sysdeps/dbl-64 with the one in
> sysdeps/dbl-64/wordsize-64 and removes the latter one.
> The code is not changed except changes in code style.
>
> Also adjusted the include path in x86_64 and sparc64 files.

LGTM, thanks.

Reviewed-by: Adhemerval Zanella <[hidden email]>

> ---
>  sysdeps/ieee754/dbl-64/s_floor.c              | 93 +++++++++----------
>  sysdeps/ieee754/dbl-64/wordsize-64/s_floor.c  | 72 --------------
>  .../sparc64/fpu/multiarch/s_floor-generic.c   |  2 +-
>  .../sparc64/fpu/multiarch/s_floor-vis3.c      |  2 +-
>  sysdeps/x86_64/fpu/multiarch/s_floor-c.c      |  2 +-
>  5 files changed, 46 insertions(+), 125 deletions(-)
>  delete mode 100644 sysdeps/ieee754/dbl-64/wordsize-64/s_floor.c
>
> diff --git a/sysdeps/ieee754/dbl-64/s_floor.c b/sysdeps/ieee754/dbl-64/s_floor.c
> index bebc018658..ce0c42bdb6 100644
> --- a/sysdeps/ieee754/dbl-64/s_floor.c
> +++ b/sysdeps/ieee754/dbl-64/s_floor.c
> @@ -1,4 +1,24 @@
> -/* @(#)s_floor.c 5.1 93/09/24 */
> +/* Round double to integer away from zero.
> +   Copyright (C) 2011-2019 Free Software Foundation, Inc.
> +   This file is part of the GNU C Library.
> +   Contributed by Ulrich Drepper <[hidden email]>, 2011.
> +
> +   The GNU C Library is free software; you can redistribute it and/or
> +   modify it under the terms of the GNU Lesser General Public
> +   License as published by the Free Software Foundation; either
> +   version 2.1 of the License, or (at your option) any later version.
> +
> +   The GNU C Library is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> +   Lesser General Public License for more details.
> +
> +   You should have received a copy of the GNU Lesser General Public
> +   License along with the GNU C Library; if not, see
> +   <https://www.gnu.org/licenses/>.  */
> +
> +/* Based on a version which carries the following copyright:  */
> +
>  /*
>   * ====================================================
>   * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
> @@ -10,6 +30,12 @@
>   * ====================================================
>   */
>  
> +#define NO_MATH_REDIRECT
> +#include <math.h>
> +#include <math_private.h>
> +#include <stdint.h>
> +#include <libm-alias-double.h>
> +
>  /*
>   * floor(x)
>   * Return x rounded toward -inf to integral value
> @@ -17,69 +43,36 @@
>   * Bit twiddling.
>   */
>  
> -#define NO_MATH_REDIRECT
> -#include <math.h>
> -#include <math_private.h>
> -#include <libm-alias-double.h>
>  
>  double
>  __floor (double x)
>  {
> -  int32_t i0, i1, j0;
> -  uint32_t i, j;
> -  EXTRACT_WORDS (i0, i1, x);
> -  j0 = ((i0 >> 20) & 0x7ff) - 0x3ff;
> -  if (j0 < 20)
> +  int64_t i0;
> +  EXTRACT_WORDS64 (i0, x);
> +  int32_t j0 = ((i0 >> 52) & 0x7ff) - 0x3ff;
> +  if (__glibc_likely (j0 < 52))
>      {
>        if (j0 < 0)
>   {
> -  /* return 0*sign(x) if |x|<1 */
> +  /* return 0 * sign (x) if |x| < 1  */
>    if (i0 >= 0)
> -    {
> -      i0 = i1 = 0;
> -    }
> -  else if (((i0 & 0x7fffffff) | i1) != 0)
> -    {
> -      i0 = 0xbff00000; i1 = 0;
> -    }
> +    i0 = 0;
> +  else if ((i0 & 0x7fffffffffffffffl) != 0)
> +    i0 = 0xbff0000000000000l;
>   }
>        else
>   {
> -  i = (0x000fffff) >> j0;
> -  if (((i0 & i) | i1) == 0)
> -    return x;                        /* x is integral */
> +  uint64_t i = 0x000fffffffffffffl >> j0;
> +  if ((i0 & i) == 0)
> +    return x; /* x is integral */
>    if (i0 < 0)
> -    i0 += (0x00100000) >> j0;
> -  i0 &= (~i); i1 = 0;
> - }
> -    }
> -  else if (j0 > 51)
> -    {
> -      if (j0 == 0x400)
> - return x + x;                   /* inf or NaN */
> -      else
> - return x;                       /* x is integral */
> -    }
> -  else
> -    {
> -      i = ((uint32_t) (0xffffffff)) >> (j0 - 20);
> -      if ((i1 & i) == 0)
> - return x;                       /* x is integral */
> -      if (i0 < 0)
> - {
> -  if (j0 == 20)
> -    i0 += 1;
> -  else
> -    {
> -      j = i1 + (1 << (52 - j0));
> -      if (j < i1)
> - i0 += 1;                /* got a carry */
> -      i1 = j;
> -    }
> +    i0 += 0x0010000000000000l >> j0;
> +  i0 &= ~i;
>   }
> -      i1 &= (~i);
> +      INSERT_WORDS64 (x, i0);
>      }
> -  INSERT_WORDS (x, i0, i1);
> +  else if (j0 == 0x400)
> +    return x + x; /* inf or NaN */
>    return x;
>  }
>  #ifndef __floor

Ok.

> diff --git a/sysdeps/ieee754/dbl-64/wordsize-64/s_floor.c b/sysdeps/ieee754/dbl-64/wordsize-64/s_floor.c
> deleted file mode 100644
> index b60f15bf00..0000000000
> --- a/sysdeps/ieee754/dbl-64/wordsize-64/s_floor.c
> +++ /dev/null
> @@ -1,72 +0,0 @@
> -/* Round double to integer away from zero.
> -   Copyright (C) 2011-2019 Free Software Foundation, Inc.
> -   This file is part of the GNU C Library.
> -   Contributed by Ulrich Drepper <[hidden email]>, 2011.
> -
> -   The GNU C Library is free software; you can redistribute it and/or
> -   modify it under the terms of the GNU Lesser General Public
> -   License as published by the Free Software Foundation; either
> -   version 2.1 of the License, or (at your option) any later version.
> -
> -   The GNU C Library is distributed in the hope that it will be useful,
> -   but WITHOUT ANY WARRANTY; without even the implied warranty of
> -   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> -   Lesser General Public License for more details.
> -
> -   You should have received a copy of the GNU Lesser General Public
> -   License along with the GNU C Library; if not, see
> -   <https://www.gnu.org/licenses/>.  */
> -
> -/* Based on a version which carries the following copyright:  */
> -
> -/*
> - * ====================================================
> - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
> - *
> - * Developed at SunPro, a Sun Microsystems, Inc. business.
> - * Permission to use, copy, modify, and distribute this
> - * software is freely granted, provided that this notice
> - * is preserved.
> - * ====================================================
> - */
> -
> -#define NO_MATH_REDIRECT
> -#include <math.h>
> -#include <math_private.h>
> -#include <stdint.h>
> -#include <libm-alias-double.h>
> -
> -/*
> - * floor(x)
> - * Return x rounded toward -inf to integral value
> - * Method:
> - * Bit twiddling.
> - */
> -
> -
> -double
> -__floor (double x)
> -{
> - int64_t i0;
> - EXTRACT_WORDS64(i0,x);
> - int32_t j0 = ((i0>>52)&0x7ff)-0x3ff;
> - if(__builtin_expect(j0<52, 1)) {
> -    if(j0<0) {
> - /* return 0*sign(x) if |x|<1 */
> - if(i0>=0) {i0=0;}
> - else if((i0&0x7fffffffffffffffl)!=0)
> -  { i0=0xbff0000000000000l;}
> -    } else {
> - uint64_t i = (0x000fffffffffffffl)>>j0;
> - if((i0&i)==0) return x; /* x is integral */
> - if(i0<0) i0 += (0x0010000000000000l)>>j0;
> - i0 &= (~i);
> -    }
> -    INSERT_WORDS64(x,i0);
> - } else if (j0==0x400)
> -    return x+x; /* inf or NaN */
> - return x;
> -}
> -#ifndef __floor
> -libm_alias_double (__floor, floor)
> -#endif

Ok.

> diff --git a/sysdeps/sparc/sparc64/fpu/multiarch/s_floor-generic.c b/sysdeps/sparc/sparc64/fpu/multiarch/s_floor-generic.c
> index 0f3361a9fb..c92b600df1 100644
> --- a/sysdeps/sparc/sparc64/fpu/multiarch/s_floor-generic.c
> +++ b/sysdeps/sparc/sparc64/fpu/multiarch/s_floor-generic.c
> @@ -1,2 +1,2 @@
>  #define __floor __floor_generic
> -#include <sysdeps/ieee754/dbl-64/wordsize-64/s_floor.c>
> +#include <sysdeps/ieee754/dbl-64/s_floor.c>

Ok.

> diff --git a/sysdeps/sparc/sparc64/fpu/multiarch/s_floor-vis3.c b/sysdeps/sparc/sparc64/fpu/multiarch/s_floor-vis3.c
> index ccac0e46af..4f3d53c0e3 100644
> --- a/sysdeps/sparc/sparc64/fpu/multiarch/s_floor-vis3.c
> +++ b/sysdeps/sparc/sparc64/fpu/multiarch/s_floor-vis3.c
> @@ -20,4 +20,4 @@
>  
>  #define __floor __floor_vis3
>  
> -#include <sysdeps/ieee754/dbl-64/wordsize-64/s_floor.c>
> +#include <sysdeps/ieee754/dbl-64/s_floor.c>

Ok.

> diff --git a/sysdeps/x86_64/fpu/multiarch/s_floor-c.c b/sysdeps/x86_64/fpu/multiarch/s_floor-c.c
> index 68733b69ef..002d12247e 100644
> --- a/sysdeps/x86_64/fpu/multiarch/s_floor-c.c
> +++ b/sysdeps/x86_64/fpu/multiarch/s_floor-c.c
> @@ -1,3 +1,3 @@
>  #undef __floor
>  #define __floor __floor_c
> -#include <sysdeps/ieee754/dbl-64/wordsize-64/s_floor.c>
> +#include <sysdeps/ieee754/dbl-64/s_floor.c>
>

Ok.
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 04/13] Always use wordsize-64 version of s_ceil.c.

Adhemerval Zanella-2
In reply to this post by Stefan Liebler-2


On 02/12/2019 11:46, Stefan Liebler wrote:
> This patch replaces s_ceil.c in sysdeps/dbl-64 with the one in
> sysdeps/dbl-64/wordsize-64 and removes the latter one.
> The code is not changed except changes in code style.
>
> Also adjusted the include path in x86_64 and sparc64 files.

LGTM, thanks.

Reviewed-by: Adhemerval Zanella <[hidden email]>

> ---
>  sysdeps/ieee754/dbl-64/s_ceil.c               | 61 ++++++-------------
>  sysdeps/ieee754/dbl-64/wordsize-64/s_ceil.c   | 52 ----------------
>  .../sparc64/fpu/multiarch/s_ceil-generic.c    |  2 +-
>  .../sparc/sparc64/fpu/multiarch/s_ceil-vis3.c |  2 +-
>  sysdeps/x86_64/fpu/multiarch/s_ceil-c.c       |  2 +-
>  5 files changed, 22 insertions(+), 97 deletions(-)
>  delete mode 100644 sysdeps/ieee754/dbl-64/wordsize-64/s_ceil.c
>
> diff --git a/sysdeps/ieee754/dbl-64/s_ceil.c b/sysdeps/ieee754/dbl-64/s_ceil.c
> index 4c96286c69..9d214eac81 100644
> --- a/sysdeps/ieee754/dbl-64/s_ceil.c
> +++ b/sysdeps/ieee754/dbl-64/s_ceil.c
> @@ -23,63 +23,40 @@
>  #include <libm-alias-double.h>
>  
>  double
> -__ceil (double x)
> +__ceil(double x)
>  {
> -  int32_t i0, i1, j0;
> -  uint32_t i, j;
> -  EXTRACT_WORDS (i0, i1, x);
> -  j0 = ((i0 >> 20) & 0x7ff) - 0x3ff;
> -  if (j0 < 20)
> +  int64_t i0, i;
> +  int32_t j0;
> +  EXTRACT_WORDS64 (i0, x);
> +  j0 = ((i0 >> 52) & 0x7ff) - 0x3ff;
> +  if (j0 <= 51)
>      {
>        if (j0 < 0)
>   {
> -  /* return 0*sign(x) if |x|<1 */
> +  /* return 0 * sign(x) if |x| < 1  */
>    if (i0 < 0)
> -    {
> -      i0 = 0x80000000; i1 = 0;
> -    }
> -  else if ((i0 | i1) != 0)
> -    {
> -      i0 = 0x3ff00000; i1 = 0;
> -    }
> +    i0 = INT64_C (0x8000000000000000);
> +  else if (i0 != 0)
> +    i0 = INT64_C (0x3ff0000000000000);
>   }
>        else
>   {
> -  i = (0x000fffff) >> j0;
> -  if (((i0 & i) | i1) == 0)
> -    return x;                        /* x is integral */
> +  i = INT64_C (0x000fffffffffffff) >> j0;
> +  if ((i0 & i) == 0)
> +    return x; /* x is integral  */
>    if (i0 > 0)
> -    i0 += (0x00100000) >> j0;
> -  i0 &= (~i); i1 = 0;
> +    i0 += UINT64_C (0x0010000000000000) >> j0;
> +  i0 &= ~i;
>   }
>      }
> -  else if (j0 > 51)
> +  else
>      {
>        if (j0 == 0x400)
> - return x + x;                   /* inf or NaN */
> + return x + x; /* inf or NaN  */
>        else
> - return x;                       /* x is integral */
> -    }
> -  else
> -    {
> -      i = ((uint32_t) (0xffffffff)) >> (j0 - 20);
> -      if ((i1 & i) == 0)
> - return x;                       /* x is integral */
> -      if (i0 > 0)
> - {
> -  if (j0 == 20)
> -    i0 += 1;
> -  else
> -    {
> -      j = i1 + (1 << (52 - j0));
> -      if (j < i1)
> - i0 += 1;                /* got a carry */
> -      i1 = j;
> -    }
> - }
> -      i1 &= (~i);
> + return x; /* x is integral  */
>      }
> -  INSERT_WORDS (x, i0, i1);
> +  INSERT_WORDS64 (x, i0);
>    return x;
>  }
>  #ifndef __ceil

Ok.

> diff --git a/sysdeps/ieee754/dbl-64/wordsize-64/s_ceil.c b/sysdeps/ieee754/dbl-64/wordsize-64/s_ceil.c
> deleted file mode 100644
> index 4bb93d0633..0000000000
> --- a/sysdeps/ieee754/dbl-64/wordsize-64/s_ceil.c
> +++ /dev/null
> @@ -1,52 +0,0 @@
> -/* @(#)s_ceil.c 5.1 93/09/24 */
> -/*
> - * ====================================================
> - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
> - *
> - * Developed at SunPro, a Sun Microsystems, Inc. business.
> - * Permission to use, copy, modify, and distribute this
> - * software is freely granted, provided that this notice
> - * is preserved.
> - * ====================================================
> - */
> -
> -/*
> - * ceil(x)
> - * Return x rounded toward -inf to integral value
> - * Method:
> - * Bit twiddling.
> - */
> -
> -#define NO_MATH_REDIRECT
> -#include <math.h>
> -#include <math_private.h>
> -#include <libm-alias-double.h>
> -
> -double
> -__ceil(double x)
> -{
> - int64_t i0,i;
> - int32_t j0;
> - EXTRACT_WORDS64(i0,x);
> - j0 = ((i0>>52)&0x7ff)-0x3ff;
> - if(j0<=51) {
> -    if(j0<0) {
> -      /* return 0*sign(x) if |x|<1 */
> -      if(i0<0) {i0=INT64_C(0x8000000000000000);}
> -      else if(i0!=0) { i0=INT64_C(0x3ff0000000000000);}
> -    } else {
> - i = INT64_C(0x000fffffffffffff)>>j0;
> - if((i0&i)==0) return x; /* x is integral */
> - if(i0>0) i0 += UINT64_C(0x0010000000000000)>>j0;
> - i0 &= (~i);
> -    }
> - } else {
> -    if(j0==0x400) return x+x; /* inf or NaN */
> -    else return x; /* x is integral */
> - }
> - INSERT_WORDS64(x,i0);
> - return x;
> -}
> -#ifndef __ceil
> -libm_alias_double (__ceil, ceil)
> -#endif

Ok.

> diff --git a/sysdeps/sparc/sparc64/fpu/multiarch/s_ceil-generic.c b/sysdeps/sparc/sparc64/fpu/multiarch/s_ceil-generic.c
> index febea745e1..80f68b6766 100644
> --- a/sysdeps/sparc/sparc64/fpu/multiarch/s_ceil-generic.c
> +++ b/sysdeps/sparc/sparc64/fpu/multiarch/s_ceil-generic.c
> @@ -1,2 +1,2 @@
>  #define __ceil __ceil_generic
> -#include <sysdeps/ieee754/dbl-64/wordsize-64/s_ceil.c>
> +#include <sysdeps/ieee754/dbl-64/s_ceil.c>
> diff --git a/sysdeps/sparc/sparc64/fpu/multiarch/s_ceil-vis3.c b/sysdeps/sparc/sparc64/fpu/multiarch/s_ceil-vis3.c
> index 9c17809da4..2b89199c62 100644
> --- a/sysdeps/sparc/sparc64/fpu/multiarch/s_ceil-vis3.c
> +++ b/sysdeps/sparc/sparc64/fpu/multiarch/s_ceil-vis3.c
> @@ -20,4 +20,4 @@
>  
>  #define __ceil __ceil_vis3
>  
> -#include <sysdeps/ieee754/dbl-64/wordsize-64/s_ceil.c>
> +#include <sysdeps/ieee754/dbl-64/s_ceil.c>

Ok.

> diff --git a/sysdeps/x86_64/fpu/multiarch/s_ceil-c.c b/sysdeps/x86_64/fpu/multiarch/s_ceil-c.c
> index 6a5ea3ff27..ada28baa1a 100644
> --- a/sysdeps/x86_64/fpu/multiarch/s_ceil-c.c
> +++ b/sysdeps/x86_64/fpu/multiarch/s_ceil-c.c
> @@ -1,2 +1,2 @@
>  #define __ceil __ceil_c
> -#include <sysdeps/ieee754/dbl-64/wordsize-64/s_ceil.c>
> +#include <sysdeps/ieee754/dbl-64/s_ceil.c>
>

Ok.
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 05/13] Always use wordsize-64 version of s_trunc.c.

Adhemerval Zanella-2
In reply to this post by Stefan Liebler-2


On 02/12/2019 11:46, Stefan Liebler wrote:
> This patch replaces s_trunc.c in sysdeps/dbl-64 with the one in
> sysdeps/dbl-64/wordsize-64 and removes the latter one.
> The code is not changed except changes in code style.
>
> Also adjusted the include path in x86_64 and sparc64 files.

LGTM, thanks.

Reviewed-by: Adhemerval Zanella <[hidden email]>

> ---
>  sysdeps/ieee754/dbl-64/s_trunc.c              | 25 ++++-----
>  sysdeps/ieee754/dbl-64/wordsize-64/s_trunc.c  | 55 -------------------
>  .../sparc64/fpu/multiarch/s_trunc-generic.c   |  2 +-
>  .../sparc64/fpu/multiarch/s_trunc-vis3.c      |  2 +-
>  sysdeps/x86_64/fpu/multiarch/s_trunc-c.c      |  2 +-
>  5 files changed, 13 insertions(+), 73 deletions(-)
>  delete mode 100644 sysdeps/ieee754/dbl-64/wordsize-64/s_trunc.c
>
> diff --git a/sysdeps/ieee754/dbl-64/s_trunc.c b/sysdeps/ieee754/dbl-64/s_trunc.c
> index 154feb9aa3..0de68ce298 100644
> --- a/sysdeps/ieee754/dbl-64/s_trunc.c
> +++ b/sysdeps/ieee754/dbl-64/s_trunc.c
> @@ -27,31 +27,26 @@
>  double
>  __trunc (double x)
>  {
> -  int32_t i0, j0;
> -  uint32_t i1;
> -  int sx;
> -
> -  EXTRACT_WORDS (i0, i1, x);
> -  sx = i0 & 0x80000000;
> -  j0 = ((i0 >> 20) & 0x7ff) - 0x3ff;
> -  if (j0 < 20)
> +  int64_t i0, j0;
> +  int64_t sx;
> +
> +  EXTRACT_WORDS64 (i0, x);
> +  sx = i0 & UINT64_C (0x8000000000000000);
> +  j0 = ((i0 >> 52) & 0x7ff) - 0x3ff;
> +  if (j0 < 52)
>      {
>        if (j0 < 0)
>   /* The magnitude of the number is < 1 so the result is +-0.  */
> - INSERT_WORDS (x, sx, 0);
> + INSERT_WORDS64 (x, sx);
>        else
> - INSERT_WORDS (x, sx | (i0 & ~(0x000fffff >> j0)), 0);
> + INSERT_WORDS64 (x, sx | (i0 & ~(UINT64_C (0x000fffffffffffff) >> j0)));
>      }
> -  else if (j0 > 51)
> +  else
>      {
>        if (j0 == 0x400)
>   /* x is inf or NaN.  */
>   return x + x;
>      }
> -  else
> -    {
> -      INSERT_WORDS (x, i0, i1 & ~(0xffffffffu >> (j0 - 20)));
> -    }
>  
>    return x;
>  }

Ok.

> diff --git a/sysdeps/ieee754/dbl-64/wordsize-64/s_trunc.c b/sysdeps/ieee754/dbl-64/wordsize-64/s_trunc.c
> deleted file mode 100644
> index 3f040bbf83..0000000000
> --- a/sysdeps/ieee754/dbl-64/wordsize-64/s_trunc.c
> +++ /dev/null
> @@ -1,55 +0,0 @@
> -/* Truncate argument to nearest integral value not larger than the argument.
> -   Copyright (C) 1997-2019 Free Software Foundation, Inc.
> -   This file is part of the GNU C Library.
> -   Contributed by Ulrich Drepper <[hidden email]>, 1997.
> -
> -   The GNU C Library is free software; you can redistribute it and/or
> -   modify it under the terms of the GNU Lesser General Public
> -   License as published by the Free Software Foundation; either
> -   version 2.1 of the License, or (at your option) any later version.
> -
> -   The GNU C Library is distributed in the hope that it will be useful,
> -   but WITHOUT ANY WARRANTY; without even the implied warranty of
> -   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> -   Lesser General Public License for more details.
> -
> -   You should have received a copy of the GNU Lesser General Public
> -   License along with the GNU C Library; if not, see
> -   <https://www.gnu.org/licenses/>.  */
> -
> -#define NO_MATH_REDIRECT
> -#include <math.h>
> -
> -#include <math_private.h>
> -#include <libm-alias-double.h>
> -
> -
> -double
> -__trunc (double x)
> -{
> -  int64_t i0, j0;
> -  int64_t sx;
> -
> -  EXTRACT_WORDS64 (i0, x);
> -  sx = i0 & UINT64_C(0x8000000000000000);
> -  j0 = ((i0 >> 52) & 0x7ff) - 0x3ff;
> -  if (j0 < 52)
> -    {
> -      if (j0 < 0)
> - /* The magnitude of the number is < 1 so the result is +-0.  */
> - INSERT_WORDS64 (x, sx);
> -      else
> - INSERT_WORDS64 (x, sx | (i0 & ~(UINT64_C(0x000fffffffffffff) >> j0)));
> -    }
> -  else
> -    {
> -      if (j0 == 0x400)
> - /* x is inf or NaN.  */
> - return x + x;
> -    }
> -
> -  return x;
> -}
> -#ifndef __trunc
> -libm_alias_double (__trunc, trunc)
> -#endif

Ok.

> diff --git a/sysdeps/sparc/sparc64/fpu/multiarch/s_trunc-generic.c b/sysdeps/sparc/sparc64/fpu/multiarch/s_trunc-generic.c
> index 00abd2a643..c198ebb3d5 100644
> --- a/sysdeps/sparc/sparc64/fpu/multiarch/s_trunc-generic.c
> +++ b/sysdeps/sparc/sparc64/fpu/multiarch/s_trunc-generic.c
> @@ -1,2 +1,2 @@
>  #define __trunc __trunc_generic
> -#include <sysdeps/ieee754/dbl-64/wordsize-64/s_trunc.c>
> +#include <sysdeps/ieee754/dbl-64/s_trunc.c>

Ok.

> diff --git a/sysdeps/sparc/sparc64/fpu/multiarch/s_trunc-vis3.c b/sysdeps/sparc/sparc64/fpu/multiarch/s_trunc-vis3.c
> index 45646c5d66..321a9eded6 100644
> --- a/sysdeps/sparc/sparc64/fpu/multiarch/s_trunc-vis3.c
> +++ b/sysdeps/sparc/sparc64/fpu/multiarch/s_trunc-vis3.c
> @@ -20,4 +20,4 @@
>  
>  #define __trunc __trunc_vis3
>  
> -#include <sysdeps/ieee754/dbl-64/wordsize-64/s_trunc.c>
> +#include <sysdeps/ieee754/dbl-64/s_trunc.c>

Ok.

> diff --git a/sysdeps/x86_64/fpu/multiarch/s_trunc-c.c b/sysdeps/x86_64/fpu/multiarch/s_trunc-c.c
> index 6204ae3c77..8aa499fbb8 100644
> --- a/sysdeps/x86_64/fpu/multiarch/s_trunc-c.c
> +++ b/sysdeps/x86_64/fpu/multiarch/s_trunc-c.c
> @@ -1,2 +1,2 @@
>  #define __trunc __trunc_c
> -#include <sysdeps/ieee754/dbl-64/wordsize-64/s_trunc.c>
> +#include <sysdeps/ieee754/dbl-64/s_trunc.c>
>

Ok.
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 06/13] Always use wordsize-64 version of s_round.c.

Adhemerval Zanella-2
In reply to this post by Stefan Liebler-2


On 02/12/2019 11:46, Stefan Liebler wrote:
> This patch replaces s_round.c in sysdeps/dbl-64 with the one in
> sysdeps/dbl-64/wordsize-64 and removes the latter one.

LGTM, thanks.

Reviewed-by: Adhemerval Zanella <[hidden email]>

> ---
>  sysdeps/ieee754/dbl-64/s_round.c             | 39 ++++--------
>  sysdeps/ieee754/dbl-64/wordsize-64/s_round.c | 66 --------------------
>  2 files changed, 12 insertions(+), 93 deletions(-)
>  delete mode 100644 sysdeps/ieee754/dbl-64/wordsize-64/s_round.c
>
> diff --git a/sysdeps/ieee754/dbl-64/s_round.c b/sysdeps/ieee754/dbl-64/s_round.c
> index 1793e575e9..8f4b7cff86 100644
> --- a/sysdeps/ieee754/dbl-64/s_round.c
> +++ b/sysdeps/ieee754/dbl-64/s_round.c
> @@ -22,38 +22,36 @@
>  
>  #include <math_private.h>
>  #include <libm-alias-double.h>
> +#include <stdint.h>
>  
>  
>  double
>  __round (double x)
>  {
> -  int32_t i0, j0;
> -  uint32_t i1;
> +  int64_t i0, j0;
>  
> -  EXTRACT_WORDS (i0, i1, x);
> -  j0 = ((i0 >> 20) & 0x7ff) - 0x3ff;
> -  if (j0 < 20)
> +  EXTRACT_WORDS64 (i0, x);
> +  j0 = ((i0 >> 52) & 0x7ff) - 0x3ff;
> +  if (__glibc_likely (j0 < 52))
>      {
>        if (j0 < 0)
>   {
> -  i0 &= 0x80000000;
> +  i0 &= UINT64_C (0x8000000000000000);
>    if (j0 == -1)
> -    i0 |= 0x3ff00000;
> -  i1 = 0;
> +    i0 |= UINT64_C (0x3ff0000000000000);
>   }
>        else
>   {
> -  uint32_t i = 0x000fffff >> j0;
> -  if (((i0 & i) | i1) == 0)
> +  uint64_t i = UINT64_C (0x000fffffffffffff) >> j0;
> +  if ((i0 & i) == 0)
>      /* X is integral.  */
>      return x;
>  
> -  i0 += 0x00080000 >> j0;
> +  i0 += UINT64_C (0x0008000000000000) >> j0;
>    i0 &= ~i;
> -  i1 = 0;
>   }
>      }
> -  else if (j0 > 51)
> +  else
>      {
>        if (j0 == 0x400)
>   /* Inf or NaN.  */
> @@ -61,21 +59,8 @@ __round (double x)
>        else
>   return x;
>      }
> -  else
> -    {
> -      uint32_t i = 0xffffffff >> (j0 - 20);
> -      if ((i1 & i) == 0)
> - /* X is integral.  */
> - return x;
> -
> -      uint32_t j = i1 + (1 << (51 - j0));
> -      if (j < i1)
> - i0 += 1;
> -      i1 = j;
> -      i1 &= ~i;
> -    }
>  
> -  INSERT_WORDS (x, i0, i1);
> +  INSERT_WORDS64 (x, i0);
>    return x;
>  }
>  libm_alias_double (__round, round)

Ok.

> diff --git a/sysdeps/ieee754/dbl-64/wordsize-64/s_round.c b/sysdeps/ieee754/dbl-64/wordsize-64/s_round.c
> deleted file mode 100644
> index 1c3fc7f50e..0000000000
> --- a/sysdeps/ieee754/dbl-64/wordsize-64/s_round.c
> +++ /dev/null
> @@ -1,66 +0,0 @@
> -/* Round double to integer away from zero.
> -   Copyright (C) 1997-2019 Free Software Foundation, Inc.
> -   This file is part of the GNU C Library.
> -   Contributed by Ulrich Drepper <[hidden email]>, 1997.
> -
> -   The GNU C Library is free software; you can redistribute it and/or
> -   modify it under the terms of the GNU Lesser General Public
> -   License as published by the Free Software Foundation; either
> -   version 2.1 of the License, or (at your option) any later version.
> -
> -   The GNU C Library is distributed in the hope that it will be useful,
> -   but WITHOUT ANY WARRANTY; without even the implied warranty of
> -   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> -   Lesser General Public License for more details.
> -
> -   You should have received a copy of the GNU Lesser General Public
> -   License along with the GNU C Library; if not, see
> -   <https://www.gnu.org/licenses/>.  */
> -
> -#define NO_MATH_REDIRECT
> -#include <math.h>
> -
> -#include <math_private.h>
> -#include <libm-alias-double.h>
> -#include <stdint.h>
> -
> -
> -double
> -__round (double x)
> -{
> -  int64_t i0, j0;
> -
> -  EXTRACT_WORDS64 (i0, x);
> -  j0 = ((i0 >> 52) & 0x7ff) - 0x3ff;
> -  if (__glibc_likely (j0 < 52))
> -    {
> -      if (j0 < 0)
> - {
> -  i0 &= UINT64_C(0x8000000000000000);
> -  if (j0 == -1)
> -    i0 |= UINT64_C(0x3ff0000000000000);
> - }
> -      else
> - {
> -  uint64_t i = UINT64_C(0x000fffffffffffff) >> j0;
> -  if ((i0 & i) == 0)
> -    /* X is integral.  */
> -    return x;
> -
> -  i0 += UINT64_C(0x0008000000000000) >> j0;
> -  i0 &= ~i;
> - }
> -    }
> -  else
> -    {
> -      if (j0 == 0x400)
> - /* Inf or NaN.  */
> - return x + x;
> -      else
> - return x;
> -    }
> -
> -  INSERT_WORDS64 (x, i0);
> -  return x;
> -}
> -libm_alias_double (__round, round)
>

Ok.
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 07/13] Use GCC builtins for nearbyint functions if desired.

Adhemerval Zanella-2
In reply to this post by Stefan Liebler-2


On 02/12/2019 11:46, Stefan Liebler wrote:
> This patch is using the corresponding GCC builtin for nearbyintf, nearbyint,
> nearbintl and nearbyintf128 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 <[hidden email]>

> ---
>  sysdeps/generic/math-use-builtins.h         | 29 ++++++++
>  sysdeps/ieee754/dbl-64/s_nearbyint.c        |  8 +++
>  sysdeps/ieee754/float128/float128_private.h |  4 ++
>  sysdeps/ieee754/flt-32/s_nearbyintf.c       | 74 ++++++++++++--------
>  sysdeps/ieee754/ldbl-128/s_nearbyintl.c     | 76 ++++++++++++---------
>  sysdeps/s390/fpu/math-use-builtins.h        | 45 ++++++++++++
>  6 files changed, 175 insertions(+), 61 deletions(-)
>  create mode 100644 sysdeps/generic/math-use-builtins.h
>  create mode 100644 sysdeps/s390/fpu/math-use-builtins.h
>
> diff --git a/sysdeps/generic/math-use-builtins.h b/sysdeps/generic/math-use-builtins.h
> new file mode 100644
> index 0000000000..e12490ed41
> --- /dev/null
> +++ b/sysdeps/generic/math-use-builtins.h
> @@ -0,0 +1,29 @@
> +/* Using math gcc builtins instead of generic implementation.  Generic version.
> +   Copyright (C) 2019 Free Software Foundation, Inc.
> +   This file is part of the GNU C Library.
> +
> +   The GNU C Library is free software; you can redistribute it and/or
> +   modify it under the terms of the GNU Lesser General Public
> +   License as published by the Free Software Foundation; either
> +   version 2.1 of the License, or (at your option) any later version.
> +
> +   The GNU C Library is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> +   Lesser General Public License for more details.
> +
> +   You should have received a copy of the GNU Lesser General Public
> +   License along with the GNU C Library; if not, see
> +   <https://www.gnu.org/licenses/>.  */
> +
> +#ifndef MATH_USE_BUILTINS_H
> +#define MATH_USE_BUILTINS_H 1
> +
> +/* Define these macros to 1 to use __builtin_xyz instead of the
> +   generic implementation.  */
> +#define USE_NEARBYINT_BUILTIN 0
> +#define USE_NEARBYINTF_BUILTIN 0
> +#define USE_NEARBYINTL_BUILTIN 0
> +#define USE_NEARBYINTF128_BUILTIN 0
> +
> +#endif /* math-use-builtins.h */

Ok.

> diff --git a/sysdeps/ieee754/dbl-64/s_nearbyint.c b/sysdeps/ieee754/dbl-64/s_nearbyint.c
> index c261885c5a..08a148e21e 100644
> --- a/sysdeps/ieee754/dbl-64/s_nearbyint.c
> +++ b/sysdeps/ieee754/dbl-64/s_nearbyint.c
> @@ -26,16 +26,23 @@
>  #include <math_private.h>
>  #include <fenv_private.h>
>  #include <libm-alias-double.h>
> +#include <math-use-builtins.h>
>  
> +#if ! USE_NEARBYINT_BUILTIN
>  static const double
>  TWO52[2] = {
>      4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
>      -4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */
>  };
> +#endif

You could just move it inside the !USE_NEARBYINT_BUILTIN within the
function.

>  
>  double
>  __nearbyint (double x)
>  {
> +#if USE_NEARBYINT_BUILTIN
> +  return __builtin_nearbyint (x);
> +#else
> +  /* Use generic implementation.  */
>    fenv_t env;
>    int64_t i0, sx;
>    int32_t j0;
> @@ -67,5 +74,6 @@ __nearbyint (double x)
>    math_force_eval (t);
>    libc_fesetenv (&env);
>    return t;
> +#endif /* USE_NEARBYINT_BUILTIN  */
>  }
>  libm_alias_double (__nearbyint, nearbyint)

Ok.

> diff --git a/sysdeps/ieee754/float128/float128_private.h b/sysdeps/ieee754/float128/float128_private.h
> index 4e31ef365b..e96986a968 100644
> --- a/sysdeps/ieee754/float128/float128_private.h
> +++ b/sysdeps/ieee754/float128/float128_private.h
> @@ -139,6 +139,9 @@
>  #undef libm_alias_double_ldouble
>  #define libm_alias_double_ldouble(func) libm_alias_float64_float128 (func)
>  
> +#include <math-use-builtins.h>
> +#undef USE_NEARBYINTL_BUILTIN
> +#define USE_NEARBYINTL_BUILTIN USE_NEARBYINTF128_BUILTIN

Ok.

>  
>  /* IEEE function renames.  */
>  #define __ieee754_acoshl __ieee754_acoshf128
> @@ -342,6 +345,7 @@
>  /* Builtin renames.  */
>  #define __builtin_copysignl __builtin_copysignf128
>  #define __builtin_signbitl __builtin_signbit
> +#define __builtin_nearbyintl __builtin_nearbyintf128
>  
>  /* Get the constant suffix from bits/floatn-compat.h.  */
>  #define L(x) __f128 (x)

Ok.

> diff --git a/sysdeps/ieee754/flt-32/s_nearbyintf.c b/sysdeps/ieee754/flt-32/s_nearbyintf.c
> index acedf34c90..d31bbdd19a 100644
> --- a/sysdeps/ieee754/flt-32/s_nearbyintf.c
> +++ b/sysdeps/ieee754/flt-32/s_nearbyintf.c
> @@ -21,42 +21,56 @@
>  #include <math_private.h>
>  #include <fenv_private.h>
>  #include <libm-alias-float.h>
> +#include <math-use-builtins.h>
>  
> +#if ! USE_NEARBYINTF_BUILTIN
>  static const float
> -TWO23[2]={
> -  8.3886080000e+06, /* 0x4b000000 */
> - -8.3886080000e+06, /* 0xcb000000 */
> +TWO23[2] = {
> +    8.3886080000e+06, /* 0x4b000000 */
> +    -8.3886080000e+06, /* 0xcb000000 */
>  };
> +#endif

You could just move it inside the !USE_NEARBYINT_BUILTIN within the
function.

>  
>  float
> -__nearbyintf(float x)
> +__nearbyintf (float x)
>  {
> - fenv_t env;
> - int32_t i0,j0,sx;
> - float w,t;
> - GET_FLOAT_WORD(i0,x);
> - sx = (i0>>31)&1;
> - j0 = ((i0>>23)&0xff)-0x7f;
> - if(j0<23) {
> -    if(j0<0) {
> - libc_feholdexceptf (&env);
> - w = TWO23[sx] + math_opt_barrier (x);
> - t =  w-TWO23[sx];
> - math_force_eval (t);
> - libc_fesetenvf (&env);
> - GET_FLOAT_WORD(i0,t);
> - SET_FLOAT_WORD(t,(i0&0x7fffffff)|(sx<<31));
> - return t;
> -    }
> - } else {
> -    if(__builtin_expect(j0==0x80, 0)) return x+x; /* inf or NaN */
> -    else return x; /* x is integral */
> +#if USE_NEARBYINTF_BUILTIN
> +  return __builtin_nearbyintf (x);
> +#else
> +  /* Use generic implementation.  */
> +  fenv_t env;
> +  int32_t i0, j0, sx;
> +  float w, t;
> +  GET_FLOAT_WORD (i0, x);
> +  sx = (i0 >> 31) & 1;
> +  j0 = ((i0 >> 23) & 0xff) - 0x7f;
> +  if (j0 < 23)
> +    {
> +      if (j0 < 0)
> + {
> +  libc_feholdexceptf (&env);
> +  w = TWO23[sx] + math_opt_barrier (x);
> +  t =  w - TWO23[sx];
> +  math_force_eval (t);
> +  libc_fesetenvf (&env);
> +  GET_FLOAT_WORD (i0, t);
> +  SET_FLOAT_WORD (t, (i0 & 0x7fffffff) | (sx << 31));
> +  return t;
>   }
> - libc_feholdexceptf (&env);
> - w = TWO23[sx] + math_opt_barrier (x);
> - t = w-TWO23[sx];
> - math_force_eval (t);
> - libc_fesetenvf (&env);
> - return t;
> +    }
> +  else
> +    {
> +      if (__glibc_unlikely (j0 == 0x80))
> + return x + x; /* inf or NaN  */
> +      else
> + return x; /* x is integral  */
> +  }
> +  libc_feholdexceptf (&env);
> +  w = TWO23[sx] + math_opt_barrier (x);
> +  t = w - TWO23[sx];
> +  math_force_eval (t);
> +  libc_fesetenvf (&env);
> +  return t;
> +#endif /* USE_NEARBYINT_BUILTIN  */
>  }
>  libm_alias_float (__nearbyint, nearbyint)

Ok, but fix the indentation in a separted patch.

> diff --git a/sysdeps/ieee754/ldbl-128/s_nearbyintl.c b/sysdeps/ieee754/ldbl-128/s_nearbyintl.c
> index f044cb4334..8f3a7e8e6b 100644
> --- a/sysdeps/ieee754/ldbl-128/s_nearbyintl.c
> +++ b/sysdeps/ieee754/ldbl-128/s_nearbyintl.c
> @@ -28,42 +28,56 @@
>  #include <math-barriers.h>
>  #include <math_private.h>
>  #include <libm-alias-ldouble.h>
> +#include <math-use-builtins.h>
>  
> +#if ! USE_NEARBYINTL_BUILTIN
>  static const _Float128
> -TWO112[2]={
> -  L(5.19229685853482762853049632922009600E+33), /* 0x406F000000000000, 0 */
> - L(-5.19229685853482762853049632922009600E+33)  /* 0xC06F000000000000, 0 */
> +TWO112[2] = {
> +     L(5.19229685853482762853049632922009600E+33), /* 0x406F000000000000, 0 */
> +     L(-5.19229685853482762853049632922009600E+33)  /* 0xC06F000000000000, 0 */
>  };
> +#endif

You could just move it inside the !USE_NEARBYINT_BUILTIN within the
function.

>  
> -_Float128 __nearbyintl(_Float128 x)
> +_Float128 __nearbyintl (_Float128 x)
>  {
> - fenv_t env;
> - int64_t i0,j0,sx;
> - uint64_t i1 __attribute__ ((unused));
> - _Float128 w,t;
> - GET_LDOUBLE_WORDS64(i0,i1,x);
> - sx = (((uint64_t)i0)>>63);
> - j0 = ((i0>>48)&0x7fff)-0x3fff;
> - if(j0<112) {
> -    if(j0<0) {
> - feholdexcept (&env);
> -        w = TWO112[sx] + math_opt_barrier (x);
> -        t = w-TWO112[sx];
> - math_force_eval (t);
> -        fesetenv (&env);
> - GET_LDOUBLE_MSW64(i0,t);
> - SET_LDOUBLE_MSW64(t,(i0&0x7fffffffffffffffLL)|(sx<<63));
> -        return t;
> -    }
> - } else {
> -    if(j0==0x4000) return x+x; /* inf or NaN */
> -    else return x; /* x is integral */
> +#if USE_NEARBYINTL_BUILTIN
> +  return __builtin_nearbyintl (x);
> +#else
> +  /* Use generic implementation.  */
> +  fenv_t env;
> +  int64_t i0, j0, sx;
> +  uint64_t i1 __attribute__ ((unused));
> +  _Float128 w, t;
> +  GET_LDOUBLE_WORDS64 (i0, i1, x);
> +  sx = (((uint64_t) i0) >> 63);
> +  j0 = ((i0 >> 48) & 0x7fff) - 0x3fff;
> +  if (j0 < 112)
> +    {
> +      if (j0 < 0)
> + {
> +  feholdexcept (&env);
> +  w = TWO112[sx] + math_opt_barrier (x);
> +  t = w - TWO112[sx];
> +  math_force_eval (t);
> +  fesetenv (&env);
> +  GET_LDOUBLE_MSW64 (i0, t);
> +  SET_LDOUBLE_MSW64 (t, (i0 & 0x7fffffffffffffffLL) | (sx << 63));
> +  return t;
>   }
> - feholdexcept (&env);
> - w = TWO112[sx] + math_opt_barrier (x);
> - t = w-TWO112[sx];
> - math_force_eval (t);
> - fesetenv (&env);
> - return t;
> +    }
> +  else
> +    {
> +      if (j0 == 0x4000)
> + return x + x; /* inf or NaN  */
> +      else
> + return x; /* x is integral  */
> +    }
> +  feholdexcept (&env);
> +  w = TWO112[sx] + math_opt_barrier (x);
> +  t = w - TWO112[sx];
> +  math_force_eval (t);
> +  fesetenv (&env);
> +  return t;
> +#endif /* USE_NEARBYINTL_BUILTIN  */
>  }
>  libm_alias_ldouble (__nearbyint, nearbyint)

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
> new file mode 100644
> index 0000000000..fd9da8893e
> --- /dev/null
> +++ b/sysdeps/s390/fpu/math-use-builtins.h
> @@ -0,0 +1,45 @@
> +/* Using math gcc builtins instead of generic implementation.  s390/s390x version.
> +   Copyright (C) 2019 Free Software Foundation, Inc.
> +   This file is part of the GNU C Library.
> +
> +   The GNU C Library is free software; you can redistribute it and/or
> +   modify it under the terms of the GNU Lesser General Public
> +   License as published by the Free Software Foundation; either
> +   version 2.1 of the License, or (at your option) any later version.
> +
> +   The GNU C Library is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> +   Lesser General Public License for more details.
> +
> +   You should have received a copy of the GNU Lesser General Public
> +   License along with the GNU C Library; if not, see
> +   <https://www.gnu.org/licenses/>.  */
> +
> +#ifndef MATH_USE_BUILTINS_S390_H
> +#define MATH_USE_BUILTINS_S390_H 1
> +
> +#ifdef HAVE_S390_MIN_Z196_ZARCH_ASM_SUPPORT
> +
> +# include <features.h> /* For __GNUC_PREREQ.  */
> +
> +/* GCC emits the z196 zarch "load fp integer" instructions for these
> +   builtins if build with at least --march=z196 -mzarch.  Otherwise a
> +   function call to libc is emitted.  */
> +# define USE_NEARBYINT_BUILTIN 1
> +# define USE_NEARBYINTF_BUILTIN 1
> +# define USE_NEARBYINTL_BUILTIN 1
> +
> +# if __GNUC_PREREQ (8, 1)
> +#  define USE_NEARBYINTF128_BUILTIN 1
> +# else
> +#  define USE_NEARBYINTF128_BUILTIN 0
> +# endif
> +
> +#else
> +
> +# include_next <math-use-builtins.h>
> +
> +#endif
> +
> +#endif /* math-use-builtins.h */
>

Ok, but since the idea is to just override it by the architecture I think
it should be more clear to just replicate the expected USE_NEARBYINT*
values for !HAVE_S390_MIN_Z196_ZARCH_ASM_SUPPORT.
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 08/13] Use GCC builtins for rint functions if desired.

Adhemerval Zanella-2
In reply to this post by Stefan Liebler-2


On 02/12/2019 11:46, Stefan Liebler wrote:
> This patch is using the corresponding GCC builtin for rintf, rint,
> rintl and rintf128 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 <[hidden email]>

> ---
>  sysdeps/generic/math-use-builtins.h         |  5 ++
>  sysdeps/ieee754/dbl-64/s_rint.c             | 11 +++-
>  sysdeps/ieee754/float128/float128_private.h |  3 +
>  sysdeps/ieee754/flt-32/s_rintf.c            | 57 ++++++++++++-------
>  sysdeps/ieee754/ldbl-128/s_rintl.c          | 63 +++++++++++++--------
>  sysdeps/s390/fpu/math-use-builtins.h        |  6 ++
>  6 files changed, 97 insertions(+), 48 deletions(-)
>
> diff --git a/sysdeps/generic/math-use-builtins.h b/sysdeps/generic/math-use-builtins.h
> index e12490ed41..64b4a4bb5b 100644
> --- a/sysdeps/generic/math-use-builtins.h
> +++ b/sysdeps/generic/math-use-builtins.h
> @@ -26,4 +26,9 @@
>  #define USE_NEARBYINTL_BUILTIN 0
>  #define USE_NEARBYINTF128_BUILTIN 0
>  
> +#define USE_RINT_BUILTIN 0
> +#define USE_RINTF_BUILTIN 0
> +#define USE_RINTL_BUILTIN 0
> +#define USE_RINTF128_BUILTIN 0
> +
>  #endif /* math-use-builtins.h */
> diff --git a/sysdeps/ieee754/dbl-64/s_rint.c b/sysdeps/ieee754/dbl-64/s_rint.c
> index f96078c405..b09ed8fc06 100644
> --- a/sysdeps/ieee754/dbl-64/s_rint.c
> +++ b/sysdeps/ieee754/dbl-64/s_rint.c
> @@ -23,16 +23,22 @@
>  #include <math.h>
>  #include <math_private.h>
>  #include <libm-alias-double.h>
> +#include <math-use-builtins.h>
>  
> +#if ! USE_RINT_BUILTIN
>  static const double
>  TWO52[2] = {
>      4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
>      -4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */
>  };
> +#endif

You could just move it inside the !USE_NEARBYINT_BUILTIN within the
function.

>  
>  double
>  __rint (double x)
>  {
> +#if USE_RINT_BUILTIN
> +  return __builtin_rint (x);
> +#else
>    int64_t i0, sx;
>    int32_t j0;
>    EXTRACT_WORDS64 (i0, x);
> @@ -47,7 +53,7 @@ __rint (double x)
>    EXTRACT_WORDS64 (i0, t);
>    INSERT_WORDS64 (t, (i0 & UINT64_C (0x7fffffffffffffff))
>    | (sx << 63));
> -      return t;
> +  return t;
>   }
>      }
>    else
> @@ -56,9 +62,10 @@ __rint (double x)
>   return x + x; /* inf or NaN  */
>        else
>   return x; /* x is integral  */
> -  }
> +    }
>    double w = TWO52[sx] + x;
>    return w - TWO52[sx];
> +#endif /* USE_RINT_BUILTIN  */
>  }
>  #ifndef __rint
>  libm_alias_double (__rint, rint)

Ok.

> diff --git a/sysdeps/ieee754/float128/float128_private.h b/sysdeps/ieee754/float128/float128_private.h
> index e96986a968..f458e7b85f 100644
> --- a/sysdeps/ieee754/float128/float128_private.h
> +++ b/sysdeps/ieee754/float128/float128_private.h
> @@ -142,6 +142,8 @@
>  #include <math-use-builtins.h>
>  #undef USE_NEARBYINTL_BUILTIN
>  #define USE_NEARBYINTL_BUILTIN USE_NEARBYINTF128_BUILTIN
> +#undef USE_RINTL_BUILTIN
> +#define USE_RINTL_BUILTIN USE_RINTF128_BUILTIN
>  
>  /* IEEE function renames.  */
>  #define __ieee754_acoshl __ieee754_acoshf128
> @@ -346,6 +348,7 @@
>  #define __builtin_copysignl __builtin_copysignf128
>  #define __builtin_signbitl __builtin_signbit
>  #define __builtin_nearbyintl __builtin_nearbyintf128
> +#define __builtin_rintl __builtin_rintf128
>  
>  /* Get the constant suffix from bits/floatn-compat.h.  */
>  #define L(x) __f128 (x)

Ok.

> diff --git a/sysdeps/ieee754/flt-32/s_rintf.c b/sysdeps/ieee754/flt-32/s_rintf.c
> index 0306dc21f4..7dbf991395 100644
> --- a/sysdeps/ieee754/flt-32/s_rintf.c
> +++ b/sysdeps/ieee754/flt-32/s_rintf.c
> @@ -17,35 +17,48 @@
>  #include <math.h>
>  #include <math_private.h>
>  #include <libm-alias-float.h>
> +#include <math-use-builtins.h>
>  
> +#if ! USE_RINTF_BUILTIN
>  static const float
> -TWO23[2]={
> -  8.3886080000e+06, /* 0x4b000000 */
> - -8.3886080000e+06, /* 0xcb000000 */
> +TWO23[2] = {
> +    8.3886080000e+06, /* 0x4b000000 */
> +    -8.3886080000e+06, /* 0xcb000000 */
>  };
> +#endif
>  
>  float
> -__rintf(float x)
> +__rintf (float x)
>  {
> - int32_t i0,j0,sx;
> - float w,t;
> - GET_FLOAT_WORD(i0,x);
> - sx = (i0>>31)&1;
> - j0 = ((i0>>23)&0xff)-0x7f;
> - if(j0<23) {
> -    if(j0<0) {
> - w = TWO23[sx]+x;
> - t =  w-TWO23[sx];
> - GET_FLOAT_WORD(i0,t);
> - SET_FLOAT_WORD(t,(i0&0x7fffffff)|(sx<<31));
> - return t;
> -    }
> - } else {
> -    if(j0==0x80) return x+x; /* inf or NaN */
> -    else return x; /* x is integral */
> +#if USE_RINTF_BUILTIN
> +  return __builtin_rintf (x);
> +#else
> +  int32_t i0, j0, sx;
> +  float w, t;
> +  GET_FLOAT_WORD (i0, x);
> +  sx = (i0 >> 31) & 1;
> +  j0 = ((i0 >> 23) & 0xff) - 0x7f;
> +  if (j0 < 23)
> +    {
> +      if(j0 < 0)
> + {
> +  w = TWO23[sx] + x;
> +  t =  w - TWO23[sx];
> +  GET_FLOAT_WORD (i0, t);
> +  SET_FLOAT_WORD (t, (i0 & 0x7fffffff) | (sx << 31));
> +  return t;
>   }
> - w = TWO23[sx]+x;
> - return w-TWO23[sx];
> +    }
> +  else
> +    {
> +      if (j0 == 0x80)
> + return x + x; /* inf or NaN  */
> +      else
> + return x; /* x is integral  */
> +    }
> +  w = TWO23[sx] + x;
> +  return w - TWO23[sx];
> +#endif /* USE_RINTF_BUILTIN  */
>  }
>  #ifndef __rintf
>  libm_alias_float (__rint, rint)

Ok, but fix the indentation in a separated patch.

> diff --git a/sysdeps/ieee754/ldbl-128/s_rintl.c b/sysdeps/ieee754/ldbl-128/s_rintl.c
> index b6337e1d8a..1c4eba566d 100644
> --- a/sysdeps/ieee754/ldbl-128/s_rintl.c
> +++ b/sysdeps/ieee754/ldbl-128/s_rintl.c
> @@ -13,7 +13,9 @@
>   * ====================================================
>   */
>  
> -#if defined(LIBM_SCCS) && !defined(lint)
> +#include <math-use-builtins.h>
> +
> +#if ! USE_RINTL_BUILTIN && defined (LIBM_SCCS) && ! defined (lint)
>  static char rcsid[] = "$NetBSD: $";
>  #endif
>  
> @@ -32,33 +34,46 @@ static char rcsid[] = "$NetBSD: $";
>  #include <math_private.h>
>  #include <libm-alias-ldouble.h>
>  
> +#if ! USE_RINTL_BUILTIN
>  static const _Float128
> -TWO112[2]={
> -  5.19229685853482762853049632922009600E+33L, /* 0x406F000000000000, 0 */
> - -5.19229685853482762853049632922009600E+33L  /* 0xC06F000000000000, 0 */
> +TWO112[2] = {
> +     5.19229685853482762853049632922009600E+33L, /* 0x406F000000000000, 0 */
> +     -5.19229685853482762853049632922009600E+33L  /* 0xC06F000000000000, 0 */
>  };
> +#endif

You could just move it inside the !USE_NEARBYINT_BUILTIN within the
function.

>  
> -_Float128 __rintl(_Float128 x)
> +_Float128
> +__rintl (_Float128 x)
>  {
> - int64_t i0,j0,sx;
> - uint64_t i1 __attribute__ ((unused));
> - _Float128 w,t;
> - GET_LDOUBLE_WORDS64(i0,i1,x);
> - sx = (((uint64_t)i0)>>63);
> - j0 = ((i0>>48)&0x7fff)-0x3fff;
> - if(j0<112) {
> -    if(j0<0) {
> -        w = TWO112[sx]+x;
> -        t = w-TWO112[sx];
> - GET_LDOUBLE_MSW64(i0,t);
> - SET_LDOUBLE_MSW64(t,(i0&0x7fffffffffffffffLL)|(sx<<63));
> -        return t;
> -    }
> - } else {
> -    if(j0==0x4000) return x+x; /* inf or NaN */
> -    else return x; /* x is integral */
> +#if USE_RINTL_BUILTIN
> +  return __builtin_rintl (x);
> +#else
> +  int64_t i0, j0, sx;
> +  uint64_t i1 __attribute__ ((unused));
> +  _Float128 w, t;
> +  GET_LDOUBLE_WORDS64 (i0, i1, x);
> +  sx = (((uint64_t) i0) >> 63);
> +  j0 = ((i0 >> 48) & 0x7fff) - 0x3fff;
> +  if (j0 < 112)
> +    {
> +      if (j0 < 0)
> + {
> +  w = TWO112[sx] + x;
> +  t = w - TWO112[sx];
> +  GET_LDOUBLE_MSW64 (i0, t);
> +  SET_LDOUBLE_MSW64 (t, (i0 & 0x7fffffffffffffffLL) | (sx << 63));
> +  return t;
>   }
> - w = TWO112[sx]+x;
> - return w-TWO112[sx];
> +    }
> +  else
> +    {
> +      if (j0 == 0x4000)
> + return x + x; /* inf or NaN  */
> +      else
> + return x; /* x is integral  */
> +    }
> +  w = TWO112[sx] + x;
> +  return w - TWO112[sx];
> +#endif /* USE_RINTL_BUILTIN  */
>  }
>  libm_alias_ldouble (__rint, rint)

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 fd9da8893e..15705fa74a 100644
> --- a/sysdeps/s390/fpu/math-use-builtins.h
> +++ b/sysdeps/s390/fpu/math-use-builtins.h
> @@ -30,10 +30,16 @@
>  # define USE_NEARBYINTF_BUILTIN 1
>  # define USE_NEARBYINTL_BUILTIN 1
>  
> +# define USE_RINT_BUILTIN 1
> +# define USE_RINTF_BUILTIN 1
> +# define USE_RINTL_BUILTIN 1
> +
>  # if __GNUC_PREREQ (8, 1)
>  #  define USE_NEARBYINTF128_BUILTIN 1
> +#  define USE_RINTF128_BUILTIN 1
>  # else
>  #  define USE_NEARBYINTF128_BUILTIN 0
> +#  define USE_RINTF128_BUILTIN 0
>  # endif
>  
>  #else
>

Ok.
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 09/13] Use GCC builtins for floor functions if desired.

Adhemerval Zanella-2
In reply to this post by Stefan Liebler-2


On 02/12/2019 11:46, Stefan Liebler wrote:
> This patch is using the corresponding GCC builtin for floorf, floor,
> floorl and floorf128 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 <[hidden email]>

> ---
>  sysdeps/generic/math-use-builtins.h         |  5 ++
>  sysdeps/ieee754/dbl-64/s_floor.c            |  5 ++
>  sysdeps/ieee754/float128/float128_private.h |  3 +
>  sysdeps/ieee754/flt-32/s_floorf.c           | 60 ++++++++-----
>  sysdeps/ieee754/ldbl-128/s_floorl.c         | 97 ++++++++++++++-------
>  sysdeps/s390/fpu/math-use-builtins.h        |  6 ++
>  6 files changed, 121 insertions(+), 55 deletions(-)
>
> diff --git a/sysdeps/generic/math-use-builtins.h b/sysdeps/generic/math-use-builtins.h
> index 64b4a4bb5b..e1c5df62e4 100644
> --- a/sysdeps/generic/math-use-builtins.h
> +++ b/sysdeps/generic/math-use-builtins.h
> @@ -31,4 +31,9 @@
>  #define USE_RINTL_BUILTIN 0
>  #define USE_RINTF128_BUILTIN 0
>  
> +#define USE_FLOOR_BUILTIN 0
> +#define USE_FLOORF_BUILTIN 0
> +#define USE_FLOORL_BUILTIN 0
> +#define USE_FLOORF128_BUILTIN 0
> +
>  #endif /* math-use-builtins.h */

Ok.

> diff --git a/sysdeps/ieee754/dbl-64/s_floor.c b/sysdeps/ieee754/dbl-64/s_floor.c
> index ce0c42bdb6..0ed22795ed 100644
> --- a/sysdeps/ieee754/dbl-64/s_floor.c
> +++ b/sysdeps/ieee754/dbl-64/s_floor.c
> @@ -35,6 +35,7 @@
>  #include <math_private.h>
>  #include <stdint.h>
>  #include <libm-alias-double.h>
> +#include <math-use-builtins.h>
>  
>  /*
>   * floor(x)
> @@ -47,6 +48,9 @@
>  double
>  __floor (double x)
>  {
> +#if USE_FLOOR_BUILTIN
> +  return __builtin_floor (x);
> +#else
>    int64_t i0;
>    EXTRACT_WORDS64 (i0, x);
>    int32_t j0 = ((i0 >> 52) & 0x7ff) - 0x3ff;
> @@ -74,6 +78,7 @@ __floor (double x)
>    else if (j0 == 0x400)
>      return x + x; /* inf or NaN */
>    return x;
> +#endif /* USE_FLOOR_BUILTIN  */
>  }
>  #ifndef __floor
>  libm_alias_double (__floor, floor)

Ok.

> diff --git a/sysdeps/ieee754/float128/float128_private.h b/sysdeps/ieee754/float128/float128_private.h
> index f458e7b85f..8c8a74a12c 100644
> --- a/sysdeps/ieee754/float128/float128_private.h
> +++ b/sysdeps/ieee754/float128/float128_private.h
> @@ -144,6 +144,8 @@
>  #define USE_NEARBYINTL_BUILTIN USE_NEARBYINTF128_BUILTIN
>  #undef USE_RINTL_BUILTIN
>  #define USE_RINTL_BUILTIN USE_RINTF128_BUILTIN
> +#undef USE_FLOORL_BUILTIN
> +#define USE_FLOORL_BUILTIN USE_FLOORF128_BUILTIN
>  
>  /* IEEE function renames.  */
>  #define __ieee754_acoshl __ieee754_acoshf128
> @@ -349,6 +351,7 @@
>  #define __builtin_signbitl __builtin_signbit
>  #define __builtin_nearbyintl __builtin_nearbyintf128
>  #define __builtin_rintl __builtin_rintf128
> +#define __builtin_floorl __builtin_floorf128
>  
>  /* Get the constant suffix from bits/floatn-compat.h.  */
>  #define L(x) __f128 (x)

Ok.

> diff --git a/sysdeps/ieee754/flt-32/s_floorf.c b/sysdeps/ieee754/flt-32/s_floorf.c
> index b34d967f01..39bb570d10 100644
> --- a/sysdeps/ieee754/flt-32/s_floorf.c
> +++ b/sysdeps/ieee754/flt-32/s_floorf.c
> @@ -24,32 +24,48 @@
>  #include <math.h>
>  #include <math_private.h>
>  #include <libm-alias-float.h>
> +#include <math-use-builtins.h>
>  
>  float
> -__floorf(float x)
> +__floorf (float x)
>  {
> - 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=0;}
> - else if((i0&0x7fffffff)!=0)
> -  { i0=0xbf800000;}
> -    } 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 */
> +#if USE_FLOORF_BUILTIN
> +  return __builtin_floorf (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 = 0;
> +  else if ((i0 & 0x7fffffff) != 0)
> +    i0 = 0xbf800000;
>   }
> - SET_FLOAT_WORD(x,i0);
> - return x;
> +      else
> + {
> +  i = (0x007fffff) >> j0;
> +  if ((i0 & i) == 0)
> +    return x; /* x is integral  */
> +  if (i0 < 0)
> +    i0 += (0x00800000) >> j0;
> +  i0 &= (~i);
> + }
> +    }
> +  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_FLOORF_BUILTIN  */
>  }
>  #ifndef __floorf
>  libm_alias_float (__floor, floor)

Ok, but fix the indentation in a separated patch.

> diff --git a/sysdeps/ieee754/ldbl-128/s_floorl.c b/sysdeps/ieee754/ldbl-128/s_floorl.c
> index f340a3fbca..8d20a79fec 100644
> --- a/sysdeps/ieee754/ldbl-128/s_floorl.c
> +++ b/sysdeps/ieee754/ldbl-128/s_floorl.c
> @@ -13,7 +13,9 @@
>   * ====================================================
>   */
>  
> -#if defined(LIBM_SCCS) && !defined(lint)
> +#include <math-use-builtins.h>
> +
> +#if ! USE_FLOORL_BUILTIN && defined (LIBM_SCCS) && ! defined (lint)
>  static char rcsid[] = "$NetBSD: $";
>  #endif
>  
> @@ -29,41 +31,70 @@ static char rcsid[] = "$NetBSD: $";
>  #include <math_private.h>
>  #include <libm-alias-ldouble.h>
>  
> -_Float128 __floorl(_Float128 x)
> +_Float128
> +__floorl (_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=i1=0;}
> - else if(((i0&0x7fffffffffffffffLL)|i1)!=0)
> -    { i0=0xbfff000000000000ULL;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_FLOORL_BUILTIN
> +  return __builtin_floorl (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 = i1 = 0;
> +    }
> +  else if (((i0 & 0x7fffffffffffffffLL) | i1) != 0)
> +    {
> +      i0 = 0xbfff000000000000ULL;
> +      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_FLOORL_BUILTIN  */
>  }
>  libm_alias_ldouble (__floor, floor)

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 15705fa74a..63cc9d7a23 100644
> --- a/sysdeps/s390/fpu/math-use-builtins.h
> +++ b/sysdeps/s390/fpu/math-use-builtins.h
> @@ -34,12 +34,18 @@
>  # define USE_RINTF_BUILTIN 1
>  # define USE_RINTL_BUILTIN 1
>  
> +# define USE_FLOOR_BUILTIN 1
> +# define USE_FLOORF_BUILTIN 1
> +# define USE_FLOORL_BUILTIN 1
> +
>  # if __GNUC_PREREQ (8, 1)
>  #  define USE_NEARBYINTF128_BUILTIN 1
>  #  define USE_RINTF128_BUILTIN 1
> +#  define USE_FLOORF128_BUILTIN 1
>  # else
>  #  define USE_NEARBYINTF128_BUILTIN 0
>  #  define USE_RINTF128_BUILTIN 0
> +#  define USE_FLOORF128_BUILTIN 0
>  # endif
>  
>  #else
>

Ok.
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 10/13] Use GCC builtins for ceil functions if desired.

Adhemerval Zanella-2
In reply to this post by Stefan Liebler-2


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 <[hidden email]>

> ---
>  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.
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 11/13] Use GCC builtins for trunc functions if desired.

Adhemerval Zanella-2
In reply to this post by Stefan Liebler-2


On 02/12/2019 11:46, Stefan Liebler wrote:
> This patch is using the corresponding GCC builtin for truncf, trunc,
> truncl and truncf128 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.

LGTM, thanks.

Reviewed-by: Adhemerval Zanella <[hidden email]>

> ---
>  sysdeps/generic/math-use-builtins.h         | 5 +++++
>  sysdeps/ieee754/dbl-64/s_trunc.c            | 6 +++++-
>  sysdeps/ieee754/float128/float128_private.h | 3 +++
>  sysdeps/ieee754/flt-32/s_truncf.c           | 6 +++++-
>  sysdeps/ieee754/ldbl-128/s_truncl.c         | 6 +++++-
>  sysdeps/s390/fpu/math-use-builtins.h        | 6 ++++++
>  6 files changed, 29 insertions(+), 3 deletions(-)
>
> diff --git a/sysdeps/generic/math-use-builtins.h b/sysdeps/generic/math-use-builtins.h
> index 076ec661b0..ab379f45ba 100644
> --- a/sysdeps/generic/math-use-builtins.h
> +++ b/sysdeps/generic/math-use-builtins.h
> @@ -41,4 +41,9 @@
>  #define USE_CEILL_BUILTIN 0
>  #define USE_CEILF128_BUILTIN 0
>  
> +#define USE_TRUNC_BUILTIN 0
> +#define USE_TRUNCF_BUILTIN 0
> +#define USE_TRUNCL_BUILTIN 0
> +#define USE_TRUNCF128_BUILTIN 0
> +
>  #endif /* math-use-builtins.h */

Ok.

> diff --git a/sysdeps/ieee754/dbl-64/s_trunc.c b/sysdeps/ieee754/dbl-64/s_trunc.c
> index 0de68ce298..6189ba4a31 100644
> --- a/sysdeps/ieee754/dbl-64/s_trunc.c
> +++ b/sysdeps/ieee754/dbl-64/s_trunc.c
> @@ -22,11 +22,14 @@
>  
>  #include <math_private.h>
>  #include <libm-alias-double.h>
> -
> +#include <math-use-builtins.h>
>  
>  double
>  __trunc (double x)
>  {
> +#if USE_TRUNC_BUILTIN
> +  return __builtin_trunc (x);
> +#else
>    int64_t i0, j0;
>    int64_t sx;
>  
> @@ -49,6 +52,7 @@ __trunc (double x)
>      }
>  
>    return x;
> +#endif /* USE_TRUNC_BUILTIN  */
>  }
>  #ifndef __trunc
>  libm_alias_double (__trunc, trunc)

Ok.

> diff --git a/sysdeps/ieee754/float128/float128_private.h b/sysdeps/ieee754/float128/float128_private.h
> index 01881b574a..9cd3a63f11 100644
> --- a/sysdeps/ieee754/float128/float128_private.h
> +++ b/sysdeps/ieee754/float128/float128_private.h
> @@ -148,6 +148,8 @@
>  #define USE_FLOORL_BUILTIN USE_FLOORF128_BUILTIN
>  #undef USE_CEILL_BUILTIN
>  #define USE_CEILL_BUILTIN USE_CEILF128_BUILTIN
> +#undef USE_TRUNCL_BUILTIN
> +#define USE_TRUNCL_BUILTIN USE_TRUNCF128_BUILTIN
>  
>  /* IEEE function renames.  */
>  #define __ieee754_acoshl __ieee754_acoshf128
> @@ -355,6 +357,7 @@
>  #define __builtin_rintl __builtin_rintf128
>  #define __builtin_floorl __builtin_floorf128
>  #define __builtin_ceill __builtin_ceilf128
> +#define __builtin_truncl __builtin_truncf128
>  
>  /* Get the constant suffix from bits/floatn-compat.h.  */
>  #define L(x) __f128 (x)

Ok.

> diff --git a/sysdeps/ieee754/flt-32/s_truncf.c b/sysdeps/ieee754/flt-32/s_truncf.c
> index e587706b5b..de6dc24a3f 100644
> --- a/sysdeps/ieee754/flt-32/s_truncf.c
> +++ b/sysdeps/ieee754/flt-32/s_truncf.c
> @@ -22,11 +22,14 @@
>  
>  #include <math_private.h>
>  #include <libm-alias-float.h>
> -
> +#include <math-use-builtins.h>
>  
>  float
>  __truncf (float x)
>  {
> +#if USE_TRUNCF_BUILTIN
> +  return __builtin_truncf (x);
> +#else
>    int32_t i0, j0;
>    int sx;
>  
> @@ -49,6 +52,7 @@ __truncf (float x)
>      }
>  
>    return x;
> +#endif /* USE_TRUNCF_BUILTIN  */
>  }
>  #ifndef __truncf
>  libm_alias_float (__trunc, trunc)

Ok.

> diff --git a/sysdeps/ieee754/ldbl-128/s_truncl.c b/sysdeps/ieee754/ldbl-128/s_truncl.c
> index de4dd34d59..ca62e2f970 100644
> --- a/sysdeps/ieee754/ldbl-128/s_truncl.c
> +++ b/sysdeps/ieee754/ldbl-128/s_truncl.c
> @@ -23,11 +23,14 @@
>  
>  #include <math_private.h>
>  #include <libm-alias-ldouble.h>
> -
> +#include <math-use-builtins.h>
>  
>  _Float128
>  __truncl (_Float128 x)
>  {
> +#if USE_TRUNCL_BUILTIN
> +  return __builtin_truncl (x);
> +#else
>    int32_t j0;
>    uint64_t i0, i1, sx;
>  
> @@ -54,5 +57,6 @@ __truncl (_Float128 x)
>      }
>  
>    return x;
> +#endif /* USE_TRUNCL_BUILTIN  */
>  }
>  libm_alias_ldouble (__trunc, trunc)

Ok.

> diff --git a/sysdeps/s390/fpu/math-use-builtins.h b/sysdeps/s390/fpu/math-use-builtins.h
> index dc364edaa8..1d88a2c40f 100644
> --- a/sysdeps/s390/fpu/math-use-builtins.h
> +++ b/sysdeps/s390/fpu/math-use-builtins.h
> @@ -42,16 +42,22 @@
>  # define USE_CEILF_BUILTIN 1
>  # define USE_CEILL_BUILTIN 1
>  
> +# define USE_TRUNC_BUILTIN 1
> +# define USE_TRUNCF_BUILTIN 1
> +# define USE_TRUNCL_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
> +#  define USE_TRUNCF128_BUILTIN 1
>  # else
>  #  define USE_NEARBYINTF128_BUILTIN 0
>  #  define USE_RINTF128_BUILTIN 0
>  #  define USE_FLOORF128_BUILTIN 0
>  #  define USE_CEILF128_BUILTIN 0
> +#  define USE_TRUNCF128_BUILTIN 0
>  # endif
>  
>  #else
>

Ok.
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 12/13] Use GCC builtins for round functions if desired.

Adhemerval Zanella-2
In reply to this post by Stefan Liebler-2


On 02/12/2019 11:46, Stefan Liebler wrote:
> This patch is using the corresponding GCC builtin for roundf, round,
> roundl and roundf128 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.

LGTM, thanks.

Reviewed-by: Adhemerval Zanella <[hidden email]>

> ---
>  sysdeps/generic/math-use-builtins.h         | 5 +++++
>  sysdeps/ieee754/dbl-64/s_round.c            | 6 +++++-
>  sysdeps/ieee754/float128/float128_private.h | 3 +++
>  sysdeps/ieee754/flt-32/s_roundf.c           | 6 +++++-
>  sysdeps/ieee754/ldbl-128/s_roundl.c         | 6 +++++-
>  sysdeps/s390/fpu/math-use-builtins.h        | 6 ++++++
>  6 files changed, 29 insertions(+), 3 deletions(-)
>
> diff --git a/sysdeps/generic/math-use-builtins.h b/sysdeps/generic/math-use-builtins.h
> index ab379f45ba..34ca438a8c 100644
> --- a/sysdeps/generic/math-use-builtins.h
> +++ b/sysdeps/generic/math-use-builtins.h
> @@ -46,4 +46,9 @@
>  #define USE_TRUNCL_BUILTIN 0
>  #define USE_TRUNCF128_BUILTIN 0
>  
> +#define USE_ROUND_BUILTIN 0
> +#define USE_ROUNDF_BUILTIN 0
> +#define USE_ROUNDL_BUILTIN 0
> +#define USE_ROUNDF128_BUILTIN 0
> +
>  #endif /* math-use-builtins.h */

Ok.

> diff --git a/sysdeps/ieee754/dbl-64/s_round.c b/sysdeps/ieee754/dbl-64/s_round.c
> index 8f4b7cff86..00c8485efb 100644
> --- a/sysdeps/ieee754/dbl-64/s_round.c
> +++ b/sysdeps/ieee754/dbl-64/s_round.c
> @@ -23,11 +23,14 @@
>  #include <math_private.h>
>  #include <libm-alias-double.h>
>  #include <stdint.h>
> -
> +#include <math-use-builtins.h>
>  
>  double
>  __round (double x)
>  {
> +#if USE_ROUND_BUILTIN
> +  return __builtin_round (x);
> +#else
>    int64_t i0, j0;
>  
>    EXTRACT_WORDS64 (i0, x);
> @@ -62,5 +65,6 @@ __round (double x)
>  
>    INSERT_WORDS64 (x, i0);
>    return x;
> +#endif /* USE_ROUND_BUILTIN  */
>  }
>  libm_alias_double (__round, round)

Ok.

> diff --git a/sysdeps/ieee754/float128/float128_private.h b/sysdeps/ieee754/float128/float128_private.h
> index 9cd3a63f11..a6c76ce364 100644
> --- a/sysdeps/ieee754/float128/float128_private.h
> +++ b/sysdeps/ieee754/float128/float128_private.h
> @@ -150,6 +150,8 @@
>  #define USE_CEILL_BUILTIN USE_CEILF128_BUILTIN
>  #undef USE_TRUNCL_BUILTIN
>  #define USE_TRUNCL_BUILTIN USE_TRUNCF128_BUILTIN
> +#undef USE_ROUNDL_BUILTIN
> +#define USE_ROUNDL_BUILTIN USE_ROUNDF128_BUILTIN
>  
>  /* IEEE function renames.  */
>  #define __ieee754_acoshl __ieee754_acoshf128
> @@ -358,6 +360,7 @@
>  #define __builtin_floorl __builtin_floorf128
>  #define __builtin_ceill __builtin_ceilf128
>  #define __builtin_truncl __builtin_truncf128
> +#define __builtin_roundl __builtin_roundf128
>  
>  /* Get the constant suffix from bits/floatn-compat.h.  */
>  #define L(x) __f128 (x)

Ok.

> diff --git a/sysdeps/ieee754/flt-32/s_roundf.c b/sysdeps/ieee754/flt-32/s_roundf.c
> index cddab7b505..33304b21f1 100644
> --- a/sysdeps/ieee754/flt-32/s_roundf.c
> +++ b/sysdeps/ieee754/flt-32/s_roundf.c
> @@ -22,11 +22,14 @@
>  
>  #include <math_private.h>
>  #include <libm-alias-float.h>
> -
> +#include <math-use-builtins.h>
>  
>  float
>  __roundf (float x)
>  {
> +#if USE_ROUNDF_BUILTIN
> +  return __builtin_roundf (x);
> +#else
>    int32_t i0, j0;
>  
>    GET_FLOAT_WORD (i0, x);
> @@ -61,5 +64,6 @@ __roundf (float x)
>  
>    SET_FLOAT_WORD (x, i0);
>    return x;
> +#endif /* USE_ROUNDF_BUILTIN  */
>  }
>  libm_alias_float (__round, round)

Ok.

> diff --git a/sysdeps/ieee754/ldbl-128/s_roundl.c b/sysdeps/ieee754/ldbl-128/s_roundl.c
> index d41c9a04dc..8d3f42cd42 100644
> --- a/sysdeps/ieee754/ldbl-128/s_roundl.c
> +++ b/sysdeps/ieee754/ldbl-128/s_roundl.c
> @@ -23,11 +23,14 @@
>  
>  #include <math_private.h>
>  #include <libm-alias-ldouble.h>
> -
> +#include <math-use-builtins.h>
>  
>  _Float128
>  __roundl (_Float128 x)
>  {
> +#if USE_ROUNDL_BUILTIN
> +  return __builtin_roundl (x);
> +#else
>    int32_t j0;
>    uint64_t i1, i0;
>  
> @@ -78,5 +81,6 @@ __roundl (_Float128 x)
>  
>    SET_LDOUBLE_WORDS64 (x, i0, i1);
>    return x;
> +#endif /* USE_ROUNDL_BUILTIN  */
>  }
>  libm_alias_ldouble (__round, round)

Ok.

> diff --git a/sysdeps/s390/fpu/math-use-builtins.h b/sysdeps/s390/fpu/math-use-builtins.h
> index 1d88a2c40f..5838a31c50 100644
> --- a/sysdeps/s390/fpu/math-use-builtins.h
> +++ b/sysdeps/s390/fpu/math-use-builtins.h
> @@ -46,18 +46,24 @@
>  # define USE_TRUNCF_BUILTIN 1
>  # define USE_TRUNCL_BUILTIN 1
>  
> +# define USE_ROUND_BUILTIN 1
> +# define USE_ROUNDF_BUILTIN 1
> +# define USE_ROUNDL_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
>  #  define USE_TRUNCF128_BUILTIN 1
> +#  define USE_ROUNDF128_BUILTIN 1
>  # else
>  #  define USE_NEARBYINTF128_BUILTIN 0
>  #  define USE_RINTF128_BUILTIN 0
>  #  define USE_FLOORF128_BUILTIN 0
>  #  define USE_CEILF128_BUILTIN 0
>  #  define USE_TRUNCF128_BUILTIN 0
> +#  define USE_ROUNDF128_BUILTIN 0
>  # endif
>  
>  #else
>

Ok.
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 00/13] Use GCC builtins for some math functions if desired.

Stefan Liebler-2
In reply to this post by Stefan Liebler-2
On 12/2/19 3:46 PM, Stefan Liebler wrote:

> Hi,
>
> this patch-series moves the nearbyint, rint, floor, ceil, trunc and round implementation from sysdeps/ieee754/dbl-64/wordsize-64 to sysdeps/ieee754/dbl-64/ as proposed by Adhemerval:
> ttps://www.sourceware.org/ml/libc-alpha/2019-11/msg00085.html
>
> It also introduces the math-use-builtins.h header with __USE_<SYMBOL>_BUILTIN macros which allows to just use GCC __builtin_<SYMBOL> instead of the current common-code implementation.  There is a float, double, long double and _Float128 version of this macro for each <SYMBOL>.
>
> The generic math-use-builtins.h header is defining all those macros to 0 in order to use the current common-code implenetation.  If an architecture wants to use the builtins, an architecture specific math-use-builtins.h needs to be created (e.g. done for s390) where those macros are defined to 1.
>
> Bye,
> Stefan
>

Hi,

thanks for the review so far.
I've sent a new version v2 with changes due to Adhemervals comments.
See "[PATCH v2 00/18] Use GCC builtins for some math functions if desired."
https://www.sourceware.org/ml/libc-alpha/2019-12/msg00258.html

Can you have a final look, please?

Bye,
Stefan

12