1 /* Inline math functions for SPARC.
2 Copyright (C) 1999, 2000, 2001, 2002, 2004, 2006, 2007, 2012
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
23 # error "Never use <bits/mathinline.h> directly; include <math.h> instead."
26 #include <bits/wordsize.h>
30 #if defined __USE_ISOC99 && !__GNUC_PREREQ (3, 0)
32 # undef isgreaterequal
40 # ifndef __NO_LONG_DOUBLE_MATH
42 # define __unordered_cmp(x, y) \
45 if (sizeof (x) == 4 && sizeof (y) == 4) \
47 float __x = (x); float __y = (y); \
48 __asm__ ("fcmps %1,%2; st %%fsr, %0" : "=m" (__r) : "f" (__x), \
51 else if (sizeof (x) <= 8 && sizeof (y) <= 8) \
53 double __x = (x); double __y = (y); \
54 __asm__ ("fcmpd\t%1,%2\n\tst\t%%fsr,%0" : "=m" (__r) : "f" (__x), \
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; \
67 # define __unordered_cmp(x, y) \
70 if (sizeof (x) == 4 && sizeof (y) == 4) \
72 float __x = (x); float __y = (y); \
73 __asm__ ("fcmps %1,%2; st %%fsr, %0" : "=m" (__r) : "f" (__x), \
78 double __x = (x); double __y = (y); \
79 __asm__ ("fcmpd\t%1,%2\n\tst\t%%fsr,%0" : "=m" (__r) : "f" (__x), \
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))
95 # define __unordered_v9cmp(x, y, op, qop) \
98 if (sizeof (x) == 4 && sizeof (y) == 4) \
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"); \
112 long double __x = (x); long double __y = (y); \
113 extern int _Qp_cmp (const long double *a, const long double *b); \
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
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)
143 /* Test for negative number. Used in the signbit() macro. */
145 __NTH (__signbitf (float __x))
147 __extension__ union { float __f; int __i; } __u = { __f: __x };
151 # if __WORDSIZE == 32
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
162 __NTH (__signbitl (long double __x))
164 __extension__ union { long double __l; int __i[4]; } __u = { __l: __x };
165 return __u.__i[0] < 0;
169 __NTH (__signbitl (long double __x))
171 return __signbit ((double)__x);
178 __NTH (__signbit (double __x))
180 __extension__ union { double __d; long int __i; } __u = { __d: __x };
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)
198 __NTH (sqrt (double __x))
201 __asm ("fsqrtd %1,%0" : "=f" (__r) : "f" (__x));
206 __NTH (sqrtf (float __x))
209 __asm ("fsqrts %1,%0" : "=f" (__r) : "f" (__x));
213 # if __WORDSIZE == 64
214 __MATH_INLINE long double
215 __NTH (sqrtl (long double __x))
218 extern void _Qp_sqrt (long double *, const long double *);
219 _Qp_sqrt (&__r, &__x);
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
236 __ieee754_sqrt (double __x)
239 __asm ("fsqrtd %1,%0" : "=f" (__r) : "f" (__x));
244 __ieee754_sqrtf (float __x)
247 __asm ("fsqrts %1,%0" : "=f" (__r) : "f" (__x));
251 # if __WORDSIZE == 64
252 __MATH_INLINE long double
253 __ieee754_sqrtl (long double __x)
256 extern void _Qp_sqrt (long double *, const long double *);
257 _Qp_sqrt(&__r, &__x);
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+ */
273 # ifndef __NO_MATH_INLINES
275 __MATH_INLINE double __NTH (fdim (double __x, double __y));
277 __NTH (fdim (double __x, double __y))
279 return __x <= __y ? 0 : __x - __y;
282 __MATH_INLINE float __NTH (fdimf (float __x, float __y));
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__ */