sparc64: add basic support
[uclibc-ng.git] / libc / sysdeps / linux / sparc64 / bits / mathinline.h
blob8bb35f6d863bd545881fe72a1c1ed96c59442db3
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/>. */
20 #ifndef _MATH_H
21 # error "Never use <bits/mathinline.h> directly; include <math.h> instead."
22 #endif
24 #ifdef __GNUC__
26 #if defined __USE_ISOC99 && !__GNUC_PREREQ (3, 0)
27 # undef isgreater
28 # undef isgreaterequal
29 # undef isless
30 # undef islessequal
31 # undef islessgreater
32 # undef isunordered
34 # define __unordered_v9cmp(x, y, op, qop) \
35 (__extension__ \
36 ({ unsigned __r; \
37 if (sizeof (x) == 4 && sizeof (y) == 4) \
38 { \
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"); \
42 } \
43 else if (sizeof (x) <= 8 && sizeof (y) <= 8) \
44 { \
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"); \
48 } \
49 else \
50 { \
51 long double __x = (x); long double __y = (y); \
52 extern int _Qp_cmp (const long double *a, const long double *b); \
53 __r = qop; \
54 } \
55 __r; }))
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__
68 # ifdef __cplusplus
69 # define __MATH_INLINE __inline
70 # else
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)
78 # ifdef __USE_ISOC99
80 /* Test for negative number. Used in the signbit() macro. */
81 __MATH_INLINE int
82 __NTH (__signbitf (float __x))
84 __extension__ union { float __f; int __i; } __u = { __f: __x };
85 return __u.__i < 0;
88 __MATH_INLINE int
89 __NTH (__signbit (double __x))
91 __extension__ union { double __d; long int __i; } __u = { __d: __x };
92 return __u.__i < 0;
95 __MATH_INLINE int
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)
106 __MATH_INLINE double
107 __NTH (sqrt (double __x))
109 register double __r;
110 __asm__ ("fsqrtd %1,%0" : "=f" (__r) : "f" (__x));
111 return __r;
114 __MATH_INLINE float
115 __NTH (sqrtf (float __x))
117 register float __r;
118 __asm__ ("fsqrts %1,%0" : "=f" (__r) : "f" (__x));
119 return __r;
122 __MATH_INLINE long double
123 __NTH (sqrtl (long double __x))
125 long double __r;
126 extern void _Qp_sqrt (long double *, __const__ long double *);
127 _Qp_sqrt (&__r, &__x);
128 return __r;
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
142 __MATH_INLINE double
143 __ieee754_sqrt (double __x)
145 register double __r;
146 __asm__ ("fsqrtd %1,%0" : "=f" (__r) : "f" (__x));
147 return __r;
150 __MATH_INLINE float
151 __ieee754_sqrtf (float __x)
153 register float __r;
154 __asm__ ("fsqrts %1,%0" : "=f" (__r) : "f" (__x));
155 return __r;
158 __MATH_INLINE long double
159 __ieee754_sqrtl (long double __x)
161 long double __r;
162 extern void _Qp_sqrt (long double *, __const__ long double *);
163 _Qp_sqrt(&__r, &__x);
164 return __r;
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+ */
176 # ifdef __USE_ISOC99
178 # ifndef __NO_MATH_INLINES
180 __MATH_INLINE double __NTH (fdim (double __x, double __y));
181 __MATH_INLINE double
182 __NTH (fdim (double __x, double __y))
184 return __x <= __y ? 0 : __x - __y;
187 __MATH_INLINE float __NTH (fdimf (float __x, float __y));
188 __MATH_INLINE float
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__ */