Back to index

glibc  2.9
math_private.h
Go to the documentation of this file.
00001 /* Private inline math functions for powerpc.
00002    Copyright (C) 2006
00003    Free Software Foundation, Inc.
00004    This file is part of the GNU C Library.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 51 Franklin St - Fifth Floor, Boston,
00019    MA 02110-1301 USA  */
00020 
00021 #ifndef _PPC_MATH_PRIVATE_H_
00022 #define _PPC_MATH_PRIVATE_H_
00023 
00024 #include <sysdep.h>
00025 #include <ldsodefs.h>
00026 #include <dl-procinfo.h>
00027 
00028 # if __WORDSIZE == 64 || defined _ARCH_PWR4
00029 #  define __CPU_HAS_FSQRT 1
00030 # else
00031 #  define __CPU_HAS_FSQRT ((GLRO(dl_hwcap) & PPC_FEATURE_64) != 0)
00032 # endif
00033 
00034 # ifndef __LIBC_INTERNAL_MATH_INLINES
00035 extern double __slow_ieee754_sqrt (double);
00036 __inline double
00037 __ieee754_sqrt (double __x)
00038 {
00039   double __z;
00040 
00041   /* If the CPU is 64-bit we can use the optional FP instructions.  */
00042   if (__CPU_HAS_FSQRT)
00043   {
00044     /* Volatile is required to prevent the compiler from moving the
00045        fsqrt instruction above the branch.  */
00046      __asm __volatile (
00047        "      fsqrt  %0,%1\n"
00048               : "=f" (__z)
00049               : "f" (__x));
00050   }
00051   else
00052      __z = __slow_ieee754_sqrt(__x);
00053 
00054   return __z;
00055 }
00056 
00057 extern float __slow_ieee754_sqrtf (float);
00058 
00059 __inline float
00060 __ieee754_sqrtf (float __x)
00061 {
00062   float __z;
00063 
00064   /* If the CPU is 64-bit we can use the optional FP instructions.  */
00065   if (__CPU_HAS_FSQRT)
00066   {
00067     /* Volatile is required to prevent the compiler from moving the
00068        fsqrts instruction above the branch.  */
00069      __asm __volatile (
00070        "      fsqrts %0,%1\n"
00071               : "=f" (__z)
00072               : "f" (__x));
00073   }
00074   else
00075      __z = __slow_ieee754_sqrtf(__x);
00076 
00077   return __z;
00078 }
00079 #endif /* __LIBC_INTERNAL_MATH_INLINES */
00080 
00081 #include <math/math_private.h>
00082 
00083 #endif /* _PPC_MATH_PRIVATE_H_ */