(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[glibc.git] / sysdeps / sparc / fpu / bits / mathinline.h
blob7add49366090cc8c4ef1073e88f9b82c55b2e248
1 /* Inline math functions for SPARC.
2 Copyright (C) 1999, 2000, 2001, 2002, 2004 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, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
21 #ifndef _MATH_H
22 # error "Never use <bits/mathinline.h> directly; include <math.h> instead."
23 #endif
25 #include <bits/wordsize.h>
27 #ifdef __GNUC__
29 #if defined __USE_ISOC99 && !__GNUC_PREREQ (3, 0)
30 # undef isgreater
31 # undef isgreaterequal
32 # undef isless
33 # undef islessequal
34 # undef islessgreater
35 # undef isunordered
37 # if __WORDSIZE == 32
39 # define __unordered_cmp(x, y) \
40 (__extension__ \
41 ({ unsigned __r; \
42 if (sizeof(x) == 4 && sizeof(y) == 4) \
43 { \
44 float __x = (x); float __y = (y); \
45 __asm__("fcmps %1,%2; st %%fsr, %0" : "=m" (__r) : "f" (__x), \
46 "f" (__y) : "cc"); \
47 } \
48 else \
49 { \
50 double __x = (x); double __y = (y); \
51 __asm__("fcmpd\t%1,%2\n\tst\t%%fsr,%0" : "=m" (__r) : "f" (__x), \
52 "f" (__y) : "cc"); \
53 } \
54 __r; }))
56 # define isgreater(x, y) ((__unordered_cmp (x, y) & (3 << 10)) == (2 << 10))
57 # define isgreaterequal(x, y) ((__unordered_cmp (x, y) & (1 << 10)) == 0)
58 # define isless(x, y) ((__unordered_cmp (x, y) & (3 << 10)) == (1 << 10))
59 # define islessequal(x, y) ((__unordered_cmp (x, y) & (2 << 10)) == 0)
60 # define islessgreater(x, y) (((__unordered_cmp (x, y) + (1 << 10)) & (2 << 10)) != 0)
61 # define isunordered(x, y) ((__unordered_cmp (x, y) & (3 << 10)) == (3 << 10))
63 # else /* sparc64 */
65 # define __unordered_v9cmp(x, y, op, qop) \
66 (__extension__ \
67 ({ unsigned __r; \
68 if (sizeof(x) == 4 && sizeof(y) == 4) \
69 { \
70 float __x = (x); float __y = (y); \
71 __asm__("fcmps\t%%fcc3,%1,%2\n\tmov" op "\t%%fcc3,1,%0" \
72 : "=r" (__r) : "f" (__x), "f" (__y), "0" (0) : "cc"); \
73 } \
74 else if (sizeof(x) <= 8 && sizeof(y) <= 8) \
75 { \
76 double __x = (x); double __y = (y); \
77 __asm__("fcmpd\t%%fcc3,%1,%2\n\tmov" op "\t%%fcc3,1,%0" \
78 : "=r" (__r) : "f" (__x), "f" (__y), "0" (0) : "cc"); \
79 } \
80 else \
81 { \
82 long double __x = (x); long double __y = (y); \
83 extern int _Qp_cmp(const long double *a, const long double *b); \
84 __r = qop; \
85 } \
86 __r; }))
88 # define isgreater(x, y) __unordered_v9cmp(x, y, "g", _Qp_cmp (&__x, &__y) == 2)
89 # define isgreaterequal(x, y) __unordered_v9cmp(x, y, "ge", (_Qp_cmp (&__x, &__y) & 1) == 0)
90 # define isless(x, y) __unordered_v9cmp(x, y, "l", _Qp_cmp (&__x, &__y) == 1)
91 # define islessequal(x, y) __unordered_v9cmp(x, y, "le", (_Qp_cmp (&__x, &__y) & 2) == 0)
92 # define islessgreater(x, y) __unordered_v9cmp(x, y, "lg", ((_Qp_cmp (&__x, &__y) + 1) & 2) != 0)
93 # define isunordered(x, y) __unordered_v9cmp(x, y, "u", _Qp_cmp (&__x, &__y) == 3)
95 # endif /* sparc64 */
97 #endif /* __USE_ISOC99 */
99 #if (!defined __NO_MATH_INLINES || defined __LIBC_INTERNAL_MATH_INLINES) && defined __OPTIMIZE__
101 # ifdef __cplusplus
102 # define __MATH_INLINE __inline
103 # else
104 # define __MATH_INLINE extern __inline
105 # endif /* __cplusplus */
107 /* The gcc, version 2.7 or below, has problems with all this inlining
108 code. So disable it for this version of the compiler. */
109 # if __GNUC_PREREQ (2, 8)
111 # ifdef __USE_ISOC99
113 /* Test for negative number. Used in the signbit() macro. */
114 __MATH_INLINE int
115 __NTH (__signbitf (float __x))
117 __extension__ union { float __f; int __i; } __u = { __f: __x };
118 return __u.__i < 0;
121 # if __WORDSIZE == 32
123 __MATH_INLINE int
124 __NTH (__signbit (double __x))
126 __extension__ union { double __d; int __i[2]; } __u = { __d: __x };
127 return __u.__i[0] < 0;
130 __MATH_INLINE int
131 __NTH (__signbitl (long double __x))
133 return __signbit ((double)__x);
136 # else /* sparc64 */
138 __MATH_INLINE int
139 __NTH (__signbit (double __x))
141 __extension__ union { double __d; long int __i; } __u = { __d: __x };
142 return __u.__i < 0;
145 __MATH_INLINE int
146 __NTH (__signbitl (long double __x))
148 __extension__ union { long double __l; long int __i[2]; } __u = { __l: __x };
149 return __u.__i[0] < 0;
152 # endif /* sparc64 */
154 # endif /* __USE_ISOC99 */
156 # if !defined __NO_MATH_INLINES && !__GNUC_PREREQ (3, 2)
158 __MATH_INLINE double
159 __NTH (sqrt (double __x))
161 register double __r;
162 __asm ("fsqrtd %1,%0" : "=f" (__r) : "f" (__x));
163 return __r;
166 __MATH_INLINE float
167 __NTH (sqrtf (float __x))
169 register float __r;
170 __asm ("fsqrts %1,%0" : "=f" (__r) : "f" (__x));
171 return __r;
174 # if __WORDSIZE == 64
175 __MATH_INLINE long double
176 __NTH (sqrtl (long double __x))
178 long double __r;
179 extern void _Qp_sqrt (long double *, __const__ long double *);
180 _Qp_sqrt (&__r, &__x);
181 return __r;
183 # endif /* sparc64 */
185 # endif /* !__NO_MATH_INLINES && !GCC 3.2+ */
187 /* This code is used internally in the GNU libc. */
188 # ifdef __LIBC_INTERNAL_MATH_INLINES
189 __MATH_INLINE double
190 __ieee754_sqrt (double __x)
192 register double __r;
193 __asm ("fsqrtd %1,%0" : "=f" (__r) : "f" (__x));
194 return __r;
197 __MATH_INLINE float
198 __ieee754_sqrtf (float __x)
200 register float __r;
201 __asm ("fsqrts %1,%0" : "=f" (__r) : "f" (__x));
202 return __r;
205 # if __WORDSIZE == 64
206 __MATH_INLINE long double
207 __ieee754_sqrtl (long double __x)
209 long double __r;
210 extern void _Qp_sqrt (long double *, __const__ long double *);
211 _Qp_sqrt(&__r, &__x);
212 return __r;
214 # endif /* sparc64 */
215 # endif /* __LIBC_INTERNAL_MATH_INLINES */
216 # endif /* gcc 2.8+ */
218 # ifdef __USE_ISOC99
220 # ifndef __NO_MATH_INLINES
222 __MATH_INLINE double __NTH (fdim (double __x, double __y));
223 __MATH_INLINE double
224 __NTH (fdim (double __x, double __y))
226 return __x <= __y ? 0 : __x - __y;
229 __MATH_INLINE float __NTH (fdimf (float __x, float __y));
230 __MATH_INLINE float
231 __NTH (fdimf (float __x, float __y))
233 return __x <= __y ? 0 : __x - __y;
236 # endif /* !__NO_MATH_INLINES */
237 # endif /* __USE_ISOC99 */
238 #endif /* !__NO_MATH_INLINES && __OPTIMIZE__ */
239 #endif /* __GNUC__ */