summaryrefslogtreecommitdiff
path: root/media-sound/ardour/files/ardour-8.12-fix_fpu.patch
blob: dd99e010fe41f4567a39a2fb2a27c9607b3e50c2 (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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
respect userflags for optimizations
files for test are patched, even if it's broken for now
--- a/wscript
+++ b/wscript
@@ -553,8 +553,7 @@ int main() { return 0; }''',
                            execute   = False,
                            msg       = 'Checking compiler for AVX512F intrinsics',
                            okmsg     = 'Found',
-                           errmsg    = 'Not supported',
-                           define_name = 'FPU_AVX512F_SUPPORT')
+                           errmsg    = 'Not supported')
 
             conf.check_cxx(fragment = "#include <immintrin.h>\nint main(void) { __m128 a; _mm_fmadd_ss(a, a, a); return 0; }\n",
                            features  = ['cxx'],
@@ -563,8 +562,7 @@ int main() { return 0; }''',
                            execute   = False,
                            msg       = 'Checking compiler for AVX/FMA intrinsics',
                            okmsg     = 'Found',
-                           errmsg    = 'Not supported',
-                           define_name = 'FPU_AVX_FMA_SUPPORT')
+                           errmsg    = 'Not supported')
 
     if opt.use_libcpp or conf.env['build_host'] in [ 'yosemite', 'el_capitan', 'sierra', 'high_sierra', 'mojave', 'catalina' ]:
         cxx_flags.append('--stdlib=libc++')
@@ -636,11 +634,12 @@ int main() { return 0; }''',
                     build_host_supports_sse = True
                 if "3dnow" in x86_flags:
                     compiler_flags.append ("-m3dnow")
-
-            if cpu == "i586":
-                compiler_flags.append ("-march=i586")
-            elif cpu == "i686":
-                compiler_flags.append ("-march=i686")
+                if "avx" in x86_flags:
+                    conf.define ('FPU_AVX_SUPPORT', 1)
+                if "fma" in x86_flags:
+                    conf.define ('FPU_AVX_FMA_SUPPORT', 1)
+                if "avx512f" in x86_flags:
+                    conf.define ('FPU_AVX512F_SUPPORT', 1)
 
         if not is_clang and ((conf.env['build_target'] == 'i686') or (conf.env['build_target'] == 'x86_64')) and build_host_supports_sse:
             compiler_flags.extend ([ flags_dict['sse'], flags_dict['fpmath-sse'], flags_dict['xmmintrinsics'] ])
@@ -762,9 +761,6 @@ int main() { return 0; }''',
             prepend_opt_flags = False
             break
 
-    if prepend_opt_flags:
-        optimization_flags[:0] = flags_dict['full-optimization']
-
     if opt.debug_symbols:
         optimization_flags += flags_dict['debuggable']
 
--- a/libs/ardour/wscript
+++ b/libs/ardour/wscript
@@ -495,14 +495,8 @@ def build(bld):
     if not Options.options.no_fpu_optimization:
         if (bld.env['build_target'] == 'i386' or bld.env['build_target'] == 'i686'):
             obj.source += [ 'sse_functions_xmm.cc', 'sse_functions.s', ]
-            avx_sources = [ 'sse_functions_avx_linux.cc' ]
-            fma_sources = [ 'x86_functions_fma.cc' ]
-            avx512f_sources = [ 'x86_functions_avx512f.cc' ]
         elif bld.env['build_target'] == 'x86_64':
             obj.source += [ 'sse_functions_xmm.cc', 'sse_functions_64bit.s', ]
-            avx_sources = [ 'sse_functions_avx_linux.cc' ]
-            fma_sources = [ 'x86_functions_fma.cc' ]
-            avx512f_sources = [ 'x86_functions_avx512f.cc' ]
         elif bld.env['build_target'] == 'mingw':
             # usability of the 64 bit windows assembler depends on the compiler target,
             # not the build host, which in turn can only be inferred from the name
@@ -533,7 +527,8 @@ def build(bld):
             obj.use += ['arm_neon_functions' ]
             obj.defines += [ 'ARM_NEON_SUPPORT' ]
 
-        if avx_sources:
+        if bld.is_defined('FPU_AVX_SUPPORT'):
+            avx_sources = [ 'sse_functions_avx_linux.cc' ]
             # as long as we want to use AVX intrinsics in this file,
             # compile it with -mavx flag - append avx flag to the existing
             avx_cxxflags = list(bld.env['CXXFLAGS'])
@@ -549,7 +544,8 @@ def build(bld):
 
             obj.use += ['sse_avx_functions' ]
 
-        if bld.is_defined('FPU_AVX_FMA_SUPPORT') and fma_sources:
+        if bld.is_defined('FPU_AVX_FMA_SUPPORT'):
+            fma_sources = [ 'x86_functions_fma.cc' ]
             fma_cxxflags = list(bld.env['CXXFLAGS'])
             fma_cxxflags.append (bld.env['compiler_flags_dict']['avx'])
             fma_cxxflags.append (bld.env['compiler_flags_dict']['pic'])
@@ -566,7 +562,8 @@ def build(bld):
             obj.use += ['sse_fma_functions' ]
             obj.defines += [ 'FPU_AVX_FMA_SUPPORT' ]
 
-        if bld.is_defined('FPU_AVX512F_SUPPORT') and avx512f_sources:
+        if bld.is_defined('FPU_AVX512F_SUPPORT'):
+            avx512f_sources = [ 'x86_functions_avx512f.cc' ]
             avx512f_cxxflags = list(bld.env['CXXFLAGS'])
             avx512f_cxxflags.append (bld.env['compiler_flags_dict']['avx512f'])
             avx512f_cxxflags.append (bld.env['compiler_flags_dict']['avx'])
--- a/libs/ardour/globals.cc
+++ b/libs/ardour/globals.cc
@@ -228,6 +228,8 @@ setup_hardware_optimization (bool try_optimization)
 
 		} else
 #endif
+
+#ifdef FPU_AVX_SUPPORT
 		if (fpu->has_avx ()) {
 			info << "Using AVX optimized routines" << endmsg;
 
@@ -241,7 +243,10 @@ setup_hardware_optimization (bool try_optimization)
 
 			generic_mix_functions = false;
 
-		} else if (fpu->has_sse ()) {
+		} else
+#endif
+
+		if (fpu->has_sse ()) {
 			info << "Using SSE optimized routines" << endmsg;
 
 			// SSE SET
--- a/libs/ardour/ardour/mix.h
+++ b/libs/ardour/ardour/mix.h
@@ -37,6 +37,7 @@ LIBARDOUR_API void x86_sse_find_peaks              (float const* buf, uint32_t n
 
 extern "C" {
 /* AVX functions */
+#ifdef FPU_AVX_SUPPORT
 	LIBARDOUR_API float x86_sse_avx_compute_peak          (float const* buf, uint32_t nsamples, float current);
 	LIBARDOUR_API void  x86_sse_avx_apply_gain_to_buffer  (float* buf, uint32_t nframes, float gain);
 	LIBARDOUR_API void  x86_sse_avx_mix_buffers_with_gain (float* dst, float const* src, uint32_t nframes, float gain);
@@ -45,6 +46,7 @@ extern "C" {
 #ifndef PLATFORM_WINDOWS
 	LIBARDOUR_API void  x86_sse_avx_find_peaks            (float const* buf, uint32_t nsamples, float* min, float* max);
 #endif
+#endif
 }
 #ifdef PLATFORM_WINDOWS
 LIBARDOUR_API void x86_sse_avx_find_peaks               (float const* buf, uint32_t nsamples, float* min, float* max);
--- a/libs/ardour/test/fpu_test.cc
+++ b/libs/ardour/test/fpu_test.cc
@@ -99,6 +99,7 @@ FPUTest::compare (std::string msg, size_t cnt, float max_diff)
 
 #if defined(ARCH_X86) && defined(BUILD_SSE_OPTIMIZATIONS)
 
+#if defined FPU_AVX_SUPPORT
 void
 FPUTest::avxFmaTest ()
 {
@@ -125,7 +126,9 @@ FPUTest::avxFmaTest ()
 
 	run (align_max, FLT_EPSILON);
 }
+#endif
 
+#if defined FPU_AVX_SUPPORT
 void
 FPUTest::avxTest ()
 {
@@ -152,7 +155,9 @@ FPUTest::avxTest ()
 
 	run (align_max);
 }
+#endif
 
+#if defined FPU_AVX512F_SUPPORT
 void
 FPUTest::avx512fTest ()
 {
@@ -179,6 +184,7 @@ FPUTest::avx512fTest ()
 
 	run (align_max, FLT_EPSILON);
 }
+#endif
 
 void
 FPUTest::sseTest ()
--- a/libs/ardour/test/fpu_test.h
+++ b/libs/ardour/test/fpu_test.h
@@ -8,9 +8,15 @@ class FPUTest : public CppUnit::TestFixture
 	CPPUNIT_TEST_SUITE (FPUTest);
 #if defined(ARCH_X86) && defined(BUILD_SSE_OPTIMIZATIONS)
 	CPPUNIT_TEST (sseTest);
+#if defined FPU_AVX_SUPPORT
 	CPPUNIT_TEST (avxTest);
+#endif
+#if defined FPU_AVX_FMA_SUPPORT
 	CPPUNIT_TEST (avxFmaTest);
+#endif
+#if defined FPU_AVX512F_SUPPORT
 	CPPUNIT_TEST (avx512fTest);
+#endif
 #elif defined ARM_NEON_SUPPORT
 	CPPUNIT_TEST (neonTest);
 #elif defined(__APPLE__) && defined(BUILD_VECLIB_OPTIMIZATIONS)