1 /* Inline math functions for SPARC.
2 Copyright (C) 1999, 2000, 2001, 2002, 2004, 2006
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, see
19 <http://www.gnu.org/licenses/>. */
22 # error "Never use <bits/mathinline.h> directly; include <math.h> instead."
25 #include <bits/wordsize.h>
29 #if defined __USE_ISOC99 && !__GNUC_PREREQ (3, 0)
31 # undef isgreaterequal
39 # ifndef __NO_LONG_DOUBLE_MATH
41 # define __unordered_cmp(x, y) \
44 if (sizeof (x) == 4 && sizeof (y) == 4) \
46 float __x = (x); float __y = (y); \
47 __asm__ ("fcmps %1,%2; st %%fsr, %0" : "=m" (__r) : "f" (__x), \
50 else if (sizeof (x) <= 8 && sizeof (y) <= 8) \
52 double __x = (x); double __y = (y); \
53 __asm__ ("fcmpd\t%1,%2\n\tst\t%%fsr,%0" : "=m" (__r) : "f" (__x), \
58 long double __x = (x); long double __y = (y); \
59 extern int _Q_cmp (const long double a, const long double b); \
60 __r = _Q_cmp (__x, __y) << 10; \
66 # define __unordered_cmp(x, y) \
69 if (sizeof (x) == 4 && sizeof (y) == 4) \
71 float __x = (x); float __y = (y); \
72 __asm__ ("fcmps %1,%2; st %%fsr, %0" : "=m" (__r) : "f" (__x), \
77 double __x = (x); double __y = (y); \
78 __asm__ ("fcmpd\t%1,%2\n\tst\t%%fsr,%0" : "=m" (__r) : "f" (__x), \
85 # define isgreater(x, y) ((__unordered_cmp (x, y) & (3 << 10)) == (2 << 10))
86 # define isgreaterequal(x, y) ((__unordered_cmp (x, y) & (1 << 10)) == 0)
87 # define isless(x, y) ((__unordered_cmp (x, y) & (3 << 10)) == (1 << 10))
88 # define islessequal(x, y) ((__unordered_cmp (x, y) & (2 << 10)) == 0)
89 # define islessgreater(x, y) (((__unordered_cmp (x, y) + (1 << 10)) & (2 << 10)) != 0)
90 # define isunordered(x, y) ((__unordered_cmp (x, y) & (3 << 10)) == (3 << 10))
94 # define __unordered_v9cmp(x, y, op, qop) \
97 if (sizeof (x) == 4 && sizeof (y) == 4) \
99 float __x = (x); float __y = (y); \
100 __asm__ ("fcmps\t%%fcc3,%1,%2\n\tmov" op "\t%%fcc3,1,%0" \
101 : "=r" (__r) : "f" (__x), "f" (__y), "0" (0) : "cc"); \
103 else if (sizeof (x) <= 8 && sizeof (y) <= 8) \
105 double __x = (x); double __y = (y); \
106 __asm__ ("fcmpd\t%%fcc3,%1,%2\n\tmov" op "\t%%fcc3,1,%0" \
107 : "=r" (__r) : "f" (__x), "f" (__y), "0" (0) : "cc"); \
111 long double __x = (x); long double __y = (y); \
112 extern int _Qp_cmp (const long double *a, const long double *b); \
117 # define isgreater(x, y) __unordered_v9cmp(x, y, "g", _Qp_cmp (&__x, &__y) == 2)
118 # define isgreaterequal(x, y) __unordered_v9cmp(x, y, "ge", (_Qp_cmp (&__x, &__y) & 1) == 0)
119 # define isless(x, y) __unordered_v9cmp(x, y, "l", _Qp_cmp (&__x, &__y) == 1)
120 # define islessequal(x, y) __unordered_v9cmp(x, y, "le", (_Qp_cmp (&__x, &__y) & 2) == 0)
121 # define islessgreater(x, y) __unordered_v9cmp(x, y, "lg", ((_Qp_cmp (&__x, &__y) + 1) & 2) != 0)
122 # define isunordered(x, y) __unordered_v9cmp(x, y, "u", _Qp_cmp (&__x, &__y) == 3)
124 # endif /* sparc64 */
126 #endif /* __USE_ISOC99 */
128 #if (!defined __NO_MATH_INLINES || defined __LIBC_INTERNAL_MATH_INLINES) && defined __OPTIMIZE__
131 # define __MATH_INLINE __inline
133 # define __MATH_INLINE extern __inline
134 # endif /* __cplusplus */
136 /* The gcc, version 2.7 or below, has problems with all this inlining
137 code. So disable it for this version of the compiler. */
138 # if __GNUC_PREREQ (2, 8)
142 /* Test for negative number. Used in the signbit() macro. */
144 __NTH (__signbitf (float __x))
146 __extension__ union { float __f; int __i; } __u = { __f: __x };
150 # if __WORDSIZE == 32
153 __NTH (__signbit (double __x))
155 __extension__ union { double __d; int __i[2]; } __u = { __d: __x };
156 return __u.__i[0] < 0;
159 # ifndef __NO_LONG_DOUBLE_MATH
161 __NTH (__signbitl (long double __x))
163 __extension__ union { long double __l; int __i[4]; } __u = { __l: __x };
164 return __u.__i[0] < 0;
168 __NTH (__signbitl (long double __x))
170 return __signbit ((double)__x);
177 __NTH (__signbit (double __x))
179 __extension__ union { double __d; long int __i; } __u = { __d: __x };
184 __NTH (__signbitl (long double __x))
186 __extension__ union { long double __l; long int __i[2]; } __u = { __l: __x };
187 return __u.__i[0] < 0;
190 # endif /* sparc64 */
192 # endif /* __USE_ISOC99 */
194 # if !defined __NO_MATH_INLINES && !__GNUC_PREREQ (3, 2)
197 __NTH (sqrt (double __x))
200 __asm__ ("fsqrtd %1,%0" : "=f" (__r) : "f" (__x));
205 __NTH (sqrtf (float __x))
208 __asm__ ("fsqrts %1,%0" : "=f" (__r) : "f" (__x));
212 # if __WORDSIZE == 64
213 __MATH_INLINE long double
214 __NTH (sqrtl (long double __x))
217 extern void _Qp_sqrt (long double *, __const__ long double *);
218 _Qp_sqrt (&__r, &__x);
221 # elif !defined __NO_LONG_DOUBLE_MATH
222 __MATH_INLINE long double
223 sqrtl (long double __x) __THROW
225 extern long double _Q_sqrt (__const__ long double);
226 return _Q_sqrt (__x);
228 # endif /* sparc64 */
230 # endif /* !__NO_MATH_INLINES && !GCC 3.2+ */
232 /* This code is used internally in the GNU libc. */
233 # ifdef __LIBC_INTERNAL_MATH_INLINES
235 __ieee754_sqrt (double __x)
238 __asm__ ("fsqrtd %1,%0" : "=f" (__r) : "f" (__x));
243 __ieee754_sqrtf (float __x)
246 __asm__ ("fsqrts %1,%0" : "=f" (__r) : "f" (__x));
250 # if __WORDSIZE == 64
251 __MATH_INLINE long double
252 __ieee754_sqrtl (long double __x)
255 extern void _Qp_sqrt (long double *, __const__ long double *);
256 _Qp_sqrt(&__r, &__x);
259 # elif !defined __NO_LONG_DOUBLE_MATH
260 __MATH_INLINE long double
261 __ieee754_sqrtl (long double __x)
263 extern long double _Q_sqrt (__const__ long double);
264 return _Q_sqrt (__x);
266 # endif /* sparc64 */
267 # endif /* __LIBC_INTERNAL_MATH_INLINES */
268 # endif /* gcc 2.8+ */
272 # ifndef __NO_MATH_INLINES
274 __MATH_INLINE double __NTH (fdim (double __x, double __y));
276 __NTH (fdim (double __x, double __y))
278 return __x <= __y ? 0 : __x - __y;
281 __MATH_INLINE float __NTH (fdimf (float __x, float __y));
283 __NTH (fdimf (float __x, float __y))
285 return __x <= __y ? 0 : __x - __y;
288 # endif /* !__NO_MATH_INLINES */
289 # endif /* __USE_ISOC99 */
290 #endif /* !__NO_MATH_INLINES && __OPTIMIZE__ */
291 #endif /* __GNUC__ */