(__getline): Define.
[glibc/history.git] / sysdeps / powerpc / fpu / bits / mathinline.h
blobaed899e8824cc7afe9587e83878524295d180071
1 /* Inline math functions for powerpc.
2 Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2004, 2006
3 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
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 /* __cplusplus */
31 #if defined __GNUC__ && !defined _SOFT_FLOAT
33 #ifdef __USE_ISOC99
34 # if !__GNUC_PREREQ (2,97)
35 # define __unordered_cmp(x, y) \
36 (__extension__ \
37 ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \
38 unsigned __r; \
39 __asm__("fcmpu 7,%1,%2 ; mfcr %0" : "=r" (__r) : "f" (__x), "f"(__y) \
40 : "cr7"); \
41 __r; }))
43 # undef isgreater
44 # undef isgreaterequal
45 # undef isless
46 # undef islessequal
47 # undef islessgreater
48 # undef isunordered
50 # define isgreater(x, y) (__unordered_cmp (x, y) >> 2 & 1)
51 # define isgreaterequal(x, y) ((__unordered_cmp (x, y) & 6) != 0)
52 # define isless(x, y) (__unordered_cmp (x, y) >> 3 & 1)
53 # define islessequal(x, y) ((__unordered_cmp (x, y) & 0xA) != 0)
54 # define islessgreater(x, y) ((__unordered_cmp (x, y) & 0xC) != 0)
55 # define isunordered(x, y) (__unordered_cmp (x, y) & 1)
57 # endif /* __GNUC_PREREQ (2,97) */
59 /* The gcc, version 2.7 or below, has problems with all this inlining
60 code. So disable it for this version of the compiler. */
61 # if __GNUC_PREREQ (2, 8)
62 /* Test for negative number. Used in the signbit() macro. */
63 __MATH_INLINE int
64 __NTH (__signbitf (float __x))
66 __extension__ union { float __f; int __i; } __u = { __f: __x };
67 return __u.__i < 0;
69 __MATH_INLINE int
70 __NTH (__signbit (double __x))
72 __extension__ union { double __d; int __i[2]; } __u = { __d: __x };
73 return __u.__i[0] < 0;
75 # endif
76 #endif /* __USE_ISOC99 */
78 #if !defined __NO_MATH_INLINES && defined __OPTIMIZE__
80 #ifdef __USE_ISOC99
82 # ifndef __powerpc64__
83 __MATH_INLINE long int lrint (double __x) __THROW;
84 __MATH_INLINE long int
85 __NTH (lrint (double __x))
87 union {
88 double __d;
89 int __ll[2];
90 } __u;
91 __asm__ ("fctiw %0,%1" : "=f"(__u.__d) : "f"(__x));
92 return __u.__ll[1];
95 __MATH_INLINE long int lrintf (float __x) __THROW;
96 __MATH_INLINE long int
97 __NTH (lrintf (float __x))
99 union {
100 double __d;
101 int __ll[2];
102 } __u;
103 __asm__ ("fctiw %0,%1" : "=f"(__u.__d) : "f"(__x));
104 return __u.__ll[1];
106 # endif
108 __MATH_INLINE double fdim (double __x, double __y) __THROW;
109 __MATH_INLINE double
110 __NTH (fdim (double __x, double __y))
112 return __x <= __y ? 0 : __x - __y;
115 __MATH_INLINE float fdimf (float __x, float __y) __THROW;
116 __MATH_INLINE float
117 __NTH (fdimf (float __x, float __y))
119 return __x <= __y ? 0 : __x - __y;
122 #endif /* __USE_ISOC99 */
123 #endif /* !__NO_MATH_INLINES && __OPTIMIZE__ */
125 /* This code is used internally in the GNU libc. */
126 #ifdef __LIBC_INTERNAL_MATH_INLINES
128 #include <sysdep.h>
129 #include <ldsodefs.h>
130 #include <dl-procinfo.h>
132 # if __WORDSIZE == 64 || defined _ARCH_PWR4
133 # define __CPU_HAS_FSQRT 1
134 # else
135 # define __CPU_HAS_FSQRT ((GLRO(dl_hwcap) & PPC_FEATURE_64) != 0)
136 # endif
138 extern double __slow_ieee754_sqrt (double);
139 __MATH_INLINE double
140 __NTH (__ieee754_sqrt (double __x))
142 double __z;
144 /* If the CPU is 64-bit we can use the optional FP instructions. */
145 if (__CPU_HAS_FSQRT)
147 /* Volatile is required to prevent the compiler from moving the
148 fsqrt instruction above the branch. */
149 __asm __volatile (
150 " fsqrt %0,%1\n"
151 : "=f" (__z)
152 : "f" (__x));
154 else
155 __z = __slow_ieee754_sqrt(__x);
157 return __z;
160 extern float __slow_ieee754_sqrtf (float);
161 __MATH_INLINE float
162 __NTH (__ieee754_sqrtf (float __x))
164 float __z;
166 /* If the CPU is 64-bit we can use the optional FP instructions. */
167 if (__CPU_HAS_FSQRT)
169 /* Volatile is required to prevent the compiler from moving the
170 fsqrts instruction above the branch. */
171 __asm __volatile (
172 " fsqrts %0,%1\n"
173 : "=f" (__z)
174 : "f" (__x));
176 else
177 __z = __slow_ieee754_sqrtf(__x);
179 return __z;
181 #endif /* __LIBC_INTERNAL_MATH_INLINES */
182 #endif /* __GNUC__ && !_SOFT_FLOAT */