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>.
5
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.
10
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.
15
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/>. */
19
20 #ifndef _MATH_H
21 # error "Never use <bits/mathinline.h> directly; include <math.h> instead."
22 #endif
23
24 #ifdef __GNUC__
25
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
33
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; }))
56
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)
63
64 #endif /* __USE_ISOC99 */
65
66 #if (!defined __NO_MATH_INLINES || defined __LIBC_INTERNAL_MATH_INLINES) && defined __OPTIMIZE__
67
68 # ifdef __cplusplus
69 # define __MATH_INLINE __inline
70 # else
71 # define __MATH_INLINE __extern_inline
72 # endif /* __cplusplus */
73
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)
77
78 # ifdef __USE_ISOC99
79
80 /* Test for negative number. Used in the signbit() macro. */
81 __MATH_INLINE int
__NTH(__signbitf (float __x))82 __NTH (__signbitf (float __x))
83 {
84 __extension__ union { float __f; int __i; } __u = { __f: __x };
85 return __u.__i < 0;
86 }
87
88 __MATH_INLINE int
__NTH(__signbit (double __x))89 __NTH (__signbit (double __x))
90 {
91 __extension__ union { double __d; long int __i; } __u = { __d: __x };
92 return __u.__i < 0;
93 }
94
95 __MATH_INLINE int
__NTH(__signbitl (long double __x))96 __NTH (__signbitl (long double __x))
97 {
98 __extension__ union { long double __l; long int __i[2]; } __u = { __l: __x };
99 return __u.__i[0] < 0;
100 }
101
102 # endif /* __USE_ISOC99 */
103
104 # if !defined __NO_MATH_INLINES && !__GNUC_PREREQ (3, 2)
105
106 __MATH_INLINE double
__NTH(sqrt (double __x))107 __NTH (sqrt (double __x))
108 {
109 register double __r;
110 __asm__ ("fsqrtd %1,%0" : "=f" (__r) : "f" (__x));
111 return __r;
112 }
113
114 __MATH_INLINE float
__NTH(sqrtf (float __x))115 __NTH (sqrtf (float __x))
116 {
117 register float __r;
118 __asm__ ("fsqrts %1,%0" : "=f" (__r) : "f" (__x));
119 return __r;
120 }
121
122 __MATH_INLINE long double
__NTH(sqrtl (long double __x))123 __NTH (sqrtl (long double __x))
124 {
125 long double __r;
126 extern void _Qp_sqrt (long double *, __const__ long double *);
127 _Qp_sqrt (&__r, &__x);
128 return __r;
129 }
130 # elif !defined __NO_LONG_DOUBLE_MATH
131 __MATH_INLINE long double
sqrtl(long double __x)132 sqrtl (long double __x) __THROW
133 {
134 extern long double _Q_sqrt (__const__ long double);
135 return _Q_sqrt (__x);
136 }
137
138 # endif /* !__NO_MATH_INLINES && !GCC 3.2+ */
139
140 /* This code is used internally in the GNU libc. */
141 # ifdef __LIBC_INTERNAL_MATH_INLINES
142 __MATH_INLINE double
__ieee754_sqrt(double __x)143 __ieee754_sqrt (double __x)
144 {
145 register double __r;
146 __asm__ ("fsqrtd %1,%0" : "=f" (__r) : "f" (__x));
147 return __r;
148 }
149
150 __MATH_INLINE float
__ieee754_sqrtf(float __x)151 __ieee754_sqrtf (float __x)
152 {
153 register float __r;
154 __asm__ ("fsqrts %1,%0" : "=f" (__r) : "f" (__x));
155 return __r;
156 }
157
158 __MATH_INLINE long double
__ieee754_sqrtl(long double __x)159 __ieee754_sqrtl (long double __x)
160 {
161 long double __r;
162 extern void _Qp_sqrt (long double *, __const__ long double *);
163 _Qp_sqrt(&__r, &__x);
164 return __r;
165 }
166 # elif !defined __NO_LONG_DOUBLE_MATH
167 __MATH_INLINE long double
__ieee754_sqrtl(long double __x)168 __ieee754_sqrtl (long double __x)
169 {
170 extern long double _Q_sqrt (__const__ long double);
171 return _Q_sqrt (__x);
172 }
173 # endif /* __LIBC_INTERNAL_MATH_INLINES */
174 # endif /* gcc 2.8+ */
175
176 # ifdef __USE_ISOC99
177
178 # ifndef __NO_MATH_INLINES
179
180 __MATH_INLINE double __NTH (fdim (double __x, double __y));
181 __MATH_INLINE double
__NTH(fdim (double __x,double __y))182 __NTH (fdim (double __x, double __y))
183 {
184 return __x <= __y ? 0 : __x - __y;
185 }
186
187 __MATH_INLINE float __NTH (fdimf (float __x, float __y));
188 __MATH_INLINE float
__NTH(fdimf (float __x,float __y))189 __NTH (fdimf (float __x, float __y))
190 {
191 return __x <= __y ? 0 : __x - __y;
192 }
193
194 # endif /* !__NO_MATH_INLINES */
195 # endif /* __USE_ISOC99 */
196 #endif /* !__NO_MATH_INLINES && __OPTIMIZE__ */
197 #endif /* __GNUC__ */
198