Update copyright dates with scripts/update-copyrights.
[glibc.git] / sysdeps / sparc / fpu / bits / mathinline.h
blob724086421403b2cdb8e54a60337558cc960cc933
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/>. */
20 #ifndef _MATH_H
21 # error "Never use <bits/mathinline.h> directly; include <math.h> instead."
22 #endif
24 #include <bits/wordsize.h>
26 #ifdef __GNUC__
28 #if defined __USE_ISOC99 && !__GNUC_PREREQ (3, 0)
29 # undef isgreater
30 # undef isgreaterequal
31 # undef isless
32 # undef islessequal
33 # undef islessgreater
34 # undef isunordered
36 # if __WORDSIZE == 32
38 # ifndef __NO_LONG_DOUBLE_MATH
40 # define __unordered_cmp(x, y) \
41 (__extension__ \
42 ({ unsigned __r; \
43 if (sizeof (x) == 4 && sizeof (y) == 4) \
44 { \
45 float __x = (x); float __y = (y); \
46 __asm__ ("fcmps %1,%2; st %%fsr, %0" : "=m" (__r) : "f" (__x), \
47 "f" (__y) : "cc"); \
48 } \
49 else if (sizeof (x) <= 8 && sizeof (y) <= 8) \
50 { \
51 double __x = (x); double __y = (y); \
52 __asm__ ("fcmpd\t%1,%2\n\tst\t%%fsr,%0" : "=m" (__r) : "f" (__x), \
53 "f" (__y) : "cc"); \
54 } \
55 else \
56 { \
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; \
60 } \
61 __r; }))
63 # else
65 # define __unordered_cmp(x, y) \
66 (__extension__ \
67 ({ unsigned __r; \
68 if (sizeof (x) == 4 && sizeof (y) == 4) \
69 { \
70 float __x = (x); float __y = (y); \
71 __asm__ ("fcmps %1,%2; st %%fsr, %0" : "=m" (__r) : "f" (__x), \
72 "f" (__y) : "cc"); \
73 } \
74 else \
75 { \
76 double __x = (x); double __y = (y); \
77 __asm__ ("fcmpd\t%1,%2\n\tst\t%%fsr,%0" : "=m" (__r) : "f" (__x), \
78 "f" (__y) : "cc"); \
79 } \
80 __r; }))
82 # endif
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))
91 # else /* sparc64 */
93 # define __unordered_v9cmp(x, y, op, qop) \
94 (__extension__ \
95 ({ unsigned __r; \
96 if (sizeof (x) == 4 && sizeof (y) == 4) \
97 { \
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"); \
108 else \
110 long double __x = (x); long double __y = (y); \
111 extern int _Qp_cmp (const long double *a, const long double *b); \
112 __r = qop; \
114 __r; }))
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
131 # else
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)
139 # ifdef __USE_ISOC99
141 /* Test for negative number. Used in the signbit() macro. */
142 __MATH_INLINE int
143 __NTH (__signbitf (float __x))
145 __extension__ union { float __f; int __i; } __u = { __f: __x };
146 return __u.__i < 0;
149 # if __WORDSIZE == 32
151 __MATH_INLINE int
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
159 __MATH_INLINE int
160 __NTH (__signbitl (long double __x))
162 __extension__ union { long double __l; int __i[4]; } __u = { __l: __x };
163 return __u.__i[0] < 0;
165 # else
166 __MATH_INLINE int
167 __NTH (__signbitl (long double __x))
169 return __signbit ((double)__x);
171 # endif
173 # else /* sparc64 */
175 __MATH_INLINE int
176 __NTH (__signbit (double __x))
178 __extension__ union { double __d; long int __i; } __u = { __d: __x };
179 return __u.__i < 0;
182 __MATH_INLINE int
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)
195 __MATH_INLINE double
196 __NTH (sqrt (double __x))
198 register double __r;
199 __asm ("fsqrtd %1,%0" : "=f" (__r) : "f" (__x));
200 return __r;
203 __MATH_INLINE float
204 __NTH (sqrtf (float __x))
206 register float __r;
207 __asm ("fsqrts %1,%0" : "=f" (__r) : "f" (__x));
208 return __r;
211 # if __WORDSIZE == 64
212 __MATH_INLINE long double
213 __NTH (sqrtl (long double __x))
215 long double __r;
216 extern void _Qp_sqrt (long double *, const long double *);
217 _Qp_sqrt (&__r, &__x);
218 return __r;
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
233 __MATH_INLINE double
234 __ieee754_sqrt (double __x)
236 register double __r;
237 __asm ("fsqrtd %1,%0" : "=f" (__r) : "f" (__x));
238 return __r;
241 __MATH_INLINE float
242 __ieee754_sqrtf (float __x)
244 register float __r;
245 __asm ("fsqrts %1,%0" : "=f" (__r) : "f" (__x));
246 return __r;
249 # if __WORDSIZE == 64
250 __MATH_INLINE long double
251 __ieee754_sqrtl (long double __x)
253 long double __r;
254 extern void _Qp_sqrt (long double *, const long double *);
255 _Qp_sqrt(&__r, &__x);
256 return __r;
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+ */
269 # ifdef __USE_ISOC99
271 # ifndef __NO_MATH_INLINES
273 __MATH_INLINE double __NTH (fdim (double __x, double __y));
274 __MATH_INLINE double
275 __NTH (fdim (double __x, double __y))
277 return __x <= __y ? 0 : __x - __y;
280 __MATH_INLINE float __NTH (fdimf (float __x, float __y));
281 __MATH_INLINE float
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__ */