Replace FSF snail mail address with URLs.
[glibc.git] / sysdeps / powerpc / fpu / math_private.h
blob7bacecb245e156bb8f5ca112a7c2a9413667e7e2
1 /* Private inline math functions for powerpc.
2 Copyright (C) 2006, 2011
3 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
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.
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.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
20 #ifndef _PPC_MATH_PRIVATE_H_
21 #define _PPC_MATH_PRIVATE_H_
23 #include <sysdep.h>
24 #include <ldsodefs.h>
25 #include <dl-procinfo.h>
27 #include <math/math_private.h>
29 # if __WORDSIZE == 64 || defined _ARCH_PWR4
30 # define __CPU_HAS_FSQRT 1
32 #ifndef __ieee754_sqrt
33 # define __ieee754_sqrt(x) \
34 ({ double __z; \
35 __asm __volatile ( \
36 " fsqrt %0,%1\n" \
37 : "=f" (__z) \
38 : "f"(x)); \
39 __z; })
40 #endif
41 #ifndef __ieee754_sqrtf
42 # define __ieee754_sqrtf(x) \
43 ({ float __z; \
44 __asm __volatile ( \
45 " fsqrts %0,%1\n" \
46 : "=f" (__z) \
47 : "f"(x)); \
48 __z; })
49 #endif
51 # else
52 # define __CPU_HAS_FSQRT ((GLRO(dl_hwcap) & PPC_FEATURE_64) != 0)
53 # endif // __WORDSIZE == 64 || defined _ARCH_PWR4
56 #if defined _ARCH_PWR5X
58 # ifndef __round
59 # define __round(x) \
60 ({ double __z; \
61 __asm __volatile ( \
62 " frin %0,%1\n" \
63 : "=f" (__z) \
64 : "f" (x)); \
65 __z; })
66 # endif
67 # ifndef __roundf
68 # define __roundf(x) \
69 ({ float __z; \
70 __asm __volatile ( \
71 " frin %0,%1\n" \
72 " frsp %0,%0\n" \
73 : "=f" (__z) \
74 : "f" (x)); \
75 __z; })
76 # endif
78 # ifndef __trunc
79 # define __trunc(x) \
80 ({ double __z; \
81 __asm __volatile ( \
82 " friz %0,%1\n" \
83 : "=f" (__z) \
84 : "f" (x)); \
85 __z; })
86 # endif
87 # ifndef __truncf
88 # define __truncf(x) \
89 ({ float __z; \
90 __asm __volatile ( \
91 " friz %0,%1\n" \
92 " frsp %0,%0\n" \
93 : "=f" (__z) \
94 : "f" (x)); \
95 __z; })
96 # endif
98 # ifndef __ceil
99 # define __ceil(x) \
100 ({ double __z; \
101 __asm __volatile ( \
102 " frip %0,%1\n" \
103 : "=f" (__z) \
104 : "f" (x)); \
105 __z; })
106 # endif
107 # ifndef __ceilf
108 # define __ceilf(x) \
109 ({ float __z; \
110 __asm __volatile ( \
111 " frip %0,%1\n" \
112 " frsp %0,%0\n" \
113 : "=f" (__z) \
114 : "f" (x)); \
115 __z; })
116 # endif
118 # ifndef __floor
119 # define __floor(x) \
120 ({ double __z; \
121 __asm __volatile ( \
122 " frim %0,%1\n" \
123 : "=f" (__z) \
124 : "f" (x)); \
125 __z; })
126 # endif
127 # ifndef __floorf
128 # define __floorf(x) \
129 ({ float __z; \
130 __asm __volatile ( \
131 " frim %0,%1\n" \
132 " frsp %0,%0\n" \
133 : "=f" (__z) \
134 : "f" (x)); \
135 __z; })
136 # endif
138 #endif /* defined _ARCH_PWR5X */
141 #if defined _ARCH_PWR6
143 # ifndef __copysign
144 # define __copysign(x, y) \
145 ({ double __z; \
146 __asm __volatile ( \
147 " fcpsgn %0,%1,%2\n" \
148 : "=f" (__z) \
149 : "f" (y), "f" (x)); \
150 __z; })
151 # endif
152 # ifndef __copysignf
153 # define __copysignf(x, y) \
154 ({ float __z; \
155 __asm __volatile ( \
156 " fcpsgn %0,%1,%2\n" \
157 " frsp %0,%0\n" \
158 : "=f" (__z) \
159 : "f" (y), "f" (x)); \
160 __z; })
161 # endif
163 #endif /* defined _ARCH_PWR6 */
166 # ifndef __LIBC_INTERNAL_MATH_INLINES
167 extern double __slow_ieee754_sqrt (double);
168 __inline double
169 __ieee754_sqrt (double __x)
171 double __z;
173 /* If the CPU is 64-bit we can use the optional FP instructions. */
174 if (__CPU_HAS_FSQRT)
176 /* Volatile is required to prevent the compiler from moving the
177 fsqrt instruction above the branch. */
178 __asm __volatile (
179 " fsqrt %0,%1\n"
180 : "=f" (__z)
181 : "f" (__x));
183 else
184 __z = __slow_ieee754_sqrt(__x);
186 return __z;
189 extern float __slow_ieee754_sqrtf (float);
191 __inline float
192 __ieee754_sqrtf (float __x)
194 float __z;
196 /* If the CPU is 64-bit we can use the optional FP instructions. */
197 if (__CPU_HAS_FSQRT)
199 /* Volatile is required to prevent the compiler from moving the
200 fsqrts instruction above the branch. */
201 __asm __volatile (
202 " fsqrts %0,%1\n"
203 : "=f" (__z)
204 : "f" (__x));
206 else
207 __z = __slow_ieee754_sqrtf(__x);
209 return __z;
211 #endif /* __LIBC_INTERNAL_MATH_INLINES */
213 #endif /* _PPC_MATH_PRIVATE_H_ */