Fixed Visual C++ release build for Visual C++ 2005
authorSam Lantinga <slouken@libsdl.org>
Sat, 10 Jan 2009 18:32:24 +0000
changeset 30127e30c2dc7783
parent 3011 8f4ed5ec2b06
child 3013 8cc00819c8d6
Fixed Visual C++ release build for Visual C++ 2005
* Some math functions become intrinsic in release mode, so we need to
convert all the math functions into SDL math functions, like we did
with the stdlib functions.
* Constant initializers of 8-bit values become calls to memset() in
release mode, but memset() itself is an intrinsic when explicitly
called. So we'll just explicitly call memset() in those cases.
acinclude.m4
configure.in
include/SDL_config.h.in
include/SDL_config_win32.h
include/SDL_stdinc.h
src/audio/SDL_audiocvt.c
src/libm/math.h
src/video/SDL_fillrect.c
src/video/SDL_gamma.c
     1.1 --- a/acinclude.m4	Fri Jan 09 20:43:30 2009 +0000
     1.2 +++ b/acinclude.m4	Sat Jan 10 18:32:24 2009 +0000
     1.3 @@ -1,3 +1,18 @@
     1.4 +define(AC_CHECK_DEFINE,[dnl
     1.5 +  AC_CACHE_CHECK(for $1 in $2, ac_cv_define_$1,
     1.6 +    AC_EGREP_CPP([YES_IS_DEFINED], [
     1.7 +#include <$2>
     1.8 +#ifdef $1
     1.9 +YES_IS_DEFINED
    1.10 +#endif
    1.11 +    ], ac_cv_define_$1=yes, ac_cv_define_$1=no)
    1.12 +  )
    1.13 +  if test "$ac_cv_define_$1" = "yes" ; then
    1.14 +    AC_DEFINE(HAVE_$1)
    1.15 +  fi
    1.16 +])dnl
    1.17 +AC_DEFINE(HAVE_$1)
    1.18 +
    1.19  ##############################################################################
    1.20  dnl Configure Paths for Alsa
    1.21  dnl Some modifications by Richard Boulton <richard-alsa@tartarus.org>
     2.1 --- a/configure.in	Fri Jan 09 20:43:30 2009 +0000
     2.2 +++ b/configure.in	Sat Jan 10 18:32:24 2009 +0000
     2.3 @@ -129,6 +129,9 @@
     2.4          have_inttypes=yes
     2.5      fi
     2.6  
     2.7 +    dnl Check for defines
     2.8 +    AC_CHECK_DEFINE(M_PI, math.h)
     2.9 +
    2.10      dnl Checks for library functions.
    2.11      case "$host" in
    2.12      *-*-cygwin* | *-*-mingw32*)
    2.13 @@ -146,10 +149,10 @@
    2.14      if test x$ac_cv_func_strtod = xyes; then
    2.15          AC_DEFINE(HAVE_STRTOD)
    2.16      fi
    2.17 -    AC_CHECK_FUNCS(malloc calloc realloc free getenv putenv unsetenv qsort abs bcopy memset memcpy memmove strlen strlcpy strlcat strdup _strrev _strupr _strlwr strchr strrchr strstr itoa _ltoa _uitoa _ultoa strtol strtoul _i64toa _ui64toa strtoll strtoull atoi atof strcmp strncmp _stricmp strcasecmp _strnicmp strncasecmp sscanf snprintf vsnprintf iconv sigaction setjmp nanosleep)
    2.18 +    AC_CHECK_FUNCS(malloc calloc realloc free getenv putenv unsetenv qsort abs bcopy memset memcpy memmove strlen strlcpy strlcat strdup _strrev _strupr _strlwr strchr strrchr strstr itoa _ltoa _uitoa _ultoa strtol strtoul _i64toa _ui64toa strtoll strtoull atoi atof strcmp strncmp _stricmp strcasecmp _strnicmp strncasecmp sscanf snprintf vsnprintf copysign cos cosf fabs floor log pow scalbn sin sinf sqrt iconv sigaction setjmp nanosleep)
    2.19  
    2.20 +    AC_CHECK_LIB(m, pow, [EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lm"])
    2.21      AC_CHECK_LIB(iconv, libiconv_open, [EXTRA_LDFLAGS="$EXTRA_LDFLAGS -liconv"])
    2.22 -    AC_CHECK_LIB(m, pow, [EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lm"])
    2.23  fi
    2.24  
    2.25  if test x$have_inttypes != xyes; then
     3.1 --- a/include/SDL_config.h.in	Fri Jan 09 20:43:30 2009 +0000
     3.2 +++ b/include/SDL_config.h.in	Sat Jan 10 18:32:24 2009 +0000
     3.3 @@ -129,7 +129,18 @@
     3.4  #undef HAVE_SSCANF
     3.5  #undef HAVE_SNPRINTF
     3.6  #undef HAVE_VSNPRINTF
     3.7 -#undef HAVE_ICONV
     3.8 +#undef HAVE_M_PI
     3.9 +#undef HAVE_COPYSIGN
    3.10 +#undef HAVE_COS
    3.11 +#undef HAVE_COSF
    3.12 +#undef HAVE_FABS
    3.13 +#undef HAVE_FLOOR
    3.14 +#undef HAVE_LOG
    3.15 +#undef HAVE_POW
    3.16 +#undef HAVE_SCALBN
    3.17 +#undef HAVE_SIN
    3.18 +#undef HAVE_SINF
    3.19 +#undef HAVE_SQRT
    3.20  #undef HAVE_SIGACTION
    3.21  #undef HAVE_SETJMP
    3.22  #undef HAVE_NANOSLEEP
     4.1 --- a/include/SDL_config_win32.h	Fri Jan 09 20:43:30 2009 +0000
     4.2 +++ b/include/SDL_config_win32.h	Sat Jan 10 18:32:24 2009 +0000
     4.3 @@ -116,6 +116,18 @@
     4.4  #define HAVE__STRICMP 1
     4.5  #define HAVE__STRNICMP 1
     4.6  #define HAVE_SSCANF 1
     4.7 +#define HAVE_M_PI 1
     4.8 +#define HAVE_COPYSIGN 1
     4.9 +#define HAVE_COS 1
    4.10 +#define HAVE_COSF 1
    4.11 +#define HAVE_FABS 1
    4.12 +#define HAVE_FLOOR 1
    4.13 +#define HAVE_LOG 1
    4.14 +#define HAVE_POW 1
    4.15 +#define HAVE_SCALBN 1
    4.16 +#define HAVE_SIN 1
    4.17 +#define HAVE_SINF 1
    4.18 +#define HAVE_SQRT 1
    4.19  #else
    4.20  #define HAVE_STDARG_H	1
    4.21  #define HAVE_STDDEF_H	1
     5.1 --- a/include/SDL_stdinc.h	Fri Jan 09 20:43:30 2009 +0000
     5.2 +++ b/include/SDL_stdinc.h	Sat Jan 10 18:32:24 2009 +0000
     5.3 @@ -72,6 +72,9 @@
     5.4  #ifdef HAVE_CTYPE_H
     5.5  # include <ctype.h>
     5.6  #endif
     5.7 +#ifdef HAVE_MATH_H
     5.8 +# include <math.h>
     5.9 +#endif
    5.10  #ifdef HAVE_ICONV_H
    5.11  # include <iconv.h>
    5.12  #endif
    5.13 @@ -639,6 +642,76 @@
    5.14                                            const char *fmt, va_list ap);
    5.15  #endif
    5.16  
    5.17 +#ifndef HAVE_M_PI
    5.18 +#define M_PI    3.14159265358979323846264338327950288   /* pi */
    5.19 +#endif
    5.20 +
    5.21 +#ifdef HAVE_COPYSIGN
    5.22 +#define SDL_copysign    copysign
    5.23 +#else
    5.24 +extern DECLSPEC double SDLCALL SDL_copysign(double x, double y);
    5.25 +#endif
    5.26 +
    5.27 +#ifdef HAVE_COS
    5.28 +#define SDL_cos         cos
    5.29 +#else
    5.30 +extern DECLSPEC double SDLCALL SDL_cos(double x);
    5.31 +#endif
    5.32 +
    5.33 +#ifdef HAVE_COSF
    5.34 +#define SDL_cosf        cosf
    5.35 +#else
    5.36 +#define SDL_cosf(x) (float)SDL_cos((double)x)
    5.37 +#endif
    5.38 +
    5.39 +#ifdef HAVE_FABS
    5.40 +#define SDL_fabs        fabs
    5.41 +#else
    5.42 +extern DECLSPEC double SDLCALL SDL_fabs(double x);
    5.43 +#endif
    5.44 +
    5.45 +#ifdef HAVE_FLOOR
    5.46 +#define SDL_floor       floor
    5.47 +#else
    5.48 +extern DECLSPEC double SDLCALL SDL_floor(double x);
    5.49 +#endif
    5.50 +
    5.51 +#ifdef HAVE_LOG
    5.52 +#define SDL_log         log
    5.53 +#else
    5.54 +extern DECLSPEC double SDLCALL SDL_log(double x);
    5.55 +#endif
    5.56 +
    5.57 +#ifdef HAVE_POW
    5.58 +#define SDL_pow         pow
    5.59 +#else
    5.60 +extern DECLSPEC double SDLCALL SDL_pow(double x, double y);
    5.61 +#endif
    5.62 +
    5.63 +#ifdef HAVE_SCALBN
    5.64 +#define SDL_scalbn      scalbn
    5.65 +#else
    5.66 +extern DECLSPEC double SDLCALL SDL_scalbn(double x, int n);
    5.67 +#endif
    5.68 +
    5.69 +#ifdef HAVE_SIN
    5.70 +#define SDL_sin         sin
    5.71 +#else
    5.72 +extern DECLSPEC double SDLCALL SDL_sin(double x);
    5.73 +#endif
    5.74 +
    5.75 +#ifdef HAVE_SINF
    5.76 +#define SDL_sinf        sinf
    5.77 +#else
    5.78 +#define SDL_sinf(x) (float)SDL_sin((double)x)
    5.79 +#endif
    5.80 +
    5.81 +#ifdef HAVE_SQRT
    5.82 +#define SDL_sqrt        sqrt
    5.83 +#else
    5.84 +extern DECLSPEC double SDLCALL SDL_sqrt(double x);
    5.85 +#endif
    5.86 +
    5.87  /* The SDL implementation of iconv() returns these error codes */
    5.88  #define SDL_ICONV_ERROR		(size_t)-1
    5.89  #define SDL_ICONV_E2BIG		(size_t)-2
     6.1 --- a/src/audio/SDL_audiocvt.c	Fri Jan 09 20:43:30 2009 +0000
     6.2 +++ b/src/audio/SDL_audiocvt.c	Sat Jan 10 18:32:24 2009 +0000
     6.3 @@ -26,8 +26,6 @@
     6.4  #include "SDL_audio.h"
     6.5  #include "SDL_audio_c.h"
     6.6  
     6.7 -#include "../libm/math.h"
     6.8 -
     6.9  //#define DEBUG_CONVERT
    6.10  
    6.11  /* These are fractional multiplication routines. That is, their inputs
    6.12 @@ -1658,13 +1656,9 @@
    6.13          if (i == m / 2) {
    6.14              fSinc[i] = two_pi_fc;
    6.15          } else {
    6.16 -            fSinc[i] =
    6.17 -                sinf(two_pi_fc * ((float) i - m_over_two)) / ((float) i -
    6.18 -                                                              m_over_two);
    6.19 +            fSinc[i] = SDL_sinf(two_pi_fc * ((float) i - m_over_two)) / ((float) i - m_over_two);
    6.20              /* Apply blackman window */
    6.21 -            fSinc[i] *=
    6.22 -                0.42f - 0.5f * cosf(two_pi_over_m * (float) i) +
    6.23 -                0.08f * cosf(four_pi_over_m * (float) i);
    6.24 +            fSinc[i] *= 0.42f - 0.5f * SDL_cosf(two_pi_over_m * (float) i) + 0.08f * SDL_cosf(four_pi_over_m * (float) i);
    6.25          }
    6.26          norm_sum += fSinc[i] < 0 ? -fSinc[i] : fSinc[i];        /* fabs(fSinc[i]); */
    6.27      }
    6.28 @@ -1740,7 +1734,7 @@
    6.29  static void SDLCALL
    6.30  SDL_Resample(SDL_AudioCVT * cvt, SDL_AudioFormat format)
    6.31  {
    6.32 -    int i, j;
    6.33 +    int i;
    6.34  
    6.35  #ifdef DEBUG_CONVERT
    6.36      printf("Converting audio rate via proper resampling (mono)\n");
    6.37 @@ -1752,8 +1746,8 @@
    6.38          for (i = cvt->len / sizeof (type); i; --i) { \
    6.39              src--; \
    6.40              dst[-1] = src[0]; \
    6.41 -            for( j = -cvt->len_mult; j < -1; ++j ) { \
    6.42 -                dst[j] = 0; \
    6.43 +            if (cvt->len_mult > 1) { \
    6.44 +                SDL_memset(dst-cvt->len_mult, 0, cvt->len_mult-1); \
    6.45              } \
    6.46              dst -= cvt->len_mult; \
    6.47          } \
     7.1 --- a/src/libm/math.h	Fri Jan 09 20:43:30 2009 +0000
     7.2 +++ b/src/libm/math.h	Sat Jan 10 18:32:24 2009 +0000
     7.3 @@ -20,34 +20,56 @@
     7.4      slouken@libsdl.org
     7.5  */
     7.6  #include "SDL_config.h"
     7.7 -
     7.8 -#ifdef HAVE_MATH_H
     7.9 -#define _USE_MATH_DEFINES
    7.10 -#include <math.h>
    7.11 -#else
    7.12 +#include "SDL_stdinc.h"
    7.13  
    7.14  /* Math routines from uClibc: http://www.uclibc.org */
    7.15  
    7.16 -#define M_PI    3.14159265358979323846264338327950288   /* pi */
    7.17 +#ifdef HAVE_COPYSIGN
    7.18 +#define copysign        SDL_uclibc_copysign
    7.19 +#else
    7.20 +#define copysign        SDL_copysign
    7.21 +#endif
    7.22 +
    7.23 +#ifdef HAVE_COS
    7.24 +#define cos             SDL_uclibc_cos
    7.25 +#else
    7.26 +#define cos             SDL_cos
    7.27 +#endif
    7.28  
    7.29 -extern double __ieee754_log(double x);
    7.30 -extern double __ieee754_pow(double x, double y);
    7.31 -extern double __ieee754_sqrt(double x);
    7.32 +#ifdef HAVE_FABS
    7.33 +#define fabs            SDL_uclibc_fabs
    7.34 +#else
    7.35 +#define fabs            SDL_fabs
    7.36 +#endif
    7.37  
    7.38 -#define log(x)      __ieee754_log(x)
    7.39 -#define pow(x, y)   __ieee754_pow(x, y)
    7.40 -#define sqrt(x)     __ieee754_sqrt(x)
    7.41 +#ifdef HAVE_FLOOR
    7.42 +#define floor           SDL_uclibc_floor
    7.43 +#else
    7.44 +#define floor           SDL_floor
    7.45 +#endif
    7.46  
    7.47 -extern double copysign(double x, double y);
    7.48 -extern double cos(double x);
    7.49 -extern double fabs(double x);
    7.50 -extern double floor(double x);
    7.51 -extern double scalbn(double x, int n);
    7.52 -extern double sin(double x);
    7.53 +#ifndef HAVE_LOG
    7.54 +#define __ieee754_log   SDL_log
    7.55 +#endif
    7.56 +
    7.57 +#ifndef HAVE_POW
    7.58 +#define __ieee754_pow   SDL_pow
    7.59 +#endif
    7.60  
    7.61 -#define sinf(x) (float)sin((double)x)
    7.62 -#define cosf(x) (float)cos((double)x)
    7.63 +#ifdef HAVE_SCALBN
    7.64 +#define scalbn          SDL_uclibc_scalbn
    7.65 +#else
    7.66 +#define scalbn          SDL_scalbn
    7.67 +#endif
    7.68  
    7.69 -#endif /* HAVE_MATH_H */
    7.70 +#ifdef HAVE_SIN
    7.71 +#define sin             SDL_uclibc_sin
    7.72 +#else
    7.73 +#define sin             SDL_sin
    7.74 +#endif
    7.75 +
    7.76 +#ifndef HAVE_SQRT
    7.77 +#define __ieee754_sqrt  SDL_sqrt
    7.78 +#endif
    7.79  
    7.80  /* vi: set ts=4 sw=4 expandtab: */
     8.1 --- a/src/video/SDL_fillrect.c	Fri Jan 09 20:43:30 2009 +0000
     8.2 +++ b/src/video/SDL_fillrect.c	Sat Jan 10 18:32:24 2009 +0000
     8.3 @@ -66,7 +66,7 @@
     8.4          int i, n = w * bpp; \
     8.5          Uint8 *p = pixels; \
     8.6   \
     8.7 -        if (n > 15) { \
     8.8 +        if (n > 63) { \
     8.9              int adjust = 16 - ((uintptr_t)p & 15); \
    8.10              if (adjust < 16) { \
    8.11                  n -= adjust; \
    8.12 @@ -92,7 +92,35 @@
    8.13      SSE_END; \
    8.14  }
    8.15  
    8.16 -DEFINE_SSE_FILLRECT(1, Uint8)
    8.17 +static void
    8.18 +SDL_FillRect1SSE(Uint8 *pixels, int pitch, Uint32 color, int w, int h)
    8.19 +{
    8.20 +    SSE_BEGIN;
    8.21 +
    8.22 +    while (h--) {
    8.23 +        int i, n = w;
    8.24 +        Uint8 *p = pixels;
    8.25 +
    8.26 +        if (n > 63) {
    8.27 +            int adjust = 16 - ((uintptr_t)p & 15);
    8.28 +            if (adjust) {
    8.29 +                n -= adjust;
    8.30 +                SDL_memset(p, color, adjust);
    8.31 +                p += adjust;
    8.32 +            }
    8.33 +            SSE_WORK;
    8.34 +        }
    8.35 +        if (n & 63) {
    8.36 +            int remainder = (n & 63);
    8.37 +            SDL_memset(p, color, remainder);
    8.38 +            p += remainder;
    8.39 +        }
    8.40 +        pixels += pitch;
    8.41 +    }
    8.42 +
    8.43 +    SSE_END;
    8.44 +}
    8.45 +/*DEFINE_SSE_FILLRECT(1, Uint8)*/
    8.46  DEFINE_SSE_FILLRECT(2, Uint16)
    8.47  DEFINE_SSE_FILLRECT(4, Uint32)
    8.48  
    8.49 @@ -131,7 +159,7 @@
    8.50          int i, n = w * bpp; \
    8.51          Uint8 *p = pixels; \
    8.52   \
    8.53 -        if (n > 7) { \
    8.54 +        if (n > 63) { \
    8.55              int adjust = 8 - ((uintptr_t)p & 7); \
    8.56              if (adjust < 8) { \
    8.57                  n -= adjust; \
    8.58 @@ -157,7 +185,35 @@
    8.59      MMX_END; \
    8.60  }
    8.61  
    8.62 -DEFINE_MMX_FILLRECT(1, Uint8)
    8.63 +static void
    8.64 +SDL_FillRect1MMX(Uint8 *pixels, int pitch, Uint32 color, int w, int h)
    8.65 +{
    8.66 +    MMX_BEGIN;
    8.67 +
    8.68 +    while (h--) {
    8.69 +        int i, n = w;
    8.70 +        Uint8 *p = pixels;
    8.71 +
    8.72 +        if (n > 63) {
    8.73 +            int adjust = 8 - ((uintptr_t)p & 7);
    8.74 +            if (adjust) {
    8.75 +                n -= adjust;
    8.76 +                SDL_memset(p, color, adjust);
    8.77 +                p += adjust;
    8.78 +            }
    8.79 +            MMX_WORK;
    8.80 +        }
    8.81 +        if (n & 63) {
    8.82 +            int remainder = (n & 63);
    8.83 +            SDL_memset(p, color, remainder);
    8.84 +            p += remainder;
    8.85 +        }
    8.86 +        pixels += pitch;
    8.87 +    }
    8.88 +
    8.89 +    MMX_END;
    8.90 +}
    8.91 +/*DEFINE_MMX_FILLRECT(1, Uint8)*/
    8.92  DEFINE_MMX_FILLRECT(2, Uint16)
    8.93  DEFINE_MMX_FILLRECT(4, Uint32)
    8.94  
     9.1 --- a/src/video/SDL_gamma.c	Fri Jan 09 20:43:30 2009 +0000
     9.2 +++ b/src/video/SDL_gamma.c	Sat Jan 10 18:32:24 2009 +0000
     9.3 @@ -23,8 +23,6 @@
     9.4  
     9.5  /* Gamma correction support */
     9.6  
     9.7 -#include "../libm/math.h"
     9.8 -
     9.9  #include "SDL_sysvideo.h"
    9.10  
    9.11  
    9.12 @@ -52,7 +50,7 @@
    9.13          int value;
    9.14          gamma = 1.0f / gamma;
    9.15          for (i = 0; i < 256; ++i) {
    9.16 -            value = (int) (pow((double) i / 256.0, gamma) * 65535.0 + 0.5);
    9.17 +            value = (int) (SDL_pow((double) i / 256.0, gamma) * 65535.0 + 0.5);
    9.18              if (value > 65535) {
    9.19                  value = 65535;
    9.20              }
    9.21 @@ -75,7 +73,7 @@
    9.22          if ((ramp[i] != 0) && (ramp[i] != 65535)) {
    9.23              double B = (double) i / 256.0;
    9.24              double A = ramp[i] / 65535.0;
    9.25 -            sum += (float) (log(A) / log(B));
    9.26 +			sum += (float) (SDL_log(A) / SDL_log(B));
    9.27              count++;
    9.28          }
    9.29      }