1 /* Inline math functions for Alpha.
2 Copyright (C) 1996, 1997, 1999, 2000, 2001 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
22 # error "Never use <bits/mathinline.h> directly; include <math.h> instead."
26 # define __MATH_INLINE __inline
28 # define __MATH_INLINE extern __inline
32 # define isunordered(x, y) \
35 __asm ("cmptun/su %1,%2,%0\n\ttrapb" \
36 : "=&f" (__r) : "f" (x), "f"(y)); \
39 # define isgreater(x, y) \
41 ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \
42 !isunordered(__x, __y) && __x > __y; }))
43 # define isgreaterequal(x, y) \
45 ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \
46 !isunordered(__x, __y) && __x >= __y; }))
47 # define isless(x, y) \
49 ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \
50 !isunordered(__x, __y) && __x < __y; }))
51 # define islessequal(x, y) \
53 ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \
54 !isunordered(__x, __y) && __x <= __y; }))
55 # define islessgreater(x, y) \
57 ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \
58 !isunordered(__x, __y) && __x != __y; }))
61 #if !defined __NO_MATH_INLINES && defined __OPTIMIZE__
63 #define __inline_copysign(NAME, TYPE) \
65 NAME (TYPE __x, TYPE __y) __THROW \
68 __asm ("cpys %1, %2, %0" : "=f" (__z) : "f" (__y), "f" (__x)); \
72 __inline_copysign(__copysignf, float)
73 __inline_copysign(copysignf, float)
74 __inline_copysign(__copysign, double)
75 __inline_copysign(copysign, double)
77 #undef __MATH_INLINE_copysign
80 #if __GNUC_PREREQ (2, 8)
81 __MATH_INLINE float __fabsf (float __x) __THROW { return __builtin_fabsf (__x); }
82 __MATH_INLINE float fabsf (float __x) __THROW { return __builtin_fabsf (__x); }
83 __MATH_INLINE double __fabs (double __x) __THROW { return __builtin_fabs (__x); }
84 __MATH_INLINE double fabs (double __x) __THROW { return __builtin_fabs (__x); }
86 #define __inline_fabs(NAME, TYPE) \
88 NAME (TYPE __x) __THROW \
91 __asm ("cpys $f31, %1, %0" : "=f" (__z) : "f" (__x)); \
95 __inline_fabs(__fabsf, float)
96 __inline_fabs(fabsf, float)
97 __inline_fabs(__fabs, double)
98 __inline_fabs(fabs, double)
104 /* Use the -inf rounding mode conversion instructions to implement
105 floor. We note when the exponent is large enough that the value
106 must be integral, as this avoids unpleasant integer overflows. */
109 __floorf (float __x) __THROW
111 /* Check not zero since floor(-0) == -0. */
112 if (__x != 0 && fabsf (__x) < 16777216.0f) /* 1 << FLT_MANT_DIG */
114 /* Note that Alpha S_Floating is stored in registers in a
115 restricted T_Floating format, so we don't even need to
116 convert back to S_Floating in the end. The initial
117 conversion to T_Floating is needed to handle denormals. */
119 float __tmp1, __tmp2;
121 __asm ("cvtst/s %3,%2\n\t"
122 #ifdef _IEEE_FP_INEXACT
123 "cvttq/svim %2,%1\n\t"
125 "cvttq/svm %2,%1\n\t"
128 : "=f"(__x), "=&f"(__tmp1), "=&f"(__tmp2)
135 __floor (double __x) __THROW
137 if (__x != 0 && fabs (__x) < 9007199254740992.0) /* 1 << DBL_MANT_DIG */
141 #ifdef _IEEE_FP_INEXACT
142 "cvttq/svim %2,%1\n\t"
144 "cvttq/svm %2,%1\n\t"
147 : "=f"(__x), "=&f"(__tmp1)
153 __MATH_INLINE float floorf (float __x) __THROW { return __floorf(__x); }
154 __MATH_INLINE double floor (double __x) __THROW { return __floor(__x); }
159 __MATH_INLINE float __fdimf (float __x, float __y) __THROW
161 return __x < __y ? 0.0f : __x - __y;
164 __MATH_INLINE float fdimf (float __x, float __y) __THROW
166 return __x < __y ? 0.0f : __x - __y;
169 __MATH_INLINE double __fdim (double __x, double __y) __THROW
171 return __x < __y ? 0.0 : __x - __y;
174 __MATH_INLINE double fdim (double __x, double __y) __THROW
176 return __x < __y ? 0.0 : __x - __y;
181 #endif /* __NO_MATH_INLINES */