audio: Wired up new SSE code to build system.
authorRyan C. Gordon <icculus@icculus.org>
Mon, 23 Jan 2017 01:05:44 -0500
changeset 108350e9e7a128391
parent 10834 336efe4fc373
child 10836 8f0aa225f261
audio: Wired up new SSE code to build system.
CMakeLists.txt
configure
configure.in
include/SDL_cpuinfo.h
src/audio/SDL_audiocvt.c
src/audio/SDL_audiotypecvt.c
     1.1 --- a/CMakeLists.txt	Sun Jan 22 20:27:48 2017 -0500
     1.2 +++ b/CMakeLists.txt	Mon Jan 23 01:05:44 2017 -0500
     1.3 @@ -262,6 +262,7 @@
     1.4  set_option(3DNOW               "Use 3Dnow! MMX assembly routines" ${OPT_DEF_ASM})
     1.5  set_option(SSE                 "Use SSE assembly routines" ${OPT_DEF_ASM})
     1.6  set_option(SSE2                "Use SSE2 assembly routines" ${OPT_DEF_SSEMATH})
     1.7 +set_option(SSE3                "Use SSE3 assembly routines" ${OPT_DEF_SSEMATH})
     1.8  set_option(ALTIVEC             "Use Altivec assembly routines" ${OPT_DEF_ASM})
     1.9  set_option(DISKAUDIO           "Support the disk writer audio driver" ON)
    1.10  set_option(DUMMYAUDIO          "Support the dummy audio driver" ON)
    1.11 @@ -516,8 +517,31 @@
    1.12        set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
    1.13      endif()
    1.14  
    1.15 +    if(SSE3)
    1.16 +      set(CMAKE_REQUIRED_FLAGS "-msse3")
    1.17 +      check_c_source_compiles("
    1.18 +          #ifdef __MINGW32__
    1.19 +          #include <_mingw.h>
    1.20 +          #ifdef __MINGW64_VERSION_MAJOR
    1.21 +          #include <intrin.h>
    1.22 +          #else
    1.23 +          #include <pmmintrin.h>
    1.24 +          #endif
    1.25 +          #else
    1.26 +          #include <pmmintrin.h>
    1.27 +          #endif
    1.28 +          #ifndef __SSE3__
    1.29 +          #error Assembler CPP flag not enabled
    1.30 +          #endif
    1.31 +          int main(int argc, char **argv) { }" HAVE_SSE3)
    1.32 +      if(HAVE_SSE3)
    1.33 +        list(APPEND EXTRA_CFLAGS "-msse3")
    1.34 +      endif()
    1.35 +      set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
    1.36 +    endif()
    1.37 +
    1.38      if(SSEMATH)
    1.39 -      if(SSE OR SSE2)
    1.40 +      if(SSE OR SSE2 OR SSE3)
    1.41          if(USE_GCC)
    1.42            list(APPEND EXTRA_CFLAGS "-mfpmath=387")
    1.43          endif()
    1.44 @@ -557,12 +581,13 @@
    1.45      endif()
    1.46      set(HAVE_SSE TRUE)
    1.47      set(HAVE_SSE2 TRUE)
    1.48 +    set(HAVE_SSE3 TRUE)
    1.49      set(SDL_ASSEMBLY_ROUTINES 1)
    1.50    endif()
    1.51  # TODO:
    1.52  #else()
    1.53  #  if(USE_GCC OR USE_CLANG)
    1.54 -#    list(APPEND EXTRA_CFLAGS "-mno-sse" "-mno-sse2" "-mno-mmx")
    1.55 +#    list(APPEND EXTRA_CFLAGS "-mno-sse" "-mno-sse2" "-mno-sse3" "-mno-mmx")
    1.56  #  endif()
    1.57  endif()
    1.58  
     2.1 --- a/configure	Sun Jan 22 20:27:48 2017 -0500
     2.2 +++ b/configure	Mon Jan 23 01:05:44 2017 -0500
     2.3 @@ -798,6 +798,7 @@
     2.4  enable_3dnow
     2.5  enable_sse
     2.6  enable_sse2
     2.7 +enable_sse3
     2.8  enable_altivec
     2.9  enable_oss
    2.10  enable_alsa
    2.11 @@ -1527,7 +1528,8 @@
    2.12    --enable-mmx            use MMX assembly routines [[default=yes]]
    2.13    --enable-3dnow          use 3DNow! assembly routines [[default=yes]]
    2.14    --enable-sse            use SSE assembly routines [[default=yes]]
    2.15 -  --enable-sse2           use SSE2 assembly routines [[default=no]]
    2.16 +  --enable-sse2           use SSE2 assembly routines [[default=maybe]]
    2.17 +  --enable-sse3           use SSE3 assembly routines [[default=maybe]]
    2.18    --enable-altivec        use Altivec assembly routines [[default=yes]]
    2.19    --enable-oss            support the OSS audio API [[default=maybe]]
    2.20    --enable-alsa           support the ALSA audio API [[default=yes]]
    2.21 @@ -17308,6 +17310,63 @@
    2.22          fi
    2.23      fi
    2.24  
    2.25 +    # Check whether --enable-sse3 was given.
    2.26 +if test "${enable_sse3+set}" = set; then :
    2.27 +  enableval=$enable_sse3;
    2.28 +else
    2.29 +  enable_sse3=$default_ssemath
    2.30 +fi
    2.31 +
    2.32 +    if test x$enable_sse3 = xyes; then
    2.33 +        save_CFLAGS="$CFLAGS"
    2.34 +        have_gcc_sse3=no
    2.35 +        { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GCC -msse3 option" >&5
    2.36 +$as_echo_n "checking for GCC -msse3 option... " >&6; }
    2.37 +        sse3_CFLAGS="-msse3"
    2.38 +        CFLAGS="$save_CFLAGS $sse3_CFLAGS"
    2.39 +
    2.40 +        cat confdefs.h - <<_ACEOF >conftest.$ac_ext
    2.41 +/* end confdefs.h.  */
    2.42 +
    2.43 +        #ifdef __MINGW32__
    2.44 +        #include <_mingw.h>
    2.45 +        #ifdef __MINGW64_VERSION_MAJOR
    2.46 +        #include <intrin.h>
    2.47 +        #else
    2.48 +        #include <pmmintrin.h>
    2.49 +        #endif
    2.50 +        #else
    2.51 +        #include <pmmintrin.h>
    2.52 +        #endif
    2.53 +        #ifndef __SSE2__
    2.54 +        #error Assembler CPP flag not enabled
    2.55 +        #endif
    2.56 +
    2.57 +int
    2.58 +main ()
    2.59 +{
    2.60 +
    2.61 +
    2.62 +  ;
    2.63 +  return 0;
    2.64 +}
    2.65 +_ACEOF
    2.66 +if ac_fn_c_try_compile "$LINENO"; then :
    2.67 +
    2.68 +        have_gcc_sse3=yes
    2.69 +
    2.70 +fi
    2.71 +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
    2.72 +        { $as_echo "$as_me:${as_lineno-$LINENO}: result: $have_gcc_sse3" >&5
    2.73 +$as_echo "$have_gcc_sse3" >&6; }
    2.74 +        CFLAGS="$save_CFLAGS"
    2.75 +
    2.76 +        if test x$have_gcc_sse3 = xyes; then
    2.77 +            EXTRA_CFLAGS="$EXTRA_CFLAGS $sse3_CFLAGS"
    2.78 +            SUMMARY_math="${SUMMARY_math} sse3"
    2.79 +        fi
    2.80 +    fi
    2.81 +
    2.82      # Check whether --enable-altivec was given.
    2.83  if test "${enable_altivec+set}" = set; then :
    2.84    enableval=$enable_altivec;
     3.1 --- a/configure.in	Sun Jan 22 20:27:48 2017 -0500
     3.2 +++ b/configure.in	Mon Jan 23 01:05:44 2017 -0500
     3.3 @@ -593,7 +593,7 @@
     3.4      fi
     3.5  
     3.6      AC_ARG_ENABLE(sse2,
     3.7 -AC_HELP_STRING([--enable-sse2], [use SSE2 assembly routines [[default=no]]]),
     3.8 +AC_HELP_STRING([--enable-sse2], [use SSE2 assembly routines [[default=maybe]]]),
     3.9                    , enable_sse2=$default_ssemath)
    3.10      if test x$enable_sse2 = xyes; then
    3.11          save_CFLAGS="$CFLAGS"
    3.12 @@ -629,6 +629,43 @@
    3.13          fi
    3.14      fi
    3.15  
    3.16 +    AC_ARG_ENABLE(sse3,
    3.17 +AC_HELP_STRING([--enable-sse3], [use SSE3 assembly routines [[default=maybe]]]),
    3.18 +                  , enable_sse3=$default_ssemath)
    3.19 +    if test x$enable_sse3 = xyes; then
    3.20 +        save_CFLAGS="$CFLAGS"
    3.21 +        have_gcc_sse3=no
    3.22 +        AC_MSG_CHECKING(for GCC -msse3 option)
    3.23 +        sse3_CFLAGS="-msse3"
    3.24 +        CFLAGS="$save_CFLAGS $sse3_CFLAGS"
    3.25 +
    3.26 +        AC_TRY_COMPILE([
    3.27 +        #ifdef __MINGW32__
    3.28 +        #include <_mingw.h>
    3.29 +        #ifdef __MINGW64_VERSION_MAJOR
    3.30 +        #include <intrin.h>
    3.31 +        #else
    3.32 +        #include <pmmintrin.h>
    3.33 +        #endif
    3.34 +        #else
    3.35 +        #include <pmmintrin.h>
    3.36 +        #endif
    3.37 +        #ifndef __SSE2__
    3.38 +        #error Assembler CPP flag not enabled
    3.39 +        #endif
    3.40 +        ],[
    3.41 +        ],[
    3.42 +        have_gcc_sse3=yes
    3.43 +        ])
    3.44 +        AC_MSG_RESULT($have_gcc_sse3)
    3.45 +        CFLAGS="$save_CFLAGS"
    3.46 +
    3.47 +        if test x$have_gcc_sse3 = xyes; then
    3.48 +            EXTRA_CFLAGS="$EXTRA_CFLAGS $sse3_CFLAGS"
    3.49 +            SUMMARY_math="${SUMMARY_math} sse3"
    3.50 +        fi
    3.51 +    fi
    3.52 +
    3.53      AC_ARG_ENABLE(altivec,
    3.54  AC_HELP_STRING([--enable-altivec], [use Altivec assembly routines [[default=yes]]]),
    3.55                    , enable_altivec=yes)
     4.1 --- a/include/SDL_cpuinfo.h	Sun Jan 22 20:27:48 2017 -0500
     4.2 +++ b/include/SDL_cpuinfo.h	Mon Jan 23 01:05:44 2017 -0500
     4.3 @@ -61,6 +61,9 @@
     4.4  #ifdef __SSE2__
     4.5  #include <emmintrin.h>
     4.6  #endif
     4.7 +#ifdef __SSE3__
     4.8 +#include <pmmintrin.h>
     4.9 +#endif
    4.10  #endif
    4.11  
    4.12  #include "begin_code.h"
     5.1 --- a/src/audio/SDL_audiocvt.c	Sun Jan 22 20:27:48 2017 -0500
     5.2 +++ b/src/audio/SDL_audiocvt.c	Mon Jan 23 01:05:44 2017 -0500
     5.3 @@ -28,13 +28,10 @@
     5.4  #include "SDL_loadso.h"
     5.5  #include "SDL_assert.h"
     5.6  #include "../SDL_dataqueue.h"
     5.7 +#include "SDL_cpuinfo.h"
     5.8  
     5.9 -/* !!! FIXME: wire this up to the configure script, etc. */
    5.10 -#include "SDL_cpuinfo.h"
    5.11 -#define HAVE_SSE3_INTRINSICS 0
    5.12 -
    5.13 -#if HAVE_SSE3_INTRINSICS
    5.14 -#include <pmmintrin.h>
    5.15 +#ifdef __SSE3__
    5.16 +#define HAVE_SSE3_INTRINSICS 1
    5.17  #endif
    5.18  
    5.19  #if HAVE_SSE3_INTRINSICS
     6.1 --- a/src/audio/SDL_audiotypecvt.c	Sun Jan 22 20:27:48 2017 -0500
     6.2 +++ b/src/audio/SDL_audiotypecvt.c	Mon Jan 23 01:05:44 2017 -0500
     6.3 @@ -28,11 +28,8 @@
     6.4  /* !!! FIXME: write NEON code. */
     6.5  #define HAVE_NEON_INTRINSICS 0
     6.6  
     6.7 -/* !!! FIXME: wire this up to the configure script, etc. */
     6.8 -#define HAVE_SSE2_INTRINSICS 0
     6.9 -
    6.10 -#if HAVE_SSE2_INTRINSICS
    6.11 -#include <emmintrin.h>
    6.12 +#ifdef __SSE2__
    6.13 +#define HAVE_SSE2_INTRINSICS 1
    6.14  #endif
    6.15  
    6.16  #if defined(__x86_64__) && HAVE_SSE2_INTRINSICS