]>
Commit | Line | Data |
---|---|---|
11bf311e | 1 | /* Private inline math functions for powerpc. |
d4697bc9 | 2 | Copyright (C) 2006-2014 Free Software Foundation, Inc. |
11bf311e UD |
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 | |
59ba27a6 PE |
16 | License along with the GNU C Library; if not, see |
17 | <http://www.gnu.org/licenses/>. */ | |
11bf311e UD |
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> | |
41e8926a | 25 | #include <fenv_private.h> |
b8c03620 | 26 | #include_next <math_private.h> |
8a6d5255 | 27 | |
11bf311e UD |
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) | |
67bb6da6 RH |
32 | # endif |
33 | ||
34 | extern double __slow_ieee754_sqrt (double); | |
35 | extern __always_inline double | |
36 | __ieee754_sqrt (double __x) | |
37 | { | |
38 | double __z; | |
8a6d5255 | 39 | |
67bb6da6 RH |
40 | if (__CPU_HAS_FSQRT) |
41 | { | |
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)); | |
45 | } | |
46 | else | |
47 | __z = __slow_ieee754_sqrt(__x); | |
48 | ||
49 | return __z; | |
50 | } | |
51 | ||
52 | extern float __slow_ieee754_sqrtf (float); | |
53 | extern __always_inline float | |
54 | __ieee754_sqrtf (float __x) | |
55 | { | |
56 | float __z; | |
57 | ||
58 | if (__CPU_HAS_FSQRT) | |
59 | { | |
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)); | |
63 | } | |
64 | else | |
65 | __z = __slow_ieee754_sqrtf(__x); | |
66 | ||
67 | return __z; | |
68 | } | |
8a6d5255 AZ |
69 | |
70 | #if defined _ARCH_PWR5X | |
71 | ||
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 | |
91 | ||
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 | |
111 | ||
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; }) | |
11bf311e UD |
130 | # endif |
131 | ||
8a6d5255 AZ |
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 | |
151 | ||
152 | #endif /* defined _ARCH_PWR5X */ | |
153 | ||
154 | ||
155 | #if defined _ARCH_PWR6 | |
156 | ||
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 | |
176 | ||
177 | #endif /* defined _ARCH_PWR6 */ | |
178 | ||
11bf311e | 179 | #endif /* _PPC_MATH_PRIVATE_H_ */ |