src/libm/math_private.h
author Gabriel Jacobo <gabomdq@gmail.com>
Wed, 21 Aug 2013 09:43:09 -0300
changeset 7677 871d43c6968a
parent 7404 dfbe1bfff593
child 7678 286c42d7c5ed
permissions -rw-r--r--
OCD fixes: Adds a space before */
     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 /*
    13  * from: @(#)fdlibm.h 5.1 93/09/24
    14  * $Id: math_private.h,v 1.3 2004/02/09 07:10:38 andersen Exp $
    15  */
    16 
    17 #ifndef _MATH_PRIVATE_H_
    18 #define _MATH_PRIVATE_H_
    19 
    20 /*#include <endian.h> */
    21 #include "SDL_endian.h"
    22 /*#include <sys/types.h> */
    23 
    24 #define attribute_hidden
    25 #define libm_hidden_proto(x)
    26 #define libm_hidden_def(x)
    27 
    28 #ifndef __HAIKU__ /* already defined in a system header. */
    29 typedef unsigned int u_int32_t;
    30 #endif
    31 
    32 #define atan            SDL_uclibc_atan
    33 #define __ieee754_atan2 SDL_uclibc_atan2
    34 #define copysign        SDL_uclibc_copysign
    35 #define cos             SDL_uclibc_cos
    36 #define fabs            SDL_uclibc_fabs
    37 #define floor           SDL_uclibc_floor
    38 #define __ieee754_log   SDL_uclibc_log
    39 #define __ieee754_pow   SDL_uclibc_pow
    40 #define scalbn          SDL_uclibc_scalbn
    41 #define sin             SDL_uclibc_sin
    42 #define __ieee754_sqrt  SDL_uclibc_sqrt
    43 
    44 /* The original fdlibm code used statements like:
    45 	n0 = ((*(int*)&one)>>29)^1;		* index of high word *
    46 	ix0 = *(n0+(int*)&x);			* high word of x *
    47 	ix1 = *((1-n0)+(int*)&x);		* low word of x *
    48    to dig two 32 bit words out of the 64 bit IEEE floating point
    49    value.  That is non-ANSI, and, moreover, the gcc instruction
    50    scheduler gets it wrong.  We instead use the following macros.
    51    Unlike the original code, we determine the endianness at compile
    52    time, not at run time; I don't see much benefit to selecting
    53    endianness at run time.  */
    54 
    55 /* A union which permits us to convert between a double and two 32 bit
    56    ints.  */
    57 
    58 /*
    59  * Math on arm is special:
    60  * For FPA, float words are always big-endian.
    61  * For VFP, floats words follow the memory system mode.
    62  */
    63 
    64 #if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
    65 
    66 typedef union
    67 {
    68     double value;
    69     struct
    70     {
    71         u_int32_t msw;
    72         u_int32_t lsw;
    73     } parts;
    74 } ieee_double_shape_type;
    75 
    76 #else
    77 
    78 typedef union
    79 {
    80     double value;
    81     struct
    82     {
    83         u_int32_t lsw;
    84         u_int32_t msw;
    85     } parts;
    86 } ieee_double_shape_type;
    87 
    88 #endif
    89 
    90 /* Get two 32 bit ints from a double.  */
    91 
    92 #define EXTRACT_WORDS(ix0,ix1,d)				\
    93 do {								\
    94   ieee_double_shape_type ew_u;					\
    95   ew_u.value = (d);						\
    96   (ix0) = ew_u.parts.msw;					\
    97   (ix1) = ew_u.parts.lsw;					\
    98 } while (0)
    99 
   100 /* Get the more significant 32 bit int from a double.  */
   101 
   102 #define GET_HIGH_WORD(i,d)					\
   103 do {								\
   104   ieee_double_shape_type gh_u;					\
   105   gh_u.value = (d);						\
   106   (i) = gh_u.parts.msw;						\
   107 } while (0)
   108 
   109 /* Get the less significant 32 bit int from a double.  */
   110 
   111 #define GET_LOW_WORD(i,d)					\
   112 do {								\
   113   ieee_double_shape_type gl_u;					\
   114   gl_u.value = (d);						\
   115   (i) = gl_u.parts.lsw;						\
   116 } while (0)
   117 
   118 /* Set a double from two 32 bit ints.  */
   119 
   120 #define INSERT_WORDS(d,ix0,ix1)					\
   121 do {								\
   122   ieee_double_shape_type iw_u;					\
   123   iw_u.parts.msw = (ix0);					\
   124   iw_u.parts.lsw = (ix1);					\
   125   (d) = iw_u.value;						\
   126 } while (0)
   127 
   128 /* Set the more significant 32 bits of a double from an int.  */
   129 
   130 #define SET_HIGH_WORD(d,v)					\
   131 do {								\
   132   ieee_double_shape_type sh_u;					\
   133   sh_u.value = (d);						\
   134   sh_u.parts.msw = (v);						\
   135   (d) = sh_u.value;						\
   136 } while (0)
   137 
   138 /* Set the less significant 32 bits of a double from an int.  */
   139 
   140 #define SET_LOW_WORD(d,v)					\
   141 do {								\
   142   ieee_double_shape_type sl_u;					\
   143   sl_u.value = (d);						\
   144   sl_u.parts.lsw = (v);						\
   145   (d) = sl_u.value;						\
   146 } while (0)
   147 
   148 /* A union which permits us to convert between a float and a 32 bit
   149    int.  */
   150 
   151 typedef union
   152 {
   153     float value;
   154     u_int32_t word;
   155 } ieee_float_shape_type;
   156 
   157 /* Get a 32 bit int from a float.  */
   158 
   159 #define GET_FLOAT_WORD(i,d)					\
   160 do {								\
   161   ieee_float_shape_type gf_u;					\
   162   gf_u.value = (d);						\
   163   (i) = gf_u.word;						\
   164 } while (0)
   165 
   166 /* Set a float from a 32 bit int.  */
   167 
   168 #define SET_FLOAT_WORD(d,i)					\
   169 do {								\
   170   ieee_float_shape_type sf_u;					\
   171   sf_u.word = (i);						\
   172   (d) = sf_u.value;						\
   173 } while (0)
   174 
   175 /* ieee style elementary functions */
   176 extern double
   177 __ieee754_sqrt(double)
   178     attribute_hidden;
   179      extern double __ieee754_acos(double) attribute_hidden;
   180      extern double __ieee754_acosh(double) attribute_hidden;
   181      extern double __ieee754_log(double) attribute_hidden;
   182      extern double __ieee754_atanh(double) attribute_hidden;
   183      extern double __ieee754_asin(double) attribute_hidden;
   184      extern double __ieee754_atan2(double, double) attribute_hidden;
   185      extern double __ieee754_exp(double) attribute_hidden;
   186      extern double __ieee754_cosh(double) attribute_hidden;
   187      extern double __ieee754_fmod(double, double) attribute_hidden;
   188      extern double __ieee754_pow(double, double) attribute_hidden;
   189      extern double __ieee754_lgamma_r(double, int *) attribute_hidden;
   190      extern double __ieee754_gamma_r(double, int *) attribute_hidden;
   191      extern double __ieee754_lgamma(double) attribute_hidden;
   192      extern double __ieee754_gamma(double) attribute_hidden;
   193      extern double __ieee754_log10(double) attribute_hidden;
   194      extern double __ieee754_sinh(double) attribute_hidden;
   195      extern double __ieee754_hypot(double, double) attribute_hidden;
   196      extern double __ieee754_j0(double) attribute_hidden;
   197      extern double __ieee754_j1(double) attribute_hidden;
   198      extern double __ieee754_y0(double) attribute_hidden;
   199      extern double __ieee754_y1(double) attribute_hidden;
   200      extern double __ieee754_jn(int, double) attribute_hidden;
   201      extern double __ieee754_yn(int, double) attribute_hidden;
   202      extern double __ieee754_remainder(double, double) attribute_hidden;
   203      extern int __ieee754_rem_pio2(double, double *) attribute_hidden;
   204 #if defined(_SCALB_INT)
   205      extern double __ieee754_scalb(double, int) attribute_hidden;
   206 #else
   207      extern double __ieee754_scalb(double, double) attribute_hidden;
   208 #endif
   209 
   210 /* fdlibm kernel function */
   211 #ifndef _IEEE_LIBM
   212      extern double __kernel_standard(double, double, int) attribute_hidden;
   213 #endif
   214      extern double __kernel_sin(double, double, int) attribute_hidden;
   215      extern double __kernel_cos(double, double) attribute_hidden;
   216      extern double __kernel_tan(double, double, int) attribute_hidden;
   217      extern int __kernel_rem_pio2(double *, double *, int, int, int,
   218                                   const int *) attribute_hidden;
   219 
   220 #endif /* _MATH_PRIVATE_H_ */