changeset 3012:7e30c2dc7783

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.
author Sam Lantinga <slouken@libsdl.org>
date Sat, 10 Jan 2009 18:32:24 +0000
parents 8f4ed5ec2b06
children 8cc00819c8d6
files 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
diffstat 9 files changed, 227 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/acinclude.m4	Fri Jan 09 20:43:30 2009 +0000
+++ b/acinclude.m4	Sat Jan 10 18:32:24 2009 +0000
@@ -1,3 +1,18 @@
+define(AC_CHECK_DEFINE,[dnl
+  AC_CACHE_CHECK(for $1 in $2, ac_cv_define_$1,
+    AC_EGREP_CPP([YES_IS_DEFINED], [
+#include <$2>
+#ifdef $1
+YES_IS_DEFINED
+#endif
+    ], ac_cv_define_$1=yes, ac_cv_define_$1=no)
+  )
+  if test "$ac_cv_define_$1" = "yes" ; then
+    AC_DEFINE(HAVE_$1)
+  fi
+])dnl
+AC_DEFINE(HAVE_$1)
+
 ##############################################################################
 dnl Configure Paths for Alsa
 dnl Some modifications by Richard Boulton <richard-alsa@tartarus.org>
--- a/configure.in	Fri Jan 09 20:43:30 2009 +0000
+++ b/configure.in	Sat Jan 10 18:32:24 2009 +0000
@@ -129,6 +129,9 @@
         have_inttypes=yes
     fi
 
+    dnl Check for defines
+    AC_CHECK_DEFINE(M_PI, math.h)
+
     dnl Checks for library functions.
     case "$host" in
     *-*-cygwin* | *-*-mingw32*)
@@ -146,10 +149,10 @@
     if test x$ac_cv_func_strtod = xyes; then
         AC_DEFINE(HAVE_STRTOD)
     fi
-    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)
+    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)
 
+    AC_CHECK_LIB(m, pow, [EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lm"])
     AC_CHECK_LIB(iconv, libiconv_open, [EXTRA_LDFLAGS="$EXTRA_LDFLAGS -liconv"])
-    AC_CHECK_LIB(m, pow, [EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lm"])
 fi
 
 if test x$have_inttypes != xyes; then
--- a/include/SDL_config.h.in	Fri Jan 09 20:43:30 2009 +0000
+++ b/include/SDL_config.h.in	Sat Jan 10 18:32:24 2009 +0000
@@ -129,7 +129,18 @@
 #undef HAVE_SSCANF
 #undef HAVE_SNPRINTF
 #undef HAVE_VSNPRINTF
-#undef HAVE_ICONV
+#undef HAVE_M_PI
+#undef HAVE_COPYSIGN
+#undef HAVE_COS
+#undef HAVE_COSF
+#undef HAVE_FABS
+#undef HAVE_FLOOR
+#undef HAVE_LOG
+#undef HAVE_POW
+#undef HAVE_SCALBN
+#undef HAVE_SIN
+#undef HAVE_SINF
+#undef HAVE_SQRT
 #undef HAVE_SIGACTION
 #undef HAVE_SETJMP
 #undef HAVE_NANOSLEEP
--- a/include/SDL_config_win32.h	Fri Jan 09 20:43:30 2009 +0000
+++ b/include/SDL_config_win32.h	Sat Jan 10 18:32:24 2009 +0000
@@ -116,6 +116,18 @@
 #define HAVE__STRICMP 1
 #define HAVE__STRNICMP 1
 #define HAVE_SSCANF 1
+#define HAVE_M_PI 1
+#define HAVE_COPYSIGN 1
+#define HAVE_COS 1
+#define HAVE_COSF 1
+#define HAVE_FABS 1
+#define HAVE_FLOOR 1
+#define HAVE_LOG 1
+#define HAVE_POW 1
+#define HAVE_SCALBN 1
+#define HAVE_SIN 1
+#define HAVE_SINF 1
+#define HAVE_SQRT 1
 #else
 #define HAVE_STDARG_H	1
 #define HAVE_STDDEF_H	1
--- a/include/SDL_stdinc.h	Fri Jan 09 20:43:30 2009 +0000
+++ b/include/SDL_stdinc.h	Sat Jan 10 18:32:24 2009 +0000
@@ -72,6 +72,9 @@
 #ifdef HAVE_CTYPE_H
 # include <ctype.h>
 #endif
+#ifdef HAVE_MATH_H
+# include <math.h>
+#endif
 #ifdef HAVE_ICONV_H
 # include <iconv.h>
 #endif
@@ -639,6 +642,76 @@
                                           const char *fmt, va_list ap);
 #endif
 
+#ifndef HAVE_M_PI
+#define M_PI    3.14159265358979323846264338327950288   /* pi */
+#endif
+
+#ifdef HAVE_COPYSIGN
+#define SDL_copysign    copysign
+#else
+extern DECLSPEC double SDLCALL SDL_copysign(double x, double y);
+#endif
+
+#ifdef HAVE_COS
+#define SDL_cos         cos
+#else
+extern DECLSPEC double SDLCALL SDL_cos(double x);
+#endif
+
+#ifdef HAVE_COSF
+#define SDL_cosf        cosf
+#else
+#define SDL_cosf(x) (float)SDL_cos((double)x)
+#endif
+
+#ifdef HAVE_FABS
+#define SDL_fabs        fabs
+#else
+extern DECLSPEC double SDLCALL SDL_fabs(double x);
+#endif
+
+#ifdef HAVE_FLOOR
+#define SDL_floor       floor
+#else
+extern DECLSPEC double SDLCALL SDL_floor(double x);
+#endif
+
+#ifdef HAVE_LOG
+#define SDL_log         log
+#else
+extern DECLSPEC double SDLCALL SDL_log(double x);
+#endif
+
+#ifdef HAVE_POW
+#define SDL_pow         pow
+#else
+extern DECLSPEC double SDLCALL SDL_pow(double x, double y);
+#endif
+
+#ifdef HAVE_SCALBN
+#define SDL_scalbn      scalbn
+#else
+extern DECLSPEC double SDLCALL SDL_scalbn(double x, int n);
+#endif
+
+#ifdef HAVE_SIN
+#define SDL_sin         sin
+#else
+extern DECLSPEC double SDLCALL SDL_sin(double x);
+#endif
+
+#ifdef HAVE_SINF
+#define SDL_sinf        sinf
+#else
+#define SDL_sinf(x) (float)SDL_sin((double)x)
+#endif
+
+#ifdef HAVE_SQRT
+#define SDL_sqrt        sqrt
+#else
+extern DECLSPEC double SDLCALL SDL_sqrt(double x);
+#endif
+
 /* The SDL implementation of iconv() returns these error codes */
 #define SDL_ICONV_ERROR		(size_t)-1
 #define SDL_ICONV_E2BIG		(size_t)-2
--- a/src/audio/SDL_audiocvt.c	Fri Jan 09 20:43:30 2009 +0000
+++ b/src/audio/SDL_audiocvt.c	Sat Jan 10 18:32:24 2009 +0000
@@ -26,8 +26,6 @@
 #include "SDL_audio.h"
 #include "SDL_audio_c.h"
 
-#include "../libm/math.h"
-
 //#define DEBUG_CONVERT
 
 /* These are fractional multiplication routines. That is, their inputs
@@ -1658,13 +1656,9 @@
         if (i == m / 2) {
             fSinc[i] = two_pi_fc;
         } else {
-            fSinc[i] =
-                sinf(two_pi_fc * ((float) i - m_over_two)) / ((float) i -
-                                                              m_over_two);
+            fSinc[i] = SDL_sinf(two_pi_fc * ((float) i - m_over_two)) / ((float) i - m_over_two);
             /* Apply blackman window */
-            fSinc[i] *=
-                0.42f - 0.5f * cosf(two_pi_over_m * (float) i) +
-                0.08f * cosf(four_pi_over_m * (float) i);
+            fSinc[i] *= 0.42f - 0.5f * SDL_cosf(two_pi_over_m * (float) i) + 0.08f * SDL_cosf(four_pi_over_m * (float) i);
         }
         norm_sum += fSinc[i] < 0 ? -fSinc[i] : fSinc[i];        /* fabs(fSinc[i]); */
     }
@@ -1740,7 +1734,7 @@
 static void SDLCALL
 SDL_Resample(SDL_AudioCVT * cvt, SDL_AudioFormat format)
 {
-    int i, j;
+    int i;
 
 #ifdef DEBUG_CONVERT
     printf("Converting audio rate via proper resampling (mono)\n");
@@ -1752,8 +1746,8 @@
         for (i = cvt->len / sizeof (type); i; --i) { \
             src--; \
             dst[-1] = src[0]; \
-            for( j = -cvt->len_mult; j < -1; ++j ) { \
-                dst[j] = 0; \
+            if (cvt->len_mult > 1) { \
+                SDL_memset(dst-cvt->len_mult, 0, cvt->len_mult-1); \
             } \
             dst -= cvt->len_mult; \
         } \
--- a/src/libm/math.h	Fri Jan 09 20:43:30 2009 +0000
+++ b/src/libm/math.h	Sat Jan 10 18:32:24 2009 +0000
@@ -20,34 +20,56 @@
     slouken@libsdl.org
 */
 #include "SDL_config.h"
-
-#ifdef HAVE_MATH_H
-#define _USE_MATH_DEFINES
-#include <math.h>
-#else
+#include "SDL_stdinc.h"
 
 /* Math routines from uClibc: http://www.uclibc.org */
 
-#define M_PI    3.14159265358979323846264338327950288   /* pi */
+#ifdef HAVE_COPYSIGN
+#define copysign        SDL_uclibc_copysign
+#else
+#define copysign        SDL_copysign
+#endif
+
+#ifdef HAVE_COS
+#define cos             SDL_uclibc_cos
+#else
+#define cos             SDL_cos
+#endif
 
-extern double __ieee754_log(double x);
-extern double __ieee754_pow(double x, double y);
-extern double __ieee754_sqrt(double x);
+#ifdef HAVE_FABS
+#define fabs            SDL_uclibc_fabs
+#else
+#define fabs            SDL_fabs
+#endif
 
-#define log(x)      __ieee754_log(x)
-#define pow(x, y)   __ieee754_pow(x, y)
-#define sqrt(x)     __ieee754_sqrt(x)
+#ifdef HAVE_FLOOR
+#define floor           SDL_uclibc_floor
+#else
+#define floor           SDL_floor
+#endif
 
-extern double copysign(double x, double y);
-extern double cos(double x);
-extern double fabs(double x);
-extern double floor(double x);
-extern double scalbn(double x, int n);
-extern double sin(double x);
+#ifndef HAVE_LOG
+#define __ieee754_log   SDL_log
+#endif
+
+#ifndef HAVE_POW
+#define __ieee754_pow   SDL_pow
+#endif
 
-#define sinf(x) (float)sin((double)x)
-#define cosf(x) (float)cos((double)x)
+#ifdef HAVE_SCALBN
+#define scalbn          SDL_uclibc_scalbn
+#else
+#define scalbn          SDL_scalbn
+#endif
 
-#endif /* HAVE_MATH_H */
+#ifdef HAVE_SIN
+#define sin             SDL_uclibc_sin
+#else
+#define sin             SDL_sin
+#endif
+
+#ifndef HAVE_SQRT
+#define __ieee754_sqrt  SDL_sqrt
+#endif
 
 /* vi: set ts=4 sw=4 expandtab: */
--- a/src/video/SDL_fillrect.c	Fri Jan 09 20:43:30 2009 +0000
+++ b/src/video/SDL_fillrect.c	Sat Jan 10 18:32:24 2009 +0000
@@ -66,7 +66,7 @@
         int i, n = w * bpp; \
         Uint8 *p = pixels; \
  \
-        if (n > 15) { \
+        if (n > 63) { \
             int adjust = 16 - ((uintptr_t)p & 15); \
             if (adjust < 16) { \
                 n -= adjust; \
@@ -92,7 +92,35 @@
     SSE_END; \
 }
 
-DEFINE_SSE_FILLRECT(1, Uint8)
+static void
+SDL_FillRect1SSE(Uint8 *pixels, int pitch, Uint32 color, int w, int h)
+{
+    SSE_BEGIN;
+
+    while (h--) {
+        int i, n = w;
+        Uint8 *p = pixels;
+
+        if (n > 63) {
+            int adjust = 16 - ((uintptr_t)p & 15);
+            if (adjust) {
+                n -= adjust;
+                SDL_memset(p, color, adjust);
+                p += adjust;
+            }
+            SSE_WORK;
+        }
+        if (n & 63) {
+            int remainder = (n & 63);
+            SDL_memset(p, color, remainder);
+            p += remainder;
+        }
+        pixels += pitch;
+    }
+
+    SSE_END;
+}
+/*DEFINE_SSE_FILLRECT(1, Uint8)*/
 DEFINE_SSE_FILLRECT(2, Uint16)
 DEFINE_SSE_FILLRECT(4, Uint32)
 
@@ -131,7 +159,7 @@
         int i, n = w * bpp; \
         Uint8 *p = pixels; \
  \
-        if (n > 7) { \
+        if (n > 63) { \
             int adjust = 8 - ((uintptr_t)p & 7); \
             if (adjust < 8) { \
                 n -= adjust; \
@@ -157,7 +185,35 @@
     MMX_END; \
 }
 
-DEFINE_MMX_FILLRECT(1, Uint8)
+static void
+SDL_FillRect1MMX(Uint8 *pixels, int pitch, Uint32 color, int w, int h)
+{
+    MMX_BEGIN;
+
+    while (h--) {
+        int i, n = w;
+        Uint8 *p = pixels;
+
+        if (n > 63) {
+            int adjust = 8 - ((uintptr_t)p & 7);
+            if (adjust) {
+                n -= adjust;
+                SDL_memset(p, color, adjust);
+                p += adjust;
+            }
+            MMX_WORK;
+        }
+        if (n & 63) {
+            int remainder = (n & 63);
+            SDL_memset(p, color, remainder);
+            p += remainder;
+        }
+        pixels += pitch;
+    }
+
+    MMX_END;
+}
+/*DEFINE_MMX_FILLRECT(1, Uint8)*/
 DEFINE_MMX_FILLRECT(2, Uint16)
 DEFINE_MMX_FILLRECT(4, Uint32)
 
--- a/src/video/SDL_gamma.c	Fri Jan 09 20:43:30 2009 +0000
+++ b/src/video/SDL_gamma.c	Sat Jan 10 18:32:24 2009 +0000
@@ -23,8 +23,6 @@
 
 /* Gamma correction support */
 
-#include "../libm/math.h"
-
 #include "SDL_sysvideo.h"
 
 
@@ -52,7 +50,7 @@
         int value;
         gamma = 1.0f / gamma;
         for (i = 0; i < 256; ++i) {
-            value = (int) (pow((double) i / 256.0, gamma) * 65535.0 + 0.5);
+            value = (int) (SDL_pow((double) i / 256.0, gamma) * 65535.0 + 0.5);
             if (value > 65535) {
                 value = 65535;
             }
@@ -75,7 +73,7 @@
         if ((ramp[i] != 0) && (ramp[i] != 65535)) {
             double B = (double) i / 256.0;
             double A = ramp[i] / 65535.0;
-            sum += (float) (log(A) / log(B));
+			sum += (float) (SDL_log(A) / SDL_log(B));
             count++;
         }
     }