Update copyright notices with scripts/update-copyrights
[glibc.git] / sysdeps / powerpc / fpu / math_private.h
blobdde153d37ae7c49c8fabc77747e6c5a1b09b8471
1 /* Private inline math functions for powerpc.
2 Copyright (C) 2006-2014 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
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/>. */
19 #ifndef _PPC_MATH_PRIVATE_H_
20 #define _PPC_MATH_PRIVATE_H_
22 #include <sysdep.h>
23 #include <ldsodefs.h>
24 #include <dl-procinfo.h>
25 #include <fenv_private.h>
26 #include_next <math_private.h>
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
34 extern double __slow_ieee754_sqrt (double);
35 extern __always_inline double
36 __ieee754_sqrt (double __x)
38 double __z;
40 if (__CPU_HAS_FSQRT)
42 /* Volatile is required to prevent the compiler from moving the
43 fsqrt instruction above the branch. */
44 __asm __volatile ("fsqrt %0,%1" : "=f" (__z) : "f" (__x));
46 else
47 __z = __slow_ieee754_sqrt(__x);
49 return __z;
52 extern float __slow_ieee754_sqrtf (float);
53 extern __always_inline float
54 __ieee754_sqrtf (float __x)
56 float __z;
58 if (__CPU_HAS_FSQRT)
60 /* Volatile is required to prevent the compiler from moving the
61 fsqrts instruction above the branch. */
62 __asm __volatile ("fsqrts %0,%1" : "=f" (__z) : "f" (__x));
64 else
65 __z = __slow_ieee754_sqrtf(__x);
67 return __z;
70 #if defined _ARCH_PWR5X
72 # ifndef __round
73 # define __round(x) \
74 ({ double __z; \
75 __asm __volatile ( \
76 " frin %0,%1\n" \
77 : "=f" (__z) \
78 : "f" (x)); \
79 __z; })
80 # endif
81 # ifndef __roundf
82 # define __roundf(x) \
83 ({ float __z; \
84 __asm __volatile ( \
85 " frin %0,%1\n" \
86 " frsp %0,%0\n" \
87 : "=f" (__z) \
88 : "f" (x)); \
89 __z; })
90 # endif
92 # ifndef __trunc
93 # define __trunc(x) \
94 ({ double __z; \
95 __asm __volatile ( \
96 " friz %0,%1\n" \
97 : "=f" (__z) \
98 : "f" (x)); \
99 __z; })
100 # endif
101 # ifndef __truncf
102 # define __truncf(x) \
103 ({ float __z; \
104 __asm __volatile ( \
105 " friz %0,%1\n" \
106 " frsp %0,%0\n" \
107 : "=f" (__z) \
108 : "f" (x)); \
109 __z; })
110 # endif
112 # ifndef __ceil
113 # define __ceil(x) \
114 ({ double __z; \
115 __asm __volatile ( \
116 " frip %0,%1\n" \
117 : "=f" (__z) \
118 : "f" (x)); \
119 __z; })
120 # endif
121 # ifndef __ceilf
122 # define __ceilf(x) \
123 ({ float __z; \
124 __asm __volatile ( \
125 " frip %0,%1\n" \
126 " frsp %0,%0\n" \
127 : "=f" (__z) \
128 : "f" (x)); \
129 __z; })
130 # endif
132 # ifndef __floor
133 # define __floor(x) \
134 ({ double __z; \
135 __asm __volatile ( \
136 " frim %0,%1\n" \
137 : "=f" (__z) \
138 : "f" (x)); \
139 __z; })
140 # endif
141 # ifndef __floorf
142 # define __floorf(x) \
143 ({ float __z; \
144 __asm __volatile ( \
145 " frim %0,%1\n" \
146 " frsp %0,%0\n" \
147 : "=f" (__z) \
148 : "f" (x)); \
149 __z; })
150 # endif
152 #endif /* defined _ARCH_PWR5X */
155 #if defined _ARCH_PWR6
157 # ifndef __copysign
158 # define __copysign(x, y) \
159 ({ double __z; \
160 __asm __volatile ( \
161 " fcpsgn %0,%1,%2\n" \
162 : "=f" (__z) \
163 : "f" (y), "f" (x)); \
164 __z; })
165 # endif
166 # ifndef __copysignf
167 # define __copysignf(x, y) \
168 ({ float __z; \
169 __asm __volatile ( \
170 " fcpsgn %0,%1,%2\n" \
171 " frsp %0,%0\n" \
172 : "=f" (__z) \
173 : "f" (y), "f" (x)); \
174 __z; })
175 # endif
177 #endif /* defined _ARCH_PWR6 */
179 #endif /* _PPC_MATH_PRIVATE_H_ */