]>
Commit | Line | Data |
---|---|---|
1 | /* Inline math functions for powerpc. | |
2 | Copyright (C) 1995-2014 Free Software Foundation, Inc. | |
3 | This file is part of the GNU C Library. | |
4 | ||
5 | The GNU C Library is free software; you can redistribute it and/or | |
6 | modify it under the terms of the GNU Lesser General Public | |
7 | License as published by the Free Software Foundation; either | |
8 | version 2.1 of the License, or (at your option) any later version. | |
9 | ||
10 | The GNU C Library is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | Lesser General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU Lesser General Public | |
16 | License along with the GNU C Library; if not, see | |
17 | <http://www.gnu.org/licenses/>. */ | |
18 | ||
19 | #ifndef _MATH_H | |
20 | # error "Never use <bits/mathinline.h> directly; include <math.h> instead." | |
21 | #endif | |
22 | ||
23 | #ifndef __extern_inline | |
24 | # define __MATH_INLINE __inline | |
25 | #else | |
26 | # define __MATH_INLINE __extern_inline | |
27 | #endif /* __cplusplus */ | |
28 | ||
29 | #if defined __GNUC__ && !defined _SOFT_FLOAT && !defined __NO_FPRS__ | |
30 | ||
31 | #ifdef __USE_ISOC99 | |
32 | # if !__GNUC_PREREQ (2,97) | |
33 | # define __unordered_cmp(x, y) \ | |
34 | (__extension__ \ | |
35 | ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \ | |
36 | unsigned __r; \ | |
37 | __asm__("fcmpu 7,%1,%2 ; mfcr %0" : "=r" (__r) : "f" (__x), "f"(__y) \ | |
38 | : "cr7"); \ | |
39 | __r; })) | |
40 | ||
41 | # undef isgreater | |
42 | # undef isgreaterequal | |
43 | # undef isless | |
44 | # undef islessequal | |
45 | # undef islessgreater | |
46 | # undef isunordered | |
47 | ||
48 | # define isgreater(x, y) (__unordered_cmp (x, y) >> 2 & 1) | |
49 | # define isgreaterequal(x, y) ((__unordered_cmp (x, y) & 6) != 0) | |
50 | # define isless(x, y) (__unordered_cmp (x, y) >> 3 & 1) | |
51 | # define islessequal(x, y) ((__unordered_cmp (x, y) & 0xA) != 0) | |
52 | # define islessgreater(x, y) ((__unordered_cmp (x, y) & 0xC) != 0) | |
53 | # define isunordered(x, y) (__unordered_cmp (x, y) & 1) | |
54 | ||
55 | # endif /* __GNUC_PREREQ (2,97) */ | |
56 | ||
57 | /* The gcc, version 2.7 or below, has problems with all this inlining | |
58 | code. So disable it for this version of the compiler. */ | |
59 | # if __GNUC_PREREQ (2, 8) | |
60 | /* Test for negative number. Used in the signbit() macro. */ | |
61 | __MATH_INLINE int | |
62 | __NTH (__signbitf (float __x)) | |
63 | { | |
64 | #if __GNUC_PREREQ (4, 0) | |
65 | return __builtin_signbitf (__x); | |
66 | #else | |
67 | __extension__ union { float __f; int __i; } __u = { __f: __x }; | |
68 | return __u.__i < 0; | |
69 | #endif | |
70 | } | |
71 | __MATH_INLINE int | |
72 | __NTH (__signbit (double __x)) | |
73 | { | |
74 | #if __GNUC_PREREQ (4, 0) | |
75 | return __builtin_signbit (__x); | |
76 | #else | |
77 | __extension__ union { double __d; long long __i; } __u = { __d: __x }; | |
78 | return __u.__i < 0; | |
79 | #endif | |
80 | } | |
81 | # ifdef __LONG_DOUBLE_128__ | |
82 | __MATH_INLINE int | |
83 | __NTH (__signbitl (long double __x)) | |
84 | { | |
85 | return __signbit ((double) __x); | |
86 | } | |
87 | # endif | |
88 | # endif | |
89 | #endif /* __USE_ISOC99 */ | |
90 | ||
91 | #if !defined __NO_MATH_INLINES && defined __OPTIMIZE__ | |
92 | ||
93 | #ifdef __USE_ISOC99 | |
94 | ||
95 | # ifndef __powerpc64__ | |
96 | __MATH_INLINE long int lrint (double __x) __THROW; | |
97 | __MATH_INLINE long int | |
98 | __NTH (lrint (double __x)) | |
99 | { | |
100 | union { | |
101 | double __d; | |
102 | long long __ll; | |
103 | } __u; | |
104 | __asm__ ("fctiw %0,%1" : "=f"(__u.__d) : "f"(__x)); | |
105 | return __u.__ll; | |
106 | } | |
107 | ||
108 | __MATH_INLINE long int lrintf (float __x) __THROW; | |
109 | __MATH_INLINE long int | |
110 | __NTH (lrintf (float __x)) | |
111 | { | |
112 | return lrint ((double) __x); | |
113 | } | |
114 | # endif | |
115 | ||
116 | __MATH_INLINE double fdim (double __x, double __y) __THROW; | |
117 | __MATH_INLINE double | |
118 | __NTH (fdim (double __x, double __y)) | |
119 | { | |
120 | return __x <= __y ? 0 : __x - __y; | |
121 | } | |
122 | ||
123 | __MATH_INLINE float fdimf (float __x, float __y) __THROW; | |
124 | __MATH_INLINE float | |
125 | __NTH (fdimf (float __x, float __y)) | |
126 | { | |
127 | return __x <= __y ? 0 : __x - __y; | |
128 | } | |
129 | ||
130 | #endif /* __USE_ISOC99 */ | |
131 | #endif /* !__NO_MATH_INLINES && __OPTIMIZE__ */ | |
132 | #endif /* __GNUC__ && !_SOFT_FLOAT && !__NO_FPRS__ */ |