mathinline.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, write to the Free
  14. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA. */
  16. #if defined __GNUC__ && !defined _SOFT_FLOAT
  17. #ifdef __USE_ISOC99
  18. # if __GNUC_PREREQ (2,96)
  19. # define isgreater(x, y) __builtin_isgreater (x, y)
  20. # define isgreaterequal(x, y) __builtin_isgreaterequal (x, y)
  21. # define isless(x, y) __builtin_isless (x, y)
  22. # define islessequal(x, y) __builtin_islessequal (x, y)
  23. # define islessgreater(x, y) __builtin_islessgreater (x, y)
  24. # define isunordered(x, y) __builtin_isunordered (x, y)
  25. # else
  26. # define __unordered_cmp(x, y) \
  27. (__extension__ \
  28. ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \
  29. unsigned __r; \
  30. __asm__("fcmpu 7,%1,%2 ; mfcr %0" : "=r" (__r) : "f" (__x), "f"(__y) \
  31. : "cr7"); \
  32. __r; }))
  33. # define isgreater(x, y) (__unordered_cmp (x, y) >> 2 & 1)
  34. # define isgreaterequal(x, y) ((__unordered_cmp (x, y) & 6) != 0)
  35. # define isless(x, y) (__unordered_cmp (x, y) >> 3 & 1)
  36. # define islessequal(x, y) ((__unordered_cmp (x, y) & 0xA) != 0)
  37. # define islessgreater(x, y) ((__unordered_cmp (x, y) & 0xC) != 0)
  38. # define isunordered(x, y) (__unordered_cmp (x, y) & 1)
  39. # endif /* __GNUC_PREREQ (2,97) */
  40. #endif /* __USE_ISOC99 */
  41. #if !defined __NO_MATH_INLINES && defined __OPTIMIZE__
  42. #ifdef __cplusplus
  43. # define __MATH_INLINE __inline
  44. #else
  45. # define __MATH_INLINE extern __inline
  46. #endif /* __cplusplus */
  47. #ifdef __USE_ISOC99
  48. __MATH_INLINE long int lrint (double __x) __THROW;
  49. __MATH_INLINE long int
  50. __NTH (lrint (double __x))
  51. {
  52. union {
  53. double __d;
  54. long int __ll[2];
  55. } __u;
  56. __asm__ ("fctiw %0,%1" : "=f"(__u.__d) : "f"(__x));
  57. return __u.__ll[1];
  58. }
  59. __MATH_INLINE long int lrintf (float __x) __THROW;
  60. __MATH_INLINE long int
  61. __NTH (lrintf (float __x))
  62. {
  63. union {
  64. double __d;
  65. long int __ll[2];
  66. } __u;
  67. __asm__ ("fctiw %0,%1" : "=f"(__u.__d) : "f"(__x));
  68. return __u.__ll[1];
  69. }
  70. __MATH_INLINE double fdim (double __x, double __y) __THROW;
  71. __MATH_INLINE double
  72. __NTH (fdim (double __x, double __y))
  73. {
  74. return __x < __y ? 0 : __x - __y;
  75. }
  76. __MATH_INLINE float fdimf (float __x, float __y) __THROW;
  77. __MATH_INLINE float
  78. __NTH (fdimf (float __x, float __y))
  79. {
  80. return __x < __y ? 0 : __x - __y;
  81. }
  82. #endif /* __USE_ISOC99 */
  83. #endif /* !__NO_MATH_INLINES && __OPTIMIZE__ */
  84. #endif /* __GNUC__ && !_SOFT_FLOAT */