Fix fsqrt build in libm

AmigaOne X5000 platform specific issues related to Linux only.
Post Reply
User avatar
xeno74
Posts: 9320
Joined: Fri Mar 23, 2012 7:58 am

Fix fsqrt build in libm

Post by xeno74 »

FYI:
Adhemerval Zanella wrote: powerpc: Fix fsqrt build in libm [BZ#16576]

Some powerpc64 processors (e5500 core for instance) does not provide the
fsqrt instruction, however current check to use in math_private.h is
__WORDSIZE and _ARCH_PWR4 (ISA 2.02). This is patch change it to use
the compiler flag _ARCH_PPCSQ (which is the same condition GCC uses to
decide whether to generate fsqrt instruction).

It fixes BZ#16576.
sysdeps/powerpc/fpu/e_sqrt.c:

Code: Select all

--- a/sysdeps/powerpc/fpu/e_sqrt.c
+++ b/sysdeps/powerpc/fpu/e_sqrt.c
@@ -24,6 +24,7 @@
 #include <sysdep.h>
 #include <ldsodefs.h>
 
+#ifndef _ARCH_PPCSQ
 static const double almost_half = 0.5000000000000001;  /* 0.5 + 2^-53 */
 static const ieee_float_shape_type a_nan = {.word = 0x7fc00000 };
 static const ieee_float_shape_type a_inf = {.word = 0x7f800000 };
@@ -152,6 +153,7 @@ __slow_ieee754_sqrt (double x)
     }
   return f_wash (x);
 }
+#endif /* _ARCH_PPCSQ  */
 
 #undef __ieee754_sqrt
 double
@@ -159,16 +161,11 @@ __ieee754_sqrt (double x)
 {
   double z;
 
-  /* 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
-        fsqrt instruction above the branch.  */
-      __asm __volatile ("      fsqrt   %0,%1\n"
-                               :"=f" (z):"f" (x));
-    }
-  else
-    z = __slow_ieee754_sqrt (x);
+#ifdef _ARCH_PPCSQ
+  asm ("fsqrt %0,%1\n" :"=f" (z):"f" (x));
+#else
+  z = __slow_ieee754_sqrt (x);
+#endif
 
   return z;
 }
sysdeps/powerpc/fpu/e_sqrtf.c:

Code: Select all

--- a/sysdeps/powerpc/fpu/e_sqrtf.c
+++ b/sysdeps/powerpc/fpu/e_sqrtf.c
@@ -24,6 +24,7 @@
 #include <sysdep.h>
 #include <ldsodefs.h>
 
+#ifndef _ARCH_PPCSQ
 static const float almost_half = 0.50000006;   /* 0.5 + 2^-24 */
 static const ieee_float_shape_type a_nan = {.word = 0x7fc00000 };
 static const ieee_float_shape_type a_inf = {.word = 0x7f800000 };
@@ -128,6 +129,7 @@ __slow_ieee754_sqrtf (float x)
     }
   return f_washf (x);
 }
+#endif /* _ARCH_PPCSQ  */
 
 #undef __ieee754_sqrtf
 float
@@ -135,16 +137,11 @@ __ieee754_sqrtf (float x)
 {
   double z;
 
-  /* 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
-        fsqrt instruction above the branch.  */
-      __asm __volatile ("      fsqrts  %0,%1\n"
-                               :"=f" (z):"f" (x));
-    }
-  else
-    z = __slow_ieee754_sqrtf (x);
+#ifdef _ARCH_PPCSQ
+  asm ("fsqrts %0,%1\n" :"=f" (z):"f" (x));
+#else
+  z = __slow_ieee754_sqrtf (x);
+#endif
 
   return z;
 }
sysdeps/powerpc/fpu/math_private.h:

Code: Select all

--- a/sysdeps/powerpc/fpu/math_private.h
+++ b/sysdeps/powerpc/fpu/math_private.h
@@ -25,26 +25,17 @@
 #include <fenv_private.h>
 #include_next <math_private.h>
 
-# if __WORDSIZE == 64 || defined _ARCH_PWR4
-#  define __CPU_HAS_FSQRT 1
-# else
-#  define __CPU_HAS_FSQRT ((GLRO(dl_hwcap) & PPC_FEATURE_64) != 0)
-# endif
-
 extern double __slow_ieee754_sqrt (double);
 extern __always_inline double
 __ieee754_sqrt (double __x)
 {
   double __z;
 
-  if (__CPU_HAS_FSQRT)
-    {
-      /* Volatile is required to prevent the compiler from moving the
-         fsqrt instruction above the branch.  */
-      __asm __volatile ("fsqrt %0,%1" : "=f" (__z) : "f" (__x));
-    }
-  else
-     __z = __slow_ieee754_sqrt(__x);
+#ifdef _ARCH_PPCSQ
+   asm ("fsqrt %0,%1" : "=f" (__z) : "f" (__x));
+#else
+   __z = __slow_ieee754_sqrt(__x);
+#endif
 
   return __z;
 }
@@ -55,14 +46,11 @@ __ieee754_sqrtf (float __x)
 {
   float __z;
 
-  if (__CPU_HAS_FSQRT)
-    {
-      /* Volatile is required to prevent the compiler from moving the
-         fsqrts instruction above the branch.  */
-      __asm __volatile ("fsqrts        %0,%1" : "=f" (__z) : "f" (__x));
-    }
-  else
-     __z = __slow_ieee754_sqrtf(__x);
+#ifdef _ARCH_PPCSQ
+  asm ("fsqrts %0,%1" : "=f" (__z) : "f" (__x));
+#else
+   __z = __slow_ieee754_sqrtf(__x);
+#endif
 
   return __z;
 }
Source: sourceware.org
http://www.amigalinux.org
http://www.supertuxkart-amiga.de

Running Linux on AmigaONEs can require some tinkering.
User avatar
xeno74
Posts: 9320
Joined: Fri Mar 23, 2012 7:58 am

Re: Fix fsqrt build in libm

Post by xeno74 »

Instructions for building a new libc6 Debian package with the fsqrt fixes (libm) for Ubuntu 10.04.4 LTS

Code: Select all

# cd /usr/local/src/

Code: Select all

# apt-get source libc6

Code: Select all

# apt-get build-dep libc6

Code: Select all

# cd eglibc-2.11.1

Code: Select all

# apt-get install devscripts
Patching the files e_sqrt.c, e_sqrtf.c, and math_private.h

Code: Select all

# dch --local mypackage

Code: Select all

# debian/rules clean && debian/rules

Code: Select all

# debian/rules binary
http://www.amigalinux.org
http://www.supertuxkart-amiga.de

Running Linux on AmigaONEs can require some tinkering.
Post Reply