1/* Inline math functions for powerpc.
2   Copyright (C) 1995,1996,1997,1998,1999,2000 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, write to the Free
17   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18   02111-1307 USA.  */
19
20#if defined __GNUC__ && !defined _SOFT_FLOAT
21
22#ifdef __USE_ISOC99
23# if __GNUC_PREREQ (2,96)
24
25#  define isgreater(x, y) __builtin_isgreater (x, y)
26#  define isgreaterequal(x, y) __builtin_isgreaterequal (x, y)
27#  define isless(x, y) __builtin_isless (x, y)
28#  define islessequal(x, y) __builtin_islessequal (x, y)
29#  define islessgreater(x, y) __builtin_islessgreater (x, y)
30#  define isunordered(x, y) __builtin_isunordered (x, y)
31
32# else
33
34#  define __unordered_cmp(x, y) \
35  (__extension__							      \
36   ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y);			      \
37      unsigned __r;							      \
38      __asm__("fcmpu 7,%1,%2 ; mfcr %0" : "=r" (__r) : "f" (__x), "f"(__y)    \
39              : "cr7");  \
40      __r; }))
41
42#  define isgreater(x, y) (__unordered_cmp (x, y) >> 2 & 1)
43#  define isgreaterequal(x, y) ((__unordered_cmp (x, y) & 6) != 0)
44#  define isless(x, y) (__unordered_cmp (x, y) >> 3 & 1)
45#  define islessequal(x, y) ((__unordered_cmp (x, y) & 0xA) != 0)
46#  define islessgreater(x, y) ((__unordered_cmp (x, y) & 0xC) != 0)
47#  define isunordered(x, y) (__unordered_cmp (x, y) & 1)
48
49# endif /* __GNUC_PREREQ (2,97) */
50#endif /* __USE_ISOC99 */
51
52#if !defined __NO_MATH_INLINES && defined __OPTIMIZE__
53
54#ifdef __cplusplus
55# define __MATH_INLINE __inline
56#else
57# define __MATH_INLINE extern __inline
58#endif  /* __cplusplus */
59
60#ifdef __USE_ISOC99
61__MATH_INLINE long int lrint (double __x) __THROW;
62__MATH_INLINE long int
63lrint (double __x) __THROW
64{
65  union {
66    double __d;
67    int __ll[2];
68  } __u;
69  __asm__ ("fctiw %0,%1" : "=f"(__u.__d) : "f"(__x));
70  return __u.__ll[1];
71}
72
73__MATH_INLINE long int lrintf (float __x) __THROW;
74__MATH_INLINE long int
75lrintf (float __x) __THROW
76{
77  union {
78    double __d;
79    int __ll[2];
80  } __u;
81  __asm__ ("fctiw %0,%1" : "=f"(__u.__d) : "f"(__x));
82  return __u.__ll[1];
83}
84
85__MATH_INLINE double fdim (double __x, double __y) __THROW;
86__MATH_INLINE double
87fdim (double __x, double __y) __THROW
88{
89  return __x < __y ? 0 : __x - __y;
90}
91
92__MATH_INLINE float fdimf (float __x, float __y) __THROW;
93__MATH_INLINE float
94fdimf (float __x, float __y) __THROW
95{
96  return __x < __y ? 0 : __x - __y;
97}
98
99#endif /* __USE_ISOC99 */
100#endif /* !__NO_MATH_INLINES && __OPTIMIZE__ */
101#endif /* __GNUC__ && !_SOFT_FLOAT */
102