Nonworking non-GNU OS port code moved to ports repository.
[glibc-ports.git] / sysdeps / alpha / fpu / bits / mathinline.h
blob187bd42f33d0f64a82e8c9dd8f18301de80659be
1 /* Inline math functions for Alpha.
2 Copyright (C) 1996, 1997, 1999-2001, 2004 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by David Mosberger-Tang.
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 #ifdef __cplusplus
26 # define __MATH_INLINE __inline
27 #else
28 # define __MATH_INLINE extern __inline
29 #endif
31 #if defined __USE_ISOC99 && defined __GNUC__ && !__GNUC_PREREQ(3,0)
32 # undef isgreater
33 # undef isgreaterequal
34 # undef isless
35 # undef islessequal
36 # undef islessgreater
37 # undef isunordered
38 # define isunordered(u, v) \
39 (__extension__ \
40 ({ double __r, __u = (u), __v = (v); \
41 __asm ("cmptun/su %1,%2,%0\n\ttrapb" \
42 : "=&f" (__r) : "f" (__u), "f"(__v)); \
43 __r != 0; }))
44 #endif /* ISO C99 */
46 #if (!defined __NO_MATH_INLINES || defined __LIBC_INTERNAL_MATH_INLINES) \
47 && defined __OPTIMIZE__
49 #define __inline_copysign(NAME, TYPE) \
50 __MATH_INLINE TYPE \
51 __NTH (NAME (TYPE __x, TYPE __y)) \
52 { \
53 TYPE __z; \
54 __asm ("cpys %1, %2, %0" : "=f" (__z) : "f" (__y), "f" (__x)); \
55 return __z; \
58 __inline_copysign (__copysignf, float)
59 __inline_copysign (copysignf, float)
60 __inline_copysign (__copysign, double)
61 __inline_copysign (copysign, double)
63 #undef __MATH_INLINE_copysign
66 #if __GNUC_PREREQ (2, 8)
67 __MATH_INLINE float
68 __NTH (__fabsf (float __x)) { return __builtin_fabsf (__x); }
69 __MATH_INLINE float
70 __NTH (fabsf (float __x)) { return __builtin_fabsf (__x); }
71 __MATH_INLINE double
72 __NTH (__fabs (double __x)) { return __builtin_fabs (__x); }
73 __MATH_INLINE double
74 __NTH (fabs (double __x)) { return __builtin_fabs (__x); }
75 #else
76 # define __inline_fabs(NAME, TYPE) \
77 __MATH_INLINE TYPE \
78 __NTH (NAME (TYPE __x)) \
79 { \
80 TYPE __z; \
81 __asm ("cpys $f31, %1, %0" : "=f" (__z) : "f" (__x)); \
82 return __z; \
85 __inline_fabs (__fabsf, float)
86 __inline_fabs (fabsf, float)
87 __inline_fabs (__fabs, double)
88 __inline_fabs (fabs, double)
90 # undef __inline_fabs
91 #endif
94 /* Use the -inf rounding mode conversion instructions to implement
95 floor. We note when the exponent is large enough that the value
96 must be integral, as this avoids unpleasant integer overflows. */
98 __MATH_INLINE float
99 __NTH (__floorf (float __x))
101 /* Check not zero since floor(-0) == -0. */
102 if (__x != 0 && fabsf (__x) < 16777216.0f) /* 1 << FLT_MANT_DIG */
104 /* Note that Alpha S_Floating is stored in registers in a
105 restricted T_Floating format, so we don't even need to
106 convert back to S_Floating in the end. The initial
107 conversion to T_Floating is needed to handle denormals. */
109 float __tmp1, __tmp2;
111 __asm ("cvtst/s %3,%2\n\t"
112 #ifdef _IEEE_FP_INEXACT
113 "cvttq/svim %2,%1\n\t"
114 #else
115 "cvttq/svm %2,%1\n\t"
116 #endif
117 "cvtqt/m %1,%0\n\t"
118 : "=f"(__x), "=&f"(__tmp1), "=&f"(__tmp2)
119 : "f"(__x));
121 return __x;
124 __MATH_INLINE double
125 __NTH (__floor (double __x))
127 if (__x != 0 && fabs (__x) < 9007199254740992.0) /* 1 << DBL_MANT_DIG */
129 double __tmp1;
130 __asm (
131 #ifdef _IEEE_FP_INEXACT
132 "cvttq/svim %2,%1\n\t"
133 #else
134 "cvttq/svm %2,%1\n\t"
135 #endif
136 "cvtqt/m %1,%0\n\t"
137 : "=f"(__x), "=&f"(__tmp1)
138 : "f"(__x));
140 return __x;
143 __MATH_INLINE float __NTH (floorf (float __x)) { return __floorf(__x); }
144 __MATH_INLINE double __NTH (floor (double __x)) { return __floor(__x); }
147 #ifdef __USE_ISOC99
149 __MATH_INLINE float
150 __NTH (__fdimf (float __x, float __y))
152 return __x <= __y ? 0.0f : __x - __y;
155 __MATH_INLINE float
156 __NTH (fdimf (float __x, float __y))
158 return __x <= __y ? 0.0f : __x - __y;
161 __MATH_INLINE double
162 __NTH (__fdim (double __x, double __y))
164 return __x <= __y ? 0.0 : __x - __y;
167 __MATH_INLINE double
168 __NTH (fdim (double __x, double __y))
170 return __x <= __y ? 0.0 : __x - __y;
173 /* Test for negative number. Used in the signbit() macro. */
174 __MATH_INLINE int
175 __NTH (__signbitf (float __x))
177 __extension__ union { float __f; int __i; } __u = { __f: __x };
178 return __u.__i < 0;
181 __MATH_INLINE int
182 __NTH (__signbit (double __x))
184 __extension__ union { double __d; long __i; } __u = { __d: __x };
185 return __u.__i < 0;
188 #endif /* C99 */
190 #endif /* __NO_MATH_INLINES */