5de29b
# commit 4a28b3ca4bc52d9a3ac0d9edb53d3de510e1b77c
5de29b
# Author: Anton Blanchard <anton@au1.ibm.com>
5de29b
# Date:   Sat Aug 17 18:28:55 2013 +0930
5de29b
# 
5de29b
#     PowerPC floating point little-endian [8 of 15]
5de29b
#     http://sourceware.org/ml/libc-alpha/2013-07/msg00199.html
5de29b
#     
5de29b
#     Corrects floating-point environment code for little-endian.
5de29b
#     
5de29b
#         * sysdeps/powerpc/fpu/fenv_libc.h (fenv_union_t): Replace int
5de29b
#         array with long long.
5de29b
#         * sysdeps/powerpc/fpu/e_sqrt.c (__slow_ieee754_sqrt): Adjust.
5de29b
#         * sysdeps/powerpc/fpu/e_sqrtf.c (__slow_ieee754_sqrtf): Adjust.
5de29b
#         * sysdeps/powerpc/fpu/fclrexcpt.c (__feclearexcept): Adjust.
5de29b
#         * sysdeps/powerpc/fpu/fedisblxcpt.c (fedisableexcept): Adjust.
5de29b
#         * sysdeps/powerpc/fpu/feenablxcpt.c (feenableexcept): Adjust.
5de29b
#         * sysdeps/powerpc/fpu/fegetexcept.c (__fegetexcept): Adjust.
5de29b
#         * sysdeps/powerpc/fpu/feholdexcpt.c (feholdexcept): Adjust.
5de29b
#         * sysdeps/powerpc/fpu/fesetenv.c (__fesetenv): Adjust.
5de29b
#         * sysdeps/powerpc/fpu/feupdateenv.c (__feupdateenv): Adjust.
5de29b
#         * sysdeps/powerpc/fpu/fgetexcptflg.c (__fegetexceptflag): Adjust.
5de29b
#         * sysdeps/powerpc/fpu/fraiseexcpt.c (__feraiseexcept): Adjust.
5de29b
#         * sysdeps/powerpc/fpu/fsetexcptflg.c (__fesetexceptflag): Adjust.
5de29b
#         * sysdeps/powerpc/fpu/ftestexcept.c (fetestexcept): Adjust.
5de29b
# 
12745e
diff -urN glibc-2.17-c758a686/sysdeps/powerpc/fpu/e_sqrt.c glibc-2.17-c758a686/sysdeps/powerpc/fpu/e_sqrt.c
12745e
--- glibc-2.17-c758a686/sysdeps/powerpc/fpu/e_sqrt.c	2014-05-27 22:31:42.000000000 -0500
12745e
+++ glibc-2.17-c758a686/sysdeps/powerpc/fpu/e_sqrt.c	2014-05-27 22:31:43.000000000 -0500
5de29b
@@ -145,7 +145,7 @@
5de29b
       feraiseexcept (FE_INVALID_SQRT);
5de29b
 
5de29b
       fenv_union_t u = { .fenv = fegetenv_register () };
5de29b
-      if ((u.l[1] & FE_INVALID) == 0)
5de29b
+      if ((u.l & FE_INVALID) == 0)
5de29b
 #endif
5de29b
 	feraiseexcept (FE_INVALID);
5de29b
       x = a_nan.value;
12745e
diff -urN glibc-2.17-c758a686/sysdeps/powerpc/fpu/e_sqrtf.c glibc-2.17-c758a686/sysdeps/powerpc/fpu/e_sqrtf.c
12745e
--- glibc-2.17-c758a686/sysdeps/powerpc/fpu/e_sqrtf.c	2014-05-27 22:31:42.000000000 -0500
12745e
+++ glibc-2.17-c758a686/sysdeps/powerpc/fpu/e_sqrtf.c	2014-05-27 22:31:43.000000000 -0500
5de29b
@@ -121,7 +121,7 @@
5de29b
       feraiseexcept (FE_INVALID_SQRT);
5de29b
 
5de29b
       fenv_union_t u = { .fenv = fegetenv_register () };
5de29b
-      if ((u.l[1] & FE_INVALID) == 0)
5de29b
+      if ((u.l & FE_INVALID) == 0)
5de29b
 #endif
5de29b
 	feraiseexcept (FE_INVALID);
5de29b
       x = a_nan.value;
12745e
diff -urN glibc-2.17-c758a686/sysdeps/powerpc/fpu/fclrexcpt.c glibc-2.17-c758a686/sysdeps/powerpc/fpu/fclrexcpt.c
12745e
--- glibc-2.17-c758a686/sysdeps/powerpc/fpu/fclrexcpt.c	2014-05-27 22:31:42.000000000 -0500
12745e
+++ glibc-2.17-c758a686/sysdeps/powerpc/fpu/fclrexcpt.c	2014-05-27 22:31:43.000000000 -0500
5de29b
@@ -28,8 +28,8 @@
5de29b
   u.fenv = fegetenv_register ();
5de29b
 
5de29b
   /* Clear the relevant bits.  */
5de29b
-  u.l[1] = u.l[1] & ~((-(excepts >> (31 - FPSCR_VX) & 1) & FE_ALL_INVALID)
5de29b
-		      | (excepts & FPSCR_STICKY_BITS));
5de29b
+  u.l = u.l & ~((-(excepts >> (31 - FPSCR_VX) & 1) & FE_ALL_INVALID)
5de29b
+		| (excepts & FPSCR_STICKY_BITS));
5de29b
 
5de29b
   /* Put the new state in effect.  */
5de29b
   fesetenv_register (u.fenv);
12745e
diff -urN glibc-2.17-c758a686/sysdeps/powerpc/fpu/fedisblxcpt.c glibc-2.17-c758a686/sysdeps/powerpc/fpu/fedisblxcpt.c
12745e
--- glibc-2.17-c758a686/sysdeps/powerpc/fpu/fedisblxcpt.c	2014-05-27 22:31:42.000000000 -0500
12745e
+++ glibc-2.17-c758a686/sysdeps/powerpc/fpu/fedisblxcpt.c	2014-05-27 22:31:43.000000000 -0500
5de29b
@@ -32,15 +32,15 @@
5de29b
 
5de29b
   fe.fenv = fegetenv_register ();
5de29b
   if (excepts & FE_INEXACT)
5de29b
-    fe.l[1] &= ~(1 << (31 - FPSCR_XE));
5de29b
+    fe.l &= ~(1 << (31 - FPSCR_XE));
5de29b
   if (excepts & FE_DIVBYZERO)
5de29b
-    fe.l[1] &= ~(1 << (31 - FPSCR_ZE));
5de29b
+    fe.l &= ~(1 << (31 - FPSCR_ZE));
5de29b
   if (excepts & FE_UNDERFLOW)
5de29b
-    fe.l[1] &= ~(1 << (31 - FPSCR_UE));
5de29b
+    fe.l &= ~(1 << (31 - FPSCR_UE));
5de29b
   if (excepts & FE_OVERFLOW)
5de29b
-    fe.l[1] &= ~(1 << (31 - FPSCR_OE));
5de29b
+    fe.l &= ~(1 << (31 - FPSCR_OE));
5de29b
   if (excepts & FE_INVALID)
5de29b
-    fe.l[1] &= ~(1 << (31 - FPSCR_VE));
5de29b
+    fe.l &= ~(1 << (31 - FPSCR_VE));
5de29b
   fesetenv_register (fe.fenv);
5de29b
 
5de29b
   new = __fegetexcept ();
12745e
diff -urN glibc-2.17-c758a686/sysdeps/powerpc/fpu/feenablxcpt.c glibc-2.17-c758a686/sysdeps/powerpc/fpu/feenablxcpt.c
12745e
--- glibc-2.17-c758a686/sysdeps/powerpc/fpu/feenablxcpt.c	2014-05-27 22:31:42.000000000 -0500
12745e
+++ glibc-2.17-c758a686/sysdeps/powerpc/fpu/feenablxcpt.c	2014-05-27 22:31:43.000000000 -0500
5de29b
@@ -32,15 +32,15 @@
5de29b
 
5de29b
   fe.fenv = fegetenv_register ();
5de29b
   if (excepts & FE_INEXACT)
5de29b
-    fe.l[1] |= (1 << (31 - FPSCR_XE));
5de29b
+    fe.l |= (1 << (31 - FPSCR_XE));
5de29b
   if (excepts & FE_DIVBYZERO)
5de29b
-    fe.l[1] |= (1 << (31 - FPSCR_ZE));
5de29b
+    fe.l |= (1 << (31 - FPSCR_ZE));
5de29b
   if (excepts & FE_UNDERFLOW)
5de29b
-    fe.l[1] |= (1 << (31 - FPSCR_UE));
5de29b
+    fe.l |= (1 << (31 - FPSCR_UE));
5de29b
   if (excepts & FE_OVERFLOW)
5de29b
-    fe.l[1] |= (1 << (31 - FPSCR_OE));
5de29b
+    fe.l |= (1 << (31 - FPSCR_OE));
5de29b
   if (excepts & FE_INVALID)
5de29b
-    fe.l[1] |= (1 << (31 - FPSCR_VE));
5de29b
+    fe.l |= (1 << (31 - FPSCR_VE));
5de29b
   fesetenv_register (fe.fenv);
5de29b
 
5de29b
   new = __fegetexcept ();
12745e
diff -urN glibc-2.17-c758a686/sysdeps/powerpc/fpu/fegetexcept.c glibc-2.17-c758a686/sysdeps/powerpc/fpu/fegetexcept.c
12745e
--- glibc-2.17-c758a686/sysdeps/powerpc/fpu/fegetexcept.c	2014-05-27 22:31:42.000000000 -0500
12745e
+++ glibc-2.17-c758a686/sysdeps/powerpc/fpu/fegetexcept.c	2014-05-27 22:31:43.000000000 -0500
5de29b
@@ -27,15 +27,15 @@
5de29b
 
5de29b
   fe.fenv = fegetenv_register ();
5de29b
 
5de29b
-  if (fe.l[1] & (1 << (31 - FPSCR_XE)))
5de29b
+  if (fe.l & (1 << (31 - FPSCR_XE)))
5de29b
       result |= FE_INEXACT;
5de29b
-  if (fe.l[1] & (1 << (31 - FPSCR_ZE)))
5de29b
+  if (fe.l & (1 << (31 - FPSCR_ZE)))
5de29b
       result |= FE_DIVBYZERO;
5de29b
-  if (fe.l[1] & (1 << (31 - FPSCR_UE)))
5de29b
+  if (fe.l & (1 << (31 - FPSCR_UE)))
5de29b
       result |= FE_UNDERFLOW;
5de29b
-  if (fe.l[1] & (1 << (31 - FPSCR_OE)))
5de29b
+  if (fe.l & (1 << (31 - FPSCR_OE)))
5de29b
       result |= FE_OVERFLOW;
5de29b
-  if (fe.l[1] & (1 << (31 - FPSCR_VE)))
5de29b
+  if (fe.l & (1 << (31 - FPSCR_VE)))
5de29b
       result |= FE_INVALID;
5de29b
 
5de29b
   return result;
12745e
diff -urN glibc-2.17-c758a686/sysdeps/powerpc/fpu/feholdexcpt.c glibc-2.17-c758a686/sysdeps/powerpc/fpu/feholdexcpt.c
12745e
--- glibc-2.17-c758a686/sysdeps/powerpc/fpu/feholdexcpt.c	2014-05-27 22:31:42.000000000 -0500
12745e
+++ glibc-2.17-c758a686/sysdeps/powerpc/fpu/feholdexcpt.c	2014-05-27 22:33:09.000000000 -0500
5de29b
@@ -30,13 +30,12 @@
5de29b
 
5de29b
   /* Clear everything except for the rounding modes and non-IEEE arithmetic
5de29b
      flag.  */
5de29b
-  new.l[1] = old.l[1] & 7;
5de29b
-  new.l[0] = old.l[0];
5de29b
+  new.l = old.l & 0xffffffff00000007LL;
5de29b
   
5de29b
   /* If the old env had any eabled exceptions, then mask SIGFPE in the
5de29b
      MSR FE0/FE1 bits.  This may allow the FPU to run faster because it
5de29b
      always takes the default action and can not generate SIGFPE. */
5de29b
-  if ((old.l[1] & _FPU_MASK_ALL) != 0)
5de29b
+  if ((old.l & _FPU_MASK_ALL) != 0)
5de29b
     (void)__fe_mask_env ();
5de29b
 
5de29b
   /* Put the new state in effect.  */
12745e
diff -urN glibc-2.17-c758a686/sysdeps/powerpc/fpu/fenv_libc.h glibc-2.17-c758a686/sysdeps/powerpc/fpu/fenv_libc.h
12745e
--- glibc-2.17-c758a686/sysdeps/powerpc/fpu/fenv_libc.h	2014-05-27 22:31:42.000000000 -0500
12745e
+++ glibc-2.17-c758a686/sysdeps/powerpc/fpu/fenv_libc.h	2014-05-27 22:31:43.000000000 -0500
5de29b
@@ -69,7 +69,7 @@
5de29b
 typedef union
5de29b
 {
5de29b
   fenv_t fenv;
5de29b
-  unsigned int l[2];
5de29b
+  unsigned long long l;
5de29b
 } fenv_union_t;
5de29b
 
5de29b
 
12745e
diff -urN glibc-2.17-c758a686/sysdeps/powerpc/fpu/fesetenv.c glibc-2.17-c758a686/sysdeps/powerpc/fpu/fesetenv.c
12745e
--- glibc-2.17-c758a686/sysdeps/powerpc/fpu/fesetenv.c	2014-05-27 22:31:42.000000000 -0500
12745e
+++ glibc-2.17-c758a686/sysdeps/powerpc/fpu/fesetenv.c	2014-05-27 22:35:18.000000000 -0500
5de29b
@@ -36,14 +36,14 @@
5de29b
      exceptions, then unmask SIGFPE in the MSR FE0/FE1 bits.  This will put the
5de29b
      hardware into "precise mode" and may cause the FPU to run slower on some
5de29b
      hardware.  */
5de29b
-  if ((old.l[1] & _FPU_MASK_ALL) == 0 && (new.l[1] & _FPU_MASK_ALL) != 0)
5de29b
+  if ((old.l & _FPU_MASK_ALL) == 0 && (new.l & _FPU_MASK_ALL) != 0)
5de29b
     (void)__fe_nomask_env ();
5de29b
   
5de29b
   /* If the old env had any enabled exceptions and the new env has no enabled
5de29b
      exceptions, then mask SIGFPE in the MSR FE0/FE1 bits.  This may allow the
5de29b
      FPU to run faster because it always takes the default action and can not 
5de29b
      generate SIGFPE. */
5de29b
-  if ((old.l[1] & _FPU_MASK_ALL) != 0 && (new.l[1] & _FPU_MASK_ALL) == 0)
5de29b
+  if ((old.l & _FPU_MASK_ALL) != 0 && (new.l & _FPU_MASK_ALL) == 0)
5de29b
     (void)__fe_mask_env ();
5de29b
     
5de29b
   fesetenv_register (*envp);
12745e
diff -urN glibc-2.17-c758a686/sysdeps/powerpc/fpu/feupdateenv.c glibc-2.17-c758a686/sysdeps/powerpc/fpu/feupdateenv.c
12745e
--- glibc-2.17-c758a686/sysdeps/powerpc/fpu/feupdateenv.c	2014-05-27 22:31:42.000000000 -0500
12745e
+++ glibc-2.17-c758a686/sysdeps/powerpc/fpu/feupdateenv.c	2014-05-27 22:34:23.000000000 -0500
5de29b
@@ -36,20 +36,20 @@
5de29b
   /* Restore rounding mode and exception enable from *envp and merge
5de29b
      exceptions.  Leave fraction rounded/inexact and FP result/CC bits
5de29b
      unchanged.  */
5de29b
-  new.l[1] = (old.l[1] & 0x1FFFFF00) | (new.l[1] & 0x1FF80FFF);
5de29b
+  new.l = (old.l & 0xffffffff1fffff00LL) | (new.l & 0x1ff80fff);
5de29b
   
5de29b
   /* If the old env has no eabled exceptions and the new env has any enabled
5de29b
      exceptions, then unmask SIGFPE in the MSR FE0/FE1 bits.  This will put
5de29b
      the hardware into "precise mode" and may cause the FPU to run slower on
5de29b
      some hardware.  */
5de29b
-  if ((old.l[1] & _FPU_MASK_ALL) == 0 && (new.l[1] & _FPU_MASK_ALL) != 0)
5de29b
+  if ((old.l & _FPU_MASK_ALL) == 0 && (new.l & _FPU_MASK_ALL) != 0)
5de29b
     (void)__fe_nomask_env ();
5de29b
   
5de29b
   /* If the old env had any eabled exceptions and the new env has no enabled
5de29b
      exceptions, then mask SIGFPE in the MSR FE0/FE1 bits.  This may allow the
5de29b
      FPU to run faster because it always takes the default action and can not 
5de29b
      generate SIGFPE. */
5de29b
-  if ((old.l[1] & _FPU_MASK_ALL) != 0 && (new.l[1] & _FPU_MASK_ALL) == 0)
5de29b
+  if ((old.l & _FPU_MASK_ALL) != 0 && (new.l & _FPU_MASK_ALL) == 0)
5de29b
     (void)__fe_mask_env ();
5de29b
 
5de29b
   /* Atomically enable and raise (if appropriate) exceptions set in `new'. */
12745e
diff -urN glibc-2.17-c758a686/sysdeps/powerpc/fpu/fgetexcptflg.c glibc-2.17-c758a686/sysdeps/powerpc/fpu/fgetexcptflg.c
12745e
--- glibc-2.17-c758a686/sysdeps/powerpc/fpu/fgetexcptflg.c	2014-05-27 22:31:42.000000000 -0500
12745e
+++ glibc-2.17-c758a686/sysdeps/powerpc/fpu/fgetexcptflg.c	2014-05-27 22:31:43.000000000 -0500
5de29b
@@ -28,7 +28,7 @@
5de29b
   u.fenv = fegetenv_register ();
5de29b
 
5de29b
   /* Return (all of) it.  */
5de29b
-  *flagp = u.l[1] & excepts & FE_ALL_EXCEPT;
5de29b
+  *flagp = u.l & excepts & FE_ALL_EXCEPT;
5de29b
 
5de29b
   /* Success.  */
5de29b
   return 0;
12745e
diff -urN glibc-2.17-c758a686/sysdeps/powerpc/fpu/fraiseexcpt.c glibc-2.17-c758a686/sysdeps/powerpc/fpu/fraiseexcpt.c
12745e
--- glibc-2.17-c758a686/sysdeps/powerpc/fpu/fraiseexcpt.c	2014-05-27 22:31:42.000000000 -0500
12745e
+++ glibc-2.17-c758a686/sysdeps/powerpc/fpu/fraiseexcpt.c	2014-05-27 22:31:43.000000000 -0500
5de29b
@@ -34,11 +34,11 @@
5de29b
   u.fenv = fegetenv_register ();
5de29b
 
5de29b
   /* Add the exceptions */
5de29b
-  u.l[1] = (u.l[1]
5de29b
-	    | (excepts & FPSCR_STICKY_BITS)
5de29b
-	    /* Turn FE_INVALID into FE_INVALID_SOFTWARE.  */
5de29b
-	    | (excepts >> ((31 - FPSCR_VX) - (31 - FPSCR_VXSOFT))
5de29b
-	       & FE_INVALID_SOFTWARE));
5de29b
+  u.l = (u.l
5de29b
+	 | (excepts & FPSCR_STICKY_BITS)
5de29b
+	 /* Turn FE_INVALID into FE_INVALID_SOFTWARE.  */
5de29b
+	 | (excepts >> ((31 - FPSCR_VX) - (31 - FPSCR_VXSOFT))
5de29b
+	    & FE_INVALID_SOFTWARE));
5de29b
 
5de29b
   /* Store the new status word (along with the rest of the environment),
5de29b
      triggering any appropriate exceptions.  */
5de29b
@@ -50,7 +50,7 @@
5de29b
 	 don't have FE_INVALID_SOFTWARE implemented.  Detect this
5de29b
 	 case and raise FE_INVALID_SNAN instead.  */
5de29b
       u.fenv = fegetenv_register ();
5de29b
-      if ((u.l[1] & FE_INVALID) == 0)
5de29b
+      if ((u.l & FE_INVALID) == 0)
5de29b
 	set_fpscr_bit (FPSCR_VXSNAN);
5de29b
     }
5de29b
 
12745e
diff -urN glibc-2.17-c758a686/sysdeps/powerpc/fpu/fsetexcptflg.c glibc-2.17-c758a686/sysdeps/powerpc/fpu/fsetexcptflg.c
12745e
--- glibc-2.17-c758a686/sysdeps/powerpc/fpu/fsetexcptflg.c	2014-05-27 22:31:42.000000000 -0500
12745e
+++ glibc-2.17-c758a686/sysdeps/powerpc/fpu/fsetexcptflg.c	2014-05-27 22:31:43.000000000 -0500
5de29b
@@ -32,10 +32,10 @@
5de29b
   flag = *flagp & excepts;
5de29b
 
5de29b
   /* Replace the exception status */
5de29b
-  u.l[1] = ((u.l[1] & ~(FPSCR_STICKY_BITS & excepts))
5de29b
-	    | (flag & FPSCR_STICKY_BITS)
5de29b
-	    | (flag >> ((31 - FPSCR_VX) - (31 - FPSCR_VXSOFT))
5de29b
-	       & FE_INVALID_SOFTWARE));
5de29b
+  u.l = ((u.l & ~(FPSCR_STICKY_BITS & excepts))
5de29b
+	 | (flag & FPSCR_STICKY_BITS)
5de29b
+	 | (flag >> ((31 - FPSCR_VX) - (31 - FPSCR_VXSOFT))
5de29b
+	    & FE_INVALID_SOFTWARE));
5de29b
 
5de29b
   /* Store the new status word (along with the rest of the environment).
5de29b
      This may cause floating-point exceptions if the restored state
12745e
diff -urN glibc-2.17-c758a686/sysdeps/powerpc/fpu/ftestexcept.c glibc-2.17-c758a686/sysdeps/powerpc/fpu/ftestexcept.c
12745e
--- glibc-2.17-c758a686/sysdeps/powerpc/fpu/ftestexcept.c	2014-05-27 22:31:42.000000000 -0500
12745e
+++ glibc-2.17-c758a686/sysdeps/powerpc/fpu/ftestexcept.c	2014-05-27 22:31:43.000000000 -0500
5de29b
@@ -28,6 +28,6 @@
5de29b
 
5de29b
   /* The FE_INVALID bit is dealt with correctly by the hardware, so we can
5de29b
      just:  */
5de29b
-  return u.l[1] & excepts;
5de29b
+  return u.l & excepts;
5de29b
 }
5de29b
 libm_hidden_def (fetestexcept)