1 /* Inline math functions for SPARC.
2 Copyright (C) 1999, 2000, 2001, 2002, 2004 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, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
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 # define __unordered_cmp(x, y) \
42 if (sizeof(x) == 4 && sizeof(y) == 4) \
44 float __x = (x); float __y = (y); \
45 __asm__("fcmps %1,%2; st %%fsr, %0" : "=m" (__r) : "f" (__x), \
50 double __x = (x); double __y = (y); \
51 __asm__("fcmpd\t%1,%2\n\tst\t%%fsr,%0" : "=m" (__r) : "f" (__x), \
56 # define isgreater(x, y) ((__unordered_cmp (x, y) & (3 << 10)) == (2 << 10))
57 # define isgreaterequal(x, y) ((__unordered_cmp (x, y) & (1 << 10)) == 0)
58 # define isless(x, y) ((__unordered_cmp (x, y) & (3 << 10)) == (1 << 10))
59 # define islessequal(x, y) ((__unordered_cmp (x, y) & (2 << 10)) == 0)
60 # define islessgreater(x, y) (((__unordered_cmp (x, y) + (1 << 10)) & (2 << 10)) != 0)
61 # define isunordered(x, y) ((__unordered_cmp (x, y) & (3 << 10)) == (3 << 10))
65 # define __unordered_v9cmp(x, y, op, qop) \
68 if (sizeof(x) == 4 && sizeof(y) == 4) \
70 float __x = (x); float __y = (y); \
71 __asm__("fcmps\t%%fcc3,%1,%2\n\tmov" op "\t%%fcc3,1,%0" \
72 : "=r" (__r) : "f" (__x), "f" (__y), "0" (0) : "cc"); \
74 else if (sizeof(x) <= 8 && sizeof(y) <= 8) \
76 double __x = (x); double __y = (y); \
77 __asm__("fcmpd\t%%fcc3,%1,%2\n\tmov" op "\t%%fcc3,1,%0" \
78 : "=r" (__r) : "f" (__x), "f" (__y), "0" (0) : "cc"); \
82 long double __x = (x); long double __y = (y); \
83 extern int _Qp_cmp(const long double *a, const long double *b); \
88 # define isgreater(x, y) __unordered_v9cmp(x, y, "g", _Qp_cmp (&__x, &__y) == 2)
89 # define isgreaterequal(x, y) __unordered_v9cmp(x, y, "ge", (_Qp_cmp (&__x, &__y) & 1) == 0)
90 # define isless(x, y) __unordered_v9cmp(x, y, "l", _Qp_cmp (&__x, &__y) == 1)
91 # define islessequal(x, y) __unordered_v9cmp(x, y, "le", (_Qp_cmp (&__x, &__y) & 2) == 0)
92 # define islessgreater(x, y) __unordered_v9cmp(x, y, "lg", ((_Qp_cmp (&__x, &__y) + 1) & 2) != 0)
93 # define isunordered(x, y) __unordered_v9cmp(x, y, "u", _Qp_cmp (&__x, &__y) == 3)
97 #endif /* __USE_ISOC99 */
99 #if (!defined __NO_MATH_INLINES || defined __LIBC_INTERNAL_MATH_INLINES) && defined __OPTIMIZE__
102 # define __MATH_INLINE __inline
104 # define __MATH_INLINE extern __inline
105 # endif /* __cplusplus */
107 /* The gcc, version 2.7 or below, has problems with all this inlining
108 code. So disable it for this version of the compiler. */
109 # if __GNUC_PREREQ (2, 8)
113 /* Test for negative number. Used in the signbit() macro. */
115 __NTH (__signbitf (float __x
))
117 __extension__
union { float __f
; int __i
; } __u
= { __f
: __x
};
121 # if __WORDSIZE == 32
124 __NTH (__signbit (double __x
))
126 __extension__
union { double __d
; int __i
[2]; } __u
= { __d
: __x
};
127 return __u
.__i
[0] < 0;
131 __NTH (__signbitl (long double __x
))
133 return __signbit ((double)__x
);
139 __NTH (__signbit (double __x
))
141 __extension__
union { double __d
; long int __i
; } __u
= { __d
: __x
};
146 __NTH (__signbitl (long double __x
))
148 __extension__
union { long double __l
; long int __i
[2]; } __u
= { __l
: __x
};
149 return __u
.__i
[0] < 0;
152 # endif /* sparc64 */
154 # endif /* __USE_ISOC99 */
156 # if !defined __NO_MATH_INLINES && !__GNUC_PREREQ (3, 2)
159 __NTH (sqrt (double __x
))
162 __asm ("fsqrtd %1,%0" : "=f" (__r
) : "f" (__x
));
167 __NTH (sqrtf (float __x
))
170 __asm ("fsqrts %1,%0" : "=f" (__r
) : "f" (__x
));
174 # if __WORDSIZE == 64
175 __MATH_INLINE
long double
176 __NTH (sqrtl (long double __x
))
179 extern void _Qp_sqrt (long double *, __const__
long double *);
180 _Qp_sqrt (&__r
, &__x
);
183 # endif /* sparc64 */
185 # endif /* !__NO_MATH_INLINES && !GCC 3.2+ */
187 /* This code is used internally in the GNU libc. */
188 # ifdef __LIBC_INTERNAL_MATH_INLINES
190 __ieee754_sqrt (double __x
)
193 __asm ("fsqrtd %1,%0" : "=f" (__r
) : "f" (__x
));
198 __ieee754_sqrtf (float __x
)
201 __asm ("fsqrts %1,%0" : "=f" (__r
) : "f" (__x
));
205 # if __WORDSIZE == 64
206 __MATH_INLINE
long double
207 __ieee754_sqrtl (long double __x
)
210 extern void _Qp_sqrt (long double *, __const__
long double *);
211 _Qp_sqrt(&__r
, &__x
);
214 # endif /* sparc64 */
215 # endif /* __LIBC_INTERNAL_MATH_INLINES */
216 # endif /* gcc 2.8+ */
220 # ifndef __NO_MATH_INLINES
222 __MATH_INLINE
double __NTH (fdim (double __x
, double __y
));
224 __NTH (fdim (double __x
, double __y
))
226 return __x
<= __y
? 0 : __x
- __y
;
229 __MATH_INLINE
float __NTH (fdimf (float __x
, float __y
));
231 __NTH (fdimf (float __x
, float __y
))
233 return __x
<= __y
? 0 : __x
- __y
;
236 # endif /* !__NO_MATH_INLINES */
237 # endif /* __USE_ISOC99 */
238 #endif /* !__NO_MATH_INLINES && __OPTIMIZE__ */
239 #endif /* __GNUC__ */