Message ID | 000001d07775$77c71880$67554980$@com |
---|---|
State | New |
Headers | show |
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.
> 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
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 --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 */