* [PATCH 00/13] Use GCC builtins for some math functions if desired.
@ 2019-12-02 14:46 Stefan Liebler
2019-12-02 14:46 ` [PATCH 09/13] Use GCC builtins for floor " Stefan Liebler
` (13 more replies)
0 siblings, 14 replies; 35+ messages in thread
From: Stefan Liebler @ 2019-12-02 14: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.
Bye,
Stefan
Stefan Liebler (13):
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.
sysdeps/generic/math-use-builtins.h | 59 +++++++++++
sysdeps/ieee754/dbl-64/s_ceil.c | 64 +++++-------
sysdeps/ieee754/dbl-64/s_copysign.c | 8 +-
sysdeps/ieee754/dbl-64/s_floor.c | 98 +++++++++----------
sysdeps/ieee754/dbl-64/s_nearbyint.c | 46 ++++-----
sysdeps/ieee754/dbl-64/s_rint.c | 39 +++++---
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 | 60 +++++++-----
sysdeps/ieee754/flt-32/s_copysignf.c | 21 ++--
sysdeps/ieee754/flt-32/s_floorf.c | 60 +++++++-----
sysdeps/ieee754/flt-32/s_nearbyintf.c | 74 ++++++++------
sysdeps/ieee754/flt-32/s_rintf.c | 57 ++++++-----
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 | 97 +++++++++++-------
sysdeps/ieee754/ldbl-128/s_nearbyintl.c | 76 ++++++++------
sysdeps/ieee754/ldbl-128/s_rintl.c | 63 +++++++-----
sysdeps/ieee754/ldbl-128/s_roundl.c | 6 +-
sysdeps/ieee754/ldbl-128/s_truncl.c | 6 +-
sysdeps/s390/fpu/math-use-builtins.h | 84 ++++++++++++++++
.../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, 750 insertions(+), 788 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] 35+ messages in thread
* [PATCH 09/13] Use GCC builtins for floor functions if desired.
2019-12-02 14:46 [PATCH 00/13] Use GCC builtins for some math functions if desired Stefan Liebler
@ 2019-12-02 14:46 ` Stefan Liebler
2019-12-05 20:40 ` Adhemerval Zanella
2019-12-02 14:46 ` [PATCH 03/13] Always use wordsize-64 version of s_floor.c Stefan Liebler
` (12 subsequent siblings)
13 siblings, 1 reply; 35+ messages in thread
From: Stefan Liebler @ 2019-12-02 14:46 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 except changes in code style.
---
sysdeps/generic/math-use-builtins.h | 5 ++
sysdeps/ieee754/dbl-64/s_floor.c | 5 ++
sysdeps/ieee754/float128/float128_private.h | 3 +
sysdeps/ieee754/flt-32/s_floorf.c | 60 ++++++++-----
sysdeps/ieee754/ldbl-128/s_floorl.c | 97 ++++++++++++++-------
sysdeps/s390/fpu/math-use-builtins.h | 6 ++
6 files changed, 121 insertions(+), 55 deletions(-)
diff --git a/sysdeps/generic/math-use-builtins.h b/sysdeps/generic/math-use-builtins.h
index 64b4a4bb5b..e1c5df62e4 100644
--- a/sysdeps/generic/math-use-builtins.h
+++ b/sysdeps/generic/math-use-builtins.h
@@ -31,4 +31,9 @@
#define USE_RINTL_BUILTIN 0
#define USE_RINTF128_BUILTIN 0
+#define USE_FLOOR_BUILTIN 0
+#define USE_FLOORF_BUILTIN 0
+#define USE_FLOORL_BUILTIN 0
+#define USE_FLOORF128_BUILTIN 0
+
#endif /* math-use-builtins.h */
diff --git a/sysdeps/ieee754/dbl-64/s_floor.c b/sysdeps/ieee754/dbl-64/s_floor.c
index ce0c42bdb6..0ed22795ed 100644
--- a/sysdeps/ieee754/dbl-64/s_floor.c
+++ b/sysdeps/ieee754/dbl-64/s_floor.c
@@ -35,6 +35,7 @@
#include <math_private.h>
#include <stdint.h>
#include <libm-alias-double.h>
+#include <math-use-builtins.h>
/*
* floor(x)
@@ -47,6 +48,9 @@
double
__floor (double x)
{
+#if USE_FLOOR_BUILTIN
+ return __builtin_floor (x);
+#else
int64_t i0;
EXTRACT_WORDS64 (i0, x);
int32_t j0 = ((i0 >> 52) & 0x7ff) - 0x3ff;
@@ -74,6 +78,7 @@ __floor (double x)
else if (j0 == 0x400)
return x + x; /* inf or NaN */
return x;
+#endif /* USE_FLOOR_BUILTIN */
}
#ifndef __floor
libm_alias_double (__floor, floor)
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..39bb570d10 100644
--- a/sysdeps/ieee754/flt-32/s_floorf.c
+++ b/sysdeps/ieee754/flt-32/s_floorf.c
@@ -24,32 +24,48 @@
#include <math.h>
#include <math_private.h>
#include <libm-alias-float.h>
+#include <math-use-builtins.h>
float
-__floorf(float x)
+__floorf (float x)
{
- int32_t i0,j0;
- uint32_t i;
- GET_FLOAT_WORD(i0,x);
- j0 = ((i0>>23)&0xff)-0x7f;
- if(j0<23) {
- if(j0<0) {
- /* return 0*sign(x) if |x|<1 */
- if(i0>=0) {i0=0;}
- else if((i0&0x7fffffff)!=0)
- { i0=0xbf800000;}
- } else {
- i = (0x007fffff)>>j0;
- if((i0&i)==0) return x; /* x is integral */
- if(i0<0) i0 += (0x00800000)>>j0;
- i0 &= (~i);
- }
- } else {
- if(__builtin_expect(j0==0x80, 0)) return x+x; /* inf or NaN */
- else return x; /* x is integral */
+#if USE_FLOORF_BUILTIN
+ return __builtin_floorf (x);
+#else
+ int32_t i0, j0;
+ uint32_t i;
+ GET_FLOAT_WORD (i0, x);
+ j0 = ((i0 >> 23) & 0xff) - 0x7f;
+ if (j0 < 23)
+ {
+ if (j0 < 0)
+ {
+ /* return 0 * sign (x) if |x| < 1 */
+ if (i0 >= 0)
+ i0 = 0;
+ else if ((i0 & 0x7fffffff) != 0)
+ i0 = 0xbf800000;
}
- SET_FLOAT_WORD(x,i0);
- return x;
+ else
+ {
+ i = (0x007fffff) >> j0;
+ if ((i0 & i) == 0)
+ return x; /* x is integral */
+ if (i0 < 0)
+ i0 += (0x00800000) >> j0;
+ i0 &= (~i);
+ }
+ }
+ else
+ {
+ if (__glibc_unlikely (j0 == 0x80))
+ return x + x; /* inf or NaN */
+ else
+ return x; /* x is integral */
+ }
+ SET_FLOAT_WORD (x, i0);
+ return x;
+#endif /* USE_FLOORF_BUILTIN */
}
#ifndef __floorf
libm_alias_float (__floor, floor)
diff --git a/sysdeps/ieee754/ldbl-128/s_floorl.c b/sysdeps/ieee754/ldbl-128/s_floorl.c
index f340a3fbca..8d20a79fec 100644
--- a/sysdeps/ieee754/ldbl-128/s_floorl.c
+++ b/sysdeps/ieee754/ldbl-128/s_floorl.c
@@ -13,7 +13,9 @@
* ====================================================
*/
-#if defined(LIBM_SCCS) && !defined(lint)
+#include <math-use-builtins.h>
+
+#if ! USE_FLOORL_BUILTIN && defined (LIBM_SCCS) && ! defined (lint)
static char rcsid[] = "$NetBSD: $";
#endif
@@ -29,41 +31,70 @@ static char rcsid[] = "$NetBSD: $";
#include <math_private.h>
#include <libm-alias-ldouble.h>
-_Float128 __floorl(_Float128 x)
+_Float128
+__floorl (_Float128 x)
{
- int64_t i0,i1,j0;
- uint64_t i,j;
- GET_LDOUBLE_WORDS64(i0,i1,x);
- j0 = ((i0>>48)&0x7fff)-0x3fff;
- if(j0<48) {
- if(j0<0) {
- /* return 0*sign(x) if |x|<1 */
- if(i0>=0) {i0=i1=0;}
- else if(((i0&0x7fffffffffffffffLL)|i1)!=0)
- { i0=0xbfff000000000000ULL;i1=0;}
- } else {
- i = (0x0000ffffffffffffULL)>>j0;
- if(((i0&i)|i1)==0) return x; /* x is integral */
- if(i0<0) i0 += (0x0001000000000000LL)>>j0;
- i0 &= (~i); i1=0;
+#if USE_FLOORL_BUILTIN
+ return __builtin_floorl (x);
+#else
+ int64_t i0, i1, j0;
+ uint64_t i, j;
+ GET_LDOUBLE_WORDS64 (i0, i1, x);
+ j0 = ((i0 >> 48) & 0x7fff) - 0x3fff;
+ if (j0 < 48)
+ {
+ if (j0 < 0)
+ {
+ /* return 0 * sign (x) if |x| < 1 */
+ if (i0 >= 0)
+ {
+ i0 = i1 = 0;
+ }
+ else if (((i0 & 0x7fffffffffffffffLL) | i1) != 0)
+ {
+ i0 = 0xbfff000000000000ULL;
+ i1 = 0;
}
- } else if (j0>111) {
- if(j0==0x4000) return x+x; /* inf or NaN */
- else return x; /* x is integral */
- } else {
- i = -1ULL>>(j0-48);
- if((i1&i)==0) return x; /* x is integral */
- if(i0<0) {
- if(j0==48) i0+=1;
- else {
- j = i1+(1LL<<(112-j0));
- if(j<i1) i0 +=1 ; /* got a carry */
- i1=j;
- }
+ }
+ else
+ {
+ i = (0x0000ffffffffffffULL) >> j0;
+ if (((i0 & i) | i1) == 0)
+ return x; /* x is integral */
+ if (i0 < 0)
+ i0 += (0x0001000000000000LL) >> j0;
+ i0 &= (~i);
+ i1 = 0;
+ }
+ }
+ else if (j0 > 111)
+ {
+ if (j0 == 0x4000)
+ return x + x; /* inf or NaN */
+ else
+ return x; /* x is integral */
+ }
+ else
+ {
+ i = -1ULL >> (j0 - 48);
+ if ((i1 & i) == 0)
+ return x; /* x is integral */
+ if (i0 < 0)
+ {
+ if (j0 == 48)
+ i0 += 1;
+ else
+ {
+ j = i1 + (1LL << (112 - j0));
+ if (j < i1)
+ i0 += 1 ; /* got a carry */
+ i1 = j;
}
- i1 &= (~i);
}
- SET_LDOUBLE_WORDS64(x,i0,i1);
- return x;
+ i1 &= (~i);
+ }
+ SET_LDOUBLE_WORDS64 (x, i0, i1);
+ return x;
+#endif /* USE_FLOORL_BUILTIN */
}
libm_alias_ldouble (__floor, floor)
diff --git a/sysdeps/s390/fpu/math-use-builtins.h b/sysdeps/s390/fpu/math-use-builtins.h
index 15705fa74a..63cc9d7a23 100644
--- a/sysdeps/s390/fpu/math-use-builtins.h
+++ b/sysdeps/s390/fpu/math-use-builtins.h
@@ -34,12 +34,18 @@
# define USE_RINTF_BUILTIN 1
# define USE_RINTL_BUILTIN 1
+# define USE_FLOOR_BUILTIN 1
+# define USE_FLOORF_BUILTIN 1
+# define USE_FLOORL_BUILTIN 1
+
# if __GNUC_PREREQ (8, 1)
# define USE_NEARBYINTF128_BUILTIN 1
# define USE_RINTF128_BUILTIN 1
+# define USE_FLOORF128_BUILTIN 1
# else
# define USE_NEARBYINTF128_BUILTIN 0
# define USE_RINTF128_BUILTIN 0
+# define USE_FLOORF128_BUILTIN 0
# endif
#else
--
2.19.1
^ permalink raw reply [flat|nested] 35+ messages in thread
* [PATCH 01/13] Always use wordsize-64 version of s_nearbyint.c.
2019-12-02 14:46 [PATCH 00/13] Use GCC builtins for some math functions if desired Stefan Liebler
` (2 preceding siblings ...)
2019-12-02 14:46 ` [PATCH 07/13] Use GCC builtins for nearbyint functions if desired Stefan Liebler
@ 2019-12-02 14:46 ` Stefan Liebler
2019-12-05 20:40 ` Adhemerval Zanella
2019-12-02 14:46 ` [PATCH 05/13] Always use wordsize-64 version of s_trunc.c Stefan Liebler
` (9 subsequent siblings)
13 siblings, 1 reply; 35+ messages in thread
From: Stefan Liebler @ 2019-12-02 14:46 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] 35+ messages in thread
* [PATCH 08/13] Use GCC builtins for rint functions if desired.
2019-12-02 14:46 [PATCH 00/13] Use GCC builtins for some math functions if desired Stefan Liebler
` (5 preceding siblings ...)
2019-12-02 14:46 ` [PATCH 02/13] Always use wordsize-64 version of s_rint.c Stefan Liebler
@ 2019-12-02 14:46 ` Stefan Liebler
2019-12-05 20:40 ` Adhemerval Zanella
2019-12-02 15:10 ` [PATCH 11/13] Use GCC builtins for trunc " Stefan Liebler
` (6 subsequent siblings)
13 siblings, 1 reply; 35+ messages in thread
From: Stefan Liebler @ 2019-12-02 14:46 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 except changes in code style.
---
sysdeps/generic/math-use-builtins.h | 5 ++
sysdeps/ieee754/dbl-64/s_rint.c | 11 +++-
sysdeps/ieee754/float128/float128_private.h | 3 +
sysdeps/ieee754/flt-32/s_rintf.c | 57 ++++++++++++-------
sysdeps/ieee754/ldbl-128/s_rintl.c | 63 +++++++++++++--------
sysdeps/s390/fpu/math-use-builtins.h | 6 ++
6 files changed, 97 insertions(+), 48 deletions(-)
diff --git a/sysdeps/generic/math-use-builtins.h b/sysdeps/generic/math-use-builtins.h
index e12490ed41..64b4a4bb5b 100644
--- a/sysdeps/generic/math-use-builtins.h
+++ b/sysdeps/generic/math-use-builtins.h
@@ -26,4 +26,9 @@
#define USE_NEARBYINTL_BUILTIN 0
#define USE_NEARBYINTF128_BUILTIN 0
+#define USE_RINT_BUILTIN 0
+#define USE_RINTF_BUILTIN 0
+#define USE_RINTL_BUILTIN 0
+#define USE_RINTF128_BUILTIN 0
+
#endif /* math-use-builtins.h */
diff --git a/sysdeps/ieee754/dbl-64/s_rint.c b/sysdeps/ieee754/dbl-64/s_rint.c
index f96078c405..b09ed8fc06 100644
--- a/sysdeps/ieee754/dbl-64/s_rint.c
+++ b/sysdeps/ieee754/dbl-64/s_rint.c
@@ -23,16 +23,22 @@
#include <math.h>
#include <math_private.h>
#include <libm-alias-double.h>
+#include <math-use-builtins.h>
+#if ! USE_RINT_BUILTIN
static const double
TWO52[2] = {
4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
-4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */
};
+#endif
double
__rint (double x)
{
+#if USE_RINT_BUILTIN
+ return __builtin_rint (x);
+#else
int64_t i0, sx;
int32_t j0;
EXTRACT_WORDS64 (i0, x);
@@ -47,7 +53,7 @@ __rint (double x)
EXTRACT_WORDS64 (i0, t);
INSERT_WORDS64 (t, (i0 & UINT64_C (0x7fffffffffffffff))
| (sx << 63));
- return t;
+ return t;
}
}
else
@@ -56,9 +62,10 @@ __rint (double x)
return x + x; /* inf or NaN */
else
return x; /* x is integral */
- }
+ }
double w = TWO52[sx] + x;
return w - TWO52[sx];
+#endif /* USE_RINT_BUILTIN */
}
#ifndef __rint
libm_alias_double (__rint, rint)
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..7dbf991395 100644
--- a/sysdeps/ieee754/flt-32/s_rintf.c
+++ b/sysdeps/ieee754/flt-32/s_rintf.c
@@ -17,35 +17,48 @@
#include <math.h>
#include <math_private.h>
#include <libm-alias-float.h>
+#include <math-use-builtins.h>
+#if ! USE_RINTF_BUILTIN
static const float
-TWO23[2]={
- 8.3886080000e+06, /* 0x4b000000 */
- -8.3886080000e+06, /* 0xcb000000 */
+TWO23[2] = {
+ 8.3886080000e+06, /* 0x4b000000 */
+ -8.3886080000e+06, /* 0xcb000000 */
};
+#endif
float
-__rintf(float x)
+__rintf (float x)
{
- int32_t i0,j0,sx;
- float w,t;
- GET_FLOAT_WORD(i0,x);
- sx = (i0>>31)&1;
- j0 = ((i0>>23)&0xff)-0x7f;
- if(j0<23) {
- if(j0<0) {
- w = TWO23[sx]+x;
- t = w-TWO23[sx];
- GET_FLOAT_WORD(i0,t);
- SET_FLOAT_WORD(t,(i0&0x7fffffff)|(sx<<31));
- return t;
- }
- } else {
- if(j0==0x80) return x+x; /* inf or NaN */
- else return x; /* x is integral */
+#if USE_RINTF_BUILTIN
+ return __builtin_rintf (x);
+#else
+ int32_t i0, j0, sx;
+ float w, t;
+ GET_FLOAT_WORD (i0, x);
+ sx = (i0 >> 31) & 1;
+ j0 = ((i0 >> 23) & 0xff) - 0x7f;
+ if (j0 < 23)
+ {
+ if(j0 < 0)
+ {
+ w = TWO23[sx] + x;
+ t = w - TWO23[sx];
+ GET_FLOAT_WORD (i0, t);
+ SET_FLOAT_WORD (t, (i0 & 0x7fffffff) | (sx << 31));
+ return t;
}
- w = TWO23[sx]+x;
- return w-TWO23[sx];
+ }
+ else
+ {
+ if (j0 == 0x80)
+ return x + x; /* inf or NaN */
+ else
+ return x; /* x is integral */
+ }
+ w = TWO23[sx] + x;
+ return w - TWO23[sx];
+#endif /* USE_RINTF_BUILTIN */
}
#ifndef __rintf
libm_alias_float (__rint, rint)
diff --git a/sysdeps/ieee754/ldbl-128/s_rintl.c b/sysdeps/ieee754/ldbl-128/s_rintl.c
index b6337e1d8a..1c4eba566d 100644
--- a/sysdeps/ieee754/ldbl-128/s_rintl.c
+++ b/sysdeps/ieee754/ldbl-128/s_rintl.c
@@ -13,7 +13,9 @@
* ====================================================
*/
-#if defined(LIBM_SCCS) && !defined(lint)
+#include <math-use-builtins.h>
+
+#if ! USE_RINTL_BUILTIN && defined (LIBM_SCCS) && ! defined (lint)
static char rcsid[] = "$NetBSD: $";
#endif
@@ -32,33 +34,46 @@ static char rcsid[] = "$NetBSD: $";
#include <math_private.h>
#include <libm-alias-ldouble.h>
+#if ! USE_RINTL_BUILTIN
static const _Float128
-TWO112[2]={
- 5.19229685853482762853049632922009600E+33L, /* 0x406F000000000000, 0 */
- -5.19229685853482762853049632922009600E+33L /* 0xC06F000000000000, 0 */
+TWO112[2] = {
+ 5.19229685853482762853049632922009600E+33L, /* 0x406F000000000000, 0 */
+ -5.19229685853482762853049632922009600E+33L /* 0xC06F000000000000, 0 */
};
+#endif
-_Float128 __rintl(_Float128 x)
+_Float128
+__rintl (_Float128 x)
{
- int64_t i0,j0,sx;
- uint64_t i1 __attribute__ ((unused));
- _Float128 w,t;
- GET_LDOUBLE_WORDS64(i0,i1,x);
- sx = (((uint64_t)i0)>>63);
- j0 = ((i0>>48)&0x7fff)-0x3fff;
- if(j0<112) {
- if(j0<0) {
- w = TWO112[sx]+x;
- t = w-TWO112[sx];
- GET_LDOUBLE_MSW64(i0,t);
- SET_LDOUBLE_MSW64(t,(i0&0x7fffffffffffffffLL)|(sx<<63));
- return t;
- }
- } else {
- if(j0==0x4000) return x+x; /* inf or NaN */
- else return x; /* x is integral */
+#if USE_RINTL_BUILTIN
+ return __builtin_rintl (x);
+#else
+ int64_t i0, j0, sx;
+ uint64_t i1 __attribute__ ((unused));
+ _Float128 w, t;
+ GET_LDOUBLE_WORDS64 (i0, i1, x);
+ sx = (((uint64_t) i0) >> 63);
+ j0 = ((i0 >> 48) & 0x7fff) - 0x3fff;
+ if (j0 < 112)
+ {
+ if (j0 < 0)
+ {
+ w = TWO112[sx] + x;
+ t = w - TWO112[sx];
+ GET_LDOUBLE_MSW64 (i0, t);
+ SET_LDOUBLE_MSW64 (t, (i0 & 0x7fffffffffffffffLL) | (sx << 63));
+ return t;
}
- w = TWO112[sx]+x;
- return w-TWO112[sx];
+ }
+ else
+ {
+ if (j0 == 0x4000)
+ return x + x; /* inf or NaN */
+ else
+ return x; /* x is integral */
+ }
+ w = TWO112[sx] + x;
+ return w - TWO112[sx];
+#endif /* USE_RINTL_BUILTIN */
}
libm_alias_ldouble (__rint, rint)
diff --git a/sysdeps/s390/fpu/math-use-builtins.h b/sysdeps/s390/fpu/math-use-builtins.h
index fd9da8893e..15705fa74a 100644
--- a/sysdeps/s390/fpu/math-use-builtins.h
+++ b/sysdeps/s390/fpu/math-use-builtins.h
@@ -30,10 +30,16 @@
# define USE_NEARBYINTF_BUILTIN 1
# define USE_NEARBYINTL_BUILTIN 1
+# define USE_RINT_BUILTIN 1
+# define USE_RINTF_BUILTIN 1
+# define USE_RINTL_BUILTIN 1
+
# if __GNUC_PREREQ (8, 1)
# define USE_NEARBYINTF128_BUILTIN 1
+# define USE_RINTF128_BUILTIN 1
# else
# define USE_NEARBYINTF128_BUILTIN 0
+# define USE_RINTF128_BUILTIN 0
# endif
#else
--
2.19.1
^ permalink raw reply [flat|nested] 35+ messages in thread
* [PATCH 07/13] Use GCC builtins for nearbyint functions if desired.
2019-12-02 14:46 [PATCH 00/13] Use GCC builtins for some math functions if desired Stefan Liebler
2019-12-02 14:46 ` [PATCH 09/13] Use GCC builtins for floor " Stefan Liebler
2019-12-02 14:46 ` [PATCH 03/13] Always use wordsize-64 version of s_floor.c Stefan Liebler
@ 2019-12-02 14:46 ` Stefan Liebler
2019-12-05 20:40 ` Adhemerval Zanella
2019-12-02 14:46 ` [PATCH 01/13] Always use wordsize-64 version of s_nearbyint.c Stefan Liebler
` (10 subsequent siblings)
13 siblings, 1 reply; 35+ messages in thread
From: Stefan Liebler @ 2019-12-02 14:46 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 except changes in code style.
---
sysdeps/generic/math-use-builtins.h | 29 ++++++++
sysdeps/ieee754/dbl-64/s_nearbyint.c | 8 +++
sysdeps/ieee754/float128/float128_private.h | 4 ++
sysdeps/ieee754/flt-32/s_nearbyintf.c | 74 ++++++++++++--------
sysdeps/ieee754/ldbl-128/s_nearbyintl.c | 76 ++++++++++++---------
sysdeps/s390/fpu/math-use-builtins.h | 45 ++++++++++++
6 files changed, 175 insertions(+), 61 deletions(-)
create mode 100644 sysdeps/generic/math-use-builtins.h
create mode 100644 sysdeps/s390/fpu/math-use-builtins.h
diff --git a/sysdeps/generic/math-use-builtins.h b/sysdeps/generic/math-use-builtins.h
new file mode 100644
index 0000000000..e12490ed41
--- /dev/null
+++ b/sysdeps/generic/math-use-builtins.h
@@ -0,0 +1,29 @@
+/* Using math gcc builtins instead of generic implementation. Generic version.
+ Copyright (C) 2019 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#ifndef MATH_USE_BUILTINS_H
+#define MATH_USE_BUILTINS_H 1
+
+/* Define these macros to 1 to use __builtin_xyz instead of the
+ generic implementation. */
+#define USE_NEARBYINT_BUILTIN 0
+#define USE_NEARBYINTF_BUILTIN 0
+#define USE_NEARBYINTL_BUILTIN 0
+#define USE_NEARBYINTF128_BUILTIN 0
+
+#endif /* math-use-builtins.h */
diff --git a/sysdeps/ieee754/dbl-64/s_nearbyint.c b/sysdeps/ieee754/dbl-64/s_nearbyint.c
index c261885c5a..08a148e21e 100644
--- a/sysdeps/ieee754/dbl-64/s_nearbyint.c
+++ b/sysdeps/ieee754/dbl-64/s_nearbyint.c
@@ -26,16 +26,23 @@
#include <math_private.h>
#include <fenv_private.h>
#include <libm-alias-double.h>
+#include <math-use-builtins.h>
+#if ! USE_NEARBYINT_BUILTIN
static const double
TWO52[2] = {
4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
-4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */
};
+#endif
double
__nearbyint (double x)
{
+#if USE_NEARBYINT_BUILTIN
+ return __builtin_nearbyint (x);
+#else
+ /* Use generic implementation. */
fenv_t env;
int64_t i0, sx;
int32_t j0;
@@ -67,5 +74,6 @@ __nearbyint (double x)
math_force_eval (t);
libc_fesetenv (&env);
return t;
+#endif /* USE_NEARBYINT_BUILTIN */
}
libm_alias_double (__nearbyint, nearbyint)
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..d31bbdd19a 100644
--- a/sysdeps/ieee754/flt-32/s_nearbyintf.c
+++ b/sysdeps/ieee754/flt-32/s_nearbyintf.c
@@ -21,42 +21,56 @@
#include <math_private.h>
#include <fenv_private.h>
#include <libm-alias-float.h>
+#include <math-use-builtins.h>
+#if ! USE_NEARBYINTF_BUILTIN
static const float
-TWO23[2]={
- 8.3886080000e+06, /* 0x4b000000 */
- -8.3886080000e+06, /* 0xcb000000 */
+TWO23[2] = {
+ 8.3886080000e+06, /* 0x4b000000 */
+ -8.3886080000e+06, /* 0xcb000000 */
};
+#endif
float
-__nearbyintf(float x)
+__nearbyintf (float x)
{
- fenv_t env;
- int32_t i0,j0,sx;
- float w,t;
- GET_FLOAT_WORD(i0,x);
- sx = (i0>>31)&1;
- j0 = ((i0>>23)&0xff)-0x7f;
- if(j0<23) {
- if(j0<0) {
- libc_feholdexceptf (&env);
- w = TWO23[sx] + math_opt_barrier (x);
- t = w-TWO23[sx];
- math_force_eval (t);
- libc_fesetenvf (&env);
- GET_FLOAT_WORD(i0,t);
- SET_FLOAT_WORD(t,(i0&0x7fffffff)|(sx<<31));
- return t;
- }
- } else {
- if(__builtin_expect(j0==0x80, 0)) return x+x; /* inf or NaN */
- else return x; /* x is integral */
+#if USE_NEARBYINTF_BUILTIN
+ return __builtin_nearbyintf (x);
+#else
+ /* Use generic implementation. */
+ fenv_t env;
+ int32_t i0, j0, sx;
+ float w, t;
+ GET_FLOAT_WORD (i0, x);
+ sx = (i0 >> 31) & 1;
+ j0 = ((i0 >> 23) & 0xff) - 0x7f;
+ if (j0 < 23)
+ {
+ if (j0 < 0)
+ {
+ libc_feholdexceptf (&env);
+ w = TWO23[sx] + math_opt_barrier (x);
+ t = w - TWO23[sx];
+ math_force_eval (t);
+ libc_fesetenvf (&env);
+ GET_FLOAT_WORD (i0, t);
+ SET_FLOAT_WORD (t, (i0 & 0x7fffffff) | (sx << 31));
+ return t;
}
- libc_feholdexceptf (&env);
- w = TWO23[sx] + math_opt_barrier (x);
- t = w-TWO23[sx];
- math_force_eval (t);
- libc_fesetenvf (&env);
- return t;
+ }
+ else
+ {
+ if (__glibc_unlikely (j0 == 0x80))
+ return x + x; /* inf or NaN */
+ else
+ return x; /* x is integral */
+ }
+ libc_feholdexceptf (&env);
+ w = TWO23[sx] + math_opt_barrier (x);
+ t = w - TWO23[sx];
+ math_force_eval (t);
+ libc_fesetenvf (&env);
+ return t;
+#endif /* USE_NEARBYINT_BUILTIN */
}
libm_alias_float (__nearbyint, nearbyint)
diff --git a/sysdeps/ieee754/ldbl-128/s_nearbyintl.c b/sysdeps/ieee754/ldbl-128/s_nearbyintl.c
index f044cb4334..8f3a7e8e6b 100644
--- a/sysdeps/ieee754/ldbl-128/s_nearbyintl.c
+++ b/sysdeps/ieee754/ldbl-128/s_nearbyintl.c
@@ -28,42 +28,56 @@
#include <math-barriers.h>
#include <math_private.h>
#include <libm-alias-ldouble.h>
+#include <math-use-builtins.h>
+#if ! USE_NEARBYINTL_BUILTIN
static const _Float128
-TWO112[2]={
- L(5.19229685853482762853049632922009600E+33), /* 0x406F000000000000, 0 */
- L(-5.19229685853482762853049632922009600E+33) /* 0xC06F000000000000, 0 */
+TWO112[2] = {
+ L(5.19229685853482762853049632922009600E+33), /* 0x406F000000000000, 0 */
+ L(-5.19229685853482762853049632922009600E+33) /* 0xC06F000000000000, 0 */
};
+#endif
-_Float128 __nearbyintl(_Float128 x)
+_Float128 __nearbyintl (_Float128 x)
{
- fenv_t env;
- int64_t i0,j0,sx;
- uint64_t i1 __attribute__ ((unused));
- _Float128 w,t;
- GET_LDOUBLE_WORDS64(i0,i1,x);
- sx = (((uint64_t)i0)>>63);
- j0 = ((i0>>48)&0x7fff)-0x3fff;
- if(j0<112) {
- if(j0<0) {
- feholdexcept (&env);
- w = TWO112[sx] + math_opt_barrier (x);
- t = w-TWO112[sx];
- math_force_eval (t);
- fesetenv (&env);
- GET_LDOUBLE_MSW64(i0,t);
- SET_LDOUBLE_MSW64(t,(i0&0x7fffffffffffffffLL)|(sx<<63));
- return t;
- }
- } else {
- if(j0==0x4000) return x+x; /* inf or NaN */
- else return x; /* x is integral */
+#if USE_NEARBYINTL_BUILTIN
+ return __builtin_nearbyintl (x);
+#else
+ /* Use generic implementation. */
+ fenv_t env;
+ int64_t i0, j0, sx;
+ uint64_t i1 __attribute__ ((unused));
+ _Float128 w, t;
+ GET_LDOUBLE_WORDS64 (i0, i1, x);
+ sx = (((uint64_t) i0) >> 63);
+ j0 = ((i0 >> 48) & 0x7fff) - 0x3fff;
+ if (j0 < 112)
+ {
+ if (j0 < 0)
+ {
+ feholdexcept (&env);
+ w = TWO112[sx] + math_opt_barrier (x);
+ t = w - TWO112[sx];
+ math_force_eval (t);
+ fesetenv (&env);
+ GET_LDOUBLE_MSW64 (i0, t);
+ SET_LDOUBLE_MSW64 (t, (i0 & 0x7fffffffffffffffLL) | (sx << 63));
+ return t;
}
- feholdexcept (&env);
- w = TWO112[sx] + math_opt_barrier (x);
- t = w-TWO112[sx];
- math_force_eval (t);
- fesetenv (&env);
- return t;
+ }
+ else
+ {
+ if (j0 == 0x4000)
+ return x + x; /* inf or NaN */
+ else
+ return x; /* x is integral */
+ }
+ feholdexcept (&env);
+ w = TWO112[sx] + math_opt_barrier (x);
+ t = w - TWO112[sx];
+ math_force_eval (t);
+ fesetenv (&env);
+ return t;
+#endif /* USE_NEARBYINTL_BUILTIN */
}
libm_alias_ldouble (__nearbyint, nearbyint)
diff --git a/sysdeps/s390/fpu/math-use-builtins.h b/sysdeps/s390/fpu/math-use-builtins.h
new file mode 100644
index 0000000000..fd9da8893e
--- /dev/null
+++ b/sysdeps/s390/fpu/math-use-builtins.h
@@ -0,0 +1,45 @@
+/* Using math gcc builtins instead of generic implementation. s390/s390x version.
+ Copyright (C) 2019 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#ifndef MATH_USE_BUILTINS_S390_H
+#define MATH_USE_BUILTINS_S390_H 1
+
+#ifdef HAVE_S390_MIN_Z196_ZARCH_ASM_SUPPORT
+
+# include <features.h> /* For __GNUC_PREREQ. */
+
+/* GCC emits the z196 zarch "load fp integer" instructions for these
+ builtins if build with at least --march=z196 -mzarch. Otherwise a
+ function call to libc is emitted. */
+# define USE_NEARBYINT_BUILTIN 1
+# define USE_NEARBYINTF_BUILTIN 1
+# define USE_NEARBYINTL_BUILTIN 1
+
+# if __GNUC_PREREQ (8, 1)
+# define USE_NEARBYINTF128_BUILTIN 1
+# else
+# define USE_NEARBYINTF128_BUILTIN 0
+# endif
+
+#else
+
+# include_next <math-use-builtins.h>
+
+#endif
+
+#endif /* math-use-builtins.h */
--
2.19.1
^ permalink raw reply [flat|nested] 35+ messages in thread
* [PATCH 02/13] Always use wordsize-64 version of s_rint.c.
2019-12-02 14:46 [PATCH 00/13] Use GCC builtins for some math functions if desired Stefan Liebler
` (4 preceding siblings ...)
2019-12-02 14:46 ` [PATCH 05/13] Always use wordsize-64 version of s_trunc.c Stefan Liebler
@ 2019-12-02 14:46 ` Stefan Liebler
2019-12-05 20:40 ` Adhemerval Zanella
2019-12-02 14:46 ` [PATCH 08/13] Use GCC builtins for rint functions if desired Stefan Liebler
` (7 subsequent siblings)
13 siblings, 1 reply; 35+ messages in thread
From: Stefan Liebler @ 2019-12-02 14:46 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 | 36 ++++++-------
sysdeps/ieee754/dbl-64/wordsize-64/s_rint.c | 58 ---------------------
sysdeps/x86_64/fpu/multiarch/s_rint-c.c | 2 +-
3 files changed, 19 insertions(+), 77 deletions(-)
delete mode 100644 sysdeps/ieee754/dbl-64/wordsize-64/s_rint.c
diff --git a/sysdeps/ieee754/dbl-64/s_rint.c b/sysdeps/ieee754/dbl-64/s_rint.c
index dd01a84176..f96078c405 100644
--- a/sysdeps/ieee754/dbl-64/s_rint.c
+++ b/sysdeps/ieee754/dbl-64/s_rint.c
@@ -1,4 +1,3 @@
-/* @(#)s_rint.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
@@ -26,38 +25,39 @@
#include <libm-alias-double.h>
static const double
- TWO52[2] = {
- 4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
- -4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */
+TWO52[2] = {
+ 4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
+ -4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */
};
double
__rint (double x)
{
- int32_t i0, j0, sx;
- double w, t;
- GET_HIGH_WORD (i0, x);
- sx = (i0 >> 31) & 1;
- j0 = ((i0 >> 20) & 0x7ff) - 0x3ff;
+ int64_t i0, sx;
+ int32_t j0;
+ EXTRACT_WORDS64 (i0, x);
+ sx = (i0 >> 63) & 1;
+ j0 = ((i0 >> 52) & 0x7ff) - 0x3ff;
if (j0 < 52)
{
if (j0 < 0)
{
- w = TWO52[sx] + x;
- t = w - TWO52[sx];
- GET_HIGH_WORD (i0, t);
- SET_HIGH_WORD (t, (i0 & 0x7fffffff) | (sx << 31));
- return t;
+ double w = TWO52[sx] + x;
+ double t = w - TWO52[sx];
+ EXTRACT_WORDS64 (i0, t);
+ INSERT_WORDS64 (t, (i0 & UINT64_C (0x7fffffffffffffff))
+ | (sx << 63));
+ return t;
}
}
else
{
if (j0 == 0x400)
- return x + x; /* inf or NaN */
+ return x + x; /* inf or NaN */
else
- return x; /* x is integral */
- }
- w = TWO52[sx] + x;
+ return x; /* x is integral */
+ }
+ double w = TWO52[sx] + x;
return w - TWO52[sx];
}
#ifndef __rint
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] 35+ messages in thread
* [PATCH 05/13] Always use wordsize-64 version of s_trunc.c.
2019-12-02 14:46 [PATCH 00/13] Use GCC builtins for some math functions if desired Stefan Liebler
` (3 preceding siblings ...)
2019-12-02 14:46 ` [PATCH 01/13] Always use wordsize-64 version of s_nearbyint.c Stefan Liebler
@ 2019-12-02 14:46 ` Stefan Liebler
2019-12-05 20:40 ` Adhemerval Zanella
2019-12-02 14:46 ` [PATCH 02/13] Always use wordsize-64 version of s_rint.c Stefan Liebler
` (8 subsequent siblings)
13 siblings, 1 reply; 35+ messages in thread
From: Stefan Liebler @ 2019-12-02 14:46 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] 35+ messages in thread
* [PATCH 03/13] Always use wordsize-64 version of s_floor.c.
2019-12-02 14:46 [PATCH 00/13] Use GCC builtins for some math functions if desired Stefan Liebler
2019-12-02 14:46 ` [PATCH 09/13] Use GCC builtins for floor " Stefan Liebler
@ 2019-12-02 14:46 ` Stefan Liebler
2019-12-05 20:40 ` Adhemerval Zanella
2019-12-02 14:46 ` [PATCH 07/13] Use GCC builtins for nearbyint functions if desired Stefan Liebler
` (11 subsequent siblings)
13 siblings, 1 reply; 35+ messages in thread
From: Stefan Liebler @ 2019-12-02 14:46 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] 35+ messages in thread
* [PATCH 11/13] Use GCC builtins for trunc functions if desired.
2019-12-02 14:46 [PATCH 00/13] Use GCC builtins for some math functions if desired Stefan Liebler
` (6 preceding siblings ...)
2019-12-02 14:46 ` [PATCH 08/13] Use GCC builtins for rint functions if desired Stefan Liebler
@ 2019-12-02 15:10 ` Stefan Liebler
2019-12-05 20:40 ` Adhemerval Zanella
2019-12-02 15:15 ` [PATCH 04/13] Always use wordsize-64 version of s_ceil.c Stefan Liebler
` (5 subsequent siblings)
13 siblings, 1 reply; 35+ messages in thread
From: Stefan Liebler @ 2019-12-02 15:10 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.
---
sysdeps/generic/math-use-builtins.h | 5 +++++
sysdeps/ieee754/dbl-64/s_trunc.c | 6 +++++-
sysdeps/ieee754/float128/float128_private.h | 3 +++
sysdeps/ieee754/flt-32/s_truncf.c | 6 +++++-
sysdeps/ieee754/ldbl-128/s_truncl.c | 6 +++++-
sysdeps/s390/fpu/math-use-builtins.h | 6 ++++++
6 files changed, 29 insertions(+), 3 deletions(-)
diff --git a/sysdeps/generic/math-use-builtins.h b/sysdeps/generic/math-use-builtins.h
index 076ec661b0..ab379f45ba 100644
--- a/sysdeps/generic/math-use-builtins.h
+++ b/sysdeps/generic/math-use-builtins.h
@@ -41,4 +41,9 @@
#define USE_CEILL_BUILTIN 0
#define USE_CEILF128_BUILTIN 0
+#define USE_TRUNC_BUILTIN 0
+#define USE_TRUNCF_BUILTIN 0
+#define USE_TRUNCL_BUILTIN 0
+#define USE_TRUNCF128_BUILTIN 0
+
#endif /* math-use-builtins.h */
diff --git a/sysdeps/ieee754/dbl-64/s_trunc.c b/sysdeps/ieee754/dbl-64/s_trunc.c
index 0de68ce298..6189ba4a31 100644
--- a/sysdeps/ieee754/dbl-64/s_trunc.c
+++ b/sysdeps/ieee754/dbl-64/s_trunc.c
@@ -22,11 +22,14 @@
#include <math_private.h>
#include <libm-alias-double.h>
-
+#include <math-use-builtins.h>
double
__trunc (double x)
{
+#if USE_TRUNC_BUILTIN
+ return __builtin_trunc (x);
+#else
int64_t i0, j0;
int64_t sx;
@@ -49,6 +52,7 @@ __trunc (double x)
}
return x;
+#endif /* USE_TRUNC_BUILTIN */
}
#ifndef __trunc
libm_alias_double (__trunc, trunc)
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..de6dc24a3f 100644
--- a/sysdeps/ieee754/flt-32/s_truncf.c
+++ b/sysdeps/ieee754/flt-32/s_truncf.c
@@ -22,11 +22,14 @@
#include <math_private.h>
#include <libm-alias-float.h>
-
+#include <math-use-builtins.h>
float
__truncf (float x)
{
+#if USE_TRUNCF_BUILTIN
+ return __builtin_truncf (x);
+#else
int32_t i0, j0;
int sx;
@@ -49,6 +52,7 @@ __truncf (float x)
}
return x;
+#endif /* USE_TRUNCF_BUILTIN */
}
#ifndef __truncf
libm_alias_float (__trunc, trunc)
diff --git a/sysdeps/ieee754/ldbl-128/s_truncl.c b/sysdeps/ieee754/ldbl-128/s_truncl.c
index de4dd34d59..ca62e2f970 100644
--- a/sysdeps/ieee754/ldbl-128/s_truncl.c
+++ b/sysdeps/ieee754/ldbl-128/s_truncl.c
@@ -23,11 +23,14 @@
#include <math_private.h>
#include <libm-alias-ldouble.h>
-
+#include <math-use-builtins.h>
_Float128
__truncl (_Float128 x)
{
+#if USE_TRUNCL_BUILTIN
+ return __builtin_truncl (x);
+#else
int32_t j0;
uint64_t i0, i1, sx;
@@ -54,5 +57,6 @@ __truncl (_Float128 x)
}
return x;
+#endif /* USE_TRUNCL_BUILTIN */
}
libm_alias_ldouble (__trunc, trunc)
diff --git a/sysdeps/s390/fpu/math-use-builtins.h b/sysdeps/s390/fpu/math-use-builtins.h
index dc364edaa8..1d88a2c40f 100644
--- a/sysdeps/s390/fpu/math-use-builtins.h
+++ b/sysdeps/s390/fpu/math-use-builtins.h
@@ -42,16 +42,22 @@
# define USE_CEILF_BUILTIN 1
# define USE_CEILL_BUILTIN 1
+# define USE_TRUNC_BUILTIN 1
+# define USE_TRUNCF_BUILTIN 1
+# define USE_TRUNCL_BUILTIN 1
+
# if __GNUC_PREREQ (8, 1)
# define USE_NEARBYINTF128_BUILTIN 1
# define USE_RINTF128_BUILTIN 1
# define USE_FLOORF128_BUILTIN 1
# define USE_CEILF128_BUILTIN 1
+# define USE_TRUNCF128_BUILTIN 1
# else
# define USE_NEARBYINTF128_BUILTIN 0
# define USE_RINTF128_BUILTIN 0
# define USE_FLOORF128_BUILTIN 0
# define USE_CEILF128_BUILTIN 0
+# define USE_TRUNCF128_BUILTIN 0
# endif
#else
--
2.19.1
^ permalink raw reply [flat|nested] 35+ messages in thread
* [PATCH 04/13] Always use wordsize-64 version of s_ceil.c.
2019-12-02 14:46 [PATCH 00/13] Use GCC builtins for some math functions if desired Stefan Liebler
` (7 preceding siblings ...)
2019-12-02 15:10 ` [PATCH 11/13] Use GCC builtins for trunc " Stefan Liebler
@ 2019-12-02 15:15 ` Stefan Liebler
2019-12-05 20:40 ` Adhemerval Zanella
2019-12-02 15:18 ` [PATCH 10/13] Use GCC builtins for ceil functions if desired Stefan Liebler
` (4 subsequent siblings)
13 siblings, 1 reply; 35+ messages in thread
From: Stefan Liebler @ 2019-12-02 15:15 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 | 61 ++++++-------------
sysdeps/ieee754/dbl-64/wordsize-64/s_ceil.c | 52 ----------------
.../sparc64/fpu/multiarch/s_ceil-generic.c | 2 +-
.../sparc/sparc64/fpu/multiarch/s_ceil-vis3.c | 2 +-
sysdeps/x86_64/fpu/multiarch/s_ceil-c.c | 2 +-
5 files changed, 22 insertions(+), 97 deletions(-)
delete mode 100644 sysdeps/ieee754/dbl-64/wordsize-64/s_ceil.c
diff --git a/sysdeps/ieee754/dbl-64/s_ceil.c b/sysdeps/ieee754/dbl-64/s_ceil.c
index 4c96286c69..9d214eac81 100644
--- a/sysdeps/ieee754/dbl-64/s_ceil.c
+++ b/sysdeps/ieee754/dbl-64/s_ceil.c
@@ -23,63 +23,40 @@
#include <libm-alias-double.h>
double
-__ceil (double x)
+__ceil(double x)
{
- int32_t i0, i1, j0;
- uint32_t i, j;
- EXTRACT_WORDS (i0, i1, x);
- j0 = ((i0 >> 20) & 0x7ff) - 0x3ff;
- if (j0 < 20)
+ int64_t i0, i;
+ int32_t j0;
+ EXTRACT_WORDS64 (i0, x);
+ j0 = ((i0 >> 52) & 0x7ff) - 0x3ff;
+ if (j0 <= 51)
{
if (j0 < 0)
{
- /* return 0*sign(x) if |x|<1 */
+ /* return 0 * sign(x) if |x| < 1 */
if (i0 < 0)
- {
- i0 = 0x80000000; i1 = 0;
- }
- else if ((i0 | i1) != 0)
- {
- i0 = 0x3ff00000; i1 = 0;
- }
+ i0 = INT64_C (0x8000000000000000);
+ else if (i0 != 0)
+ i0 = INT64_C (0x3ff0000000000000);
}
else
{
- i = (0x000fffff) >> j0;
- if (((i0 & i) | i1) == 0)
- return x; /* x is integral */
+ i = INT64_C (0x000fffffffffffff) >> j0;
+ if ((i0 & i) == 0)
+ return x; /* x is integral */
if (i0 > 0)
- i0 += (0x00100000) >> j0;
- i0 &= (~i); i1 = 0;
+ i0 += UINT64_C (0x0010000000000000) >> j0;
+ i0 &= ~i;
}
}
- else if (j0 > 51)
+ else
{
if (j0 == 0x400)
- return x + x; /* inf or NaN */
+ return x + x; /* inf or NaN */
else
- return x; /* x is integral */
- }
- else
- {
- i = ((uint32_t) (0xffffffff)) >> (j0 - 20);
- if ((i1 & i) == 0)
- return x; /* x is integral */
- if (i0 > 0)
- {
- if (j0 == 20)
- i0 += 1;
- else
- {
- j = i1 + (1 << (52 - j0));
- if (j < i1)
- i0 += 1; /* got a carry */
- i1 = j;
- }
- }
- i1 &= (~i);
+ return x; /* x is integral */
}
- INSERT_WORDS (x, i0, i1);
+ INSERT_WORDS64 (x, i0);
return x;
}
#ifndef __ceil
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] 35+ messages in thread
* [PATCH 10/13] Use GCC builtins for ceil functions if desired.
2019-12-02 14:46 [PATCH 00/13] Use GCC builtins for some math functions if desired Stefan Liebler
` (8 preceding siblings ...)
2019-12-02 15:15 ` [PATCH 04/13] Always use wordsize-64 version of s_ceil.c Stefan Liebler
@ 2019-12-02 15:18 ` Stefan Liebler
2019-12-05 20:40 ` Adhemerval Zanella
2019-12-02 15:46 ` [PATCH 06/13] Always use wordsize-64 version of s_round.c Stefan Liebler
` (3 subsequent siblings)
13 siblings, 1 reply; 35+ messages in thread
From: Stefan Liebler @ 2019-12-02 15:18 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 except changes in code style.
---
sysdeps/generic/math-use-builtins.h | 5 ++
sysdeps/ieee754/dbl-64/s_ceil.c | 7 +-
sysdeps/ieee754/float128/float128_private.h | 3 +
sysdeps/ieee754/flt-32/s_ceilf.c | 60 ++++++++-----
sysdeps/ieee754/ldbl-128/s_ceill.c | 97 ++++++++++++++-------
sysdeps/s390/fpu/math-use-builtins.h | 6 ++
6 files changed, 123 insertions(+), 55 deletions(-)
diff --git a/sysdeps/generic/math-use-builtins.h b/sysdeps/generic/math-use-builtins.h
index e1c5df62e4..076ec661b0 100644
--- a/sysdeps/generic/math-use-builtins.h
+++ b/sysdeps/generic/math-use-builtins.h
@@ -36,4 +36,9 @@
#define USE_FLOORL_BUILTIN 0
#define USE_FLOORF128_BUILTIN 0
+#define USE_CEIL_BUILTIN 0
+#define USE_CEILF_BUILTIN 0
+#define USE_CEILL_BUILTIN 0
+#define USE_CEILF128_BUILTIN 0
+
#endif /* math-use-builtins.h */
diff --git a/sysdeps/ieee754/dbl-64/s_ceil.c b/sysdeps/ieee754/dbl-64/s_ceil.c
index 9d214eac81..c0ba9e8a73 100644
--- a/sysdeps/ieee754/dbl-64/s_ceil.c
+++ b/sysdeps/ieee754/dbl-64/s_ceil.c
@@ -21,10 +21,14 @@
#include <math.h>
#include <math_private.h>
#include <libm-alias-double.h>
+#include <math-use-builtins.h>
double
-__ceil(double x)
+__ceil (double x)
{
+#if USE_CEIL_BUILTIN
+ return __builtin_ceil (x);
+#else
int64_t i0, i;
int32_t j0;
EXTRACT_WORDS64 (i0, x);
@@ -58,6 +62,7 @@ __ceil(double x)
}
INSERT_WORDS64 (x, i0);
return x;
+#endif /* USE_CEIL_BUILTIN */
}
#ifndef __ceil
libm_alias_double (__ceil, ceil)
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..4a7ce45800 100644
--- a/sysdeps/ieee754/flt-32/s_ceilf.c
+++ b/sysdeps/ieee754/flt-32/s_ceilf.c
@@ -17,33 +17,49 @@
#include <math.h>
#include <math_private.h>
#include <libm-alias-float.h>
-
+#include <math-use-builtins.h>
float
-__ceilf(float x)
+__ceilf (float x)
{
- int32_t i0,j0;
- uint32_t i;
+#if USE_CEILF_BUILTIN
+ return __builtin_ceilf (x);
+#else
+ int32_t i0, j0;
+ uint32_t i;
- GET_FLOAT_WORD(i0,x);
- j0 = ((i0>>23)&0xff)-0x7f;
- if(j0<23) {
- if(j0<0) {
- /* return 0*sign(x) if |x|<1 */
- if(i0<0) {i0=0x80000000;}
- else if(i0!=0) { i0=0x3f800000;}
- } else {
- i = (0x007fffff)>>j0;
- if((i0&i)==0) return x; /* x is integral */
- if(i0>0) i0 += (0x00800000)>>j0;
- i0 &= (~i);
- }
- } else {
- if(__builtin_expect(j0==0x80, 0)) return x+x; /* inf or NaN */
- else return x; /* x is integral */
+ GET_FLOAT_WORD (i0, x);
+ j0 = ((i0 >> 23) & 0xff) - 0x7f;
+ if (j0 < 23)
+ {
+ if (j0 < 0)
+ {
+ /* return 0 * sign (x) if |x| < 1 */
+ if (i0 < 0)
+ i0 = 0x80000000;
+ else if (i0 != 0)
+ i0 = 0x3f800000;
+ }
+ else
+ {
+ i = (0x007fffff) >> j0;
+ if ((i0 & i) == 0)
+ return x; /* x is integral */
+ if (i0 > 0)
+ i0 += (0x00800000) >> j0;
+ i0 &= (~i);
}
- SET_FLOAT_WORD(x,i0);
- return x;
+ }
+ else
+ {
+ if (__glibc_unlikely (j0 == 0x80))
+ return x + x; /* inf or NaN */
+ else
+ return x; /* x is integral */
+ }
+ SET_FLOAT_WORD (x, i0);
+ return x;
+#endif /* USE_CEILF_BUILTIN */
}
#ifndef __ceilf
libm_alias_float (__ceil, ceil)
diff --git a/sysdeps/ieee754/ldbl-128/s_ceill.c b/sysdeps/ieee754/ldbl-128/s_ceill.c
index 2ec55de25a..019f9fd950 100644
--- a/sysdeps/ieee754/ldbl-128/s_ceill.c
+++ b/sysdeps/ieee754/ldbl-128/s_ceill.c
@@ -13,7 +13,9 @@
* ====================================================
*/
-#if defined(LIBM_SCCS) && !defined(lint)
+#include <math-use-builtins.h>
+
+#if ! USE_CEILL_BUILTIN && defined (LIBM_SCCS) && ! defined (lint)
static char rcsid[] = "$NetBSD: $";
#endif
@@ -29,40 +31,71 @@ static char rcsid[] = "$NetBSD: $";
#include <math_private.h>
#include <libm-alias-ldouble.h>
-_Float128 __ceill(_Float128 x)
+_Float128
+__ceill (_Float128 x)
{
- int64_t i0,i1,j0;
- uint64_t i,j;
- GET_LDOUBLE_WORDS64(i0,i1,x);
- j0 = ((i0>>48)&0x7fff)-0x3fff;
- if(j0<48) {
- if(j0<0) {
- /* return 0*sign(x) if |x|<1 */
- if(i0<0) {i0=0x8000000000000000ULL;i1=0;}
- else if((i0|i1)!=0) { i0=0x3fff000000000000ULL;i1=0;}
- } else {
- i = (0x0000ffffffffffffULL)>>j0;
- if(((i0&i)|i1)==0) return x; /* x is integral */
- if(i0>0) i0 += (0x0001000000000000LL)>>j0;
- i0 &= (~i); i1=0;
+#if USE_CEILL_BUILTIN
+ return __builtin_ceill (x);
+#else
+ int64_t i0, i1, j0;
+ uint64_t i, j;
+ GET_LDOUBLE_WORDS64 (i0, i1, x);
+ j0 = ((i0 >> 48) & 0x7fff) - 0x3fff;
+ if (j0 < 48)
+ {
+ if (j0 < 0)
+ {
+ /* return 0 * sign (x) if |x| < 1 */
+ if (i0 < 0)
+ {
+ i0 = 0x8000000000000000ULL;
+ i1 = 0;
+ }
+ else if ((i0 | i1) != 0)
+ {
+ i0 = 0x3fff000000000000ULL;
+ i1 = 0;
}
- } else if (j0>111) {
- if(j0==0x4000) return x+x; /* inf or NaN */
- else return x; /* x is integral */
- } else {
- i = -1ULL>>(j0-48);
- if((i1&i)==0) return x; /* x is integral */
- if(i0>0) {
- if(j0==48) i0+=1;
- else {
- j = i1+(1LL<<(112-j0));
- if(j<i1) i0 +=1 ; /* got a carry */
- i1=j;
- }
+ }
+ else
+ {
+ i = (0x0000ffffffffffffULL) >> j0;
+ if (((i0 & i) | i1) == 0)
+ return x; /* x is integral */
+ if (i0 > 0)
+ i0 += (0x0001000000000000LL) >> j0;
+ i0 &= (~i);
+ i1 = 0;
+ }
+ }
+ else if (j0 > 111)
+ {
+ if (j0 == 0x4000)
+ return x + x; /* inf or NaN */
+ else
+ return x; /* x is integral */
+ }
+ else
+ {
+ i = -1ULL >> (j0 - 48);
+ if ((i1 & i) == 0)
+ return x; /* x is integral */
+ if (i0 > 0)
+ {
+ if (j0 == 48)
+ i0 += 1;
+ else
+ {
+ j = i1 + (1LL << (112 - j0));
+ if (j < i1)
+ i0 += 1; /* got a carry */
+ i1 = j;
}
- i1 &= (~i);
}
- SET_LDOUBLE_WORDS64(x,i0,i1);
- return x;
+ i1 &= (~i);
+ }
+ SET_LDOUBLE_WORDS64 (x, i0, i1);
+ return x;
+#endif /* USE_CEILL_BUILTIN */
}
libm_alias_ldouble (__ceil, ceil)
diff --git a/sysdeps/s390/fpu/math-use-builtins.h b/sysdeps/s390/fpu/math-use-builtins.h
index 63cc9d7a23..dc364edaa8 100644
--- a/sysdeps/s390/fpu/math-use-builtins.h
+++ b/sysdeps/s390/fpu/math-use-builtins.h
@@ -38,14 +38,20 @@
# define USE_FLOORF_BUILTIN 1
# define USE_FLOORL_BUILTIN 1
+# define USE_CEIL_BUILTIN 1
+# define USE_CEILF_BUILTIN 1
+# define USE_CEILL_BUILTIN 1
+
# if __GNUC_PREREQ (8, 1)
# define USE_NEARBYINTF128_BUILTIN 1
# define USE_RINTF128_BUILTIN 1
# define USE_FLOORF128_BUILTIN 1
+# define USE_CEILF128_BUILTIN 1
# else
# define USE_NEARBYINTF128_BUILTIN 0
# define USE_RINTF128_BUILTIN 0
# define USE_FLOORF128_BUILTIN 0
+# define USE_CEILF128_BUILTIN 0
# endif
#else
--
2.19.1
^ permalink raw reply [flat|nested] 35+ messages in thread
* [PATCH 06/13] Always use wordsize-64 version of s_round.c.
2019-12-02 14:46 [PATCH 00/13] Use GCC builtins for some math functions if desired Stefan Liebler
` (9 preceding siblings ...)
2019-12-02 15:18 ` [PATCH 10/13] Use GCC builtins for ceil functions if desired Stefan Liebler
@ 2019-12-02 15:46 ` Stefan Liebler
2019-12-05 20:40 ` Adhemerval Zanella
2019-12-02 15:50 ` [PATCH 12/13] Use GCC builtins for round functions if desired Stefan Liebler
` (2 subsequent siblings)
13 siblings, 1 reply; 35+ messages in thread
From: Stefan Liebler @ 2019-12-02 15:46 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] 35+ messages in thread
* [PATCH 12/13] Use GCC builtins for round functions if desired.
2019-12-02 14:46 [PATCH 00/13] Use GCC builtins for some math functions if desired Stefan Liebler
` (10 preceding siblings ...)
2019-12-02 15:46 ` [PATCH 06/13] Always use wordsize-64 version of s_round.c Stefan Liebler
@ 2019-12-02 15:50 ` Stefan Liebler
2019-12-05 20:41 ` Adhemerval Zanella
2019-12-02 15:52 ` [PATCH 13/13] Use GCC builtins for copysign " Stefan Liebler
2019-12-09 12:58 ` [PATCH 00/13] Use GCC builtins for some math " Stefan Liebler
13 siblings, 1 reply; 35+ messages in thread
From: Stefan Liebler @ 2019-12-02 15:50 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.
---
sysdeps/generic/math-use-builtins.h | 5 +++++
sysdeps/ieee754/dbl-64/s_round.c | 6 +++++-
sysdeps/ieee754/float128/float128_private.h | 3 +++
sysdeps/ieee754/flt-32/s_roundf.c | 6 +++++-
sysdeps/ieee754/ldbl-128/s_roundl.c | 6 +++++-
sysdeps/s390/fpu/math-use-builtins.h | 6 ++++++
6 files changed, 29 insertions(+), 3 deletions(-)
diff --git a/sysdeps/generic/math-use-builtins.h b/sysdeps/generic/math-use-builtins.h
index ab379f45ba..34ca438a8c 100644
--- a/sysdeps/generic/math-use-builtins.h
+++ b/sysdeps/generic/math-use-builtins.h
@@ -46,4 +46,9 @@
#define USE_TRUNCL_BUILTIN 0
#define USE_TRUNCF128_BUILTIN 0
+#define USE_ROUND_BUILTIN 0
+#define USE_ROUNDF_BUILTIN 0
+#define USE_ROUNDL_BUILTIN 0
+#define USE_ROUNDF128_BUILTIN 0
+
#endif /* math-use-builtins.h */
diff --git a/sysdeps/ieee754/dbl-64/s_round.c b/sysdeps/ieee754/dbl-64/s_round.c
index 8f4b7cff86..00c8485efb 100644
--- a/sysdeps/ieee754/dbl-64/s_round.c
+++ b/sysdeps/ieee754/dbl-64/s_round.c
@@ -23,11 +23,14 @@
#include <math_private.h>
#include <libm-alias-double.h>
#include <stdint.h>
-
+#include <math-use-builtins.h>
double
__round (double x)
{
+#if USE_ROUND_BUILTIN
+ return __builtin_round (x);
+#else
int64_t i0, j0;
EXTRACT_WORDS64 (i0, x);
@@ -62,5 +65,6 @@ __round (double x)
INSERT_WORDS64 (x, i0);
return x;
+#endif /* USE_ROUND_BUILTIN */
}
libm_alias_double (__round, round)
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..33304b21f1 100644
--- a/sysdeps/ieee754/flt-32/s_roundf.c
+++ b/sysdeps/ieee754/flt-32/s_roundf.c
@@ -22,11 +22,14 @@
#include <math_private.h>
#include <libm-alias-float.h>
-
+#include <math-use-builtins.h>
float
__roundf (float x)
{
+#if USE_ROUNDF_BUILTIN
+ return __builtin_roundf (x);
+#else
int32_t i0, j0;
GET_FLOAT_WORD (i0, x);
@@ -61,5 +64,6 @@ __roundf (float x)
SET_FLOAT_WORD (x, i0);
return x;
+#endif /* USE_ROUNDF_BUILTIN */
}
libm_alias_float (__round, round)
diff --git a/sysdeps/ieee754/ldbl-128/s_roundl.c b/sysdeps/ieee754/ldbl-128/s_roundl.c
index d41c9a04dc..8d3f42cd42 100644
--- a/sysdeps/ieee754/ldbl-128/s_roundl.c
+++ b/sysdeps/ieee754/ldbl-128/s_roundl.c
@@ -23,11 +23,14 @@
#include <math_private.h>
#include <libm-alias-ldouble.h>
-
+#include <math-use-builtins.h>
_Float128
__roundl (_Float128 x)
{
+#if USE_ROUNDL_BUILTIN
+ return __builtin_roundl (x);
+#else
int32_t j0;
uint64_t i1, i0;
@@ -78,5 +81,6 @@ __roundl (_Float128 x)
SET_LDOUBLE_WORDS64 (x, i0, i1);
return x;
+#endif /* USE_ROUNDL_BUILTIN */
}
libm_alias_ldouble (__round, round)
diff --git a/sysdeps/s390/fpu/math-use-builtins.h b/sysdeps/s390/fpu/math-use-builtins.h
index 1d88a2c40f..5838a31c50 100644
--- a/sysdeps/s390/fpu/math-use-builtins.h
+++ b/sysdeps/s390/fpu/math-use-builtins.h
@@ -46,18 +46,24 @@
# define USE_TRUNCF_BUILTIN 1
# define USE_TRUNCL_BUILTIN 1
+# define USE_ROUND_BUILTIN 1
+# define USE_ROUNDF_BUILTIN 1
+# define USE_ROUNDL_BUILTIN 1
+
# if __GNUC_PREREQ (8, 1)
# define USE_NEARBYINTF128_BUILTIN 1
# define USE_RINTF128_BUILTIN 1
# define USE_FLOORF128_BUILTIN 1
# define USE_CEILF128_BUILTIN 1
# define USE_TRUNCF128_BUILTIN 1
+# define USE_ROUNDF128_BUILTIN 1
# else
# define USE_NEARBYINTF128_BUILTIN 0
# define USE_RINTF128_BUILTIN 0
# define USE_FLOORF128_BUILTIN 0
# define USE_CEILF128_BUILTIN 0
# define USE_TRUNCF128_BUILTIN 0
+# define USE_ROUNDF128_BUILTIN 0
# endif
#else
--
2.19.1
^ permalink raw reply [flat|nested] 35+ messages in thread
* [PATCH 13/13] Use GCC builtins for copysign functions if desired.
2019-12-02 14:46 [PATCH 00/13] Use GCC builtins for some math functions if desired Stefan Liebler
` (11 preceding siblings ...)
2019-12-02 15:50 ` [PATCH 12/13] Use GCC builtins for round functions if desired Stefan Liebler
@ 2019-12-02 15:52 ` Stefan Liebler
2019-12-02 21:00 ` Joseph Myers
2019-12-09 12:58 ` [PATCH 00/13] Use GCC builtins for some math " Stefan Liebler
13 siblings, 1 reply; 35+ messages in thread
From: Stefan Liebler @ 2019-12-02 15:52 UTC (permalink / raw)
To: libc-alpha; +Cc: Stefan Liebler
This patch is using the corresponding GCC builtin for copysignf, copysign,
copysignl and copysignf128 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.
Note: z196 is no typo but a bug in GCC!
---
sysdeps/generic/math-use-builtins.h | 5 +++++
sysdeps/ieee754/dbl-64/s_copysign.c | 8 ++++++-
sysdeps/ieee754/float128/float128_private.h | 3 +++
sysdeps/ieee754/flt-32/s_copysignf.c | 21 ++++++++++++-------
sysdeps/ieee754/ldbl-128/s_copysignl.c | 23 ++++++++++++++-------
sysdeps/s390/fpu/math-use-builtins.h | 9 ++++++++
6 files changed, 53 insertions(+), 16 deletions(-)
diff --git a/sysdeps/generic/math-use-builtins.h b/sysdeps/generic/math-use-builtins.h
index 34ca438a8c..a22d787791 100644
--- a/sysdeps/generic/math-use-builtins.h
+++ b/sysdeps/generic/math-use-builtins.h
@@ -51,4 +51,9 @@
#define USE_ROUNDL_BUILTIN 0
#define USE_ROUNDF128_BUILTIN 0
+#define USE_COPYSIGN_BUILTIN 0
+#define USE_COPYSIGNF_BUILTIN 0
+#define USE_COPYSIGNL_BUILTIN 0
+#define USE_COPYSIGNF128_BUILTIN 0
+
#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..0be1a6420f 100644
--- a/sysdeps/ieee754/dbl-64/s_copysign.c
+++ b/sysdeps/ieee754/dbl-64/s_copysign.c
@@ -10,7 +10,9 @@
* ====================================================
*/
-#if defined(LIBM_SCCS) && !defined(lint)
+#include <math-use-builtins.h>
+
+#if ! USE_COPYSIGN_BUILTIN && defined (LIBM_SCCS) && ! defined (lint)
static char rcsid[] = "$NetBSD: s_copysign.c,v 1.8 1995/05/10 20:46:57 jtc Exp $";
#endif
@@ -28,10 +30,14 @@ static char rcsid[] = "$NetBSD: s_copysign.c,v 1.8 1995/05/10 20:46:57 jtc Exp $
double
__copysign (double x, double y)
{
+#if USE_COPYSIGN_BUILTIN
+ return __builtin_copysign (x, y);
+#else
uint32_t hx, hy;
GET_HIGH_WORD (hx, x);
GET_HIGH_WORD (hy, y);
SET_HIGH_WORD (x, (hx & 0x7fffffff) | (hy & 0x80000000));
return x;
+#endif
}
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..9a9e6389cd 100644
--- a/sysdeps/ieee754/flt-32/s_copysignf.c
+++ b/sysdeps/ieee754/flt-32/s_copysignf.c
@@ -13,7 +13,9 @@
* ====================================================
*/
-#if defined(LIBM_SCCS) && !defined(lint)
+#include <math-use-builtins.h>
+
+#if ! USE_COPYSIGNF_BUILTIN && defined (LIBM_SCCS) && ! defined (lint)
static char rcsid[] = "$NetBSD: s_copysignf.c,v 1.4 1995/05/10 20:46:59 jtc Exp $";
#endif
@@ -28,12 +30,17 @@ static char rcsid[] = "$NetBSD: s_copysignf.c,v 1.4 1995/05/10 20:46:59 jtc Exp
#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;
+#if USE_COPYSIGNF_BUILTIN
+ return __builtin_copysignf (x, y);
+#else
+ uint32_t ix, iy;
+ GET_FLOAT_WORD (ix, x);
+ GET_FLOAT_WORD (iy, y);
+ SET_FLOAT_WORD (x, (ix & 0x7fffffff) | (iy & 0x80000000));
+ return x;
+#endif
}
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..6095b7fc73 100644
--- a/sysdeps/ieee754/ldbl-128/s_copysignl.c
+++ b/sysdeps/ieee754/ldbl-128/s_copysignl.c
@@ -13,7 +13,9 @@
* ====================================================
*/
-#if defined(LIBM_SCCS) && !defined(lint)
+#include <math-use-builtins.h>
+
+#if ! USE_COPYSIGNL_BUILTIN && defined (LIBM_SCCS) && ! defined (lint)
static char rcsid[] = "$NetBSD: $";
#endif
@@ -28,13 +30,18 @@ static char rcsid[] = "$NetBSD: $";
#include <math_private.h>
#include <libm-alias-ldouble.h>
-_Float128 __copysignl(_Float128 x, _Float128 y)
+_Float128
+__copysignl (_Float128 x, _Float128 y)
{
- uint64_t hx,hy;
- GET_LDOUBLE_MSW64(hx,x);
- GET_LDOUBLE_MSW64(hy,y);
- SET_LDOUBLE_MSW64(x,(hx&0x7fffffffffffffffULL)
- |(hy&0x8000000000000000ULL));
- return x;
+#if USE_COPYSIGNL_BUILTIN
+ return __builtin_copysignl (x, y);
+#else
+ 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
}
libm_alias_ldouble (__copysign, copysign)
diff --git a/sysdeps/s390/fpu/math-use-builtins.h b/sysdeps/s390/fpu/math-use-builtins.h
index 5838a31c50..ed2a05775f 100644
--- a/sysdeps/s390/fpu/math-use-builtins.h
+++ b/sysdeps/s390/fpu/math-use-builtins.h
@@ -50,6 +50,13 @@
# define USE_ROUNDF_BUILTIN 1
# define USE_ROUNDL_BUILTIN 1
+/* GCC emits the z9-ec zarch "copy sign" instruction for these
+ builtins if build with at least --march=z196 -mzarch.
+ Note: z196 is no typo but a bug in GCC! */
+# define USE_COPYSIGN_BUILTIN 1
+# define USE_COPYSIGNF_BUILTIN 1
+# define USE_COPYSIGNL_BUILTIN 1
+
# if __GNUC_PREREQ (8, 1)
# define USE_NEARBYINTF128_BUILTIN 1
# define USE_RINTF128_BUILTIN 1
@@ -57,6 +64,7 @@
# define USE_CEILF128_BUILTIN 1
# define USE_TRUNCF128_BUILTIN 1
# define USE_ROUNDF128_BUILTIN 1
+# define USE_COPYSIGNF128_BUILTIN 1
# else
# define USE_NEARBYINTF128_BUILTIN 0
# define USE_RINTF128_BUILTIN 0
@@ -64,6 +72,7 @@
# define USE_CEILF128_BUILTIN 0
# define USE_TRUNCF128_BUILTIN 0
# define USE_ROUNDF128_BUILTIN 0
+# define USE_COPYSIGNF128_BUILTIN 0
# endif
#else
--
2.19.1
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [PATCH 13/13] Use GCC builtins for copysign functions if desired.
2019-12-02 15:52 ` [PATCH 13/13] Use GCC builtins for copysign " Stefan Liebler
@ 2019-12-02 21:00 ` Joseph Myers
2019-12-03 8:27 ` Stefan Liebler
0 siblings, 1 reply; 35+ messages in thread
From: Joseph Myers @ 2019-12-02 21:00 UTC (permalink / raw)
To: Stefan Liebler; +Cc: libc-alpha
On Mon, 2 Dec 2019, Stefan Liebler wrote:
> This patch is using the corresponding GCC builtin for copysignf, copysign,
> copysignl and copysignf128 if the USE_FUNCTION_BUILTIN macros are defined to one
> in math-use-builtins.h.
I believe this is always safe for these implementations (the only case
where GCC might not expand copysign functions inline is copysignl for IBM
long double, in the soft-float case).
--
Joseph S. Myers
joseph@codesourcery.com
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [PATCH 13/13] Use GCC builtins for copysign functions if desired.
2019-12-02 21:00 ` Joseph Myers
@ 2019-12-03 8:27 ` Stefan Liebler
2019-12-03 16:51 ` Joseph Myers
0 siblings, 1 reply; 35+ messages in thread
From: Stefan Liebler @ 2019-12-03 8:27 UTC (permalink / raw)
To: Joseph Myers; +Cc: libc-alpha
On 12/2/19 10:00 PM, Joseph Myers wrote:
> On Mon, 2 Dec 2019, Stefan Liebler wrote:
>
>> This patch is using the corresponding GCC builtin for copysignf, copysign,
>> copysignl and copysignf128 if the USE_FUNCTION_BUILTIN macros are defined to one
>> in math-use-builtins.h.
>
> I believe this is always safe for these implementations (the only case
> where GCC might not expand copysign functions inline is copysignl for IBM
> long double, in the soft-float case).
>
Thus you mean we can do the following preset in
sysdeps/generic/math-use-builtins.h?
#define USE_COPYSIGN_BUILTIN 1
#define USE_COPYSIGNF_BUILTIN 1
#define USE_COPYSIGNL_BUILTIN 0
#define USE_COPYSIGNF128_BUILTIN 0
Or even also set USE_COPYSIGNL_BUILTIN to one as IBM long double has its
own implementation in ./sysdeps/ieee754/ldbl-128ibm/s_copysignl.c.
On the other hand, I'm not able to run tests on the different
architectures. Thus the safest way would be to leave all those macros
set to zero and let the architectures decide.
In each case, I would prefer to set those macros to one in a separate
patch. Then this patch could be reverted in case of failing on one
architecture.
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [PATCH 13/13] Use GCC builtins for copysign functions if desired.
2019-12-03 8:27 ` Stefan Liebler
@ 2019-12-03 16:51 ` Joseph Myers
2019-12-04 13:15 ` Stefan Liebler
0 siblings, 1 reply; 35+ messages in thread
From: Joseph Myers @ 2019-12-03 16:51 UTC (permalink / raw)
To: Stefan Liebler; +Cc: libc-alpha
On Tue, 3 Dec 2019, Stefan Liebler wrote:
> On 12/2/19 10:00 PM, Joseph Myers wrote:
> > On Mon, 2 Dec 2019, Stefan Liebler wrote:
> >
> > > This patch is using the corresponding GCC builtin for copysignf, copysign,
> > > copysignl and copysignf128 if the USE_FUNCTION_BUILTIN macros are defined
> > > to one
> > > in math-use-builtins.h.
> >
> > I believe this is always safe for these implementations (the only case
> > where GCC might not expand copysign functions inline is copysignl for IBM
> > long double, in the soft-float case).
> >
> Thus you mean we can do the following preset in
> sysdeps/generic/math-use-builtins.h?
> #define USE_COPYSIGN_BUILTIN 1
> #define USE_COPYSIGNF_BUILTIN 1
> #define USE_COPYSIGNL_BUILTIN 0
> #define USE_COPYSIGNF128_BUILTIN 0
>
> Or even also set USE_COPYSIGNL_BUILTIN to one as IBM long double has its own
> implementation in ./sysdeps/ieee754/ldbl-128ibm/s_copysignl.c.
I think they can all be 1, given that IBM long double has its own
implementation. Except that you shouldn't need the indirection through
these macros at all. Just use __builtin_copysign etc. directly in the
implementations (other than IBM long double), unconditionally, the same
way that sysdeps/ieee754/dbl-64/s_fabs.c uses __builtin_fabs directly
without such macros being needed.
--
Joseph S. Myers
joseph@codesourcery.com
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [PATCH 13/13] Use GCC builtins for copysign functions if desired.
2019-12-03 16:51 ` Joseph Myers
@ 2019-12-04 13:15 ` Stefan Liebler
2019-12-04 13:20 ` Joseph Myers
0 siblings, 1 reply; 35+ messages in thread
From: Stefan Liebler @ 2019-12-04 13:15 UTC (permalink / raw)
To: Joseph Myers; +Cc: libc-alpha
[-- Attachment #1: Type: text/plain, Size: 1678 bytes --]
On 12/3/19 5:50 PM, Joseph Myers wrote:
> On Tue, 3 Dec 2019, Stefan Liebler wrote:
>
>> On 12/2/19 10:00 PM, Joseph Myers wrote:
>>> On Mon, 2 Dec 2019, Stefan Liebler wrote:
>>>
>>>> This patch is using the corresponding GCC builtin for copysignf, copysign,
>>>> copysignl and copysignf128 if the USE_FUNCTION_BUILTIN macros are defined
>>>> to one
>>>> in math-use-builtins.h.
>>>
>>> I believe this is always safe for these implementations (the only case
>>> where GCC might not expand copysign functions inline is copysignl for IBM
>>> long double, in the soft-float case).
>>>
>> Thus you mean we can do the following preset in
>> sysdeps/generic/math-use-builtins.h?
>> #define USE_COPYSIGN_BUILTIN 1
>> #define USE_COPYSIGNF_BUILTIN 1
>> #define USE_COPYSIGNL_BUILTIN 0
>> #define USE_COPYSIGNF128_BUILTIN 0
>>
>> Or even also set USE_COPYSIGNL_BUILTIN to one as IBM long double has its own
>> implementation in ./sysdeps/ieee754/ldbl-128ibm/s_copysignl.c.
>
> I think they can all be 1, given that IBM long double has its own
> implementation. Except that you shouldn't need the indirection through
> these macros at all. Just use __builtin_copysign etc. directly in the
> implementations (other than IBM long double), unconditionally, the same
> way that sysdeps/ieee754/dbl-64/s_fabs.c uses __builtin_fabs directly
> without such macros being needed.
>
Okay. I've set them to 1 and also used build-many-glibcs.py and had a
look into the s_copysign*.os files. There is no function call to
copysign* itself.
If one architecture encounters issues with those builtins, an
architecture specific math-use-builtins.sh file can set the macros to zero.
Bye,
Stefan
[-- Attachment #2: 0013-Use-GCC-builtins-for-copysign-functions-if-desired.patch --]
[-- Type: text/x-patch, Size: 6534 bytes --]
commit 91e337064c1684bd10c63ecc559e8340656f0cf5
Author: Stefan Liebler <stli@linux.ibm.com>
Date: Mon Dec 2 15:32:44 2019 +0100
Use GCC builtins for copysign functions if desired.
This patch is using the corresponding GCC builtin for copysignf, copysign,
copysignl and copysignf128 if the USE_FUNCTION_BUILTIN macros are defined to one
in math-use-builtins.h.
By default the float, double and long double macros are set to one.
According to Joseph Myers it is safe to just use those builtins.
Also the objdumps of s_copysign*.os files generated by build-many-glibcs.py
do not show copysign* function calls.
If one architecture encounters issues with those builtins, an architecture
specific math-use-builtins.sh file can set the macros to zero.
diff --git a/sysdeps/generic/math-use-builtins.h b/sysdeps/generic/math-use-builtins.h
index 34ca438a8c..df8fc97a2e 100644
--- a/sysdeps/generic/math-use-builtins.h
+++ b/sysdeps/generic/math-use-builtins.h
@@ -51,4 +51,9 @@
#define USE_ROUNDL_BUILTIN 0
#define USE_ROUNDF128_BUILTIN 0
+#define USE_COPYSIGN_BUILTIN 1
+#define USE_COPYSIGNF_BUILTIN 1
+#define USE_COPYSIGNL_BUILTIN 1
+#define USE_COPYSIGNF128_BUILTIN 0
+
#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..0be1a6420f 100644
--- a/sysdeps/ieee754/dbl-64/s_copysign.c
+++ b/sysdeps/ieee754/dbl-64/s_copysign.c
@@ -10,7 +10,9 @@
* ====================================================
*/
-#if defined(LIBM_SCCS) && !defined(lint)
+#include <math-use-builtins.h>
+
+#if ! USE_COPYSIGN_BUILTIN && defined (LIBM_SCCS) && ! defined (lint)
static char rcsid[] = "$NetBSD: s_copysign.c,v 1.8 1995/05/10 20:46:57 jtc Exp $";
#endif
@@ -28,10 +30,14 @@ static char rcsid[] = "$NetBSD: s_copysign.c,v 1.8 1995/05/10 20:46:57 jtc Exp $
double
__copysign (double x, double y)
{
+#if USE_COPYSIGN_BUILTIN
+ return __builtin_copysign (x, y);
+#else
uint32_t hx, hy;
GET_HIGH_WORD (hx, x);
GET_HIGH_WORD (hy, y);
SET_HIGH_WORD (x, (hx & 0x7fffffff) | (hy & 0x80000000));
return x;
+#endif
}
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..9a9e6389cd 100644
--- a/sysdeps/ieee754/flt-32/s_copysignf.c
+++ b/sysdeps/ieee754/flt-32/s_copysignf.c
@@ -13,7 +13,9 @@
* ====================================================
*/
-#if defined(LIBM_SCCS) && !defined(lint)
+#include <math-use-builtins.h>
+
+#if ! USE_COPYSIGNF_BUILTIN && defined (LIBM_SCCS) && ! defined (lint)
static char rcsid[] = "$NetBSD: s_copysignf.c,v 1.4 1995/05/10 20:46:59 jtc Exp $";
#endif
@@ -28,12 +30,17 @@ static char rcsid[] = "$NetBSD: s_copysignf.c,v 1.4 1995/05/10 20:46:59 jtc Exp
#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;
+#if USE_COPYSIGNF_BUILTIN
+ return __builtin_copysignf (x, y);
+#else
+ uint32_t ix, iy;
+ GET_FLOAT_WORD (ix, x);
+ GET_FLOAT_WORD (iy, y);
+ SET_FLOAT_WORD (x, (ix & 0x7fffffff) | (iy & 0x80000000));
+ return x;
+#endif
}
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..6095b7fc73 100644
--- a/sysdeps/ieee754/ldbl-128/s_copysignl.c
+++ b/sysdeps/ieee754/ldbl-128/s_copysignl.c
@@ -13,7 +13,9 @@
* ====================================================
*/
-#if defined(LIBM_SCCS) && !defined(lint)
+#include <math-use-builtins.h>
+
+#if ! USE_COPYSIGNL_BUILTIN && defined (LIBM_SCCS) && ! defined (lint)
static char rcsid[] = "$NetBSD: $";
#endif
@@ -28,13 +30,18 @@ static char rcsid[] = "$NetBSD: $";
#include <math_private.h>
#include <libm-alias-ldouble.h>
-_Float128 __copysignl(_Float128 x, _Float128 y)
+_Float128
+__copysignl (_Float128 x, _Float128 y)
{
- uint64_t hx,hy;
- GET_LDOUBLE_MSW64(hx,x);
- GET_LDOUBLE_MSW64(hy,y);
- SET_LDOUBLE_MSW64(x,(hx&0x7fffffffffffffffULL)
- |(hy&0x8000000000000000ULL));
- return x;
+#if USE_COPYSIGNL_BUILTIN
+ return __builtin_copysignl (x, y);
+#else
+ 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
}
libm_alias_ldouble (__copysign, copysign)
diff --git a/sysdeps/s390/fpu/math-use-builtins.h b/sysdeps/s390/fpu/math-use-builtins.h
index 5838a31c50..ed2a05775f 100644
--- a/sysdeps/s390/fpu/math-use-builtins.h
+++ b/sysdeps/s390/fpu/math-use-builtins.h
@@ -50,6 +50,13 @@
# define USE_ROUNDF_BUILTIN 1
# define USE_ROUNDL_BUILTIN 1
+/* GCC emits the z9-ec zarch "copy sign" instruction for these
+ builtins if build with at least --march=z196 -mzarch.
+ Note: z196 is no typo but a bug in GCC! */
+# define USE_COPYSIGN_BUILTIN 1
+# define USE_COPYSIGNF_BUILTIN 1
+# define USE_COPYSIGNL_BUILTIN 1
+
# if __GNUC_PREREQ (8, 1)
# define USE_NEARBYINTF128_BUILTIN 1
# define USE_RINTF128_BUILTIN 1
@@ -57,6 +64,7 @@
# define USE_CEILF128_BUILTIN 1
# define USE_TRUNCF128_BUILTIN 1
# define USE_ROUNDF128_BUILTIN 1
+# define USE_COPYSIGNF128_BUILTIN 1
# else
# define USE_NEARBYINTF128_BUILTIN 0
# define USE_RINTF128_BUILTIN 0
@@ -64,6 +72,7 @@
# define USE_CEILF128_BUILTIN 0
# define USE_TRUNCF128_BUILTIN 0
# define USE_ROUNDF128_BUILTIN 0
+# define USE_COPYSIGNF128_BUILTIN 0
# endif
#else
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [PATCH 13/13] Use GCC builtins for copysign functions if desired.
2019-12-04 13:15 ` Stefan Liebler
@ 2019-12-04 13:20 ` Joseph Myers
2019-12-04 16:34 ` Stefan Liebler
0 siblings, 1 reply; 35+ messages in thread
From: Joseph Myers @ 2019-12-04 13:20 UTC (permalink / raw)
To: Stefan Liebler; +Cc: libc-alpha
On Wed, 4 Dec 2019, Stefan Liebler wrote:
> > I think they can all be 1, given that IBM long double has its own
> > implementation. Except that you shouldn't need the indirection through
> > these macros at all. Just use __builtin_copysign etc. directly in the
> > implementations (other than IBM long double), unconditionally, the same
> > way that sysdeps/ieee754/dbl-64/s_fabs.c uses __builtin_fabs directly
> > without such macros being needed.
> >
>
> Okay. I've set them to 1 and also used build-many-glibcs.py and had a look
> into the s_copysign*.os files. There is no function call to copysign* itself.
I think we should handle this like fabs and not have the macros at all,
just call __builtin_copysign etc. unconditionally.
--
Joseph S. Myers
joseph@codesourcery.com
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [PATCH 13/13] Use GCC builtins for copysign functions if desired.
2019-12-04 13:20 ` Joseph Myers
@ 2019-12-04 16:34 ` Stefan Liebler
2019-12-04 20:43 ` Joseph Myers
0 siblings, 1 reply; 35+ messages in thread
From: Stefan Liebler @ 2019-12-04 16:34 UTC (permalink / raw)
To: Joseph Myers; +Cc: libc-alpha
[-- Attachment #1: Type: text/plain, Size: 1008 bytes --]
On 12/4/19 2:20 PM, Joseph Myers wrote:
> On Wed, 4 Dec 2019, Stefan Liebler wrote:
>
>>> I think they can all be 1, given that IBM long double has its own
>>> implementation. Except that you shouldn't need the indirection through
>>> these macros at all. Just use __builtin_copysign etc. directly in the
>>> implementations (other than IBM long double), unconditionally, the same
>>> way that sysdeps/ieee754/dbl-64/s_fabs.c uses __builtin_fabs directly
>>> without such macros being needed.
>>>
>>
>> Okay. I've set them to 1 and also used build-many-glibcs.py and had a look
>> into the s_copysign*.os files. There is no function call to copysign* itself.
>
> I think we should handle this like fabs and not have the macros at all,
> just call __builtin_copysign etc. unconditionally.
>
Okay. Then I've removed the macros for float and double and call the
builtins unconditionally.
But I still need the long double version as the f128 builtin is not
available with every GCC version.
Bye,
Stefan
[-- Attachment #2: 0013-Use-GCC-builtins-for-copysign-functions-if-desired.patch --]
[-- Type: text/x-patch, Size: 6038 bytes --]
commit 105b38cfc6d03772b4fe913dc1db9f56b4045bfb
Author: Stefan Liebler <stli@linux.ibm.com>
Date: Mon Dec 2 15:32:44 2019 +0100
Use GCC builtins for copysign functions if desired.
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.
diff --git a/sysdeps/generic/math-use-builtins.h b/sysdeps/generic/math-use-builtins.h
index 34ca438a8c..ca44926dc6 100644
--- a/sysdeps/generic/math-use-builtins.h
+++ b/sysdeps/generic/math-use-builtins.h
@@ -51,4 +51,7 @@
#define USE_ROUNDL_BUILTIN 0
#define USE_ROUNDF128_BUILTIN 0
+#define USE_COPYSIGNL_BUILTIN 1
+#define USE_COPYSIGNF128_BUILTIN 0
+
#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..6095b7fc73 100644
--- a/sysdeps/ieee754/ldbl-128/s_copysignl.c
+++ b/sysdeps/ieee754/ldbl-128/s_copysignl.c
@@ -13,7 +13,9 @@
* ====================================================
*/
-#if defined(LIBM_SCCS) && !defined(lint)
+#include <math-use-builtins.h>
+
+#if ! USE_COPYSIGNL_BUILTIN && defined (LIBM_SCCS) && ! defined (lint)
static char rcsid[] = "$NetBSD: $";
#endif
@@ -28,13 +30,18 @@ static char rcsid[] = "$NetBSD: $";
#include <math_private.h>
#include <libm-alias-ldouble.h>
-_Float128 __copysignl(_Float128 x, _Float128 y)
+_Float128
+__copysignl (_Float128 x, _Float128 y)
{
- uint64_t hx,hy;
- GET_LDOUBLE_MSW64(hx,x);
- GET_LDOUBLE_MSW64(hy,y);
- SET_LDOUBLE_MSW64(x,(hx&0x7fffffffffffffffULL)
- |(hy&0x8000000000000000ULL));
- return x;
+#if USE_COPYSIGNL_BUILTIN
+ return __builtin_copysignl (x, y);
+#else
+ 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
}
libm_alias_ldouble (__copysign, copysign)
diff --git a/sysdeps/s390/fpu/math-use-builtins.h b/sysdeps/s390/fpu/math-use-builtins.h
index 5838a31c50..cd722ad884 100644
--- a/sysdeps/s390/fpu/math-use-builtins.h
+++ b/sysdeps/s390/fpu/math-use-builtins.h
@@ -50,6 +50,11 @@
# define USE_ROUNDF_BUILTIN 1
# define USE_ROUNDL_BUILTIN 1
+/* GCC emits the z9-ec zarch "copy sign" instruction for these
+ builtins if build with at least --march=z196 -mzarch.
+ Note: z196 is no typo but a bug in GCC! */
+# define USE_COPYSIGNL_BUILTIN 1
+
# if __GNUC_PREREQ (8, 1)
# define USE_NEARBYINTF128_BUILTIN 1
# define USE_RINTF128_BUILTIN 1
@@ -57,6 +62,7 @@
# define USE_CEILF128_BUILTIN 1
# define USE_TRUNCF128_BUILTIN 1
# define USE_ROUNDF128_BUILTIN 1
+# define USE_COPYSIGNF128_BUILTIN 1
# else
# define USE_NEARBYINTF128_BUILTIN 0
# define USE_RINTF128_BUILTIN 0
@@ -64,6 +70,7 @@
# define USE_CEILF128_BUILTIN 0
# define USE_TRUNCF128_BUILTIN 0
# define USE_ROUNDF128_BUILTIN 0
+# define USE_COPYSIGNF128_BUILTIN 0
# endif
#else
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [PATCH 13/13] Use GCC builtins for copysign functions if desired.
2019-12-04 16:34 ` Stefan Liebler
@ 2019-12-04 20:43 ` Joseph Myers
2019-12-05 15:40 ` Stefan Liebler
0 siblings, 1 reply; 35+ messages in thread
From: Joseph Myers @ 2019-12-04 20:43 UTC (permalink / raw)
To: Stefan Liebler; +Cc: libc-alpha
On Wed, 4 Dec 2019, Stefan Liebler wrote:
> Okay. Then I've removed the macros for float and double and call the builtins
> unconditionally.
> But I still need the long double version as the f128 builtin is not available
> with every GCC version.
I think the _Float128 version could be defined to 1 for GCC 7 and later
(so both long double and _Float128 versions could be removed once we
require GCC 7 or later to build glibc).
--
Joseph S. Myers
joseph@codesourcery.com
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [PATCH 13/13] Use GCC builtins for copysign functions if desired.
2019-12-04 20:43 ` Joseph Myers
@ 2019-12-05 15:40 ` Stefan Liebler
0 siblings, 0 replies; 35+ messages in thread
From: Stefan Liebler @ 2019-12-05 15:40 UTC (permalink / raw)
To: Joseph Myers; +Cc: libc-alpha
[-- Attachment #1: Type: text/plain, Size: 549 bytes --]
On 12/4/19 9:43 PM, Joseph Myers wrote:
> On Wed, 4 Dec 2019, Stefan Liebler wrote:
>
>> Okay. Then I've removed the macros for float and double and call the builtins
>> unconditionally.
>> But I still need the long double version as the f128 builtin is not available
>> with every GCC version.
>
> I think the _Float128 version could be defined to 1 for GCC 7 and later
> (so both long double and _Float128 versions could be removed once we
> require GCC 7 or later to build glibc).
>
Okay. I've defined it to 1 for GCC 7 and later.
Bye
Stefan
[-- Attachment #2: 20191205_1630_copysign.patch --]
[-- Type: text/x-patch, Size: 6379 bytes --]
commit 8eae596471235a9baf3e6cf4e4d6bdeb121855cb
Author: Stefan Liebler <stli@linux.ibm.com>
Date: Mon Dec 2 15:32:44 2019 +0100
Use GCC builtins for copysign functions if desired.
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.
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..6095b7fc73 100644
--- a/sysdeps/ieee754/ldbl-128/s_copysignl.c
+++ b/sysdeps/ieee754/ldbl-128/s_copysignl.c
@@ -13,7 +13,9 @@
* ====================================================
*/
-#if defined(LIBM_SCCS) && !defined(lint)
+#include <math-use-builtins.h>
+
+#if ! USE_COPYSIGNL_BUILTIN && defined (LIBM_SCCS) && ! defined (lint)
static char rcsid[] = "$NetBSD: $";
#endif
@@ -28,13 +30,18 @@ static char rcsid[] = "$NetBSD: $";
#include <math_private.h>
#include <libm-alias-ldouble.h>
-_Float128 __copysignl(_Float128 x, _Float128 y)
+_Float128
+__copysignl (_Float128 x, _Float128 y)
{
- uint64_t hx,hy;
- GET_LDOUBLE_MSW64(hx,x);
- GET_LDOUBLE_MSW64(hy,y);
- SET_LDOUBLE_MSW64(x,(hx&0x7fffffffffffffffULL)
- |(hy&0x8000000000000000ULL));
- return x;
+#if USE_COPYSIGNL_BUILTIN
+ return __builtin_copysignl (x, y);
+#else
+ 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
}
libm_alias_ldouble (__copysign, copysign)
diff --git a/sysdeps/s390/fpu/math-use-builtins.h b/sysdeps/s390/fpu/math-use-builtins.h
index 5838a31c50..cd722ad884 100644
--- a/sysdeps/s390/fpu/math-use-builtins.h
+++ b/sysdeps/s390/fpu/math-use-builtins.h
@@ -50,6 +50,11 @@
# define USE_ROUNDF_BUILTIN 1
# define USE_ROUNDL_BUILTIN 1
+/* GCC emits the z9-ec zarch "copy sign" instruction for these
+ builtins if build with at least --march=z196 -mzarch.
+ Note: z196 is no typo but a bug in GCC! */
+# define USE_COPYSIGNL_BUILTIN 1
+
# if __GNUC_PREREQ (8, 1)
# define USE_NEARBYINTF128_BUILTIN 1
# define USE_RINTF128_BUILTIN 1
@@ -57,6 +62,7 @@
# define USE_CEILF128_BUILTIN 1
# define USE_TRUNCF128_BUILTIN 1
# define USE_ROUNDF128_BUILTIN 1
+# define USE_COPYSIGNF128_BUILTIN 1
# else
# define USE_NEARBYINTF128_BUILTIN 0
# define USE_RINTF128_BUILTIN 0
@@ -64,6 +70,7 @@
# define USE_CEILF128_BUILTIN 0
# define USE_TRUNCF128_BUILTIN 0
# define USE_ROUNDF128_BUILTIN 0
+# define USE_COPYSIGNF128_BUILTIN 0
# endif
#else
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [PATCH 08/13] Use GCC builtins for rint functions if desired.
2019-12-02 14:46 ` [PATCH 08/13] Use GCC builtins for rint functions if desired Stefan Liebler
@ 2019-12-05 20:40 ` Adhemerval Zanella
0 siblings, 0 replies; 35+ messages in thread
From: Adhemerval Zanella @ 2019-12-05 20:40 UTC (permalink / raw)
To: libc-alpha
On 02/12/2019 11:46, Stefan Liebler wrote:
> This patch is using the corresponding GCC builtin for rintf, rint,
> rintl and rintf128 if the USE_FUNCTION_BUILTIN macros are defined to one
> in math-use-builtins.h.
>
> This is the case for s390 if build with at least --march=z196 --mzarch.
> Otherwise the generic implementation is used. The code of the generic
> implementation is not changed except changes in code style.
LGTM with some changes below.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
> ---
> sysdeps/generic/math-use-builtins.h | 5 ++
> sysdeps/ieee754/dbl-64/s_rint.c | 11 +++-
> sysdeps/ieee754/float128/float128_private.h | 3 +
> sysdeps/ieee754/flt-32/s_rintf.c | 57 ++++++++++++-------
> sysdeps/ieee754/ldbl-128/s_rintl.c | 63 +++++++++++++--------
> sysdeps/s390/fpu/math-use-builtins.h | 6 ++
> 6 files changed, 97 insertions(+), 48 deletions(-)
>
> diff --git a/sysdeps/generic/math-use-builtins.h b/sysdeps/generic/math-use-builtins.h
> index e12490ed41..64b4a4bb5b 100644
> --- a/sysdeps/generic/math-use-builtins.h
> +++ b/sysdeps/generic/math-use-builtins.h
> @@ -26,4 +26,9 @@
> #define USE_NEARBYINTL_BUILTIN 0
> #define USE_NEARBYINTF128_BUILTIN 0
>
> +#define USE_RINT_BUILTIN 0
> +#define USE_RINTF_BUILTIN 0
> +#define USE_RINTL_BUILTIN 0
> +#define USE_RINTF128_BUILTIN 0
> +
> #endif /* math-use-builtins.h */
> diff --git a/sysdeps/ieee754/dbl-64/s_rint.c b/sysdeps/ieee754/dbl-64/s_rint.c
> index f96078c405..b09ed8fc06 100644
> --- a/sysdeps/ieee754/dbl-64/s_rint.c
> +++ b/sysdeps/ieee754/dbl-64/s_rint.c
> @@ -23,16 +23,22 @@
> #include <math.h>
> #include <math_private.h>
> #include <libm-alias-double.h>
> +#include <math-use-builtins.h>
>
> +#if ! USE_RINT_BUILTIN
> static const double
> TWO52[2] = {
> 4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
> -4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */
> };
> +#endif
You could just move it inside the !USE_NEARBYINT_BUILTIN within the
function.
>
> double
> __rint (double x)
> {
> +#if USE_RINT_BUILTIN
> + return __builtin_rint (x);
> +#else
> int64_t i0, sx;
> int32_t j0;
> EXTRACT_WORDS64 (i0, x);
> @@ -47,7 +53,7 @@ __rint (double x)
> EXTRACT_WORDS64 (i0, t);
> INSERT_WORDS64 (t, (i0 & UINT64_C (0x7fffffffffffffff))
> | (sx << 63));
> - return t;
> + return t;
> }
> }
> else
> @@ -56,9 +62,10 @@ __rint (double x)
> return x + x; /* inf or NaN */
> else
> return x; /* x is integral */
> - }
> + }
> double w = TWO52[sx] + x;
> return w - TWO52[sx];
> +#endif /* USE_RINT_BUILTIN */
> }
> #ifndef __rint
> libm_alias_double (__rint, rint)
Ok.
> diff --git a/sysdeps/ieee754/float128/float128_private.h b/sysdeps/ieee754/float128/float128_private.h
> index e96986a968..f458e7b85f 100644
> --- a/sysdeps/ieee754/float128/float128_private.h
> +++ b/sysdeps/ieee754/float128/float128_private.h
> @@ -142,6 +142,8 @@
> #include <math-use-builtins.h>
> #undef USE_NEARBYINTL_BUILTIN
> #define USE_NEARBYINTL_BUILTIN USE_NEARBYINTF128_BUILTIN
> +#undef USE_RINTL_BUILTIN
> +#define USE_RINTL_BUILTIN USE_RINTF128_BUILTIN
>
> /* IEEE function renames. */
> #define __ieee754_acoshl __ieee754_acoshf128
> @@ -346,6 +348,7 @@
> #define __builtin_copysignl __builtin_copysignf128
> #define __builtin_signbitl __builtin_signbit
> #define __builtin_nearbyintl __builtin_nearbyintf128
> +#define __builtin_rintl __builtin_rintf128
>
> /* Get the constant suffix from bits/floatn-compat.h. */
> #define L(x) __f128 (x)
Ok.
> diff --git a/sysdeps/ieee754/flt-32/s_rintf.c b/sysdeps/ieee754/flt-32/s_rintf.c
> index 0306dc21f4..7dbf991395 100644
> --- a/sysdeps/ieee754/flt-32/s_rintf.c
> +++ b/sysdeps/ieee754/flt-32/s_rintf.c
> @@ -17,35 +17,48 @@
> #include <math.h>
> #include <math_private.h>
> #include <libm-alias-float.h>
> +#include <math-use-builtins.h>
>
> +#if ! USE_RINTF_BUILTIN
> static const float
> -TWO23[2]={
> - 8.3886080000e+06, /* 0x4b000000 */
> - -8.3886080000e+06, /* 0xcb000000 */
> +TWO23[2] = {
> + 8.3886080000e+06, /* 0x4b000000 */
> + -8.3886080000e+06, /* 0xcb000000 */
> };
> +#endif
>
> float
> -__rintf(float x)
> +__rintf (float x)
> {
> - int32_t i0,j0,sx;
> - float w,t;
> - GET_FLOAT_WORD(i0,x);
> - sx = (i0>>31)&1;
> - j0 = ((i0>>23)&0xff)-0x7f;
> - if(j0<23) {
> - if(j0<0) {
> - w = TWO23[sx]+x;
> - t = w-TWO23[sx];
> - GET_FLOAT_WORD(i0,t);
> - SET_FLOAT_WORD(t,(i0&0x7fffffff)|(sx<<31));
> - return t;
> - }
> - } else {
> - if(j0==0x80) return x+x; /* inf or NaN */
> - else return x; /* x is integral */
> +#if USE_RINTF_BUILTIN
> + return __builtin_rintf (x);
> +#else
> + int32_t i0, j0, sx;
> + float w, t;
> + GET_FLOAT_WORD (i0, x);
> + sx = (i0 >> 31) & 1;
> + j0 = ((i0 >> 23) & 0xff) - 0x7f;
> + if (j0 < 23)
> + {
> + if(j0 < 0)
> + {
> + w = TWO23[sx] + x;
> + t = w - TWO23[sx];
> + GET_FLOAT_WORD (i0, t);
> + SET_FLOAT_WORD (t, (i0 & 0x7fffffff) | (sx << 31));
> + return t;
> }
> - w = TWO23[sx]+x;
> - return w-TWO23[sx];
> + }
> + else
> + {
> + if (j0 == 0x80)
> + return x + x; /* inf or NaN */
> + else
> + return x; /* x is integral */
> + }
> + w = TWO23[sx] + x;
> + return w - TWO23[sx];
> +#endif /* USE_RINTF_BUILTIN */
> }
> #ifndef __rintf
> libm_alias_float (__rint, rint)
Ok, but fix the indentation in a separated patch.
> diff --git a/sysdeps/ieee754/ldbl-128/s_rintl.c b/sysdeps/ieee754/ldbl-128/s_rintl.c
> index b6337e1d8a..1c4eba566d 100644
> --- a/sysdeps/ieee754/ldbl-128/s_rintl.c
> +++ b/sysdeps/ieee754/ldbl-128/s_rintl.c
> @@ -13,7 +13,9 @@
> * ====================================================
> */
>
> -#if defined(LIBM_SCCS) && !defined(lint)
> +#include <math-use-builtins.h>
> +
> +#if ! USE_RINTL_BUILTIN && defined (LIBM_SCCS) && ! defined (lint)
> static char rcsid[] = "$NetBSD: $";
> #endif
>
> @@ -32,33 +34,46 @@ static char rcsid[] = "$NetBSD: $";
> #include <math_private.h>
> #include <libm-alias-ldouble.h>
>
> +#if ! USE_RINTL_BUILTIN
> static const _Float128
> -TWO112[2]={
> - 5.19229685853482762853049632922009600E+33L, /* 0x406F000000000000, 0 */
> - -5.19229685853482762853049632922009600E+33L /* 0xC06F000000000000, 0 */
> +TWO112[2] = {
> + 5.19229685853482762853049632922009600E+33L, /* 0x406F000000000000, 0 */
> + -5.19229685853482762853049632922009600E+33L /* 0xC06F000000000000, 0 */
> };
> +#endif
You could just move it inside the !USE_NEARBYINT_BUILTIN within the
function.
>
> -_Float128 __rintl(_Float128 x)
> +_Float128
> +__rintl (_Float128 x)
> {
> - int64_t i0,j0,sx;
> - uint64_t i1 __attribute__ ((unused));
> - _Float128 w,t;
> - GET_LDOUBLE_WORDS64(i0,i1,x);
> - sx = (((uint64_t)i0)>>63);
> - j0 = ((i0>>48)&0x7fff)-0x3fff;
> - if(j0<112) {
> - if(j0<0) {
> - w = TWO112[sx]+x;
> - t = w-TWO112[sx];
> - GET_LDOUBLE_MSW64(i0,t);
> - SET_LDOUBLE_MSW64(t,(i0&0x7fffffffffffffffLL)|(sx<<63));
> - return t;
> - }
> - } else {
> - if(j0==0x4000) return x+x; /* inf or NaN */
> - else return x; /* x is integral */
> +#if USE_RINTL_BUILTIN
> + return __builtin_rintl (x);
> +#else
> + int64_t i0, j0, sx;
> + uint64_t i1 __attribute__ ((unused));
> + _Float128 w, t;
> + GET_LDOUBLE_WORDS64 (i0, i1, x);
> + sx = (((uint64_t) i0) >> 63);
> + j0 = ((i0 >> 48) & 0x7fff) - 0x3fff;
> + if (j0 < 112)
> + {
> + if (j0 < 0)
> + {
> + w = TWO112[sx] + x;
> + t = w - TWO112[sx];
> + GET_LDOUBLE_MSW64 (i0, t);
> + SET_LDOUBLE_MSW64 (t, (i0 & 0x7fffffffffffffffLL) | (sx << 63));
> + return t;
> }
> - w = TWO112[sx]+x;
> - return w-TWO112[sx];
> + }
> + else
> + {
> + if (j0 == 0x4000)
> + return x + x; /* inf or NaN */
> + else
> + return x; /* x is integral */
> + }
> + w = TWO112[sx] + x;
> + return w - TWO112[sx];
> +#endif /* USE_RINTL_BUILTIN */
> }
> libm_alias_ldouble (__rint, rint)
Ok, but fix the indentation in a separated patch.
> diff --git a/sysdeps/s390/fpu/math-use-builtins.h b/sysdeps/s390/fpu/math-use-builtins.h
> index fd9da8893e..15705fa74a 100644
> --- a/sysdeps/s390/fpu/math-use-builtins.h
> +++ b/sysdeps/s390/fpu/math-use-builtins.h
> @@ -30,10 +30,16 @@
> # define USE_NEARBYINTF_BUILTIN 1
> # define USE_NEARBYINTL_BUILTIN 1
>
> +# define USE_RINT_BUILTIN 1
> +# define USE_RINTF_BUILTIN 1
> +# define USE_RINTL_BUILTIN 1
> +
> # if __GNUC_PREREQ (8, 1)
> # define USE_NEARBYINTF128_BUILTIN 1
> +# define USE_RINTF128_BUILTIN 1
> # else
> # define USE_NEARBYINTF128_BUILTIN 0
> +# define USE_RINTF128_BUILTIN 0
> # endif
>
> #else
>
Ok.
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [PATCH 09/13] Use GCC builtins for floor functions if desired.
2019-12-02 14:46 ` [PATCH 09/13] Use GCC builtins for floor " Stefan Liebler
@ 2019-12-05 20:40 ` Adhemerval Zanella
0 siblings, 0 replies; 35+ messages in thread
From: Adhemerval Zanella @ 2019-12-05 20:40 UTC (permalink / raw)
To: libc-alpha
On 02/12/2019 11:46, Stefan Liebler wrote:
> This patch is using the corresponding GCC builtin for floorf, floor,
> floorl and floorf128 if the USE_FUNCTION_BUILTIN macros are defined to one
> in math-use-builtins.h.
>
> This is the case for s390 if build with at least --march=z196 --mzarch.
> Otherwise the generic implementation is used. The code of the generic
> implementation is not changed except changes in code style.
LGTM with some changes below.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
> ---
> sysdeps/generic/math-use-builtins.h | 5 ++
> sysdeps/ieee754/dbl-64/s_floor.c | 5 ++
> sysdeps/ieee754/float128/float128_private.h | 3 +
> sysdeps/ieee754/flt-32/s_floorf.c | 60 ++++++++-----
> sysdeps/ieee754/ldbl-128/s_floorl.c | 97 ++++++++++++++-------
> sysdeps/s390/fpu/math-use-builtins.h | 6 ++
> 6 files changed, 121 insertions(+), 55 deletions(-)
>
> diff --git a/sysdeps/generic/math-use-builtins.h b/sysdeps/generic/math-use-builtins.h
> index 64b4a4bb5b..e1c5df62e4 100644
> --- a/sysdeps/generic/math-use-builtins.h
> +++ b/sysdeps/generic/math-use-builtins.h
> @@ -31,4 +31,9 @@
> #define USE_RINTL_BUILTIN 0
> #define USE_RINTF128_BUILTIN 0
>
> +#define USE_FLOOR_BUILTIN 0
> +#define USE_FLOORF_BUILTIN 0
> +#define USE_FLOORL_BUILTIN 0
> +#define USE_FLOORF128_BUILTIN 0
> +
> #endif /* math-use-builtins.h */
Ok.
> diff --git a/sysdeps/ieee754/dbl-64/s_floor.c b/sysdeps/ieee754/dbl-64/s_floor.c
> index ce0c42bdb6..0ed22795ed 100644
> --- a/sysdeps/ieee754/dbl-64/s_floor.c
> +++ b/sysdeps/ieee754/dbl-64/s_floor.c
> @@ -35,6 +35,7 @@
> #include <math_private.h>
> #include <stdint.h>
> #include <libm-alias-double.h>
> +#include <math-use-builtins.h>
>
> /*
> * floor(x)
> @@ -47,6 +48,9 @@
> double
> __floor (double x)
> {
> +#if USE_FLOOR_BUILTIN
> + return __builtin_floor (x);
> +#else
> int64_t i0;
> EXTRACT_WORDS64 (i0, x);
> int32_t j0 = ((i0 >> 52) & 0x7ff) - 0x3ff;
> @@ -74,6 +78,7 @@ __floor (double x)
> else if (j0 == 0x400)
> return x + x; /* inf or NaN */
> return x;
> +#endif /* USE_FLOOR_BUILTIN */
> }
> #ifndef __floor
> libm_alias_double (__floor, floor)
Ok.
> diff --git a/sysdeps/ieee754/float128/float128_private.h b/sysdeps/ieee754/float128/float128_private.h
> index f458e7b85f..8c8a74a12c 100644
> --- a/sysdeps/ieee754/float128/float128_private.h
> +++ b/sysdeps/ieee754/float128/float128_private.h
> @@ -144,6 +144,8 @@
> #define USE_NEARBYINTL_BUILTIN USE_NEARBYINTF128_BUILTIN
> #undef USE_RINTL_BUILTIN
> #define USE_RINTL_BUILTIN USE_RINTF128_BUILTIN
> +#undef USE_FLOORL_BUILTIN
> +#define USE_FLOORL_BUILTIN USE_FLOORF128_BUILTIN
>
> /* IEEE function renames. */
> #define __ieee754_acoshl __ieee754_acoshf128
> @@ -349,6 +351,7 @@
> #define __builtin_signbitl __builtin_signbit
> #define __builtin_nearbyintl __builtin_nearbyintf128
> #define __builtin_rintl __builtin_rintf128
> +#define __builtin_floorl __builtin_floorf128
>
> /* Get the constant suffix from bits/floatn-compat.h. */
> #define L(x) __f128 (x)
Ok.
> diff --git a/sysdeps/ieee754/flt-32/s_floorf.c b/sysdeps/ieee754/flt-32/s_floorf.c
> index b34d967f01..39bb570d10 100644
> --- a/sysdeps/ieee754/flt-32/s_floorf.c
> +++ b/sysdeps/ieee754/flt-32/s_floorf.c
> @@ -24,32 +24,48 @@
> #include <math.h>
> #include <math_private.h>
> #include <libm-alias-float.h>
> +#include <math-use-builtins.h>
>
> float
> -__floorf(float x)
> +__floorf (float x)
> {
> - int32_t i0,j0;
> - uint32_t i;
> - GET_FLOAT_WORD(i0,x);
> - j0 = ((i0>>23)&0xff)-0x7f;
> - if(j0<23) {
> - if(j0<0) {
> - /* return 0*sign(x) if |x|<1 */
> - if(i0>=0) {i0=0;}
> - else if((i0&0x7fffffff)!=0)
> - { i0=0xbf800000;}
> - } else {
> - i = (0x007fffff)>>j0;
> - if((i0&i)==0) return x; /* x is integral */
> - if(i0<0) i0 += (0x00800000)>>j0;
> - i0 &= (~i);
> - }
> - } else {
> - if(__builtin_expect(j0==0x80, 0)) return x+x; /* inf or NaN */
> - else return x; /* x is integral */
> +#if USE_FLOORF_BUILTIN
> + return __builtin_floorf (x);
> +#else
> + int32_t i0, j0;
> + uint32_t i;
> + GET_FLOAT_WORD (i0, x);
> + j0 = ((i0 >> 23) & 0xff) - 0x7f;
> + if (j0 < 23)
> + {
> + if (j0 < 0)
> + {
> + /* return 0 * sign (x) if |x| < 1 */
> + if (i0 >= 0)
> + i0 = 0;
> + else if ((i0 & 0x7fffffff) != 0)
> + i0 = 0xbf800000;
> }
> - SET_FLOAT_WORD(x,i0);
> - return x;
> + else
> + {
> + i = (0x007fffff) >> j0;
> + if ((i0 & i) == 0)
> + return x; /* x is integral */
> + if (i0 < 0)
> + i0 += (0x00800000) >> j0;
> + i0 &= (~i);
> + }
> + }
> + else
> + {
> + if (__glibc_unlikely (j0 == 0x80))
> + return x + x; /* inf or NaN */
> + else
> + return x; /* x is integral */
> + }
> + SET_FLOAT_WORD (x, i0);
> + return x;
> +#endif /* USE_FLOORF_BUILTIN */
> }
> #ifndef __floorf
> libm_alias_float (__floor, floor)
Ok, but fix the indentation in a separated patch.
> diff --git a/sysdeps/ieee754/ldbl-128/s_floorl.c b/sysdeps/ieee754/ldbl-128/s_floorl.c
> index f340a3fbca..8d20a79fec 100644
> --- a/sysdeps/ieee754/ldbl-128/s_floorl.c
> +++ b/sysdeps/ieee754/ldbl-128/s_floorl.c
> @@ -13,7 +13,9 @@
> * ====================================================
> */
>
> -#if defined(LIBM_SCCS) && !defined(lint)
> +#include <math-use-builtins.h>
> +
> +#if ! USE_FLOORL_BUILTIN && defined (LIBM_SCCS) && ! defined (lint)
> static char rcsid[] = "$NetBSD: $";
> #endif
>
> @@ -29,41 +31,70 @@ static char rcsid[] = "$NetBSD: $";
> #include <math_private.h>
> #include <libm-alias-ldouble.h>
>
> -_Float128 __floorl(_Float128 x)
> +_Float128
> +__floorl (_Float128 x)
> {
> - int64_t i0,i1,j0;
> - uint64_t i,j;
> - GET_LDOUBLE_WORDS64(i0,i1,x);
> - j0 = ((i0>>48)&0x7fff)-0x3fff;
> - if(j0<48) {
> - if(j0<0) {
> - /* return 0*sign(x) if |x|<1 */
> - if(i0>=0) {i0=i1=0;}
> - else if(((i0&0x7fffffffffffffffLL)|i1)!=0)
> - { i0=0xbfff000000000000ULL;i1=0;}
> - } else {
> - i = (0x0000ffffffffffffULL)>>j0;
> - if(((i0&i)|i1)==0) return x; /* x is integral */
> - if(i0<0) i0 += (0x0001000000000000LL)>>j0;
> - i0 &= (~i); i1=0;
> +#if USE_FLOORL_BUILTIN
> + return __builtin_floorl (x);
> +#else
> + int64_t i0, i1, j0;
> + uint64_t i, j;
> + GET_LDOUBLE_WORDS64 (i0, i1, x);
> + j0 = ((i0 >> 48) & 0x7fff) - 0x3fff;
> + if (j0 < 48)
> + {
> + if (j0 < 0)
> + {
> + /* return 0 * sign (x) if |x| < 1 */
> + if (i0 >= 0)
> + {
> + i0 = i1 = 0;
> + }
> + else if (((i0 & 0x7fffffffffffffffLL) | i1) != 0)
> + {
> + i0 = 0xbfff000000000000ULL;
> + i1 = 0;
> }
> - } else if (j0>111) {
> - if(j0==0x4000) return x+x; /* inf or NaN */
> - else return x; /* x is integral */
> - } else {
> - i = -1ULL>>(j0-48);
> - if((i1&i)==0) return x; /* x is integral */
> - if(i0<0) {
> - if(j0==48) i0+=1;
> - else {
> - j = i1+(1LL<<(112-j0));
> - if(j<i1) i0 +=1 ; /* got a carry */
> - i1=j;
> - }
> + }
> + else
> + {
> + i = (0x0000ffffffffffffULL) >> j0;
> + if (((i0 & i) | i1) == 0)
> + return x; /* x is integral */
> + if (i0 < 0)
> + i0 += (0x0001000000000000LL) >> j0;
> + i0 &= (~i);
> + i1 = 0;
> + }
> + }
> + else if (j0 > 111)
> + {
> + if (j0 == 0x4000)
> + return x + x; /* inf or NaN */
> + else
> + return x; /* x is integral */
> + }
> + else
> + {
> + i = -1ULL >> (j0 - 48);
> + if ((i1 & i) == 0)
> + return x; /* x is integral */
> + if (i0 < 0)
> + {
> + if (j0 == 48)
> + i0 += 1;
> + else
> + {
> + j = i1 + (1LL << (112 - j0));
> + if (j < i1)
> + i0 += 1 ; /* got a carry */
> + i1 = j;
> }
> - i1 &= (~i);
> }
> - SET_LDOUBLE_WORDS64(x,i0,i1);
> - return x;
> + i1 &= (~i);
> + }
> + SET_LDOUBLE_WORDS64 (x, i0, i1);
> + return x;
> +#endif /* USE_FLOORL_BUILTIN */
> }
> libm_alias_ldouble (__floor, floor)
Ok, but fix the indentation in a separated patch.
> diff --git a/sysdeps/s390/fpu/math-use-builtins.h b/sysdeps/s390/fpu/math-use-builtins.h
> index 15705fa74a..63cc9d7a23 100644
> --- a/sysdeps/s390/fpu/math-use-builtins.h
> +++ b/sysdeps/s390/fpu/math-use-builtins.h
> @@ -34,12 +34,18 @@
> # define USE_RINTF_BUILTIN 1
> # define USE_RINTL_BUILTIN 1
>
> +# define USE_FLOOR_BUILTIN 1
> +# define USE_FLOORF_BUILTIN 1
> +# define USE_FLOORL_BUILTIN 1
> +
> # if __GNUC_PREREQ (8, 1)
> # define USE_NEARBYINTF128_BUILTIN 1
> # define USE_RINTF128_BUILTIN 1
> +# define USE_FLOORF128_BUILTIN 1
> # else
> # define USE_NEARBYINTF128_BUILTIN 0
> # define USE_RINTF128_BUILTIN 0
> +# define USE_FLOORF128_BUILTIN 0
> # endif
>
> #else
>
Ok.
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [PATCH 02/13] Always use wordsize-64 version of s_rint.c.
2019-12-02 14:46 ` [PATCH 02/13] Always use wordsize-64 version of s_rint.c Stefan Liebler
@ 2019-12-05 20:40 ` Adhemerval Zanella
0 siblings, 0 replies; 35+ messages in thread
From: Adhemerval Zanella @ 2019-12-05 20:40 UTC (permalink / raw)
To: libc-alpha
On 02/12/2019 11:46, Stefan Liebler wrote:
> This patch replaces s_rint.c in sysdeps/dbl-64 with the one in
> sysdeps/dbl-64/wordsize-64 and removes the latter one.
> The code is not changed except changes in code style.
>
> Also adjusted the include path in x86_64 file.
LGTM, thanks.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
> ---
> sysdeps/ieee754/dbl-64/s_rint.c | 36 ++++++-------
> sysdeps/ieee754/dbl-64/wordsize-64/s_rint.c | 58 ---------------------
> sysdeps/x86_64/fpu/multiarch/s_rint-c.c | 2 +-
> 3 files changed, 19 insertions(+), 77 deletions(-)
> delete mode 100644 sysdeps/ieee754/dbl-64/wordsize-64/s_rint.c
>
> diff --git a/sysdeps/ieee754/dbl-64/s_rint.c b/sysdeps/ieee754/dbl-64/s_rint.c
> index dd01a84176..f96078c405 100644
> --- a/sysdeps/ieee754/dbl-64/s_rint.c
> +++ b/sysdeps/ieee754/dbl-64/s_rint.c
> @@ -1,4 +1,3 @@
> -/* @(#)s_rint.c 5.1 93/09/24 */
> /*
> * ====================================================
> * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
> @@ -26,38 +25,39 @@
> #include <libm-alias-double.h>
>
> static const double
> - TWO52[2] = {
> - 4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
> - -4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */
> +TWO52[2] = {
> + 4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
> + -4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */
> };
>
> double
> __rint (double x)
> {
> - int32_t i0, j0, sx;
> - double w, t;
> - GET_HIGH_WORD (i0, x);
> - sx = (i0 >> 31) & 1;
> - j0 = ((i0 >> 20) & 0x7ff) - 0x3ff;
> + int64_t i0, sx;
> + int32_t j0;
> + EXTRACT_WORDS64 (i0, x);
> + sx = (i0 >> 63) & 1;
> + j0 = ((i0 >> 52) & 0x7ff) - 0x3ff;
> if (j0 < 52)
> {
> if (j0 < 0)
> {
> - w = TWO52[sx] + x;
> - t = w - TWO52[sx];
> - GET_HIGH_WORD (i0, t);
> - SET_HIGH_WORD (t, (i0 & 0x7fffffff) | (sx << 31));
> - return t;
> + double w = TWO52[sx] + x;
> + double t = w - TWO52[sx];
> + EXTRACT_WORDS64 (i0, t);
> + INSERT_WORDS64 (t, (i0 & UINT64_C (0x7fffffffffffffff))
> + | (sx << 63));
> + return t;
> }
> }
> else
> {
> if (j0 == 0x400)
> - return x + x; /* inf or NaN */
> + return x + x; /* inf or NaN */
> else
> - return x; /* x is integral */
> - }
> - w = TWO52[sx] + x;
> + return x; /* x is integral */
> + }
> + double w = TWO52[sx] + x;
> return w - TWO52[sx];
> }
> #ifndef __rint
Ok.
> diff --git a/sysdeps/ieee754/dbl-64/wordsize-64/s_rint.c b/sysdeps/ieee754/dbl-64/wordsize-64/s_rint.c
> deleted file mode 100644
> index 378b73a544..0000000000
> --- a/sysdeps/ieee754/dbl-64/wordsize-64/s_rint.c
> +++ /dev/null
> @@ -1,58 +0,0 @@
> -/*
> - * ====================================================
> - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
> - *
> - * Developed at SunPro, a Sun Microsystems, Inc. business.
> - * Permission to use, copy, modify, and distribute this
> - * software is freely granted, provided that this notice
> - * is preserved.
> - * ====================================================
> - */
> -
> -/*
> - * rint(x)
> - * Return x rounded to integral value according to the prevailing
> - * rounding mode.
> - * Method:
> - * Using floating addition.
> - * Exception:
> - * Inexact flag raised if x not equal to rint(x).
> - */
> -
> -#define NO_MATH_REDIRECT
> -#include <math.h>
> -#include <math_private.h>
> -#include <libm-alias-double.h>
> -
> -static const double
> -TWO52[2]={
> - 4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
> - -4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */
> -};
> -
> -double
> -__rint(double x)
> -{
> - int64_t i0,sx;
> - int32_t j0;
> - EXTRACT_WORDS64(i0,x);
> - sx = (i0>>63)&1;
> - j0 = ((i0>>52)&0x7ff)-0x3ff;
> - if(j0<52) {
> - if(j0<0) {
> - double w = TWO52[sx]+x;
> - double t = w-TWO52[sx];
> - EXTRACT_WORDS64(i0,t);
> - INSERT_WORDS64(t,(i0&UINT64_C(0x7fffffffffffffff))|(sx<<63));
> - return t;
> - }
> - } else {
> - if(j0==0x400) return x+x; /* inf or NaN */
> - else return x; /* x is integral */
> - }
> - double w = TWO52[sx]+x;
> - return w-TWO52[sx];
> -}
> -#ifndef __rint
> -libm_alias_double (__rint, rint)
> -#endif
Ok.
> diff --git a/sysdeps/x86_64/fpu/multiarch/s_rint-c.c b/sysdeps/x86_64/fpu/multiarch/s_rint-c.c
> index 162a630ff9..b010150f52 100644
> --- a/sysdeps/x86_64/fpu/multiarch/s_rint-c.c
> +++ b/sysdeps/x86_64/fpu/multiarch/s_rint-c.c
> @@ -1,3 +1,3 @@
> #undef __rint
> #define __rint __rint_c
> -#include <sysdeps/ieee754/dbl-64/wordsize-64/s_rint.c>
> +#include <sysdeps/ieee754/dbl-64/s_rint.c>
>
Ok.
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [PATCH 03/13] Always use wordsize-64 version of s_floor.c.
2019-12-02 14:46 ` [PATCH 03/13] Always use wordsize-64 version of s_floor.c Stefan Liebler
@ 2019-12-05 20:40 ` Adhemerval Zanella
0 siblings, 0 replies; 35+ messages in thread
From: Adhemerval Zanella @ 2019-12-05 20:40 UTC (permalink / raw)
To: libc-alpha
On 02/12/2019 11:46, Stefan Liebler wrote:
> This patch replaces s_floor.c in sysdeps/dbl-64 with the one in
> sysdeps/dbl-64/wordsize-64 and removes the latter one.
> The code is not changed except changes in code style.
>
> Also adjusted the include path in x86_64 and sparc64 files.
LGTM, thanks.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
> ---
> 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
Ok.
> diff --git a/sysdeps/ieee754/dbl-64/wordsize-64/s_floor.c b/sysdeps/ieee754/dbl-64/wordsize-64/s_floor.c
> deleted file mode 100644
> index b60f15bf00..0000000000
> --- a/sysdeps/ieee754/dbl-64/wordsize-64/s_floor.c
> +++ /dev/null
> @@ -1,72 +0,0 @@
> -/* Round double to integer away from zero.
> - Copyright (C) 2011-2019 Free Software Foundation, Inc.
> - This file is part of the GNU C Library.
> - Contributed by Ulrich Drepper <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
Ok.
> diff --git a/sysdeps/sparc/sparc64/fpu/multiarch/s_floor-generic.c b/sysdeps/sparc/sparc64/fpu/multiarch/s_floor-generic.c
> index 0f3361a9fb..c92b600df1 100644
> --- a/sysdeps/sparc/sparc64/fpu/multiarch/s_floor-generic.c
> +++ b/sysdeps/sparc/sparc64/fpu/multiarch/s_floor-generic.c
> @@ -1,2 +1,2 @@
> #define __floor __floor_generic
> -#include <sysdeps/ieee754/dbl-64/wordsize-64/s_floor.c>
> +#include <sysdeps/ieee754/dbl-64/s_floor.c>
Ok.
> diff --git a/sysdeps/sparc/sparc64/fpu/multiarch/s_floor-vis3.c b/sysdeps/sparc/sparc64/fpu/multiarch/s_floor-vis3.c
> index ccac0e46af..4f3d53c0e3 100644
> --- a/sysdeps/sparc/sparc64/fpu/multiarch/s_floor-vis3.c
> +++ b/sysdeps/sparc/sparc64/fpu/multiarch/s_floor-vis3.c
> @@ -20,4 +20,4 @@
>
> #define __floor __floor_vis3
>
> -#include <sysdeps/ieee754/dbl-64/wordsize-64/s_floor.c>
> +#include <sysdeps/ieee754/dbl-64/s_floor.c>
Ok.
> diff --git a/sysdeps/x86_64/fpu/multiarch/s_floor-c.c b/sysdeps/x86_64/fpu/multiarch/s_floor-c.c
> index 68733b69ef..002d12247e 100644
> --- a/sysdeps/x86_64/fpu/multiarch/s_floor-c.c
> +++ b/sysdeps/x86_64/fpu/multiarch/s_floor-c.c
> @@ -1,3 +1,3 @@
> #undef __floor
> #define __floor __floor_c
> -#include <sysdeps/ieee754/dbl-64/wordsize-64/s_floor.c>
> +#include <sysdeps/ieee754/dbl-64/s_floor.c>
>
Ok.
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [PATCH 10/13] Use GCC builtins for ceil functions if desired.
2019-12-02 15:18 ` [PATCH 10/13] Use GCC builtins for ceil functions if desired Stefan Liebler
@ 2019-12-05 20:40 ` Adhemerval Zanella
0 siblings, 0 replies; 35+ messages in thread
From: Adhemerval Zanella @ 2019-12-05 20:40 UTC (permalink / raw)
To: libc-alpha
On 02/12/2019 11:46, Stefan Liebler wrote:
> This patch is using the corresponding GCC builtin for ceilf, ceil,
> ceill and ceilf128 if the USE_FUNCTION_BUILTIN macros are defined to one
> in math-use-builtins.h.
>
> This is the case for s390 if build with at least --march=z196 --mzarch.
> Otherwise the generic implementation is used. The code of the generic
> implementation is not changed except changes in code style.
LGTM with some changes below.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
> ---
> sysdeps/generic/math-use-builtins.h | 5 ++
> sysdeps/ieee754/dbl-64/s_ceil.c | 7 +-
> sysdeps/ieee754/float128/float128_private.h | 3 +
> sysdeps/ieee754/flt-32/s_ceilf.c | 60 ++++++++-----
> sysdeps/ieee754/ldbl-128/s_ceill.c | 97 ++++++++++++++-------
> sysdeps/s390/fpu/math-use-builtins.h | 6 ++
> 6 files changed, 123 insertions(+), 55 deletions(-)
>
> diff --git a/sysdeps/generic/math-use-builtins.h b/sysdeps/generic/math-use-builtins.h
> index e1c5df62e4..076ec661b0 100644
> --- a/sysdeps/generic/math-use-builtins.h
> +++ b/sysdeps/generic/math-use-builtins.h
> @@ -36,4 +36,9 @@
> #define USE_FLOORL_BUILTIN 0
> #define USE_FLOORF128_BUILTIN 0
>
> +#define USE_CEIL_BUILTIN 0
> +#define USE_CEILF_BUILTIN 0
> +#define USE_CEILL_BUILTIN 0
> +#define USE_CEILF128_BUILTIN 0
> +
> #endif /* math-use-builtins.h */
Ok.
> diff --git a/sysdeps/ieee754/dbl-64/s_ceil.c b/sysdeps/ieee754/dbl-64/s_ceil.c
> index 9d214eac81..c0ba9e8a73 100644
> --- a/sysdeps/ieee754/dbl-64/s_ceil.c
> +++ b/sysdeps/ieee754/dbl-64/s_ceil.c
> @@ -21,10 +21,14 @@
> #include <math.h>
> #include <math_private.h>
> #include <libm-alias-double.h>
> +#include <math-use-builtins.h>
>
> double
> -__ceil(double x)
> +__ceil (double x)
> {
> +#if USE_CEIL_BUILTIN
> + return __builtin_ceil (x);
> +#else
> int64_t i0, i;
> int32_t j0;
> EXTRACT_WORDS64 (i0, x);
> @@ -58,6 +62,7 @@ __ceil(double x)
> }
> INSERT_WORDS64 (x, i0);
> return x;
> +#endif /* USE_CEIL_BUILTIN */
> }
> #ifndef __ceil
> libm_alias_double (__ceil, ceil)
Ok.
> diff --git a/sysdeps/ieee754/float128/float128_private.h b/sysdeps/ieee754/float128/float128_private.h
> index 8c8a74a12c..01881b574a 100644
> --- a/sysdeps/ieee754/float128/float128_private.h
> +++ b/sysdeps/ieee754/float128/float128_private.h
> @@ -146,6 +146,8 @@
> #define USE_RINTL_BUILTIN USE_RINTF128_BUILTIN
> #undef USE_FLOORL_BUILTIN
> #define USE_FLOORL_BUILTIN USE_FLOORF128_BUILTIN
> +#undef USE_CEILL_BUILTIN
> +#define USE_CEILL_BUILTIN USE_CEILF128_BUILTIN
>
> /* IEEE function renames. */
> #define __ieee754_acoshl __ieee754_acoshf128
> @@ -352,6 +354,7 @@
> #define __builtin_nearbyintl __builtin_nearbyintf128
> #define __builtin_rintl __builtin_rintf128
> #define __builtin_floorl __builtin_floorf128
> +#define __builtin_ceill __builtin_ceilf128
>
> /* Get the constant suffix from bits/floatn-compat.h. */
> #define L(x) __f128 (x)
Ok.
> diff --git a/sysdeps/ieee754/flt-32/s_ceilf.c b/sysdeps/ieee754/flt-32/s_ceilf.c
> index 25cba0807c..4a7ce45800 100644
> --- a/sysdeps/ieee754/flt-32/s_ceilf.c
> +++ b/sysdeps/ieee754/flt-32/s_ceilf.c
> @@ -17,33 +17,49 @@
> #include <math.h>
> #include <math_private.h>
> #include <libm-alias-float.h>
> -
> +#include <math-use-builtins.h>
>
> float
> -__ceilf(float x)
> +__ceilf (float x)
> {
> - int32_t i0,j0;
> - uint32_t i;
> +#if USE_CEILF_BUILTIN
> + return __builtin_ceilf (x);
> +#else
> + int32_t i0, j0;
> + uint32_t i;
>
> - GET_FLOAT_WORD(i0,x);
> - j0 = ((i0>>23)&0xff)-0x7f;
> - if(j0<23) {
> - if(j0<0) {
> - /* return 0*sign(x) if |x|<1 */
> - if(i0<0) {i0=0x80000000;}
> - else if(i0!=0) { i0=0x3f800000;}
> - } else {
> - i = (0x007fffff)>>j0;
> - if((i0&i)==0) return x; /* x is integral */
> - if(i0>0) i0 += (0x00800000)>>j0;
> - i0 &= (~i);
> - }
> - } else {
> - if(__builtin_expect(j0==0x80, 0)) return x+x; /* inf or NaN */
> - else return x; /* x is integral */
> + GET_FLOAT_WORD (i0, x);
> + j0 = ((i0 >> 23) & 0xff) - 0x7f;
> + if (j0 < 23)
> + {
> + if (j0 < 0)
> + {
> + /* return 0 * sign (x) if |x| < 1 */
> + if (i0 < 0)
> + i0 = 0x80000000;
> + else if (i0 != 0)
> + i0 = 0x3f800000;
> + }
> + else
> + {
> + i = (0x007fffff) >> j0;
> + if ((i0 & i) == 0)
> + return x; /* x is integral */
> + if (i0 > 0)
> + i0 += (0x00800000) >> j0;
> + i0 &= (~i);
> }
> - SET_FLOAT_WORD(x,i0);
> - return x;
> + }
> + else
> + {
> + if (__glibc_unlikely (j0 == 0x80))
> + return x + x; /* inf or NaN */
> + else
> + return x; /* x is integral */
> + }
> + SET_FLOAT_WORD (x, i0);
> + return x;
> +#endif /* USE_CEILF_BUILTIN */
> }
> #ifndef __ceilf
> libm_alias_float (__ceil, ceil)
Ok, but fix the indentation in a separated patch.
> diff --git a/sysdeps/ieee754/ldbl-128/s_ceill.c b/sysdeps/ieee754/ldbl-128/s_ceill.c
> index 2ec55de25a..019f9fd950 100644
> --- a/sysdeps/ieee754/ldbl-128/s_ceill.c
> +++ b/sysdeps/ieee754/ldbl-128/s_ceill.c
> @@ -13,7 +13,9 @@
> * ====================================================
> */
>
> -#if defined(LIBM_SCCS) && !defined(lint)
> +#include <math-use-builtins.h>
> +
> +#if ! USE_CEILL_BUILTIN && defined (LIBM_SCCS) && ! defined (lint)
> static char rcsid[] = "$NetBSD: $";
> #endif
>
> @@ -29,40 +31,71 @@ static char rcsid[] = "$NetBSD: $";
> #include <math_private.h>
> #include <libm-alias-ldouble.h>
>
> -_Float128 __ceill(_Float128 x)
> +_Float128
> +__ceill (_Float128 x)
> {
> - int64_t i0,i1,j0;
> - uint64_t i,j;
> - GET_LDOUBLE_WORDS64(i0,i1,x);
> - j0 = ((i0>>48)&0x7fff)-0x3fff;
> - if(j0<48) {
> - if(j0<0) {
> - /* return 0*sign(x) if |x|<1 */
> - if(i0<0) {i0=0x8000000000000000ULL;i1=0;}
> - else if((i0|i1)!=0) { i0=0x3fff000000000000ULL;i1=0;}
> - } else {
> - i = (0x0000ffffffffffffULL)>>j0;
> - if(((i0&i)|i1)==0) return x; /* x is integral */
> - if(i0>0) i0 += (0x0001000000000000LL)>>j0;
> - i0 &= (~i); i1=0;
> +#if USE_CEILL_BUILTIN
> + return __builtin_ceill (x);
> +#else
> + int64_t i0, i1, j0;
> + uint64_t i, j;
> + GET_LDOUBLE_WORDS64 (i0, i1, x);
> + j0 = ((i0 >> 48) & 0x7fff) - 0x3fff;
> + if (j0 < 48)
> + {
> + if (j0 < 0)
> + {
> + /* return 0 * sign (x) if |x| < 1 */
> + if (i0 < 0)
> + {
> + i0 = 0x8000000000000000ULL;
> + i1 = 0;
> + }
> + else if ((i0 | i1) != 0)
> + {
> + i0 = 0x3fff000000000000ULL;
> + i1 = 0;
> }
> - } else if (j0>111) {
> - if(j0==0x4000) return x+x; /* inf or NaN */
> - else return x; /* x is integral */
> - } else {
> - i = -1ULL>>(j0-48);
> - if((i1&i)==0) return x; /* x is integral */
> - if(i0>0) {
> - if(j0==48) i0+=1;
> - else {
> - j = i1+(1LL<<(112-j0));
> - if(j<i1) i0 +=1 ; /* got a carry */
> - i1=j;
> - }
> + }
> + else
> + {
> + i = (0x0000ffffffffffffULL) >> j0;
> + if (((i0 & i) | i1) == 0)
> + return x; /* x is integral */
> + if (i0 > 0)
> + i0 += (0x0001000000000000LL) >> j0;
> + i0 &= (~i);
> + i1 = 0;
> + }
> + }
> + else if (j0 > 111)
> + {
> + if (j0 == 0x4000)
> + return x + x; /* inf or NaN */
> + else
> + return x; /* x is integral */
> + }
> + else
> + {
> + i = -1ULL >> (j0 - 48);
> + if ((i1 & i) == 0)
> + return x; /* x is integral */
> + if (i0 > 0)
> + {
> + if (j0 == 48)
> + i0 += 1;
> + else
> + {
> + j = i1 + (1LL << (112 - j0));
> + if (j < i1)
> + i0 += 1; /* got a carry */
> + i1 = j;
> }
> - i1 &= (~i);
> }
> - SET_LDOUBLE_WORDS64(x,i0,i1);
> - return x;
> + i1 &= (~i);
> + }
> + SET_LDOUBLE_WORDS64 (x, i0, i1);
> + return x;
> +#endif /* USE_CEILL_BUILTIN */
> }
> libm_alias_ldouble (__ceil, ceil)
Ok, but fix the indentation in a separated patch.
> diff --git a/sysdeps/s390/fpu/math-use-builtins.h b/sysdeps/s390/fpu/math-use-builtins.h
> index 63cc9d7a23..dc364edaa8 100644
> --- a/sysdeps/s390/fpu/math-use-builtins.h
> +++ b/sysdeps/s390/fpu/math-use-builtins.h
> @@ -38,14 +38,20 @@
> # define USE_FLOORF_BUILTIN 1
> # define USE_FLOORL_BUILTIN 1
>
> +# define USE_CEIL_BUILTIN 1
> +# define USE_CEILF_BUILTIN 1
> +# define USE_CEILL_BUILTIN 1
> +
> # if __GNUC_PREREQ (8, 1)
> # define USE_NEARBYINTF128_BUILTIN 1
> # define USE_RINTF128_BUILTIN 1
> # define USE_FLOORF128_BUILTIN 1
> +# define USE_CEILF128_BUILTIN 1
> # else
> # define USE_NEARBYINTF128_BUILTIN 0
> # define USE_RINTF128_BUILTIN 0
> # define USE_FLOORF128_BUILTIN 0
> +# define USE_CEILF128_BUILTIN 0
> # endif
>
> #else
>
Ok.
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [PATCH 05/13] Always use wordsize-64 version of s_trunc.c.
2019-12-02 14:46 ` [PATCH 05/13] Always use wordsize-64 version of s_trunc.c Stefan Liebler
@ 2019-12-05 20:40 ` Adhemerval Zanella
0 siblings, 0 replies; 35+ messages in thread
From: Adhemerval Zanella @ 2019-12-05 20:40 UTC (permalink / raw)
To: libc-alpha
On 02/12/2019 11:46, Stefan Liebler wrote:
> This patch replaces s_trunc.c in sysdeps/dbl-64 with the one in
> sysdeps/dbl-64/wordsize-64 and removes the latter one.
> The code is not changed except changes in code style.
>
> Also adjusted the include path in x86_64 and sparc64 files.
LGTM, thanks.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
> ---
> sysdeps/ieee754/dbl-64/s_trunc.c | 25 ++++-----
> sysdeps/ieee754/dbl-64/wordsize-64/s_trunc.c | 55 -------------------
> .../sparc64/fpu/multiarch/s_trunc-generic.c | 2 +-
> .../sparc64/fpu/multiarch/s_trunc-vis3.c | 2 +-
> sysdeps/x86_64/fpu/multiarch/s_trunc-c.c | 2 +-
> 5 files changed, 13 insertions(+), 73 deletions(-)
> delete mode 100644 sysdeps/ieee754/dbl-64/wordsize-64/s_trunc.c
>
> diff --git a/sysdeps/ieee754/dbl-64/s_trunc.c b/sysdeps/ieee754/dbl-64/s_trunc.c
> index 154feb9aa3..0de68ce298 100644
> --- a/sysdeps/ieee754/dbl-64/s_trunc.c
> +++ b/sysdeps/ieee754/dbl-64/s_trunc.c
> @@ -27,31 +27,26 @@
> double
> __trunc (double x)
> {
> - int32_t i0, j0;
> - uint32_t i1;
> - int sx;
> -
> - EXTRACT_WORDS (i0, i1, x);
> - sx = i0 & 0x80000000;
> - j0 = ((i0 >> 20) & 0x7ff) - 0x3ff;
> - if (j0 < 20)
> + int64_t i0, j0;
> + int64_t sx;
> +
> + EXTRACT_WORDS64 (i0, x);
> + sx = i0 & UINT64_C (0x8000000000000000);
> + j0 = ((i0 >> 52) & 0x7ff) - 0x3ff;
> + if (j0 < 52)
> {
> if (j0 < 0)
> /* The magnitude of the number is < 1 so the result is +-0. */
> - INSERT_WORDS (x, sx, 0);
> + INSERT_WORDS64 (x, sx);
> else
> - INSERT_WORDS (x, sx | (i0 & ~(0x000fffff >> j0)), 0);
> + INSERT_WORDS64 (x, sx | (i0 & ~(UINT64_C (0x000fffffffffffff) >> j0)));
> }
> - else if (j0 > 51)
> + else
> {
> if (j0 == 0x400)
> /* x is inf or NaN. */
> return x + x;
> }
> - else
> - {
> - INSERT_WORDS (x, i0, i1 & ~(0xffffffffu >> (j0 - 20)));
> - }
>
> return x;
> }
Ok.
> diff --git a/sysdeps/ieee754/dbl-64/wordsize-64/s_trunc.c b/sysdeps/ieee754/dbl-64/wordsize-64/s_trunc.c
> deleted file mode 100644
> index 3f040bbf83..0000000000
> --- a/sysdeps/ieee754/dbl-64/wordsize-64/s_trunc.c
> +++ /dev/null
> @@ -1,55 +0,0 @@
> -/* Truncate argument to nearest integral value not larger than the argument.
> - Copyright (C) 1997-2019 Free Software Foundation, Inc.
> - This file is part of the GNU C Library.
> - Contributed by Ulrich Drepper <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
Ok.
> diff --git a/sysdeps/sparc/sparc64/fpu/multiarch/s_trunc-generic.c b/sysdeps/sparc/sparc64/fpu/multiarch/s_trunc-generic.c
> index 00abd2a643..c198ebb3d5 100644
> --- a/sysdeps/sparc/sparc64/fpu/multiarch/s_trunc-generic.c
> +++ b/sysdeps/sparc/sparc64/fpu/multiarch/s_trunc-generic.c
> @@ -1,2 +1,2 @@
> #define __trunc __trunc_generic
> -#include <sysdeps/ieee754/dbl-64/wordsize-64/s_trunc.c>
> +#include <sysdeps/ieee754/dbl-64/s_trunc.c>
Ok.
> diff --git a/sysdeps/sparc/sparc64/fpu/multiarch/s_trunc-vis3.c b/sysdeps/sparc/sparc64/fpu/multiarch/s_trunc-vis3.c
> index 45646c5d66..321a9eded6 100644
> --- a/sysdeps/sparc/sparc64/fpu/multiarch/s_trunc-vis3.c
> +++ b/sysdeps/sparc/sparc64/fpu/multiarch/s_trunc-vis3.c
> @@ -20,4 +20,4 @@
>
> #define __trunc __trunc_vis3
>
> -#include <sysdeps/ieee754/dbl-64/wordsize-64/s_trunc.c>
> +#include <sysdeps/ieee754/dbl-64/s_trunc.c>
Ok.
> diff --git a/sysdeps/x86_64/fpu/multiarch/s_trunc-c.c b/sysdeps/x86_64/fpu/multiarch/s_trunc-c.c
> index 6204ae3c77..8aa499fbb8 100644
> --- a/sysdeps/x86_64/fpu/multiarch/s_trunc-c.c
> +++ b/sysdeps/x86_64/fpu/multiarch/s_trunc-c.c
> @@ -1,2 +1,2 @@
> #define __trunc __trunc_c
> -#include <sysdeps/ieee754/dbl-64/wordsize-64/s_trunc.c>
> +#include <sysdeps/ieee754/dbl-64/s_trunc.c>
>
Ok.
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [PATCH 01/13] Always use wordsize-64 version of s_nearbyint.c.
2019-12-02 14:46 ` [PATCH 01/13] Always use wordsize-64 version of s_nearbyint.c Stefan Liebler
@ 2019-12-05 20:40 ` Adhemerval Zanella
0 siblings, 0 replies; 35+ messages in thread
From: Adhemerval Zanella @ 2019-12-05 20:40 UTC (permalink / raw)
To: libc-alpha
On 02/12/2019 11:46, Stefan Liebler wrote:
> This patch replaces s_nearbyint.c in sysdeps/dbl-64 with the one in
> sysdeps/dbl-64/wordsize-64 and removes the latter one.
> The code is not changed except changes in code style.
>
> Also adjusted the include path in x86_64 file.
LGTM, thanks.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
> ---
> sysdeps/ieee754/dbl-64/s_nearbyint.c | 38 +++++------
> .../ieee754/dbl-64/wordsize-64/s_nearbyint.c | 65 -------------------
> sysdeps/x86_64/fpu/multiarch/s_nearbyint-c.c | 2 +-
> 3 files changed, 17 insertions(+), 88 deletions(-)
> delete mode 100644 sysdeps/ieee754/dbl-64/wordsize-64/s_nearbyint.c
>
> diff --git a/sysdeps/ieee754/dbl-64/s_nearbyint.c b/sysdeps/ieee754/dbl-64/s_nearbyint.c
> index 4ce570ac7f..c261885c5a 100644
> --- a/sysdeps/ieee754/dbl-64/s_nearbyint.c
> +++ b/sysdeps/ieee754/dbl-64/s_nearbyint.c
> @@ -10,10 +10,6 @@
> * ====================================================
> */
>
> -#if defined(LIBM_SCCS) && !defined(lint)
> -static char rcsid[] = "$NetBSD: s_rint.c,v 1.8 1995/05/10 20:48:04 jtc Exp $";
> -#endif
> -
> /*
> * rint(x)
> * Return x rounded to integral value according to the prevailing
> @@ -32,44 +28,42 @@ static char rcsid[] = "$NetBSD: s_rint.c,v 1.8 1995/05/10 20:48:04 jtc Exp $";
> #include <libm-alias-double.h>
>
> static const double
> - TWO52[2] = {
> - 4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
> - -4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */
> +TWO52[2] = {
> + 4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
> + -4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */
> };
>
> double
> __nearbyint (double x)
> {
> fenv_t env;
> - int32_t i0, j0, sx;
> - double w, t;
> - GET_HIGH_WORD (i0, x);
> - sx = (i0 >> 31) & 1;
> - j0 = ((i0 >> 20) & 0x7ff) - 0x3ff;
> - if (j0 < 52)
> + int64_t i0, sx;
> + int32_t j0;
> + EXTRACT_WORDS64 (i0, x);
> + sx = (i0 >> 63) & 1;
> + j0 = ((i0 >> 52) & 0x7ff) - 0x3ff;
> + if (__glibc_likely (j0 < 52))
> {
> if (j0 < 0)
> {
> libc_feholdexcept (&env);
> - w = TWO52[sx] + math_opt_barrier (x);
> - t = w - TWO52[sx];
> + double w = TWO52[sx] + math_opt_barrier (x);
> + double t = w - TWO52[sx];
> math_force_eval (t);
> libc_fesetenv (&env);
> - GET_HIGH_WORD (i0, t);
> - SET_HIGH_WORD (t, (i0 & 0x7fffffff) | (sx << 31));
> - return t;
> + return copysign (t, x);
> }
> }
> else
> {
> if (j0 == 0x400)
> - return x + x; /* inf or NaN */
> + return x + x; /* inf or NaN */
> else
> - return x; /* x is integral */
> + return x; /* x is integral */
> }
> libc_feholdexcept (&env);
> - w = TWO52[sx] + math_opt_barrier (x);
> - t = w - TWO52[sx];
> + double w = TWO52[sx] + math_opt_barrier (x);
> + double t = w - TWO52[sx];
> math_force_eval (t);
> libc_fesetenv (&env);
> return t;
Ok.
> diff --git a/sysdeps/ieee754/dbl-64/wordsize-64/s_nearbyint.c b/sysdeps/ieee754/dbl-64/wordsize-64/s_nearbyint.c
> deleted file mode 100644
> index 92fa72af59..0000000000
> --- a/sysdeps/ieee754/dbl-64/wordsize-64/s_nearbyint.c
> +++ /dev/null
> @@ -1,65 +0,0 @@
> -/* Adapted for use as nearbyint by Ulrich Drepper <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)
Ok.
> diff --git a/sysdeps/x86_64/fpu/multiarch/s_nearbyint-c.c b/sysdeps/x86_64/fpu/multiarch/s_nearbyint-c.c
> index f897a2a6a6..4fdeb11291 100644
> --- a/sysdeps/x86_64/fpu/multiarch/s_nearbyint-c.c
> +++ b/sysdeps/x86_64/fpu/multiarch/s_nearbyint-c.c
> @@ -1,3 +1,3 @@
> #undef __nearbyint
> #define __nearbyint __nearbyint_c
> -#include <sysdeps/ieee754/dbl-64/wordsize-64/s_nearbyint.c>
> +#include <sysdeps/ieee754/dbl-64/s_nearbyint.c>
>
Ok.
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [PATCH 11/13] Use GCC builtins for trunc functions if desired.
2019-12-02 15:10 ` [PATCH 11/13] Use GCC builtins for trunc " Stefan Liebler
@ 2019-12-05 20:40 ` Adhemerval Zanella
0 siblings, 0 replies; 35+ messages in thread
From: Adhemerval Zanella @ 2019-12-05 20:40 UTC (permalink / raw)
To: libc-alpha
On 02/12/2019 11:46, Stefan Liebler wrote:
> This patch is using the corresponding GCC builtin for truncf, trunc,
> truncl and truncf128 if the USE_FUNCTION_BUILTIN macros are defined to one
> in math-use-builtins.h.
>
> This is the case for s390 if build with at least --march=z196 --mzarch.
> Otherwise the generic implementation is used.
LGTM, thanks.
Reviewed-by: Adhemerval Zanella <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 | 6 ++++++
> 6 files changed, 29 insertions(+), 3 deletions(-)
>
> diff --git a/sysdeps/generic/math-use-builtins.h b/sysdeps/generic/math-use-builtins.h
> index 076ec661b0..ab379f45ba 100644
> --- a/sysdeps/generic/math-use-builtins.h
> +++ b/sysdeps/generic/math-use-builtins.h
> @@ -41,4 +41,9 @@
> #define USE_CEILL_BUILTIN 0
> #define USE_CEILF128_BUILTIN 0
>
> +#define USE_TRUNC_BUILTIN 0
> +#define USE_TRUNCF_BUILTIN 0
> +#define USE_TRUNCL_BUILTIN 0
> +#define USE_TRUNCF128_BUILTIN 0
> +
> #endif /* math-use-builtins.h */
Ok.
> diff --git a/sysdeps/ieee754/dbl-64/s_trunc.c b/sysdeps/ieee754/dbl-64/s_trunc.c
> index 0de68ce298..6189ba4a31 100644
> --- a/sysdeps/ieee754/dbl-64/s_trunc.c
> +++ b/sysdeps/ieee754/dbl-64/s_trunc.c
> @@ -22,11 +22,14 @@
>
> #include <math_private.h>
> #include <libm-alias-double.h>
> -
> +#include <math-use-builtins.h>
>
> double
> __trunc (double x)
> {
> +#if USE_TRUNC_BUILTIN
> + return __builtin_trunc (x);
> +#else
> int64_t i0, j0;
> int64_t sx;
>
> @@ -49,6 +52,7 @@ __trunc (double x)
> }
>
> return x;
> +#endif /* USE_TRUNC_BUILTIN */
> }
> #ifndef __trunc
> libm_alias_double (__trunc, trunc)
Ok.
> diff --git a/sysdeps/ieee754/float128/float128_private.h b/sysdeps/ieee754/float128/float128_private.h
> index 01881b574a..9cd3a63f11 100644
> --- a/sysdeps/ieee754/float128/float128_private.h
> +++ b/sysdeps/ieee754/float128/float128_private.h
> @@ -148,6 +148,8 @@
> #define USE_FLOORL_BUILTIN USE_FLOORF128_BUILTIN
> #undef USE_CEILL_BUILTIN
> #define USE_CEILL_BUILTIN USE_CEILF128_BUILTIN
> +#undef USE_TRUNCL_BUILTIN
> +#define USE_TRUNCL_BUILTIN USE_TRUNCF128_BUILTIN
>
> /* IEEE function renames. */
> #define __ieee754_acoshl __ieee754_acoshf128
> @@ -355,6 +357,7 @@
> #define __builtin_rintl __builtin_rintf128
> #define __builtin_floorl __builtin_floorf128
> #define __builtin_ceill __builtin_ceilf128
> +#define __builtin_truncl __builtin_truncf128
>
> /* Get the constant suffix from bits/floatn-compat.h. */
> #define L(x) __f128 (x)
Ok.
> diff --git a/sysdeps/ieee754/flt-32/s_truncf.c b/sysdeps/ieee754/flt-32/s_truncf.c
> index e587706b5b..de6dc24a3f 100644
> --- a/sysdeps/ieee754/flt-32/s_truncf.c
> +++ b/sysdeps/ieee754/flt-32/s_truncf.c
> @@ -22,11 +22,14 @@
>
> #include <math_private.h>
> #include <libm-alias-float.h>
> -
> +#include <math-use-builtins.h>
>
> float
> __truncf (float x)
> {
> +#if USE_TRUNCF_BUILTIN
> + return __builtin_truncf (x);
> +#else
> int32_t i0, j0;
> int sx;
>
> @@ -49,6 +52,7 @@ __truncf (float x)
> }
>
> return x;
> +#endif /* USE_TRUNCF_BUILTIN */
> }
> #ifndef __truncf
> libm_alias_float (__trunc, trunc)
Ok.
> diff --git a/sysdeps/ieee754/ldbl-128/s_truncl.c b/sysdeps/ieee754/ldbl-128/s_truncl.c
> index de4dd34d59..ca62e2f970 100644
> --- a/sysdeps/ieee754/ldbl-128/s_truncl.c
> +++ b/sysdeps/ieee754/ldbl-128/s_truncl.c
> @@ -23,11 +23,14 @@
>
> #include <math_private.h>
> #include <libm-alias-ldouble.h>
> -
> +#include <math-use-builtins.h>
>
> _Float128
> __truncl (_Float128 x)
> {
> +#if USE_TRUNCL_BUILTIN
> + return __builtin_truncl (x);
> +#else
> int32_t j0;
> uint64_t i0, i1, sx;
>
> @@ -54,5 +57,6 @@ __truncl (_Float128 x)
> }
>
> return x;
> +#endif /* USE_TRUNCL_BUILTIN */
> }
> libm_alias_ldouble (__trunc, trunc)
Ok.
> diff --git a/sysdeps/s390/fpu/math-use-builtins.h b/sysdeps/s390/fpu/math-use-builtins.h
> index dc364edaa8..1d88a2c40f 100644
> --- a/sysdeps/s390/fpu/math-use-builtins.h
> +++ b/sysdeps/s390/fpu/math-use-builtins.h
> @@ -42,16 +42,22 @@
> # define USE_CEILF_BUILTIN 1
> # define USE_CEILL_BUILTIN 1
>
> +# define USE_TRUNC_BUILTIN 1
> +# define USE_TRUNCF_BUILTIN 1
> +# define USE_TRUNCL_BUILTIN 1
> +
> # if __GNUC_PREREQ (8, 1)
> # define USE_NEARBYINTF128_BUILTIN 1
> # define USE_RINTF128_BUILTIN 1
> # define USE_FLOORF128_BUILTIN 1
> # define USE_CEILF128_BUILTIN 1
> +# define USE_TRUNCF128_BUILTIN 1
> # else
> # define USE_NEARBYINTF128_BUILTIN 0
> # define USE_RINTF128_BUILTIN 0
> # define USE_FLOORF128_BUILTIN 0
> # define USE_CEILF128_BUILTIN 0
> +# define USE_TRUNCF128_BUILTIN 0
> # endif
>
> #else
>
Ok.
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [PATCH 04/13] Always use wordsize-64 version of s_ceil.c.
2019-12-02 15:15 ` [PATCH 04/13] Always use wordsize-64 version of s_ceil.c Stefan Liebler
@ 2019-12-05 20:40 ` Adhemerval Zanella
0 siblings, 0 replies; 35+ messages in thread
From: Adhemerval Zanella @ 2019-12-05 20:40 UTC (permalink / raw)
To: libc-alpha
On 02/12/2019 11:46, Stefan Liebler wrote:
> This patch replaces s_ceil.c in sysdeps/dbl-64 with the one in
> sysdeps/dbl-64/wordsize-64 and removes the latter one.
> The code is not changed except changes in code style.
>
> Also adjusted the include path in x86_64 and sparc64 files.
LGTM, thanks.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
> ---
> sysdeps/ieee754/dbl-64/s_ceil.c | 61 ++++++-------------
> sysdeps/ieee754/dbl-64/wordsize-64/s_ceil.c | 52 ----------------
> .../sparc64/fpu/multiarch/s_ceil-generic.c | 2 +-
> .../sparc/sparc64/fpu/multiarch/s_ceil-vis3.c | 2 +-
> sysdeps/x86_64/fpu/multiarch/s_ceil-c.c | 2 +-
> 5 files changed, 22 insertions(+), 97 deletions(-)
> delete mode 100644 sysdeps/ieee754/dbl-64/wordsize-64/s_ceil.c
>
> diff --git a/sysdeps/ieee754/dbl-64/s_ceil.c b/sysdeps/ieee754/dbl-64/s_ceil.c
> index 4c96286c69..9d214eac81 100644
> --- a/sysdeps/ieee754/dbl-64/s_ceil.c
> +++ b/sysdeps/ieee754/dbl-64/s_ceil.c
> @@ -23,63 +23,40 @@
> #include <libm-alias-double.h>
>
> double
> -__ceil (double x)
> +__ceil(double x)
> {
> - int32_t i0, i1, j0;
> - uint32_t i, j;
> - EXTRACT_WORDS (i0, i1, x);
> - j0 = ((i0 >> 20) & 0x7ff) - 0x3ff;
> - if (j0 < 20)
> + int64_t i0, i;
> + int32_t j0;
> + EXTRACT_WORDS64 (i0, x);
> + j0 = ((i0 >> 52) & 0x7ff) - 0x3ff;
> + if (j0 <= 51)
> {
> if (j0 < 0)
> {
> - /* return 0*sign(x) if |x|<1 */
> + /* return 0 * sign(x) if |x| < 1 */
> if (i0 < 0)
> - {
> - i0 = 0x80000000; i1 = 0;
> - }
> - else if ((i0 | i1) != 0)
> - {
> - i0 = 0x3ff00000; i1 = 0;
> - }
> + i0 = INT64_C (0x8000000000000000);
> + else if (i0 != 0)
> + i0 = INT64_C (0x3ff0000000000000);
> }
> else
> {
> - i = (0x000fffff) >> j0;
> - if (((i0 & i) | i1) == 0)
> - return x; /* x is integral */
> + i = INT64_C (0x000fffffffffffff) >> j0;
> + if ((i0 & i) == 0)
> + return x; /* x is integral */
> if (i0 > 0)
> - i0 += (0x00100000) >> j0;
> - i0 &= (~i); i1 = 0;
> + i0 += UINT64_C (0x0010000000000000) >> j0;
> + i0 &= ~i;
> }
> }
> - else if (j0 > 51)
> + else
> {
> if (j0 == 0x400)
> - return x + x; /* inf or NaN */
> + return x + x; /* inf or NaN */
> else
> - return x; /* x is integral */
> - }
> - else
> - {
> - i = ((uint32_t) (0xffffffff)) >> (j0 - 20);
> - if ((i1 & i) == 0)
> - return x; /* x is integral */
> - if (i0 > 0)
> - {
> - if (j0 == 20)
> - i0 += 1;
> - else
> - {
> - j = i1 + (1 << (52 - j0));
> - if (j < i1)
> - i0 += 1; /* got a carry */
> - i1 = j;
> - }
> - }
> - i1 &= (~i);
> + return x; /* x is integral */
> }
> - INSERT_WORDS (x, i0, i1);
> + INSERT_WORDS64 (x, i0);
> return x;
> }
> #ifndef __ceil
Ok.
> diff --git a/sysdeps/ieee754/dbl-64/wordsize-64/s_ceil.c b/sysdeps/ieee754/dbl-64/wordsize-64/s_ceil.c
> deleted file mode 100644
> index 4bb93d0633..0000000000
> --- a/sysdeps/ieee754/dbl-64/wordsize-64/s_ceil.c
> +++ /dev/null
> @@ -1,52 +0,0 @@
> -/* @(#)s_ceil.c 5.1 93/09/24 */
> -/*
> - * ====================================================
> - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
> - *
> - * Developed at SunPro, a Sun Microsystems, Inc. business.
> - * Permission to use, copy, modify, and distribute this
> - * software is freely granted, provided that this notice
> - * is preserved.
> - * ====================================================
> - */
> -
> -/*
> - * ceil(x)
> - * Return x rounded toward -inf to integral value
> - * Method:
> - * Bit twiddling.
> - */
> -
> -#define NO_MATH_REDIRECT
> -#include <math.h>
> -#include <math_private.h>
> -#include <libm-alias-double.h>
> -
> -double
> -__ceil(double x)
> -{
> - int64_t i0,i;
> - int32_t j0;
> - EXTRACT_WORDS64(i0,x);
> - j0 = ((i0>>52)&0x7ff)-0x3ff;
> - if(j0<=51) {
> - if(j0<0) {
> - /* return 0*sign(x) if |x|<1 */
> - if(i0<0) {i0=INT64_C(0x8000000000000000);}
> - else if(i0!=0) { i0=INT64_C(0x3ff0000000000000);}
> - } else {
> - i = INT64_C(0x000fffffffffffff)>>j0;
> - if((i0&i)==0) return x; /* x is integral */
> - if(i0>0) i0 += UINT64_C(0x0010000000000000)>>j0;
> - i0 &= (~i);
> - }
> - } else {
> - if(j0==0x400) return x+x; /* inf or NaN */
> - else return x; /* x is integral */
> - }
> - INSERT_WORDS64(x,i0);
> - return x;
> -}
> -#ifndef __ceil
> -libm_alias_double (__ceil, ceil)
> -#endif
Ok.
> diff --git a/sysdeps/sparc/sparc64/fpu/multiarch/s_ceil-generic.c b/sysdeps/sparc/sparc64/fpu/multiarch/s_ceil-generic.c
> index febea745e1..80f68b6766 100644
> --- a/sysdeps/sparc/sparc64/fpu/multiarch/s_ceil-generic.c
> +++ b/sysdeps/sparc/sparc64/fpu/multiarch/s_ceil-generic.c
> @@ -1,2 +1,2 @@
> #define __ceil __ceil_generic
> -#include <sysdeps/ieee754/dbl-64/wordsize-64/s_ceil.c>
> +#include <sysdeps/ieee754/dbl-64/s_ceil.c>
> diff --git a/sysdeps/sparc/sparc64/fpu/multiarch/s_ceil-vis3.c b/sysdeps/sparc/sparc64/fpu/multiarch/s_ceil-vis3.c
> index 9c17809da4..2b89199c62 100644
> --- a/sysdeps/sparc/sparc64/fpu/multiarch/s_ceil-vis3.c
> +++ b/sysdeps/sparc/sparc64/fpu/multiarch/s_ceil-vis3.c
> @@ -20,4 +20,4 @@
>
> #define __ceil __ceil_vis3
>
> -#include <sysdeps/ieee754/dbl-64/wordsize-64/s_ceil.c>
> +#include <sysdeps/ieee754/dbl-64/s_ceil.c>
Ok.
> diff --git a/sysdeps/x86_64/fpu/multiarch/s_ceil-c.c b/sysdeps/x86_64/fpu/multiarch/s_ceil-c.c
> index 6a5ea3ff27..ada28baa1a 100644
> --- a/sysdeps/x86_64/fpu/multiarch/s_ceil-c.c
> +++ b/sysdeps/x86_64/fpu/multiarch/s_ceil-c.c
> @@ -1,2 +1,2 @@
> #define __ceil __ceil_c
> -#include <sysdeps/ieee754/dbl-64/wordsize-64/s_ceil.c>
> +#include <sysdeps/ieee754/dbl-64/s_ceil.c>
>
Ok.
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [PATCH 06/13] Always use wordsize-64 version of s_round.c.
2019-12-02 15:46 ` [PATCH 06/13] Always use wordsize-64 version of s_round.c Stefan Liebler
@ 2019-12-05 20:40 ` Adhemerval Zanella
0 siblings, 0 replies; 35+ messages in thread
From: Adhemerval Zanella @ 2019-12-05 20:40 UTC (permalink / raw)
To: libc-alpha
On 02/12/2019 11:46, Stefan Liebler wrote:
> This patch replaces s_round.c in sysdeps/dbl-64 with the one in
> sysdeps/dbl-64/wordsize-64 and removes the latter one.
LGTM, thanks.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
> ---
> sysdeps/ieee754/dbl-64/s_round.c | 39 ++++--------
> sysdeps/ieee754/dbl-64/wordsize-64/s_round.c | 66 --------------------
> 2 files changed, 12 insertions(+), 93 deletions(-)
> delete mode 100644 sysdeps/ieee754/dbl-64/wordsize-64/s_round.c
>
> diff --git a/sysdeps/ieee754/dbl-64/s_round.c b/sysdeps/ieee754/dbl-64/s_round.c
> index 1793e575e9..8f4b7cff86 100644
> --- a/sysdeps/ieee754/dbl-64/s_round.c
> +++ b/sysdeps/ieee754/dbl-64/s_round.c
> @@ -22,38 +22,36 @@
>
> #include <math_private.h>
> #include <libm-alias-double.h>
> +#include <stdint.h>
>
>
> double
> __round (double x)
> {
> - int32_t i0, j0;
> - uint32_t i1;
> + int64_t i0, j0;
>
> - EXTRACT_WORDS (i0, i1, x);
> - j0 = ((i0 >> 20) & 0x7ff) - 0x3ff;
> - if (j0 < 20)
> + EXTRACT_WORDS64 (i0, x);
> + j0 = ((i0 >> 52) & 0x7ff) - 0x3ff;
> + if (__glibc_likely (j0 < 52))
> {
> if (j0 < 0)
> {
> - i0 &= 0x80000000;
> + i0 &= UINT64_C (0x8000000000000000);
> if (j0 == -1)
> - i0 |= 0x3ff00000;
> - i1 = 0;
> + i0 |= UINT64_C (0x3ff0000000000000);
> }
> else
> {
> - uint32_t i = 0x000fffff >> j0;
> - if (((i0 & i) | i1) == 0)
> + uint64_t i = UINT64_C (0x000fffffffffffff) >> j0;
> + if ((i0 & i) == 0)
> /* X is integral. */
> return x;
>
> - i0 += 0x00080000 >> j0;
> + i0 += UINT64_C (0x0008000000000000) >> j0;
> i0 &= ~i;
> - i1 = 0;
> }
> }
> - else if (j0 > 51)
> + else
> {
> if (j0 == 0x400)
> /* Inf or NaN. */
> @@ -61,21 +59,8 @@ __round (double x)
> else
> return x;
> }
> - else
> - {
> - uint32_t i = 0xffffffff >> (j0 - 20);
> - if ((i1 & i) == 0)
> - /* X is integral. */
> - return x;
> -
> - uint32_t j = i1 + (1 << (51 - j0));
> - if (j < i1)
> - i0 += 1;
> - i1 = j;
> - i1 &= ~i;
> - }
>
> - INSERT_WORDS (x, i0, i1);
> + INSERT_WORDS64 (x, i0);
> return x;
> }
> libm_alias_double (__round, round)
Ok.
> diff --git a/sysdeps/ieee754/dbl-64/wordsize-64/s_round.c b/sysdeps/ieee754/dbl-64/wordsize-64/s_round.c
> deleted file mode 100644
> index 1c3fc7f50e..0000000000
> --- a/sysdeps/ieee754/dbl-64/wordsize-64/s_round.c
> +++ /dev/null
> @@ -1,66 +0,0 @@
> -/* Round double to integer away from zero.
> - Copyright (C) 1997-2019 Free Software Foundation, Inc.
> - This file is part of the GNU C Library.
> - Contributed by Ulrich Drepper <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)
>
Ok.
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [PATCH 07/13] Use GCC builtins for nearbyint functions if desired.
2019-12-02 14:46 ` [PATCH 07/13] Use GCC builtins for nearbyint functions if desired Stefan Liebler
@ 2019-12-05 20:40 ` Adhemerval Zanella
0 siblings, 0 replies; 35+ messages in thread
From: Adhemerval Zanella @ 2019-12-05 20:40 UTC (permalink / raw)
To: libc-alpha
On 02/12/2019 11:46, Stefan Liebler wrote:
> This patch is using the corresponding GCC builtin for nearbyintf, nearbyint,
> nearbintl and nearbyintf128 if the USE_FUNCTION_BUILTIN macros are defined to one
> in math-use-builtins.h.
>
> This is the case for s390 if build with at least --march=z196 --mzarch.
> Otherwise the generic implementation is used. The code of the generic
> implementation is not changed except changes in code style.
LGTM with some changes below.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
> ---
> sysdeps/generic/math-use-builtins.h | 29 ++++++++
> sysdeps/ieee754/dbl-64/s_nearbyint.c | 8 +++
> sysdeps/ieee754/float128/float128_private.h | 4 ++
> sysdeps/ieee754/flt-32/s_nearbyintf.c | 74 ++++++++++++--------
> sysdeps/ieee754/ldbl-128/s_nearbyintl.c | 76 ++++++++++++---------
> sysdeps/s390/fpu/math-use-builtins.h | 45 ++++++++++++
> 6 files changed, 175 insertions(+), 61 deletions(-)
> create mode 100644 sysdeps/generic/math-use-builtins.h
> create mode 100644 sysdeps/s390/fpu/math-use-builtins.h
>
> diff --git a/sysdeps/generic/math-use-builtins.h b/sysdeps/generic/math-use-builtins.h
> new file mode 100644
> index 0000000000..e12490ed41
> --- /dev/null
> +++ b/sysdeps/generic/math-use-builtins.h
> @@ -0,0 +1,29 @@
> +/* Using math gcc builtins instead of generic implementation. Generic version.
> + Copyright (C) 2019 Free Software Foundation, Inc.
> + This file is part of the GNU C Library.
> +
> + The GNU C Library is free software; you can redistribute it and/or
> + modify it under the terms of the GNU Lesser General Public
> + License as published by the Free Software Foundation; either
> + version 2.1 of the License, or (at your option) any later version.
> +
> + The GNU C Library is distributed in the hope that it will be useful,
> + but WITHOUT ANY WARRANTY; without even the implied warranty of
> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> + Lesser General Public License for more details.
> +
> + You should have received a copy of the GNU Lesser General Public
> + License along with the GNU C Library; if not, see
> + <https://www.gnu.org/licenses/>. */
> +
> +#ifndef MATH_USE_BUILTINS_H
> +#define MATH_USE_BUILTINS_H 1
> +
> +/* Define these macros to 1 to use __builtin_xyz instead of the
> + generic implementation. */
> +#define USE_NEARBYINT_BUILTIN 0
> +#define USE_NEARBYINTF_BUILTIN 0
> +#define USE_NEARBYINTL_BUILTIN 0
> +#define USE_NEARBYINTF128_BUILTIN 0
> +
> +#endif /* math-use-builtins.h */
Ok.
> diff --git a/sysdeps/ieee754/dbl-64/s_nearbyint.c b/sysdeps/ieee754/dbl-64/s_nearbyint.c
> index c261885c5a..08a148e21e 100644
> --- a/sysdeps/ieee754/dbl-64/s_nearbyint.c
> +++ b/sysdeps/ieee754/dbl-64/s_nearbyint.c
> @@ -26,16 +26,23 @@
> #include <math_private.h>
> #include <fenv_private.h>
> #include <libm-alias-double.h>
> +#include <math-use-builtins.h>
>
> +#if ! USE_NEARBYINT_BUILTIN
> static const double
> TWO52[2] = {
> 4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
> -4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */
> };
> +#endif
You could just move it inside the !USE_NEARBYINT_BUILTIN within the
function.
>
> double
> __nearbyint (double x)
> {
> +#if USE_NEARBYINT_BUILTIN
> + return __builtin_nearbyint (x);
> +#else
> + /* Use generic implementation. */
> fenv_t env;
> int64_t i0, sx;
> int32_t j0;
> @@ -67,5 +74,6 @@ __nearbyint (double x)
> math_force_eval (t);
> libc_fesetenv (&env);
> return t;
> +#endif /* USE_NEARBYINT_BUILTIN */
> }
> libm_alias_double (__nearbyint, nearbyint)
Ok.
> diff --git a/sysdeps/ieee754/float128/float128_private.h b/sysdeps/ieee754/float128/float128_private.h
> index 4e31ef365b..e96986a968 100644
> --- a/sysdeps/ieee754/float128/float128_private.h
> +++ b/sysdeps/ieee754/float128/float128_private.h
> @@ -139,6 +139,9 @@
> #undef libm_alias_double_ldouble
> #define libm_alias_double_ldouble(func) libm_alias_float64_float128 (func)
>
> +#include <math-use-builtins.h>
> +#undef USE_NEARBYINTL_BUILTIN
> +#define USE_NEARBYINTL_BUILTIN USE_NEARBYINTF128_BUILTIN
Ok.
>
> /* IEEE function renames. */
> #define __ieee754_acoshl __ieee754_acoshf128
> @@ -342,6 +345,7 @@
> /* Builtin renames. */
> #define __builtin_copysignl __builtin_copysignf128
> #define __builtin_signbitl __builtin_signbit
> +#define __builtin_nearbyintl __builtin_nearbyintf128
>
> /* Get the constant suffix from bits/floatn-compat.h. */
> #define L(x) __f128 (x)
Ok.
> diff --git a/sysdeps/ieee754/flt-32/s_nearbyintf.c b/sysdeps/ieee754/flt-32/s_nearbyintf.c
> index acedf34c90..d31bbdd19a 100644
> --- a/sysdeps/ieee754/flt-32/s_nearbyintf.c
> +++ b/sysdeps/ieee754/flt-32/s_nearbyintf.c
> @@ -21,42 +21,56 @@
> #include <math_private.h>
> #include <fenv_private.h>
> #include <libm-alias-float.h>
> +#include <math-use-builtins.h>
>
> +#if ! USE_NEARBYINTF_BUILTIN
> static const float
> -TWO23[2]={
> - 8.3886080000e+06, /* 0x4b000000 */
> - -8.3886080000e+06, /* 0xcb000000 */
> +TWO23[2] = {
> + 8.3886080000e+06, /* 0x4b000000 */
> + -8.3886080000e+06, /* 0xcb000000 */
> };
> +#endif
You could just move it inside the !USE_NEARBYINT_BUILTIN within the
function.
>
> float
> -__nearbyintf(float x)
> +__nearbyintf (float x)
> {
> - fenv_t env;
> - int32_t i0,j0,sx;
> - float w,t;
> - GET_FLOAT_WORD(i0,x);
> - sx = (i0>>31)&1;
> - j0 = ((i0>>23)&0xff)-0x7f;
> - if(j0<23) {
> - if(j0<0) {
> - libc_feholdexceptf (&env);
> - w = TWO23[sx] + math_opt_barrier (x);
> - t = w-TWO23[sx];
> - math_force_eval (t);
> - libc_fesetenvf (&env);
> - GET_FLOAT_WORD(i0,t);
> - SET_FLOAT_WORD(t,(i0&0x7fffffff)|(sx<<31));
> - return t;
> - }
> - } else {
> - if(__builtin_expect(j0==0x80, 0)) return x+x; /* inf or NaN */
> - else return x; /* x is integral */
> +#if USE_NEARBYINTF_BUILTIN
> + return __builtin_nearbyintf (x);
> +#else
> + /* Use generic implementation. */
> + fenv_t env;
> + int32_t i0, j0, sx;
> + float w, t;
> + GET_FLOAT_WORD (i0, x);
> + sx = (i0 >> 31) & 1;
> + j0 = ((i0 >> 23) & 0xff) - 0x7f;
> + if (j0 < 23)
> + {
> + if (j0 < 0)
> + {
> + libc_feholdexceptf (&env);
> + w = TWO23[sx] + math_opt_barrier (x);
> + t = w - TWO23[sx];
> + math_force_eval (t);
> + libc_fesetenvf (&env);
> + GET_FLOAT_WORD (i0, t);
> + SET_FLOAT_WORD (t, (i0 & 0x7fffffff) | (sx << 31));
> + return t;
> }
> - libc_feholdexceptf (&env);
> - w = TWO23[sx] + math_opt_barrier (x);
> - t = w-TWO23[sx];
> - math_force_eval (t);
> - libc_fesetenvf (&env);
> - return t;
> + }
> + else
> + {
> + if (__glibc_unlikely (j0 == 0x80))
> + return x + x; /* inf or NaN */
> + else
> + return x; /* x is integral */
> + }
> + libc_feholdexceptf (&env);
> + w = TWO23[sx] + math_opt_barrier (x);
> + t = w - TWO23[sx];
> + math_force_eval (t);
> + libc_fesetenvf (&env);
> + return t;
> +#endif /* USE_NEARBYINT_BUILTIN */
> }
> libm_alias_float (__nearbyint, nearbyint)
Ok, but fix the indentation in a separted patch.
> diff --git a/sysdeps/ieee754/ldbl-128/s_nearbyintl.c b/sysdeps/ieee754/ldbl-128/s_nearbyintl.c
> index f044cb4334..8f3a7e8e6b 100644
> --- a/sysdeps/ieee754/ldbl-128/s_nearbyintl.c
> +++ b/sysdeps/ieee754/ldbl-128/s_nearbyintl.c
> @@ -28,42 +28,56 @@
> #include <math-barriers.h>
> #include <math_private.h>
> #include <libm-alias-ldouble.h>
> +#include <math-use-builtins.h>
>
> +#if ! USE_NEARBYINTL_BUILTIN
> static const _Float128
> -TWO112[2]={
> - L(5.19229685853482762853049632922009600E+33), /* 0x406F000000000000, 0 */
> - L(-5.19229685853482762853049632922009600E+33) /* 0xC06F000000000000, 0 */
> +TWO112[2] = {
> + L(5.19229685853482762853049632922009600E+33), /* 0x406F000000000000, 0 */
> + L(-5.19229685853482762853049632922009600E+33) /* 0xC06F000000000000, 0 */
> };
> +#endif
You could just move it inside the !USE_NEARBYINT_BUILTIN within the
function.
>
> -_Float128 __nearbyintl(_Float128 x)
> +_Float128 __nearbyintl (_Float128 x)
> {
> - fenv_t env;
> - int64_t i0,j0,sx;
> - uint64_t i1 __attribute__ ((unused));
> - _Float128 w,t;
> - GET_LDOUBLE_WORDS64(i0,i1,x);
> - sx = (((uint64_t)i0)>>63);
> - j0 = ((i0>>48)&0x7fff)-0x3fff;
> - if(j0<112) {
> - if(j0<0) {
> - feholdexcept (&env);
> - w = TWO112[sx] + math_opt_barrier (x);
> - t = w-TWO112[sx];
> - math_force_eval (t);
> - fesetenv (&env);
> - GET_LDOUBLE_MSW64(i0,t);
> - SET_LDOUBLE_MSW64(t,(i0&0x7fffffffffffffffLL)|(sx<<63));
> - return t;
> - }
> - } else {
> - if(j0==0x4000) return x+x; /* inf or NaN */
> - else return x; /* x is integral */
> +#if USE_NEARBYINTL_BUILTIN
> + return __builtin_nearbyintl (x);
> +#else
> + /* Use generic implementation. */
> + fenv_t env;
> + int64_t i0, j0, sx;
> + uint64_t i1 __attribute__ ((unused));
> + _Float128 w, t;
> + GET_LDOUBLE_WORDS64 (i0, i1, x);
> + sx = (((uint64_t) i0) >> 63);
> + j0 = ((i0 >> 48) & 0x7fff) - 0x3fff;
> + if (j0 < 112)
> + {
> + if (j0 < 0)
> + {
> + feholdexcept (&env);
> + w = TWO112[sx] + math_opt_barrier (x);
> + t = w - TWO112[sx];
> + math_force_eval (t);
> + fesetenv (&env);
> + GET_LDOUBLE_MSW64 (i0, t);
> + SET_LDOUBLE_MSW64 (t, (i0 & 0x7fffffffffffffffLL) | (sx << 63));
> + return t;
> }
> - feholdexcept (&env);
> - w = TWO112[sx] + math_opt_barrier (x);
> - t = w-TWO112[sx];
> - math_force_eval (t);
> - fesetenv (&env);
> - return t;
> + }
> + else
> + {
> + if (j0 == 0x4000)
> + return x + x; /* inf or NaN */
> + else
> + return x; /* x is integral */
> + }
> + feholdexcept (&env);
> + w = TWO112[sx] + math_opt_barrier (x);
> + t = w - TWO112[sx];
> + math_force_eval (t);
> + fesetenv (&env);
> + return t;
> +#endif /* USE_NEARBYINTL_BUILTIN */
> }
> libm_alias_ldouble (__nearbyint, nearbyint)
Ok, but fix the indentation in a separated patch.
> diff --git a/sysdeps/s390/fpu/math-use-builtins.h b/sysdeps/s390/fpu/math-use-builtins.h
> new file mode 100644
> index 0000000000..fd9da8893e
> --- /dev/null
> +++ b/sysdeps/s390/fpu/math-use-builtins.h
> @@ -0,0 +1,45 @@
> +/* Using math gcc builtins instead of generic implementation. s390/s390x version.
> + Copyright (C) 2019 Free Software Foundation, Inc.
> + This file is part of the GNU C Library.
> +
> + The GNU C Library is free software; you can redistribute it and/or
> + modify it under the terms of the GNU Lesser General Public
> + License as published by the Free Software Foundation; either
> + version 2.1 of the License, or (at your option) any later version.
> +
> + The GNU C Library is distributed in the hope that it will be useful,
> + but WITHOUT ANY WARRANTY; without even the implied warranty of
> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> + Lesser General Public License for more details.
> +
> + You should have received a copy of the GNU Lesser General Public
> + License along with the GNU C Library; if not, see
> + <https://www.gnu.org/licenses/>. */
> +
> +#ifndef MATH_USE_BUILTINS_S390_H
> +#define MATH_USE_BUILTINS_S390_H 1
> +
> +#ifdef HAVE_S390_MIN_Z196_ZARCH_ASM_SUPPORT
> +
> +# include <features.h> /* For __GNUC_PREREQ. */
> +
> +/* GCC emits the z196 zarch "load fp integer" instructions for these
> + builtins if build with at least --march=z196 -mzarch. Otherwise a
> + function call to libc is emitted. */
> +# define USE_NEARBYINT_BUILTIN 1
> +# define USE_NEARBYINTF_BUILTIN 1
> +# define USE_NEARBYINTL_BUILTIN 1
> +
> +# if __GNUC_PREREQ (8, 1)
> +# define USE_NEARBYINTF128_BUILTIN 1
> +# else
> +# define USE_NEARBYINTF128_BUILTIN 0
> +# endif
> +
> +#else
> +
> +# include_next <math-use-builtins.h>
> +
> +#endif
> +
> +#endif /* math-use-builtins.h */
>
Ok, but since the idea is to just override it by the architecture I think
it should be more clear to just replicate the expected USE_NEARBYINT*
values for !HAVE_S390_MIN_Z196_ZARCH_ASM_SUPPORT.
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [PATCH 12/13] Use GCC builtins for round functions if desired.
2019-12-02 15:50 ` [PATCH 12/13] Use GCC builtins for round functions if desired Stefan Liebler
@ 2019-12-05 20:41 ` Adhemerval Zanella
0 siblings, 0 replies; 35+ messages in thread
From: Adhemerval Zanella @ 2019-12-05 20:41 UTC (permalink / raw)
To: libc-alpha
On 02/12/2019 11:46, Stefan Liebler wrote:
> This patch is using the corresponding GCC builtin for roundf, round,
> roundl and roundf128 if the USE_FUNCTION_BUILTIN macros are defined to one
> in math-use-builtins.h.
>
> This is the case for s390 if build with at least --march=z196 --mzarch.
> Otherwise the generic implementation is used.
LGTM, thanks.
Reviewed-by: Adhemerval Zanella <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 | 6 ++++++
> 6 files changed, 29 insertions(+), 3 deletions(-)
>
> diff --git a/sysdeps/generic/math-use-builtins.h b/sysdeps/generic/math-use-builtins.h
> index ab379f45ba..34ca438a8c 100644
> --- a/sysdeps/generic/math-use-builtins.h
> +++ b/sysdeps/generic/math-use-builtins.h
> @@ -46,4 +46,9 @@
> #define USE_TRUNCL_BUILTIN 0
> #define USE_TRUNCF128_BUILTIN 0
>
> +#define USE_ROUND_BUILTIN 0
> +#define USE_ROUNDF_BUILTIN 0
> +#define USE_ROUNDL_BUILTIN 0
> +#define USE_ROUNDF128_BUILTIN 0
> +
> #endif /* math-use-builtins.h */
Ok.
> diff --git a/sysdeps/ieee754/dbl-64/s_round.c b/sysdeps/ieee754/dbl-64/s_round.c
> index 8f4b7cff86..00c8485efb 100644
> --- a/sysdeps/ieee754/dbl-64/s_round.c
> +++ b/sysdeps/ieee754/dbl-64/s_round.c
> @@ -23,11 +23,14 @@
> #include <math_private.h>
> #include <libm-alias-double.h>
> #include <stdint.h>
> -
> +#include <math-use-builtins.h>
>
> double
> __round (double x)
> {
> +#if USE_ROUND_BUILTIN
> + return __builtin_round (x);
> +#else
> int64_t i0, j0;
>
> EXTRACT_WORDS64 (i0, x);
> @@ -62,5 +65,6 @@ __round (double x)
>
> INSERT_WORDS64 (x, i0);
> return x;
> +#endif /* USE_ROUND_BUILTIN */
> }
> libm_alias_double (__round, round)
Ok.
> diff --git a/sysdeps/ieee754/float128/float128_private.h b/sysdeps/ieee754/float128/float128_private.h
> index 9cd3a63f11..a6c76ce364 100644
> --- a/sysdeps/ieee754/float128/float128_private.h
> +++ b/sysdeps/ieee754/float128/float128_private.h
> @@ -150,6 +150,8 @@
> #define USE_CEILL_BUILTIN USE_CEILF128_BUILTIN
> #undef USE_TRUNCL_BUILTIN
> #define USE_TRUNCL_BUILTIN USE_TRUNCF128_BUILTIN
> +#undef USE_ROUNDL_BUILTIN
> +#define USE_ROUNDL_BUILTIN USE_ROUNDF128_BUILTIN
>
> /* IEEE function renames. */
> #define __ieee754_acoshl __ieee754_acoshf128
> @@ -358,6 +360,7 @@
> #define __builtin_floorl __builtin_floorf128
> #define __builtin_ceill __builtin_ceilf128
> #define __builtin_truncl __builtin_truncf128
> +#define __builtin_roundl __builtin_roundf128
>
> /* Get the constant suffix from bits/floatn-compat.h. */
> #define L(x) __f128 (x)
Ok.
> diff --git a/sysdeps/ieee754/flt-32/s_roundf.c b/sysdeps/ieee754/flt-32/s_roundf.c
> index cddab7b505..33304b21f1 100644
> --- a/sysdeps/ieee754/flt-32/s_roundf.c
> +++ b/sysdeps/ieee754/flt-32/s_roundf.c
> @@ -22,11 +22,14 @@
>
> #include <math_private.h>
> #include <libm-alias-float.h>
> -
> +#include <math-use-builtins.h>
>
> float
> __roundf (float x)
> {
> +#if USE_ROUNDF_BUILTIN
> + return __builtin_roundf (x);
> +#else
> int32_t i0, j0;
>
> GET_FLOAT_WORD (i0, x);
> @@ -61,5 +64,6 @@ __roundf (float x)
>
> SET_FLOAT_WORD (x, i0);
> return x;
> +#endif /* USE_ROUNDF_BUILTIN */
> }
> libm_alias_float (__round, round)
Ok.
> diff --git a/sysdeps/ieee754/ldbl-128/s_roundl.c b/sysdeps/ieee754/ldbl-128/s_roundl.c
> index d41c9a04dc..8d3f42cd42 100644
> --- a/sysdeps/ieee754/ldbl-128/s_roundl.c
> +++ b/sysdeps/ieee754/ldbl-128/s_roundl.c
> @@ -23,11 +23,14 @@
>
> #include <math_private.h>
> #include <libm-alias-ldouble.h>
> -
> +#include <math-use-builtins.h>
>
> _Float128
> __roundl (_Float128 x)
> {
> +#if USE_ROUNDL_BUILTIN
> + return __builtin_roundl (x);
> +#else
> int32_t j0;
> uint64_t i1, i0;
>
> @@ -78,5 +81,6 @@ __roundl (_Float128 x)
>
> SET_LDOUBLE_WORDS64 (x, i0, i1);
> return x;
> +#endif /* USE_ROUNDL_BUILTIN */
> }
> libm_alias_ldouble (__round, round)
Ok.
> diff --git a/sysdeps/s390/fpu/math-use-builtins.h b/sysdeps/s390/fpu/math-use-builtins.h
> index 1d88a2c40f..5838a31c50 100644
> --- a/sysdeps/s390/fpu/math-use-builtins.h
> +++ b/sysdeps/s390/fpu/math-use-builtins.h
> @@ -46,18 +46,24 @@
> # define USE_TRUNCF_BUILTIN 1
> # define USE_TRUNCL_BUILTIN 1
>
> +# define USE_ROUND_BUILTIN 1
> +# define USE_ROUNDF_BUILTIN 1
> +# define USE_ROUNDL_BUILTIN 1
> +
> # if __GNUC_PREREQ (8, 1)
> # define USE_NEARBYINTF128_BUILTIN 1
> # define USE_RINTF128_BUILTIN 1
> # define USE_FLOORF128_BUILTIN 1
> # define USE_CEILF128_BUILTIN 1
> # define USE_TRUNCF128_BUILTIN 1
> +# define USE_ROUNDF128_BUILTIN 1
> # else
> # define USE_NEARBYINTF128_BUILTIN 0
> # define USE_RINTF128_BUILTIN 0
> # define USE_FLOORF128_BUILTIN 0
> # define USE_CEILF128_BUILTIN 0
> # define USE_TRUNCF128_BUILTIN 0
> +# define USE_ROUNDF128_BUILTIN 0
> # endif
>
> #else
>
Ok.
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [PATCH 00/13] Use GCC builtins for some math functions if desired.
2019-12-02 14:46 [PATCH 00/13] Use GCC builtins for some math functions if desired Stefan Liebler
` (12 preceding siblings ...)
2019-12-02 15:52 ` [PATCH 13/13] Use GCC builtins for copysign " Stefan Liebler
@ 2019-12-09 12:58 ` Stefan Liebler
13 siblings, 0 replies; 35+ messages in thread
From: Stefan Liebler @ 2019-12-09 12:58 UTC (permalink / raw)
To: libc-alpha; +Cc: Adhemerval Zanella, Joseph S. Myers
On 12/2/19 3:46 PM, Stefan Liebler wrote:
> Hi,
>
> this patch-series moves the nearbyint, rint, floor, ceil, trunc and round implementation from sysdeps/ieee754/dbl-64/wordsize-64 to sysdeps/ieee754/dbl-64/ as proposed by Adhemerval:
> ttps://www.sourceware.org/ml/libc-alpha/2019-11/msg00085.html
>
> It also introduces the math-use-builtins.h header with __USE_<SYMBOL>_BUILTIN macros which allows to just use GCC __builtin_<SYMBOL> instead of the current common-code implementation. There is a float, double, long double and _Float128 version of this macro for each <SYMBOL>.
>
> The generic math-use-builtins.h header is defining all those macros to 0 in order to use the current common-code implenetation. If an architecture wants to use the builtins, an architecture specific math-use-builtins.h needs to be created (e.g. done for s390) where those macros are defined to 1.
>
> Bye,
> Stefan
>
Hi,
thanks for the review so far.
I've sent a new version v2 with changes due to Adhemervals comments.
See "[PATCH v2 00/18] Use GCC builtins for some math functions if desired."
https://www.sourceware.org/ml/libc-alpha/2019-12/msg00258.html
Can you have a final look, please?
Bye,
Stefan
^ permalink raw reply [flat|nested] 35+ messages in thread
end of thread, other threads:[~2019-12-09 12:58 UTC | newest]
Thread overview: 35+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-02 14:46 [PATCH 00/13] Use GCC builtins for some math functions if desired Stefan Liebler
2019-12-02 14:46 ` [PATCH 09/13] Use GCC builtins for floor " Stefan Liebler
2019-12-05 20:40 ` Adhemerval Zanella
2019-12-02 14:46 ` [PATCH 03/13] Always use wordsize-64 version of s_floor.c Stefan Liebler
2019-12-05 20:40 ` Adhemerval Zanella
2019-12-02 14:46 ` [PATCH 07/13] Use GCC builtins for nearbyint functions if desired Stefan Liebler
2019-12-05 20:40 ` Adhemerval Zanella
2019-12-02 14:46 ` [PATCH 01/13] Always use wordsize-64 version of s_nearbyint.c Stefan Liebler
2019-12-05 20:40 ` Adhemerval Zanella
2019-12-02 14:46 ` [PATCH 05/13] Always use wordsize-64 version of s_trunc.c Stefan Liebler
2019-12-05 20:40 ` Adhemerval Zanella
2019-12-02 14:46 ` [PATCH 02/13] Always use wordsize-64 version of s_rint.c Stefan Liebler
2019-12-05 20:40 ` Adhemerval Zanella
2019-12-02 14:46 ` [PATCH 08/13] Use GCC builtins for rint functions if desired Stefan Liebler
2019-12-05 20:40 ` Adhemerval Zanella
2019-12-02 15:10 ` [PATCH 11/13] Use GCC builtins for trunc " Stefan Liebler
2019-12-05 20:40 ` Adhemerval Zanella
2019-12-02 15:15 ` [PATCH 04/13] Always use wordsize-64 version of s_ceil.c Stefan Liebler
2019-12-05 20:40 ` Adhemerval Zanella
2019-12-02 15:18 ` [PATCH 10/13] Use GCC builtins for ceil functions if desired Stefan Liebler
2019-12-05 20:40 ` Adhemerval Zanella
2019-12-02 15:46 ` [PATCH 06/13] Always use wordsize-64 version of s_round.c Stefan Liebler
2019-12-05 20:40 ` Adhemerval Zanella
2019-12-02 15:50 ` [PATCH 12/13] Use GCC builtins for round functions if desired Stefan Liebler
2019-12-05 20:41 ` Adhemerval Zanella
2019-12-02 15:52 ` [PATCH 13/13] Use GCC builtins for copysign " Stefan Liebler
2019-12-02 21:00 ` Joseph Myers
2019-12-03 8:27 ` Stefan Liebler
2019-12-03 16:51 ` Joseph Myers
2019-12-04 13:15 ` Stefan Liebler
2019-12-04 13:20 ` Joseph Myers
2019-12-04 16:34 ` Stefan Liebler
2019-12-04 20:43 ` Joseph Myers
2019-12-05 15:40 ` Stefan Liebler
2019-12-09 12:58 ` [PATCH 00/13] Use GCC builtins for some math " 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).