2.9
[glibc/nacl-glibc.git] / sysdeps / sparc / fpu / bits / mathinline.h
blobd3ff44c5a90cd14fd8dbd4e295b6639a2b4801fa
1 /* Inline math functions for SPARC.
2 Copyright (C) 1999, 2000, 2001, 2002, 2004, 2006, 2007
3 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
5 Contributed by Jakub Jelinek <jakub@redhat.com>.
7 The GNU C Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 The GNU C Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with the GNU C Library; if not, write to the Free
19 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 02111-1307 USA. */
22 #ifndef _MATH_H
23 # error "Never use <bits/mathinline.h> directly; include <math.h> instead."
24 #endif
26 #include <bits/wordsize.h>
28 #ifdef __GNUC__
30 #if defined __USE_ISOC99 && !__GNUC_PREREQ (3, 0)
31 # undef isgreater
32 # undef isgreaterequal
33 # undef isless
34 # undef islessequal
35 # undef islessgreater
36 # undef isunordered
38 # if __WORDSIZE == 32
40 # ifndef __NO_LONG_DOUBLE_MATH
42 # define __unordered_cmp(x, y) \
43 (__extension__ \
44 ({ unsigned __r; \
45 if (sizeof (x) == 4 && sizeof (y) == 4) \
46 { \
47 float __x = (x); float __y = (y); \
48 __asm__ ("fcmps %1,%2; st %%fsr, %0" : "=m" (__r) : "f" (__x), \
49 "f" (__y) : "cc"); \
50 } \
51 else if (sizeof (x) <= 8 && sizeof (y) <= 8) \
52 { \
53 double __x = (x); double __y = (y); \
54 __asm__ ("fcmpd\t%1,%2\n\tst\t%%fsr,%0" : "=m" (__r) : "f" (__x), \
55 "f" (__y) : "cc"); \
56 } \
57 else \
58 { \
59 long double __x = (x); long double __y = (y); \
60 extern int _Q_cmp (const long double a, const long double b); \
61 __r = _Q_cmp (__x, __y) << 10; \
62 } \
63 __r; }))
65 # else
67 # define __unordered_cmp(x, y) \
68 (__extension__ \
69 ({ unsigned __r; \
70 if (sizeof (x) == 4 && sizeof (y) == 4) \
71 { \
72 float __x = (x); float __y = (y); \
73 __asm__ ("fcmps %1,%2; st %%fsr, %0" : "=m" (__r) : "f" (__x), \
74 "f" (__y) : "cc"); \
75 } \
76 else \
77 { \
78 double __x = (x); double __y = (y); \
79 __asm__ ("fcmpd\t%1,%2\n\tst\t%%fsr,%0" : "=m" (__r) : "f" (__x), \
80 "f" (__y) : "cc"); \
81 } \
82 __r; }))
84 # endif
86 # define isgreater(x, y) ((__unordered_cmp (x, y) & (3 << 10)) == (2 << 10))
87 # define isgreaterequal(x, y) ((__unordered_cmp (x, y) & (1 << 10)) == 0)
88 # define isless(x, y) ((__unordered_cmp (x, y) & (3 << 10)) == (1 << 10))
89 # define islessequal(x, y) ((__unordered_cmp (x, y) & (2 << 10)) == 0)
90 # define islessgreater(x, y) (((__unordered_cmp (x, y) + (1 << 10)) & (2 << 10)) != 0)
91 # define isunordered(x, y) ((__unordered_cmp (x, y) & (3 << 10)) == (3 << 10))
93 # else /* sparc64 */
95 # define __unordered_v9cmp(x, y, op, qop) \
96 (__extension__ \
97 ({ unsigned __r; \
98 if (sizeof (x) == 4 && sizeof (y) == 4) \
99 { \
100 float __x = (x); float __y = (y); \
101 __asm__ ("fcmps\t%%fcc3,%1,%2\n\tmov" op "\t%%fcc3,1,%0" \
102 : "=r" (__r) : "f" (__x), "f" (__y), "0" (0) : "cc"); \
104 else if (sizeof (x) <= 8 && sizeof (y) <= 8) \
106 double __x = (x); double __y = (y); \
107 __asm__ ("fcmpd\t%%fcc3,%1,%2\n\tmov" op "\t%%fcc3,1,%0" \
108 : "=r" (__r) : "f" (__x), "f" (__y), "0" (0) : "cc"); \
110 else \
112 long double __x = (x); long double __y = (y); \
113 extern int _Qp_cmp (const long double *a, const long double *b); \
114 __r = qop; \
116 __r; }))
118 # define isgreater(x, y) __unordered_v9cmp(x, y, "g", _Qp_cmp (&__x, &__y) == 2)
119 # define isgreaterequal(x, y) __unordered_v9cmp(x, y, "ge", (_Qp_cmp (&__x, &__y) & 1) == 0)
120 # define isless(x, y) __unordered_v9cmp(x, y, "l", _Qp_cmp (&__x, &__y) == 1)
121 # define islessequal(x, y) __unordered_v9cmp(x, y, "le", (_Qp_cmp (&__x, &__y) & 2) == 0)
122 # define islessgreater(x, y) __unordered_v9cmp(x, y, "lg", ((_Qp_cmp (&__x, &__y) + 1) & 2) != 0)
123 # define isunordered(x, y) __unordered_v9cmp(x, y, "u", _Qp_cmp (&__x, &__y) == 3)
125 # endif /* sparc64 */
127 #endif /* __USE_ISOC99 */
129 #if (!defined __NO_MATH_INLINES || defined __LIBC_INTERNAL_MATH_INLINES) && defined __OPTIMIZE__
131 # ifndef __extern_inline
132 # define __MATH_INLINE __inline
133 # else
134 # define __MATH_INLINE __extern_inline
135 # endif /* __cplusplus */
137 /* The gcc, version 2.7 or below, has problems with all this inlining
138 code. So disable it for this version of the compiler. */
139 # if __GNUC_PREREQ (2, 8)
141 # ifdef __USE_ISOC99
143 /* Test for negative number. Used in the signbit() macro. */
144 __MATH_INLINE int
145 __NTH (__signbitf (float __x))
147 __extension__ union { float __f; int __i; } __u = { __f: __x };
148 return __u.__i < 0;
151 # if __WORDSIZE == 32
153 __MATH_INLINE int
154 __NTH (__signbit (double __x))
156 __extension__ union { double __d; int __i[2]; } __u = { __d: __x };
157 return __u.__i[0] < 0;
160 # ifndef __NO_LONG_DOUBLE_MATH
161 __MATH_INLINE int
162 __NTH (__signbitl (long double __x))
164 __extension__ union { long double __l; int __i[4]; } __u = { __l: __x };
165 return __u.__i[0] < 0;
167 # else
168 __MATH_INLINE int
169 __NTH (__signbitl (long double __x))
171 return __signbit ((double)__x);
173 # endif
175 # else /* sparc64 */
177 __MATH_INLINE int
178 __NTH (__signbit (double __x))
180 __extension__ union { double __d; long int __i; } __u = { __d: __x };
181 return __u.__i < 0;
184 __MATH_INLINE int
185 __NTH (__signbitl (long double __x))
187 __extension__ union { long double __l; long int __i[2]; } __u = { __l: __x };
188 return __u.__i[0] < 0;
191 # endif /* sparc64 */
193 # endif /* __USE_ISOC99 */
195 # if !defined __NO_MATH_INLINES && !__GNUC_PREREQ (3, 2)
197 __MATH_INLINE double
198 __NTH (sqrt (double __x))
200 register double __r;
201 __asm ("fsqrtd %1,%0" : "=f" (__r) : "f" (__x));
202 return __r;
205 __MATH_INLINE float
206 __NTH (sqrtf (float __x))
208 register float __r;
209 __asm ("fsqrts %1,%0" : "=f" (__r) : "f" (__x));
210 return __r;
213 # if __WORDSIZE == 64
214 __MATH_INLINE long double
215 __NTH (sqrtl (long double __x))
217 long double __r;
218 extern void _Qp_sqrt (long double *, __const__ long double *);
219 _Qp_sqrt (&__r, &__x);
220 return __r;
222 # elif !defined __NO_LONG_DOUBLE_MATH
223 __MATH_INLINE long double
224 sqrtl (long double __x) __THROW
226 extern long double _Q_sqrt (__const__ long double);
227 return _Q_sqrt (__x);
229 # endif /* sparc64 */
231 # endif /* !__NO_MATH_INLINES && !GCC 3.2+ */
233 /* This code is used internally in the GNU libc. */
234 # ifdef __LIBC_INTERNAL_MATH_INLINES
235 __MATH_INLINE double
236 __ieee754_sqrt (double __x)
238 register double __r;
239 __asm ("fsqrtd %1,%0" : "=f" (__r) : "f" (__x));
240 return __r;
243 __MATH_INLINE float
244 __ieee754_sqrtf (float __x)
246 register float __r;
247 __asm ("fsqrts %1,%0" : "=f" (__r) : "f" (__x));
248 return __r;
251 # if __WORDSIZE == 64
252 __MATH_INLINE long double
253 __ieee754_sqrtl (long double __x)
255 long double __r;
256 extern void _Qp_sqrt (long double *, __const__ long double *);
257 _Qp_sqrt(&__r, &__x);
258 return __r;
260 # elif !defined __NO_LONG_DOUBLE_MATH
261 __MATH_INLINE long double
262 __ieee754_sqrtl (long double __x)
264 extern long double _Q_sqrt (__const__ long double);
265 return _Q_sqrt (__x);
267 # endif /* sparc64 */
268 # endif /* __LIBC_INTERNAL_MATH_INLINES */
269 # endif /* gcc 2.8+ */
271 # ifdef __USE_ISOC99
273 # ifndef __NO_MATH_INLINES
275 __MATH_INLINE double __NTH (fdim (double __x, double __y));
276 __MATH_INLINE double
277 __NTH (fdim (double __x, double __y))
279 return __x <= __y ? 0 : __x - __y;
282 __MATH_INLINE float __NTH (fdimf (float __x, float __y));
283 __MATH_INLINE float
284 __NTH (fdimf (float __x, float __y))
286 return __x <= __y ? 0 : __x - __y;
289 # endif /* !__NO_MATH_INLINES */
290 # endif /* __USE_ISOC99 */
291 #endif /* !__NO_MATH_INLINES && __OPTIMIZE__ */
292 #endif /* __GNUC__ */