1 /* Inline math functions for SPARC.
2 Copyright (C) 1999-2015 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Jakub Jelinek <jakub@redhat.com>.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
21 # error "Never use <bits/mathinline.h> directly; include <math.h> instead."
24 #include <bits/wordsize.h>
28 #if defined __USE_ISOC99 && !__GNUC_PREREQ (3, 0)
30 # undef isgreaterequal
38 # ifndef __NO_LONG_DOUBLE_MATH
40 # define __unordered_cmp(x, y) \
43 if (sizeof (x) == 4 && sizeof (y) == 4) \
45 float __x = (x); float __y = (y); \
46 __asm__ ("fcmps %1,%2; st %%fsr, %0" : "=m" (__r) : "f" (__x), \
49 else if (sizeof (x) <= 8 && sizeof (y) <= 8) \
51 double __x = (x); double __y = (y); \
52 __asm__ ("fcmpd\t%1,%2\n\tst\t%%fsr,%0" : "=m" (__r) : "f" (__x), \
57 long double __x = (x); long double __y = (y); \
58 extern int _Q_cmp (const long double a, const long double b); \
59 __r = _Q_cmp (__x, __y) << 10; \
65 # define __unordered_cmp(x, y) \
68 if (sizeof (x) == 4 && sizeof (y) == 4) \
70 float __x = (x); float __y = (y); \
71 __asm__ ("fcmps %1,%2; st %%fsr, %0" : "=m" (__r) : "f" (__x), \
76 double __x = (x); double __y = (y); \
77 __asm__ ("fcmpd\t%1,%2\n\tst\t%%fsr,%0" : "=m" (__r) : "f" (__x), \
84 # define isgreater(x, y) ((__unordered_cmp (x, y) & (3 << 10)) == (2 << 10))
85 # define isgreaterequal(x, y) ((__unordered_cmp (x, y) & (1 << 10)) == 0)
86 # define isless(x, y) ((__unordered_cmp (x, y) & (3 << 10)) == (1 << 10))
87 # define islessequal(x, y) ((__unordered_cmp (x, y) & (2 << 10)) == 0)
88 # define islessgreater(x, y) (((__unordered_cmp (x, y) + (1 << 10)) & (2 << 10)) != 0)
89 # define isunordered(x, y) ((__unordered_cmp (x, y) & (3 << 10)) == (3 << 10))
93 # define __unordered_v9cmp(x, y, op, qop) \
96 if (sizeof (x) == 4 && sizeof (y) == 4) \
98 float __x = (x); float __y = (y); \
99 __asm__ ("fcmps\t%%fcc3,%1,%2\n\tmov" op "\t%%fcc3,1,%0" \
100 : "=r" (__r) : "f" (__x), "f" (__y), "0" (0) : "cc"); \
102 else if (sizeof (x) <= 8 && sizeof (y) <= 8) \
104 double __x = (x); double __y = (y); \
105 __asm__ ("fcmpd\t%%fcc3,%1,%2\n\tmov" op "\t%%fcc3,1,%0" \
106 : "=r" (__r) : "f" (__x), "f" (__y), "0" (0) : "cc"); \
110 long double __x = (x); long double __y = (y); \
111 extern int _Qp_cmp (const long double *a, const long double *b); \
116 # define isgreater(x, y) __unordered_v9cmp(x, y, "g", _Qp_cmp (&__x, &__y) == 2)
117 # define isgreaterequal(x, y) __unordered_v9cmp(x, y, "ge", (_Qp_cmp (&__x, &__y) & 1) == 0)
118 # define isless(x, y) __unordered_v9cmp(x, y, "l", _Qp_cmp (&__x, &__y) == 1)
119 # define islessequal(x, y) __unordered_v9cmp(x, y, "le", (_Qp_cmp (&__x, &__y) & 2) == 0)
120 # define islessgreater(x, y) __unordered_v9cmp(x, y, "lg", ((_Qp_cmp (&__x, &__y) + 1) & 2) != 0)
121 # define isunordered(x, y) __unordered_v9cmp(x, y, "u", _Qp_cmp (&__x, &__y) == 3)
123 # endif /* sparc64 */
125 #endif /* __USE_ISOC99 */
127 #if (!defined __NO_MATH_INLINES || defined __LIBC_INTERNAL_MATH_INLINES) && defined __OPTIMIZE__
129 # ifndef __extern_inline
130 # define __MATH_INLINE __inline
132 # define __MATH_INLINE __extern_inline
133 # endif /* __cplusplus */
135 /* The gcc, version 2.7 or below, has problems with all this inlining
136 code. So disable it for this version of the compiler. */
137 # if __GNUC_PREREQ (2, 8)
141 /* Test for negative number. Used in the signbit() macro. */
143 __NTH (__signbitf (float __x
))
145 __extension__
union { float __f
; int __i
; } __u
= { __f
: __x
};
149 # if __WORDSIZE == 32
152 __NTH (__signbit (double __x
))
154 __extension__
union { double __d
; int __i
[2]; } __u
= { __d
: __x
};
155 return __u
.__i
[0] < 0;
158 # ifndef __NO_LONG_DOUBLE_MATH
160 __NTH (__signbitl (long double __x
))
162 __extension__
union { long double __l
; int __i
[4]; } __u
= { __l
: __x
};
163 return __u
.__i
[0] < 0;
167 __NTH (__signbitl (long double __x
))
169 return __signbit ((double)__x
);
176 __NTH (__signbit (double __x
))
178 __extension__
union { double __d
; long int __i
; } __u
= { __d
: __x
};
183 __NTH (__signbitl (long double __x
))
185 __extension__
union { long double __l
; long int __i
[2]; } __u
= { __l
: __x
};
186 return __u
.__i
[0] < 0;
189 # endif /* sparc64 */
191 # endif /* __USE_ISOC99 */
193 # if !defined __NO_MATH_INLINES && !__GNUC_PREREQ (3, 2)
196 __NTH (sqrt (double __x
))
199 __asm ("fsqrtd %1,%0" : "=f" (__r
) : "f" (__x
));
204 __NTH (sqrtf (float __x
))
207 __asm ("fsqrts %1,%0" : "=f" (__r
) : "f" (__x
));
211 # if __WORDSIZE == 64
212 __MATH_INLINE
long double
213 __NTH (sqrtl (long double __x
))
216 extern void _Qp_sqrt (long double *, const long double *);
217 _Qp_sqrt (&__r
, &__x
);
220 # elif !defined __NO_LONG_DOUBLE_MATH
221 __MATH_INLINE
long double
222 sqrtl (long double __x
) __THROW
224 extern long double _Q_sqrt (const long double);
225 return _Q_sqrt (__x
);
227 # endif /* sparc64 */
229 # endif /* !__NO_MATH_INLINES && !GCC 3.2+ */
231 /* This code is used internally in the GNU libc. */
232 # ifdef __LIBC_INTERNAL_MATH_INLINES
234 __ieee754_sqrt (double __x
)
237 __asm ("fsqrtd %1,%0" : "=f" (__r
) : "f" (__x
));
242 __ieee754_sqrtf (float __x
)
245 __asm ("fsqrts %1,%0" : "=f" (__r
) : "f" (__x
));
249 # if __WORDSIZE == 64
250 __MATH_INLINE
long double
251 __ieee754_sqrtl (long double __x
)
254 extern void _Qp_sqrt (long double *, const long double *);
255 _Qp_sqrt(&__r
, &__x
);
258 # elif !defined __NO_LONG_DOUBLE_MATH
259 __MATH_INLINE
long double
260 __ieee754_sqrtl (long double __x
)
262 extern long double _Q_sqrt (const long double);
263 return _Q_sqrt (__x
);
265 # endif /* sparc64 */
266 # endif /* __LIBC_INTERNAL_MATH_INLINES */
267 # endif /* gcc 2.8+ */
271 # ifndef __NO_MATH_INLINES
273 __MATH_INLINE
double __NTH (fdim (double __x
, double __y
));
275 __NTH (fdim (double __x
, double __y
))
277 return __x
<= __y
? 0 : __x
- __y
;
280 __MATH_INLINE
float __NTH (fdimf (float __x
, float __y
));
282 __NTH (fdimf (float __x
, float __y
))
284 return __x
<= __y
? 0 : __x
- __y
;
287 # endif /* !__NO_MATH_INLINES */
288 # endif /* __USE_ISOC99 */
289 #endif /* !__NO_MATH_INLINES && __OPTIMIZE__ */
290 #endif /* __GNUC__ */