Print this page
11210 libm should be cstyle(1ONBLD) clean
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libm/i386/src/libm_inlines.h
+++ new/usr/src/lib/libm/i386/src/libm_inlines.h
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26
↓ open down ↓ |
26 lines elided |
↑ open up ↑ |
27 27 /*
28 28 * Copyright 2011, Richard Lowe
29 29 */
30 30
31 31 /* Functions in this file are duplicated in locallibm.il. Keep them in sync */
32 32
33 33 #ifndef _LIBM_INLINES_H
34 34 #define _LIBM_INLINES_H
35 35
36 36 #ifdef __GNUC__
37 -
38 37 #ifdef __cplusplus
39 38 extern "C" {
40 39 #endif
41 40
42 41 #include <sys/types.h>
43 42 #include <sys/ieeefp.h>
44 43
45 44 #define _LO_WORD(x) ((uint32_t *)&x)[0]
46 45 #define _HI_WORD(x) ((uint32_t *)&x)[1]
47 46 #define _HIER_WORD(x) ((uint32_t *)&x)[2]
48 47
49 48 extern __GNU_INLINE double
50 49 __inline_sqrt(double a)
51 50 {
52 51 double ret;
53 52
54 53 __asm__ __volatile__("fsqrt\n\t" : "=t" (ret) : "0" (a) : "cc");
55 54 return (ret);
56 55 }
57 56
58 57 extern __GNU_INLINE double
59 58 __ieee754_sqrt(double a)
60 59 {
61 60 return (__inline_sqrt(a));
62 61 }
63 62
64 63 extern __GNU_INLINE float
65 64 __inline_sqrtf(float a)
66 65 {
67 66 float ret;
68 67
69 68 __asm__ __volatile__("fsqrt\n\t" : "=t" (ret) : "0" (a) : "cc");
70 69 return (ret);
71 70 }
72 71
73 72 extern __GNU_INLINE double
74 73 __inline_rint(double a)
75 74 {
76 75 __asm__ __volatile__(
77 76 "andl $0x7fffffff,%1\n\t"
78 77 "cmpl $0x43300000,%1\n\t"
79 78 "jae 1f\n\t"
80 79 "frndint\n\t"
81 80 "1: fwait\n\t"
82 81 : "+t" (a), "+&r" (_HI_WORD(a))
83 82 :
84 83 : "cc");
85 84
86 85 return (a);
87 86 }
88 87
89 88 /*
90 89 * 00 - 24 bits
91 90 * 01 - reserved
92 91 * 10 - 53 bits
93 92 * 11 - 64 bits
94 93 */
95 94 extern __GNU_INLINE int
96 95 __swapRP(int i)
97 96 {
98 97 int ret;
99 98 uint16_t cw;
100 99
101 100 __asm__ __volatile__("fstcw %0\n\t" : "=m" (cw));
102 101
103 102 ret = (cw >> 8) & 0x3;
104 103 cw = (cw & 0xfcff) | ((i & 0x3) << 8);
105 104
106 105 __asm__ __volatile__("fldcw %0\n\t" : : "m" (cw));
107 106
108 107 return (ret);
109 108 }
110 109
111 110 /*
112 111 * 00 - Round to nearest, with even preferred
113 112 * 01 - Round down
114 113 * 10 - Round up
115 114 * 11 - Chop
116 115 */
117 116 extern __GNU_INLINE enum fp_direction_type
118 117 __swap87RD(enum fp_direction_type i)
119 118 {
120 119 int ret;
121 120 uint16_t cw;
122 121
123 122 __asm__ __volatile__("fstcw %0\n\t" : "=m" (cw));
124 123
125 124 ret = (cw >> 10) & 0x3;
126 125 cw = (cw & 0xf3ff) | ((i & 0x3) << 10);
127 126
128 127 __asm__ __volatile__("fldcw %0\n\t" : : "m" (cw));
129 128
130 129 return (ret);
131 130 }
132 131
133 132 extern __GNU_INLINE double
134 133 ceil(double d)
135 134 {
136 135 /*
137 136 * Let's set a Rounding Control (RC) bits from x87 FPU Control Word
138 137 * to fp_positive and save old bits in rd.
139 138 */
140 139 short rd = __swap87RD(fp_positive);
141 140
142 141 /*
143 142 * The FRNDINT instruction returns a floating-point value that is the
144 143 * integral value closest to the source value in the direction of the
145 144 * rounding mode specified in the RC field of the x87 FPU control word.
146 145 *
147 146 * Rounds the source value in the ST(0) register to the nearest
148 147 * integral value, depending on the current rounding mode
149 148 * (setting of the RC field of the FPU control word),
150 149 * and stores the result in ST(0).
151 150 */
152 151 __asm__ __volatile__("frndint" : "+t" (d) : : "cc");
153 152
154 153 /* restore old RC bits */
155 154 __swap87RD(rd);
156 155
157 156 return (d);
158 157 }
159 158
160 159 extern __GNU_INLINE double
161 160 copysign(double d1, double d2)
162 161 {
163 162 __asm__ __volatile__(
164 163 "andl $0x7fffffff,%0\n\t" /* %0 <-- hi_32(abs(d)) */
165 164 "andl $0x80000000,%1\n\t" /* %1[31] <-- sign_bit(d2) */
166 165 "orl %1,%0\n\t" /* %0 <-- hi_32(copysign(x,y)) */
167 166 : "+&r" (_HI_WORD(d1)), "+r" (_HI_WORD(d2))
168 167 :
169 168 : "cc");
170 169
171 170 return (d1);
172 171 }
173 172
174 173 extern __GNU_INLINE double
175 174 fabs(double d)
176 175 {
177 176 __asm__ __volatile__("fabs\n\t" : "+t" (d) : : "cc");
178 177 return (d);
179 178 }
180 179
181 180 extern __GNU_INLINE float
182 181 fabsf(float d)
183 182 {
184 183 __asm__ __volatile__("fabs\n\t" : "+t" (d) : : "cc");
185 184 return (d);
186 185 }
187 186
188 187 extern __GNU_INLINE long double
189 188 fabsl(long double d)
190 189 {
191 190 __asm__ __volatile__("fabs\n\t" : "+t" (d) : : "cc");
192 191 return (d);
193 192 }
194 193
195 194 extern __GNU_INLINE int
196 195 finite(double d)
197 196 {
198 197 int ret = _HI_WORD(d);
199 198
200 199 __asm__ __volatile__(
201 200 "notl %0\n\t"
202 201 "andl $0x7ff00000,%0\n\t"
203 202 "negl %0\n\t"
204 203 "shrl $31,%0\n\t"
205 204 : "+r" (ret)
206 205 :
207 206 : "cc");
208 207 return (ret);
209 208 }
210 209
211 210 extern __GNU_INLINE double
212 211 floor(double d)
213 212 {
214 213 short rd = __swap87RD(fp_negative);
215 214
216 215 __asm__ __volatile__("frndint" : "+t" (d), "+r" (rd) : : "cc");
217 216 __swap87RD(rd);
218 217
219 218 return (d);
220 219 }
221 220
222 221 /*
223 222 * branchless __isnan
224 223 * ((0x7ff00000-[((lx|-lx)>>31)&1]|ahx)>>31)&1 = 1 iff x is NaN
225 224 */
226 225 extern __GNU_INLINE int
227 226 isnan(double d)
228 227 {
229 228 int ret;
230 229
231 230 __asm__ __volatile__(
232 231 "movl %1,%%ecx\n\t"
233 232 "negl %%ecx\n\t" /* ecx <-- -lo_32(x) */
234 233 "orl %%ecx,%1\n\t"
235 234 "shrl $31,%1\n\t" /* 1 iff lx != 0 */
236 235 "andl $0x7fffffff,%2\n\t" /* ecx <-- hi_32(abs(x)) */
237 236 "orl %2,%1\n\t"
238 237 "subl $0x7ff00000,%1\n\t"
239 238 "negl %1\n\t"
240 239 "shrl $31,%1\n\t"
241 240 : "=r" (ret)
242 241 : "0" (_HI_WORD(d)), "r" (_LO_WORD(d))
243 242 : "ecx");
244 243
245 244 return (ret);
246 245 }
247 246
248 247 extern __GNU_INLINE int
249 248 isnanf(float f)
250 249 {
251 250 __asm__ __volatile__(
252 251 "andl $0x7fffffff,%0\n\t"
253 252 "negl %0\n\t"
↓ open down ↓ |
206 lines elided |
↑ open up ↑ |
254 253 "addl $0x7f800000,%0\n\t"
255 254 "shrl $31,%0\n\t"
256 255 : "+r" (f)
257 256 :
258 257 : "cc");
259 258
260 259 return (f);
261 260 }
262 261
263 262 extern __GNU_INLINE double
264 -rint(double a) {
265 - return (__inline_rint(a));
263 +rint(double a)
264 +{
265 + return (__inline_rint(a));
266 266 }
267 267
268 268 extern __GNU_INLINE double
269 269 scalbn(double d, int n)
270 270 {
271 271 double dummy;
272 272
273 273 __asm__ __volatile__(
274 274 "fildl %2\n\t" /* Convert N to extended */
275 275 "fxch\n\t"
276 276 "fscale\n\t"
277 277 : "+t" (d), "=u" (dummy)
278 278 : "m" (n)
279 279 : "cc");
280 280
281 281 return (d);
282 282 }
283 283
284 284 extern __GNU_INLINE int
285 285 signbit(double d)
286 286 {
287 287 return (_HI_WORD(d) >> 31);
288 288 }
289 289
290 290 extern __GNU_INLINE int
291 291 signbitf(float f)
292 292 {
293 293 return ((*(uint32_t *)&f) >> 31);
294 294 }
295 295
296 296 extern __GNU_INLINE double
297 297 sqrt(double d)
298 298 {
299 299 return (__inline_sqrt(d));
300 300 }
301 301
302 302 extern __GNU_INLINE float
303 303 sqrtf(float f)
304 304 {
305 305 return (__inline_sqrtf(f));
306 306 }
307 307
308 308 extern __GNU_INLINE long double
309 309 sqrtl(long double ld)
310 310 {
311 311 __asm__ __volatile__("fsqrt" : "+t" (ld) : : "cc");
312 312 return (ld);
313 313 }
314 314
315 315 extern __GNU_INLINE int
316 316 isnanl(long double ld)
317 317 {
318 318 int ret = _HIER_WORD(ld);
319 319
320 320 __asm__ __volatile__(
321 321 "andl $0x00007fff,%0\n\t"
322 322 "jz 1f\n\t" /* jump if exp is all 0 */
323 323 "xorl $0x00007fff,%0\n\t"
324 324 "jz 2f\n\t" /* jump if exp is all 1 */
325 325 "testl $0x80000000,%1\n\t"
326 326 "jz 3f\n\t" /* jump if leading bit is 0 */
327 327 "xorl %0,%0\n\t"
328 328 "jmp 1f\n\t"
329 329 "2:\n\t" /* note that %0 = 0 from before */
330 330 "cmpl $0x80000000,%1\n\t" /* what is first half of significand? */
331 331 "jnz 3f\n\t" /* jump if not equal to 0x80000000 */
332 332 "testl $0xffffffff,%2\n\t" /* is second half of significand 0? */
333 333 "jnz 3f\n\t" /* jump if not equal to 0 */
334 334 "jmp 1f\n\t"
335 335 "3:\n\t"
336 336 "movl $1,%0\n\t"
337 337 "1:\n\t"
↓ open down ↓ |
62 lines elided |
↑ open up ↑ |
338 338 : "+&r" (ret)
339 339 : "r" (_HI_WORD(ld)), "r" (_LO_WORD(ld))
340 340 : "cc");
341 341
342 342 return (ret);
343 343 }
344 344
345 345 #ifdef __cplusplus
346 346 }
347 347 #endif
348 -
349 348 #endif /* __GNUC__ */
350 -
351 349 #endif /* _LIBM_INLINES_H */
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX