src/libm/math_private.h
changeset 2756 a98604b691c8
child 2760 02aa80d7905f
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/libm/math_private.h	Mon Sep 15 06:33:23 2008 +0000
     1.3 @@ -0,0 +1,204 @@
     1.4 +/*
     1.5 + * ====================================================
     1.6 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
     1.7 + *
     1.8 + * Developed at SunPro, a Sun Microsystems, Inc. business.
     1.9 + * Permission to use, copy, modify, and distribute this
    1.10 + * software is freely granted, provided that this notice
    1.11 + * is preserved.
    1.12 + * ====================================================
    1.13 + */
    1.14 +
    1.15 +/*
    1.16 + * from: @(#)fdlibm.h 5.1 93/09/24
    1.17 + * $Id: math_private.h,v 1.3 2004/02/09 07:10:38 andersen Exp $
    1.18 + */
    1.19 +
    1.20 +#ifndef _MATH_PRIVATE_H_
    1.21 +#define _MATH_PRIVATE_H_
    1.22 +
    1.23 +/*#include <endian.h>*/
    1.24 +#include <sys/types.h>
    1.25 +
    1.26 +#define attribute_hidden
    1.27 +#define libm_hidden_proto(x)
    1.28 +#define libm_hidden_def(x)
    1.29 +
    1.30 +/* The original fdlibm code used statements like:
    1.31 +	n0 = ((*(int*)&one)>>29)^1;		* index of high word *
    1.32 +	ix0 = *(n0+(int*)&x);			* high word of x *
    1.33 +	ix1 = *((1-n0)+(int*)&x);		* low word of x *
    1.34 +   to dig two 32 bit words out of the 64 bit IEEE floating point
    1.35 +   value.  That is non-ANSI, and, moreover, the gcc instruction
    1.36 +   scheduler gets it wrong.  We instead use the following macros.
    1.37 +   Unlike the original code, we determine the endianness at compile
    1.38 +   time, not at run time; I don't see much benefit to selecting
    1.39 +   endianness at run time.  */
    1.40 +
    1.41 +/* A union which permits us to convert between a double and two 32 bit
    1.42 +   ints.  */
    1.43 +
    1.44 +/*
    1.45 + * Math on arm is special:
    1.46 + * For FPA, float words are always big-endian.
    1.47 + * For VFP, floats words follow the memory system mode.
    1.48 + */
    1.49 +
    1.50 +#if (__BYTE_ORDER == __BIG_ENDIAN) || \
    1.51 +    (!defined(__VFP_FP__) && (defined(__arm__) || defined(__thumb__)))
    1.52 +
    1.53 +typedef union
    1.54 +{
    1.55 +    double value;
    1.56 +    struct
    1.57 +    {
    1.58 +        u_int32_t msw;
    1.59 +        u_int32_t lsw;
    1.60 +    } parts;
    1.61 +} ieee_double_shape_type;
    1.62 +
    1.63 +#else
    1.64 +
    1.65 +typedef union
    1.66 +{
    1.67 +    double value;
    1.68 +    struct
    1.69 +    {
    1.70 +        u_int32_t lsw;
    1.71 +        u_int32_t msw;
    1.72 +    } parts;
    1.73 +} ieee_double_shape_type;
    1.74 +
    1.75 +#endif
    1.76 +
    1.77 +/* Get two 32 bit ints from a double.  */
    1.78 +
    1.79 +#define EXTRACT_WORDS(ix0,ix1,d)				\
    1.80 +do {								\
    1.81 +  ieee_double_shape_type ew_u;					\
    1.82 +  ew_u.value = (d);						\
    1.83 +  (ix0) = ew_u.parts.msw;					\
    1.84 +  (ix1) = ew_u.parts.lsw;					\
    1.85 +} while (0)
    1.86 +
    1.87 +/* Get the more significant 32 bit int from a double.  */
    1.88 +
    1.89 +#define GET_HIGH_WORD(i,d)					\
    1.90 +do {								\
    1.91 +  ieee_double_shape_type gh_u;					\
    1.92 +  gh_u.value = (d);						\
    1.93 +  (i) = gh_u.parts.msw;						\
    1.94 +} while (0)
    1.95 +
    1.96 +/* Get the less significant 32 bit int from a double.  */
    1.97 +
    1.98 +#define GET_LOW_WORD(i,d)					\
    1.99 +do {								\
   1.100 +  ieee_double_shape_type gl_u;					\
   1.101 +  gl_u.value = (d);						\
   1.102 +  (i) = gl_u.parts.lsw;						\
   1.103 +} while (0)
   1.104 +
   1.105 +/* Set a double from two 32 bit ints.  */
   1.106 +
   1.107 +#define INSERT_WORDS(d,ix0,ix1)					\
   1.108 +do {								\
   1.109 +  ieee_double_shape_type iw_u;					\
   1.110 +  iw_u.parts.msw = (ix0);					\
   1.111 +  iw_u.parts.lsw = (ix1);					\
   1.112 +  (d) = iw_u.value;						\
   1.113 +} while (0)
   1.114 +
   1.115 +/* Set the more significant 32 bits of a double from an int.  */
   1.116 +
   1.117 +#define SET_HIGH_WORD(d,v)					\
   1.118 +do {								\
   1.119 +  ieee_double_shape_type sh_u;					\
   1.120 +  sh_u.value = (d);						\
   1.121 +  sh_u.parts.msw = (v);						\
   1.122 +  (d) = sh_u.value;						\
   1.123 +} while (0)
   1.124 +
   1.125 +/* Set the less significant 32 bits of a double from an int.  */
   1.126 +
   1.127 +#define SET_LOW_WORD(d,v)					\
   1.128 +do {								\
   1.129 +  ieee_double_shape_type sl_u;					\
   1.130 +  sl_u.value = (d);						\
   1.131 +  sl_u.parts.lsw = (v);						\
   1.132 +  (d) = sl_u.value;						\
   1.133 +} while (0)
   1.134 +
   1.135 +/* A union which permits us to convert between a float and a 32 bit
   1.136 +   int.  */
   1.137 +
   1.138 +typedef union
   1.139 +{
   1.140 +    float value;
   1.141 +    u_int32_t word;
   1.142 +} ieee_float_shape_type;
   1.143 +
   1.144 +/* Get a 32 bit int from a float.  */
   1.145 +
   1.146 +#define GET_FLOAT_WORD(i,d)					\
   1.147 +do {								\
   1.148 +  ieee_float_shape_type gf_u;					\
   1.149 +  gf_u.value = (d);						\
   1.150 +  (i) = gf_u.word;						\
   1.151 +} while (0)
   1.152 +
   1.153 +/* Set a float from a 32 bit int.  */
   1.154 +
   1.155 +#define SET_FLOAT_WORD(d,i)					\
   1.156 +do {								\
   1.157 +  ieee_float_shape_type sf_u;					\
   1.158 +  sf_u.word = (i);						\
   1.159 +  (d) = sf_u.value;						\
   1.160 +} while (0)
   1.161 +
   1.162 +/* ieee style elementary functions */
   1.163 +extern double
   1.164 +__ieee754_sqrt(double)
   1.165 +    attribute_hidden;
   1.166 +     extern double __ieee754_acos(double) attribute_hidden;
   1.167 +     extern double __ieee754_acosh(double) attribute_hidden;
   1.168 +     extern double __ieee754_log(double) attribute_hidden;
   1.169 +     extern double __ieee754_atanh(double) attribute_hidden;
   1.170 +     extern double __ieee754_asin(double) attribute_hidden;
   1.171 +     extern double __ieee754_atan2(double, double) attribute_hidden;
   1.172 +     extern double __ieee754_exp(double) attribute_hidden;
   1.173 +     extern double __ieee754_cosh(double) attribute_hidden;
   1.174 +     extern double __ieee754_fmod(double, double) attribute_hidden;
   1.175 +     extern double __ieee754_pow(double, double) attribute_hidden;
   1.176 +     extern double __ieee754_lgamma_r(double, int *) attribute_hidden;
   1.177 +     extern double __ieee754_gamma_r(double, int *) attribute_hidden;
   1.178 +     extern double __ieee754_lgamma(double) attribute_hidden;
   1.179 +     extern double __ieee754_gamma(double) attribute_hidden;
   1.180 +     extern double __ieee754_log10(double) attribute_hidden;
   1.181 +     extern double __ieee754_sinh(double) attribute_hidden;
   1.182 +     extern double __ieee754_hypot(double, double) attribute_hidden;
   1.183 +     extern double __ieee754_j0(double) attribute_hidden;
   1.184 +     extern double __ieee754_j1(double) attribute_hidden;
   1.185 +     extern double __ieee754_y0(double) attribute_hidden;
   1.186 +     extern double __ieee754_y1(double) attribute_hidden;
   1.187 +     extern double __ieee754_jn(int, double) attribute_hidden;
   1.188 +     extern double __ieee754_yn(int, double) attribute_hidden;
   1.189 +     extern double __ieee754_remainder(double, double) attribute_hidden;
   1.190 +     extern int __ieee754_rem_pio2(double, double *) attribute_hidden;
   1.191 +#if defined(_SCALB_INT)
   1.192 +     extern double __ieee754_scalb(double, int) attribute_hidden;
   1.193 +#else
   1.194 +     extern double __ieee754_scalb(double, double) attribute_hidden;
   1.195 +#endif
   1.196 +
   1.197 +/* fdlibm kernel function */
   1.198 +#ifndef _IEEE_LIBM
   1.199 +     extern double __kernel_standard(double, double, int) attribute_hidden;
   1.200 +#endif
   1.201 +     extern double __kernel_sin(double, double, int) attribute_hidden;
   1.202 +     extern double __kernel_cos(double, double) attribute_hidden;
   1.203 +     extern double __kernel_tan(double, double, int) attribute_hidden;
   1.204 +     extern int __kernel_rem_pio2(double *, double *, int, int, int,
   1.205 +                                  const int *) attribute_hidden;
   1.206 +
   1.207 +#endif /* _MATH_PRIVATE_H_ */