Update copyright notices with scripts/update-copyrights.
[jlayton/glibc.git] / sysdeps / powerpc / fpu / math_private.h
1 /* Private inline math functions for powerpc.
2    Copyright (C) 2006-2013 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
9
10    The GNU C Library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
14
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library; if not, see
17    <http://www.gnu.org/licenses/>.  */
18
19 #ifndef _PPC_MATH_PRIVATE_H_
20 #define _PPC_MATH_PRIVATE_H_
21
22 #include <sysdep.h>
23 #include <ldsodefs.h>
24 #include <dl-procinfo.h>
25 #include_next <math_private.h>
26
27 # if __WORDSIZE == 64 || defined _ARCH_PWR4
28 #  define __CPU_HAS_FSQRT 1
29 # else
30 #  define __CPU_HAS_FSQRT ((GLRO(dl_hwcap) & PPC_FEATURE_64) != 0)
31 # endif
32
33 extern double __slow_ieee754_sqrt (double);
34 extern __always_inline double
35 __ieee754_sqrt (double __x)
36 {
37   double __z;
38
39   if (__CPU_HAS_FSQRT)
40     {
41       /* Volatile is required to prevent the compiler from moving the
42          fsqrt instruction above the branch.  */
43       __asm __volatile ("fsqrt  %0,%1" : "=f" (__z) : "f" (__x));
44     }
45   else
46      __z = __slow_ieee754_sqrt(__x);
47
48   return __z;
49 }
50
51 extern float __slow_ieee754_sqrtf (float);
52 extern __always_inline float
53 __ieee754_sqrtf (float __x)
54 {
55   float __z;
56
57   if (__CPU_HAS_FSQRT)
58     {
59       /* Volatile is required to prevent the compiler from moving the
60          fsqrts instruction above the branch.  */
61       __asm __volatile ("fsqrts %0,%1" : "=f" (__z) : "f" (__x));
62     }
63   else
64      __z = __slow_ieee754_sqrtf(__x);
65
66   return __z;
67 }
68
69 #if defined _ARCH_PWR5X
70
71 # ifndef __round
72 #  define __round(x)                    \
73     ({ double __z;                      \
74       __asm __volatile (                \
75         "       frin %0,%1\n"           \
76                 : "=f" (__z)            \
77                 : "f" (x));             \
78      __z; })
79 # endif
80 # ifndef __roundf
81 #  define __roundf(x)                   \
82     ({ float __z;                       \
83      __asm __volatile (                 \
84         "       frin %0,%1\n"           \
85         "       frsp %0,%0\n"           \
86                 : "=f" (__z)            \
87                 : "f" (x));             \
88      __z; })
89 # endif
90
91 # ifndef __trunc
92 #  define __trunc(x)                    \
93     ({ double __z;                      \
94      __asm __volatile (                 \
95         "       friz %0,%1\n"           \
96                 : "=f" (__z)            \
97                 : "f" (x));             \
98      __z; })
99 # endif
100 # ifndef __truncf
101 #  define __truncf(x)                   \
102     ({ float __z;                       \
103      __asm __volatile (                 \
104         "       friz %0,%1\n"           \
105         "       frsp %0,%0\n"           \
106                 : "=f" (__z)            \
107                 : "f" (x));             \
108      __z; })
109 # endif
110
111 # ifndef __ceil
112 #  define __ceil(x)                     \
113     ({ double __z;                      \
114      __asm __volatile (                 \
115         "       frip %0,%1\n"           \
116                 : "=f" (__z)            \
117                 : "f" (x));             \
118      __z; })
119 # endif
120 # ifndef __ceilf
121 #  define __ceilf(x)                    \
122     ({ float __z;                       \
123      __asm __volatile (                 \
124         "       frip %0,%1\n"           \
125         "       frsp %0,%0\n"           \
126                 : "=f" (__z)            \
127                 : "f" (x));             \
128      __z; })
129 # endif
130
131 # ifndef __floor
132 #  define __floor(x)                    \
133     ({ double __z;                      \
134      __asm __volatile (                 \
135         "       frim %0,%1\n"           \
136                 : "=f" (__z)            \
137                 : "f" (x));             \
138      __z; })
139 # endif
140 # ifndef __floorf
141 #  define __floorf(x)                   \
142     ({ float __z;                       \
143      __asm __volatile (                 \
144         "       frim %0,%1\n"           \
145         "       frsp %0,%0\n"           \
146                 : "=f" (__z)            \
147                 : "f" (x));             \
148      __z; })
149 # endif
150
151 #endif  /* defined _ARCH_PWR5X */
152
153
154 #if defined _ARCH_PWR6
155
156 # ifndef __copysign
157 #  define __copysign(x, y)              \
158     ({ double __z;                      \
159      __asm __volatile (                 \
160         "       fcpsgn %0,%1,%2\n"      \
161                 : "=f" (__z)            \
162                 : "f" (y), "f" (x));    \
163      __z; })
164 # endif
165 # ifndef __copysignf
166 #  define __copysignf(x, y)             \
167     ({ float __z;                       \
168      __asm __volatile (                 \
169         "       fcpsgn %0,%1,%2\n"      \
170         "       frsp %0,%0\n"           \
171                 : "=f" (__z)            \
172                 : "f" (y), "f" (x));    \
173      __z; })
174 # endif
175
176 #endif /* defined _ARCH_PWR6 */
177
178 #endif /* _PPC_MATH_PRIVATE_H_ */