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