summarylogtreecommitdiffstats
path: root/0003-configure-add-msee-when-using-xmmintin.h.patch
blob: 8d5b33a1ac82c1d79f6de07b67c4b655c2641737 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
From 0ad59584f9a8dfb613a9b7fd89a78f6adfef503d Mon Sep 17 00:00:00 2001
From: Stefan Sauer <ensonic@users.sf.net>
Date: Wed, 30 Dec 2015 15:08:39 +0100
Subject: [PATCH 3/4] configure: add -msee when using xmmintin.h

Fixes #57
---
 configure.ac        | 29 ++++++++++++++++++++++-------
 src/lib/core/core.c | 10 +++++++---
 2 files changed, 29 insertions(+), 10 deletions(-)

diff --git a/configure.ac b/configure.ac
index 3b7c920..5b5681a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -538,17 +538,32 @@ AC_CHECK_DECL(sysi86,[
 ])
 
 dnl check for SSE intrisics
+have_mmx_intrinsics=no
 ARCH_CFLAGS=""
-ARCH_CPPFLAGS=""
 case "x${target_cpu}" in
   xi?86|k?|xx86_64|xamd64)
-    # seems to cause "CPU you selected does not support x86-64 instruction set" on some targets
-    #ARCH_CFLAGS="-march=native"
-    ARCH_CPPFLAGS="-D__SSE__ -D__MMX__"
-    AC_CHECK_HEADERS([xmmintrin.h])
+    AC_CHECK_HEADERS([xmmintrin.h],
+      [
+        SAVED_CFLAGS="${CFLAGS}"
+        AC_MSG_CHECKING([for working mmx intrinsics])
+        CFLAGS="-mmmx -msse"
+        AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
+                          #include <mmintrin.h>
+                          int main () {
+                              _mm_getcsr ();
+                          }]])], [
+                          AC_MSG_RESULT(yes)
+                          have_mmx_intrinsics=yes],[
+                          AC_MSG_RESULT(no)])
+        CFLAGS="${SAVED_CFLAGS}"
+        ARCH_CFLAGS="-mmmx -msse"
+      ],[])
     ;;
 esac
-
+if test $have_mmx_intrinsics = yes ; then
+   AC_DEFINE(USE_X86_MMX, 1, [use x86 MMX compiler intrinsics])
+   ARCH_CFLAGS="-mmmx -msse"
+fi
 
 dnl check for libraries
 LT_LIB_M
@@ -593,7 +608,7 @@ AC_ARG_ENABLE(Bsymbolic,
 dnl Extra vars
 BT_INCLUDEDIR='-I${includedir}'
 dnl -Wl,--as-needed # can be put into CFLAGS to drop all unused libs
-BT_CFLAGS="$ARCH_CFLAGS $ARCH_CPPFLAGS $DEBUG_CFLAGS $COVERAGE_CFLAGS $BT_DISABLE_DEPRECATED"
+BT_CFLAGS="$ARCH_CFLAGS $DEBUG_CFLAGS $COVERAGE_CFLAGS $BT_DISABLE_DEPRECATED"
 BT_LIBDIR='-L${libdir}'
 BT_LIBS="$COVERAGE_LIBS"
 BT_LDFLAGS="$DEBUG_LDFLAGS"
diff --git a/src/lib/core/core.c b/src/lib/core/core.c
index 6a03d5e..f9d2061 100644
--- a/src/lib/core/core.c
+++ b/src/lib/core/core.c
@@ -32,14 +32,16 @@
 
 #ifdef HAVE_SCHED_SETSCHEDULER
 #include <sched.h>
-#if HAVE_MLOCKALL
+#ifdef HAVE_MLOCKALL
 #include <sys/mman.h>
 #endif
 #endif
 
-#if HAVE_XMMINTRIN_H
+#ifdef USE_X86_MMX
+#ifdef HAVE_XMMINTRIN_H
 #include <xmmintrin.h>
 #endif
+#endif
 
 /**
  * bt_major_version:
@@ -145,11 +147,13 @@ bt_init_post (void)
 #endif
 #endif
 
-#if HAVE_XMMINTRIN_H
+#if USE_X86_MMX
   // TODO(ensonic): we need to probe the CPU capabilities
   // see http://www.mail-archive.com/linux-audio-dev@music.columbia.edu/msg19520.html
   //   [linux-audio-dev] Channels and best practice
   // _MM_FLUSH_ZERO_ON = FZ
+  // TODO(ensonic): wikipedia says we must do this for each thread:
+  // https://en.wikipedia.org/wiki/Denormal_number#Disabling_denormal_floats_at_the_code_level
   _mm_setcsr (_mm_getcsr () | 0x8040);  // set DAZ and FZ bits
 #endif
 
-- 
2.6.4