diff options
Diffstat (limited to 'libc/sysdeps/powerpc/fpu')
-rw-r--r-- | libc/sysdeps/powerpc/fpu/e_sqrt.c | 2 | ||||
-rw-r--r-- | libc/sysdeps/powerpc/fpu/e_sqrtf.c | 2 | ||||
-rw-r--r-- | libc/sysdeps/powerpc/fpu/fclrexcpt.c | 4 | ||||
-rw-r--r-- | libc/sysdeps/powerpc/fpu/fedisblxcpt.c | 10 | ||||
-rw-r--r-- | libc/sysdeps/powerpc/fpu/feenablxcpt.c | 10 | ||||
-rw-r--r-- | libc/sysdeps/powerpc/fpu/fegetexcept.c | 10 | ||||
-rw-r--r-- | libc/sysdeps/powerpc/fpu/feholdexcpt.c | 5 | ||||
-rw-r--r-- | libc/sysdeps/powerpc/fpu/fenv_libc.h | 2 | ||||
-rw-r--r-- | libc/sysdeps/powerpc/fpu/fesetenv.c | 4 | ||||
-rw-r--r-- | libc/sysdeps/powerpc/fpu/feupdateenv.c | 6 | ||||
-rw-r--r-- | libc/sysdeps/powerpc/fpu/fgetexcptflg.c | 2 | ||||
-rw-r--r-- | libc/sysdeps/powerpc/fpu/fraiseexcpt.c | 12 | ||||
-rw-r--r-- | libc/sysdeps/powerpc/fpu/fsetexcptflg.c | 8 | ||||
-rw-r--r-- | libc/sysdeps/powerpc/fpu/ftestexcept.c | 2 | ||||
-rw-r--r-- | libc/sysdeps/powerpc/fpu/libm-test-ulps | 68 | ||||
-rw-r--r-- | libc/sysdeps/powerpc/fpu/s_float_bitwise.h | 54 | ||||
-rw-r--r-- | libc/sysdeps/powerpc/fpu/s_llround.c | 33 | ||||
-rw-r--r-- | libc/sysdeps/powerpc/fpu/s_llroundf.c | 33 | ||||
-rw-r--r-- | libc/sysdeps/powerpc/fpu/tst-setcontext-fpscr.c | 87 |
19 files changed, 210 insertions, 144 deletions
diff --git a/libc/sysdeps/powerpc/fpu/e_sqrt.c b/libc/sysdeps/powerpc/fpu/e_sqrt.c index 3efe277f3..2d50fb525 100644 --- a/libc/sysdeps/powerpc/fpu/e_sqrt.c +++ b/libc/sysdeps/powerpc/fpu/e_sqrt.c @@ -145,7 +145,7 @@ __slow_ieee754_sqrt (double x) feraiseexcept (FE_INVALID_SQRT); fenv_union_t u = { .fenv = fegetenv_register () }; - if ((u.l[1] & FE_INVALID) == 0) + if ((u.l & FE_INVALID) == 0) #endif feraiseexcept (FE_INVALID); x = a_nan.value; diff --git a/libc/sysdeps/powerpc/fpu/e_sqrtf.c b/libc/sysdeps/powerpc/fpu/e_sqrtf.c index 6e50a3cd7..91d2d37d7 100644 --- a/libc/sysdeps/powerpc/fpu/e_sqrtf.c +++ b/libc/sysdeps/powerpc/fpu/e_sqrtf.c @@ -121,7 +121,7 @@ __slow_ieee754_sqrtf (float x) feraiseexcept (FE_INVALID_SQRT); fenv_union_t u = { .fenv = fegetenv_register () }; - if ((u.l[1] & FE_INVALID) == 0) + if ((u.l & FE_INVALID) == 0) #endif feraiseexcept (FE_INVALID); x = a_nan.value; diff --git a/libc/sysdeps/powerpc/fpu/fclrexcpt.c b/libc/sysdeps/powerpc/fpu/fclrexcpt.c index 86575dba6..7f66e21ce 100644 --- a/libc/sysdeps/powerpc/fpu/fclrexcpt.c +++ b/libc/sysdeps/powerpc/fpu/fclrexcpt.c @@ -28,8 +28,8 @@ __feclearexcept (int excepts) u.fenv = fegetenv_register (); /* Clear the relevant bits. */ - u.l[1] = u.l[1] & ~((-(excepts >> (31 - FPSCR_VX) & 1) & FE_ALL_INVALID) - | (excepts & FPSCR_STICKY_BITS)); + u.l = u.l & ~((-(excepts >> (31 - FPSCR_VX) & 1) & FE_ALL_INVALID) + | (excepts & FPSCR_STICKY_BITS)); /* Put the new state in effect. */ fesetenv_register (u.fenv); diff --git a/libc/sysdeps/powerpc/fpu/fedisblxcpt.c b/libc/sysdeps/powerpc/fpu/fedisblxcpt.c index 659566b67..f2c45a60c 100644 --- a/libc/sysdeps/powerpc/fpu/fedisblxcpt.c +++ b/libc/sysdeps/powerpc/fpu/fedisblxcpt.c @@ -32,15 +32,15 @@ fedisableexcept (int excepts) fe.fenv = fegetenv_register (); if (excepts & FE_INEXACT) - fe.l[1] &= ~(1 << (31 - FPSCR_XE)); + fe.l &= ~(1 << (31 - FPSCR_XE)); if (excepts & FE_DIVBYZERO) - fe.l[1] &= ~(1 << (31 - FPSCR_ZE)); + fe.l &= ~(1 << (31 - FPSCR_ZE)); if (excepts & FE_UNDERFLOW) - fe.l[1] &= ~(1 << (31 - FPSCR_UE)); + fe.l &= ~(1 << (31 - FPSCR_UE)); if (excepts & FE_OVERFLOW) - fe.l[1] &= ~(1 << (31 - FPSCR_OE)); + fe.l &= ~(1 << (31 - FPSCR_OE)); if (excepts & FE_INVALID) - fe.l[1] &= ~(1 << (31 - FPSCR_VE)); + fe.l &= ~(1 << (31 - FPSCR_VE)); fesetenv_register (fe.fenv); new = __fegetexcept (); diff --git a/libc/sysdeps/powerpc/fpu/feenablxcpt.c b/libc/sysdeps/powerpc/fpu/feenablxcpt.c index fc4bfffad..472796d15 100644 --- a/libc/sysdeps/powerpc/fpu/feenablxcpt.c +++ b/libc/sysdeps/powerpc/fpu/feenablxcpt.c @@ -32,15 +32,15 @@ feenableexcept (int excepts) fe.fenv = fegetenv_register (); if (excepts & FE_INEXACT) - fe.l[1] |= (1 << (31 - FPSCR_XE)); + fe.l |= (1 << (31 - FPSCR_XE)); if (excepts & FE_DIVBYZERO) - fe.l[1] |= (1 << (31 - FPSCR_ZE)); + fe.l |= (1 << (31 - FPSCR_ZE)); if (excepts & FE_UNDERFLOW) - fe.l[1] |= (1 << (31 - FPSCR_UE)); + fe.l |= (1 << (31 - FPSCR_UE)); if (excepts & FE_OVERFLOW) - fe.l[1] |= (1 << (31 - FPSCR_OE)); + fe.l |= (1 << (31 - FPSCR_OE)); if (excepts & FE_INVALID) - fe.l[1] |= (1 << (31 - FPSCR_VE)); + fe.l |= (1 << (31 - FPSCR_VE)); fesetenv_register (fe.fenv); new = __fegetexcept (); diff --git a/libc/sysdeps/powerpc/fpu/fegetexcept.c b/libc/sysdeps/powerpc/fpu/fegetexcept.c index f3d5724e9..23d47a27e 100644 --- a/libc/sysdeps/powerpc/fpu/fegetexcept.c +++ b/libc/sysdeps/powerpc/fpu/fegetexcept.c @@ -27,15 +27,15 @@ __fegetexcept (void) fe.fenv = fegetenv_register (); - if (fe.l[1] & (1 << (31 - FPSCR_XE))) + if (fe.l & (1 << (31 - FPSCR_XE))) result |= FE_INEXACT; - if (fe.l[1] & (1 << (31 - FPSCR_ZE))) + if (fe.l & (1 << (31 - FPSCR_ZE))) result |= FE_DIVBYZERO; - if (fe.l[1] & (1 << (31 - FPSCR_UE))) + if (fe.l & (1 << (31 - FPSCR_UE))) result |= FE_UNDERFLOW; - if (fe.l[1] & (1 << (31 - FPSCR_OE))) + if (fe.l & (1 << (31 - FPSCR_OE))) result |= FE_OVERFLOW; - if (fe.l[1] & (1 << (31 - FPSCR_VE))) + if (fe.l & (1 << (31 - FPSCR_VE))) result |= FE_INVALID; return result; diff --git a/libc/sysdeps/powerpc/fpu/feholdexcpt.c b/libc/sysdeps/powerpc/fpu/feholdexcpt.c index 013d2bfbb..0ecf0f7bc 100644 --- a/libc/sysdeps/powerpc/fpu/feholdexcpt.c +++ b/libc/sysdeps/powerpc/fpu/feholdexcpt.c @@ -30,13 +30,12 @@ feholdexcept (fenv_t *envp) /* Clear everything except for the rounding modes and non-IEEE arithmetic flag. */ - new.l[1] = old.l[1] & 7; - new.l[0] = old.l[0]; + new.l = old.l & 0xffffffff00000007LL; /* If the old env had any enabled exceptions, then mask SIGFPE in the MSR FE0/FE1 bits. This may allow the FPU to run faster because it always takes the default action and can not generate SIGFPE. */ - if ((old.l[1] & _FPU_MASK_ALL) != 0) + if ((old.l & _FPU_MASK_ALL) != 0) (void)__fe_mask_env (); /* Put the new state in effect. */ diff --git a/libc/sysdeps/powerpc/fpu/fenv_libc.h b/libc/sysdeps/powerpc/fpu/fenv_libc.h index 191095156..baa2a7d39 100644 --- a/libc/sysdeps/powerpc/fpu/fenv_libc.h +++ b/libc/sysdeps/powerpc/fpu/fenv_libc.h @@ -69,7 +69,7 @@ libm_hidden_proto (__fe_nomask_env) typedef union { fenv_t fenv; - unsigned int l[2]; + unsigned long long l; } fenv_union_t; diff --git a/libc/sysdeps/powerpc/fpu/fesetenv.c b/libc/sysdeps/powerpc/fpu/fesetenv.c index e92adb4c5..6c00b267a 100644 --- a/libc/sysdeps/powerpc/fpu/fesetenv.c +++ b/libc/sysdeps/powerpc/fpu/fesetenv.c @@ -34,14 +34,14 @@ __fesetenv (const fenv_t *envp) exceptions, then unmask SIGFPE in the MSR FE0/FE1 bits. This will put the hardware into "precise mode" and may cause the FPU to run slower on some hardware. */ - if ((old.l[1] & _FPU_MASK_ALL) == 0 && (new.l[1] & _FPU_MASK_ALL) != 0) + if ((old.l & _FPU_MASK_ALL) == 0 && (new.l & _FPU_MASK_ALL) != 0) (void)__fe_nomask_env (); /* If the old env had any enabled exceptions and the new env has no enabled exceptions, then mask SIGFPE in the MSR FE0/FE1 bits. This may allow the FPU to run faster because it always takes the default action and can not generate SIGFPE. */ - if ((old.l[1] & _FPU_MASK_ALL) != 0 && (new.l[1] & _FPU_MASK_ALL) == 0) + if ((old.l & _FPU_MASK_ALL) != 0 && (new.l & _FPU_MASK_ALL) == 0) (void)__fe_mask_env (); fesetenv_register (*envp); diff --git a/libc/sysdeps/powerpc/fpu/feupdateenv.c b/libc/sysdeps/powerpc/fpu/feupdateenv.c index 6500ea173..677504416 100644 --- a/libc/sysdeps/powerpc/fpu/feupdateenv.c +++ b/libc/sysdeps/powerpc/fpu/feupdateenv.c @@ -34,20 +34,20 @@ __feupdateenv (const fenv_t *envp) /* Restore rounding mode and exception enable from *envp and merge exceptions. Leave fraction rounded/inexact and FP result/CC bits unchanged. */ - new.l[1] = (old.l[1] & 0x1FFFFF00) | (new.l[1] & 0x1FF80FFF); + new.l = (old.l & 0xffffffff1fffff00LL) | (new.l & 0x1ff80fff); /* If the old env has no enabled exceptions and the new env has any enabled exceptions, then unmask SIGFPE in the MSR FE0/FE1 bits. This will put the hardware into "precise mode" and may cause the FPU to run slower on some hardware. */ - if ((old.l[1] & _FPU_MASK_ALL) == 0 && (new.l[1] & _FPU_MASK_ALL) != 0) + if ((old.l & _FPU_MASK_ALL) == 0 && (new.l & _FPU_MASK_ALL) != 0) (void)__fe_nomask_env (); /* If the old env had any enabled exceptions and the new env has no enabled exceptions, then mask SIGFPE in the MSR FE0/FE1 bits. This may allow the FPU to run faster because it always takes the default action and can not generate SIGFPE. */ - if ((old.l[1] & _FPU_MASK_ALL) != 0 && (new.l[1] & _FPU_MASK_ALL) == 0) + if ((old.l & _FPU_MASK_ALL) != 0 && (new.l & _FPU_MASK_ALL) == 0) (void)__fe_mask_env (); /* Atomically enable and raise (if appropriate) exceptions set in `new'. */ diff --git a/libc/sysdeps/powerpc/fpu/fgetexcptflg.c b/libc/sysdeps/powerpc/fpu/fgetexcptflg.c index f6327ce17..1395bede0 100644 --- a/libc/sysdeps/powerpc/fpu/fgetexcptflg.c +++ b/libc/sysdeps/powerpc/fpu/fgetexcptflg.c @@ -27,7 +27,7 @@ __fegetexceptflag (fexcept_t *flagp, int excepts) u.fenv = fegetenv_register (); /* Return (all of) it. */ - *flagp = u.l[1] & excepts & FE_ALL_EXCEPT; + *flagp = u.l & excepts & FE_ALL_EXCEPT; /* Success. */ return 0; diff --git a/libc/sysdeps/powerpc/fpu/fraiseexcpt.c b/libc/sysdeps/powerpc/fpu/fraiseexcpt.c index 9118c1954..6193071bd 100644 --- a/libc/sysdeps/powerpc/fpu/fraiseexcpt.c +++ b/libc/sysdeps/powerpc/fpu/fraiseexcpt.c @@ -33,11 +33,11 @@ __feraiseexcept (int excepts) u.fenv = fegetenv_register (); /* Add the exceptions */ - u.l[1] = (u.l[1] - | (excepts & FPSCR_STICKY_BITS) - /* Turn FE_INVALID into FE_INVALID_SOFTWARE. */ - | (excepts >> ((31 - FPSCR_VX) - (31 - FPSCR_VXSOFT)) - & FE_INVALID_SOFTWARE)); + u.l = (u.l + | (excepts & FPSCR_STICKY_BITS) + /* Turn FE_INVALID into FE_INVALID_SOFTWARE. */ + | (excepts >> ((31 - FPSCR_VX) - (31 - FPSCR_VXSOFT)) + & FE_INVALID_SOFTWARE)); /* Store the new status word (along with the rest of the environment), triggering any appropriate exceptions. */ @@ -49,7 +49,7 @@ __feraiseexcept (int excepts) don't have FE_INVALID_SOFTWARE implemented. Detect this case and raise FE_INVALID_SNAN instead. */ u.fenv = fegetenv_register (); - if ((u.l[1] & FE_INVALID) == 0) + if ((u.l & FE_INVALID) == 0) set_fpscr_bit (FPSCR_VXSNAN); } diff --git a/libc/sysdeps/powerpc/fpu/fsetexcptflg.c b/libc/sysdeps/powerpc/fpu/fsetexcptflg.c index c050d4022..0d309c8d5 100644 --- a/libc/sysdeps/powerpc/fpu/fsetexcptflg.c +++ b/libc/sysdeps/powerpc/fpu/fsetexcptflg.c @@ -31,10 +31,10 @@ __fesetexceptflag (const fexcept_t *flagp, int excepts) flag = *flagp & excepts; /* Replace the exception status */ - u.l[1] = ((u.l[1] & ~(FPSCR_STICKY_BITS & excepts)) - | (flag & FPSCR_STICKY_BITS) - | (flag >> ((31 - FPSCR_VX) - (31 - FPSCR_VXSOFT)) - & FE_INVALID_SOFTWARE)); + u.l = ((u.l & ~(FPSCR_STICKY_BITS & excepts)) + | (flag & FPSCR_STICKY_BITS) + | (flag >> ((31 - FPSCR_VX) - (31 - FPSCR_VXSOFT)) + & FE_INVALID_SOFTWARE)); /* Store the new status word (along with the rest of the environment). This may cause floating-point exceptions if the restored state diff --git a/libc/sysdeps/powerpc/fpu/ftestexcept.c b/libc/sysdeps/powerpc/fpu/ftestexcept.c index 0dbc3befb..86eea0fb0 100644 --- a/libc/sysdeps/powerpc/fpu/ftestexcept.c +++ b/libc/sysdeps/powerpc/fpu/ftestexcept.c @@ -28,6 +28,6 @@ fetestexcept (int excepts) /* The FE_INVALID bit is dealt with correctly by the hardware, so we can just: */ - return u.l[1] & excepts; + return u.l & excepts; } libm_hidden_def (fetestexcept) diff --git a/libc/sysdeps/powerpc/fpu/libm-test-ulps b/libc/sysdeps/powerpc/fpu/libm-test-ulps index 6fdace9ee..37b2ca192 100644 --- a/libc/sysdeps/powerpc/fpu/libm-test-ulps +++ b/libc/sysdeps/powerpc/fpu/libm-test-ulps @@ -5927,11 +5927,31 @@ double: 1 idouble: 1 # gamma +Test "gamma (-0x1p-10)": +double: 1 +idouble: 1 +Test "gamma (-0x1p-15)": +double: 1 +float: 1 +idouble: 1 +ifloat: 1 +Test "gamma (-0x1p-20)": +double: 1 +idouble: 1 +Test "gamma (-0x1p-5)": +double: 1 +idouble: 1 Test "gamma (0.7)": double: 1 float: 1 idouble: 1 ifloat: 1 +Test "gamma (0x1p-10)": +float: 1 +ifloat: 1 +Test "gamma (0x1p-30)": +double: 1 +idouble: 1 Test "gamma (1.2)": double: 1 float: 2 @@ -6131,9 +6151,9 @@ ildouble: 1 ldouble: 1 Test "jn (10, 10.0)": double: 2 -float: 1 +float: 2 idouble: 2 -ifloat: 1 +ifloat: 2 ildouble: 4 ldouble: 4 Test "jn (10, 2.0)": @@ -6146,6 +6166,14 @@ double: 2 float: 2 idouble: 2 ifloat: 2 +Test "jn (2, 0x1p1023)": +ildouble: 1 +ldouble: 1 +Test "jn (2, 0x1p127)": +double: 1 +idouble: 1 +ildouble: 1 +ldouble: 1 Test "jn (2, 2.4048255576957729)": double: 2 float: 1 @@ -6226,11 +6254,31 @@ ildouble: 7 ldouble: 7 # lgamma +Test "lgamma (-0x1p-10)": +double: 1 +idouble: 1 +Test "lgamma (-0x1p-15)": +double: 1 +float: 1 +idouble: 1 +ifloat: 1 +Test "lgamma (-0x1p-20)": +double: 1 +idouble: 1 +Test "lgamma (-0x1p-5)": +double: 1 +idouble: 1 Test "lgamma (0.7)": double: 1 float: 1 idouble: 1 ifloat: 1 +Test "lgamma (0x1p-10)": +float: 1 +ifloat: 1 +Test "lgamma (0x1p-30)": +double: 1 +idouble: 1 Test "lgamma (1.2)": double: 1 float: 2 @@ -6592,6 +6640,9 @@ float: 1 ifloat: 1 ildouble: 2 ldouble: 2 +Test "tan_towardzero (2)": +ildouble: 1 +ldouble: 1 Test "tan_towardzero (3)": float: 1 ifloat: 1 @@ -7334,6 +7385,19 @@ idouble: 3 ifloat: 1 ildouble: 1 ldouble: 1 +Test "yn (2, 0x1.ffff62p+99)": +double: 1 +idouble: 1 +Test "yn (2, 0x1p1023)": +ildouble: 1 +ldouble: 1 +Test "yn (2, 0x1p127)": +double: 1 +float: 1 +idouble: 1 +ifloat: 1 +ildouble: 1 +ldouble: 1 Test "yn (3, 0.125)": double: 1 idouble: 1 diff --git a/libc/sysdeps/powerpc/fpu/s_float_bitwise.h b/libc/sysdeps/powerpc/fpu/s_float_bitwise.h index 8e4adca86..c0a4e56be 100644 --- a/libc/sysdeps/powerpc/fpu/s_float_bitwise.h +++ b/libc/sysdeps/powerpc/fpu/s_float_bitwise.h @@ -23,18 +23,19 @@ #include <math_private.h> /* Returns (int)(num & 0x7FFFFFF0 == value) */ -static inline -int __float_and_test28 (float num, float value) +static inline int +__float_and_test28 (float num, float value) { float ret; #ifdef _ARCH_PWR7 - vector int mask = (vector int) { - 0x7ffffffe, 0x00000000, 0x00000000, 0x0000000 - }; + union { + int i; + float f; + } mask = { .i = 0x7ffffff0 }; __asm__ ( - /* the 'f' constrain is use on mask because we just need + /* the 'f' constraint is used on mask because we just need * to compare floats, not full vector */ - "xxland %x0,%x1,%x2" : "=f" (ret) : "f" (num), "f" (mask) + "xxland %x0,%x1,%x2" : "=f" (ret) : "f" (num), "f" (mask.f) ); #else int32_t inum; @@ -46,16 +47,17 @@ int __float_and_test28 (float num, float value) } /* Returns (int)(num & 0x7FFFFF00 == value) */ -static inline -int __float_and_test24 (float num, float value) +static inline int +__float_and_test24 (float num, float value) { float ret; #ifdef _ARCH_PWR7 - vector int mask = (vector int) { - 0x7fffffe0, 0x00000000, 0x00000000, 0x0000000 - }; + union { + int i; + float f; + } mask = { .i = 0x7fffff00 }; __asm__ ( - "xxland %x0,%x1,%x2" : "=f" (ret) : "f" (num), "f" (mask) + "xxland %x0,%x1,%x2" : "=f" (ret) : "f" (num), "f" (mask.f) ); #else int32_t inum; @@ -67,16 +69,17 @@ int __float_and_test24 (float num, float value) } /* Returns (float)(num & 0x7F800000) */ -static inline -float __float_and8 (float num) +static inline float +__float_and8 (float num) { float ret; #ifdef _ARCH_PWR7 - vector int mask = (vector int) { - 0x7ff00000, 0x00000000, 0x00000000, 0x00000000 - }; + union { + int i; + float f; + } mask = { .i = 0x7f800000 }; __asm__ ( - "xxland %x0,%x1,%x2" : "=f" (ret) : "f" (num), "f" (mask) + "xxland %x0,%x1,%x2" : "=f" (ret) : "f" (num), "f" (mask.f) ); #else int32_t inum; @@ -88,17 +91,18 @@ float __float_and8 (float num) } /* Returns ((int32_t)(num & 0x7F800000) >> 23) */ -static inline -int32_t __float_get_exp (float num) +static inline int32_t +__float_get_exp (float num) { int32_t inum; #ifdef _ARCH_PWR7 float ret; - vector int mask = (vector int) { - 0x7ff00000, 0x00000000, 0x00000000, 0x00000000 - }; + union { + int i; + float f; + } mask = { .i = 0x7f800000 }; __asm__ ( - "xxland %x0,%x1,%x2" : "=f" (ret) : "f" (num), "f" (mask) + "xxland %x0,%x1,%x2" : "=f" (ret) : "f" (num), "f" (mask.f) ); GET_FLOAT_WORD(inum, ret); #else diff --git a/libc/sysdeps/powerpc/fpu/s_llround.c b/libc/sysdeps/powerpc/fpu/s_llround.c index 9a0182653..995d0a724 100644 --- a/libc/sysdeps/powerpc/fpu/s_llround.c +++ b/libc/sysdeps/powerpc/fpu/s_llround.c @@ -19,29 +19,28 @@ #include <math.h> #include <math_ldbl_opt.h> -/* I think that what this routine is supposed to do is round a value - to the nearest integer, with values exactly on the boundary rounded - away from zero. */ -/* This routine relies on (long long)x, when x is out of range of a long long, - clipping to MAX_LLONG or MIN_LLONG. */ +/* Round to the nearest integer, with values exactly on a 0.5 boundary + rounded away from zero, regardless of the current rounding mode. + If (long long)x, when x is out of range of a long long, clips at + LLONG_MAX or LLONG_MIN, then this implementation also clips. */ long long int __llround (double x) { - double xrf; - long long int xr; - xr = (long long int) x; - xrf = (double) xr; + long long xr = (long long) x; + double xrf = (double) xr; + if (x >= 0.0) - if (x - xrf >= 0.5 && x - xrf < 1.0 && x+1 > 0) - return x+1; - else - return x; + { + if (x - xrf >= 0.5) + xr += (long long) ((unsigned long long) xr + 1) > 0; + } else - if (xrf - x >= 0.5 && xrf - x < 1.0 && x-1 < 0) - return x-1; - else - return x; + { + if (xrf - x >= 0.5) + xr -= (long long) ((unsigned long long) xr - 1) < 0; + } + return xr; } weak_alias (__llround, llround) #ifdef NO_LONG_DOUBLE diff --git a/libc/sysdeps/powerpc/fpu/s_llroundf.c b/libc/sysdeps/powerpc/fpu/s_llroundf.c index 07d12adbf..0935de662 100644 --- a/libc/sysdeps/powerpc/fpu/s_llroundf.c +++ b/libc/sysdeps/powerpc/fpu/s_llroundf.c @@ -18,28 +18,27 @@ #include <math.h> -/* I think that what this routine is supposed to do is round a value - to the nearest integer, with values exactly on the boundary rounded - away from zero. */ -/* This routine relies on (long long)x, when x is out of range of a long long, - clipping to MAX_LLONG or MIN_LLONG. */ +/* Round to the nearest integer, with values exactly on a 0.5 boundary + rounded away from zero, regardless of the current rounding mode. + If (long long)x, when x is out of range of a long long, clips at + LLONG_MAX or LLONG_MIN, then this implementation also clips. */ long long int __llroundf (float x) { - float xrf; - long long int xr; - xr = (long long int) x; - xrf = (float) xr; + long long xr = (long long) x; + float xrf = (float) xr; + if (x >= 0.0) - if (x - xrf >= 0.5 && x - xrf < 1.0 && x+1 > 0) - return x+1; - else - return x; + { + if (x - xrf >= 0.5) + xr += (long long) ((unsigned long long) xr + 1) > 0; + } else - if (xrf - x >= 0.5 && xrf - x < 1.0 && x-1 < 0) - return x-1; - else - return x; + { + if (xrf - x >= 0.5) + xr -= (long long) ((unsigned long long) xr - 1) < 0; + } + return xr; } weak_alias (__llroundf, llroundf) diff --git a/libc/sysdeps/powerpc/fpu/tst-setcontext-fpscr.c b/libc/sysdeps/powerpc/fpu/tst-setcontext-fpscr.c index feffa6b4f..cc9b320bf 100644 --- a/libc/sysdeps/powerpc/fpu/tst-setcontext-fpscr.c +++ b/libc/sysdeps/powerpc/fpu/tst-setcontext-fpscr.c @@ -83,7 +83,7 @@ ElfW(Addr) query_auxv(int type) return 0; } -typedef unsigned long long di_fpscr_t __attribute__ ((__mode__ (__DI__))); +typedef unsigned int di_fpscr_t __attribute__ ((__mode__ (__DI__))); typedef unsigned int si_fpscr_t __attribute__ ((__mode__ (__SI__))); #define _FPSCR_RESERVED 0xfffffff8ffffff04ULL @@ -95,50 +95,51 @@ typedef unsigned int si_fpscr_t __attribute__ ((__mode__ (__SI__))); #define _FPSCR_TEST1_RN 0x0000000000000002ULL /* Macros for accessing the hardware control word on Power6[x]. */ -# define _GET_DI_FPSCR(__fpscr) ({ \ - union { double d; \ - di_fpscr_t fpscr; } \ - tmp __attribute__ ((__aligned__(8))); \ - __asm__ ("mffs 0; stfd%U0 0,%0" : "=m" (tmp.d) : : "fr0"); \ - (__fpscr)=tmp.fpscr; \ - tmp.fpscr; }) - -/* We make sure to zero fp0 after we use it in order to prevent stale data +#define _GET_DI_FPSCR(__fpscr) \ + ({union { double d; di_fpscr_t fpscr; } u; \ + register double fr; \ + __asm__ ("mffs %0" : "=f" (fr)); \ + u.d = fr; \ + (__fpscr) = u.fpscr; \ + u.fpscr; \ + }) + +/* We make sure to zero fp after we use it in order to prevent stale data in an fp register from making a test-case pass erroneously. */ -# define _SET_DI_FPSCR(__fpscr) { \ - union { double d; di_fpscr_t fpscr; } \ - tmp __attribute__ ((__aligned__(8))); \ - tmp.fpscr = __fpscr; \ - /* Set the entire 64-bit FPSCR. */ \ - __asm__ ("lfd%U0 0,%0; " \ - ".machine push; " \ - ".machine \"power6\"; " \ - "mtfsf 255,0,1,0; " \ - ".machine pop" : : "m" (tmp.d) : "fr0"); \ - tmp.d = 0; \ - __asm__("lfd%U0 0,%0" : : "m" (tmp.d) : "fr0"); \ -} - -# define _GET_SI_FPSCR(__fpscr) ({ \ - union { double d; \ - si_fpscr_t cw[2]; } \ - tmp __attribute__ ((__aligned__(8))); \ - __asm__ ("mffs 0; stfd%U0 0,%0" : "=m" (tmp.d) : : "fr0"); \ - (__fpscr)=tmp.cw[1]; \ - tmp.cw[0]; }) - -/* We make sure to zero fp0 after we use it in order to prevent stale data +# define _SET_DI_FPSCR(__fpscr) \ + { union { double d; di_fpscr_t fpscr; } u; \ + register double fr; \ + u.fpscr = __fpscr; \ + fr = u.d; \ + /* Set the entire 64-bit FPSCR. */ \ + __asm__ (".machine push; " \ + ".machine \"power6\"; " \ + "mtfsf 255,%0,1,0; " \ + ".machine pop" : : "f" (fr)); \ + fr = 0.0; \ + } + +# define _GET_SI_FPSCR(__fpscr) \ + ({union { double d; di_fpscr_t fpscr; } u; \ + register double fr; \ + __asm__ ("mffs %0" : "=f" (fr)); \ + u.d = fr; \ + (__fpscr) = (si_fpscr_t) u.fpscr; \ + (si_fpscr_t) u.fpscr; \ + }) + +/* We make sure to zero fp after we use it in order to prevent stale data in an fp register from making a test-case pass erroneously. */ -# define _SET_SI_FPSCR(__fpscr) { \ - union { double d; si_fpscr_t fpscr[2]; } \ - tmp __attribute__ ((__aligned__(8))); \ - /* More-or-less arbitrary; this is a QNaN. */ \ - tmp.fpscr[0] = 0xFFF80000; \ - tmp.fpscr[1] = __fpscr; \ - __asm__ ("lfd%U0 0,%0; mtfsf 255,0" : : "m" (tmp.d) : "fr0"); \ - tmp.d = 0; \ - __asm__("lfd%U0 0,%0" : : "m" (tmp.d) : "fr0"); \ -} +# define _SET_SI_FPSCR(__fpscr) \ + { union { double d; di_fpscr_t fpscr; } u; \ + register double fr; \ + /* More-or-less arbitrary; this is a QNaN. */ \ + u.fpscr = 0xfff80000ULL << 32; \ + u.fpscr |= __fpscr & 0xffffffffULL; \ + fr = u.d; \ + __asm__ ("mtfsf 255,%0" : : "f" (fr)); \ + fr = 0.0; \ + } void prime_special_regs(int which) { |