Back to index

glibc  2.9
mathinline.h
Go to the documentation of this file.
00001 /* Inline math functions for powerpc.
00002    Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2004, 2006, 2007, 2008
00003    Free Software Foundation, Inc.
00004    This file is part of the GNU C Library.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #ifndef _MATH_H
00022 # error "Never use <bits/mathinline.h> directly; include <math.h> instead."
00023 #endif
00024 
00025 #ifndef __extern_inline
00026 # define __MATH_INLINE __inline
00027 #else
00028 # define __MATH_INLINE __extern_inline
00029 #endif  /* __cplusplus */
00030 
00031 #if defined __GNUC__ && !defined _SOFT_FLOAT
00032 
00033 #ifdef __USE_ISOC99
00034 # if !__GNUC_PREREQ (2,97)
00035 #  define __unordered_cmp(x, y) \
00036   (__extension__                                                     \
00037    ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y);                     \
00038       unsigned __r;                                                  \
00039       __asm__("fcmpu 7,%1,%2 ; mfcr %0" : "=r" (__r) : "f" (__x), "f"(__y)    \
00040               : "cr7");  \
00041       __r; }))
00042 
00043 #  undef isgreater
00044 #  undef isgreaterequal
00045 #  undef isless
00046 #  undef islessequal
00047 #  undef islessgreater
00048 #  undef isunordered
00049 
00050 #  define isgreater(x, y) (__unordered_cmp (x, y) >> 2 & 1)
00051 #  define isgreaterequal(x, y) ((__unordered_cmp (x, y) & 6) != 0)
00052 #  define isless(x, y) (__unordered_cmp (x, y) >> 3 & 1)
00053 #  define islessequal(x, y) ((__unordered_cmp (x, y) & 0xA) != 0)
00054 #  define islessgreater(x, y) ((__unordered_cmp (x, y) & 0xC) != 0)
00055 #  define isunordered(x, y) (__unordered_cmp (x, y) & 1)
00056 
00057 # endif /* __GNUC_PREREQ (2,97) */
00058 
00059 /* The gcc, version 2.7 or below, has problems with all this inlining
00060    code.  So disable it for this version of the compiler.  */
00061 # if __GNUC_PREREQ (2, 8)
00062 /* Test for negative number.  Used in the signbit() macro.  */
00063 __MATH_INLINE int
00064 __NTH (__signbitf (float __x))
00065 {
00066   __extension__ union { float __f; int __i; } __u = { __f: __x };
00067   return __u.__i < 0;
00068 }
00069 __MATH_INLINE int
00070 __NTH (__signbit (double __x))
00071 {
00072   __extension__ union { double __d; int __i[2]; } __u = { __d: __x };
00073   return __u.__i[0] < 0;
00074 }
00075 #  ifdef __LONG_DOUBLE_128__
00076 __MATH_INLINE int
00077 __NTH (__signbitl (long double __x))
00078 {
00079   __extension__ union { long double __d; int __i[4]; } __u = { __d: __x };
00080   return __u.__i[0] < 0;
00081 }
00082 #  endif
00083 # endif
00084 #endif /* __USE_ISOC99 */
00085 
00086 #if !defined __NO_MATH_INLINES && defined __OPTIMIZE__
00087 
00088 #ifdef __USE_ISOC99
00089 
00090 # ifndef __powerpc64__
00091 __MATH_INLINE long int lrint (double __x) __THROW;
00092 __MATH_INLINE long int
00093 __NTH (lrint (double __x))
00094 {
00095   union {
00096     double __d;
00097     int __ll[2];
00098   } __u;
00099   __asm__ ("fctiw %0,%1" : "=f"(__u.__d) : "f"(__x));
00100   return __u.__ll[1];
00101 }
00102 
00103 __MATH_INLINE long int lrintf (float __x) __THROW;
00104 __MATH_INLINE long int
00105 __NTH (lrintf (float __x))
00106 {
00107   union {
00108     double __d;
00109     int __ll[2];
00110   } __u;
00111   __asm__ ("fctiw %0,%1" : "=f"(__u.__d) : "f"(__x));
00112   return __u.__ll[1];
00113 }
00114 # endif
00115 
00116 __MATH_INLINE double fdim (double __x, double __y) __THROW;
00117 __MATH_INLINE double
00118 __NTH (fdim (double __x, double __y))
00119 {
00120   return __x <= __y ? 0 : __x - __y;
00121 }
00122 
00123 __MATH_INLINE float fdimf (float __x, float __y) __THROW;
00124 __MATH_INLINE float
00125 __NTH (fdimf (float __x, float __y))
00126 {
00127   return __x <= __y ? 0 : __x - __y;
00128 }
00129 
00130 #endif /* __USE_ISOC99 */
00131 #endif /* !__NO_MATH_INLINES && __OPTIMIZE__ */
00132 #endif /* __GNUC__ && !_SOFT_FLOAT */