sparc: cleanup sparc64 bits and unused soft-fp
[uclibc-ng.git] / libc / sysdeps / linux / sparc / bits / mathinline.h
blob1a63f23e9ab09745b7e11ab396519a7447927af7
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/>. */
21 #ifndef _MATH_H
22 # error "Never use <bits/mathinline.h> directly; include <math.h> instead."
23 #endif
25 #ifdef __GNUC__
27 #if defined __USE_ISOC99 && !__GNUC_PREREQ (3, 0)
28 # undef isgreater
29 # undef isgreaterequal
30 # undef isless
31 # undef islessequal
32 # undef islessgreater
33 # undef isunordered
35 # ifndef __NO_LONG_DOUBLE_MATH
37 # define __unordered_cmp(x, y) \
38 (__extension__ \
39 ({ unsigned __r; \
40 if (sizeof (x) == 4 && sizeof (y) == 4) \
41 { \
42 float __x = (x); float __y = (y); \
43 __asm__ ("fcmps %1,%2; st %%fsr, %0" : "=m" (__r) : "f" (__x), \
44 "f" (__y) : "cc"); \
45 } \
46 else if (sizeof (x) <= 8 && sizeof (y) <= 8) \
47 { \
48 double __x = (x); double __y = (y); \
49 __asm__ ("fcmpd\t%1,%2\n\tst\t%%fsr,%0" : "=m" (__r) : "f" (__x), \
50 "f" (__y) : "cc"); \
51 } \
52 else \
53 { \
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; \
57 } \
58 __r; }))
60 # else
62 # define __unordered_cmp(x, y) \
63 (__extension__ \
64 ({ unsigned __r; \
65 if (sizeof (x) == 4 && sizeof (y) == 4) \
66 { \
67 float __x = (x); float __y = (y); \
68 __asm__ ("fcmps %1,%2; st %%fsr, %0" : "=m" (__r) : "f" (__x), \
69 "f" (__y) : "cc"); \
70 } \
71 else \
72 { \
73 double __x = (x); double __y = (y); \
74 __asm__ ("fcmpd\t%1,%2\n\tst\t%%fsr,%0" : "=m" (__r) : "f" (__x), \
75 "f" (__y) : "cc"); \
76 } \
77 __r; }))
79 # endif
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__
92 # ifdef __cplusplus
93 # define __MATH_INLINE __inline
94 # else
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)
102 # ifdef __USE_ISOC99
104 /* Test for negative number. Used in the signbit() macro. */
105 __MATH_INLINE int
106 __NTH (__signbitf (float __x))
108 __extension__ union { float __f; int __i; } __u = { __f: __x };
109 return __u.__i < 0;
112 __MATH_INLINE int
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
120 __MATH_INLINE int
121 __NTH (__signbitl (long double __x))
123 __extension__ union { long double __l; int __i[4]; } __u = { __l: __x };
124 return __u.__i[0] < 0;
126 # else
127 __MATH_INLINE int
128 __NTH (__signbitl (long double __x))
130 return __signbit ((double)__x);
132 # endif
134 # endif /* __USE_ISOC99 */
136 # if !defined __NO_MATH_INLINES && !__GNUC_PREREQ (3, 2)
138 __MATH_INLINE double
139 __NTH (sqrt (double __x))
141 register double __r;
142 __asm__ ("fsqrtd %1,%0" : "=f" (__r) : "f" (__x));
143 return __r;
146 __MATH_INLINE float
147 __NTH (sqrtf (float __x))
149 register float __r;
150 __asm__ ("fsqrts %1,%0" : "=f" (__r) : "f" (__x));
151 return __r;
154 # endif /* !__NO_MATH_INLINES && !GCC 3.2+ */
156 /* This code is used internally in the GNU libc. */
157 # ifdef __LIBC_INTERNAL_MATH_INLINES
158 __MATH_INLINE double
159 __ieee754_sqrt (double __x)
161 register double __r;
162 __asm__ ("fsqrtd %1,%0" : "=f" (__r) : "f" (__x));
163 return __r;
166 __MATH_INLINE float
167 __ieee754_sqrtf (float __x)
169 register float __r;
170 __asm__ ("fsqrts %1,%0" : "=f" (__r) : "f" (__x));
171 return __r;
174 # endif /* __LIBC_INTERNAL_MATH_INLINES */
175 # endif /* gcc 2.8+ */
177 # ifdef __USE_ISOC99
179 # ifndef __NO_MATH_INLINES
181 __MATH_INLINE double __NTH (fdim (double __x, double __y));
182 __MATH_INLINE double
183 __NTH (fdim (double __x, double __y))
185 return __x <= __y ? 0 : __x - __y;
188 __MATH_INLINE float __NTH (fdimf (float __x, float __y));
189 __MATH_INLINE float
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__ */