This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
RE: [PATCH][AArch64] Add inlines for signbit (v2)
- From: "Wilco Dijkstra" <wdijkstr at arm dot com>
- To: "'Joseph Myers'" <joseph at codesourcery dot com>
- Cc: <libc-alpha at sourceware dot org>
- Date: Fri, 22 May 2015 11:58:26 +0100
- Subject: RE: [PATCH][AArch64] Add inlines for signbit (v2)
- Authentication-results: sourceware.org; auth=none
- References: <000001d07775$77c71880$67554980$ at com> <alpine dot DEB dot 2 dot 10 dot 1504241724020 dot 30193 at digraph dot polyomino dot org dot uk> <000001d080d7$830485a0$890d90e0$ at com> <alpine dot DEB dot 2 dot 10 dot 1504271707220 dot 17788 at digraph dot polyomino dot org dot uk>
> Joseph Myers wrote:
> On Mon, 27 Apr 2015, Wilco Dijkstra wrote:
>
> > > Joseph Myers wrote:
> > > On Wed, 15 Apr 2015, Wilco Dijkstra wrote:
> > >
> > > > Is there a reason this couldn't be done by default in math.h similar to isgreater
> (unlike
> > > > __builtin_isinf et al, GCC implements signbit efficiently and correctly).
> > >
> > > It is, however, not type-generic in GCC
> > > <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=36757>, so you'd still need
> > > to have a macro expansion checking sizeof.
> >
> > Yes indeed. However the issue is how to deal with the targets that currently
> > define inlines. Would it be reasonable just to leave them and add a signbit
> > expansion for GCC >= 3.0 that directly uses the builtins?
> > (if we define __signbit(f/l) to be __builtin_signbit(f/l), things may go
> > wrong as the various mathinlines don't do an undef first).
>
> I'd think defining __signbit to __builtin_signbit, etc., would be
> appropriate (with conditionals in the mathinline.h files to disable their
> local definitions for GCC versions where __builtin_signbit works and is at
> least as good for that architecture). It would also cover cases within
> glibc that directly use the __signbit etc. names (although arguably those
> should move to using the type-generic macros; likewise direct uses of e.g.
> __finite, __isnan).
OK, I tried that and it works fine without having to change all the targets if
I define __signbit at the end of math.h.
Add inlining of the __signbit(f/l) functions for all targets using the GCC
builtin functions when available. The out-of-line implementations need undefs
to ensure the correct symbols are exported.
OK for commit?
ChangeLog:
2015-05-22 Wilco Dijkstra <wdijkstr@arm.com>
* math/math.h: (__signbit): Define. (__signbitf): Define.
(__signbitl): Define.
* sysdeps/ieee754/dbl-64/s_signbit.c: Undef __signbit.
* sysdeps/ieee754/flt-32/s_signbitf.c: Undef __signbitf.
* sysdeps/ieee754/ldbl-128/s_signbitl.c: Undef __signbitl.
* sysdeps/ieee754/ldbl-128ibm/s_signbitl.c: Likewise.
* sysdeps/ieee754/ldbl-64-128/s_signbitl.c: Likewise.
* sysdeps/ieee754/ldbl-96/s_signbitl.c: Likewise.
---
math/math.h | 7 +++++++
sysdeps/ieee754/dbl-64/s_signbit.c | 3 ++-
sysdeps/ieee754/flt-32/s_signbitf.c | 3 ++-
sysdeps/ieee754/ldbl-128/s_signbitl.c | 3 ++-
sysdeps/ieee754/ldbl-128ibm/s_signbitl.c | 2 ++
sysdeps/ieee754/ldbl-64-128/s_signbitl.c | 1 +
sysdeps/ieee754/ldbl-96/s_signbitl.c | 3 ++-
7 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/math/math.h b/math/math.h
index 7e959fc..1262f49 100644
--- a/math/math.h
+++ b/math/math.h
@@ -493,6 +493,13 @@ extern int matherr (struct exception *__exc);
fpclassify (__u) == FP_NAN || fpclassify (__v) == FP_NAN; }))
# endif
+# if __GNUC_PREREQ (4,0)
+# undef __signbitl
+# define __signbit(x) __builtin_signbit(x)
+# define __signbitf(x) __builtin_signbitf(x)
+# define __signbitl(x) __builtin_signbitl(x)
+# endif
+
#endif
__END_DECLS
diff --git a/sysdeps/ieee754/dbl-64/s_signbit.c b/sysdeps/ieee754/dbl-64/s_signbit.c
index 764f11a..e78e998 100644
--- a/sysdeps/ieee754/dbl-64/s_signbit.c
+++ b/sysdeps/ieee754/dbl-64/s_signbit.c
@@ -18,9 +18,10 @@
<http://www.gnu.org/licenses/>. */
#include <math.h>
-
#include <math_private.h>
+#undef __signbit
+
int
__signbit (double x)
{
diff --git a/sysdeps/ieee754/flt-32/s_signbitf.c b/sysdeps/ieee754/flt-32/s_signbitf.c
index 169820e..dccf0c7 100644
--- a/sysdeps/ieee754/flt-32/s_signbitf.c
+++ b/sysdeps/ieee754/flt-32/s_signbitf.c
@@ -18,9 +18,10 @@
<http://www.gnu.org/licenses/>. */
#include <math.h>
-
#include <math_private.h>
+#undef __signbitf
+
int
__signbitf (float x)
{
diff --git a/sysdeps/ieee754/ldbl-128/s_signbitl.c b/sysdeps/ieee754/ldbl-128/s_signbitl.c
index acfe859..25c0bc7 100644
--- a/sysdeps/ieee754/ldbl-128/s_signbitl.c
+++ b/sysdeps/ieee754/ldbl-128/s_signbitl.c
@@ -18,9 +18,10 @@
<http://www.gnu.org/licenses/>. */
#include <math.h>
-
#include <math_private.h>
+#undef __signbitl
+
int
__signbitl (long double x)
{
diff --git a/sysdeps/ieee754/ldbl-128ibm/s_signbitl.c b/sysdeps/ieee754/ldbl-128ibm/s_signbitl.c
index e95ad55..39102d2 100644
--- a/sysdeps/ieee754/ldbl-128ibm/s_signbitl.c
+++ b/sysdeps/ieee754/ldbl-128ibm/s_signbitl.c
@@ -21,6 +21,8 @@
#include <math_private.h>
#include <math_ldbl_opt.h>
+#undef __signbitl
+
int
___signbitl (long double x)
{
diff --git a/sysdeps/ieee754/ldbl-64-128/s_signbitl.c b/sysdeps/ieee754/ldbl-64-128/s_signbitl.c
index 850db73..9955ecf 100644
--- a/sysdeps/ieee754/ldbl-64-128/s_signbitl.c
+++ b/sysdeps/ieee754/ldbl-64-128/s_signbitl.c
@@ -1,6 +1,7 @@
#include <math_ldbl_opt.h>
#undef weak_alias
#define weak_alias(n,a)
+#undef __signbitl
#define __signbitl(arg) ___signbitl(arg)
#include <sysdeps/ieee754/ldbl-128/s_signbitl.c>
#undef __signbitl
diff --git a/sysdeps/ieee754/ldbl-96/s_signbitl.c b/sysdeps/ieee754/ldbl-96/s_signbitl.c
index bbe72a6..5e7a0d7 100644
--- a/sysdeps/ieee754/ldbl-96/s_signbitl.c
+++ b/sysdeps/ieee754/ldbl-96/s_signbitl.c
@@ -18,9 +18,10 @@
<http://www.gnu.org/licenses/>. */
#include <math.h>
-
#include <math_private.h>
+#undef __signbitl
+
int
__signbitl (long double x)
{
--
1.9.1