public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2 00/18] Use GCC builtins for some math functions if desired.
@ 2019-12-09 12:46 Stefan Liebler
  2019-12-09 12:47 ` [PATCH v2 02/18] Always use wordsize-64 version of s_rint.c Stefan Liebler
                   ` (18 more replies)
  0 siblings, 19 replies; 33+ messages in thread
From: Stefan Liebler @ 2019-12-09 12:46 UTC (permalink / raw)
  To: libc-alpha; +Cc: Stefan Liebler

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.

Changes compared to first version (see https://www.sourceware.org/ml/libc-alpha/2019-12/msg00029.html) due to review from:
Joseph Myers:
* The copysign builtins are now used unconditionally for float, double and long double.  For _Float128 the macro is defined to 1 if build with GCC >= 7.

Adhemerval Zanella:
* Some static array definitions like TWO52 in s_nearbyint.c are moved inside the !USE_NEARBYINT_BUILTIN within the function.
* The s390 math-use-builtins.h header is now replicating the USE_XYZ* macros for !HAVE_S390_MIN_Z196_ZARCH_ASM_SUPPORT instead of just including the generic header file.
* The changes regarding code style in the "Use GCC builtins for xyz functions if desired" patches are splitted out into the new patches "Adjust s_XYZ.c regarding code style."

Bye,
Stefan

Stefan Liebler (18):
  Always use wordsize-64 version of s_nearbyint.c.
  Always use wordsize-64 version of s_rint.c.
  Always use wordsize-64 version of s_floor.c.
  Always use wordsize-64 version of s_ceil.c.
  Always use wordsize-64 version of s_trunc.c.
  Always use wordsize-64 version of s_round.c.
  Use GCC builtins for nearbyint functions if desired.
  Use GCC builtins for rint functions if desired.
  Use GCC builtins for floor functions if desired.
  Use GCC builtins for ceil functions if desired.
  Use GCC builtins for trunc functions if desired.
  Use GCC builtins for round functions if desired.
  Use GCC builtins for copysign functions if desired.
  Adjust s_nearbyintf.c and s_nearbyintl.c regarding code style.
  Adjust s_rintf.c and s_rintl.c regarding code style.
  Adjust s_floorf.c and s_floorl.c regarding code style.
  Adjust s_ceilf.c and s_ceill.c regarding code style.
  Adjust s_copysignl.c regarding code style.

 sysdeps/generic/math-use-builtins.h           |  63 ++++++++++
 sysdeps/ieee754/dbl-64/s_ceil.c               |  65 ++++------
 sysdeps/ieee754/dbl-64/s_copysign.c           |   9 +-
 sysdeps/ieee754/dbl-64/s_floor.c              |  99 ++++++++--------
 sysdeps/ieee754/dbl-64/s_nearbyint.c          |  49 ++++----
 sysdeps/ieee754/dbl-64/s_rint.c               |  43 ++++---
 sysdeps/ieee754/dbl-64/s_round.c              |  45 +++----
 sysdeps/ieee754/dbl-64/s_trunc.c              |  31 ++---
 sysdeps/ieee754/dbl-64/wordsize-64/s_ceil.c   |  52 --------
 sysdeps/ieee754/dbl-64/wordsize-64/s_floor.c  |  72 ------------
 .../ieee754/dbl-64/wordsize-64/s_nearbyint.c  |  65 ----------
 sysdeps/ieee754/dbl-64/wordsize-64/s_rint.c   |  58 ---------
 sysdeps/ieee754/dbl-64/wordsize-64/s_round.c  |  66 -----------
 sysdeps/ieee754/dbl-64/wordsize-64/s_trunc.c  |  55 ---------
 sysdeps/ieee754/float128/float128_private.h   |  22 ++++
 sysdeps/ieee754/flt-32/s_ceilf.c              |  61 ++++++----
 sysdeps/ieee754/flt-32/s_copysignf.c          |  12 +-
 sysdeps/ieee754/flt-32/s_floorf.c             |  61 ++++++----
 sysdeps/ieee754/flt-32/s_nearbyintf.c         |  77 ++++++------
 sysdeps/ieee754/flt-32/s_rintf.c              |  61 ++++++----
 sysdeps/ieee754/flt-32/s_roundf.c             |   6 +
 sysdeps/ieee754/flt-32/s_truncf.c             |   6 +
 sysdeps/ieee754/ldbl-128/s_ceill.c            |  97 ++++++++++-----
 sysdeps/ieee754/ldbl-128/s_copysignl.c        |  23 ++--
 sysdeps/ieee754/ldbl-128/s_floorl.c           |  95 ++++++++++-----
 sysdeps/ieee754/ldbl-128/s_nearbyintl.c       |  80 +++++++------
 sysdeps/ieee754/ldbl-128/s_rintl.c            |  66 ++++++-----
 sysdeps/ieee754/ldbl-128/s_roundl.c           |   6 +
 sysdeps/ieee754/ldbl-128/s_truncl.c           |   6 +
 sysdeps/s390/fpu/math-use-builtins.h          | 111 ++++++++++++++++++
 .../sparc64/fpu/multiarch/s_ceil-generic.c    |   2 +-
 .../sparc/sparc64/fpu/multiarch/s_ceil-vis3.c |   2 +-
 .../sparc64/fpu/multiarch/s_floor-generic.c   |   2 +-
 .../sparc64/fpu/multiarch/s_floor-vis3.c      |   2 +-
 .../sparc64/fpu/multiarch/s_trunc-generic.c   |   2 +-
 .../sparc64/fpu/multiarch/s_trunc-vis3.c      |   2 +-
 sysdeps/x86_64/fpu/multiarch/s_ceil-c.c       |   2 +-
 sysdeps/x86_64/fpu/multiarch/s_floor-c.c      |   2 +-
 sysdeps/x86_64/fpu/multiarch/s_nearbyint-c.c  |   2 +-
 sysdeps/x86_64/fpu/multiarch/s_rint-c.c       |   2 +-
 sysdeps/x86_64/fpu/multiarch/s_trunc-c.c      |   2 +-
 41 files changed, 778 insertions(+), 806 deletions(-)
 create mode 100644 sysdeps/generic/math-use-builtins.h
 delete mode 100644 sysdeps/ieee754/dbl-64/wordsize-64/s_ceil.c
 delete mode 100644 sysdeps/ieee754/dbl-64/wordsize-64/s_floor.c
 delete mode 100644 sysdeps/ieee754/dbl-64/wordsize-64/s_nearbyint.c
 delete mode 100644 sysdeps/ieee754/dbl-64/wordsize-64/s_rint.c
 delete mode 100644 sysdeps/ieee754/dbl-64/wordsize-64/s_round.c
 delete mode 100644 sysdeps/ieee754/dbl-64/wordsize-64/s_trunc.c
 create mode 100644 sysdeps/s390/fpu/math-use-builtins.h

-- 
2.19.1

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH v2 01/18] Always use wordsize-64 version of s_nearbyint.c.
  2019-12-09 12:46 [PATCH v2 00/18] Use GCC builtins for some math functions if desired Stefan Liebler
  2019-12-09 12:47 ` [PATCH v2 02/18] Always use wordsize-64 version of s_rint.c Stefan Liebler
@ 2019-12-09 12:47 ` Stefan Liebler
  2019-12-09 12:48 ` [PATCH v2 03/18] Always use wordsize-64 version of s_floor.c Stefan Liebler
                   ` (16 subsequent siblings)
  18 siblings, 0 replies; 33+ messages in thread
From: Stefan Liebler @ 2019-12-09 12:47 UTC (permalink / raw)
  To: libc-alpha; +Cc: Stefan Liebler

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.
---
 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;
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 <drepper@cygnus.com>.  */
-/*
- * ====================================================
- * 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)
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>
-- 
2.19.1

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH v2 02/18] Always use wordsize-64 version of s_rint.c.
  2019-12-09 12:46 [PATCH v2 00/18] Use GCC builtins for some math functions if desired Stefan Liebler
@ 2019-12-09 12:47 ` Stefan Liebler
  2019-12-09 12:47 ` [PATCH v2 01/18] Always use wordsize-64 version of s_nearbyint.c Stefan Liebler
                   ` (17 subsequent siblings)
  18 siblings, 0 replies; 33+ messages in thread
From: Stefan Liebler @ 2019-12-09 12:47 UTC (permalink / raw)
  To: libc-alpha; +Cc: Stefan Liebler

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.
---
 sysdeps/ieee754/dbl-64/s_rint.c             | 32 ++++++------
 sysdeps/ieee754/dbl-64/wordsize-64/s_rint.c | 58 ---------------------
 sysdeps/x86_64/fpu/multiarch/s_rint-c.c     |  2 +-
 3 files changed, 17 insertions(+), 75 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..66c9196473 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));
+	  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 */
+	return x;			/* x is integral  */
     }
-  w = TWO52[sx] + x;
+  double w = TWO52[sx] + x;
   return w - TWO52[sx];
 }
 #ifndef __rint
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
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>
-- 
2.19.1

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH v2 04/18] Always use wordsize-64 version of s_ceil.c.
  2019-12-09 12:46 [PATCH v2 00/18] Use GCC builtins for some math functions if desired Stefan Liebler
                   ` (2 preceding siblings ...)
  2019-12-09 12:48 ` [PATCH v2 03/18] Always use wordsize-64 version of s_floor.c Stefan Liebler
@ 2019-12-09 12:48 ` Stefan Liebler
  2019-12-09 12:49 ` [PATCH v2 05/18] Always use wordsize-64 version of s_trunc.c Stefan Liebler
                   ` (14 subsequent siblings)
  18 siblings, 0 replies; 33+ messages in thread
From: Stefan Liebler @ 2019-12-09 12:48 UTC (permalink / raw)
  To: libc-alpha; +Cc: Stefan Liebler

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.
---
 sysdeps/ieee754/dbl-64/s_ceil.c               | 59 ++++++-------------
 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, 21 insertions(+), 96 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..8d66f027e7 100644
--- a/sysdeps/ieee754/dbl-64/s_ceil.c
+++ b/sysdeps/ieee754/dbl-64/s_ceil.c
@@ -25,61 +25,38 @@
 double
 __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
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
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>
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>
-- 
2.19.1

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH v2 03/18] Always use wordsize-64 version of s_floor.c.
  2019-12-09 12:46 [PATCH v2 00/18] Use GCC builtins for some math functions if desired Stefan Liebler
  2019-12-09 12:47 ` [PATCH v2 02/18] Always use wordsize-64 version of s_rint.c Stefan Liebler
  2019-12-09 12:47 ` [PATCH v2 01/18] Always use wordsize-64 version of s_nearbyint.c Stefan Liebler
@ 2019-12-09 12:48 ` Stefan Liebler
  2019-12-09 12:48 ` [PATCH v2 04/18] Always use wordsize-64 version of s_ceil.c Stefan Liebler
                   ` (15 subsequent siblings)
  18 siblings, 0 replies; 33+ messages in thread
From: Stefan Liebler @ 2019-12-09 12:48 UTC (permalink / raw)
  To: libc-alpha; +Cc: Stefan Liebler

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.
---
 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 <drepper@cygnus.com>, 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
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 <drepper@cygnus.com>, 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
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>
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>
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>
-- 
2.19.1

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH v2 05/18] Always use wordsize-64 version of s_trunc.c.
  2019-12-09 12:46 [PATCH v2 00/18] Use GCC builtins for some math functions if desired Stefan Liebler
                   ` (3 preceding siblings ...)
  2019-12-09 12:48 ` [PATCH v2 04/18] Always use wordsize-64 version of s_ceil.c Stefan Liebler
@ 2019-12-09 12:49 ` Stefan Liebler
  2019-12-09 12:49 ` [PATCH v2 07/18] Use GCC builtins for nearbyint functions if desired Stefan Liebler
                   ` (13 subsequent siblings)
  18 siblings, 0 replies; 33+ messages in thread
From: Stefan Liebler @ 2019-12-09 12:49 UTC (permalink / raw)
  To: libc-alpha; +Cc: Stefan Liebler

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.
---
 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;
 }
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 <drepper@cygnus.com>, 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
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>
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>
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>
-- 
2.19.1

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH v2 07/18] Use GCC builtins for nearbyint functions if desired.
  2019-12-09 12:46 [PATCH v2 00/18] Use GCC builtins for some math functions if desired Stefan Liebler
                   ` (4 preceding siblings ...)
  2019-12-09 12:49 ` [PATCH v2 05/18] Always use wordsize-64 version of s_trunc.c Stefan Liebler
@ 2019-12-09 12:49 ` Stefan Liebler
  2019-12-10 19:16   ` Adhemerval Zanella
  2019-12-09 12:49 ` [PATCH v2 06/18] Always use wordsize-64 version of s_round.c Stefan Liebler
                   ` (12 subsequent siblings)
  18 siblings, 1 reply; 33+ messages in thread
From: Stefan Liebler @ 2019-12-09 12:49 UTC (permalink / raw)
  To: libc-alpha; +Cc: Stefan Liebler

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.
---
 sysdeps/generic/math-use-builtins.h         | 29 ++++++++++++
 sysdeps/ieee754/dbl-64/s_nearbyint.c        | 17 ++++---
 sysdeps/ieee754/float128/float128_private.h |  4 ++
 sysdeps/ieee754/flt-32/s_nearbyintf.c       | 17 ++++---
 sysdeps/ieee754/ldbl-128/s_nearbyintl.c     | 17 ++++---
 sysdeps/s390/fpu/math-use-builtins.h        | 49 +++++++++++++++++++++
 6 files changed, 115 insertions(+), 18 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 */
diff --git a/sysdeps/ieee754/dbl-64/s_nearbyint.c b/sysdeps/ieee754/dbl-64/s_nearbyint.c
index c261885c5a..2deaeb2568 100644
--- a/sysdeps/ieee754/dbl-64/s_nearbyint.c
+++ b/sysdeps/ieee754/dbl-64/s_nearbyint.c
@@ -26,16 +26,20 @@
 #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 */
-};
+#include <math-use-builtins.h>
 
 double
 __nearbyint (double x)
 {
+#if USE_NEARBYINT_BUILTIN
+  return __builtin_nearbyint (x);
+#else
+  /* Use generic implementation.  */
+  static const double
+    TWO52[2] = {
+		4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
+		-4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */
+  };
   fenv_t env;
   int64_t i0, sx;
   int32_t j0;
@@ -67,5 +71,6 @@ __nearbyint (double x)
   math_force_eval (t);
   libc_fesetenv (&env);
   return t;
+#endif /* ! USE_NEARBYINT_BUILTIN  */
 }
 libm_alias_double (__nearbyint, nearbyint)
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
 
 /* 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)
diff --git a/sysdeps/ieee754/flt-32/s_nearbyintf.c b/sysdeps/ieee754/flt-32/s_nearbyintf.c
index acedf34c90..b37e003e12 100644
--- a/sysdeps/ieee754/flt-32/s_nearbyintf.c
+++ b/sysdeps/ieee754/flt-32/s_nearbyintf.c
@@ -21,16 +21,20 @@
 #include <math_private.h>
 #include <fenv_private.h>
 #include <libm-alias-float.h>
-
-static const float
-TWO23[2]={
-  8.3886080000e+06, /* 0x4b000000 */
- -8.3886080000e+06, /* 0xcb000000 */
-};
+#include <math-use-builtins.h>
 
 float
 __nearbyintf(float x)
 {
+#if USE_NEARBYINTF_BUILTIN
+  return __builtin_nearbyintf (x);
+#else
+  /* Use generic implementation.  */
+  static const float
+    TWO23[2] = {
+		8.3886080000e+06, /* 0x4b000000 */
+		-8.3886080000e+06, /* 0xcb000000 */
+  };
 	fenv_t env;
 	int32_t i0,j0,sx;
 	float w,t;
@@ -58,5 +62,6 @@ __nearbyintf(float x)
 	math_force_eval (t);
 	libc_fesetenvf (&env);
 	return t;
+#endif /* ! USE_NEARBYINT_BUILTIN  */
 }
 libm_alias_float (__nearbyint, nearbyint)
diff --git a/sysdeps/ieee754/ldbl-128/s_nearbyintl.c b/sysdeps/ieee754/ldbl-128/s_nearbyintl.c
index f044cb4334..a4ad8e82e5 100644
--- a/sysdeps/ieee754/ldbl-128/s_nearbyintl.c
+++ b/sysdeps/ieee754/ldbl-128/s_nearbyintl.c
@@ -28,15 +28,19 @@
 #include <math-barriers.h>
 #include <math_private.h>
 #include <libm-alias-ldouble.h>
-
-static const _Float128
-TWO112[2]={
-  L(5.19229685853482762853049632922009600E+33), /* 0x406F000000000000, 0 */
- L(-5.19229685853482762853049632922009600E+33)  /* 0xC06F000000000000, 0 */
-};
+#include <math-use-builtins.h>
 
 _Float128 __nearbyintl(_Float128 x)
 {
+#if USE_NEARBYINTL_BUILTIN
+  return __builtin_nearbyintl (x);
+#else
+  /* Use generic implementation.  */
+  static const _Float128
+    TWO112[2] = {
+		 L(5.19229685853482762853049632922009600E+33), /* 0x406F000000000000, 0 */
+		 L(-5.19229685853482762853049632922009600E+33)  /* 0xC06F000000000000, 0 */
+  };
 	fenv_t env;
 	int64_t i0,j0,sx;
 	uint64_t i1 __attribute__ ((unused));
@@ -65,5 +69,6 @@ _Float128 __nearbyintl(_Float128 x)
 	math_force_eval (t);
 	fesetenv (&env);
 	return t;
+#endif /* ! USE_NEARBYINTL_BUILTIN  */
 }
 libm_alias_ldouble (__nearbyint, nearbyint)
diff --git a/sysdeps/s390/fpu/math-use-builtins.h b/sysdeps/s390/fpu/math-use-builtins.h
new file mode 100644
index 0000000000..7abbfb3b50
--- /dev/null
+++ b/sysdeps/s390/fpu/math-use-builtins.h
@@ -0,0 +1,49 @@
+/* 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, 0)
+#  define USE_NEARBYINTF128_BUILTIN 1
+# else
+#  define USE_NEARBYINTF128_BUILTIN 0
+# endif
+
+#else
+
+/* Disable the builtins if we do not have the z196 zarch instructions.  */
+# define USE_NEARBYINT_BUILTIN 0
+# define USE_NEARBYINTF_BUILTIN 0
+# define USE_NEARBYINTL_BUILTIN 0
+# define USE_NEARBYINTF128_BUILTIN 0
+
+#endif /* ! HAVE_S390_MIN_Z196_ZARCH_ASM_SUPPORT  */
+
+#endif /* math-use-builtins.h */
-- 
2.19.1

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH v2 06/18] Always use wordsize-64 version of s_round.c.
  2019-12-09 12:46 [PATCH v2 00/18] Use GCC builtins for some math functions if desired Stefan Liebler
                   ` (5 preceding siblings ...)
  2019-12-09 12:49 ` [PATCH v2 07/18] Use GCC builtins for nearbyint functions if desired Stefan Liebler
@ 2019-12-09 12:49 ` Stefan Liebler
  2019-12-09 12:50 ` [PATCH v2 10/18] Use GCC builtins for ceil functions if desired Stefan Liebler
                   ` (11 subsequent siblings)
  18 siblings, 0 replies; 33+ messages in thread
From: Stefan Liebler @ 2019-12-09 12:49 UTC (permalink / raw)
  To: libc-alpha; +Cc: Stefan Liebler

This patch replaces s_round.c in sysdeps/dbl-64 with the one in
sysdeps/dbl-64/wordsize-64 and removes the latter one.
---
 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)
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 <drepper@cygnus.com>, 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)
-- 
2.19.1

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH v2 10/18] Use GCC builtins for ceil functions if desired.
  2019-12-09 12:46 [PATCH v2 00/18] Use GCC builtins for some math functions if desired Stefan Liebler
                   ` (6 preceding siblings ...)
  2019-12-09 12:49 ` [PATCH v2 06/18] Always use wordsize-64 version of s_round.c Stefan Liebler
@ 2019-12-09 12:50 ` Stefan Liebler
  2019-12-10 19:16   ` Adhemerval Zanella
  2019-12-09 12:50 ` [PATCH v2 08/18] Use GCC builtins for rint " Stefan Liebler
                   ` (10 subsequent siblings)
  18 siblings, 1 reply; 33+ messages in thread
From: Stefan Liebler @ 2019-12-09 12:50 UTC (permalink / raw)
  To: libc-alpha; +Cc: Stefan Liebler

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.
---
 sysdeps/generic/math-use-builtins.h         |  5 +++++
 sysdeps/ieee754/dbl-64/s_ceil.c             |  6 ++++++
 sysdeps/ieee754/float128/float128_private.h |  3 +++
 sysdeps/ieee754/flt-32/s_ceilf.c            |  7 ++++++-
 sysdeps/ieee754/ldbl-128/s_ceill.c          |  6 ++++++
 sysdeps/s390/fpu/math-use-builtins.h        | 11 +++++++++++
 6 files changed, 37 insertions(+), 1 deletion(-)

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 */
diff --git a/sysdeps/ieee754/dbl-64/s_ceil.c b/sysdeps/ieee754/dbl-64/s_ceil.c
index 8d66f027e7..3738211360 100644
--- a/sysdeps/ieee754/dbl-64/s_ceil.c
+++ b/sysdeps/ieee754/dbl-64/s_ceil.c
@@ -21,10 +21,15 @@
 #include <math.h>
 #include <math_private.h>
 #include <libm-alias-double.h>
+#include <math-use-builtins.h>
 
 double
 __ceil (double x)
 {
+#if USE_CEIL_BUILTIN
+  return __builtin_ceil (x);
+#else
+  /* Use generic implementation.  */
   int64_t i0, i;
   int32_t j0;
   EXTRACT_WORDS64 (i0, x);
@@ -58,6 +63,7 @@ __ceil (double x)
     }
   INSERT_WORDS64 (x, i0);
   return x;
+#endif /* ! USE_CEIL_BUILTIN  */
 }
 #ifndef __ceil
 libm_alias_double (__ceil, ceil)
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)
diff --git a/sysdeps/ieee754/flt-32/s_ceilf.c b/sysdeps/ieee754/flt-32/s_ceilf.c
index 25cba0807c..7d4990f3ff 100644
--- a/sysdeps/ieee754/flt-32/s_ceilf.c
+++ b/sysdeps/ieee754/flt-32/s_ceilf.c
@@ -17,11 +17,15 @@
 #include <math.h>
 #include <math_private.h>
 #include <libm-alias-float.h>
-
+#include <math-use-builtins.h>
 
 float
 __ceilf(float x)
 {
+#if USE_CEILF_BUILTIN
+  return __builtin_ceilf (x);
+#else
+  /* Use generic implementation.  */
 	int32_t i0,j0;
 	uint32_t i;
 
@@ -44,6 +48,7 @@ __ceilf(float x)
 	}
 	SET_FLOAT_WORD(x,i0);
 	return x;
+#endif /* ! USE_CEILF_BUILTIN  */
 }
 #ifndef __ceilf
 libm_alias_float (__ceil, ceil)
diff --git a/sysdeps/ieee754/ldbl-128/s_ceill.c b/sysdeps/ieee754/ldbl-128/s_ceill.c
index 2ec55de25a..02ffa7af2b 100644
--- a/sysdeps/ieee754/ldbl-128/s_ceill.c
+++ b/sysdeps/ieee754/ldbl-128/s_ceill.c
@@ -28,9 +28,14 @@ static char rcsid[] = "$NetBSD: $";
 #include <math.h>
 #include <math_private.h>
 #include <libm-alias-ldouble.h>
+#include <math-use-builtins.h>
 
 _Float128 __ceill(_Float128 x)
 {
+#if USE_CEILL_BUILTIN
+  return __builtin_ceill (x);
+#else
+  /* Use generic implementation.  */
 	int64_t i0,i1,j0;
 	uint64_t i,j;
 	GET_LDOUBLE_WORDS64(i0,i1,x);
@@ -64,5 +69,6 @@ _Float128 __ceill(_Float128 x)
 	}
 	SET_LDOUBLE_WORDS64(x,i0,i1);
 	return x;
+#endif /* ! USE_CEILL_BUILTIN  */
 }
 libm_alias_ldouble (__ceil, ceil)
diff --git a/sysdeps/s390/fpu/math-use-builtins.h b/sysdeps/s390/fpu/math-use-builtins.h
index c213c16c6f..5435cbb65f 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, 0)
 #  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
@@ -66,6 +72,11 @@
 # 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 /* ! HAVE_S390_MIN_Z196_ZARCH_ASM_SUPPORT  */
 
 #endif /* math-use-builtins.h */
-- 
2.19.1

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH v2 11/18] Use GCC builtins for trunc functions if desired.
  2019-12-09 12:46 [PATCH v2 00/18] Use GCC builtins for some math functions if desired Stefan Liebler
                   ` (9 preceding siblings ...)
  2019-12-09 12:50 ` [PATCH v2 09/18] Use GCC builtins for floor " Stefan Liebler
@ 2019-12-09 12:50 ` Stefan Liebler
  2019-12-10 19:15   ` Adhemerval Zanella
  2019-12-09 12:51 ` [PATCH v2 15/18] Adjust s_rintf.c and s_rintl.c regarding code style Stefan Liebler
                   ` (7 subsequent siblings)
  18 siblings, 1 reply; 33+ messages in thread
From: Stefan Liebler @ 2019-12-09 12:50 UTC (permalink / raw)
  To: libc-alpha; +Cc: Stefan Liebler

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.  The code of the generic
implementation is not changed.
---
 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        | 11 +++++++++++
 6 files changed, 37 insertions(+)

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 */
diff --git a/sysdeps/ieee754/dbl-64/s_trunc.c b/sysdeps/ieee754/dbl-64/s_trunc.c
index 0de68ce298..c3129fea7b 100644
--- a/sysdeps/ieee754/dbl-64/s_trunc.c
+++ b/sysdeps/ieee754/dbl-64/s_trunc.c
@@ -22,11 +22,16 @@
 
 #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
+  /* Use generic implementation.  */
   int64_t i0, j0;
   int64_t sx;
 
@@ -49,6 +54,7 @@ __trunc (double x)
     }
 
   return x;
+#endif /* ! USE_TRUNC_BUILTIN  */
 }
 #ifndef __trunc
 libm_alias_double (__trunc, trunc)
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)
diff --git a/sysdeps/ieee754/flt-32/s_truncf.c b/sysdeps/ieee754/flt-32/s_truncf.c
index e587706b5b..274638820e 100644
--- a/sysdeps/ieee754/flt-32/s_truncf.c
+++ b/sysdeps/ieee754/flt-32/s_truncf.c
@@ -22,11 +22,16 @@
 
 #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
+  /* Use generic implementation.  */
   int32_t i0, j0;
   int sx;
 
@@ -49,6 +54,7 @@ __truncf (float x)
     }
 
   return x;
+#endif /* ! USE_TRUNCF_BUILTIN  */
 }
 #ifndef __truncf
 libm_alias_float (__trunc, trunc)
diff --git a/sysdeps/ieee754/ldbl-128/s_truncl.c b/sysdeps/ieee754/ldbl-128/s_truncl.c
index de4dd34d59..d11ab937e2 100644
--- a/sysdeps/ieee754/ldbl-128/s_truncl.c
+++ b/sysdeps/ieee754/ldbl-128/s_truncl.c
@@ -23,11 +23,16 @@
 
 #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
+  /* Use generic implementation.  */
   int32_t j0;
   uint64_t i0, i1, sx;
 
@@ -54,5 +59,6 @@ __truncl (_Float128 x)
     }
 
   return x;
+#endif /* ! USE_TRUNCL_BUILTIN  */
 }
 libm_alias_ldouble (__trunc, trunc)
diff --git a/sysdeps/s390/fpu/math-use-builtins.h b/sysdeps/s390/fpu/math-use-builtins.h
index 5435cbb65f..a39715c612 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, 0)
 #  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
@@ -77,6 +83,11 @@
 # 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 /* ! HAVE_S390_MIN_Z196_ZARCH_ASM_SUPPORT  */
 
 #endif /* math-use-builtins.h */
-- 
2.19.1

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH v2 09/18] Use GCC builtins for floor functions if desired.
  2019-12-09 12:46 [PATCH v2 00/18] Use GCC builtins for some math functions if desired Stefan Liebler
                   ` (8 preceding siblings ...)
  2019-12-09 12:50 ` [PATCH v2 08/18] Use GCC builtins for rint " Stefan Liebler
@ 2019-12-09 12:50 ` Stefan Liebler
  2019-12-10 19:15   ` Adhemerval Zanella
  2019-12-09 12:50 ` [PATCH v2 11/18] Use GCC builtins for trunc " Stefan Liebler
                   ` (8 subsequent siblings)
  18 siblings, 1 reply; 33+ messages in thread
From: Stefan Liebler @ 2019-12-09 12:50 UTC (permalink / raw)
  To: libc-alpha; +Cc: Stefan Liebler

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.
---
 sysdeps/generic/math-use-builtins.h         |  5 +++++
 sysdeps/ieee754/dbl-64/s_floor.c            |  6 ++++++
 sysdeps/ieee754/float128/float128_private.h |  3 +++
 sysdeps/ieee754/flt-32/s_floorf.c           |  6 ++++++
 sysdeps/ieee754/ldbl-128/s_floorl.c         |  6 ++++++
 sysdeps/s390/fpu/math-use-builtins.h        | 11 +++++++++++
 6 files changed, 37 insertions(+)

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 */
diff --git a/sysdeps/ieee754/dbl-64/s_floor.c b/sysdeps/ieee754/dbl-64/s_floor.c
index ce0c42bdb6..78325214f4 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,10 @@
 double
 __floor (double x)
 {
+#if USE_FLOOR_BUILTIN
+  return __builtin_floor (x);
+#else
+  /* Use generic implementation.  */
   int64_t i0;
   EXTRACT_WORDS64 (i0, x);
   int32_t j0 = ((i0 >> 52) & 0x7ff) - 0x3ff;
@@ -74,6 +79,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)
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)
diff --git a/sysdeps/ieee754/flt-32/s_floorf.c b/sysdeps/ieee754/flt-32/s_floorf.c
index b34d967f01..afe02a1693 100644
--- a/sysdeps/ieee754/flt-32/s_floorf.c
+++ b/sysdeps/ieee754/flt-32/s_floorf.c
@@ -24,10 +24,15 @@
 #include <math.h>
 #include <math_private.h>
 #include <libm-alias-float.h>
+#include <math-use-builtins.h>
 
 float
 __floorf(float x)
 {
+#if USE_FLOORF_BUILTIN
+  return __builtin_floorf (x);
+#else
+  /* Use generic implementation.  */
 	int32_t i0,j0;
 	uint32_t i;
 	GET_FLOAT_WORD(i0,x);
@@ -50,6 +55,7 @@ __floorf(float x)
 	}
 	SET_FLOAT_WORD(x,i0);
 	return x;
+#endif /* ! USE_FLOORF_BUILTIN  */
 }
 #ifndef __floorf
 libm_alias_float (__floor, floor)
diff --git a/sysdeps/ieee754/ldbl-128/s_floorl.c b/sysdeps/ieee754/ldbl-128/s_floorl.c
index f340a3fbca..cfe008392a 100644
--- a/sysdeps/ieee754/ldbl-128/s_floorl.c
+++ b/sysdeps/ieee754/ldbl-128/s_floorl.c
@@ -28,9 +28,14 @@ static char rcsid[] = "$NetBSD: $";
 #include <math.h>
 #include <math_private.h>
 #include <libm-alias-ldouble.h>
+#include <math-use-builtins.h>
 
 _Float128 __floorl(_Float128 x)
 {
+#if USE_FLOORL_BUILTIN
+  return __builtin_floorl (x);
+#else
+  /* Use generic implementation.  */
 	int64_t i0,i1,j0;
 	uint64_t i,j;
 	GET_LDOUBLE_WORDS64(i0,i1,x);
@@ -65,5 +70,6 @@ _Float128 __floorl(_Float128 x)
 	}
 	SET_LDOUBLE_WORDS64(x,i0,i1);
 	return x;
+#endif /* ! USE_FLOORL_BUILTIN  */
 }
 libm_alias_ldouble (__floor, floor)
diff --git a/sysdeps/s390/fpu/math-use-builtins.h b/sysdeps/s390/fpu/math-use-builtins.h
index 8b702a6a90..c213c16c6f 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, 0)
 #  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
@@ -55,6 +61,11 @@
 # 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 /* ! HAVE_S390_MIN_Z196_ZARCH_ASM_SUPPORT  */
 
 #endif /* math-use-builtins.h */
-- 
2.19.1

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH v2 08/18] Use GCC builtins for rint functions if desired.
  2019-12-09 12:46 [PATCH v2 00/18] Use GCC builtins for some math functions if desired Stefan Liebler
                   ` (7 preceding siblings ...)
  2019-12-09 12:50 ` [PATCH v2 10/18] Use GCC builtins for ceil functions if desired Stefan Liebler
@ 2019-12-09 12:50 ` Stefan Liebler
  2019-12-10 19:15   ` Adhemerval Zanella
  2019-12-09 12:50 ` [PATCH v2 09/18] Use GCC builtins for floor " Stefan Liebler
                   ` (9 subsequent siblings)
  18 siblings, 1 reply; 33+ messages in thread
From: Stefan Liebler @ 2019-12-09 12:50 UTC (permalink / raw)
  To: libc-alpha; +Cc: Stefan Liebler

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.
---
 sysdeps/generic/math-use-builtins.h         |  5 +++++
 sysdeps/ieee754/dbl-64/s_rint.c             | 17 +++++++++++------
 sysdeps/ieee754/float128/float128_private.h |  3 +++
 sysdeps/ieee754/flt-32/s_rintf.c            | 17 +++++++++++------
 sysdeps/ieee754/ldbl-128/s_rintl.c          | 17 +++++++++++------
 sysdeps/s390/fpu/math-use-builtins.h        | 11 +++++++++++
 6 files changed, 52 insertions(+), 18 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 66c9196473..8604733ef9 100644
--- a/sysdeps/ieee754/dbl-64/s_rint.c
+++ b/sysdeps/ieee754/dbl-64/s_rint.c
@@ -23,16 +23,20 @@
 #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 */
-};
+#include <math-use-builtins.h>
 
 double
 __rint (double x)
 {
+#if USE_RINT_BUILTIN
+  return __builtin_rint (x);
+#else
+  /* Use generic implementation.  */
+  static const double
+    TWO52[2] = {
+		4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
+		-4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */
+  };
   int64_t i0, sx;
   int32_t j0;
   EXTRACT_WORDS64 (i0, x);
@@ -59,6 +63,7 @@ __rint (double x)
     }
   double w = TWO52[sx] + x;
   return w - TWO52[sx];
+#endif /* ! USE_RINT_BUILTIN  */
 }
 #ifndef __rint
 libm_alias_double (__rint, rint)
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)
diff --git a/sysdeps/ieee754/flt-32/s_rintf.c b/sysdeps/ieee754/flt-32/s_rintf.c
index 0306dc21f4..34c16ea164 100644
--- a/sysdeps/ieee754/flt-32/s_rintf.c
+++ b/sysdeps/ieee754/flt-32/s_rintf.c
@@ -17,16 +17,20 @@
 #include <math.h>
 #include <math_private.h>
 #include <libm-alias-float.h>
-
-static const float
-TWO23[2]={
-  8.3886080000e+06, /* 0x4b000000 */
- -8.3886080000e+06, /* 0xcb000000 */
-};
+#include <math-use-builtins.h>
 
 float
 __rintf(float x)
 {
+#if USE_RINTF_BUILTIN
+  return __builtin_rintf (x);
+#else
+  /* Use generic implementation.  */
+  static const float
+    TWO23[2] = {
+		8.3886080000e+06, /* 0x4b000000 */
+		-8.3886080000e+06, /* 0xcb000000 */
+  };
 	int32_t i0,j0,sx;
 	float w,t;
 	GET_FLOAT_WORD(i0,x);
@@ -46,6 +50,7 @@ __rintf(float x)
 	}
 	w = TWO23[sx]+x;
 	return w-TWO23[sx];
+#endif /* ! USE_RINTF_BUILTIN  */
 }
 #ifndef __rintf
 libm_alias_float (__rint, rint)
diff --git a/sysdeps/ieee754/ldbl-128/s_rintl.c b/sysdeps/ieee754/ldbl-128/s_rintl.c
index b6337e1d8a..3340c35ee1 100644
--- a/sysdeps/ieee754/ldbl-128/s_rintl.c
+++ b/sysdeps/ieee754/ldbl-128/s_rintl.c
@@ -31,15 +31,19 @@ static char rcsid[] = "$NetBSD: $";
 #include <math.h>
 #include <math_private.h>
 #include <libm-alias-ldouble.h>
-
-static const _Float128
-TWO112[2]={
-  5.19229685853482762853049632922009600E+33L, /* 0x406F000000000000, 0 */
- -5.19229685853482762853049632922009600E+33L  /* 0xC06F000000000000, 0 */
-};
+#include <math-use-builtins.h>
 
 _Float128 __rintl(_Float128 x)
 {
+#if USE_RINTL_BUILTIN
+  return __builtin_rintl (x);
+#else
+  /* Use generic implementation.  */
+  static const _Float128
+    TWO112[2] = {
+		 5.19229685853482762853049632922009600E+33L, /* 0x406F000000000000, 0 */
+		 -5.19229685853482762853049632922009600E+33L  /* 0xC06F000000000000, 0 */
+  };
 	int64_t i0,j0,sx;
 	uint64_t i1 __attribute__ ((unused));
 	_Float128 w,t;
@@ -60,5 +64,6 @@ _Float128 __rintl(_Float128 x)
 	}
 	w = TWO112[sx]+x;
 	return w-TWO112[sx];
+#endif /* ! USE_RINTL_BUILTIN  */
 }
 libm_alias_ldouble (__rint, rint)
diff --git a/sysdeps/s390/fpu/math-use-builtins.h b/sysdeps/s390/fpu/math-use-builtins.h
index 7abbfb3b50..8b702a6a90 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, 0)
 #  define USE_NEARBYINTF128_BUILTIN 1
+#  define USE_RINTF128_BUILTIN 1
 # else
 #  define USE_NEARBYINTF128_BUILTIN 0
+#  define USE_RINTF128_BUILTIN 0
 # endif
 
 #else
@@ -44,6 +50,11 @@
 # 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 /* ! HAVE_S390_MIN_Z196_ZARCH_ASM_SUPPORT  */
 
 #endif /* math-use-builtins.h */
-- 
2.19.1

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH v2 13/18] Use GCC builtins for copysign functions if desired.
  2019-12-09 12:46 [PATCH v2 00/18] Use GCC builtins for some math functions if desired Stefan Liebler
                   ` (14 preceding siblings ...)
  2019-12-09 12:51 ` [PATCH v2 12/18] Use GCC builtins for round functions if desired Stefan Liebler
@ 2019-12-09 12:51 ` Stefan Liebler
  2019-12-10 19:16   ` Adhemerval Zanella
  2019-12-09 12:52 ` [PATCH v2 17/18] Adjust s_ceilf.c and s_ceill.c regarding code style Stefan Liebler
                   ` (2 subsequent siblings)
  18 siblings, 1 reply; 33+ messages in thread
From: Stefan Liebler @ 2019-12-09 12:51 UTC (permalink / raw)
  To: libc-alpha; +Cc: Stefan Liebler

This patch is always using the corresponding GCC builtin for copysignf, copysign,
and is using the builtin for copysignl, copysignf128 if the USE_FUNCTION_BUILTIN
macros are defined to one in math-use-builtins.h.

Altough the long double version is enabled by default we still need
the macro and the alternative implementation as the _Float128 version
of the builtin is not available with all supported GCC versions.
---
 sysdeps/generic/math-use-builtins.h         |  9 +++++++++
 sysdeps/ieee754/dbl-64/s_copysign.c         |  9 ++-------
 sysdeps/ieee754/float128/float128_private.h |  3 +++
 sysdeps/ieee754/flt-32/s_copysignf.c        | 12 ++++--------
 sysdeps/ieee754/ldbl-128/s_copysignl.c      |  6 ++++++
 sysdeps/s390/fpu/math-use-builtins.h        |  7 +++++++
 6 files changed, 31 insertions(+), 15 deletions(-)

diff --git a/sysdeps/generic/math-use-builtins.h b/sysdeps/generic/math-use-builtins.h
index 34ca438a8c..770b54ce61 100644
--- a/sysdeps/generic/math-use-builtins.h
+++ b/sysdeps/generic/math-use-builtins.h
@@ -19,6 +19,8 @@
 #ifndef MATH_USE_BUILTINS_H
 #define MATH_USE_BUILTINS_H	1
 
+#include <features.h> /* For __GNUC_PREREQ.  */
+
 /* Define these macros to 1 to use __builtin_xyz instead of the
    generic implementation.  */
 #define USE_NEARBYINT_BUILTIN 0
@@ -51,4 +53,11 @@
 #define USE_ROUNDL_BUILTIN 0
 #define USE_ROUNDF128_BUILTIN 0
 
+#define USE_COPYSIGNL_BUILTIN 1
+#if __GNUC_PREREQ (7, 0)
+# define USE_COPYSIGNF128_BUILTIN 1
+#else
+# define USE_COPYSIGNF128_BUILTIN 0
+#endif
+
 #endif /* math-use-builtins.h */
diff --git a/sysdeps/ieee754/dbl-64/s_copysign.c b/sysdeps/ieee754/dbl-64/s_copysign.c
index 589b088c95..94025b7854 100644
--- a/sysdeps/ieee754/dbl-64/s_copysign.c
+++ b/sysdeps/ieee754/dbl-64/s_copysign.c
@@ -10,7 +10,7 @@
  * ====================================================
  */
 
-#if defined(LIBM_SCCS) && !defined(lint)
+#if defined (LIBM_SCCS) && ! defined (lint)
 static char rcsid[] = "$NetBSD: s_copysign.c,v 1.8 1995/05/10 20:46:57 jtc Exp $";
 #endif
 
@@ -22,16 +22,11 @@ static char rcsid[] = "$NetBSD: s_copysign.c,v 1.8 1995/05/10 20:46:57 jtc Exp $
 
 #define NO_MATH_REDIRECT
 #include <math.h>
-#include <math_private.h>
 #include <libm-alias-double.h>
 
 double
 __copysign (double x, double y)
 {
-  uint32_t hx, hy;
-  GET_HIGH_WORD (hx, x);
-  GET_HIGH_WORD (hy, y);
-  SET_HIGH_WORD (x, (hx & 0x7fffffff) | (hy & 0x80000000));
-  return x;
+  return __builtin_copysign (x, y);
 }
 libm_alias_double (__copysign, copysign)
diff --git a/sysdeps/ieee754/float128/float128_private.h b/sysdeps/ieee754/float128/float128_private.h
index a6c76ce364..7f7f904152 100644
--- a/sysdeps/ieee754/float128/float128_private.h
+++ b/sysdeps/ieee754/float128/float128_private.h
@@ -152,6 +152,8 @@
 #define USE_TRUNCL_BUILTIN USE_TRUNCF128_BUILTIN
 #undef USE_ROUNDL_BUILTIN
 #define USE_ROUNDL_BUILTIN USE_ROUNDF128_BUILTIN
+#undef USE_COPYSIGNL_BUILTIN
+#define USE_COPYSIGNL_BUILTIN USE_COPYSIGNF128_BUILTIN
 
 /* IEEE function renames.  */
 #define __ieee754_acoshl __ieee754_acoshf128
@@ -361,6 +363,7 @@
 #define __builtin_ceill __builtin_ceilf128
 #define __builtin_truncl __builtin_truncf128
 #define __builtin_roundl __builtin_roundf128
+#define __builtin_copysignl __builtin_copysignf128
 
 /* Get the constant suffix from bits/floatn-compat.h.  */
 #define L(x) __f128 (x)
diff --git a/sysdeps/ieee754/flt-32/s_copysignf.c b/sysdeps/ieee754/flt-32/s_copysignf.c
index 77d1d90e92..1c097d313f 100644
--- a/sysdeps/ieee754/flt-32/s_copysignf.c
+++ b/sysdeps/ieee754/flt-32/s_copysignf.c
@@ -13,7 +13,7 @@
  * ====================================================
  */
 
-#if defined(LIBM_SCCS) && !defined(lint)
+#if defined (LIBM_SCCS) && ! defined (lint)
 static char rcsid[] = "$NetBSD: s_copysignf.c,v 1.4 1995/05/10 20:46:59 jtc Exp $";
 #endif
 
@@ -25,15 +25,11 @@ static char rcsid[] = "$NetBSD: s_copysignf.c,v 1.4 1995/05/10 20:46:59 jtc Exp
 
 #define NO_MATH_REDIRECT
 #include <math.h>
-#include <math_private.h>
 #include <libm-alias-float.h>
 
-float __copysignf(float x, float y)
+float
+__copysignf (float x, float y)
 {
-	uint32_t ix,iy;
-	GET_FLOAT_WORD(ix,x);
-	GET_FLOAT_WORD(iy,y);
-	SET_FLOAT_WORD(x,(ix&0x7fffffff)|(iy&0x80000000));
-        return x;
+  return __builtin_copysignf (x, y);
 }
 libm_alias_float (__copysign, copysign)
diff --git a/sysdeps/ieee754/ldbl-128/s_copysignl.c b/sysdeps/ieee754/ldbl-128/s_copysignl.c
index a501139f71..848a184524 100644
--- a/sysdeps/ieee754/ldbl-128/s_copysignl.c
+++ b/sysdeps/ieee754/ldbl-128/s_copysignl.c
@@ -27,14 +27,20 @@ static char rcsid[] = "$NetBSD: $";
 #include <math.h>
 #include <math_private.h>
 #include <libm-alias-ldouble.h>
+#include <math-use-builtins.h>
 
 _Float128 __copysignl(_Float128 x, _Float128 y)
 {
+#if USE_COPYSIGNL_BUILTIN
+  return __builtin_copysignl (x, y);
+#else
+  /* Use generic implementation.  */
 	uint64_t hx,hy;
 	GET_LDOUBLE_MSW64(hx,x);
 	GET_LDOUBLE_MSW64(hy,y);
 	SET_LDOUBLE_MSW64(x,(hx&0x7fffffffffffffffULL)
 			    |(hy&0x8000000000000000ULL));
         return x;
+#endif /* ! USE_COPYSIGNL_BUILTIN  */
 }
 libm_alias_ldouble (__copysign, copysign)
diff --git a/sysdeps/s390/fpu/math-use-builtins.h b/sysdeps/s390/fpu/math-use-builtins.h
index 51cb9f91ab..4c4aad2ab5 100644
--- a/sysdeps/s390/fpu/math-use-builtins.h
+++ b/sysdeps/s390/fpu/math-use-builtins.h
@@ -101,4 +101,11 @@
 
 #endif /* ! HAVE_S390_MIN_Z196_ZARCH_ASM_SUPPORT  */
 
+#define USE_COPYSIGNL_BUILTIN 1
+#if __GNUC_PREREQ (7, 0)
+# define USE_COPYSIGNF128_BUILTIN 1
+#else
+# define USE_COPYSIGNF128_BUILTIN 0
+#endif
+
 #endif /* math-use-builtins.h */
-- 
2.19.1

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH v2 12/18] Use GCC builtins for round functions if desired.
  2019-12-09 12:46 [PATCH v2 00/18] Use GCC builtins for some math functions if desired Stefan Liebler
                   ` (13 preceding siblings ...)
  2019-12-09 12:51 ` [PATCH v2 14/18] Adjust s_nearbyintf.c and s_nearbyintl.c " Stefan Liebler
@ 2019-12-09 12:51 ` Stefan Liebler
  2019-12-10 19:15   ` Adhemerval Zanella
  2019-12-09 12:51 ` [PATCH v2 13/18] Use GCC builtins for copysign " Stefan Liebler
                   ` (3 subsequent siblings)
  18 siblings, 1 reply; 33+ messages in thread
From: Stefan Liebler @ 2019-12-09 12:51 UTC (permalink / raw)
  To: libc-alpha; +Cc: Stefan Liebler

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.  The code of the generic
implementation is not changed.
---
 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        | 11 +++++++++++
 6 files changed, 37 insertions(+)

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 */
diff --git a/sysdeps/ieee754/dbl-64/s_round.c b/sysdeps/ieee754/dbl-64/s_round.c
index 8f4b7cff86..7eb1ecb482 100644
--- a/sysdeps/ieee754/dbl-64/s_round.c
+++ b/sysdeps/ieee754/dbl-64/s_round.c
@@ -23,11 +23,16 @@
 #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
+  /* Use generic implementation.  */
   int64_t i0, j0;
 
   EXTRACT_WORDS64 (i0, x);
@@ -62,5 +67,6 @@ __round (double x)
 
   INSERT_WORDS64 (x, i0);
   return x;
+#endif /* ! USE_ROUND_BUILTIN  */
 }
 libm_alias_double (__round, round)
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)
diff --git a/sysdeps/ieee754/flt-32/s_roundf.c b/sysdeps/ieee754/flt-32/s_roundf.c
index cddab7b505..5d91239d6e 100644
--- a/sysdeps/ieee754/flt-32/s_roundf.c
+++ b/sysdeps/ieee754/flt-32/s_roundf.c
@@ -22,11 +22,16 @@
 
 #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
+  /* Use generic implementation.  */
   int32_t i0, j0;
 
   GET_FLOAT_WORD (i0, x);
@@ -61,5 +66,6 @@ __roundf (float x)
 
   SET_FLOAT_WORD (x, i0);
   return x;
+#endif /* ! USE_ROUNDF_BUILTIN  */
 }
 libm_alias_float (__round, round)
diff --git a/sysdeps/ieee754/ldbl-128/s_roundl.c b/sysdeps/ieee754/ldbl-128/s_roundl.c
index d41c9a04dc..8c7ae82217 100644
--- a/sysdeps/ieee754/ldbl-128/s_roundl.c
+++ b/sysdeps/ieee754/ldbl-128/s_roundl.c
@@ -23,11 +23,16 @@
 
 #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
+  /* Use generic implementation.  */
   int32_t j0;
   uint64_t i1, i0;
 
@@ -78,5 +83,6 @@ __roundl (_Float128 x)
 
   SET_LDOUBLE_WORDS64 (x, i0, i1);
   return x;
+#endif /* ! USE_ROUNDL_BUILTIN  */
 }
 libm_alias_ldouble (__round, round)
diff --git a/sysdeps/s390/fpu/math-use-builtins.h b/sysdeps/s390/fpu/math-use-builtins.h
index a39715c612..51cb9f91ab 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, 0)
 #  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
@@ -88,6 +94,11 @@
 # 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 /* ! HAVE_S390_MIN_Z196_ZARCH_ASM_SUPPORT  */
 
 #endif /* math-use-builtins.h */
-- 
2.19.1

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH v2 16/18] Adjust s_floorf.c and s_floorl.c regarding code style.
  2019-12-09 12:46 [PATCH v2 00/18] Use GCC builtins for some math functions if desired Stefan Liebler
                   ` (11 preceding siblings ...)
  2019-12-09 12:51 ` [PATCH v2 15/18] Adjust s_rintf.c and s_rintl.c regarding code style Stefan Liebler
@ 2019-12-09 12:51 ` Stefan Liebler
  2019-12-10 19:16   ` Adhemerval Zanella
  2019-12-09 12:51 ` [PATCH v2 14/18] Adjust s_nearbyintf.c and s_nearbyintl.c " Stefan Liebler
                   ` (5 subsequent siblings)
  18 siblings, 1 reply; 33+ messages in thread
From: Stefan Liebler @ 2019-12-09 12:51 UTC (permalink / raw)
  To: libc-alpha; +Cc: Stefan Liebler

This patch just adjusts the generic implementation regarding code style.
No functional change.
---
 sysdeps/ieee754/flt-32/s_floorf.c   | 55 +++++++++++-------
 sysdeps/ieee754/ldbl-128/s_floorl.c | 89 ++++++++++++++++++-----------
 2 files changed, 90 insertions(+), 54 deletions(-)

diff --git a/sysdeps/ieee754/flt-32/s_floorf.c b/sysdeps/ieee754/flt-32/s_floorf.c
index afe02a1693..da6c6dfa8a 100644
--- a/sysdeps/ieee754/flt-32/s_floorf.c
+++ b/sysdeps/ieee754/flt-32/s_floorf.c
@@ -27,34 +27,45 @@
 #include <math-use-builtins.h>
 
 float
-__floorf(float x)
+__floorf (float x)
 {
 #if USE_FLOORF_BUILTIN
   return __builtin_floorf (x);
 #else
   /* Use generic implementation.  */
-	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 */
+  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
diff --git a/sysdeps/ieee754/ldbl-128/s_floorl.c b/sysdeps/ieee754/ldbl-128/s_floorl.c
index cfe008392a..0475120d7e 100644
--- a/sysdeps/ieee754/ldbl-128/s_floorl.c
+++ b/sysdeps/ieee754/ldbl-128/s_floorl.c
@@ -30,46 +30,71 @@ static char rcsid[] = "$NetBSD: $";
 #include <libm-alias-ldouble.h>
 #include <math-use-builtins.h>
 
-_Float128 __floorl(_Float128 x)
+_Float128
+__floorl (_Float128 x)
 {
 #if USE_FLOORL_BUILTIN
   return __builtin_floorl (x);
 #else
   /* Use generic implementation.  */
-	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;
+  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 (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 if (((i0 & 0x7fffffffffffffffLL) | i1) != 0)
+	    {
+	      i0 = 0xbfff000000000000ULL;
+	      i1 = 0;
 	    }
-	    i1 &= (~i);
 	}
-	SET_LDOUBLE_WORDS64(x,i0,i1);
-	return x;
+      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;
 #endif /* ! USE_FLOORL_BUILTIN  */
 }
 libm_alias_ldouble (__floor, floor)
-- 
2.19.1

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH v2 14/18] Adjust s_nearbyintf.c and s_nearbyintl.c regarding code style.
  2019-12-09 12:46 [PATCH v2 00/18] Use GCC builtins for some math functions if desired Stefan Liebler
                   ` (12 preceding siblings ...)
  2019-12-09 12:51 ` [PATCH v2 16/18] Adjust s_floorf.c and s_floorl.c " Stefan Liebler
@ 2019-12-09 12:51 ` Stefan Liebler
  2019-12-10 19:16   ` Adhemerval Zanella
  2019-12-09 12:51 ` [PATCH v2 12/18] Use GCC builtins for round functions if desired Stefan Liebler
                   ` (4 subsequent siblings)
  18 siblings, 1 reply; 33+ messages in thread
From: Stefan Liebler @ 2019-12-09 12:51 UTC (permalink / raw)
  To: libc-alpha; +Cc: Stefan Liebler

This patch just adjusts the generic implementation regarding code style.
No functional change.
---
 sysdeps/ieee754/flt-32/s_nearbyintf.c   | 60 ++++++++++++-----------
 sysdeps/ieee754/ldbl-128/s_nearbyintl.c | 63 ++++++++++++++-----------
 2 files changed, 68 insertions(+), 55 deletions(-)

diff --git a/sysdeps/ieee754/flt-32/s_nearbyintf.c b/sysdeps/ieee754/flt-32/s_nearbyintf.c
index b37e003e12..2a79907168 100644
--- a/sysdeps/ieee754/flt-32/s_nearbyintf.c
+++ b/sysdeps/ieee754/flt-32/s_nearbyintf.c
@@ -24,7 +24,7 @@
 #include <math-use-builtins.h>
 
 float
-__nearbyintf(float x)
+__nearbyintf (float x)
 {
 #if USE_NEARBYINTF_BUILTIN
   return __builtin_nearbyintf (x);
@@ -35,33 +35,39 @@ __nearbyintf(float x)
 		8.3886080000e+06, /* 0x4b000000 */
 		-8.3886080000e+06, /* 0xcb000000 */
   };
-	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 */
+  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)
diff --git a/sysdeps/ieee754/ldbl-128/s_nearbyintl.c b/sysdeps/ieee754/ldbl-128/s_nearbyintl.c
index a4ad8e82e5..8d26786f78 100644
--- a/sysdeps/ieee754/ldbl-128/s_nearbyintl.c
+++ b/sysdeps/ieee754/ldbl-128/s_nearbyintl.c
@@ -30,7 +30,8 @@
 #include <libm-alias-ldouble.h>
 #include <math-use-builtins.h>
 
-_Float128 __nearbyintl(_Float128 x)
+_Float128
+__nearbyintl (_Float128 x)
 {
 #if USE_NEARBYINTL_BUILTIN
   return __builtin_nearbyintl (x);
@@ -41,34 +42,40 @@ _Float128 __nearbyintl(_Float128 x)
 		 L(5.19229685853482762853049632922009600E+33), /* 0x406F000000000000, 0 */
 		 L(-5.19229685853482762853049632922009600E+33)  /* 0xC06F000000000000, 0 */
   };
-	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 */
+  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)
-- 
2.19.1

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH v2 15/18] Adjust s_rintf.c and s_rintl.c regarding code style.
  2019-12-09 12:46 [PATCH v2 00/18] Use GCC builtins for some math functions if desired Stefan Liebler
                   ` (10 preceding siblings ...)
  2019-12-09 12:50 ` [PATCH v2 11/18] Use GCC builtins for trunc " Stefan Liebler
@ 2019-12-09 12:51 ` Stefan Liebler
  2019-12-10 19:15   ` Adhemerval Zanella
  2019-12-09 12:51 ` [PATCH v2 16/18] Adjust s_floorf.c and s_floorl.c " Stefan Liebler
                   ` (6 subsequent siblings)
  18 siblings, 1 reply; 33+ messages in thread
From: Stefan Liebler @ 2019-12-09 12:51 UTC (permalink / raw)
  To: libc-alpha; +Cc: Stefan Liebler

This patch just adjusts the generic implementation regarding code style.
No functional change.
---
 sysdeps/ieee754/flt-32/s_rintf.c   | 44 +++++++++++++++------------
 sysdeps/ieee754/ldbl-128/s_rintl.c | 49 +++++++++++++++++-------------
 2 files changed, 53 insertions(+), 40 deletions(-)

diff --git a/sysdeps/ieee754/flt-32/s_rintf.c b/sysdeps/ieee754/flt-32/s_rintf.c
index 34c16ea164..627bada566 100644
--- a/sysdeps/ieee754/flt-32/s_rintf.c
+++ b/sysdeps/ieee754/flt-32/s_rintf.c
@@ -20,7 +20,7 @@
 #include <math-use-builtins.h>
 
 float
-__rintf(float x)
+__rintf (float x)
 {
 #if USE_RINTF_BUILTIN
   return __builtin_rintf (x);
@@ -31,25 +31,31 @@ __rintf(float x)
 		8.3886080000e+06, /* 0x4b000000 */
 		-8.3886080000e+06, /* 0xcb000000 */
   };
-	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 */
+  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
diff --git a/sysdeps/ieee754/ldbl-128/s_rintl.c b/sysdeps/ieee754/ldbl-128/s_rintl.c
index 3340c35ee1..16965f9582 100644
--- a/sysdeps/ieee754/ldbl-128/s_rintl.c
+++ b/sysdeps/ieee754/ldbl-128/s_rintl.c
@@ -13,7 +13,7 @@
  * ====================================================
  */
 
-#if defined(LIBM_SCCS) && !defined(lint)
+#if defined (LIBM_SCCS) && ! defined (lint)
 static char rcsid[] = "$NetBSD: $";
 #endif
 
@@ -33,7 +33,8 @@ static char rcsid[] = "$NetBSD: $";
 #include <libm-alias-ldouble.h>
 #include <math-use-builtins.h>
 
-_Float128 __rintl(_Float128 x)
+_Float128
+__rintl (_Float128 x)
 {
 #if USE_RINTL_BUILTIN
   return __builtin_rintl (x);
@@ -44,26 +45,32 @@ _Float128 __rintl(_Float128 x)
 		 5.19229685853482762853049632922009600E+33L, /* 0x406F000000000000, 0 */
 		 -5.19229685853482762853049632922009600E+33L  /* 0xC06F000000000000, 0 */
   };
-	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 */
+  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)
-- 
2.19.1

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH v2 18/18] Adjust s_copysignl.c regarding code style.
  2019-12-09 12:46 [PATCH v2 00/18] Use GCC builtins for some math functions if desired Stefan Liebler
                   ` (16 preceding siblings ...)
  2019-12-09 12:52 ` [PATCH v2 17/18] Adjust s_ceilf.c and s_ceill.c regarding code style Stefan Liebler
@ 2019-12-09 12:52 ` Stefan Liebler
  2019-12-10 19:16   ` Adhemerval Zanella
  2019-12-10 19:18 ` [PATCH v2 00/18] Use GCC builtins for some math functions if desired Adhemerval Zanella
  18 siblings, 1 reply; 33+ messages in thread
From: Stefan Liebler @ 2019-12-09 12:52 UTC (permalink / raw)
  To: libc-alpha; +Cc: Stefan Liebler

This patch just adjusts the generic implementation regarding code style.
No functional change.
---
 sysdeps/ieee754/ldbl-128/s_copysignl.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/sysdeps/ieee754/ldbl-128/s_copysignl.c b/sysdeps/ieee754/ldbl-128/s_copysignl.c
index 848a184524..a8b0639d2e 100644
--- a/sysdeps/ieee754/ldbl-128/s_copysignl.c
+++ b/sysdeps/ieee754/ldbl-128/s_copysignl.c
@@ -13,7 +13,7 @@
  * ====================================================
  */
 
-#if defined(LIBM_SCCS) && !defined(lint)
+#if defined (LIBM_SCCS) && ! defined (lint)
 static char rcsid[] = "$NetBSD: $";
 #endif
 
@@ -29,18 +29,19 @@ static char rcsid[] = "$NetBSD: $";
 #include <libm-alias-ldouble.h>
 #include <math-use-builtins.h>
 
-_Float128 __copysignl(_Float128 x, _Float128 y)
+_Float128
+__copysignl (_Float128 x, _Float128 y)
 {
 #if USE_COPYSIGNL_BUILTIN
   return __builtin_copysignl (x, y);
 #else
   /* Use generic implementation.  */
-	uint64_t hx,hy;
-	GET_LDOUBLE_MSW64(hx,x);
-	GET_LDOUBLE_MSW64(hy,y);
-	SET_LDOUBLE_MSW64(x,(hx&0x7fffffffffffffffULL)
-			    |(hy&0x8000000000000000ULL));
-        return x;
+  uint64_t hx, hy;
+  GET_LDOUBLE_MSW64 (hx, x);
+  GET_LDOUBLE_MSW64 (hy, y);
+  SET_LDOUBLE_MSW64 (x, (hx & 0x7fffffffffffffffULL)
+		     | (hy & 0x8000000000000000ULL));
+  return x;
 #endif /* ! USE_COPYSIGNL_BUILTIN  */
 }
 libm_alias_ldouble (__copysign, copysign)
-- 
2.19.1

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH v2 17/18] Adjust s_ceilf.c and s_ceill.c regarding code style.
  2019-12-09 12:46 [PATCH v2 00/18] Use GCC builtins for some math functions if desired Stefan Liebler
                   ` (15 preceding siblings ...)
  2019-12-09 12:51 ` [PATCH v2 13/18] Use GCC builtins for copysign " Stefan Liebler
@ 2019-12-09 12:52 ` Stefan Liebler
  2019-12-10 19:15   ` Adhemerval Zanella
  2019-12-09 12:52 ` [PATCH v2 18/18] Adjust s_copysignl.c " Stefan Liebler
  2019-12-10 19:18 ` [PATCH v2 00/18] Use GCC builtins for some math functions if desired Adhemerval Zanella
  18 siblings, 1 reply; 33+ messages in thread
From: Stefan Liebler @ 2019-12-09 12:52 UTC (permalink / raw)
  To: libc-alpha; +Cc: Stefan Liebler

This patch just adjusts the generic implementation regarding code style.
No functional change.
---
 sysdeps/ieee754/flt-32/s_ceilf.c   | 54 +++++++++++-------
 sysdeps/ieee754/ldbl-128/s_ceill.c | 91 +++++++++++++++++++-----------
 2 files changed, 92 insertions(+), 53 deletions(-)

diff --git a/sysdeps/ieee754/flt-32/s_ceilf.c b/sysdeps/ieee754/flt-32/s_ceilf.c
index 7d4990f3ff..5c4abfe145 100644
--- a/sysdeps/ieee754/flt-32/s_ceilf.c
+++ b/sysdeps/ieee754/flt-32/s_ceilf.c
@@ -20,34 +20,46 @@
 #include <math-use-builtins.h>
 
 float
-__ceilf(float x)
+__ceilf (float x)
 {
 #if USE_CEILF_BUILTIN
   return __builtin_ceilf (x);
 #else
   /* Use generic implementation.  */
-	int32_t i0,j0;
-	uint32_t i;
+  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;
 	}
-	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_CEILF_BUILTIN  */
 }
 #ifndef __ceilf
diff --git a/sysdeps/ieee754/ldbl-128/s_ceill.c b/sysdeps/ieee754/ldbl-128/s_ceill.c
index 02ffa7af2b..c5d98e1e37 100644
--- a/sysdeps/ieee754/ldbl-128/s_ceill.c
+++ b/sysdeps/ieee754/ldbl-128/s_ceill.c
@@ -13,7 +13,7 @@
  * ====================================================
  */
 
-#if defined(LIBM_SCCS) && !defined(lint)
+#if defined (LIBM_SCCS) && ! defined (lint)
 static char rcsid[] = "$NetBSD: $";
 #endif
 
@@ -30,45 +30,72 @@ static char rcsid[] = "$NetBSD: $";
 #include <libm-alias-ldouble.h>
 #include <math-use-builtins.h>
 
-_Float128 __ceill(_Float128 x)
+_Float128
+__ceill (_Float128 x)
 {
 #if USE_CEILL_BUILTIN
   return __builtin_ceill (x);
 #else
   /* Use generic implementation.  */
-	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;
+  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 (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 if ((i0 | i1) != 0)
+	    {
+	      i0 = 0x3fff000000000000ULL;
+	      i1 = 0;
 	    }
-	    i1 &= (~i);
 	}
-	SET_LDOUBLE_WORDS64(x,i0,i1);
-	return x;
+      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;
 #endif /* ! USE_CEILL_BUILTIN  */
 }
 libm_alias_ldouble (__ceil, ceil)
-- 
2.19.1

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v2 08/18] Use GCC builtins for rint functions if desired.
  2019-12-09 12:50 ` [PATCH v2 08/18] Use GCC builtins for rint " Stefan Liebler
@ 2019-12-10 19:15   ` Adhemerval Zanella
  0 siblings, 0 replies; 33+ messages in thread
From: Adhemerval Zanella @ 2019-12-10 19:15 UTC (permalink / raw)
  To: libc-alpha



On 09/12/2019 09:45, 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.

LGTM, thanks.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>

> ---
>  sysdeps/generic/math-use-builtins.h         |  5 +++++
>  sysdeps/ieee754/dbl-64/s_rint.c             | 17 +++++++++++------
>  sysdeps/ieee754/float128/float128_private.h |  3 +++
>  sysdeps/ieee754/flt-32/s_rintf.c            | 17 +++++++++++------
>  sysdeps/ieee754/ldbl-128/s_rintl.c          | 17 +++++++++++------
>  sysdeps/s390/fpu/math-use-builtins.h        | 11 +++++++++++
>  6 files changed, 52 insertions(+), 18 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 */

Ok.

> diff --git a/sysdeps/ieee754/dbl-64/s_rint.c b/sysdeps/ieee754/dbl-64/s_rint.c
> index 66c9196473..8604733ef9 100644
> --- a/sysdeps/ieee754/dbl-64/s_rint.c
> +++ b/sysdeps/ieee754/dbl-64/s_rint.c
> @@ -23,16 +23,20 @@
>  #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 */
> -};
> +#include <math-use-builtins.h>
>  
>  double
>  __rint (double x)
>  {
> +#if USE_RINT_BUILTIN
> +  return __builtin_rint (x);
> +#else
> +  /* Use generic implementation.  */
> +  static const double
> +    TWO52[2] = {
> +		4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
> +		-4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */
> +  };
>    int64_t i0, sx;
>    int32_t j0;
>    EXTRACT_WORDS64 (i0, x);
> @@ -59,6 +63,7 @@ __rint (double x)
>      }
>    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..34c16ea164 100644
> --- a/sysdeps/ieee754/flt-32/s_rintf.c
> +++ b/sysdeps/ieee754/flt-32/s_rintf.c
> @@ -17,16 +17,20 @@
>  #include <math.h>
>  #include <math_private.h>
>  #include <libm-alias-float.h>
> -
> -static const float
> -TWO23[2]={
> -  8.3886080000e+06, /* 0x4b000000 */
> - -8.3886080000e+06, /* 0xcb000000 */
> -};
> +#include <math-use-builtins.h>
>  
>  float
>  __rintf(float x)
>  {
> +#if USE_RINTF_BUILTIN
> +  return __builtin_rintf (x);
> +#else
> +  /* Use generic implementation.  */
> +  static const float
> +    TWO23[2] = {
> +		8.3886080000e+06, /* 0x4b000000 */
> +		-8.3886080000e+06, /* 0xcb000000 */
> +  };
>  	int32_t i0,j0,sx;
>  	float w,t;
>  	GET_FLOAT_WORD(i0,x);
> @@ -46,6 +50,7 @@ __rintf(float x)
>  	}
>  	w = TWO23[sx]+x;
>  	return w-TWO23[sx];
> +#endif /* ! USE_RINTF_BUILTIN  */
>  }
>  #ifndef __rintf
>  libm_alias_float (__rint, rint)

Ok.

> diff --git a/sysdeps/ieee754/ldbl-128/s_rintl.c b/sysdeps/ieee754/ldbl-128/s_rintl.c
> index b6337e1d8a..3340c35ee1 100644
> --- a/sysdeps/ieee754/ldbl-128/s_rintl.c
> +++ b/sysdeps/ieee754/ldbl-128/s_rintl.c
> @@ -31,15 +31,19 @@ static char rcsid[] = "$NetBSD: $";
>  #include <math.h>
>  #include <math_private.h>
>  #include <libm-alias-ldouble.h>
> -
> -static const _Float128
> -TWO112[2]={
> -  5.19229685853482762853049632922009600E+33L, /* 0x406F000000000000, 0 */
> - -5.19229685853482762853049632922009600E+33L  /* 0xC06F000000000000, 0 */
> -};
> +#include <math-use-builtins.h>
>  
>  _Float128 __rintl(_Float128 x)
>  {
> +#if USE_RINTL_BUILTIN
> +  return __builtin_rintl (x);
> +#else
> +  /* Use generic implementation.  */
> +  static const _Float128
> +    TWO112[2] = {
> +		 5.19229685853482762853049632922009600E+33L, /* 0x406F000000000000, 0 */
> +		 -5.19229685853482762853049632922009600E+33L  /* 0xC06F000000000000, 0 */
> +  };
>  	int64_t i0,j0,sx;
>  	uint64_t i1 __attribute__ ((unused));
>  	_Float128 w,t;
> @@ -60,5 +64,6 @@ _Float128 __rintl(_Float128 x)
>  	}
>  	w = TWO112[sx]+x;
>  	return w-TWO112[sx];
> +#endif /* ! USE_RINTL_BUILTIN  */
>  }
>  libm_alias_ldouble (__rint, rint)

Ok.

> diff --git a/sysdeps/s390/fpu/math-use-builtins.h b/sysdeps/s390/fpu/math-use-builtins.h
> index 7abbfb3b50..8b702a6a90 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, 0)
>  #  define USE_NEARBYINTF128_BUILTIN 1
> +#  define USE_RINTF128_BUILTIN 1
>  # else
>  #  define USE_NEARBYINTF128_BUILTIN 0
> +#  define USE_RINTF128_BUILTIN 0
>  # endif
>  
>  #else
> @@ -44,6 +50,11 @@
>  # 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 /* ! HAVE_S390_MIN_Z196_ZARCH_ASM_SUPPORT  */
>  
>  #endif /* math-use-builtins.h */
> 

Ok.

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v2 17/18] Adjust s_ceilf.c and s_ceill.c regarding code style.
  2019-12-09 12:52 ` [PATCH v2 17/18] Adjust s_ceilf.c and s_ceill.c regarding code style Stefan Liebler
@ 2019-12-10 19:15   ` Adhemerval Zanella
  0 siblings, 0 replies; 33+ messages in thread
From: Adhemerval Zanella @ 2019-12-10 19:15 UTC (permalink / raw)
  To: libc-alpha



On 09/12/2019 09:46, Stefan Liebler wrote:
> This patch just adjusts the generic implementation regarding code style.
> No functional change.

LGTM, thanks.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>

> ---
>  sysdeps/ieee754/flt-32/s_ceilf.c   | 54 +++++++++++-------
>  sysdeps/ieee754/ldbl-128/s_ceill.c | 91 +++++++++++++++++++-----------
>  2 files changed, 92 insertions(+), 53 deletions(-)
> 
> diff --git a/sysdeps/ieee754/flt-32/s_ceilf.c b/sysdeps/ieee754/flt-32/s_ceilf.c
> index 7d4990f3ff..5c4abfe145 100644
> --- a/sysdeps/ieee754/flt-32/s_ceilf.c
> +++ b/sysdeps/ieee754/flt-32/s_ceilf.c
> @@ -20,34 +20,46 @@
>  #include <math-use-builtins.h>
>  
>  float
> -__ceilf(float x)
> +__ceilf (float x)
>  {
>  #if USE_CEILF_BUILTIN
>    return __builtin_ceilf (x);
>  #else
>    /* Use generic implementation.  */
> -	int32_t i0,j0;
> -	uint32_t i;
> +  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;
>  	}
> -	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_CEILF_BUILTIN  */
>  }
>  #ifndef __ceilf

Ok.

> diff --git a/sysdeps/ieee754/ldbl-128/s_ceill.c b/sysdeps/ieee754/ldbl-128/s_ceill.c
> index 02ffa7af2b..c5d98e1e37 100644
> --- a/sysdeps/ieee754/ldbl-128/s_ceill.c
> +++ b/sysdeps/ieee754/ldbl-128/s_ceill.c
> @@ -13,7 +13,7 @@
>   * ====================================================
>   */
>  
> -#if defined(LIBM_SCCS) && !defined(lint)
> +#if defined (LIBM_SCCS) && ! defined (lint)
>  static char rcsid[] = "$NetBSD: $";
>  #endif
>  
> @@ -30,45 +30,72 @@ static char rcsid[] = "$NetBSD: $";
>  #include <libm-alias-ldouble.h>
>  #include <math-use-builtins.h>
>  
> -_Float128 __ceill(_Float128 x)
> +_Float128
> +__ceill (_Float128 x)
>  {
>  #if USE_CEILL_BUILTIN
>    return __builtin_ceill (x);
>  #else
>    /* Use generic implementation.  */
> -	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;
> +  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 (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 if ((i0 | i1) != 0)
> +	    {
> +	      i0 = 0x3fff000000000000ULL;
> +	      i1 = 0;
>  	    }
> -	    i1 &= (~i);
>  	}
> -	SET_LDOUBLE_WORDS64(x,i0,i1);
> -	return x;
> +      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;
>  #endif /* ! USE_CEILL_BUILTIN  */
>  }
>  libm_alias_ldouble (__ceil, ceil)
> 

Ok.

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v2 09/18] Use GCC builtins for floor functions if desired.
  2019-12-09 12:50 ` [PATCH v2 09/18] Use GCC builtins for floor " Stefan Liebler
@ 2019-12-10 19:15   ` Adhemerval Zanella
  0 siblings, 0 replies; 33+ messages in thread
From: Adhemerval Zanella @ 2019-12-10 19:15 UTC (permalink / raw)
  To: libc-alpha



On 09/12/2019 09:45, 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.

LGTM, thanks.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>

> ---
>  sysdeps/generic/math-use-builtins.h         |  5 +++++
>  sysdeps/ieee754/dbl-64/s_floor.c            |  6 ++++++
>  sysdeps/ieee754/float128/float128_private.h |  3 +++
>  sysdeps/ieee754/flt-32/s_floorf.c           |  6 ++++++
>  sysdeps/ieee754/ldbl-128/s_floorl.c         |  6 ++++++
>  sysdeps/s390/fpu/math-use-builtins.h        | 11 +++++++++++
>  6 files changed, 37 insertions(+)
> 
> 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..78325214f4 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,10 @@
>  double
>  __floor (double x)
>  {
> +#if USE_FLOOR_BUILTIN
> +  return __builtin_floor (x);
> +#else
> +  /* Use generic implementation.  */
>    int64_t i0;
>    EXTRACT_WORDS64 (i0, x);
>    int32_t j0 = ((i0 >> 52) & 0x7ff) - 0x3ff;
> @@ -74,6 +79,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..afe02a1693 100644
> --- a/sysdeps/ieee754/flt-32/s_floorf.c
> +++ b/sysdeps/ieee754/flt-32/s_floorf.c
> @@ -24,10 +24,15 @@
>  #include <math.h>
>  #include <math_private.h>
>  #include <libm-alias-float.h>
> +#include <math-use-builtins.h>
>  
>  float
>  __floorf(float x)
>  {
> +#if USE_FLOORF_BUILTIN
> +  return __builtin_floorf (x);
> +#else
> +  /* Use generic implementation.  */
>  	int32_t i0,j0;
>  	uint32_t i;
>  	GET_FLOAT_WORD(i0,x);
> @@ -50,6 +55,7 @@ __floorf(float x)
>  	}
>  	SET_FLOAT_WORD(x,i0);
>  	return x;
> +#endif /* ! USE_FLOORF_BUILTIN  */
>  }
>  #ifndef __floorf
>  libm_alias_float (__floor, floor)

Ok.

> diff --git a/sysdeps/ieee754/ldbl-128/s_floorl.c b/sysdeps/ieee754/ldbl-128/s_floorl.c
> index f340a3fbca..cfe008392a 100644
> --- a/sysdeps/ieee754/ldbl-128/s_floorl.c
> +++ b/sysdeps/ieee754/ldbl-128/s_floorl.c
> @@ -28,9 +28,14 @@ static char rcsid[] = "$NetBSD: $";
>  #include <math.h>
>  #include <math_private.h>
>  #include <libm-alias-ldouble.h>
> +#include <math-use-builtins.h>
>  
>  _Float128 __floorl(_Float128 x)
>  {
> +#if USE_FLOORL_BUILTIN
> +  return __builtin_floorl (x);
> +#else
> +  /* Use generic implementation.  */
>  	int64_t i0,i1,j0;
>  	uint64_t i,j;
>  	GET_LDOUBLE_WORDS64(i0,i1,x);
> @@ -65,5 +70,6 @@ _Float128 __floorl(_Float128 x)
>  	}
>  	SET_LDOUBLE_WORDS64(x,i0,i1);
>  	return x;
> +#endif /* ! USE_FLOORL_BUILTIN  */
>  }
>  libm_alias_ldouble (__floor, floor)

Ok.

> diff --git a/sysdeps/s390/fpu/math-use-builtins.h b/sysdeps/s390/fpu/math-use-builtins.h
> index 8b702a6a90..c213c16c6f 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, 0)
>  #  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
> @@ -55,6 +61,11 @@
>  # 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 /* ! HAVE_S390_MIN_Z196_ZARCH_ASM_SUPPORT  */
>  
>  #endif /* math-use-builtins.h */
> 

Ok.

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v2 11/18] Use GCC builtins for trunc functions if desired.
  2019-12-09 12:50 ` [PATCH v2 11/18] Use GCC builtins for trunc " Stefan Liebler
@ 2019-12-10 19:15   ` Adhemerval Zanella
  0 siblings, 0 replies; 33+ messages in thread
From: Adhemerval Zanella @ 2019-12-10 19:15 UTC (permalink / raw)
  To: libc-alpha



On 09/12/2019 09: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.  The code of the generic
> implementation is not changed.

LGTM, thanks.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>

> ---
>  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        | 11 +++++++++++
>  6 files changed, 37 insertions(+)
> 
> 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..c3129fea7b 100644
> --- a/sysdeps/ieee754/dbl-64/s_trunc.c
> +++ b/sysdeps/ieee754/dbl-64/s_trunc.c
> @@ -22,11 +22,16 @@
>  
>  #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
> +  /* Use generic implementation.  */
>    int64_t i0, j0;
>    int64_t sx;
>  
> @@ -49,6 +54,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..274638820e 100644
> --- a/sysdeps/ieee754/flt-32/s_truncf.c
> +++ b/sysdeps/ieee754/flt-32/s_truncf.c
> @@ -22,11 +22,16 @@
>  
>  #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
> +  /* Use generic implementation.  */
>    int32_t i0, j0;
>    int sx;
>  
> @@ -49,6 +54,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..d11ab937e2 100644
> --- a/sysdeps/ieee754/ldbl-128/s_truncl.c
> +++ b/sysdeps/ieee754/ldbl-128/s_truncl.c
> @@ -23,11 +23,16 @@
>  
>  #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
> +  /* Use generic implementation.  */
>    int32_t j0;
>    uint64_t i0, i1, sx;
>  
> @@ -54,5 +59,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 5435cbb65f..a39715c612 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, 0)
>  #  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
> @@ -77,6 +83,11 @@
>  # 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 /* ! HAVE_S390_MIN_Z196_ZARCH_ASM_SUPPORT  */
>  
>  #endif /* math-use-builtins.h */
> 

Ok.

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v2 15/18] Adjust s_rintf.c and s_rintl.c regarding code style.
  2019-12-09 12:51 ` [PATCH v2 15/18] Adjust s_rintf.c and s_rintl.c regarding code style Stefan Liebler
@ 2019-12-10 19:15   ` Adhemerval Zanella
  0 siblings, 0 replies; 33+ messages in thread
From: Adhemerval Zanella @ 2019-12-10 19:15 UTC (permalink / raw)
  To: libc-alpha



On 09/12/2019 09:46, Stefan Liebler wrote:
> This patch just adjusts the generic implementation regarding code style.
> No functional change.

LGTM, thanks.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>

> ---
>  sysdeps/ieee754/flt-32/s_rintf.c   | 44 +++++++++++++++------------
>  sysdeps/ieee754/ldbl-128/s_rintl.c | 49 +++++++++++++++++-------------
>  2 files changed, 53 insertions(+), 40 deletions(-)
> 
> diff --git a/sysdeps/ieee754/flt-32/s_rintf.c b/sysdeps/ieee754/flt-32/s_rintf.c
> index 34c16ea164..627bada566 100644
> --- a/sysdeps/ieee754/flt-32/s_rintf.c
> +++ b/sysdeps/ieee754/flt-32/s_rintf.c
> @@ -20,7 +20,7 @@
>  #include <math-use-builtins.h>
>  
>  float
> -__rintf(float x)
> +__rintf (float x)
>  {
>  #if USE_RINTF_BUILTIN
>    return __builtin_rintf (x);
> @@ -31,25 +31,31 @@ __rintf(float x)
>  		8.3886080000e+06, /* 0x4b000000 */
>  		-8.3886080000e+06, /* 0xcb000000 */
>    };
> -	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 */
> +  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

Ok.

> diff --git a/sysdeps/ieee754/ldbl-128/s_rintl.c b/sysdeps/ieee754/ldbl-128/s_rintl.c
> index 3340c35ee1..16965f9582 100644
> --- a/sysdeps/ieee754/ldbl-128/s_rintl.c
> +++ b/sysdeps/ieee754/ldbl-128/s_rintl.c
> @@ -13,7 +13,7 @@
>   * ====================================================
>   */
>  
> -#if defined(LIBM_SCCS) && !defined(lint)
> +#if defined (LIBM_SCCS) && ! defined (lint)
>  static char rcsid[] = "$NetBSD: $";
>  #endif
>  
> @@ -33,7 +33,8 @@ static char rcsid[] = "$NetBSD: $";
>  #include <libm-alias-ldouble.h>
>  #include <math-use-builtins.h>
>  
> -_Float128 __rintl(_Float128 x)
> +_Float128
> +__rintl (_Float128 x)
>  {
>  #if USE_RINTL_BUILTIN
>    return __builtin_rintl (x);
> @@ -44,26 +45,32 @@ _Float128 __rintl(_Float128 x)
>  		 5.19229685853482762853049632922009600E+33L, /* 0x406F000000000000, 0 */
>  		 -5.19229685853482762853049632922009600E+33L  /* 0xC06F000000000000, 0 */
>    };
> -	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 */
> +  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.

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v2 12/18] Use GCC builtins for round functions if desired.
  2019-12-09 12:51 ` [PATCH v2 12/18] Use GCC builtins for round functions if desired Stefan Liebler
@ 2019-12-10 19:15   ` Adhemerval Zanella
  0 siblings, 0 replies; 33+ messages in thread
From: Adhemerval Zanella @ 2019-12-10 19:15 UTC (permalink / raw)
  To: libc-alpha



On 09/12/2019 09: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.  The code of the generic
> implementation is not changed.

LGTM, thanks.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>

> ---
>  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        | 11 +++++++++++
>  6 files changed, 37 insertions(+)
> 
> 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..7eb1ecb482 100644
> --- a/sysdeps/ieee754/dbl-64/s_round.c
> +++ b/sysdeps/ieee754/dbl-64/s_round.c
> @@ -23,11 +23,16 @@
>  #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
> +  /* Use generic implementation.  */
>    int64_t i0, j0;
>  
>    EXTRACT_WORDS64 (i0, x);
> @@ -62,5 +67,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..5d91239d6e 100644
> --- a/sysdeps/ieee754/flt-32/s_roundf.c
> +++ b/sysdeps/ieee754/flt-32/s_roundf.c
> @@ -22,11 +22,16 @@
>  
>  #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
> +  /* Use generic implementation.  */
>    int32_t i0, j0;
>  
>    GET_FLOAT_WORD (i0, x);
> @@ -61,5 +66,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..8c7ae82217 100644
> --- a/sysdeps/ieee754/ldbl-128/s_roundl.c
> +++ b/sysdeps/ieee754/ldbl-128/s_roundl.c
> @@ -23,11 +23,16 @@
>  
>  #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
> +  /* Use generic implementation.  */
>    int32_t j0;
>    uint64_t i1, i0;
>  
> @@ -78,5 +83,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 a39715c612..51cb9f91ab 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, 0)
>  #  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
> @@ -88,6 +94,11 @@
>  # 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 /* ! HAVE_S390_MIN_Z196_ZARCH_ASM_SUPPORT  */
>  
>  #endif /* math-use-builtins.h */
> 

Ok.

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v2 07/18] Use GCC builtins for nearbyint functions if desired.
  2019-12-09 12:49 ` [PATCH v2 07/18] Use GCC builtins for nearbyint functions if desired Stefan Liebler
@ 2019-12-10 19:16   ` Adhemerval Zanella
  0 siblings, 0 replies; 33+ messages in thread
From: Adhemerval Zanella @ 2019-12-10 19:16 UTC (permalink / raw)
  To: libc-alpha



On 09/12/2019 09:45, 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.

LGTM, thanks.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>

> ---
>  sysdeps/generic/math-use-builtins.h         | 29 ++++++++++++
>  sysdeps/ieee754/dbl-64/s_nearbyint.c        | 17 ++++---
>  sysdeps/ieee754/float128/float128_private.h |  4 ++
>  sysdeps/ieee754/flt-32/s_nearbyintf.c       | 17 ++++---
>  sysdeps/ieee754/ldbl-128/s_nearbyintl.c     | 17 ++++---
>  sysdeps/s390/fpu/math-use-builtins.h        | 49 +++++++++++++++++++++
>  6 files changed, 115 insertions(+), 18 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..2deaeb2568 100644
> --- a/sysdeps/ieee754/dbl-64/s_nearbyint.c
> +++ b/sysdeps/ieee754/dbl-64/s_nearbyint.c
> @@ -26,16 +26,20 @@
>  #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 */
> -};
> +#include <math-use-builtins.h>
>  
>  double
>  __nearbyint (double x)
>  {
> +#if USE_NEARBYINT_BUILTIN
> +  return __builtin_nearbyint (x);
> +#else
> +  /* Use generic implementation.  */
> +  static const double
> +    TWO52[2] = {
> +		4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
> +		-4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */
> +  };
>    fenv_t env;
>    int64_t i0, sx;
>    int32_t j0;
> @@ -67,5 +71,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
>  
>  /* 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..b37e003e12 100644
> --- a/sysdeps/ieee754/flt-32/s_nearbyintf.c
> +++ b/sysdeps/ieee754/flt-32/s_nearbyintf.c
> @@ -21,16 +21,20 @@
>  #include <math_private.h>
>  #include <fenv_private.h>
>  #include <libm-alias-float.h>
> -
> -static const float
> -TWO23[2]={
> -  8.3886080000e+06, /* 0x4b000000 */
> - -8.3886080000e+06, /* 0xcb000000 */
> -};
> +#include <math-use-builtins.h>
>  
>  float
>  __nearbyintf(float x)
>  {
> +#if USE_NEARBYINTF_BUILTIN
> +  return __builtin_nearbyintf (x);
> +#else
> +  /* Use generic implementation.  */
> +  static const float
> +    TWO23[2] = {
> +		8.3886080000e+06, /* 0x4b000000 */
> +		-8.3886080000e+06, /* 0xcb000000 */
> +  };
>  	fenv_t env;
>  	int32_t i0,j0,sx;
>  	float w,t;
> @@ -58,5 +62,6 @@ __nearbyintf(float x)
>  	math_force_eval (t);
>  	libc_fesetenvf (&env);
>  	return t;
> +#endif /* ! USE_NEARBYINT_BUILTIN  */
>  }
>  libm_alias_float (__nearbyint, nearbyint)

Ok.

> diff --git a/sysdeps/ieee754/ldbl-128/s_nearbyintl.c b/sysdeps/ieee754/ldbl-128/s_nearbyintl.c
> index f044cb4334..a4ad8e82e5 100644
> --- a/sysdeps/ieee754/ldbl-128/s_nearbyintl.c
> +++ b/sysdeps/ieee754/ldbl-128/s_nearbyintl.c
> @@ -28,15 +28,19 @@
>  #include <math-barriers.h>
>  #include <math_private.h>
>  #include <libm-alias-ldouble.h>
> -
> -static const _Float128
> -TWO112[2]={
> -  L(5.19229685853482762853049632922009600E+33), /* 0x406F000000000000, 0 */
> - L(-5.19229685853482762853049632922009600E+33)  /* 0xC06F000000000000, 0 */
> -};
> +#include <math-use-builtins.h>
>  
>  _Float128 __nearbyintl(_Float128 x)
>  {
> +#if USE_NEARBYINTL_BUILTIN
> +  return __builtin_nearbyintl (x);
> +#else
> +  /* Use generic implementation.  */
> +  static const _Float128
> +    TWO112[2] = {
> +		 L(5.19229685853482762853049632922009600E+33), /* 0x406F000000000000, 0 */
> +		 L(-5.19229685853482762853049632922009600E+33)  /* 0xC06F000000000000, 0 */
> +  };
>  	fenv_t env;
>  	int64_t i0,j0,sx;
>  	uint64_t i1 __attribute__ ((unused));
> @@ -65,5 +69,6 @@ _Float128 __nearbyintl(_Float128 x)
>  	math_force_eval (t);
>  	fesetenv (&env);
>  	return t;
> +#endif /* ! USE_NEARBYINTL_BUILTIN  */
>  }
>  libm_alias_ldouble (__nearbyint, nearbyint)

Ok.

> diff --git a/sysdeps/s390/fpu/math-use-builtins.h b/sysdeps/s390/fpu/math-use-builtins.h
> new file mode 100644
> index 0000000000..7abbfb3b50
> --- /dev/null
> +++ b/sysdeps/s390/fpu/math-use-builtins.h
> @@ -0,0 +1,49 @@
> +/* 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, 0)
> +#  define USE_NEARBYINTF128_BUILTIN 1
> +# else
> +#  define USE_NEARBYINTF128_BUILTIN 0
> +# endif
> +
> +#else
> +
> +/* Disable the builtins if we do not have the z196 zarch instructions.  */
> +# define USE_NEARBYINT_BUILTIN 0
> +# define USE_NEARBYINTF_BUILTIN 0
> +# define USE_NEARBYINTL_BUILTIN 0
> +# define USE_NEARBYINTF128_BUILTIN 0
> +
> +#endif /* ! HAVE_S390_MIN_Z196_ZARCH_ASM_SUPPORT  */
> +
> +#endif /* math-use-builtins.h */
> 

Ok.

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v2 18/18] Adjust s_copysignl.c regarding code style.
  2019-12-09 12:52 ` [PATCH v2 18/18] Adjust s_copysignl.c " Stefan Liebler
@ 2019-12-10 19:16   ` Adhemerval Zanella
  0 siblings, 0 replies; 33+ messages in thread
From: Adhemerval Zanella @ 2019-12-10 19:16 UTC (permalink / raw)
  To: libc-alpha



On 09/12/2019 09:46, Stefan Liebler wrote:
> This patch just adjusts the generic implementation regarding code style.
> No functional change.

LGTM, thanks.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>

> ---
>  sysdeps/ieee754/ldbl-128/s_copysignl.c | 17 +++++++++--------
>  1 file changed, 9 insertions(+), 8 deletions(-)
> 
> diff --git a/sysdeps/ieee754/ldbl-128/s_copysignl.c b/sysdeps/ieee754/ldbl-128/s_copysignl.c
> index 848a184524..a8b0639d2e 100644
> --- a/sysdeps/ieee754/ldbl-128/s_copysignl.c
> +++ b/sysdeps/ieee754/ldbl-128/s_copysignl.c
> @@ -13,7 +13,7 @@
>   * ====================================================
>   */
>  
> -#if defined(LIBM_SCCS) && !defined(lint)
> +#if defined (LIBM_SCCS) && ! defined (lint)
>  static char rcsid[] = "$NetBSD: $";
>  #endif
>  
> @@ -29,18 +29,19 @@ static char rcsid[] = "$NetBSD: $";
>  #include <libm-alias-ldouble.h>
>  #include <math-use-builtins.h>
>  
> -_Float128 __copysignl(_Float128 x, _Float128 y)
> +_Float128
> +__copysignl (_Float128 x, _Float128 y)
>  {
>  #if USE_COPYSIGNL_BUILTIN
>    return __builtin_copysignl (x, y);
>  #else
>    /* Use generic implementation.  */
> -	uint64_t hx,hy;
> -	GET_LDOUBLE_MSW64(hx,x);
> -	GET_LDOUBLE_MSW64(hy,y);
> -	SET_LDOUBLE_MSW64(x,(hx&0x7fffffffffffffffULL)
> -			    |(hy&0x8000000000000000ULL));
> -        return x;
> +  uint64_t hx, hy;
> +  GET_LDOUBLE_MSW64 (hx, x);
> +  GET_LDOUBLE_MSW64 (hy, y);
> +  SET_LDOUBLE_MSW64 (x, (hx & 0x7fffffffffffffffULL)
> +		     | (hy & 0x8000000000000000ULL));
> +  return x;
>  #endif /* ! USE_COPYSIGNL_BUILTIN  */
>  }
>  libm_alias_ldouble (__copysign, copysign)
> 

Ok.

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v2 13/18] Use GCC builtins for copysign functions if desired.
  2019-12-09 12:51 ` [PATCH v2 13/18] Use GCC builtins for copysign " Stefan Liebler
@ 2019-12-10 19:16   ` Adhemerval Zanella
  0 siblings, 0 replies; 33+ messages in thread
From: Adhemerval Zanella @ 2019-12-10 19:16 UTC (permalink / raw)
  To: libc-alpha



On 09/12/2019 09:46, Stefan Liebler wrote:
> This patch is always using the corresponding GCC builtin for copysignf, copysign,
> and is using the builtin for copysignl, copysignf128 if the USE_FUNCTION_BUILTIN
> macros are defined to one in math-use-builtins.h.
> 
> Altough the long double version is enabled by default we still need
> the macro and the alternative implementation as the _Float128 version
> of the builtin is not available with all supported GCC versions.

LGTM, thanks.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>

> ---
>  sysdeps/generic/math-use-builtins.h         |  9 +++++++++
>  sysdeps/ieee754/dbl-64/s_copysign.c         |  9 ++-------
>  sysdeps/ieee754/float128/float128_private.h |  3 +++
>  sysdeps/ieee754/flt-32/s_copysignf.c        | 12 ++++--------
>  sysdeps/ieee754/ldbl-128/s_copysignl.c      |  6 ++++++
>  sysdeps/s390/fpu/math-use-builtins.h        |  7 +++++++
>  6 files changed, 31 insertions(+), 15 deletions(-)
> 
> diff --git a/sysdeps/generic/math-use-builtins.h b/sysdeps/generic/math-use-builtins.h
> index 34ca438a8c..770b54ce61 100644
> --- a/sysdeps/generic/math-use-builtins.h
> +++ b/sysdeps/generic/math-use-builtins.h
> @@ -19,6 +19,8 @@
>  #ifndef MATH_USE_BUILTINS_H
>  #define MATH_USE_BUILTINS_H	1
>  
> +#include <features.h> /* For __GNUC_PREREQ.  */
> +
>  /* Define these macros to 1 to use __builtin_xyz instead of the
>     generic implementation.  */
>  #define USE_NEARBYINT_BUILTIN 0
> @@ -51,4 +53,11 @@
>  #define USE_ROUNDL_BUILTIN 0
>  #define USE_ROUNDF128_BUILTIN 0
>  
> +#define USE_COPYSIGNL_BUILTIN 1
> +#if __GNUC_PREREQ (7, 0)
> +# define USE_COPYSIGNF128_BUILTIN 1
> +#else
> +# define USE_COPYSIGNF128_BUILTIN 0
> +#endif
> +
>  #endif /* math-use-builtins.h */

Ok.

> diff --git a/sysdeps/ieee754/dbl-64/s_copysign.c b/sysdeps/ieee754/dbl-64/s_copysign.c
> index 589b088c95..94025b7854 100644
> --- a/sysdeps/ieee754/dbl-64/s_copysign.c
> +++ b/sysdeps/ieee754/dbl-64/s_copysign.c
> @@ -10,7 +10,7 @@
>   * ====================================================
>   */
>  
> -#if defined(LIBM_SCCS) && !defined(lint)
> +#if defined (LIBM_SCCS) && ! defined (lint)
>  static char rcsid[] = "$NetBSD: s_copysign.c,v 1.8 1995/05/10 20:46:57 jtc Exp $";
>  #endif
>  
> @@ -22,16 +22,11 @@ static char rcsid[] = "$NetBSD: s_copysign.c,v 1.8 1995/05/10 20:46:57 jtc Exp $
>  
>  #define NO_MATH_REDIRECT
>  #include <math.h>
> -#include <math_private.h>
>  #include <libm-alias-double.h>
>  
>  double
>  __copysign (double x, double y)
>  {
> -  uint32_t hx, hy;
> -  GET_HIGH_WORD (hx, x);
> -  GET_HIGH_WORD (hy, y);
> -  SET_HIGH_WORD (x, (hx & 0x7fffffff) | (hy & 0x80000000));
> -  return x;
> +  return __builtin_copysign (x, y);
>  }
>  libm_alias_double (__copysign, copysign)

Ok.

> diff --git a/sysdeps/ieee754/float128/float128_private.h b/sysdeps/ieee754/float128/float128_private.h
> index a6c76ce364..7f7f904152 100644
> --- a/sysdeps/ieee754/float128/float128_private.h
> +++ b/sysdeps/ieee754/float128/float128_private.h
> @@ -152,6 +152,8 @@
>  #define USE_TRUNCL_BUILTIN USE_TRUNCF128_BUILTIN
>  #undef USE_ROUNDL_BUILTIN
>  #define USE_ROUNDL_BUILTIN USE_ROUNDF128_BUILTIN
> +#undef USE_COPYSIGNL_BUILTIN
> +#define USE_COPYSIGNL_BUILTIN USE_COPYSIGNF128_BUILTIN
>  
>  /* IEEE function renames.  */
>  #define __ieee754_acoshl __ieee754_acoshf128
> @@ -361,6 +363,7 @@
>  #define __builtin_ceill __builtin_ceilf128
>  #define __builtin_truncl __builtin_truncf128
>  #define __builtin_roundl __builtin_roundf128
> +#define __builtin_copysignl __builtin_copysignf128
>  
>  /* Get the constant suffix from bits/floatn-compat.h.  */
>  #define L(x) __f128 (x)

Ok.

> diff --git a/sysdeps/ieee754/flt-32/s_copysignf.c b/sysdeps/ieee754/flt-32/s_copysignf.c
> index 77d1d90e92..1c097d313f 100644
> --- a/sysdeps/ieee754/flt-32/s_copysignf.c
> +++ b/sysdeps/ieee754/flt-32/s_copysignf.c
> @@ -13,7 +13,7 @@
>   * ====================================================
>   */
>  
> -#if defined(LIBM_SCCS) && !defined(lint)
> +#if defined (LIBM_SCCS) && ! defined (lint)
>  static char rcsid[] = "$NetBSD: s_copysignf.c,v 1.4 1995/05/10 20:46:59 jtc Exp $";
>  #endif
>  
> @@ -25,15 +25,11 @@ static char rcsid[] = "$NetBSD: s_copysignf.c,v 1.4 1995/05/10 20:46:59 jtc Exp
>  
>  #define NO_MATH_REDIRECT
>  #include <math.h>
> -#include <math_private.h>
>  #include <libm-alias-float.h>
>  
> -float __copysignf(float x, float y)
> +float
> +__copysignf (float x, float y)
>  {
> -	uint32_t ix,iy;
> -	GET_FLOAT_WORD(ix,x);
> -	GET_FLOAT_WORD(iy,y);
> -	SET_FLOAT_WORD(x,(ix&0x7fffffff)|(iy&0x80000000));
> -        return x;
> +  return __builtin_copysignf (x, y);
>  }
>  libm_alias_float (__copysign, copysign)

Ok.

> diff --git a/sysdeps/ieee754/ldbl-128/s_copysignl.c b/sysdeps/ieee754/ldbl-128/s_copysignl.c
> index a501139f71..848a184524 100644
> --- a/sysdeps/ieee754/ldbl-128/s_copysignl.c
> +++ b/sysdeps/ieee754/ldbl-128/s_copysignl.c
> @@ -27,14 +27,20 @@ static char rcsid[] = "$NetBSD: $";
>  #include <math.h>
>  #include <math_private.h>
>  #include <libm-alias-ldouble.h>
> +#include <math-use-builtins.h>
>  
>  _Float128 __copysignl(_Float128 x, _Float128 y)
>  {
> +#if USE_COPYSIGNL_BUILTIN
> +  return __builtin_copysignl (x, y);
> +#else
> +  /* Use generic implementation.  */
>  	uint64_t hx,hy;
>  	GET_LDOUBLE_MSW64(hx,x);
>  	GET_LDOUBLE_MSW64(hy,y);
>  	SET_LDOUBLE_MSW64(x,(hx&0x7fffffffffffffffULL)
>  			    |(hy&0x8000000000000000ULL));
>          return x;
> +#endif /* ! USE_COPYSIGNL_BUILTIN  */
>  }
>  libm_alias_ldouble (__copysign, copysign)

Ok.

> diff --git a/sysdeps/s390/fpu/math-use-builtins.h b/sysdeps/s390/fpu/math-use-builtins.h
> index 51cb9f91ab..4c4aad2ab5 100644
> --- a/sysdeps/s390/fpu/math-use-builtins.h
> +++ b/sysdeps/s390/fpu/math-use-builtins.h
> @@ -101,4 +101,11 @@
>  
>  #endif /* ! HAVE_S390_MIN_Z196_ZARCH_ASM_SUPPORT  */
>  
> +#define USE_COPYSIGNL_BUILTIN 1
> +#if __GNUC_PREREQ (7, 0)
> +# define USE_COPYSIGNF128_BUILTIN 1
> +#else
> +# define USE_COPYSIGNF128_BUILTIN 0
> +#endif
> +
>  #endif /* math-use-builtins.h */
> 

Ok.

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v2 14/18] Adjust s_nearbyintf.c and s_nearbyintl.c regarding code style.
  2019-12-09 12:51 ` [PATCH v2 14/18] Adjust s_nearbyintf.c and s_nearbyintl.c " Stefan Liebler
@ 2019-12-10 19:16   ` Adhemerval Zanella
  0 siblings, 0 replies; 33+ messages in thread
From: Adhemerval Zanella @ 2019-12-10 19:16 UTC (permalink / raw)
  To: libc-alpha



On 09/12/2019 09:46, Stefan Liebler wrote:
> This patch just adjusts the generic implementation regarding code style.
> No functional change.

LGTM, thanks.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>

> ---
>  sysdeps/ieee754/flt-32/s_nearbyintf.c   | 60 ++++++++++++-----------
>  sysdeps/ieee754/ldbl-128/s_nearbyintl.c | 63 ++++++++++++++-----------
>  2 files changed, 68 insertions(+), 55 deletions(-)
> 
> diff --git a/sysdeps/ieee754/flt-32/s_nearbyintf.c b/sysdeps/ieee754/flt-32/s_nearbyintf.c
> index b37e003e12..2a79907168 100644
> --- a/sysdeps/ieee754/flt-32/s_nearbyintf.c
> +++ b/sysdeps/ieee754/flt-32/s_nearbyintf.c
> @@ -24,7 +24,7 @@
>  #include <math-use-builtins.h>
>  
>  float
> -__nearbyintf(float x)
> +__nearbyintf (float x)
>  {
>  #if USE_NEARBYINTF_BUILTIN
>    return __builtin_nearbyintf (x);
> @@ -35,33 +35,39 @@ __nearbyintf(float x)
>  		8.3886080000e+06, /* 0x4b000000 */
>  		-8.3886080000e+06, /* 0xcb000000 */
>    };
> -	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 */
> +  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.

> diff --git a/sysdeps/ieee754/ldbl-128/s_nearbyintl.c b/sysdeps/ieee754/ldbl-128/s_nearbyintl.c
> index a4ad8e82e5..8d26786f78 100644
> --- a/sysdeps/ieee754/ldbl-128/s_nearbyintl.c
> +++ b/sysdeps/ieee754/ldbl-128/s_nearbyintl.c
> @@ -30,7 +30,8 @@
>  #include <libm-alias-ldouble.h>
>  #include <math-use-builtins.h>
>  
> -_Float128 __nearbyintl(_Float128 x)
> +_Float128
> +__nearbyintl (_Float128 x)
>  {
>  #if USE_NEARBYINTL_BUILTIN
>    return __builtin_nearbyintl (x);
> @@ -41,34 +42,40 @@ _Float128 __nearbyintl(_Float128 x)
>  		 L(5.19229685853482762853049632922009600E+33), /* 0x406F000000000000, 0 */
>  		 L(-5.19229685853482762853049632922009600E+33)  /* 0xC06F000000000000, 0 */
>    };
> -	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 */
> +  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.

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v2 10/18] Use GCC builtins for ceil functions if desired.
  2019-12-09 12:50 ` [PATCH v2 10/18] Use GCC builtins for ceil functions if desired Stefan Liebler
@ 2019-12-10 19:16   ` Adhemerval Zanella
  0 siblings, 0 replies; 33+ messages in thread
From: Adhemerval Zanella @ 2019-12-10 19:16 UTC (permalink / raw)
  To: libc-alpha



On 09/12/2019 09: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.

LGTM, thanks.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>

> ---
>  sysdeps/generic/math-use-builtins.h         |  5 +++++
>  sysdeps/ieee754/dbl-64/s_ceil.c             |  6 ++++++
>  sysdeps/ieee754/float128/float128_private.h |  3 +++
>  sysdeps/ieee754/flt-32/s_ceilf.c            |  7 ++++++-
>  sysdeps/ieee754/ldbl-128/s_ceill.c          |  6 ++++++
>  sysdeps/s390/fpu/math-use-builtins.h        | 11 +++++++++++
>  6 files changed, 37 insertions(+), 1 deletion(-)
> 
> 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 8d66f027e7..3738211360 100644
> --- a/sysdeps/ieee754/dbl-64/s_ceil.c
> +++ b/sysdeps/ieee754/dbl-64/s_ceil.c
> @@ -21,10 +21,15 @@
>  #include <math.h>
>  #include <math_private.h>
>  #include <libm-alias-double.h>
> +#include <math-use-builtins.h>
>  
>  double
>  __ceil (double x)
>  {
> +#if USE_CEIL_BUILTIN
> +  return __builtin_ceil (x);
> +#else
> +  /* Use generic implementation.  */
>    int64_t i0, i;
>    int32_t j0;
>    EXTRACT_WORDS64 (i0, x);
> @@ -58,6 +63,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)
> diff --git a/sysdeps/ieee754/flt-32/s_ceilf.c b/sysdeps/ieee754/flt-32/s_ceilf.c
> index 25cba0807c..7d4990f3ff 100644
> --- a/sysdeps/ieee754/flt-32/s_ceilf.c
> +++ b/sysdeps/ieee754/flt-32/s_ceilf.c
> @@ -17,11 +17,15 @@
>  #include <math.h>
>  #include <math_private.h>
>  #include <libm-alias-float.h>
> -
> +#include <math-use-builtins.h>
>  
>  float
>  __ceilf(float x)
>  {
> +#if USE_CEILF_BUILTIN
> +  return __builtin_ceilf (x);
> +#else
> +  /* Use generic implementation.  */
>  	int32_t i0,j0;
>  	uint32_t i;
>  
> @@ -44,6 +48,7 @@ __ceilf(float x)
>  	}
>  	SET_FLOAT_WORD(x,i0);
>  	return x;
> +#endif /* ! USE_CEILF_BUILTIN  */
>  }
>  #ifndef __ceilf
>  libm_alias_float (__ceil, ceil)

Ok.

> diff --git a/sysdeps/ieee754/ldbl-128/s_ceill.c b/sysdeps/ieee754/ldbl-128/s_ceill.c
> index 2ec55de25a..02ffa7af2b 100644
> --- a/sysdeps/ieee754/ldbl-128/s_ceill.c
> +++ b/sysdeps/ieee754/ldbl-128/s_ceill.c
> @@ -28,9 +28,14 @@ static char rcsid[] = "$NetBSD: $";
>  #include <math.h>
>  #include <math_private.h>
>  #include <libm-alias-ldouble.h>
> +#include <math-use-builtins.h>
>  
>  _Float128 __ceill(_Float128 x)
>  {
> +#if USE_CEILL_BUILTIN
> +  return __builtin_ceill (x);
> +#else
> +  /* Use generic implementation.  */
>  	int64_t i0,i1,j0;
>  	uint64_t i,j;
>  	GET_LDOUBLE_WORDS64(i0,i1,x);
> @@ -64,5 +69,6 @@ _Float128 __ceill(_Float128 x)
>  	}
>  	SET_LDOUBLE_WORDS64(x,i0,i1);
>  	return x;
> +#endif /* ! USE_CEILL_BUILTIN  */
>  }
>  libm_alias_ldouble (__ceil, ceil)

Ok.

> diff --git a/sysdeps/s390/fpu/math-use-builtins.h b/sysdeps/s390/fpu/math-use-builtins.h
> index c213c16c6f..5435cbb65f 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, 0)
>  #  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
> @@ -66,6 +72,11 @@
>  # 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 /* ! HAVE_S390_MIN_Z196_ZARCH_ASM_SUPPORT  */
>  
>  #endif /* math-use-builtins.h */
> 

Ok.

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v2 16/18] Adjust s_floorf.c and s_floorl.c regarding code style.
  2019-12-09 12:51 ` [PATCH v2 16/18] Adjust s_floorf.c and s_floorl.c " Stefan Liebler
@ 2019-12-10 19:16   ` Adhemerval Zanella
  0 siblings, 0 replies; 33+ messages in thread
From: Adhemerval Zanella @ 2019-12-10 19:16 UTC (permalink / raw)
  To: libc-alpha



On 09/12/2019 09:46, Stefan Liebler wrote:
> This patch just adjusts the generic implementation regarding code style.
> No functional change.

LGTM, thanks.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>

> ---
>  sysdeps/ieee754/flt-32/s_floorf.c   | 55 +++++++++++-------
>  sysdeps/ieee754/ldbl-128/s_floorl.c | 89 ++++++++++++++++++-----------
>  2 files changed, 90 insertions(+), 54 deletions(-)
> 
> diff --git a/sysdeps/ieee754/flt-32/s_floorf.c b/sysdeps/ieee754/flt-32/s_floorf.c
> index afe02a1693..da6c6dfa8a 100644
> --- a/sysdeps/ieee754/flt-32/s_floorf.c
> +++ b/sysdeps/ieee754/flt-32/s_floorf.c
> @@ -27,34 +27,45 @@
>  #include <math-use-builtins.h>
>  
>  float
> -__floorf(float x)
> +__floorf (float x)
>  {
>  #if USE_FLOORF_BUILTIN
>    return __builtin_floorf (x);
>  #else
>    /* Use generic implementation.  */
> -	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 */
> +  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

Ok.

> diff --git a/sysdeps/ieee754/ldbl-128/s_floorl.c b/sysdeps/ieee754/ldbl-128/s_floorl.c
> index cfe008392a..0475120d7e 100644
> --- a/sysdeps/ieee754/ldbl-128/s_floorl.c
> +++ b/sysdeps/ieee754/ldbl-128/s_floorl.c
> @@ -30,46 +30,71 @@ static char rcsid[] = "$NetBSD: $";
>  #include <libm-alias-ldouble.h>
>  #include <math-use-builtins.h>
>  
> -_Float128 __floorl(_Float128 x)
> +_Float128
> +__floorl (_Float128 x)
>  {
>  #if USE_FLOORL_BUILTIN
>    return __builtin_floorl (x);
>  #else
>    /* Use generic implementation.  */
> -	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;
> +  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 (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 if (((i0 & 0x7fffffffffffffffLL) | i1) != 0)
> +	    {
> +	      i0 = 0xbfff000000000000ULL;
> +	      i1 = 0;
>  	    }
> -	    i1 &= (~i);
>  	}
> -	SET_LDOUBLE_WORDS64(x,i0,i1);
> -	return x;
> +      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;
>  #endif /* ! USE_FLOORL_BUILTIN  */
>  }
>  libm_alias_ldouble (__floor, floor)
> 

Ok.

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v2 00/18] Use GCC builtins for some math functions if desired.
  2019-12-09 12:46 [PATCH v2 00/18] Use GCC builtins for some math functions if desired Stefan Liebler
                   ` (17 preceding siblings ...)
  2019-12-09 12:52 ` [PATCH v2 18/18] Adjust s_copysignl.c " Stefan Liebler
@ 2019-12-10 19:18 ` Adhemerval Zanella
  2019-12-11 14:16   ` Stefan Liebler
  18 siblings, 1 reply; 33+ messages in thread
From: Adhemerval Zanella @ 2019-12-10 19:18 UTC (permalink / raw)
  To: libc-alpha, Stefan Liebler



On 09/12/2019 09:45, 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.
> 
> Changes compared to first version (see https://www.sourceware.org/ml/libc-alpha/2019-12/msg00029.html) due to review from:
> Joseph Myers:
> * The copysign builtins are now used unconditionally for float, double and long double.  For _Float128 the macro is defined to 1 if build with GCC >= 7.
> 
> Adhemerval Zanella:
> * Some static array definitions like TWO52 in s_nearbyint.c are moved inside the !USE_NEARBYINT_BUILTIN within the function.
> * The s390 math-use-builtins.h header is now replicating the USE_XYZ* macros for !HAVE_S390_MIN_Z196_ZARCH_ASM_SUPPORT instead of just including the generic header file.
> * The changes regarding code style in the "Use GCC builtins for xyz functions if desired" patches are splitted out into the new patches "Adjust s_XYZ.c regarding code style."

Hi Stefan,

I reviewed the whole series and it looks good.  I haven't reviewed again the
parts 01 to 07 since they are essentially the same as previous version and
they are already reviewed.

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v2 00/18] Use GCC builtins for some math functions if desired.
  2019-12-10 19:18 ` [PATCH v2 00/18] Use GCC builtins for some math functions if desired Adhemerval Zanella
@ 2019-12-11 14:16   ` Stefan Liebler
  0 siblings, 0 replies; 33+ messages in thread
From: Stefan Liebler @ 2019-12-11 14:16 UTC (permalink / raw)
  To: Adhemerval Zanella, libc-alpha

On 12/10/19 8:18 PM, Adhemerval Zanella wrote:
> 
> 
> On 09/12/2019 09:45, 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.
>>
>> Changes compared to first version (see https://www.sourceware.org/ml/libc-alpha/2019-12/msg00029.html) due to review from:
>> Joseph Myers:
>> * The copysign builtins are now used unconditionally for float, double and long double.  For _Float128 the macro is defined to 1 if build with GCC >= 7.
>>
>> Adhemerval Zanella:
>> * Some static array definitions like TWO52 in s_nearbyint.c are moved inside the !USE_NEARBYINT_BUILTIN within the function.
>> * The s390 math-use-builtins.h header is now replicating the USE_XYZ* macros for !HAVE_S390_MIN_Z196_ZARCH_ASM_SUPPORT instead of just including the generic header file.
>> * The changes regarding code style in the "Use GCC builtins for xyz functions if desired" patches are splitted out into the new patches "Adjust s_XYZ.c regarding code style."
> 
> Hi Stefan,
> 
> I reviewed the whole series and it looks good.  I haven't reviewed again the
> parts 01 to 07 since they are essentially the same as previous version and
> they are already reviewed.
> 

Hi Adhemerval,

Thanks for the review. Yes, the first parts have not changed compared to 
the first version.

I've just committed the patches.

Bye
Stefan

^ permalink raw reply	[flat|nested] 33+ messages in thread

end of thread, other threads:[~2019-12-11 14:16 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-09 12:46 [PATCH v2 00/18] Use GCC builtins for some math functions if desired Stefan Liebler
2019-12-09 12:47 ` [PATCH v2 02/18] Always use wordsize-64 version of s_rint.c Stefan Liebler
2019-12-09 12:47 ` [PATCH v2 01/18] Always use wordsize-64 version of s_nearbyint.c Stefan Liebler
2019-12-09 12:48 ` [PATCH v2 03/18] Always use wordsize-64 version of s_floor.c Stefan Liebler
2019-12-09 12:48 ` [PATCH v2 04/18] Always use wordsize-64 version of s_ceil.c Stefan Liebler
2019-12-09 12:49 ` [PATCH v2 05/18] Always use wordsize-64 version of s_trunc.c Stefan Liebler
2019-12-09 12:49 ` [PATCH v2 07/18] Use GCC builtins for nearbyint functions if desired Stefan Liebler
2019-12-10 19:16   ` Adhemerval Zanella
2019-12-09 12:49 ` [PATCH v2 06/18] Always use wordsize-64 version of s_round.c Stefan Liebler
2019-12-09 12:50 ` [PATCH v2 10/18] Use GCC builtins for ceil functions if desired Stefan Liebler
2019-12-10 19:16   ` Adhemerval Zanella
2019-12-09 12:50 ` [PATCH v2 08/18] Use GCC builtins for rint " Stefan Liebler
2019-12-10 19:15   ` Adhemerval Zanella
2019-12-09 12:50 ` [PATCH v2 09/18] Use GCC builtins for floor " Stefan Liebler
2019-12-10 19:15   ` Adhemerval Zanella
2019-12-09 12:50 ` [PATCH v2 11/18] Use GCC builtins for trunc " Stefan Liebler
2019-12-10 19:15   ` Adhemerval Zanella
2019-12-09 12:51 ` [PATCH v2 15/18] Adjust s_rintf.c and s_rintl.c regarding code style Stefan Liebler
2019-12-10 19:15   ` Adhemerval Zanella
2019-12-09 12:51 ` [PATCH v2 16/18] Adjust s_floorf.c and s_floorl.c " Stefan Liebler
2019-12-10 19:16   ` Adhemerval Zanella
2019-12-09 12:51 ` [PATCH v2 14/18] Adjust s_nearbyintf.c and s_nearbyintl.c " Stefan Liebler
2019-12-10 19:16   ` Adhemerval Zanella
2019-12-09 12:51 ` [PATCH v2 12/18] Use GCC builtins for round functions if desired Stefan Liebler
2019-12-10 19:15   ` Adhemerval Zanella
2019-12-09 12:51 ` [PATCH v2 13/18] Use GCC builtins for copysign " Stefan Liebler
2019-12-10 19:16   ` Adhemerval Zanella
2019-12-09 12:52 ` [PATCH v2 17/18] Adjust s_ceilf.c and s_ceill.c regarding code style Stefan Liebler
2019-12-10 19:15   ` Adhemerval Zanella
2019-12-09 12:52 ` [PATCH v2 18/18] Adjust s_copysignl.c " Stefan Liebler
2019-12-10 19:16   ` Adhemerval Zanella
2019-12-10 19:18 ` [PATCH v2 00/18] Use GCC builtins for some math functions if desired Adhemerval Zanella
2019-12-11 14:16   ` Stefan Liebler

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).