1999-10-31 17:37:43 +00:00
|
|
|
/* Inline math functions for powerpc.
|
2004-02-20 20:21:20 +00:00
|
|
|
Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2004
|
|
|
|
Free Software Foundation, Inc.
|
1999-10-31 17:37:43 +00:00
|
|
|
This file is part of the GNU C Library.
|
|
|
|
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
2001-07-06 04:58:11 +00:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
1999-10-31 17:37:43 +00:00
|
|
|
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2001-07-06 04:58:11 +00:00
|
|
|
Lesser General Public License for more details.
|
1999-10-31 17:37:43 +00:00
|
|
|
|
2001-07-06 04:58:11 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with the GNU C Library; if not, write to the Free
|
|
|
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
|
|
|
02111-1307 USA. */
|
1999-10-31 17:37:43 +00:00
|
|
|
|
2004-04-01 20:31:01 +00:00
|
|
|
#ifndef _MATH_H
|
|
|
|
# error "Never use <bits/mathinline.h> directly; include <math.h> instead."
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
# define __MATH_INLINE __inline
|
|
|
|
#else
|
|
|
|
# define __MATH_INLINE extern __inline
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
1999-10-31 17:37:43 +00:00
|
|
|
#if defined __GNUC__ && !defined _SOFT_FLOAT
|
|
|
|
|
|
|
|
#ifdef __USE_ISOC99
|
2004-03-10 06:05:14 +00:00
|
|
|
# if !__GNUC_PREREQ (2,97)
|
2000-10-20 07:31:42 +00:00
|
|
|
# define __unordered_cmp(x, y) \
|
1999-10-31 17:37:43 +00:00
|
|
|
(__extension__ \
|
|
|
|
({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \
|
|
|
|
unsigned __r; \
|
|
|
|
__asm__("fcmpu 7,%1,%2 ; mfcr %0" : "=r" (__r) : "f" (__x), "f"(__y) \
|
|
|
|
: "cr7"); \
|
|
|
|
__r; }))
|
|
|
|
|
2004-03-10 06:05:14 +00:00
|
|
|
# undef isgreater
|
|
|
|
# undef isgreaterequal
|
|
|
|
# undef isless
|
|
|
|
# undef islessequal
|
|
|
|
# undef islessgreater
|
|
|
|
# undef isunordered
|
|
|
|
|
2000-10-20 07:31:42 +00:00
|
|
|
# define isgreater(x, y) (__unordered_cmp (x, y) >> 2 & 1)
|
|
|
|
# define isgreaterequal(x, y) ((__unordered_cmp (x, y) & 6) != 0)
|
|
|
|
# define isless(x, y) (__unordered_cmp (x, y) >> 3 & 1)
|
|
|
|
# define islessequal(x, y) ((__unordered_cmp (x, y) & 0xA) != 0)
|
|
|
|
# define islessgreater(x, y) ((__unordered_cmp (x, y) & 0xC) != 0)
|
|
|
|
# define isunordered(x, y) (__unordered_cmp (x, y) & 1)
|
2000-10-19 08:15:41 +00:00
|
|
|
|
2000-10-20 07:31:42 +00:00
|
|
|
# endif /* __GNUC_PREREQ (2,97) */
|
2004-04-01 20:31:01 +00:00
|
|
|
|
|
|
|
/* The gcc, version 2.7 or below, has problems with all this inlining
|
|
|
|
code. So disable it for this version of the compiler. */
|
|
|
|
# if __GNUC_PREREQ (2, 8)
|
|
|
|
/* Test for negative number. Used in the signbit() macro. */
|
|
|
|
__MATH_INLINE int
|
2004-09-07 22:33:37 +00:00
|
|
|
__NTH (__signbitf (float __x))
|
2004-04-01 20:31:01 +00:00
|
|
|
{
|
|
|
|
__extension__ union { float __f; int __i; } __u = { __f: __x };
|
|
|
|
return __u.__i < 0;
|
|
|
|
}
|
|
|
|
__MATH_INLINE int
|
2004-09-07 22:33:37 +00:00
|
|
|
__NTH (__signbit (double __x))
|
2004-04-01 20:31:01 +00:00
|
|
|
{
|
|
|
|
__extension__ union { double __d; int __i[2]; } __u = { __d: __x };
|
|
|
|
return __u.__i[0] < 0;
|
|
|
|
}
|
|
|
|
# endif
|
2000-10-19 08:15:41 +00:00
|
|
|
#endif /* __USE_ISOC99 */
|
1999-10-31 17:37:43 +00:00
|
|
|
|
|
|
|
#if !defined __NO_MATH_INLINES && defined __OPTIMIZE__
|
|
|
|
|
|
|
|
#ifdef __USE_ISOC99
|
2004-02-20 20:21:20 +00:00
|
|
|
|
|
|
|
# ifndef __powerpc64__
|
2000-06-04 16:11:43 +00:00
|
|
|
__MATH_INLINE long int lrint (double __x) __THROW;
|
1999-10-31 17:37:43 +00:00
|
|
|
__MATH_INLINE long int
|
2004-09-07 22:33:37 +00:00
|
|
|
__NTH (lrint (double __x))
|
1999-10-31 17:37:43 +00:00
|
|
|
{
|
|
|
|
union {
|
2004-04-01 20:31:01 +00:00
|
|
|
double __d;
|
2002-09-20 20:06:45 +00:00
|
|
|
int __ll[2];
|
1999-10-31 17:37:43 +00:00
|
|
|
} __u;
|
|
|
|
__asm__ ("fctiw %0,%1" : "=f"(__u.__d) : "f"(__x));
|
|
|
|
return __u.__ll[1];
|
|
|
|
}
|
|
|
|
|
2000-06-04 16:11:43 +00:00
|
|
|
__MATH_INLINE long int lrintf (float __x) __THROW;
|
1999-10-31 17:37:43 +00:00
|
|
|
__MATH_INLINE long int
|
2004-09-07 22:33:37 +00:00
|
|
|
__NTH (lrintf (float __x))
|
1999-10-31 17:37:43 +00:00
|
|
|
{
|
|
|
|
union {
|
|
|
|
double __d;
|
2002-09-20 20:06:45 +00:00
|
|
|
int __ll[2];
|
1999-10-31 17:37:43 +00:00
|
|
|
} __u;
|
|
|
|
__asm__ ("fctiw %0,%1" : "=f"(__u.__d) : "f"(__x));
|
|
|
|
return __u.__ll[1];
|
|
|
|
}
|
2004-02-20 20:21:20 +00:00
|
|
|
# endif
|
1999-10-31 17:37:43 +00:00
|
|
|
|
2000-06-04 16:11:43 +00:00
|
|
|
__MATH_INLINE double fdim (double __x, double __y) __THROW;
|
1999-10-31 17:37:43 +00:00
|
|
|
__MATH_INLINE double
|
2004-09-07 22:33:37 +00:00
|
|
|
__NTH (fdim (double __x, double __y))
|
1999-10-31 17:37:43 +00:00
|
|
|
{
|
|
|
|
return __x < __y ? 0 : __x - __y;
|
|
|
|
}
|
|
|
|
|
2000-06-04 16:11:43 +00:00
|
|
|
__MATH_INLINE float fdimf (float __x, float __y) __THROW;
|
1999-10-31 17:37:43 +00:00
|
|
|
__MATH_INLINE float
|
2004-09-07 22:33:37 +00:00
|
|
|
__NTH (fdimf (float __x, float __y))
|
1999-10-31 17:37:43 +00:00
|
|
|
{
|
|
|
|
return __x < __y ? 0 : __x - __y;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* __USE_ISOC99 */
|
|
|
|
#endif /* !__NO_MATH_INLINES && __OPTIMIZE__ */
|
2004-05-26 04:47:00 +00:00
|
|
|
|
|
|
|
/* This code is used internally in the GNU libc. */
|
|
|
|
# ifdef __LIBC_INTERNAL_MATH_INLINES
|
|
|
|
|
|
|
|
#include <sysdep.h>
|
|
|
|
#include <ldsodefs.h>
|
|
|
|
#include <dl-procinfo.h>
|
|
|
|
|
|
|
|
extern double __slow_ieee754_sqrt (double);
|
|
|
|
__MATH_INLINE double
|
2004-09-07 22:33:37 +00:00
|
|
|
__NTH (__ieee754_sqrt (double __x))
|
2004-05-26 04:47:00 +00:00
|
|
|
{
|
|
|
|
double __z;
|
2004-09-07 22:33:37 +00:00
|
|
|
|
2004-05-26 04:47:00 +00:00
|
|
|
/* If the CPU is 64-bit we can use the optional FP instructions we. */
|
|
|
|
if ((GLRO(dl_hwcap) & PPC_FEATURE_64) != 0)
|
|
|
|
{
|
2004-09-07 22:33:37 +00:00
|
|
|
/* Volatile is required to prevent the compiler from moving the
|
2004-05-26 04:47:00 +00:00
|
|
|
fsqrt instruction above the branch. */
|
|
|
|
__asm __volatile (
|
|
|
|
" fsqrt %0,%1\n"
|
|
|
|
: "=f" (__z)
|
|
|
|
: "f" (__x));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
__z = __slow_ieee754_sqrt(__x);
|
2004-09-07 22:33:37 +00:00
|
|
|
|
2004-05-26 04:47:00 +00:00
|
|
|
return __z;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern float __slow_ieee754_sqrtf (float);
|
|
|
|
__MATH_INLINE float
|
2004-09-07 22:33:37 +00:00
|
|
|
__NTH (__ieee754_sqrtf (float __x))
|
2004-05-26 04:47:00 +00:00
|
|
|
{
|
|
|
|
float __z;
|
2004-09-07 22:33:37 +00:00
|
|
|
|
2004-05-26 04:47:00 +00:00
|
|
|
/* If the CPU is 64-bit we can use the optional FP instructions we. */
|
|
|
|
if ((GLRO(dl_hwcap) & PPC_FEATURE_64) != 0)
|
|
|
|
{
|
2004-09-07 22:33:37 +00:00
|
|
|
/* Volatile is required to prevent the compiler from moving the
|
2004-05-26 04:47:00 +00:00
|
|
|
fsqrts instruction above the branch. */
|
|
|
|
__asm __volatile (
|
|
|
|
" fsqrts %0,%1\n"
|
|
|
|
: "=f" (__z)
|
|
|
|
: "f" (__x));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
__z = __slow_ieee754_sqrtf(__x);
|
2004-09-07 22:33:37 +00:00
|
|
|
|
2004-05-26 04:47:00 +00:00
|
|
|
return __z;
|
|
|
|
}
|
|
|
|
# endif /* __LIBC_INTERNAL_MATH_INLINES */
|
1999-10-31 17:37:43 +00:00
|
|
|
#endif /* __GNUC__ && !_SOFT_FLOAT */
|