diff mbox

[AArch64] Add inlines for signbit

Message ID 000001d07775$77c71880$67554980$@com
State New
Headers show

Commit Message

Wilco April 15, 2015, 12:12 p.m. UTC
Add AArch64 inlines for __signbit, __signbitf and __signbitl which default to the GCC builtin
functions.

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

OK for commit?

2015-04-15  Wilco Dijkstra  <wdijkstr@arm.com>

	* sysdeps/aarch64/fpu/bits/mathinline.h: New file.
	(__signbit): New function, use __builtin_signbit.
	(__signbitf): Likewise.  (__signbitl): Likewise.

---
 sysdeps/aarch64/fpu/bits/mathinline.h | 49 +++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)
 create mode 100644 sysdeps/aarch64/fpu/bits/mathinline.h

Comments

Joseph Myers April 24, 2015, 5:25 p.m. UTC | #1
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.
Wilco April 27, 2015, 10:47 a.m. UTC | #2
> 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).

Eg. in math.h:

#if defined __USE_ISOC99 && __GNUC_PREREQ(2,97)
# undef signbit
# ifdef __NO_LONG_DOUBLE_MATH
#  define signbit(x) \
     (sizeof (x) == sizeof (float) ? __builtin_signbitf (x) : __builtin_signbit (x))
# else
...

Wilco
Joseph Myers April 27, 2015, 5:09 p.m. UTC | #3
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).
diff mbox

Patch

diff --git a/sysdeps/aarch64/fpu/bits/mathinline.h b/sysdeps/aarch64/fpu/bits/mathinline.h
new file mode 100644
index 0000000..e3d6a3d
--- /dev/null
+++ b/sysdeps/aarch64/fpu/bits/mathinline.h
@@ -0,0 +1,49 @@ 
+/* Inline math functions for AArch64.
+   Copyright (C) 2015 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
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef _MATH_H
+# error "Never use <bits/mathinline.h> directly; include <math.h> instead."
+#endif
+
+#ifndef __extern_inline
+# define __MATH_INLINE __inline
+#else
+# define __MATH_INLINE __extern_inline
+#endif
+
+#ifdef __USE_ISOC99
+
+__MATH_INLINE int
+__NTH (__signbitf (float __x))
+{
+  return __builtin_signbitf (__x);
+}
+
+__MATH_INLINE int
+__NTH (__signbit (double __x))
+{
+  return __builtin_signbit (__x);
+}
+
+__MATH_INLINE int
+__NTH (__signbitl (long double __x))
+{
+  return __builtin_signbitl (__x);
+}
+
+#endif /* C99 */