Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

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.
  • Loading branch information
slouken committed Jan 10, 2009
1 parent 35b53db commit 292229f71579d1449690c470349730767828a4ac
Showing with 226 additions and 42 deletions.
  1. +15 −0 acinclude.m4
  2. +5 −2 configure.in
  3. +12 −1 include/SDL_config.h.in
  4. +12 −0 include/SDL_config_win32.h
  5. +73 −0 include/SDL_stdinc.h
  6. +5 −11 src/audio/SDL_audiocvt.c
  7. +42 −20 src/libm/math.h
  8. +60 −4 src/video/SDL_fillrect.c
  9. +2 −4 src/video/SDL_gamma.c
@@ -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>
@@ -129,6 +129,9 @@ if test x$enable_libc = xyes; then
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$enable_libc = xyes; then
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(iconv, libiconv_open, [EXTRA_LDFLAGS="$EXTRA_LDFLAGS -liconv"])
AC_CHECK_LIB(m, pow, [EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lm"])
AC_CHECK_LIB(iconv, libiconv_open, [EXTRA_LDFLAGS="$EXTRA_LDFLAGS -liconv"])
fi

if test x$have_inttypes != xyes; then
@@ -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
@@ -116,6 +116,18 @@ typedef unsigned int uintptr_t;
#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
@@ -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 @@ extern DECLSPEC int SDLCALL SDL_vsnprintf(char *text, size_t maxlen,
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
@@ -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 @@ SDL_BuildWindowedSinc(SDL_AudioCVT * cvt, SDL_AudioFormat format,
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 @@ SDL_GCD(int a, int b)
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 @@ SDL_Resample(SDL_AudioCVT * cvt, SDL_AudioFormat format)
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; \
} \
@@ -20,34 +20,56 @@
slouken@libsdl.org
*/
#include "SDL_config.h"
#include "SDL_stdinc.h"

#ifdef HAVE_MATH_H
#define _USE_MATH_DEFINES
#include <math.h>
/* Math routines from uClibc: http://www.uclibc.org */

#ifdef HAVE_COPYSIGN
#define copysign SDL_uclibc_copysign
#else
#define copysign SDL_copysign
#endif

/* Math routines from uClibc: http://www.uclibc.org */
#ifdef HAVE_COS
#define cos SDL_uclibc_cos
#else
#define cos SDL_cos
#endif

#define M_PI 3.14159265358979323846264338327950288 /* pi */
#ifdef HAVE_FABS
#define fabs SDL_uclibc_fabs
#else
#define fabs SDL_fabs
#endif

extern double __ieee754_log(double x);
extern double __ieee754_pow(double x, double y);
extern double __ieee754_sqrt(double x);
#ifdef HAVE_FLOOR
#define floor SDL_uclibc_floor
#else
#define floor SDL_floor
#endif

#ifndef HAVE_LOG
#define __ieee754_log SDL_log
#endif

#define log(x) __ieee754_log(x)
#define pow(x, y) __ieee754_pow(x, y)
#define sqrt(x) __ieee754_sqrt(x)
#ifndef HAVE_POW
#define __ieee754_pow SDL_pow
#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);
#ifdef HAVE_SCALBN
#define scalbn SDL_uclibc_scalbn
#else
#define scalbn SDL_scalbn
#endif

#define sinf(x) (float)sin((double)x)
#define cosf(x) (float)cos((double)x)
#ifdef HAVE_SIN
#define sin SDL_uclibc_sin
#else
#define sin SDL_sin
#endif

#endif /* HAVE_MATH_H */
#ifndef HAVE_SQRT
#define __ieee754_sqrt SDL_sqrt
#endif

/* vi: set ts=4 sw=4 expandtab: */
@@ -66,7 +66,7 @@ SDL_FillRect##bpp##SSE(Uint8 *pixels, int pitch, Uint32 color, int w, int h) \
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 @@ SDL_FillRect##bpp##SSE(Uint8 *pixels, int pitch, Uint32 color, int w, int h) \
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 @@ SDL_FillRect##bpp##MMX(Uint8 *pixels, int pitch, Uint32 color, int w, int h) \
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 @@ SDL_FillRect##bpp##MMX(Uint8 *pixels, int pitch, Uint32 color, int w, int h) \
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)

0 comments on commit 292229f

Please sign in to comment.