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."
27 #if defined __USE_ISOC99 && !__GNUC_PREREQ (3, 0)
29 # undef isgreaterequal
35 # ifndef __NO_LONG_DOUBLE_MATH
37 # define __unordered_cmp(x, y) \
40 if (sizeof (x) == 4 && sizeof (y) == 4) \
42 float __x = (x); float __y = (y); \
43 __asm__ ("fcmps %1,%2; st %%fsr, %0" : "=m" (__r) : "f" (__x), \
46 else if (sizeof (x) <= 8 && sizeof (y) <= 8) \
48 double __x = (x); double __y = (y); \
49 __asm__ ("fcmpd\t%1,%2\n\tst\t%%fsr,%0" : "=m" (__r) : "f" (__x), \
54 long double __x = (x); long double __y = (y); \
55 extern int _Q_cmp (const long double a, const long double b); \
56 __r = _Q_cmp (__x, __y) << 10; \
62 # define __unordered_cmp(x, y) \
65 if (sizeof (x) == 4 && sizeof (y) == 4) \
67 float __x = (x); float __y = (y); \
68 __asm__ ("fcmps %1,%2; st %%fsr, %0" : "=m" (__r) : "f" (__x), \
73 double __x = (x); double __y = (y); \
74 __asm__ ("fcmpd\t%1,%2\n\tst\t%%fsr,%0" : "=m" (__r) : "f" (__x), \
81 # define isgreater(x, y) ((__unordered_cmp (x, y) & (3 << 10)) == (2 << 10))
82 # define isgreaterequal(x, y) ((__unordered_cmp (x, y) & (1 << 10)) == 0)
83 # define isless(x, y) ((__unordered_cmp (x, y) & (3 << 10)) == (1 << 10))
84 # define islessequal(x, y) ((__unordered_cmp (x, y) & (2 << 10)) == 0)
85 # define islessgreater(x, y) (((__unordered_cmp (x, y) + (1 << 10)) & (2 << 10)) != 0)
86 # define isunordered(x, y) ((__unordered_cmp (x, y) & (3 << 10)) == (3 << 10))
88 #endif /* __USE_ISOC99 */
90 #if (!defined __NO_MATH_INLINES || defined __LIBC_INTERNAL_MATH_INLINES) && defined __OPTIMIZE__
93 # define __MATH_INLINE __inline
95 # define __MATH_INLINE __extern_inline
96 # endif /* __cplusplus */
98 /* The gcc, version 2.7 or below, has problems with all this inlining
99 code. So disable it for this version of the compiler. */
100 # if __GNUC_PREREQ (2, 8)
104 /* Test for negative number. Used in the signbit() macro. */
106 __NTH (__signbitf (float __x
))
108 __extension__
union { float __f
; int __i
; } __u
= { __f
: __x
};
113 __NTH (__signbit (double __x
))
115 __extension__
union { double __d
; int __i
[2]; } __u
= { __d
: __x
};
116 return __u
.__i
[0] < 0;
119 # ifndef __NO_LONG_DOUBLE_MATH
121 __NTH (__signbitl (long double __x
))
123 __extension__
union { long double __l
; int __i
[4]; } __u
= { __l
: __x
};
124 return __u
.__i
[0] < 0;
128 __NTH (__signbitl (long double __x
))
130 return __signbit ((double)__x
);
134 # endif /* __USE_ISOC99 */
136 # if !defined __NO_MATH_INLINES && !__GNUC_PREREQ (3, 2)
139 __NTH (sqrt (double __x
))
142 __asm__ ("fsqrtd %1,%0" : "=f" (__r
) : "f" (__x
));
147 __NTH (sqrtf (float __x
))
150 __asm__ ("fsqrts %1,%0" : "=f" (__r
) : "f" (__x
));
154 # endif /* !__NO_MATH_INLINES && !GCC 3.2+ */
156 /* This code is used internally in the GNU libc. */
157 # ifdef __LIBC_INTERNAL_MATH_INLINES
159 __ieee754_sqrt (double __x
)
162 __asm__ ("fsqrtd %1,%0" : "=f" (__r
) : "f" (__x
));
167 __ieee754_sqrtf (float __x
)
170 __asm__ ("fsqrts %1,%0" : "=f" (__r
) : "f" (__x
));
174 # endif /* __LIBC_INTERNAL_MATH_INLINES */
175 # endif /* gcc 2.8+ */
179 # ifndef __NO_MATH_INLINES
181 __MATH_INLINE
double __NTH (fdim (double __x
, double __y
));
183 __NTH (fdim (double __x
, double __y
))
185 return __x
<= __y
? 0 : __x
- __y
;
188 __MATH_INLINE
float __NTH (fdimf (float __x
, float __y
));
190 __NTH (fdimf (float __x
, float __y
))
192 return __x
<= __y
? 0 : __x
- __y
;
195 # endif /* !__NO_MATH_INLINES */
196 # endif /* __USE_ISOC99 */
197 #endif /* !__NO_MATH_INLINES && __OPTIMIZE__ */
198 #endif /* __GNUC__ */