summaryrefslogtreecommitdiff
path: root/libc/sysdeps/powerpc
diff options
context:
space:
mode:
authorjoseph <joseph@7b3dc134-2b1b-0410-93df-9e9f96275f8d>2008-04-12 10:53:49 +0000
committerjoseph <joseph@7b3dc134-2b1b-0410-93df-9e9f96275f8d>2008-04-12 10:53:49 +0000
commit08567827b4d55a05c3afcdadb5ae322089287150 (patch)
treee67a3610598bd7351d4c4cad020a093f9d41ed25 /libc/sysdeps/powerpc
parent29888bcfdf080afd1ccbe11b7939b17a9eb5d9bf (diff)
downloadeglibc2-08567827b4d55a05c3afcdadb5ae322089287150.tar.gz
Merge changes between r5879 and r5900 from /fsf/trunk.
Also: * sysdeps/unix/sysv/linux/powerpc/bits/mathinline.h: Also test __NO_FPRS__. git-svn-id: svn://svn.eglibc.org/trunk@5901 7b3dc134-2b1b-0410-93df-9e9f96275f8d
Diffstat (limited to 'libc/sysdeps/powerpc')
-rw-r--r--libc/sysdeps/powerpc/bits/fenv.h7
-rw-r--r--libc/sysdeps/powerpc/fpu/e_sqrt.c8
-rw-r--r--libc/sysdeps/powerpc/fpu/e_sqrtf.c8
-rw-r--r--libc/sysdeps/powerpc/fpu/fe_nomask.c5
-rw-r--r--libc/sysdeps/powerpc/fpu/fedisblxcpt.c6
-rw-r--r--libc/sysdeps/powerpc/fpu/feenablxcpt.c6
-rw-r--r--libc/sysdeps/powerpc/fpu/fegetexcept.c7
-rw-r--r--libc/sysdeps/powerpc/fpu/fenv_libc.h6
-rw-r--r--libc/sysdeps/powerpc/fpu/fraiseexcpt.c11
-rw-r--r--libc/sysdeps/powerpc/powerpc32/fpu/s_lround.S52
-rw-r--r--libc/sysdeps/powerpc/powerpc32/fpu/s_lroundf.S1
-rw-r--r--libc/sysdeps/powerpc/powerpc32/power4/fpu/s_llround.S71
-rw-r--r--libc/sysdeps/powerpc/powerpc32/power5+/fpu/s_llroundf.S1
-rw-r--r--libc/sysdeps/powerpc/powerpc32/power6/fpu/s_llroundf.S1
-rw-r--r--libc/sysdeps/powerpc/powerpc64/fpu/s_llround.S57
-rw-r--r--libc/sysdeps/powerpc/powerpc64/fpu/s_llroundf.S53
-rw-r--r--libc/sysdeps/powerpc/powerpc64/fpu/s_lrint.S1
-rw-r--r--libc/sysdeps/powerpc/powerpc64/fpu/s_lround.S1
-rw-r--r--libc/sysdeps/powerpc/powerpc64/fpu/s_lroundf.S1
19 files changed, 186 insertions, 117 deletions
diff --git a/libc/sysdeps/powerpc/bits/fenv.h b/libc/sysdeps/powerpc/bits/fenv.h
index dc70d9117..14447b5f4 100644
--- a/libc/sysdeps/powerpc/bits/fenv.h
+++ b/libc/sysdeps/powerpc/bits/fenv.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 1998, 1999, 2004, 2006 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 1998, 1999, 2004, 2006,2008 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
@@ -196,6 +196,8 @@ extern const fenv_t __fe_enabled_env;
extern const fenv_t __fe_nonieee_env;
# define FE_NONIEEE_ENV (&__fe_nonieee_env)
+__BEGIN_DECLS
+
/* Floating-point environment with all exceptions enabled. Note that
just evaluating this value does not change the processor exception mode.
Passing this mask to fesetenv will result in a prctl syscall to change
@@ -212,6 +214,9 @@ extern const fenv_t *__fe_nomask_env (void);
this allows the fastest possible floating point execution.*/
extern const fenv_t *__fe_mask_env (void);
# define FE_MASK_ENV FE_DFL_ENV
+
+__END_DECLS
+
#endif
#endif
diff --git a/libc/sysdeps/powerpc/fpu/e_sqrt.c b/libc/sysdeps/powerpc/fpu/e_sqrt.c
index 540b92465..24e0dd352 100644
--- a/libc/sysdeps/powerpc/fpu/e_sqrt.c
+++ b/libc/sysdeps/powerpc/fpu/e_sqrt.c
@@ -1,5 +1,5 @@
/* Double-precision floating point square root.
- Copyright (C) 1997, 2002, 2003, 2004 Free Software Foundation, Inc.
+ Copyright (C) 1997, 2002, 2003, 2004, 2008 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
@@ -150,7 +150,9 @@ __slow_ieee754_sqrt (x)
FE_INVALID_SQRT. */
#ifdef FE_INVALID_SQRT
feraiseexcept (FE_INVALID_SQRT);
- if (!fetestexcept (FE_INVALID))
+
+ fenv_union_t u = { .fenv = fegetenv_register () };
+ if ((u.l[1] & FE_INVALID) == 0)
#endif
feraiseexcept (FE_INVALID);
x = a_nan.value;
@@ -172,7 +174,7 @@ __ieee754_sqrt (x)
/* If the CPU is 64-bit we can use the optional FP instructions. */
if (__CPU_HAS_FSQRT)
{
- /* Volatile is required to prevent the compiler from moving the
+ /* Volatile is required to prevent the compiler from moving the
fsqrt instruction above the branch. */
__asm __volatile (" fsqrt %0,%1\n"
:"=f" (z):"f" (x));
diff --git a/libc/sysdeps/powerpc/fpu/e_sqrtf.c b/libc/sysdeps/powerpc/fpu/e_sqrtf.c
index b63d31472..8e8138a17 100644
--- a/libc/sysdeps/powerpc/fpu/e_sqrtf.c
+++ b/libc/sysdeps/powerpc/fpu/e_sqrtf.c
@@ -1,5 +1,5 @@
/* Single-precision floating point square root.
- Copyright (C) 1997, 2003, 2004 Free Software Foundation, Inc.
+ Copyright (C) 1997, 2003, 2004, 2008 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
@@ -126,7 +126,9 @@ __slow_ieee754_sqrtf (x)
FE_INVALID_SQRT. */
#ifdef FE_INVALID_SQRT
feraiseexcept (FE_INVALID_SQRT);
- if (!fetestexcept (FE_INVALID))
+
+ fenv_union_t u = { .fenv = fegetenv_register () };
+ if ((u.l[1] & FE_INVALID) == 0)
#endif
feraiseexcept (FE_INVALID);
x = a_nan.value;
@@ -149,7 +151,7 @@ __ieee754_sqrtf (x)
/* If the CPU is 64-bit we can use the optional FP instructions. */
if (__CPU_HAS_FSQRT)
{
- /* Volatile is required to prevent the compiler from moving the
+ /* Volatile is required to prevent the compiler from moving the
fsqrt instruction above the branch. */
__asm __volatile (" fsqrts %0,%1\n"
:"=f" (z):"f" (x));
diff --git a/libc/sysdeps/powerpc/fpu/fe_nomask.c b/libc/sysdeps/powerpc/fpu/fe_nomask.c
index 3cccee1d0..bc18bb8f8 100644
--- a/libc/sysdeps/powerpc/fpu/fe_nomask.c
+++ b/libc/sysdeps/powerpc/fpu/fe_nomask.c
@@ -1,5 +1,5 @@
/* Procedure definition for FE_NOMASK_ENV.
- Copyright (C) 1997 Free Software Foundation, Inc.
+ Copyright (C) 1997, 2008 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
@@ -17,7 +17,7 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
-#include <fenv.h>
+#include <fenv_libc.h>
#include <errno.h>
/* This is a generic stub. An OS specific override is required to set
@@ -30,4 +30,5 @@ __fe_nomask_env(void)
__set_errno (ENOSYS);
return FE_ENABLED_ENV;
}
+libm_hidden_def (__fe_nomask_env)
stub_warning (__fe_nomask_env)
diff --git a/libc/sysdeps/powerpc/fpu/fedisblxcpt.c b/libc/sysdeps/powerpc/fpu/fedisblxcpt.c
index 3002b1b4c..9df4bbc7e 100644
--- a/libc/sysdeps/powerpc/fpu/fedisblxcpt.c
+++ b/libc/sysdeps/powerpc/fpu/fedisblxcpt.c
@@ -1,5 +1,5 @@
/* Disable floating-point exceptions.
- Copyright (C) 2000 Free Software Foundation, Inc.
+ Copyright (C) 2000, 2008 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Geoffrey Keating <geoffk@geoffk.org>, 2000.
@@ -26,7 +26,7 @@ fedisableexcept (int excepts)
fenv_union_t fe;
int result, new;
- result = fegetexcept ();
+ result = __fegetexcept ();
if ((excepts & FE_ALL_INVALID) == FE_ALL_INVALID)
excepts = (excepts | FE_INVALID) & ~ FE_ALL_INVALID;
@@ -44,7 +44,7 @@ fedisableexcept (int excepts)
fe.l[1] &= ~(1 << (31 - FPSCR_VE));
fesetenv_register (fe.fenv);
- new = fegetexcept ();
+ new = __fegetexcept ();
if (new == 0 && result != 0)
(void)__fe_mask_env ();
diff --git a/libc/sysdeps/powerpc/fpu/feenablxcpt.c b/libc/sysdeps/powerpc/fpu/feenablxcpt.c
index 7bff18b42..4875e95e3 100644
--- a/libc/sysdeps/powerpc/fpu/feenablxcpt.c
+++ b/libc/sysdeps/powerpc/fpu/feenablxcpt.c
@@ -1,5 +1,5 @@
/* Enable floating-point exceptions.
- Copyright (C) 2000 Free Software Foundation, Inc.
+ Copyright (C) 2000, 2008 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Geoffrey Keating <geoffk@geoffk.org>, 2000.
@@ -26,7 +26,7 @@ feenableexcept (int excepts)
fenv_union_t fe;
int result, new;
- result = fegetexcept ();
+ result = __fegetexcept ();
if ((excepts & FE_ALL_INVALID) == FE_ALL_INVALID)
excepts = (excepts | FE_INVALID) & ~ FE_ALL_INVALID;
@@ -44,7 +44,7 @@ feenableexcept (int excepts)
fe.l[1] |= (1 << (31 - FPSCR_VE));
fesetenv_register (fe.fenv);
- new = fegetexcept ();
+ new = __fegetexcept ();
if (new != 0 && result == 0)
(void)__fe_nomask_env ();
diff --git a/libc/sysdeps/powerpc/fpu/fegetexcept.c b/libc/sysdeps/powerpc/fpu/fegetexcept.c
index 0b5cebb6d..c85cb1b22 100644
--- a/libc/sysdeps/powerpc/fpu/fegetexcept.c
+++ b/libc/sysdeps/powerpc/fpu/fegetexcept.c
@@ -1,5 +1,5 @@
/* Get floating-point exceptions.
- Copyright (C) 2000 Free Software Foundation, Inc.
+ Copyright (C) 2000, 2008 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Geoffrey Keating <geoffk@geoffk.org>, 2000.
@@ -21,13 +21,13 @@
#include <fenv_libc.h>
int
-fegetexcept (void)
+__fegetexcept (void)
{
fenv_union_t fe;
int result = 0;
fe.fenv = fegetenv_register ();
-
+
if (fe.l[1] & (1 << (31 - FPSCR_XE)))
result |= FE_INEXACT;
if (fe.l[1] & (1 << (31 - FPSCR_ZE)))
@@ -41,3 +41,4 @@ fegetexcept (void)
return result;
}
+weak_alias (__fegetexcept, fegetexcept)
diff --git a/libc/sysdeps/powerpc/fpu/fenv_libc.h b/libc/sysdeps/powerpc/fpu/fenv_libc.h
index fd5fc0c76..6f116b60d 100644
--- a/libc/sysdeps/powerpc/fpu/fenv_libc.h
+++ b/libc/sysdeps/powerpc/fpu/fenv_libc.h
@@ -1,5 +1,5 @@
/* Internal libc stuff for floating point environment routines.
- Copyright (C) 1997, 2006 Free Software Foundation, Inc.
+ Copyright (C) 1997, 2006, 2008 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
@@ -22,6 +22,8 @@
#include <fenv.h>
+libm_hidden_proto (__fe_nomask_env)
+
/* The sticky bits in the FPSCR indicating exceptions have occurred. */
#define FPSCR_STICKY_BITS ((FE_ALL_EXCEPT | FE_ALL_INVALID) & ~FE_INVALID)
@@ -137,5 +139,5 @@ enum {
({ float f; asm volatile ("fmuls %0,%1,%2" \
: "=f"(f) \
: "f" (x), "f"((float)1.0)); f; })
-
+
#endif /* fenv_libc.h */
diff --git a/libc/sysdeps/powerpc/fpu/fraiseexcpt.c b/libc/sysdeps/powerpc/fpu/fraiseexcpt.c
index dbe36c3d5..2d983d97c 100644
--- a/libc/sysdeps/powerpc/fpu/fraiseexcpt.c
+++ b/libc/sysdeps/powerpc/fpu/fraiseexcpt.c
@@ -1,5 +1,5 @@
/* Raise given exceptions.
- Copyright (C) 1997,99,2000,01,02 Free Software Foundation, Inc.
+ Copyright (C) 1997,1999-2002, 2008 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
@@ -45,12 +45,15 @@ __feraiseexcept (int excepts)
triggering any appropriate exceptions. */
fesetenv_register (u.fenv);
- if ((excepts & FE_INVALID)
+ if ((excepts & FE_INVALID))
+ {
/* For some reason, some PowerPC chips (the 601, in particular)
don't have FE_INVALID_SOFTWARE implemented. Detect this
case and raise FE_INVALID_SNAN instead. */
- && !fetestexcept (FE_INVALID))
- set_fpscr_bit (FPSCR_VXSNAN);
+ u.fenv = fegetenv_register ();
+ if ((u.l[1] & FE_INVALID) == 0)
+ set_fpscr_bit (FPSCR_VXSNAN);
+ }
/* Success. */
return 0;
diff --git a/libc/sysdeps/powerpc/powerpc32/fpu/s_lround.S b/libc/sysdeps/powerpc/powerpc32/fpu/s_lround.S
index 9c534ec2b..ebaccccd9 100644
--- a/libc/sysdeps/powerpc/powerpc32/fpu/s_lround.S
+++ b/libc/sysdeps/powerpc/powerpc32/fpu/s_lround.S
@@ -1,5 +1,5 @@
/* lround function. PowerPC32 version.
- Copyright (C) 2004, 2006 Free Software Foundation, Inc.
+ Copyright (C) 2004, 2006, 2007 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
@@ -20,13 +20,10 @@
#include <sysdep.h>
#include <math_ldbl_opt.h>
- .section .rodata.cst8,"aM",@progbits,8
+ .section .rodata.cst4,"aM",@progbits,4
.align 2
-.LC0: /* 0.0 */
- .long 0x00000000
-.LC1: /* 0.5 */
+.LC0: /* 0.5 */
.long 0x3f000000
-
.section ".text"
/* long [r3] lround (float x [fp1])
@@ -37,7 +34,10 @@
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. */
+ 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. */
ENTRY (__lround)
stwu r1,-16(r1)
@@ -49,40 +49,40 @@ ENTRY (__lround)
bcl 20,31,1f
1: mflr r9
addis r9,r9,.LC0-1b@ha
- addi r9,r9,.LC0-1b@l
+ lfs fp10,.LC0-1b@l(r9)
# else
bl _GLOBAL_OFFSET_TABLE_@local-4
mflr r10
lwz r9,.LC0@got(10)
+ lfs fp10,0(r9)
# endif
mtlr r11
cfi_same_value (lr)
- lfs fp12,0(r9)
#else
lis r9,.LC0@ha
- lfs fp12,.LC0@l(r9)
-#endif
-#ifdef SHARED
- lfs fp10,.LC1-.LC0(r9)
-#else
- lis r9,.LC1@ha
- lfs fp10,.LC1@l(r9)
+ lfs fp10,.LC0@l(r9)
#endif
- fcmpu cr6,fp1,fp12 /* if (x > 0.0) */
- ble- cr6,.L4
- fadd fp1,fp1,fp10 /* x+= 0.5; */
-.L9:
- fctiwz fp2,fp1 /* Convert To Integer DW lround toward 0. */
- stfd fp2,8(r1)
+ fabs fp2, fp1 /* Get the absolute value of x. */
+ fsub fp12,fp10,fp10 /* Compute 0.0. */
+ fcmpu cr6, fp2, fp10 /* if |x| < 0.5 */
+ fcmpu cr3, fp1, fp12 /* x is negative? x < 0.0 */
+ blt- cr6,.Lretzero
+ fadd fp3,fp2,fp10 /* |x|+=0.5 bias to prepare to round. */
+ bge cr3,.Lconvert /* x is positive so don't negate x. */
+ fnabs fp3,fp3 /* -(|x|+=0.5) */
+.Lconvert:
+ fctiwz fp4,fp3 /* Convert to Integer word lround toward 0. */
+ stfd fp4,8(r1)
nop /* Ensure the following load is in a different dispatch */
nop /* group to avoid pipe stall on POWER4&5. */
nop
- lwz r3,12(r1)
+ lwz r3,12(r1) /* Load return as integer. */
+.Lout:
addi r1,r1,16
blr
-.L4:
- fsub fp1,fp1,fp10 /* x-= 0.5; */
- b .L9
+.Lretzero: /* when 0.5 > x > -0.5 */
+ li r3,0 /* return 0. */
+ b .Lout
END (__lround)
weak_alias (__lround, lround)
diff --git a/libc/sysdeps/powerpc/powerpc32/fpu/s_lroundf.S b/libc/sysdeps/powerpc/powerpc32/fpu/s_lroundf.S
index e3c992d77..6289e0be5 100644
--- a/libc/sysdeps/powerpc/powerpc32/fpu/s_lroundf.S
+++ b/libc/sysdeps/powerpc/powerpc32/fpu/s_lroundf.S
@@ -1,2 +1 @@
/* __lroundf is in s_lround.S */
-/* __lroundf is in s_lround.S */
diff --git a/libc/sysdeps/powerpc/powerpc32/power4/fpu/s_llround.S b/libc/sysdeps/powerpc/powerpc32/power4/fpu/s_llround.S
index 952d2aa6a..4b1691efd 100644
--- a/libc/sysdeps/powerpc/powerpc32/power4/fpu/s_llround.S
+++ b/libc/sysdeps/powerpc/powerpc32/power4/fpu/s_llround.S
@@ -1,5 +1,5 @@
/* llround function. PowerPC32 on PowerPC64 version.
- Copyright (C) 2004, 2006 Free Software Foundation, Inc.
+ Copyright (C) 2004, 2006, 2007 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
@@ -20,15 +20,15 @@
#include <sysdep.h>
#include <math_ldbl_opt.h>
- .section .rodata.cst8,"aM",@progbits,8
- .align 2
-.LC0: /* 0.0 */
+ .section .rodata.cst12,"aM",@progbits,12
+ .align 3
+ .LC0: /* 0x1.0000000000000p+52 == 2^52 */
+ .long 0x43300000
.long 0x00000000
-.LC1: /* 0.5 */
- .long 0x3f000000
+ .long 0x3f000000 /* Use this for 0.5 */
.section ".text"
-
+
/* long [r3] lround (float x [fp1])
IEEE 1003.1 lround function. IEEE specifies "round to the nearest
integer value, rounding halfway cases away from zero, regardless of
@@ -37,7 +37,15 @@
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. */
+ 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)
stwu r1,-16(r1)
@@ -57,30 +65,41 @@ ENTRY (__llround)
# endif
mtlr r11
cfi_same_value (lr)
- lfs fp12,0(r9)
- lfs fp10,.LC1-.LC0(r9)
+ lfd fp9,0(r9)
+ lfs fp10,8(r9)
#else
- lis r9,.LC0@ha
- lis r10,.LC1@ha
- lfs fp12,.LC0@l(r9)
- lfs fp10,.LC1@l(r10)
+ lis r9,.LC0@ha
+ lfd fp9,.LC0@l(r9) /* Load 2^52 into fpr9. */
+ lfs fp10,.LC0@l+8(r9) /* Load 0.5 into fpr10. */
#endif
- fcmpu cr6,fp1,fp12 /* if (x > 0.0) */
- ble- cr6,.L4
- fadd fp1,fp1,fp10 /* x+= 0.5; */
-.L9:
- fctidz fp2,fp1 /* Convert To Integer DW round toward 0. */
- stfd fp2,8(r1)
- nop /* Ensure the following load is in a different dispatch */
- nop /* group to avoid pipe stall on POWER4&5. */
+ fabs fp2,fp1 /* Get the absolute value of x. */
+ fsub fp12,fp10,fp10 /* Compute 0.0 into fpr12. */
+ fcmpu cr6,fp2,fp10 /* if |x| < 0.5 */
+ fcmpu cr4,fp2,fp9 /* if |x| >= 2^52 */
+ fcmpu cr3,fp1,fp12 /* x is negative? x < 0.0 */
+ blt- cr6,.Lretzero /* 0.5 > x < -0.5 so just return 0. */
+ bge- cr4,.Lnobias /* 2^52 > x < -2^52 just convert with no bias. */
+ fadd fp3,fp2,fp10 /* |x|+=0.5 bias to prepare to round. */
+ bge cr3,.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,8(r1)
+ nop
+ nop
nop
- lwz r4,12(r1)
+ lwz r4,12(r1) /* Load return as integer. */
lwz r3,8(r1)
+.Lout:
addi r1,r1,16
blr
-.L4:
- fsub fp1,fp1,fp10 /* x-= 0.5; */
- b .L9
+.Lretzero: /* 0.5 > x > -0.5 */
+ li r3,0 /* return 0. */
+ li r4,0
+ b .Lout
+.Lnobias:
+ fmr fp3,fp1
+ b .Lconvert
END (__llround)
weak_alias (__llround, llround)
diff --git a/libc/sysdeps/powerpc/powerpc32/power5+/fpu/s_llroundf.S b/libc/sysdeps/powerpc/powerpc32/power5+/fpu/s_llroundf.S
index ffe6b7eb3..030d2fdff 100644
--- a/libc/sysdeps/powerpc/powerpc32/power5+/fpu/s_llroundf.S
+++ b/libc/sysdeps/powerpc/powerpc32/power5+/fpu/s_llroundf.S
@@ -1,2 +1 @@
/* __llroundf is in s_llround.S */
-/* __llroundf is in s_llround.S */
diff --git a/libc/sysdeps/powerpc/powerpc32/power6/fpu/s_llroundf.S b/libc/sysdeps/powerpc/powerpc32/power6/fpu/s_llroundf.S
index ffe6b7eb3..030d2fdff 100644
--- a/libc/sysdeps/powerpc/powerpc32/power6/fpu/s_llroundf.S
+++ b/libc/sysdeps/powerpc/powerpc32/power6/fpu/s_llroundf.S
@@ -1,2 +1 @@
/* __llroundf is in s_llround.S */
-/* __llroundf is in s_llround.S */
diff --git a/libc/sysdeps/powerpc/powerpc64/fpu/s_llround.S b/libc/sysdeps/powerpc/powerpc64/fpu/s_llround.S
index d023b8f2c..413484753 100644
--- a/libc/sysdeps/powerpc/powerpc64/fpu/s_llround.S
+++ b/libc/sysdeps/powerpc/powerpc64/fpu/s_llround.S
@@ -1,5 +1,5 @@
/* llround function. PowerPC64 version.
- Copyright (C) 2004, 2006 Free Software Foundation, Inc.
+ Copyright (C) 2004, 2006, 2007 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
@@ -21,13 +21,13 @@
#include <math_ldbl_opt.h>
.section ".toc","aw"
-.LC0: /* -0.0 */
- .tc FD_00000000_0[TC],0x0000000000000000
+.LC0: /* 2^52 */
+ .tc FD_43300000_0[TC],0x4330000000000000
.LC1: /* 0.5 */
.tc FD_3fe00000_0[TC],0x3fe0000000000000
.section ".text"
-/* long long [r3] llround (float x [fp1])
+/* 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
@@ -35,26 +35,45 @@
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. */
+ 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 fp12,.LC0@toc(2)
- lfd fp10,.LC1@toc(2)
- fcmpu cr6,fp1,fp12 /* if (x > 0.0) */
- ble- cr6,.L4
- fadd fp1,fp1,fp10 /* x+= 0.5; */
-.L9:
- fctidz fp2,fp1 /* Convert To Integer DW llround toward 0. */
- stfd fp2,-16(r1)
- nop /* Insure the following load is in a different dispatch group */
- nop /* to avoid pipe stall on POWER4&5. */
+ 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 cr4,fp2,fp9 /* if |x| >= 2^52 */
+ fcmpu cr3,fp1,fp12 /* x is negative? x < 0.0 */
+ blt- cr6,.Lretzero /* 0.5 > x < -0.5 so just return 0. */
+ bge- cr4,.Lnobias /* 2^52 > x < -2^52 just convert with no bias. */
+ fadd fp3,fp2,fp10 /* |x|+=0.5 bias to prepare to round. */
+ bge cr3,.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)
+ ld r3,-16(r1) /* Load return as integer. */
+.Lout:
blr
-.L4:
- fsub fp1,fp1,fp10 /* x-= 0.5; */
- b .L9
+.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)
diff --git a/libc/sysdeps/powerpc/powerpc64/fpu/s_llroundf.S b/libc/sysdeps/powerpc/powerpc64/fpu/s_llroundf.S
index bbbd05492..a21187939 100644
--- a/libc/sysdeps/powerpc/powerpc64/fpu/s_llroundf.S
+++ b/libc/sysdeps/powerpc/powerpc64/fpu/s_llroundf.S
@@ -1,5 +1,5 @@
/* llroundf function. PowerPC64 version.
- Copyright (C) 2004, 2006 Free Software Foundation, Inc.
+ Copyright (C) 2004, 2006, 2007 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
@@ -20,8 +20,8 @@
#include <sysdep.h>
.section ".toc","aw"
-.LC0: /* -0.0 */
- .tc FD_00000000_0[TC],0x0000000000000000
+.LC0: /* 2^23 */
+ .tc FD_41600000_0[TC],0x4160000000000000
.LC1: /* 0.5 */
.tc FD_3fe00000_0[TC],0x3fe0000000000000
.section ".text"
@@ -34,24 +34,45 @@
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. */
+ 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 fp12,.LC0@toc(2)
- lfd fp10,.LC1@toc(2)
- fcmpu cr6,fp1,fp12 /* if (x < 0.0) */
- fsubs fp3,fp1,fp10 /* x-= 0.5; */
- ble- cr6,.L9
- fadds fp3,fp1,fp10 /* x+= 0.5; */
-.L9:
- fctidz fp2,fp3 /* Convert To Integer DW round toward 0. */
- stfd fp2,-16(r1)
- nop /* Insure the following load is in a different dispatch group */
- nop /* to avoid pipe stall on POWER4&5. */
+ lfd fp9,.LC0@toc(2) /* Load 2^23 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 cr4,fp2,fp9 /* if |x| >= 2^23 */
+ fcmpu cr3,fp1,fp12 /* x is negative? x < 0.0 */
+ blt- cr6,.Lretzero /* 0.5 > x < -0.5 so just return 0. */
+ bge- cr4,.Lnobias /* 2^23 > x < -2^23 just convert with no bias. */
+ fadd fp3,fp2,fp10 /* |x|+=0.5 bias to prepare to round. */
+ bge cr3,.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)
+ 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)
diff --git a/libc/sysdeps/powerpc/powerpc64/fpu/s_lrint.S b/libc/sysdeps/powerpc/powerpc64/fpu/s_lrint.S
index fe774693b..d3c2fff58 100644
--- a/libc/sysdeps/powerpc/powerpc64/fpu/s_lrint.S
+++ b/libc/sysdeps/powerpc/powerpc64/fpu/s_lrint.S
@@ -1,2 +1 @@
/* __lrint is in s_llrint.c */
-/* __lrint is in s_llrint.c */
diff --git a/libc/sysdeps/powerpc/powerpc64/fpu/s_lround.S b/libc/sysdeps/powerpc/powerpc64/fpu/s_lround.S
index 883bba1c5..4306c405c 100644
--- a/libc/sysdeps/powerpc/powerpc64/fpu/s_lround.S
+++ b/libc/sysdeps/powerpc/powerpc64/fpu/s_lround.S
@@ -1,2 +1 @@
/* __lround is in s_llround.S */
-/* __lround is in s_llround.S */
diff --git a/libc/sysdeps/powerpc/powerpc64/fpu/s_lroundf.S b/libc/sysdeps/powerpc/powerpc64/fpu/s_lroundf.S
index 15506f680..6b2a4e37a 100644
--- a/libc/sysdeps/powerpc/powerpc64/fpu/s_lroundf.S
+++ b/libc/sysdeps/powerpc/powerpc64/fpu/s_lroundf.S
@@ -1,2 +1 @@
/* __lroundf is in s_llroundf.S */
-/* __lroundf is in s_llroundf.S */