src/libm/math_private.h
author Sam Lantinga
Fri, 05 Jul 2013 23:57:19 -0700
changeset 7351 668a3dc28361
parent 5086 c2539ff054c8
child 7404 dfbe1bfff593
permissions -rw-r--r--
Removed the inline functions from SDL_stdinc.h
Having the SDL functions inline is causing build issues, and in the case of malloc(), etc. causing malloc/free mismatches, if the application build environment differs from the SDL build environment.

In the interest of safety and consistency, the functions will always be in the SDL library and will only be redirected to the C library there, if they are available.

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