1 /* Inline math functions for SPARC.
2 Copyright (C) 1999, 2000, 2001, 2002, 2004, 2006
3 Free Software Foundation, Inc.
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."
26 #if defined __USE_ISOC99 && !__GNUC_PREREQ (3, 0)
28 # undef isgreaterequal
34 # define __unordered_v9cmp(x, y, op, qop) \
37 if (sizeof (x) == 4 && sizeof (y) == 4) \
39 float __x = (x); float __y = (y); \
40 __asm__ ("fcmps\t%%fcc3,%1,%2\n\tmov" op "\t%%fcc3,1,%0" \
41 : "=r" (__r) : "f" (__x), "f" (__y), "0" (0) : "cc"); \
43 else if (sizeof (x) <= 8 && sizeof (y) <= 8) \
45 double __x = (x); double __y = (y); \
46 __asm__ ("fcmpd\t%%fcc3,%1,%2\n\tmov" op "\t%%fcc3,1,%0" \
47 : "=r" (__r) : "f" (__x), "f" (__y), "0" (0) : "cc"); \
51 long double __x = (x); long double __y = (y); \
52 extern int _Qp_cmp (const long double *a, const long double *b); \
57 # define isgreater(x, y) __unordered_v9cmp(x, y, "g", _Qp_cmp (&__x, &__y) == 2)
58 # define isgreaterequal(x, y) __unordered_v9cmp(x, y, "ge", (_Qp_cmp (&__x, &__y) & 1) == 0)
59 # define isless(x, y) __unordered_v9cmp(x, y, "l", _Qp_cmp (&__x, &__y) == 1)
60 # define islessequal(x, y) __unordered_v9cmp(x, y, "le", (_Qp_cmp (&__x, &__y) & 2) == 0)
61 # define islessgreater(x, y) __unordered_v9cmp(x, y, "lg", ((_Qp_cmp (&__x, &__y) + 1) & 2) != 0)
62 # define isunordered(x, y) __unordered_v9cmp(x, y, "u", _Qp_cmp (&__x, &__y) == 3)
64 #endif /* __USE_ISOC99 */
66 #if (!defined __NO_MATH_INLINES || defined __LIBC_INTERNAL_MATH_INLINES) && defined __OPTIMIZE__
69 # define __MATH_INLINE __inline
71 # define __MATH_INLINE __extern_inline
72 # endif /* __cplusplus */
74 /* The gcc, version 2.7 or below, has problems with all this inlining
75 code. So disable it for this version of the compiler. */
76 # if __GNUC_PREREQ (2, 8)
80 /* Test for negative number. Used in the signbit() macro. */
82 __NTH (__signbitf (float __x
))
84 __extension__
union { float __f
; int __i
; } __u
= { __f
: __x
};
89 __NTH (__signbit (double __x
))
91 __extension__
union { double __d
; long int __i
; } __u
= { __d
: __x
};
96 __NTH (__signbitl (long double __x
))
98 __extension__
union { long double __l
; long int __i
[2]; } __u
= { __l
: __x
};
99 return __u
.__i
[0] < 0;
102 # endif /* __USE_ISOC99 */
104 # if !defined __NO_MATH_INLINES && !__GNUC_PREREQ (3, 2)
107 __NTH (sqrt (double __x
))
110 __asm__ ("fsqrtd %1,%0" : "=f" (__r
) : "f" (__x
));
115 __NTH (sqrtf (float __x
))
118 __asm__ ("fsqrts %1,%0" : "=f" (__r
) : "f" (__x
));
122 __MATH_INLINE
long double
123 __NTH (sqrtl (long double __x
))
126 extern void _Qp_sqrt (long double *, __const__
long double *);
127 _Qp_sqrt (&__r
, &__x
);
130 # elif !defined __NO_LONG_DOUBLE_MATH
131 __MATH_INLINE
long double
132 sqrtl (long double __x
) __THROW
134 extern long double _Q_sqrt (__const__
long double);
135 return _Q_sqrt (__x
);
138 # endif /* !__NO_MATH_INLINES && !GCC 3.2+ */
140 /* This code is used internally in the GNU libc. */
141 # ifdef __LIBC_INTERNAL_MATH_INLINES
143 __ieee754_sqrt (double __x
)
146 __asm__ ("fsqrtd %1,%0" : "=f" (__r
) : "f" (__x
));
151 __ieee754_sqrtf (float __x
)
154 __asm__ ("fsqrts %1,%0" : "=f" (__r
) : "f" (__x
));
158 __MATH_INLINE
long double
159 __ieee754_sqrtl (long double __x
)
162 extern void _Qp_sqrt (long double *, __const__
long double *);
163 _Qp_sqrt(&__r
, &__x
);
166 # elif !defined __NO_LONG_DOUBLE_MATH
167 __MATH_INLINE
long double
168 __ieee754_sqrtl (long double __x
)
170 extern long double _Q_sqrt (__const__
long double);
171 return _Q_sqrt (__x
);
173 # endif /* __LIBC_INTERNAL_MATH_INLINES */
174 # endif /* gcc 2.8+ */
178 # ifndef __NO_MATH_INLINES
180 __MATH_INLINE
double __NTH (fdim (double __x
, double __y
));
182 __NTH (fdim (double __x
, double __y
))
184 return __x
<= __y
? 0 : __x
- __y
;
187 __MATH_INLINE
float __NTH (fdimf (float __x
, float __y
));
189 __NTH (fdimf (float __x
, float __y
))
191 return __x
<= __y
? 0 : __x
- __y
;
194 # endif /* !__NO_MATH_INLINES */
195 # endif /* __USE_ISOC99 */
196 #endif /* !__NO_MATH_INLINES && __OPTIMIZE__ */
197 #endif /* __GNUC__ */