math_private.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*
  2. * ====================================================
  3. * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  4. *
  5. * Developed at SunPro, a Sun Microsystems, Inc. business.
  6. * Permission to use, copy, modify, and distribute this
  7. * software is freely granted, provided that this notice
  8. * is preserved.
  9. * ====================================================
  10. */
  11. /*
  12. * from: @(#)fdlibm.h 5.1 93/09/24
  13. * $Id: math_private.h,v 1.3 2004/02/09 07:10:38 andersen Exp $
  14. */
  15. #ifndef _MATH_PRIVATE_H_
  16. #define _MATH_PRIVATE_H_
  17. #include <endian.h>
  18. #include <sys/types.h>
  19. /* The original fdlibm code used statements like:
  20. n0 = ((*(int*)&one)>>29)^1; * index of high word *
  21. ix0 = *(n0+(int*)&x); * high word of x *
  22. ix1 = *((1-n0)+(int*)&x); * low word of x *
  23. to dig two 32 bit words out of the 64 bit IEEE floating point
  24. value. That is non-ANSI, and, moreover, the gcc instruction
  25. scheduler gets it wrong. We instead use the following macros.
  26. Unlike the original code, we determine the endianness at compile
  27. time, not at run time; I don't see much benefit to selecting
  28. endianness at run time. */
  29. /* A union which permits us to convert between a double and two 32 bit
  30. ints. */
  31. /*
  32. * Math on arm is special (read: stupid):
  33. * For FPA, float words are always big-endian.
  34. * For VFP, float words follow the memory system mode.
  35. * For Maverick, float words are always little-endian.
  36. */
  37. #if !defined(__MAVERICK__) && ((__BYTE_ORDER == __BIG_ENDIAN) || \
  38. (!defined(__VFP_FP__) && (defined(__arm__) || defined(__thumb__))))
  39. typedef union
  40. {
  41. double value;
  42. struct
  43. {
  44. u_int32_t msw;
  45. u_int32_t lsw;
  46. } parts;
  47. } ieee_double_shape_type;
  48. #else
  49. typedef union
  50. {
  51. double value;
  52. struct
  53. {
  54. u_int32_t lsw;
  55. u_int32_t msw;
  56. } parts;
  57. } ieee_double_shape_type;
  58. #endif
  59. /* Get two 32 bit ints from a double. */
  60. #define EXTRACT_WORDS(ix0,ix1,d) \
  61. do { \
  62. ieee_double_shape_type ew_u; \
  63. ew_u.value = (d); \
  64. (ix0) = ew_u.parts.msw; \
  65. (ix1) = ew_u.parts.lsw; \
  66. } while (0)
  67. /* Get the more significant 32 bit int from a double. */
  68. #define GET_HIGH_WORD(i,d) \
  69. do { \
  70. ieee_double_shape_type gh_u; \
  71. gh_u.value = (d); \
  72. (i) = gh_u.parts.msw; \
  73. } while (0)
  74. /* Get the less significant 32 bit int from a double. */
  75. #define GET_LOW_WORD(i,d) \
  76. do { \
  77. ieee_double_shape_type gl_u; \
  78. gl_u.value = (d); \
  79. (i) = gl_u.parts.lsw; \
  80. } while (0)
  81. /* Set a double from two 32 bit ints. */
  82. #define INSERT_WORDS(d,ix0,ix1) \
  83. do { \
  84. ieee_double_shape_type iw_u; \
  85. iw_u.parts.msw = (ix0); \
  86. iw_u.parts.lsw = (ix1); \
  87. (d) = iw_u.value; \
  88. } while (0)
  89. /* Set the more significant 32 bits of a double from an int. */
  90. #define SET_HIGH_WORD(d,v) \
  91. do { \
  92. ieee_double_shape_type sh_u; \
  93. sh_u.value = (d); \
  94. sh_u.parts.msw = (v); \
  95. (d) = sh_u.value; \
  96. } while (0)
  97. /* Set the less significant 32 bits of a double from an int. */
  98. #define SET_LOW_WORD(d,v) \
  99. do { \
  100. ieee_double_shape_type sl_u; \
  101. sl_u.value = (d); \
  102. sl_u.parts.lsw = (v); \
  103. (d) = sl_u.value; \
  104. } while (0)
  105. /* A union which permits us to convert between a float and a 32 bit
  106. int. */
  107. typedef union
  108. {
  109. float value;
  110. u_int32_t word;
  111. } ieee_float_shape_type;
  112. /* Get a 32 bit int from a float. */
  113. #define GET_FLOAT_WORD(i,d) \
  114. do { \
  115. ieee_float_shape_type gf_u; \
  116. gf_u.value = (d); \
  117. (i) = gf_u.word; \
  118. } while (0)
  119. /* Set a float from a 32 bit int. */
  120. #define SET_FLOAT_WORD(d,i) \
  121. do { \
  122. ieee_float_shape_type sf_u; \
  123. sf_u.word = (i); \
  124. (d) = sf_u.value; \
  125. } while (0)
  126. /* ieee style elementary functions */
  127. extern double __ieee754_sqrt (double) attribute_hidden;
  128. extern double __ieee754_acos (double) attribute_hidden;
  129. extern double __ieee754_acosh (double) attribute_hidden;
  130. extern double __ieee754_log (double) attribute_hidden;
  131. extern double __ieee754_log2 (double) attribute_hidden;
  132. extern double __ieee754_atanh (double) attribute_hidden;
  133. extern double __ieee754_asin (double) attribute_hidden;
  134. extern double __ieee754_atan2 (double,double) attribute_hidden;
  135. extern double __ieee754_exp (double) attribute_hidden;
  136. extern double __ieee754_cosh (double) attribute_hidden;
  137. extern double __ieee754_fmod (double,double) attribute_hidden;
  138. extern double __ieee754_pow (double,double) attribute_hidden;
  139. extern double __ieee754_lgamma_r (double,int *) attribute_hidden;
  140. extern double __ieee754_gamma_r (double,int *) attribute_hidden;
  141. extern double __ieee754_lgamma (double) attribute_hidden;
  142. extern double __ieee754_gamma (double) attribute_hidden;
  143. extern double __ieee754_log10 (double) attribute_hidden;
  144. extern double __ieee754_sinh (double) attribute_hidden;
  145. extern double __ieee754_hypot (double,double) attribute_hidden;
  146. extern double __ieee754_j0 (double) attribute_hidden;
  147. extern double __ieee754_j1 (double) attribute_hidden;
  148. extern double __ieee754_y0 (double) attribute_hidden;
  149. extern double __ieee754_y1 (double) attribute_hidden;
  150. extern double __ieee754_jn (int,double) attribute_hidden;
  151. extern double __ieee754_yn (int,double) attribute_hidden;
  152. extern double __ieee754_remainder (double,double) attribute_hidden;
  153. extern int __ieee754_rem_pio2 (double,double*) attribute_hidden;
  154. #if defined(_SCALB_INT)
  155. extern double __ieee754_scalb (double,int) attribute_hidden;
  156. #else
  157. extern double __ieee754_scalb (double,double) attribute_hidden;
  158. #endif
  159. /* fdlibm kernel function */
  160. #ifndef _IEEE_LIBM
  161. extern double __kernel_standard (double,double,int) attribute_hidden;
  162. #endif
  163. extern double __kernel_sin (double,double,int) attribute_hidden;
  164. extern double __kernel_cos (double,double) attribute_hidden;
  165. extern double __kernel_tan (double,double,int) attribute_hidden;
  166. extern int __kernel_rem_pio2 (double*,double*,int,int,int,const int*) attribute_hidden;
  167. #endif /* _MATH_PRIVATE_H_ */