I found just a small problem in this patch (see below).
On Fri, Mar 29 2019, Adhemerval Zanella wrote:
>
> The IFUNC support is also moved only to powerpc64 only, since for
> powerpc64le generic implementation resulting in optimized code.
Thanks, again.
For reference, again, a powerpc64 build produces:
000000000007e6c0 <.__llround_power8>:
7e6c0: fc 20 0b 10 frin f1,f1
7e6c4: fc 00 0e 5e fctidz f0,f1
7e6c8: 7c 03 00 66 mfvsrd r3,vs0
7e6cc: 4e 80 00 20 blr
000000000007e6e0 <.__llround_power6x>:
7e6e0: fc 20 0b 10 frin f1,f1
7e6e4: fc 00 0e 5e fctidz f0,f1
7e6e8: 7c 60 05 be mftgpr r3,f0
7e6ec: 4e 80 00 20 blr
000000000007e700 <.__llround_power5plus>:
7e700: fc 20 0b 10 frin f1,f1
7e704: fc 00 0e 5e fctidz f0,f1
7e708: d8 01 ff f8 stfd f0,-8(r1)
7e70c: 60 00 00 00 nop
7e710: e8 61 ff f8 ld r3,-8(r1)
7e714: 4e 80 00 20 blr
000000000007e730 <.__llround_ppc64>:
7e730: 3d 22 ff fa addis r9,r2,-6
7e734: fc 00 0a 10 fabs f0,f1
7e738: 38 60 00 00 li r3,0
7e73c: c1 89 a1 f4 lfs f12,-24076(r9)
7e740: fc 00 60 00 fcmpu cr0,f0,f12
7e744: 4d 80 00 20 bltlr
7e748: 3d 22 ff fa addis r9,r2,-6
7e74c: c1 49 6a 04 lfs f10,27140(r9)
7e750: fc 00 50 00 fcmpu cr0,f0,f10
7e754: 40 80 00 2c bge 7e780 <.__llround_ppc64+0x50>
7e758: fd 60 50 2a fadd f11,f0,f10
7e75c: fd 6b 50 28 fsub f11,f11,f10
7e760: fc 00 58 00 fcmpu cr0,f0,f11
7e764: 41 82 00 1c beq 7e780 <.__llround_ppc64+0x50>
7e768: 3d 22 ff fa addis r9,r2,-6
7e76c: fc 00 60 2a fadd f0,f0,f12
7e770: c1 69 9c e0 lfs f11,-25376(r9)
7e774: fc 01 58 00 fcmpu cr0,f1,f11
7e778: 41 80 00 28 blt 7e7a0 <.__llround_ppc64+0x70>
7e77c: fc 20 00 90 fmr f1,f0
7e780: fc 20 0e 5e fctidz f1,f1
7e784: d8 21 ff f8 stfd f1,-8(r1)
7e788: 60 00 00 00 nop
7e78c: 60 00 00 00 nop
7e790: 60 00 00 00 nop
7e794: e8 61 ff f8 ld r3,-8(r1)
7e798: 4e 80 00 20 blr
> --- a/sysdeps/powerpc/powerpc64/be/fpu/multiarch/Makefile
> +++ b/sysdeps/powerpc/powerpc64/be/fpu/multiarch/Makefile
>
> [...]
> CFLAGS-s_roundf-power5+.c = -mcpu=power5+
> CFLAGS-s_trunc-power5+.c = -mcpu=power5+
> CFLAGS-s_truncf-power5+.c = -mcpu=power5+
> -CFLAGS-s_llrint-power8.c += -mcpu=power8
> -CFLAGS-s_llrint-power6x.c += -mcpu=power6x
> +CFLAGS-s_llround-power8.c += -mcpu=power8
> +CFLAGS-s_llround-power6x.c += -mcpu=power6x
> +CFLAGS-s_llround-power5+.c += -mcpu=power5+
> endif
The removal of the two lines above is likely unintentional and wrong.
Looks good to me with that fixed. Thanks.
Reviewed-by: Gabriel F. T. Gomes <gabrielftg@linux.ibm.com>
@@ -17,7 +17,12 @@ libm-sysdep_routines += s_ceil-power5+ \
s_truncf-ppc64 \
s_llrint-power8 \
s_llrint-power6x \
- s_llrint-ppc64
+ s_llrint-ppc64 \
+ s_llround-power8 \
+ s_llround-power6x \
+ s_llround-power5+ \
+ s_llround-ppc64 \
+ s_llroundf-ppc64
CFLAGS-s_ceil-power5+.c = -mcpu=power5+
CFLAGS-s_ceilf-power5+.c = -mcpu=power5+
@@ -27,6 +32,7 @@ CFLAGS-s_round-power5+.c = -mcpu=power5+
CFLAGS-s_roundf-power5+.c = -mcpu=power5+
CFLAGS-s_trunc-power5+.c = -mcpu=power5+
CFLAGS-s_truncf-power5+.c = -mcpu=power5+
-CFLAGS-s_llrint-power8.c += -mcpu=power8
-CFLAGS-s_llrint-power6x.c += -mcpu=power6x
+CFLAGS-s_llround-power8.c += -mcpu=power8
+CFLAGS-s_llround-power6x.c += -mcpu=power6x
+CFLAGS-s_llround-power5+.c += -mcpu=power5+
endif
new file mode 100644
@@ -0,0 +1,2 @@
+#define __llround __llround_power5plus
+#include <sysdeps/powerpc/powerpc64/fpu/s_llround.c>
new file mode 100644
@@ -0,0 +1,2 @@
+#define __llround __llround_power6x
+#include <sysdeps/powerpc/powerpc64/fpu/s_llround.c>
new file mode 100644
@@ -0,0 +1,2 @@
+#define __llround __llround_power8
+#include <sysdeps/powerpc/powerpc64/fpu/s_llround.c>
new file mode 100644
@@ -0,0 +1,2 @@
+#define __llround __llround_ppc64
+#include <sysdeps/powerpc/powerpc64/fpu/s_llround.c>
similarity index 100%
rename from sysdeps/powerpc/powerpc64/fpu/multiarch/s_llround.c
rename to sysdeps/powerpc/powerpc64/be/fpu/multiarch/s_llround.c
new file mode 100644
@@ -0,0 +1,2 @@
+#define __llroundf __llroundf_ppc64
+#include <sysdeps/powerpc/powerpc64/fpu/s_llroundf.c>
similarity index 100%
rename from sysdeps/powerpc/powerpc64/fpu/multiarch/s_llroundf.c
rename to sysdeps/powerpc/powerpc64/be/fpu/multiarch/s_llroundf.c
similarity index 100%
rename from sysdeps/powerpc/powerpc64/fpu/multiarch/s_lround.c
rename to sysdeps/powerpc/powerpc64/be/fpu/multiarch/s_lround.c
@@ -2,4 +2,6 @@ ifeq ($(subdir),math)
# lrintf and llrintf are aliased to llrint, so suppress compiler builtins to
# avoid mismatched signatures.
CFLAGS-s_llrint.c += -fno-builtin-lrintf -fno-builtin-llrintf
+# Same as before but for lroundf and llroundf
+CFLAGS-s_llround.c += -fno-builtin-lroundf -fno-builtin-llroundf
endif
@@ -6,13 +6,10 @@ sysdep_calls := s_modf-power5+ s_modf-ppc64 \
s_modff-power5+ s_modff-ppc64
sysdep_routines += $(sysdep_calls)
-libm-sysdep_routines += s_llround-power6x \
- s_llround-power5+ s_llround-ppc64 \
- s_logb-power7 s_logbf-power7 \
+libm-sysdep_routines += s_logb-power7 s_logbf-power7 \
s_logbl-power7 s_logb-ppc64 s_logbf-ppc64 \
s_logbl-ppc64 e_hypot-ppc64 \
e_hypot-power7 e_hypotf-ppc64 e_hypotf-power7 \
- s_llround-power8 s_llroundf-ppc64 \
e_expf-power8 e_expf-ppc64 \
$(sysdep_calls:s_%=m_%)
deleted file mode 100644
@@ -1,31 +0,0 @@
-/* llround(). PowerPC64 default version.
- Copyright (C) 2013-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
- <http://www.gnu.org/licenses/>. */
-
-#include <shlib-compat.h>
-
-#undef weak_alias
-#define weak_alias(name, alias)
-#undef strong_alias
-#define strong_alias(name, alias)
-#undef compat_symbol
-#define compat_symbol(a,b,c,d)
-
-#define __llround __llround_power5plus
-#define __lround __lround_power5plus
-
-#include <sysdeps/powerpc/powerpc64/power5+/fpu/s_llround.S>
deleted file mode 100644
@@ -1,31 +0,0 @@
-/* llround(). PowerPC64 default version.
- Copyright (C) 2013-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
- <http://www.gnu.org/licenses/>. */
-
-#include <shlib-compat.h>
-
-#undef weak_alias
-#define weak_alias(name, alias)
-#undef strong_alias
-#define strong_alias(name, alias)
-#undef compat_symbol
-#define compat_symbol(lib, name, alias, ver)
-
-#define __llround __llround_power6x
-#define __lround __lround_power6x
-
-#include <sysdeps/powerpc/powerpc64/power6x/fpu/s_llround.S>
deleted file mode 100644
@@ -1,30 +0,0 @@
-/* llround(). PowerPC64 default version.
- Copyright (C) 2014-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
- <http://www.gnu.org/licenses/>. */
-
-#include <shlib-compat.h>
-
-#undef weak_alias
-#define weak_alias(name, alias)
-#undef strong_alias
-#define strong_alias(name, alias)
-#undef compat_symbol
-#define compat_symbol(lib, name, alias, ver)
-
-#define __llround __llround_power8
-
-#include <sysdeps/powerpc/powerpc64/power8/fpu/s_llround.S>
deleted file mode 100644
@@ -1,27 +0,0 @@
-/* llround(). PowerPC64 default version.
- Copyright (C) 2013-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
- <http://www.gnu.org/licenses/>. */
-
-#include <shlib-compat.h>
-
-#undef compat_symbol
-#define compat_symbol(a,b,c,d)
-
-#define __llround __llround_ppc64
-#define __lround __lround_ppc64
-
-#include <sysdeps/powerpc/powerpc64/fpu/s_llround.S>
deleted file mode 100644
@@ -1,31 +0,0 @@
-/* llroundf(). PowerPC64 default version.
- Copyright (C) 2017-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
- <http://www.gnu.org/licenses/>. */
-
-#include <shlib-compat.h>
-
-#undef weak_alias
-#define weak_alias(a,b)
-#undef strong_alias
-#define strong_alias(a,b)
-#undef compat_symbol
-#define compat_symbol(a,b,c,d)
-
-#define __llroundf __llroundf_ppc64
-#define __lroundf __lroundf_ppc64
-
-#include <sysdeps/powerpc/powerpc64/fpu/s_llroundf.S>
deleted file mode 100644
@@ -1,86 +0,0 @@
-/* llround function. PowerPC64 version.
- Copyright (C) 2004-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
- <http://www.gnu.org/licenses/>. */
-
-#include <sysdep.h>
-#include <math_ldbl_opt.h>
-#include <libm-alias-double.h>
-
- .section ".toc","aw"
-.LC0: /* 2^52 */
- .tc FD_43300000_0[TC],0x4330000000000000
-.LC1: /* 0.5 */
- .tc FD_3fe00000_0[TC],0x3fe0000000000000
- .section ".text"
-
-/* long long [r3] llround (double x [fp1])
- IEEE 1003.1 llround function. IEEE specifies "round to the nearest
- integer value, rounding halfway cases away from zero, regardless of
- the current rounding mode." However PowerPC Architecture defines
- "round to Nearest" as "Choose the best approximation. In case of a
- tie, choose the one that is even (least significant bit o).".
- So we can't use the PowerPC "round to Nearest" mode. Instead we set
- "round toward Zero" mode and round by adding +-0.5 before rounding
- to the integer value.
-
- It is necessary to detect when x is (+-)0x1.fffffffffffffp-2
- because adding +-0.5 in this case will cause an erroneous shift,
- carry and round. We simply return 0 if 0.5 > x > -0.5. Likewise
- if x is and odd number between +-(2^52 and 2^53-1) a shift and
- carry will erroneously round if biased with +-0.5. Therefore if x
- is greater/less than +-2^52 we don't need to bias the number with
- +-0.5. */
-
-ENTRY (__llround)
- CALL_MCOUNT 0
- lfd fp9,.LC0@toc(2) /* Load 2^52 into fpr9. */
- lfd fp10,.LC1@toc(2)/* Load 0.5 into fpr10. */
- fabs fp2,fp1 /* Get the absolute value of x. */
- fsub fp12,fp10,fp10 /* Compute 0.0 into fp12. */
- fcmpu cr6,fp2,fp10 /* if |x| < 0.5 */
- fcmpu cr7,fp2,fp9 /* if |x| >= 2^52 */
- fcmpu cr1,fp1,fp12 /* x is negative? x < 0.0 */
- blt- cr6,.Lretzero /* 0.5 > x < -0.5 so just return 0. */
- bge- cr7,.Lnobias /* 2^52 > x < -2^52 just convert with no bias. */
- /* Test whether an integer to avoid spurious "inexact". */
- fadd fp3,fp2,fp9
- fsub fp3,fp3,fp9
- fcmpu cr5,fp2,fp3
- beq cr5,.Lnobias
- fadd fp3,fp2,fp10 /* |x|+=0.5 bias to prepare to round. */
- bge cr1,.Lconvert /* x is positive so don't negate x. */
- fnabs fp3,fp3 /* -(|x|+=0.5) */
-.Lconvert:
- fctidz fp4,fp3 /* Convert to Integer double word round toward 0. */
- stfd fp4,-16(r1)
- nop
- nop
- nop
- ld r3,-16(r1) /* Load return as integer. */
-.Lout:
- blr
-.Lretzero: /* 0.5 > x > -0.5 */
- li r3,0 /* return 0. */
- b .Lout
-.Lnobias:
- fmr fp3,fp1
- b .Lconvert
- END (__llround)
-
-strong_alias (__llround, __lround)
-libm_alias_double (__llround, llround)
-libm_alias_double (__lround, lround)
new file mode 100644
@@ -0,0 +1,83 @@
+/* Round to nearest integer. PowerPC64 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
+#define lround __redirect_lround
+#define __lround __redirect___lround
+#include <math.h>
+#undef lround
+#undef __lround
+#include <libm-alias-double.h>
+#include <math-barriers.h>
+
+long long int
+__llround (double x)
+{
+#ifdef _ARCH_PWR5X
+ double r = __builtin_round (x);
+ /* Prevent gcc from calling llround directly when compiled with
+ -fno-math-errno by inserting a barrier. */
+ math_opt_barrier (r);
+ return r;
+#else
+ /* IEEE 1003.1 llround function. IEEE specifies "round to the nearest
+ integer value, rounding halfway cases away from zero, regardless of
+ the current rounding mode." However PowerPC Architecture defines
+ "round to Nearest" as "Choose the best approximation. In case of a
+ tie, choose the one that is even (least significant bit o).".
+ So we can't use the PowerPC "round to Nearest" mode. Instead we set
+ "round toward Zero" mode and round by adding +-0.5 before rounding
+ to the integer value.
+
+ It is necessary to detect when x is (+-)0x1.fffffffffffffp-2
+ because adding +-0.5 in this case will cause an erroneous shift,
+ carry and round. We simply return 0 if 0.5 > x > -0.5. Likewise
+ if x is and odd number between +-(2^52 and 2^53-1) a shift and
+ carry will erroneously round if biased with +-0.5. Therefore if x
+ is greater/less than +-2^52 we don't need to bias the number with
+ +-0.5. */
+
+ double ax = fabs (x);
+
+ if (ax < 0.5)
+ return 0;
+
+ if (ax < 0x1p+52)
+ {
+ /* Test whether an integer to avoid spurious "inexact". */
+ double t = ax + 0x1p+52;
+ t = t - 0x1p+52;
+ if (ax != t)
+ {
+ ax = ax + 0.5;
+ if (x < 0.0)
+ ax = -fabs (ax);
+ x = ax;
+ }
+ }
+
+ long int ret;
+ __asm__ ("fctidz %0, %1" : "=d" (ret) : "d" (x));
+ return ret;
+#endif
+}
+#ifndef __llround
+strong_alias (__llround, __lround)
+libm_alias_double (__llround, llround)
+libm_alias_double (__lround, lround)
+#endif
deleted file mode 100644
@@ -1,89 +0,0 @@
-/* llroundf function. PowerPC64 version.
- Copyright (C) 2004-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
- <http://www.gnu.org/licenses/>. */
-
-#include <sysdep.h>
-#include <libm-alias-float.h>
-
- .section ".toc","aw"
-.LC0: /* 2^23 */
- .tc FD_41600000_0[TC],0x4160000000000000
-.LC1: /* 0.5 */
- .tc FD_3fe00000_0[TC],0x3fe0000000000000
-.LC2: /* 2^52 */
- .tc FD_43300000_0[TC],0x4330000000000000
- .section ".text"
-
-/* long long [r3] llroundf (float x [fp1])
- IEEE 1003.1 llroundf function. IEEE specifies "roundf to the nearest
- integer value, rounding halfway cases away from zero, regardless of
- the current rounding mode." However PowerPC Architecture defines
- "roundf to Nearest" as "Choose the best approximation. In case of a
- tie, choose the one that is even (least significant bit o).".
- So we can't use the PowerPC "round to Nearest" mode. Instead we set
- "round toward Zero" mode and round by adding +-0.5 before rounding
- to the integer value.
-
- It is necessary to detect when x is (+-)0x1.fffffffffffffp-2
- because adding +-0.5 in this case will cause an erroneous shift,
- carry and round. We simply return 0 if 0.5 > x > -0.5. Likewise
- if x is and odd number between +-(2^23 and 2^24-1) a shift and
- carry will erroneously round if biased with +-0.5. Therefore if x
- is greater/less than +-2^23 we don't need to bias the number with
- +-0.5. */
-
-ENTRY (__llroundf)
- CALL_MCOUNT 0
- lfd fp9,.LC0@toc(2) /* Load 2^23 into fpr9. */
- lfd fp10,.LC1@toc(2)/* Load 0.5 into fpr10. */
- lfd fp11,.LC2@toc(2) /* Load 2^52 into fpr11. */
- fabs fp2,fp1 /* Get the absolute value of x. */
- fsub fp12,fp10,fp10 /* Compute 0.0 into fp12. */
- fcmpu cr6,fp2,fp10 /* if |x| < 0.5 */
- fcmpu cr7,fp2,fp9 /* if |x| >= 2^23 */
- fcmpu cr1,fp1,fp12 /* x is negative? x < 0.0 */
- blt- cr6,.Lretzero /* 0.5 > x < -0.5 so just return 0. */
- bge- cr7,.Lnobias /* 2^23 > x < -2^23 just convert with no bias. */
- /* Test whether an integer to avoid spurious "inexact". */
- fadd fp3,fp2,fp11
- fsub fp3,fp3,fp11
- fcmpu cr5,fp2,fp3
- beq cr5,.Lnobias
- fadd fp3,fp2,fp10 /* |x|+=0.5 bias to prepare to round. */
- bge cr1,.Lconvert /* x is positive so don't negate x. */
- fnabs fp3,fp3 /* -(|x|+=0.5) */
-.Lconvert:
- fctidz fp4,fp3 /* Convert to Integer double word round toward 0. */
- stfd fp4,-16(r1)
- nop
- nop
- nop
- ld r3,-16(r1) /* Load return as integer. */
-.Lout:
- blr
-.Lretzero: /* 0.5 > x > -0.5 */
- li r3,0 /* return 0. */
- b .Lout
-.Lnobias:
- fmr fp3,fp1
- b .Lconvert
- END (__llroundf)
-
-strong_alias (__llroundf, __lroundf)
-libm_alias_float (__llround, llround)
-libm_alias_float (__lround, lround)
-
new file mode 100644
@@ -0,0 +1,83 @@
+/* Round to nearest integer. PowerPC64 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
+#define lroundf __redirect_llround
+#define __lroundf __redirect___lround
+#include <math.h>
+#undef lroundf
+#undef __lroundf
+#include <libm-alias-float.h>
+#include <math-barriers.h>
+
+long long int
+__llroundf (float x)
+{
+#ifdef _ARCH_PWR5X
+ double r = __builtin_round (x);
+ /* Prevent gcc from calling llround directly when compiled with
+ -fno-math-errno by inserting a barrier. */
+ math_opt_barrier (r);
+ return r;
+#else
+ /* IEEE 1003.1 llroundf function. IEEE specifies "roundf to the nearest
+ integer value, rounding halfway cases away from zero, regardless of
+ the current rounding mode." However PowerPC Architecture defines
+ "roundf to Nearest" as "Choose the best approximation. In case of a
+ tie, choose the one that is even (least significant bit o).".
+ So we can't use the PowerPC "round to Nearest" mode. Instead we set
+ "round toward Zero" mode and round by adding +-0.5 before rounding
+ to the integer value.
+
+ It is necessary to detect when x is (+-)0x1.fffffffffffffp-2
+ because adding +-0.5 in this case will cause an erroneous shift,
+ carry and round. We simply return 0 if 0.5 > x > -0.5. Likewise
+ if x is and odd number between +-(2^23 and 2^24-1) a shift and
+ carry will erroneously round if biased with +-0.5. Therefore if x
+ is greater/less than +-2^23 we don't need to bias the number with
+ +-0.5. */
+
+ float ax = fabsf (x);
+
+ if (ax < 0.5f)
+ return 0;
+
+ if (ax < 0x1p+23f)
+ {
+ /* Test whether an integer to avoid spurious "inexact". */
+ float t = ax + 0x1p+23f;
+ t = t - 0x1p+23f;
+ if (ax != t)
+ {
+ ax = ax + 0.5f;
+ if (x < 0.0f)
+ ax = -fabs (ax);
+ x = ax;
+ }
+ }
+
+ long int ret;
+ __asm__ ("fctidz %0, %1" : "=d" (ret) : "d" (x));
+ return ret;
+#endif
+}
+#ifndef __llroundf
+strong_alias (__llroundf, __lroundf)
+libm_alias_float (__llround, lround)
+libm_alias_float (__llround, llround)
+#endif
deleted file mode 100644
@@ -1 +0,0 @@
-/* __lround is in s_llround.S */
new file mode 100644
@@ -0,0 +1 @@
+/* lround is implemented at s_llround.c as an alias to lround. */
deleted file mode 100644
@@ -1 +0,0 @@
-/* __lroundf is in s_llroundf.S */
new file mode 100644
@@ -0,0 +1 @@
+/* __lroundf is in s_llroundf.c */
deleted file mode 100644
@@ -1,56 +0,0 @@
-/* llround function. POWER5+, PowerPC64 version.
- Copyright (C) 2006-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
- <http://www.gnu.org/licenses/>. */
-
-#include <sysdep.h>
-#include <math_ldbl_opt.h>
-#include <libm-alias-float.h>
-#include <libm-alias-double.h>
-
-/* long long [r3] llround (float x [fp1])
- IEEE 1003.1 llround function. IEEE specifies "round to the nearest
- integer value, rounding halfway cases away from zero, regardless of
- the current rounding mode." However PowerPC Architecture defines
- "round to Nearest" as "Choose the best approximation. In case of a
- tie, choose the one that is even (least significant bit o).".
- So we pre-round using the V2.02 Floating Round to Integer Nearest
- instruction before we use Floating Convert to Integer Word with
- round to zero instruction. */
-
- .machine "power5"
-ENTRY_TOCLESS (__llround, 4)
- CALL_MCOUNT 0
- frin fp2, fp1 /* Round to nearest +-0.5. */
- fctidz fp3, fp2 /* Convert To Integer DW round toward 0. */
- stfd fp3, -16(r1)
- nop /* Insure the following load is in a different dispatch group */
- nop /* to avoid pipe stall on POWER4&5. */
- nop
- ld r3, -16(r1)
- blr
- END (__llround)
-
-strong_alias (__llround, __lround)
-libm_alias_double (__llround, llround)
-libm_alias_double (__lround, lround)
-/* The double version also works for single-precision as both float and
- double parameters are passed in 64bit FPRs and both versions are expected
- to return [long] long type. */
-strong_alias (__llround, __llroundf)
-libm_alias_float (__llround, llround)
-strong_alias (__lround, __lroundf)
-libm_alias_float (__lround, lround)
deleted file mode 100644
@@ -1 +0,0 @@
-/* __lroundf is in s_llround.S. */
deleted file mode 100644
@@ -1,52 +0,0 @@
-/* llround function. POWER6x PowerPC64 version.
- Copyright (C) 2006-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
- <http://www.gnu.org/licenses/>. */
-
-#include <sysdep.h>
-#include <math_ldbl_opt.h>
-#include <libm-alias-float.h>
-#include <libm-alias-double.h>
-
-/* long long [r3] llround (float x [fp1])
- IEEE 1003.1 llround function. IEEE specifies "round to the nearest
- integer value, rounding halfway cases away from zero, regardless of
- the current rounding mode." However PowerPC Architecture defines
- "round to Nearest" as "Choose the best approximation. In case of a
- tie, choose the one that is even (least significant bit o).".
- So we pre-round using the V2.02 Floating Round to Integer Nearest
- instruction before we use Floating Convert to Integer Word with
- round to zero instruction. */
-
- .machine "power6"
-ENTRY_TOCLESS (__llround)
- CALL_MCOUNT 0
- frin fp2,fp1 /* Round to nearest +-0.5. */
- fctidz fp3,fp2 /* Convert To Integer DW round toward 0. */
- mftgpr r3,fp3 /* Transfer integer to R3. */
- blr
- END (__llround)
-
-strong_alias (__llround, __lround)
-libm_alias_double (__llround, llround)
-libm_alias_double (__lround, lround)
-/* The double version also works for single-precision as both float and
- double parameters are passed in 64bit FPRs and both versions are expected
- to return [long] long type. */
-strong_alias (__llround, __llroundf)
-libm_alias_float (__llround, llround)
-strong_alias (__lround, __lroundf)
-libm_alias_float (__lround, lround)
deleted file mode 100644
@@ -1 +0,0 @@
-/* __lroundf is in s_llround.S. */
deleted file mode 100644
@@ -1,46 +0,0 @@
-/* llround function. POWER8 PowerPC64 version.
- Copyright (C) 2014-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
- <http://www.gnu.org/licenses/>. */
-
-#include <sysdep.h>
-#include <endian.h>
-#include <math_ldbl_opt.h>
-#include <libm-alias-float.h>
-#include <libm-alias-double.h>
-
-#define MFVSRD_R3_V1 .long 0x7c230066 /* mfvsrd r3,vs1 */
-
-/* long long [r3] llround (float x [fp1]) */
-
-ENTRY_TOCLESS (__llround)
- CALL_MCOUNT 0
- frin fp1,fp1 /* Round to nearest +-0.5. */
- fctidz fp1,fp1 /* Convert To Integer DW round toward 0. */
- MFVSRD_R3_V1
- blr
-END (__llround)
-
-strong_alias (__llround, __lround)
-libm_alias_double (__llround, llround)
-libm_alias_double (__lround, lround)
-/* The double version also works for single-precision as both float and
- double parameters are passed in 64bit FPRs and both versions are expected
- to return [long] long type. */
-strong_alias (__llround, __llroundf)
-libm_alias_float (__llround, llround)
-strong_alias (__lround, __lroundf)
-libm_alias_float (__lround, lround)
deleted file mode 100644
@@ -1 +0,0 @@
-/* __lroundf is in s_llround.S. */