2.9
[glibc/nacl-glibc.git] / sysdeps / alpha / fpu / bits / mathinline.h
blob5378a181c6c96d4ac1c904ffd1eb0f2a07a7dd4b
1 /* Inline math functions for Alpha.
2 Copyright (C) 1996, 1997, 1999-2001, 2004, 2007
3 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
5 Contributed by David Mosberger-Tang.
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, write to the Free
19 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 02111-1307 USA. */
22 #ifndef _MATH_H
23 # error "Never use <bits/mathinline.h> directly; include <math.h> instead."
24 #endif
26 #ifndef __extern_inline
27 # define __MATH_INLINE __inline
28 #else
29 # define __MATH_INLINE __extern_inline
30 #endif
32 #if defined __USE_ISOC99 && defined __GNUC__ && !__GNUC_PREREQ(3,0)
33 # undef isgreater
34 # undef isgreaterequal
35 # undef isless
36 # undef islessequal
37 # undef islessgreater
38 # undef isunordered
39 # define isunordered(u, v) \
40 (__extension__ \
41 ({ double __r, __u = (u), __v = (v); \
42 __asm ("cmptun/su %1,%2,%0\n\ttrapb" \
43 : "=&f" (__r) : "f" (__u), "f"(__v)); \
44 __r != 0; }))
45 #endif /* ISO C99 */
47 #if (!defined __NO_MATH_INLINES || defined __LIBC_INTERNAL_MATH_INLINES) \
48 && defined __OPTIMIZE__
50 #if !__GNUC_PREREQ (4, 0)
51 # define __inline_copysign(NAME, TYPE) \
52 __MATH_INLINE TYPE \
53 __NTH (NAME (TYPE __x, TYPE __y)) \
54 { \
55 TYPE __z; \
56 __asm ("cpys %1, %2, %0" : "=f" (__z) : "f" (__y), "f" (__x)); \
57 return __z; \
60 __inline_copysign (__copysignf, float)
61 __inline_copysign (copysignf, float)
62 __inline_copysign (__copysign, double)
63 __inline_copysign (copysign, double)
65 # undef __inline_copysign
66 #endif
69 #if !__GNUC_PREREQ (2, 8)
70 # define __inline_fabs(NAME, TYPE) \
71 __MATH_INLINE TYPE \
72 __NTH (NAME (TYPE __x)) \
73 { \
74 TYPE __z; \
75 __asm ("cpys $f31, %1, %0" : "=f" (__z) : "f" (__x)); \
76 return __z; \
79 __inline_fabs (__fabsf, float)
80 __inline_fabs (fabsf, float)
81 __inline_fabs (__fabs, double)
82 __inline_fabs (fabs, double)
84 # undef __inline_fabs
85 #endif
87 #ifdef __USE_ISOC99
89 /* Test for negative number. Used in the signbit() macro. */
90 __MATH_INLINE int
91 __NTH (__signbitf (float __x))
93 #if !__GNUC_PREREQ (4, 0)
94 __extension__ union { float __f; int __i; } __u = { __f: __x };
95 return __u.__i < 0;
96 #else
97 return __builtin_signbitf (__x);
98 #endif
101 __MATH_INLINE int
102 __NTH (__signbit (double __x))
104 #if !__GNUC_PREREQ (4, 0)
105 __extension__ union { double __d; long __i; } __u = { __d: __x };
106 return __u.__i < 0;
107 #else
108 return __builtin_signbit (__x);
109 #endif
112 __MATH_INLINE int
113 __NTH (__signbitl (long double __x))
115 #if !__GNUC_PREREQ (4, 0)
116 __extension__ union {
117 long double __d;
118 long __i[sizeof(long double)/sizeof(long)];
119 } __u = { __d: __x };
120 return __u.__i[sizeof(long double)/sizeof(long) - 1] < 0;
121 #else
122 return __builtin_signbitl (__x);
123 #endif
126 /* Test for NaN. Used in the isnan() macro. */
128 __MATH_INLINE int
129 __NTH (__isnanf (float __x))
131 return isunordered (__x, __x);
134 __MATH_INLINE int
135 __NTH (__isnan (double __x))
137 return isunordered (__x, __x);
140 #ifndef __NO_LONG_DOUBLE_MATH
141 __MATH_INLINE int
142 __NTH (__isnanl (long double __x))
144 return isunordered (__x, __x);
146 #endif
148 #endif /* C99 */
150 #endif /* __NO_MATH_INLINES */