Upload Tizen:Base source
[external/eglibc.git] / sysdeps / powerpc / fpu / math_private.h
1 /* Private inline math functions for powerpc.
2    Copyright (C) 2006
3    Free Software Foundation, Inc.
4    This file is part of the GNU C Library.
5
6    The GNU C Library is free software; you can redistribute it and/or
7    modify it under the terms of the GNU Lesser General Public
8    License as published by the Free Software Foundation; either
9    version 2.1 of the License, or (at your option) any later version.
10
11    The GNU C Library is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    Lesser General Public License for more details.
15
16    You should have received a copy of the GNU Lesser General Public
17    License along with the GNU C Library; if not, write to the Free
18    Software Foundation, Inc., 51 Franklin St - Fifth Floor, Boston,
19    MA 02110-1301 USA  */
20
21 #ifndef _PPC_MATH_PRIVATE_H_
22 #define _PPC_MATH_PRIVATE_H_
23
24 #include <sysdep.h>
25 #include <ldsodefs.h>
26 #include <dl-procinfo.h>
27
28 # if __WORDSIZE == 64 || defined _ARCH_PWR4
29 #  define __CPU_HAS_FSQRT 1
30 # else
31 #  define __CPU_HAS_FSQRT ((GLRO(dl_hwcap) & PPC_FEATURE_64) != 0)
32 # endif
33
34 # ifndef __LIBC_INTERNAL_MATH_INLINES
35 extern double __slow_ieee754_sqrt (double);
36 __inline double
37 __ieee754_sqrt (double __x)
38 {
39   double __z;
40
41   /* If the CPU is 64-bit we can use the optional FP instructions.  */
42   if (__CPU_HAS_FSQRT)
43   {
44     /* Volatile is required to prevent the compiler from moving the
45        fsqrt instruction above the branch.  */
46      __asm __volatile (
47         "       fsqrt   %0,%1\n"
48                 : "=f" (__z)
49                 : "f" (__x));
50   }
51   else
52      __z = __slow_ieee754_sqrt(__x);
53
54   return __z;
55 }
56
57 extern float __slow_ieee754_sqrtf (float);
58
59 __inline float
60 __ieee754_sqrtf (float __x)
61 {
62   float __z;
63
64   /* If the CPU is 64-bit we can use the optional FP instructions.  */
65   if (__CPU_HAS_FSQRT)
66   {
67     /* Volatile is required to prevent the compiler from moving the
68        fsqrts instruction above the branch.  */
69      __asm __volatile (
70         "       fsqrts  %0,%1\n"
71                 : "=f" (__z)
72                 : "f" (__x));
73   }
74   else
75      __z = __slow_ieee754_sqrtf(__x);
76
77   return __z;
78 }
79 #endif /* __LIBC_INTERNAL_MATH_INLINES */
80
81 #include <math/math_private.h>
82
83 #endif /* _PPC_MATH_PRIVATE_H_ */