[Speex-dev] configure patch to check for SSE

Thorvald Natvig thorvald at natvig.com
Thu Apr 3 08:39:54 PDT 2008


Hi,

The attached patch changes the configure.ac logic as follows:

It tests if the current compiler/cflags combination supports SSE, and if 
so enables _USE_SSE. This can be overridden by the '--enable-sse' and 
'--disable-sse' flags. Using '--enable-sse' will additionally add '-O3 
-msse' to CFLAGS, just as it used to.

I've tested this using the following combinations:
x86_64: ./configure: Detected and used.
x86_64: ./configure --disable-sse: Detected but not used.
i686: ./configure: Not detected.
i686: CFLAGS="-march=pentium3" ./configure: Detected and used.
i686: CFLAGS="-march=pentium2 -msse" ./configure: Detected and used.
i686: CFLAGS="-march=pentium2" ./configure: Not detected, not used.
i686: ./configure --enable-sse: Not detected, still enabled and '-O3 
-msse' added.

In other words, if you've already set up your compiler to produce SSE 
code, we'll use the SSE intrinsics in Speex.
-------------- next part --------------
Index: configure.ac
===================================================================
--- configure.ac	(revision 14652)
+++ configure.ac	(working copy)
@@ -72,6 +72,22 @@
 )
 AC_MSG_RESULT($has_alloca)
 
+AC_MSG_CHECKING(for SSE in current arch/CFLAGS)
+AC_LINK_IFELSE([
+AC_LANG_PROGRAM([[
+#include <xmmintrin.h>
+__m128 testfunc(float *a, float *b) {
+  return _mm_add_ps(_mm_loadu_ps(a), _mm_loadu_ps(b));
+}
+]])],
+[
+has_sse=yes
+],
+[
+has_sse=no
+]
+)
+AC_MSG_RESULT($has_sse)  
 
 AC_CHECK_HEADERS(sys/soundcard.h sys/audioio.h)
 
@@ -102,12 +118,19 @@
   AC_DEFINE([ENABLE_VALGRIND], , [Enable valgrind extra checks])
 fi])
 
-AC_ARG_ENABLE(sse, [  --enable-sse            Enable SSE support], [if test "$enableval" = yes; then
-AC_DEFINE([_USE_SSE], , [Enable SSE support])
+AC_ARG_ENABLE(sse, [  --enable-sse            Enable SSE support], [
+if test "x$enableval" != xno; then
+has_sse=yes
 CFLAGS="$CFLAGS -O3 -msse"
+else
+has_sse=no
 fi
 ])
 
+if test "$has_sse" = yes; then
+  AC_DEFINE([_USE_SSE], , [Enable SSE support])
+fi
+
 AC_ARG_ENABLE(fixed-point, [  --enable-fixed-point    Compile as fixed-point],
 [if test "$enableval" = yes; then
   AC_DEFINE([FIXED_POINT], , [Compile as fixed-point])


More information about the Speex-dev mailing list