diff options
author | Adhemerval Zanella <adhemerval.zanella@linaro.org> | 2019-03-15 18:42:00 +0000 |
---|---|---|
committer | Adhemerval Zanella <adhemerval.zanella@linaro.org> | 2019-04-29 08:43:37 -0300 |
commit | 6cac323c8dd78668e65aaa29f044cbd33c1a66a5 (patch) | |
tree | 12ea516e5207039c8117594223aac9e3acb23805 /sysdeps/powerpc/fpu | |
parent | c4c0848bbb7a4ad6ab8149abf982a0f10fd2821b (diff) | |
download | glibc-6cac323c8dd78668e65aaa29f044cbd33c1a66a5.tar.gz glibc-6cac323c8dd78668e65aaa29f044cbd33c1a66a5.tar.xz glibc-6cac323c8dd78668e65aaa29f044cbd33c1a66a5.zip |
powerpc: ceil/ceilf refactor
This patches consolidates all the powerpc ceil{f} implementations on the generic sysdeps/powerpc/fpu/s_ceil{f}. The generic implementation uses either the compiler builts for ISA 2.03+ (which generates the frip instruction) or a generic implementation which uses FP only operations. It adds a generic implementation (round_to_integer.h) which is shared with other rounding to integer routines. The resulting code should be similar in term os performance to previous assembly one. The IFUNC organization for powerpc64 is also change to be enabled only for powerpc64 and not for powerpc64le (since minium ISA of 2.08 does not require the fallback generic implementation). Checked on powerpc-linux-gnu (built without --with-cpu, with --with-cpu=power4 and with --with-cpu=power5+ and --disable-multi-arch), powerpc64-linux-gnu (built without --with-cp and with --with-cpu=power5+ and --disable-multi-arch). * sysdeps/powerpc/fpu/fenv_libc.h (__fesetround_inline_nocheck): New function. * sysdeps/powerpc/fpu/round_to_integer.h: New file. * sysdeps/powerpc/fpu/s_ceil.c: Likewise. * sysdeps/powerpc/fpu/s_ceilf.c: Likewise. * sysdeps/powerpc/powerpc32/fpu/s_ceil.S: Remove file. * sysdeps/powerpc/powerpc32/fpu/s_ceilf.S: Likewise. * sysdeps/powerpc/powerpc32/power4/fpu/multiarch/Makefile (CFLAGS-s_ceil-power5+.c, CFLAGS-s_ceilf-power5+.c): New rule. * sysdeps/powerpc/powerpc32/power4/fpu/multiarch/s_ceil-power5+.S: Remove file. * sysdeps/powerpc/powerpc32/power4/fpu/multiarch/s_ceil-ppc32.S: Likewise. * sysdeps/powerpc/powerpc32/power4/fpu/multiarch/s_ceilf-power5+.S: Likewise. * sysdeps/powerpc/powerpc32/power4/fpu/multiarch/s_ceilf-ppc32.S: Likewise. * sysdeps/powerpc/powerpc32/power4/fpu/multiarch/s_ceil-power5+.c: New file. * sysdeps/powerpc/powerpc32/power4/fpu/multiarch/s_ceil-ppc32.c: Likewise. * sysdeps/powerpc/powerpc32/power4/fpu/multiarch/s_ceilf-power5+.c: Likewise. * sysdeps/powerpc/powerpc32/power4/fpu/multiarch/s_ceilf-ppc32.c: Likewise. * sysdeps/powerpc/powerpc32/power5+/fpu/s_ceil.S: Remove file. * sysdeps/powerpc/powerpc32/power5+/fpu/s_ceilf.S: Likewise. * sysdeps/powerpc/powerpc64/be/fpu/multiarch/Makefile: New file. * sysdeps/powerpc/powerpc64/be/fpu/multiarch/s_ceil-power5+.c: Likewise. * sysdeps/powerpc/powerpc64/be/fpu/multiarch/s_ceil-ppc64.c: Likewise. * sysdeps/powerpc/powerpc64/fpu/multiarch/s_ceil.c: Move to ... * sysdeps/powerpc/powerpc64/be/fpu/multiarch/s_ceil.c: ... here. * sysdeps/powerpc/powerpc64/be/fpu/multiarch/s_ceilf-power5+.c: New file. * sysdeps/powerpc/powerpc64/be/fpu/multiarch/s_ceilf-ppc64.c: Likewise. * sysdeps/powerpc/powerpc64/fpu/multiarch/s_ceilf.c: Move to ... * sysdeps/powerpc/powerpc64/be/fpu/multiarch/s_ceilf.c: ... * here. * sysdeps/powerpc/powerpc64/fpu/multiarch/Makefile (libm-sysdep_routines): Remove s_ceil-power5+, s_ceil-ppc64, s_ceilf-power5+, and s_ceilf-ppc64. * sysdeps/powerpc/powerpc64/fpu/multiarch/s_ceil-power5+.S: Remove file. * sysdeps/powerpc/powerpc64/fpu/multiarch/s_ceil-ppc64.S: Likewise. * sysdeps/powerpc/powerpc64/fpu/multiarch/s_ceilf-power5+.S: Likewise. * sysdeps/powerpc/powerpc64/fpu/multiarch/s_ceilf-ppc64.S: Likewise. * sysdeps/powerpc/powerpc64/fpu/s_ceil.S: Likewise. * sysdeps/powerpc/powerpc64/fpu/s_ceilf.S: Likewise. * sysdeps/powerpc/powerpc64/power5+/fpu/s_ceil.S: Likewise. * sysdeps/powerpc/powerpc64/power5+/fpu/s_ceilf.S: Likewise. Reviewed-by: Gabriel F. T. Gomes <gabriel@inconstante.eti.br>
Diffstat (limited to 'sysdeps/powerpc/fpu')
-rw-r--r-- | sysdeps/powerpc/fpu/fenv_libc.h | 8 | ||||
-rw-r--r-- | sysdeps/powerpc/fpu/round_to_integer.h | 105 | ||||
-rw-r--r-- | sysdeps/powerpc/fpu/s_ceil.c | 35 | ||||
-rw-r--r-- | sysdeps/powerpc/fpu/s_ceilf.c | 35 |
4 files changed, 183 insertions, 0 deletions
diff --git a/sysdeps/powerpc/fpu/fenv_libc.h b/sysdeps/powerpc/fpu/fenv_libc.h index 8a0bace84d..f8dd1b7a8b 100644 --- a/sysdeps/powerpc/fpu/fenv_libc.h +++ b/sysdeps/powerpc/fpu/fenv_libc.h @@ -97,6 +97,14 @@ __fesetround_inline (int round) return 0; } +/* Same as __fesetround_inline, however without runtime check to use DFP + mtfsfi syntax (as relax_fenv_state) or if round value is valid. */ +static inline void +__fesetround_inline_nocheck (const int round) +{ + asm volatile ("mtfsfi 7,%0" : : "i" (round)); +} + /* Definitions of all the FPSCR bit numbers */ enum { FPSCR_FX = 0, /* exception summary */ diff --git a/sysdeps/powerpc/fpu/round_to_integer.h b/sysdeps/powerpc/fpu/round_to_integer.h new file mode 100644 index 0000000000..c70afbb10f --- /dev/null +++ b/sysdeps/powerpc/fpu/round_to_integer.h @@ -0,0 +1,105 @@ +/* Round to integer generic implementation. + 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 Library General Public License as + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If + not, see <http://www.gnu.org/licenses/>. */ + +#ifndef _ROUND_TO_INTEGER_H +#define _ROUND_TO_INTEGER_H + +#include <fenv_private.h> + +enum round_mode +{ + CEIL +}; + +static inline void +set_fenv_mode (enum round_mode mode) +{ + int rmode; + switch (mode) + { + case CEIL: rmode = FE_UPWARD; break; + default: rmode = FE_TONEAREST; break; + } + __fesetround_inline_nocheck (rmode); +} + +static inline float +round_to_integer_float (enum round_mode mode, float x) +{ + /* Ensure sNaN input is converted to qNaN. */ + if (__glibc_unlikely (isnan (x))) + return x + x; + + if (fabs (x) > 0x1p+23) + return x; + + float r = x; + + /* Save current FPU rounding mode and inexact state. */ + fenv_t fe = fegetenv_register (); + set_fenv_mode (mode); + if (x > 0.0) + { + r += 0x1p+23; + r -= 0x1p+23; + r = fabs (r); + } + else if (x < 0.0) + { + r -= 0x1p+23; + r += 0x1p+23; + r = -fabs (r); + } + __builtin_mtfsf (0xff, fe); + + return r; +} + +static inline double +round_to_integer_double (enum round_mode mode, double x) +{ + /* Ensure sNaN input is converted to qNaN. */ + if (__glibc_unlikely (isnan (x))) + return x + x; + + if (fabs (x) > 0x1p+52) + return x; + + double r = x; + + /* Save current FPU rounding mode and inexact state. */ + fenv_t fe = fegetenv_register (); + set_fenv_mode (mode); + if (x > 0.0) + { + r += 0x1p+52; + r -= 0x1p+52; + r = fabs (r); + } + else if (x < 0.0) + { + r -= 0x1p+52; + r += 0x1p+52; + r = -fabs (r); + } + __builtin_mtfsf (0xff, fe); + + return r; +} + +#endif diff --git a/sysdeps/powerpc/fpu/s_ceil.c b/sysdeps/powerpc/fpu/s_ceil.c new file mode 100644 index 0000000000..49008c7af8 --- /dev/null +++ b/sysdeps/powerpc/fpu/s_ceil.c @@ -0,0 +1,35 @@ +/* Smallest integral value not less than argument. PowerPC 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 Library General Public License as + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If + not, see <http://www.gnu.org/licenses/>. */ + +#define NO_MATH_REDIRECT +#include <math.h> +#include <libm-alias-double.h> +#include <round_to_integer.h> + +double +__ceil (double x) +{ +#ifdef _ARCH_PWR5X + return __builtin_ceil (x); +#else + return round_to_integer_double (CEIL, x); +#endif +} +#ifndef __ceil +libm_alias_double (__ceil, ceil) +#endif diff --git a/sysdeps/powerpc/fpu/s_ceilf.c b/sysdeps/powerpc/fpu/s_ceilf.c new file mode 100644 index 0000000000..8c86bf30a3 --- /dev/null +++ b/sysdeps/powerpc/fpu/s_ceilf.c @@ -0,0 +1,35 @@ +/* Smallest integral value not less than argument. PowerPC 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 Library General Public License as + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If + not, see <http://www.gnu.org/licenses/>. */ + +#define NO_MATH_REDIRECT +#include <math.h> +#include <libm-alias-float.h> +#include <round_to_integer.h> + +float +__ceilf (float x) +{ +#ifdef _ARCH_PWR5X + return __builtin_ceilf (x); +#else + return round_to_integer_float (CEIL, x); +#endif +} +#ifndef __ceilf +libm_alias_float (__ceil, ceil) +#endif |