]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/sparc/fpu/bits/mathinline.h
Simplify C99 isgreater macros
[thirdparty/glibc.git] / sysdeps / sparc / fpu / bits / mathinline.h
1 /* Inline math functions for SPARC.
2 Copyright (C) 1999-2017 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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 #include <bits/wordsize.h>
25
26 #ifdef __GNUC__
27
28 #if (!defined __NO_MATH_INLINES || defined __LIBC_INTERNAL_MATH_INLINES) && defined __OPTIMIZE__
29
30 # ifndef __extern_inline
31 # define __MATH_INLINE __inline
32 # else
33 # define __MATH_INLINE __extern_inline
34 # endif /* __cplusplus */
35
36 /* The gcc, version 2.7 or below, has problems with all this inlining
37 code. So disable it for this version of the compiler. */
38 # if __GNUC_PREREQ (2, 8)
39
40 # ifdef __USE_ISOC99
41
42 /* Test for negative number. Used in the signbit() macro. */
43 __MATH_INLINE int
44 __NTH (__signbitf (float __x))
45 {
46 __extension__ union { float __f; int __i; } __u = { __f: __x };
47 return __u.__i < 0;
48 }
49
50 # if __WORDSIZE == 32
51
52 __MATH_INLINE int
53 __NTH (__signbit (double __x))
54 {
55 __extension__ union { double __d; int __i[2]; } __u = { __d: __x };
56 return __u.__i[0] < 0;
57 }
58
59 # ifndef __NO_LONG_DOUBLE_MATH
60 __MATH_INLINE int
61 __NTH (__signbitl (long double __x))
62 {
63 __extension__ union { long double __l; int __i[4]; } __u = { __l: __x };
64 return __u.__i[0] < 0;
65 }
66 # else
67 __MATH_INLINE int
68 __NTH (__signbitl (long double __x))
69 {
70 return __signbit ((double)__x);
71 }
72 # endif
73
74 # else /* sparc64 */
75
76 __MATH_INLINE int
77 __NTH (__signbit (double __x))
78 {
79 __extension__ union { double __d; long int __i; } __u = { __d: __x };
80 return __u.__i < 0;
81 }
82
83 __MATH_INLINE int
84 __NTH (__signbitl (long double __x))
85 {
86 __extension__ union { long double __l; long int __i[2]; } __u = { __l: __x };
87 return __u.__i[0] < 0;
88 }
89
90 # endif /* sparc64 */
91
92 # endif /* __USE_ISOC99 */
93
94 # if !defined __NO_MATH_INLINES && !__GNUC_PREREQ (3, 2)
95
96 __MATH_INLINE double
97 __NTH (sqrt (double __x))
98 {
99 register double __r;
100 __asm ("fsqrtd %1,%0" : "=f" (__r) : "f" (__x));
101 return __r;
102 }
103
104 __MATH_INLINE float
105 __NTH (sqrtf (float __x))
106 {
107 register float __r;
108 __asm ("fsqrts %1,%0" : "=f" (__r) : "f" (__x));
109 return __r;
110 }
111
112 # if __WORDSIZE == 64
113 __MATH_INLINE long double
114 __NTH (sqrtl (long double __x))
115 {
116 long double __r;
117 extern void _Qp_sqrt (long double *, const long double *);
118 _Qp_sqrt (&__r, &__x);
119 return __r;
120 }
121 # elif !defined __NO_LONG_DOUBLE_MATH
122 __MATH_INLINE long double
123 sqrtl (long double __x) __THROW
124 {
125 extern long double _Q_sqrt (const long double);
126 return _Q_sqrt (__x);
127 }
128 # endif /* sparc64 */
129
130 # endif /* !__NO_MATH_INLINES && !GCC 3.2+ */
131
132 /* This code is used internally in the GNU libc. */
133 # ifdef __LIBC_INTERNAL_MATH_INLINES
134 __MATH_INLINE double
135 __ieee754_sqrt (double __x)
136 {
137 register double __r;
138 __asm ("fsqrtd %1,%0" : "=f" (__r) : "f" (__x));
139 return __r;
140 }
141
142 __MATH_INLINE float
143 __ieee754_sqrtf (float __x)
144 {
145 register float __r;
146 __asm ("fsqrts %1,%0" : "=f" (__r) : "f" (__x));
147 return __r;
148 }
149
150 # if __WORDSIZE == 64
151 __MATH_INLINE long double
152 __ieee754_sqrtl (long double __x)
153 {
154 long double __r;
155 extern void _Qp_sqrt (long double *, const long double *);
156 _Qp_sqrt(&__r, &__x);
157 return __r;
158 }
159 # elif !defined __NO_LONG_DOUBLE_MATH
160 __MATH_INLINE long double
161 __ieee754_sqrtl (long double __x)
162 {
163 extern long double _Q_sqrt (const long double);
164 return _Q_sqrt (__x);
165 }
166 # endif /* sparc64 */
167 # endif /* __LIBC_INTERNAL_MATH_INLINES */
168 # endif /* gcc 2.8+ */
169
170 # ifdef __USE_ISOC99
171
172 # ifndef __NO_MATH_INLINES
173
174 __MATH_INLINE double __NTH (fdim (double __x, double __y));
175 __MATH_INLINE double
176 __NTH (fdim (double __x, double __y))
177 {
178 return __x <= __y ? 0 : __x - __y;
179 }
180
181 __MATH_INLINE float __NTH (fdimf (float __x, float __y));
182 __MATH_INLINE float
183 __NTH (fdimf (float __x, float __y))
184 {
185 return __x <= __y ? 0 : __x - __y;
186 }
187
188 # endif /* !__NO_MATH_INLINES */
189 # endif /* __USE_ISOC99 */
190 #endif /* !__NO_MATH_INLINES && __OPTIMIZE__ */
191 #endif /* __GNUC__ */