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.
5
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.
10
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.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
19
20 #include <features.h>
21
22 #ifndef _MATH_H
23 # error "Never use <bits/mathinline.h> directly; include <math.h> instead."
24 #endif
25
26 #ifdef __cplusplus
27 # define __MATH_INLINE __inline
28 #else
29 # define __MATH_INLINE __extern_inline
30 #endif /* __cplusplus */
31
32 #if defined __GNUC__ && !defined _SOFT_FLOAT
33
34 #ifdef __USE_ISOC99
35 # if !__GNUC_PREREQ (2,97)
36 # define __unordered_cmp(x, y) \
37 (__extension__ \
38 ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \
39 unsigned __r; \
40 __asm__("fcmpu 7,%1,%2 ; mfcr %0" : "=r" (__r) : "f" (__x), "f"(__y) \
41 : "cr7"); \
42 __r; }))
43
44 # undef isgreater
45 # undef isgreaterequal
46 # undef isless
47 # undef islessequal
48 # undef islessgreater
49 # undef isunordered
50
51 # define isgreater(x, y) (__unordered_cmp (x, y) >> 2 & 1)
52 # define isgreaterequal(x, y) ((__unordered_cmp (x, y) & 6) != 0)
53 # define isless(x, y) (__unordered_cmp (x, y) >> 3 & 1)
54 # define islessequal(x, y) ((__unordered_cmp (x, y) & 0xA) != 0)
55 # define islessgreater(x, y) ((__unordered_cmp (x, y) & 0xC) != 0)
56 # define isunordered(x, y) (__unordered_cmp (x, y) & 1)
57
58 # endif /* __GNUC_PREREQ (2,97) */
59
60 #endif /* __USE_ISOC99 */
61
62 #if !defined __NO_MATH_INLINES && defined __OPTIMIZE__
63
64 #ifdef __USE_ISOC99
65
66 __MATH_INLINE long int lrint (double __x) __THROW;
67 __MATH_INLINE long int
__NTH(lrint (double __x))68 __NTH (lrint (double __x))
69 {
70 union {
71 double __d;
72 int __ll[2];
73 } __u;
74 __asm__ ("fctiw %0,%1" : "=f"(__u.__d) : "f"(__x));
75 return __u.__ll[1];
76 }
77
78 __MATH_INLINE long int lrintf (float __x) __THROW;
79 __MATH_INLINE long int
__NTH(lrintf (float __x))80 __NTH (lrintf (float __x))
81 {
82 union {
83 double __d;
84 int __ll[2];
85 } __u;
86 __asm__ ("fctiw %0,%1" : "=f"(__u.__d) : "f"(__x));
87 return __u.__ll[1];
88 }
89
90 __MATH_INLINE double fdim (double __x, double __y) __THROW;
91 __MATH_INLINE double
__NTH(fdim (double __x,double __y))92 __NTH (fdim (double __x, double __y))
93 {
94 return __x <= __y ? 0 : __x - __y;
95 }
96
97 __MATH_INLINE float fdimf (float __x, float __y) __THROW;
98 __MATH_INLINE float
__NTH(fdimf (float __x,float __y))99 __NTH (fdimf (float __x, float __y))
100 {
101 return __x <= __y ? 0 : __x - __y;
102 }
103
104 #endif /* __USE_ISOC99 */
105 #endif /* !__NO_MATH_INLINES && __OPTIMIZE__ */
106
107 #endif /* __GNUC__ && !_SOFT_FLOAT */
108
109