]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/powerpc/bits/mathinline.h
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / sysdeps / powerpc / bits / mathinline.h
CommitLineData
ec751a23 1/* Inline math functions for powerpc.
bfff8b1b 2 Copyright (C) 1995-2017 Free Software Foundation, Inc.
ec751a23
UD
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
41bdb6e2
AJ
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.
ec751a23
UD
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
41bdb6e2 13 Lesser General Public License for more details.
ec751a23 14
41bdb6e2 15 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
ec751a23 18
3c55cffa
UD
19#ifndef _MATH_H
20# error "Never use <bits/mathinline.h> directly; include <math.h> instead."
21#endif
22
de1c3ebb 23#ifndef __extern_inline
3c55cffa
UD
24# define __MATH_INLINE __inline
25#else
b037a293 26# define __MATH_INLINE __extern_inline
3c55cffa
UD
27#endif /* __cplusplus */
28
59981e9b 29#if defined __GNUC__ && !defined _SOFT_FLOAT && !defined __NO_FPRS__
ec751a23
UD
30
31#ifdef __USE_ISOC99
f4c024d1 32# if !__GNUC_PREREQ (2,97)
eca33418 33# define __unordered_cmp(x, y) \
ec751a23
UD
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
f4c024d1
UD
41# undef isgreater
42# undef isgreaterequal
43# undef isless
44# undef islessequal
45# undef islessgreater
46# undef isunordered
47
eca33418
UD
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)
781ca93d 54
eca33418 55# endif /* __GNUC_PREREQ (2,97) */
3c55cffa
UD
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
f377d022 62__NTH (__signbitf (float __x))
3c55cffa 63{
2ca85d2b
AB
64#if __GNUC_PREREQ (4, 0)
65 return __builtin_signbitf (__x);
66#else
3c55cffa
UD
67 __extension__ union { float __f; int __i; } __u = { __f: __x };
68 return __u.__i < 0;
2ca85d2b 69#endif
3c55cffa
UD
70}
71__MATH_INLINE int
f377d022 72__NTH (__signbit (double __x))
3c55cffa 73{
2ca85d2b
AB
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
3c55cffa 80}
7df49c5d
UD
81# ifdef __LONG_DOUBLE_128__
82__MATH_INLINE int
83__NTH (__signbitl (long double __x))
84{
2ca85d2b 85 return __signbit ((double) __x);
7df49c5d
UD
86}
87# endif
3c55cffa 88# endif
781ca93d 89#endif /* __USE_ISOC99 */
ec751a23
UD
90
91#if !defined __NO_MATH_INLINES && defined __OPTIMIZE__
92
ec751a23 93#ifdef __USE_ISOC99
33ab3b66
UD
94
95# ifndef __powerpc64__
cc46c92d 96__MATH_INLINE long int lrint (double __x) __THROW;
ec751a23 97__MATH_INLINE long int
f377d022 98__NTH (lrint (double __x))
ec751a23
UD
99{
100 union {
3c55cffa 101 double __d;
2ca85d2b 102 long long __ll;
ec751a23
UD
103 } __u;
104 __asm__ ("fctiw %0,%1" : "=f"(__u.__d) : "f"(__x));
2ca85d2b 105 return __u.__ll;
ec751a23
UD
106}
107
cc46c92d 108__MATH_INLINE long int lrintf (float __x) __THROW;
ec751a23 109__MATH_INLINE long int
f377d022 110__NTH (lrintf (float __x))
ec751a23 111{
2ca85d2b 112 return lrint ((double) __x);
ec751a23 113}
33ab3b66 114# endif
ec751a23 115
cc46c92d 116__MATH_INLINE double fdim (double __x, double __y) __THROW;
ec751a23 117__MATH_INLINE double
f377d022 118__NTH (fdim (double __x, double __y))
ec751a23 119{
8930fcf9 120 return __x <= __y ? 0 : __x - __y;
ec751a23
UD
121}
122
cc46c92d 123__MATH_INLINE float fdimf (float __x, float __y) __THROW;
ec751a23 124__MATH_INLINE float
f377d022 125__NTH (fdimf (float __x, float __y))
ec751a23 126{
8930fcf9 127 return __x <= __y ? 0 : __x - __y;
ec751a23
UD
128}
129
130#endif /* __USE_ISOC99 */
131#endif /* !__NO_MATH_INLINES && __OPTIMIZE__ */
59981e9b 132#endif /* __GNUC__ && !_SOFT_FLOAT && !__NO_FPRS__ */