src/libm/math_private.h
author Ryan C. Gordon <icculus@icculus.org>
Mon, 21 May 2018 12:00:21 -0400
changeset 11994 8e094f91ddab
parent 11852 c3fc99758ad2
child 12068 ce88faaf8bd2
permissions -rw-r--r--
thread: fixed compiler warnings on non-Linux systems that use pthread.

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