From da9b170c6f06184a5114dc66afb8385cd0ffff83 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Sun, 6 Jun 2004 03:45:53 +0000 Subject: [PATCH] optional and disabled by default memalign hack for SSE/SSE2 on that alternative OS Originally committed as revision 3199 to svn://svn.ffmpeg.org/ffmpeg/trunk --- configure | 9 +++++++++ libavcodec/mem.c | 18 +++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/configure b/configure index 43e9e87dbe..01d7d9ee61 100755 --- a/configure +++ b/configure @@ -62,6 +62,7 @@ echo " --disable-ffserver disable ffserver build" echo " --disable-ffplay disable ffplay build" echo " --disable-risky disables patent encumbered codecs" echo " --enable-small optimize for size instead of speed" +echo " --enable-memalign-hack emulate memalign, interferes with memory debuggers" echo "" echo "NOTE: The object files are build at the place where configure is launched" exit 1 @@ -178,6 +179,7 @@ amr_nb_fixed="no" sunmlib="no" pthreads="no" gpl="no" +memalignhack="no" # OS specific targetos=`uname -s` @@ -427,6 +429,8 @@ for opt do ;; --enable-gpl) gpl="yes" ;; + --enable-memalign-hack) memalignhack="yes" + ;; esac done @@ -1269,6 +1273,11 @@ else echo "#undef HAVE_MEMALIGN" >> $TMPH fi +if test "$memalignhack" = "yes" ; then + echo "#define MEMALIGN_HACK 1" >> $TMPH +fi + + if test "$netserver" = "yes" ; then echo "#define CONFIG_BEOS_NETSERVER 1" >> $TMPH echo "CONFIG_BEOS_NETSERVER=yes" >> config.mak diff --git a/libavcodec/mem.c b/libavcodec/mem.c index c5ca166d33..35c8305033 100644 --- a/libavcodec/mem.c +++ b/libavcodec/mem.c @@ -46,7 +46,13 @@ void *av_malloc(unsigned int size) { void *ptr; -#if defined (HAVE_MEMALIGN) +#ifdef MEMALIGN_HACK + int diff; + ptr = malloc(size+16+1); + diff= ((-(int)ptr - 1)&15) + 1; + ptr += diff; + ((char*)ptr)[-1]= diff; +#elif defined (HAVE_MEMALIGN) ptr = memalign(16,size); /* Why 64? Indeed, we should align it: @@ -87,7 +93,13 @@ void *av_malloc(unsigned int size) */ void *av_realloc(void *ptr, unsigned int size) { +#ifdef MEMALIGN_HACK + //FIXME this isnt aligned correctly though it probably isnt needed + int diff= ptr ? ((char*)ptr)[-1] : 0; + return realloc(ptr - diff, size + diff) + diff; +#else return realloc(ptr, size); +#endif } /* NOTE: ptr = NULL is explicetly allowed */ @@ -95,6 +107,10 @@ void av_free(void *ptr) { /* XXX: this test should not be needed on most libcs */ if (ptr) +#ifdef MEMALIGN_HACK + free(ptr - ((char*)ptr)[-1]); +#else free(ptr); +#endif }