Debian Codegraph @

packaging/flatpak/patches/lame-3.100-sse-20171014.patch

raw
1 --- libmp3lame/fft.c.orig 2017-09-07 04:33:36.000000000 +0900
2 +++ libmp3lame/fft.c 2017-10-14 12:03:44.000000000 +0900
3 @@ -331,7 +331,7 @@ init_fft(lame_internal_flags * const gfc
4 }
5 #else
6 #ifdef HAVE_XMMINTRIN_H
7 -#ifdef MIN_ARCH_SSE
8 +#if defined(MIN_ARCH_SSE) || defined(__x86_64__)
9 gfc->fft_fht = fht_SSE2;
10 #endif
11 #endif
12 --- libmp3lame/gain_analysis.c.orig 2017-10-11 04:08:39.000000000 +0900
13 +++ libmp3lame/gain_analysis.c 2017-10-14 12:06:19.000000000 +0900
14 @@ -95,6 +95,9 @@
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <string.h>
18 +#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
19 +#include <xmmintrin.h>
20 +#endif
21
22 #include "lame.h"
23 #include "machine.h"
24 @@ -109,6 +112,67 @@
25
26
27 /*lint -save -e736 loss of precision */
28 +#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
29 +static const Float_t ABYule[9][2 * YULE_ORDER + 1 + 3] __attribute__ ((aligned (16))) = {
30 + {0.03857599435200, -3.84664617118067, -0.02160367184185, 7.81501653005538, -0.00123395316851,
31 + -11.34170355132042, -0.00009291677959, 13.05504219327545, -0.01655260341619,
32 + -12.28759895145294, 0.02161526843274, 9.48293806319790, -0.02074045215285, -5.87257861775999,
33 + 0.00594298065125, 2.75465861874613, 0.00306428023191, -0.86984376593551, 0.00012025322027,
34 + 0.13919314567432, 0.00288463683916, 0.0, 0.0, 0.0},
35 + {0.05418656406430, -3.47845948550071, -0.02911007808948, 6.36317777566148, -0.00848709379851,
36 + -8.54751527471874, -0.00851165645469, 9.47693607801280, -0.00834990904936, -8.81498681370155,
37 + 0.02245293253339, 6.85401540936998, -0.02596338512915, -4.39470996079559, 0.01624864962975,
38 + 2.19611684890774, -0.00240879051584, -0.75104302451432, 0.00674613682247, 0.13149317958808,
39 + -0.00187763777362, 0.0, 0.0, 0.0},
40 + {0.15457299681924, -2.37898834973084, -0.09331049056315, 2.84868151156327, -0.06247880153653,
41 + -2.64577170229825, 0.02163541888798, 2.23697657451713, -0.05588393329856, -1.67148153367602,
42 + 0.04781476674921, 1.00595954808547, 0.00222312597743, -0.45953458054983, 0.03174092540049,
43 + 0.16378164858596, -0.01390589421898, -0.05032077717131, 0.00651420667831, 0.02347897407020,
44 + -0.00881362733839, 0.0, 0.0, 0.0},
45 + {0.30296907319327, -1.61273165137247, -0.22613988682123, 1.07977492259970, -0.08587323730772,
46 + -0.25656257754070, 0.03282930172664, -0.16276719120440, -0.00915702933434, -0.22638893773906,
47 + -0.02364141202522, 0.39120800788284, -0.00584456039913, -0.22138138954925, 0.06276101321749,
48 + 0.04500235387352, -0.00000828086748, 0.02005851806501, 0.00205861885564, 0.00302439095741,
49 + -0.02950134983287, 0.0, 0.0, 0.0},
50 + {0.33642304856132, -1.49858979367799, -0.25572241425570, 0.87350271418188, -0.11828570177555,
51 + 0.12205022308084, 0.11921148675203, -0.80774944671438, -0.07834489609479, 0.47854794562326,
52 + -0.00469977914380, -0.12453458140019, -0.00589500224440, -0.04067510197014, 0.05724228140351,
53 + 0.08333755284107, 0.00832043980773, -0.04237348025746, -0.01635381384540, 0.02977207319925,
54 + -0.01760176568150, 0.0, 0.0, 0.0},
55 + {0.44915256608450, -0.62820619233671, -0.14351757464547, 0.29661783706366, -0.22784394429749,
56 + -0.37256372942400, -0.01419140100551, 0.00213767857124, 0.04078262797139, -0.42029820170918,
57 + -0.12398163381748, 0.22199650564824, 0.04097565135648, 0.00613424350682, 0.10478503600251,
58 + 0.06747620744683, -0.01863887810927, 0.05784820375801, -0.03193428438915, 0.03222754072173,
59 + 0.00541907748707, 0.0, 0.0, 0.0},
60 + {0.56619470757641, -1.04800335126349, -0.75464456939302, 0.29156311971249, 0.16242137742230,
61 + -0.26806001042947, 0.16744243493672, 0.00819999645858, -0.18901604199609, 0.45054734505008,
62 + 0.30931782841830, -0.33032403314006, -0.27562961986224, 0.06739368333110, 0.00647310677246,
63 + -0.04784254229033, 0.08647503780351, 0.01639907836189, -0.03788984554840, 0.01807364323573,
64 + -0.00588215443421, 0.0, 0.0, 0.0},
65 + {0.58100494960553, -0.51035327095184, -0.53174909058578, -0.31863563325245, -0.14289799034253,
66 + -0.20256413484477, 0.17520704835522, 0.14728154134330, 0.02377945217615, 0.38952639978999,
67 + 0.15558449135573, -0.23313271880868, -0.25344790059353, -0.05246019024463, 0.01628462406333,
68 + -0.02505961724053, 0.06920467763959, 0.02442357316099, -0.03721611395801, 0.01818801111503,
69 + -0.00749618797172, 0.0, 0.0, 0.0},
70 + {0.53648789255105, -0.25049871956020, -0.42163034350696, -0.43193942311114, -0.00275953611929,
71 + -0.03424681017675, 0.04267842219415, -0.04678328784242, -0.10214864179676, 0.26408300200955,
72 + 0.14590772289388, 0.15113130533216, -0.02459864859345, -0.17556493366449, -0.11202315195388,
73 + -0.18823009262115, -0.04060034127000, 0.05477720428674, 0.04788665548180, 0.04704409688120,
74 + -0.02217936801134, 0.0, 0.0, 0.0}
75 +};
76 +
77 +static const Float_t ABButter[9][2 * BUTTER_ORDER + 1 + 3] __attribute__ ((aligned (16))) = {
78 + {0.98621192462708, -1.97223372919527, -1.97242384925416, 0.97261396931306, 0.98621192462708, 0.0, 0.0, 0.0},
79 + {0.98500175787242, -1.96977855582618, -1.97000351574484, 0.97022847566350, 0.98500175787242, 0.0, 0.0, 0.0},
80 + {0.97938932735214, -1.95835380975398, -1.95877865470428, 0.95920349965459, 0.97938932735214, 0.0, 0.0, 0.0},
81 + {0.97531843204928, -1.95002759149878, -1.95063686409857, 0.95124613669835, 0.97531843204928, 0.0, 0.0, 0.0},
82 + {0.97316523498161, -1.94561023566527, -1.94633046996323, 0.94705070426118, 0.97316523498161, 0.0, 0.0, 0.0},
83 + {0.96454515552826, -1.92783286977036, -1.92909031105652, 0.93034775234268, 0.96454515552826, 0.0, 0.0, 0.0},
84 + {0.96009142950541, -1.91858953033784, -1.92018285901082, 0.92177618768381, 0.96009142950541, 0.0, 0.0, 0.0},
85 + {0.95856916599601, -1.91542108074780, -1.91713833199203, 0.91885558323625, 0.95856916599601, 0.0, 0.0, 0.0},
86 + {0.94597685600279, -1.88903307939452, -1.89195371200558, 0.89487434461664, 0.94597685600279, 0.0, 0.0, 0.0}
87 +};
88 +#else
89 static const Float_t ABYule[9][multiple_of(4, 2 * YULE_ORDER + 1)] = {
90 /* 20 18 16 14 12 10 8 6 4 2 0 19 17 15 13 11 9 7 5 3 1 */
91 { 0.00288463683916, 0.00012025322027, 0.00306428023191, 0.00594298065125, -0.02074045215285, 0.02161526843274, -0.01655260341619, -0.00009291677959, -0.00123395316851, -0.02160367184185, 0.03857599435200, 0.13919314567432, -0.86984376593551, 2.75465861874613, -5.87257861775999, 9.48293806319790,-12.28759895145294, 13.05504219327545,-11.34170355132042, 7.81501653005538, -3.84664617118067},
92 @@ -133,7 +197,8 @@ static const Float_t ABButter[9][multipl
93 {0.96009142950541, 0.92177618768381, -1.92018285901082, -1.91858953033784, 0.96009142950541},
94 {0.95856916599601, 0.91885558323625, -1.91713833199203, -1.91542108074780, 0.95856916599601},
95 {0.94597685600279, 0.89487434461664, -1.89195371200558, -1.88903307939452, 0.94597685600279}
96 -};
97 + };
98 +#endif
99
100 /*lint -restore */
101
102 @@ -143,6 +208,128 @@ static const Float_t ABButter[9][multipl
103
104 /* When calling this procedure, make sure that ip[-order] and op[-order] point to real data! */
105
106 +#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
107 +static void
108 +filterYule(const Float_t * input, Float_t * output, size_t nSamples, const Float_t * const kernel)
109 +{
110 + __m128 v1, v2, v3, v4, v5, v6, v7, v8;
111 + __asm__ __volatile__ (
112 + "movups -12(%8), %0 \n\t"
113 + "movups -28(%8), %1 \n\t"
114 + "movlps -36(%8), %2 \n\t"
115 + "movups -16(%9), %3 \n\t"
116 + "movups -32(%9), %4 \n\t"
117 + "movlps -40(%9), %5 \n\t"
118 + "movaps %0, %6 \n\t"
119 + "movaps %1, %7 \n\t"
120 + "unpckhps %3, %0 \n\t"
121 + "unpckhps %4, %1 \n\t"
122 + "shufps $0x4e, %0, %0 \n\t"
123 + "shufps $0x4e, %1, %1 \n\t"
124 + "unpcklps %3, %6 \n\t"
125 + "unpcklps %4, %7 \n\t"
126 + "shufps $0x4e, %6, %6 \n\t"
127 + "shufps $0x4e, %7, %7 \n\t"
128 + "unpcklps %5, %2 \n\t"
129 + "shufps $0x4e, %2, %2 \n\t"
130 + "movss -40(%8), %3 \n\t"
131 + "jmp 2f \n\t"
132 + "1: \n\t"
133 + "movhlps %2, %3 \n\t"
134 + "movaps %7, %5 \n\t"
135 + "shufps $0x4e, %2, %5 \n\t"
136 + "movaps %5, %2 \n\t"
137 + "movaps %1, %5 \n\t"
138 + "shufps $0x4e, %7, %5 \n\t"
139 + "movaps %5, %7 \n\t"
140 + "movaps %6, %5 \n\t"
141 + "shufps $0x4e, %1, %5 \n\t"
142 + "movaps %5, %1 \n\t"
143 + "movaps %0, %5 \n\t"
144 + "shufps $0x4e, %6, %5 \n\t"
145 + "movaps %5, %6 \n\t"
146 + "movss (%8), %5 \n\t"
147 + "shufps $0x00, %5, %4 \n\t"
148 + "shufps $0x42, %0, %4 \n\t"
149 + "movaps %4, %0 \n\t"
150 + "2: \n\t"
151 + "movaps %0, %4 \n\t"
152 + "movaps %6, %5 \n\t"
153 + "mulps (%11), %4 \n\t"
154 + "mulps 16(%11), %5 \n\t"
155 + "addps %5, %4 \n\t"
156 + "movaps %1, %5 \n\t"
157 + "mulps 32(%11), %5 \n\t"
158 + "addps %5, %4 \n\t"
159 + "movaps %7, %5 \n\t"
160 + "mulps 48(%11), %5 \n\t"
161 + "addps %5, %4 \n\t"
162 + "movaps %2, %5 \n\t"
163 + "mulps 64(%11), %5 \n\t"
164 + "addps %5, %4 \n\t"
165 + "mulps 80(%11), %3 \n\t"
166 + "addps %3, %4 \n\t"
167 + "movhlps %4, %5 \n\t"
168 + "addps %5, %4 \n\t"
169 +#if defined(__SSE3__)
170 + "hsubps %4, %4 \n\t"
171 +#else
172 + "movaps %4, %5 \n\t"
173 + "shufps $0x01, %5, %5 \n\t"
174 + "subps %5, %4 \n\t"
175 +#endif
176 + "movss %4, (%9) \n\t"
177 + "add $4, %8 \n\t"
178 + "add $4, %9 \n\t"
179 + "dec %10 \n\t"
180 + "jnz 1b \n\t"
181 + : "=x" (v1), "=x" (v2), "=x" (v3), "=x" (v4), "=x" (v5), "=x" (v6), "=x" (v7), "=x" (v8),
182 + "+r" (input), "+r" (output), "+r" (nSamples)
183 + : "r" (kernel)
184 + );
185 +}
186 +
187 +static void
188 +filterButter(const Float_t * input, Float_t * output, size_t nSamples, const Float_t * const kernel)
189 +{
190 + __m128 v1, v2, v3, v4, v5;
191 + __asm__ __volatile__ (
192 + "movlps -4(%5), %0 \n\t"
193 + "movlps -8(%6), %2 \n\t"
194 + "unpcklps %2, %0 \n\t"
195 + "shufps $0x4e, %0, %0 \n\t"
196 + "movss -8(%5), %4 \n\t"
197 + "movaps %0, %1 \n\t"
198 + "jmp 2f \n\t"
199 + "1: \n\t"
200 + "movhlps %0, %4 \n\t"
201 + "movss (%5), %2 \n\t"
202 + "shufps $0x00, %2, %1 \n\t"
203 + "shufps $0x42, %0, %1 \n\t"
204 + "movaps %1, %0 \n\t"
205 + "2: \n\t"
206 + "mulps (%8), %1 \n\t"
207 + "mulps 16(%8), %4 \n\t"
208 + "addps %4, %1 \n\t"
209 + "movhlps %1, %2 \n\t"
210 + "addps %2, %1 \n\t"
211 +#if defined(__SSE3__)
212 + "hsubps %1, %1 \n\t"
213 +#else
214 + "movaps %1, %2 \n\t"
215 + "shufps $0x01, %2, %2 \n\t"
216 + "subps %2, %1 \n\t"
217 +#endif
218 + "movss %1, (%6) \n\t"
219 + "add $4, %5 \n\t"
220 + "add $4, %6 \n\t"
221 + "dec %7 \n\t"
222 + "jnz 1b \n\t"
223 + : "=x" (v1), "=x" (v2), "=x" (v3), "=x" (v4), "=x" (v5), "+r" (input), "+r" (output), "+r" (nSamples)
224 + : "r" (kernel)
225 + );
226 +}
227 +#else
228 static void
229 filterYule(const Float_t * input, Float_t * output, size_t nSamples, const Float_t * const kernel)
230 {
231 @@ -188,6 +375,7 @@ filterButter(const Float_t * input, Floa
232 ++input;
233 }
234 }
235 +#endif
236
237
238
239 --- libmp3lame/l3side.h.orig 2012-02-07 22:36:35.000000000 +0900
240 +++ libmp3lame/l3side.h 2017-10-14 12:03:44.000000000 +0900
241 @@ -46,7 +46,7 @@ typedef struct {
242
243 typedef struct {
244 FLOAT xr[576];
245 - int l3_enc[576];
246 + int l3_enc[576] __attribute__ ((aligned (16)));
247 int scalefac[SFBMAX];
248 FLOAT xrpow_max;
249
250 @@ -84,7 +84,7 @@ typedef struct {
251 } gr_info;
252
253 typedef struct {
254 - gr_info tt[2][2];
255 + gr_info tt[2][2] __attribute__ ((aligned (16)));
256 int main_data_begin;
257 int private_bits;
258 int resvDrain_pre;
259 --- libmp3lame/lame.c.orig 2017-10-11 04:08:39.000000000 +0900
260 +++ libmp3lame/lame.c 2017-10-14 12:03:44.000000000 +0900
261 @@ -2364,7 +2364,7 @@ lame_init_internal_flags(lame_internal_f
262 gfc->ov_rpg.noclipGainChange = 0;
263 gfc->ov_rpg.noclipScale = -1.0;
264
265 - gfc->ATH = lame_calloc(ATH_t, 1);
266 + gfc->ATH = calloc_aligned16(1, sizeof(ATH_t));
267 if (NULL == gfc->ATH)
268 return -2; /* maybe error codes should be enumerated in lame.h ?? */
269
270 @@ -2455,7 +2455,7 @@ lame_init_old(lame_global_flags * gfp)
271 gfp->report.errorf = &lame_report_def;
272 gfp->report.msgf = &lame_report_def;
273
274 - gfp->internal_flags = lame_calloc(lame_internal_flags, 1);
275 + gfp->internal_flags = calloc_aligned16(1, sizeof(lame_internal_flags));
276
277 if (lame_init_internal_flags(gfp->internal_flags) < 0) {
278 freegfc(gfp->internal_flags);
279 --- libmp3lame/newmdct.c.orig 2011-05-08 01:05:17.000000000 +0900
280 +++ libmp3lame/newmdct.c 2017-10-14 12:03:44.000000000 +0900
281 @@ -36,10 +36,13 @@
282 #include "util.h"
283 #include "newmdct.h"
284
285 +#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
286 +#include <xmmintrin.h>
287 +#endif
288
289
290 #ifndef USE_GOGO_SUBBAND
291 -static const FLOAT enwindow[] = {
292 +static const FLOAT enwindow[] __attribute__ ((aligned (16))) = {
293 -4.77e-07 * 0.740951125354959 / 2.384e-06, 1.03951e-04 * 0.740951125354959 / 2.384e-06,
294 9.53674e-04 * 0.740951125354959 / 2.384e-06, 2.841473e-03 * 0.740951125354959 / 2.384e-06,
295 3.5758972e-02 * 0.740951125354959 / 2.384e-06, 3.401756e-03 * 0.740951125354959 / 2.384e-06, 9.83715e-04 * 0.740951125354959 / 2.384e-06, 9.9182e-05 * 0.740951125354959 / 2.384e-06, /* 15 */
296 @@ -435,6 +438,241 @@ window_subband(const sample_t * x1, FLOA
297
298 const sample_t *x2 = &x1[238 - 14 - 286];
299
300 +#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
301 + __m128 v1, v2, v3, v4, v5, v6, v7, v8;
302 + i=4;
303 + __asm__ __volatile__ (
304 + "1: \n\t"
305 + "movaps -40(%12), %0 \n\t"
306 + "movups 32(%12), %1 \n\t"
307 + "movaps 104(%12), %2 \n\t"
308 + "movups 176(%12), %3 \n\t"
309 + "movaps %0, %4 \n\t"
310 + "movaps %2, %5 \n\t"
311 + "unpcklps %1, %0 \n\t"
312 + "unpcklps %3, %2 \n\t"
313 + "unpckhps %1, %4 \n\t"
314 + "unpckhps %3, %5 \n\t"
315 + "movaps %0, %1 \n\t"
316 + "movlhps %2, %0 \n\t"
317 + "movhlps %1, %2 \n\t"
318 + "movaps %4, %1 \n\t"
319 + "movlhps %5, %1 \n\t"
320 + "movhlps %4, %5 \n\t"
321 + "movaps %5, %3 \n\t"
322 + "movups 884(%9), %6 \n\t"
323 + "movups -896(%10), %7 \n\t"
324 + "shufps $0x1b, %6, %6 \n\t"
325 + "mulps %0, %6 \n\t"
326 + "mulps %0, %7 \n\t"
327 + "movups 628(%9), %4 \n\t"
328 + "movups -640(%10), %5 \n\t"
329 + "shufps $0x1b, %4, %4 \n\t"
330 + "mulps %2, %4 \n\t"
331 + "mulps %2, %5 \n\t"
332 + "addps %4, %6 \n\t"
333 + "addps %5, %7 \n\t"
334 + "movups 372(%9), %4 \n\t"
335 + "movups -384(%10), %5 \n\t"
336 + "shufps $0x1b, %4, %4 \n\t"
337 + "mulps %1, %4 \n\t"
338 + "mulps %1, %5 \n\t"
339 + "addps %4, %6 \n\t"
340 + "addps %5, %7 \n\t"
341 + "movups 116(%9), %4 \n\t"
342 + "movups -128(%10), %5 \n\t"
343 + "shufps $0x1b, %4, %4 \n\t"
344 + "mulps %3, %4 \n\t"
345 + "mulps %3, %5 \n\t"
346 + "addps %4, %6 \n\t"
347 + "addps %5, %7 \n\t"
348 +
349 + "movaps -24(%12), %0 \n\t"
350 + "movups 48(%12), %1 \n\t"
351 + "movaps 120(%12), %2 \n\t"
352 + "movups 192(%12), %3 \n\t"
353 + "movaps %0, %4 \n\t"
354 + "movaps %2, %5 \n\t"
355 + "unpcklps %1, %0 \n\t"
356 + "unpcklps %3, %2 \n\t"
357 + "unpckhps %1, %4 \n\t"
358 + "unpckhps %3, %5 \n\t"
359 + "movaps %0, %1 \n\t"
360 + "movlhps %2, %0 \n\t"
361 + "movhlps %1, %2 \n\t"
362 + "movaps %4, %1 \n\t"
363 + "movlhps %5, %1 \n\t"
364 + "movhlps %4, %5 \n\t"
365 + "movaps %5, %3 \n\t"
366 + "movups -140(%9), %4 \n\t"
367 + "movups 128(%10), %5 \n\t"
368 + "shufps $0x1b, %4, %4 \n\t"
369 + "mulps %0, %4 \n\t"
370 + "mulps %0, %5 \n\t"
371 + "addps %4, %6 \n\t"
372 + "addps %5, %7 \n\t"
373 + "movups -396(%9), %4 \n\t"
374 + "movups 384(%10), %5 \n\t"
375 + "shufps $0x1b, %4, %4 \n\t"
376 + "mulps %2, %4 \n\t"
377 + "mulps %2, %5 \n\t"
378 + "addps %4, %6 \n\t"
379 + "addps %5, %7 \n\t"
380 + "movups -652(%9), %4 \n\t"
381 + "movups 640(%10), %5 \n\t"
382 + "shufps $0x1b, %4, %4 \n\t"
383 + "mulps %1, %4 \n\t"
384 + "mulps %1, %5 \n\t"
385 + "addps %4, %6 \n\t"
386 + "addps %5, %7 \n\t"
387 + "movups -908(%9), %4 \n\t"
388 + "movups 896(%10), %5 \n\t"
389 + "shufps $0x1b, %4, %4 \n\t"
390 + "mulps %3, %4 \n\t"
391 + "mulps %3, %5 \n\t"
392 + "addps %4, %6 \n\t"
393 + "addps %5, %7 \n\t"
394 +
395 + "movaps -8(%12), %0 \n\t"
396 + "movups 64(%12), %1 \n\t"
397 + "movaps 136(%12), %2 \n\t"
398 + "movups 208(%12), %3 \n\t"
399 + "movaps %0, %4 \n\t"
400 + "movaps %2, %5 \n\t"
401 + "unpcklps %1, %0 \n\t"
402 + "unpcklps %3, %2 \n\t"
403 + "unpckhps %1, %4 \n\t"
404 + "unpckhps %3, %5 \n\t"
405 + "movaps %0, %1 \n\t"
406 + "movlhps %2, %0 \n\t"
407 + "movhlps %1, %2 \n\t"
408 + "movaps %4, %1 \n\t"
409 + "movlhps %5, %1 \n\t"
410 + "movhlps %4, %5 \n\t"
411 + "movaps %5, %3 \n\t"
412 + "movups -1036(%9), %4 \n\t"
413 + "movups 1024(%10), %5 \n\t"
414 + "shufps $0x1b, %4, %4 \n\t"
415 + "mulps %0, %4 \n\t"
416 + "mulps %0, %5 \n\t"
417 + "addps %4, %7 \n\t"
418 + "subps %5, %6 \n\t"
419 + "movups -780(%9), %4 \n\t"
420 + "movups 768(%10), %5 \n\t"
421 + "shufps $0x1b, %4, %4 \n\t"
422 + "mulps %2, %4 \n\t"
423 + "mulps %2, %5 \n\t"
424 + "addps %4, %7 \n\t"
425 + "subps %5, %6 \n\t"
426 + "movups -524(%9), %4 \n\t"
427 + "movups 512(%10), %5 \n\t"
428 + "shufps $0x1b, %4, %4 \n\t"
429 + "mulps %1, %4 \n\t"
430 + "mulps %1, %5 \n\t"
431 + "addps %4, %7 \n\t"
432 + "subps %5, %6 \n\t"
433 + "movups -268(%9), %4 \n\t"
434 + "movups 256(%10), %5 \n\t"
435 + "shufps $0x1b, %4, %4 \n\t"
436 + "mulps %3, %4 \n\t"
437 + "mulps %3, %5 \n\t"
438 + "addps %4, %7 \n\t"
439 + "subps %5, %6 \n\t"
440 +
441 + "movaps 8(%12), %0 \n\t"
442 + "movups 80(%12), %1 \n\t"
443 + "movaps 152(%12), %2 \n\t"
444 + "movups 224(%12), %3 \n\t"
445 + "movaps %0, %4 \n\t"
446 + "movaps %2, %5 \n\t"
447 + "unpcklps %1, %0 \n\t"
448 + "unpcklps %3, %2 \n\t"
449 + "unpckhps %1, %4 \n\t"
450 + "unpckhps %3, %5 \n\t"
451 + "movaps %0, %1 \n\t"
452 + "movlhps %2, %0 \n\t"
453 + "movhlps %1, %2 \n\t"
454 + "movaps %4, %1 \n\t"
455 + "movlhps %5, %1 \n\t"
456 + "movhlps %4, %5 \n\t"
457 + "movaps %5, %3 \n\t"
458 + "movups -12(%9), %4 \n\t"
459 + "movups (%10), %5 \n\t"
460 + "shufps $0x1b, %4, %4 \n\t"
461 + "mulps %0, %4 \n\t"
462 + "mulps %0, %5 \n\t"
463 + "addps %4, %7 \n\t"
464 + "subps %5, %6 \n\t"
465 + "movups 244(%9), %4 \n\t"
466 + "movups -256(%10), %5 \n\t"
467 + "shufps $0x1b, %4, %4 \n\t"
468 + "mulps %2, %4 \n\t"
469 + "mulps %2, %5 \n\t"
470 + "addps %4, %7 \n\t"
471 + "subps %5, %6 \n\t"
472 + "movups 500(%9), %4 \n\t"
473 + "movups -512(%10), %5 \n\t"
474 + "shufps $0x1b, %4, %4 \n\t"
475 + "mulps %1, %4 \n\t"
476 + "mulps %1, %5 \n\t"
477 + "addps %4, %7 \n\t"
478 + "subps %5, %6 \n\t"
479 + "movups 756(%9), %4 \n\t"
480 + "movups -768(%10), %5 \n\t"
481 + "shufps $0x1b, %4, %4 \n\t"
482 + "mulps %3, %4 \n\t"
483 + "mulps %3, %5 \n\t"
484 + "addps %4, %7 \n\t"
485 + "subps %5, %6 \n\t"
486 +
487 + "movlps 24(%12), %0 \n\t"
488 + "movlps 96(%12), %1 \n\t"
489 + "movlps 168(%12), %2 \n\t"
490 + "movlps 240(%12), %3 \n\t"
491 + "unpcklps %1, %0 \n\t"
492 + "unpcklps %3, %2 \n\t"
493 + "movaps %0, %1 \n\t"
494 + "movlhps %2, %0 \n\t"
495 + "movhlps %1, %2 \n\t"
496 + "mulps %0, %7 \n\t"
497 + "movaps %6, %4 \n\t"
498 + "subps %7, %4 \n\t"
499 + "addps %7, %6 \n\t"
500 + "mulps %2, %4 \n\t"
501 + "movaps %6, %5 \n\t"
502 + "unpcklps %4, %6 \n\t"
503 + "unpckhps %4, %5 \n\t"
504 + "movups %6, (%11) \n\t"
505 + "movups %5, 16(%11) \n\t"
506 +
507 +#if defined(__x86_64__)
508 + "subq $16, %9 \n\t"
509 + "addq $16, %10 \n\t"
510 + "addq $288, %12 \n\t"
511 + "addq $32, %11 \n\t"
512 + "decl %8 \n\t"
513 + "jnz 1b \n\t"
514 + "addq $4, %9 \n\t"
515 + "subq $4, %10 \n\t"
516 + "subq $128, %11 \n\t"
517 +#else
518 + "subl $16, %9 \n\t"
519 + "addl $16, %10 \n\t"
520 + "addl $288, %12 \n\t"
521 + "addl $32, %11 \n\t"
522 + "decl %8 \n\t"
523 + "jnz 1b \n\t"
524 + "addl $4, %9 \n\t"
525 + "subl $4, %10 \n\t"
526 + "subl $128, %11 \n\t"
527 +#endif
528 + : "=x" (v1), "=x" (v2), "=x" (v3), "=x" (v4), "=x" (v5), "=x" (v6), "=x" (v7), "=x" (v8),
529 + "+r" (i), "+r" (x1), "+r" (x2), "+r" (a)
530 + : "r" (wp)
531 + : "memory"
532 + );
533 + wp = enwindow + 280;
534 +#else
535 for (i = -15; i < 0; i++) {
536 FLOAT w, s, t;
537
538 @@ -501,6 +739,7 @@ window_subband(const sample_t * x1, FLOA
539 x1--;
540 x2++;
541 }
542 +#endif
543 {
544 FLOAT s, t, u, v;
545 t = x1[-16] * wp[-10];
546 --- libmp3lame/psymodel.c.orig 2017-09-07 04:38:23.000000000 +0900
547 +++ libmp3lame/psymodel.c 2017-10-14 12:03:44.000000000 +0900
548 @@ -155,6 +155,9 @@ blocktype_d[2] block type to use
549 #include "fft.h"
550 #include "lame-analysis.h"
551
552 +#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
553 +#include <xmmintrin.h>
554 +#endif
555
556 #define NSFIRLEN 21
557
558 @@ -218,10 +221,58 @@ psycho_loudness_approx(FLOAT const *ener
559 int i;
560 FLOAT loudness_power;
561
562 +#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
563 + __m128 v1, v2, v3, v4, v5, v6, v7, v8;
564 + i = 32;
565 + __asm__ __volatile__ (
566 + "xorps %0, %0 \n\t"
567 + "xorps %1, %1 \n\t"
568 + "xorps %2, %2 \n\t"
569 + "xorps %3, %3 \n\t"
570 + "1: \n\t"
571 + "movaps (%9), %4 \n\t"
572 + "movaps 16(%9), %5 \n\t"
573 + "movaps 32(%9), %6 \n\t"
574 + "movaps 48(%9), %7 \n\t"
575 + "mulps (%10), %4 \n\t"
576 + "mulps 16(%10), %5 \n\t"
577 + "mulps 32(%10), %6 \n\t"
578 + "mulps 48(%10), %7 \n\t"
579 + "addps %4, %0 \n\t"
580 + "addps %5, %1 \n\t"
581 + "addps %6, %2 \n\t"
582 + "addps %7, %3 \n\t"
583 +#if defined(__x86_64__)
584 + "addq $64, %9 \n\t"
585 + "addq $64, %10 \n\t"
586 +#else
587 + "addl $64, %9 \n\t"
588 + "addl $64, %10 \n\t"
589 +#endif
590 + "decl %8 \n\t"
591 + "jnz 1b \n\t"
592 + "addps %1, %0 \n\t"
593 + "addps %3, %2 \n\t"
594 + "addps %2, %0 \n\t"
595 + "movhlps %0, %1 \n\t"
596 + "addps %1, %0 \n\t"
597 +#if defined(__SSE3__)
598 + "haddps %0, %0 \n\t"
599 +#else
600 + "movaps %0, %1 \n\t"
601 + "shufps $0x01, %1, %1 \n\t"
602 + "addps %1, %0 \n\t"
603 +#endif
604 + : "=x" (v1), "=x" (v2), "=x" (v3), "=x" (v4), "=x" (v5), "=x" (v6), "=x" (v7), "=x" (v8),
605 + "+r" (i), "+r" (eql_w), "+r" (energy)
606 + );
607 + _mm_store_ss(&loudness_power, v1);
608 +#else
609 loudness_power = 0.0;
610 /* apply weights to power in freq. bands */
611 for (i = 0; i < BLKSIZE / 2; ++i)
612 loudness_power += energy[i] * eql_w[i];
613 +#endif
614 loudness_power *= VO_SCALE;
615
616 return loudness_power;
617 @@ -666,6 +717,9 @@ static void
618 vbrpsy_compute_fft_l(lame_internal_flags * gfc, const sample_t * const buffer[2], int chn,
619 int gr_out, FLOAT fftenergy[HBLKSIZE], FLOAT(*wsamp_l)[BLKSIZE])
620 {
621 +#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
622 + __m128 v1, v2, v3, v4, v5, v6, v7;
623 +#endif
624 SessionConfig_t const *const cfg = &gfc->cfg;
625 PsyStateVar_t *psv = &gfc->sv_psy;
626 plotting_data *plt = cfg->analysis ? gfc->pinfo : 0;
627 @@ -676,6 +730,47 @@ vbrpsy_compute_fft_l(lame_internal_flags
628 }
629 else if (chn == 2) {
630 FLOAT const sqrt2_half = SQRT2 * 0.5f;
631 +#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
632 + FLOAT *wsamp_lp1 = *wsamp_l;
633 + FLOAT *wsamp_lp2 = *wsamp_l+1024;
634 + j = 128;
635 + __asm__ __volatile__ (
636 + "movss (%10), %6 \n\t"
637 + "shufps $0x00, %6, %6 \n\t"
638 + "1: \n\t"
639 + "movaps (%8), %0 \n\t"
640 + "movaps 16(%8), %1 \n\t"
641 + "movaps (%9), %2 \n\t"
642 + "movaps 16(%9), %3 \n\t"
643 + "movaps %0, %4 \n\t"
644 + "movaps %1, %5 \n\t"
645 + "addps %2, %0 \n\t"
646 + "addps %3, %1 \n\t"
647 + "subps %2, %4 \n\t"
648 + "subps %3, %5 \n\t"
649 + "mulps %6, %0 \n\t"
650 + "mulps %6, %1 \n\t"
651 + "mulps %6, %4 \n\t"
652 + "mulps %6, %5 \n\t"
653 + "movaps %0, (%8) \n\t"
654 + "movaps %1, 16(%8) \n\t"
655 + "movaps %4, 0(%9) \n\t"
656 + "movaps %5, 16(%9) \n\t"
657 +#if defined(__x86_64__)
658 + "addq $32, %8 \n\t"
659 + "addq $32, %9 \n\t"
660 +#else
661 + "addl $32, %8 \n\t"
662 + "addl $32, %9 \n\t"
663 +#endif
664 + "decl %7 \n\t"
665 + "jnz 1b \n\t"
666 + : "=x" (v1), "=x" (v2), "=x" (v3), "=x" (v4), "=x" (v5), "=x" (v6), "=x" (v7),
667 + "+r" (j), "+r" (wsamp_lp1), "+r" (wsamp_lp2)
668 + : "r" (&sqrt2_half)
669 + : "memory"
670 + );
671 +#else
672 /* FFT data for mid and side channel is derived from L & R */
673 for (j = BLKSIZE - 1; j >= 0; --j) {
674 FLOAT const l = wsamp_l[0][j];
675 @@ -683,6 +778,7 @@ vbrpsy_compute_fft_l(lame_internal_flags
676 wsamp_l[0][j] = (l + r) * sqrt2_half;
677 wsamp_l[1][j] = (l - r) * sqrt2_half;
678 }
679 +#endif
680 }
681
682 /*********************************************************************
683 @@ -691,6 +787,73 @@ vbrpsy_compute_fft_l(lame_internal_flags
684 fftenergy[0] = wsamp_l[0][0];
685 fftenergy[0] *= fftenergy[0];
686
687 +#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
688 + FLOAT *wsamp_lp1 = *wsamp_l+1;
689 + FLOAT *wsamp_lp2 = *wsamp_l+1020;
690 + FLOAT *fftenergyp = fftenergy+1;
691 + j = 64;
692 + __asm__ __volatile__ (
693 + "pcmpeqd %4, %4 \n\t"
694 + "psrld $26, %4 \n\t"
695 + "pslld $24, %4 \n\t"
696 + "xorps %5, %5 \n\t"
697 + "1: \n\t"
698 + "movups (%7), %0 \n\t"
699 + "movups 16(%7), %1 \n\t"
700 + "movaps (%8), %2 \n\t"
701 + "movaps -16(%8), %3 \n\t"
702 + "shufps $0x1b, %2, %2 \n\t"
703 + "shufps $0x1b, %3, %3 \n\t"
704 + "mulps %0, %0 \n\t"
705 + "mulps %2, %2 \n\t"
706 + "mulps %1, %1 \n\t"
707 + "mulps %3, %3 \n\t"
708 + "addps %2, %0 \n\t"
709 + "addps %3, %1 \n\t"
710 + "mulps %4, %0 \n\t"
711 + "mulps %4, %1 \n\t"
712 + "movups %0, (%9) \n\t"
713 + "movups %1, 16(%9) \n\t"
714 + "addps %1, %0 \n\t"
715 + "addps %0, %5 \n\t"
716 +#if defined(__x86_64__)
717 + "addq $32, %7 \n\t"
718 + "subq $32, %8 \n\t"
719 + "addq $32, %9 \n\t"
720 + "decl %6 \n\t"
721 + "jnz 1b \n\t"
722 + "subq $2048, %9 \n\t"
723 +#else
724 + "addl $32, %7 \n\t"
725 + "subl $32, %8 \n\t"
726 + "addl $32, %9 \n\t"
727 + "decl %6 \n\t"
728 + "jnz 1b \n\t"
729 + "subl $2048, %9 \n\t"
730 +#endif
731 + "movups (%9), %0 \n\t"
732 + "movups 16(%9), %1 \n\t"
733 + "xorps %2, %2 \n\t"
734 + "movlps 32(%9), %2 \n\t"
735 + "addps %1, %0 \n\t"
736 + "addps %2, %0 \n\t"
737 + "subps %0, %5 \n\t"
738 + "movhlps %5, %0 \n\t"
739 + "addps %5, %0 \n\t"
740 +#if defined(__SSE3__)
741 + "haddps %0, %0 \n\t"
742 +#else
743 + "movaps %0, %1 \n\t"
744 + "shufps $0x01, %1, %1 \n\t"
745 + "addps %1, %0 \n\t"
746 +#endif
747 + "movss %0, (%10) \n\t"
748 + : "=x" (v1), "=x" (v2), "=x" (v3), "=x" (v4), "=x" (v5), "=x" (v6),
749 + "+r" (j), "+r" (wsamp_lp1), "+r" (wsamp_lp2), "+r" (fftenergyp)
750 + : "r" (&psv->tot_ener[chn])
751 + : "memory"
752 + );
753 +#else
754 for (j = BLKSIZE / 2 - 1; j >= 0; --j) {
755 FLOAT const re = (*wsamp_l)[BLKSIZE / 2 - j];
756 FLOAT const im = (*wsamp_l)[BLKSIZE / 2 + j];
757 @@ -704,6 +867,7 @@ vbrpsy_compute_fft_l(lame_internal_flags
758
759 psv->tot_ener[chn] = totalenergy;
760 }
761 +#endif
762
763 if (plt) {
764 for (j = 0; j < HBLKSIZE; j++) {
765 @@ -772,7 +936,7 @@ vbrpsy_attack_detection(lame_internal_fl
766 FLOAT energy[4], FLOAT sub_short_factor[4][3], int ns_attacks[4][4],
767 int uselongblock[2])
768 {
769 - FLOAT ns_hpfsmpl[2][576];
770 + FLOAT ns_hpfsmpl[2][576] __attribute__ ((aligned (16)));
771 SessionConfig_t const *const cfg = &gfc->cfg;
772 PsyStateVar_t *const psv = &gfc->sv_psy;
773 plotting_data *plt = cfg->analysis ? gfc->pinfo : 0;
774 @@ -785,14 +949,170 @@ vbrpsy_attack_detection(lame_internal_fl
775 /* Don't copy the input buffer into a temporary buffer */
776 /* unroll the loop 2 times */
777 for (chn = 0; chn < n_chn_out; chn++) {
778 - static const FLOAT fircoef[] = {
779 + static const FLOAT fircoef[] __attribute__ ((aligned (16))) = {
780 -8.65163e-18 * 2, -0.00851586 * 2, -6.74764e-18 * 2, 0.0209036 * 2,
781 -3.36639e-17 * 2, -0.0438162 * 2, -1.54175e-17 * 2, 0.0931738 * 2,
782 - -5.52212e-17 * 2, -0.313819 * 2
783 + -5.52212e-17 * 2, -0.313819 * 2, 0, 0
784 };
785 /* apply high pass filter of fs/4 */
786 const sample_t *const firbuf = &buffer[chn][576 - 350 - NSFIRLEN + 192];
787 - assert(dimension_of(fircoef) == ((NSFIRLEN - 1) / 2));
788 + //assert(dimension_of(fircoef) == ((NSFIRLEN - 1) / 2));
789 +#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
790 + __m128 v1, v2, v3, v4, v5, v6, v7;
791 + float *firbufp = (float *)firbuf;
792 + float *ns_hpfsmplp = &ns_hpfsmpl[chn][0];
793 + i = 144;
794 + __asm__ __volatile__ (
795 + "1: \n\t"
796 + "movups 40(%8), %0 \n\t"
797 + "xorps %1, %1 \n\t"
798 + "movaps %0, %2 \n\t"
799 + "unpcklps %1, %0 \n\t"
800 + "unpckhps %1, %2 \n\t"
801 + "movaps %2, %1 \n\t"
802 +
803 + "movaps (%10), %2 \n\t"
804 + "movups (%8), %3 \n\t"
805 + "movups 72(%8), %4 \n\t"
806 + "shufps $0x1b, %4, %4 \n\t"
807 + "addps %4, %3 \n\t"
808 + "mulps %3, %2 \n\t"
809 + "movaps 16(%10), %5 \n\t"
810 + "movups 16(%8), %3 \n\t"
811 + "movups 56(%8), %4 \n\t"
812 + "shufps $0x1b, %4, %4 \n\t"
813 + "addps %4, %3 \n\t"
814 + "mulps %3, %5 \n\t"
815 + "addps %5, %2 \n\t"
816 + "movaps 32(%10), %5 \n\t"
817 + "movups 32(%8), %3 \n\t"
818 + "movups 40(%8), %4 \n\t"
819 + "shufps $0x1b, %4, %4 \n\t"
820 + "addps %4, %3 \n\t"
821 + "mulps %3, %5 \n\t"
822 + "addps %5, %2 \n\t"
823 + "movhlps %2, %6 \n\t"
824 + "addps %2, %6 \n\t"
825 +#if defined(__x86_64__)
826 + "addq $4, %8 \n\t"
827 +#else
828 + "addl $4, %8 \n\t"
829 +#endif
830 +
831 + "movaps (%10), %2 \n\t"
832 + "movups (%8), %3 \n\t"
833 + "movups 72(%8), %4 \n\t"
834 + "shufps $0x1b, %4, %4 \n\t"
835 + "addps %4, %3 \n\t"
836 + "mulps %3, %2 \n\t"
837 + "movaps 16(%10), %5 \n\t"
838 + "movups 16(%8), %3 \n\t"
839 + "movups 56(%8), %4 \n\t"
840 + "shufps $0x1b, %4, %4 \n\t"
841 + "addps %4, %3 \n\t"
842 + "mulps %3, %5 \n\t"
843 + "addps %5, %2 \n\t"
844 + "movaps 32(%10), %5 \n\t"
845 + "movups 32(%8), %3 \n\t"
846 + "movups 40(%8), %4 \n\t"
847 + "shufps $0x1b, %4, %4 \n\t"
848 + "addps %4, %3 \n\t"
849 + "mulps %3, %5 \n\t"
850 + "addps %5, %2 \n\t"
851 + "movhlps %2, %3 \n\t"
852 + "addps %3, %2 \n\t"
853 + "movlhps %2, %6 \n\t"
854 + "addps %6, %0 \n\t"
855 +#if defined(__x86_64__)
856 + "addq $4, %8 \n\t"
857 +#else
858 + "addl $4, %8 \n\t"
859 +#endif
860 +
861 + "movaps (%10), %2 \n\t"
862 + "movups (%8), %3 \n\t"
863 + "movups 72(%8), %4 \n\t"
864 + "shufps $0x1b, %4, %4 \n\t"
865 + "addps %4, %3 \n\t"
866 + "mulps %3, %2 \n\t"
867 + "movaps 16(%10), %5 \n\t"
868 + "movups 16(%8), %3 \n\t"
869 + "movups 56(%8), %4 \n\t"
870 + "shufps $0x1b, %4, %4 \n\t"
871 + "addps %4, %3 \n\t"
872 + "mulps %3, %5 \n\t"
873 + "addps %5, %2 \n\t"
874 + "movaps 32(%10), %5 \n\t"
875 + "movups 32(%8), %3 \n\t"
876 + "movups 40(%8), %4 \n\t"
877 + "shufps $0x1b, %4, %4 \n\t"
878 + "addps %4, %3 \n\t"
879 + "mulps %3, %5 \n\t"
880 + "addps %5, %2 \n\t"
881 + "movhlps %2, %6 \n\t"
882 + "addps %2, %6 \n\t"
883 +#if defined(__x86_64__)
884 + "addq $4, %8 \n\t"
885 +#else
886 + "addl $4, %8 \n\t"
887 +#endif
888 +
889 + "movaps (%10), %2 \n\t"
890 + "movups (%8), %3 \n\t"
891 + "movups 72(%8), %4 \n\t"
892 + "shufps $0x1b, %4, %4 \n\t"
893 + "addps %4, %3 \n\t"
894 + "mulps %3, %2 \n\t"
895 + "movaps 16(%10), %5 \n\t"
896 + "movups 16(%8), %3 \n\t"
897 + "movups 56(%8), %4 \n\t"
898 + "shufps $0x1b, %4, %4 \n\t"
899 + "addps %4, %3 \n\t"
900 + "mulps %3, %5 \n\t"
901 + "addps %5, %2 \n\t"
902 + "movaps 32(%10), %5 \n\t"
903 + "movups 32(%8), %3 \n\t"
904 + "movups 40(%8), %4 \n\t"
905 + "shufps $0x1b, %4, %4 \n\t"
906 + "addps %4, %3 \n\t"
907 + "mulps %3, %5 \n\t"
908 + "addps %5, %2 \n\t"
909 + "movhlps %2, %3 \n\t"
910 + "addps %3, %2 \n\t"
911 + "movlhps %2, %6 \n\t"
912 + "addps %6, %1 \n\t"
913 +#if defined(__x86_64__)
914 + "addq $4, %8 \n\t"
915 +#else
916 + "addl $4, %8 \n\t"
917 +#endif
918 +
919 +#if defined(__SSE3__)
920 + "haddps %1, %0 \n\t"
921 +#else
922 + "movaps %0, %2 \n\t"
923 + "movaps %1, %3 \n\t"
924 + "shufps $0x31, %2, %2 \n\t"
925 + "shufps $0x31, %3, %3 \n\t"
926 + "addps %2, %0 \n\t"
927 + "addps %3, %1 \n\t"
928 + "shufps $0x88, %1, %0 \n\t"
929 +#endif
930 + "movaps %0, (%9) \n\t"
931 +
932 +#if defined(__x86_64__)
933 + "addq $16, %9 \n\t"
934 +#else
935 + "addl $16, %9 \n\t"
936 +#endif
937 + "decl %7 \n\t"
938 + "jnz 1b \n\t"
939 + : "=x" (v1), "=x" (v2), "=x" (v3), "=x" (v4), "=x" (v5), "=x" (v6), "=x" (v7),
940 + "+r" (i), "+r" (firbufp), "+r" (ns_hpfsmplp)
941 + : "r" (fircoef)
942 + : "memory"
943 + );
944 +#else
945 for (i = 0; i < 576; i++) {
946 FLOAT sum1, sum2;
947 sum1 = firbuf[i + 10];
948 @@ -803,6 +1123,7 @@ vbrpsy_attack_detection(lame_internal_fl
949 }
950 ns_hpfsmpl[chn][i] = sum1 + sum2;
951 }
952 +#endif
953 masking_ratio[gr_out][chn].en = psv->en[chn];
954 masking_ratio[gr_out][chn].thm = psv->thm[chn];
955 if (n_chn_psy > 2) {
956 @@ -1423,10 +1744,10 @@ L3psycho_anal_vbr(lame_internal_flags *
957 /* fft and energy calculation */
958 FLOAT(*wsamp_l)[BLKSIZE];
959 FLOAT(*wsamp_s)[3][BLKSIZE_s];
960 - FLOAT fftenergy[HBLKSIZE];
961 - FLOAT fftenergy_s[3][HBLKSIZE_s];
962 - FLOAT wsamp_L[2][BLKSIZE];
963 - FLOAT wsamp_S[2][3][BLKSIZE_s];
964 + FLOAT fftenergy[HBLKSIZE] __attribute__ ((aligned (16)));
965 + FLOAT fftenergy_s[3][HBLKSIZE_s] __attribute__ ((aligned (16)));
966 + FLOAT wsamp_L[2][BLKSIZE] __attribute__ ((aligned (16)));
967 + FLOAT wsamp_S[2][3][BLKSIZE_s] __attribute__ ((aligned (16)));
968 FLOAT eb[4][CBANDS], thr[4][CBANDS];
969
970 FLOAT sub_short_factor[4][3];
971 --- libmp3lame/quantize.c.orig 2017-08-15 22:40:45.000000000 +0900
972 +++ libmp3lame/quantize.c 2017-10-14 12:03:44.000000000 +0900
973 @@ -99,7 +99,7 @@ init_xrpow_core_init(lame_internal_flags
974 gfc->init_xrpow_core = init_xrpow_core_sse;
975 #endif
976 #ifndef HAVE_NASM
977 -#ifdef MIN_ARCH_SSE
978 +#if defined(MIN_ARCH_SSE) || defined(__x86_64__)
979 gfc->init_xrpow_core = init_xrpow_core_sse;
980 #endif
981 #endif
982 @@ -1495,7 +1495,7 @@ VBR_old_iteration_loop(lame_internal_fla
983 EncResult_t *const eov = &gfc->ov_enc;
984 FLOAT l3_xmin[2][2][SFBMAX];
985
986 - FLOAT xrpow[576];
987 + FLOAT xrpow[576] __attribute__ ((aligned (16)));
988 int bands[2][2];
989 int frameBits[15];
990 int used_bits;
991 @@ -1904,7 +1904,7 @@ ABR_iteration_loop(lame_internal_flags *
992 SessionConfig_t const *const cfg = &gfc->cfg;
993 EncResult_t *const eov = &gfc->ov_enc;
994 FLOAT l3_xmin[SFBMAX];
995 - FLOAT xrpow[576];
996 + FLOAT xrpow[576] __attribute__ ((aligned (16)));
997 int targ_bits[2][2];
998 int mean_bits, max_frame_bits;
999 int ch, gr, ath_over;
1000 @@ -1991,7 +1991,7 @@ CBR_iteration_loop(lame_internal_flags *
1001 {
1002 SessionConfig_t const *const cfg = &gfc->cfg;
1003 FLOAT l3_xmin[SFBMAX];
1004 - FLOAT xrpow[576];
1005 + FLOAT xrpow[576] __attribute__ ((aligned (16)));
1006 int targ_bits[2];
1007 int mean_bits, max_bits;
1008 int gr, ch;
1009 --- libmp3lame/quantize_pvt.c.orig 2017-09-07 04:33:36.000000000 +0900
1010 +++ libmp3lame/quantize_pvt.c 2017-10-14 12:03:44.000000000 +0900
1011 @@ -27,6 +27,7 @@
1012 # include <config.h>
1013 #endif
1014
1015 +#undef TAKEHIRO_IEEE754_HACK
1016
1017 #include "lame.h"
1018 #include "machine.h"
1019 @@ -37,6 +38,9 @@
1020 #include "lame-analysis.h"
1021 #include <float.h>
1022
1023 +#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
1024 +#include <xmmintrin.h>
1025 +#endif
1026
1027 #define NSATHSCALE 100 /* Assuming dynamic range=96dB, this value should be 92 */
1028
1029 @@ -767,6 +771,70 @@ calc_noise_core_c(const gr_info * const
1030 }
1031 }
1032 else if (j > cod_info->big_values) {
1033 +#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
1034 + __m128 v1, v2, v3, v4, v5;
1035 + int remaining = l & 1;
1036 + l = l >> 1;
1037 + const int *ixp = ix+j;
1038 + const FLOAT *xrp = cod_info->xr+j;
1039 + j += 4*l;
1040 + v5 = _mm_set_ss(step);
1041 + __asm__ __volatile__ (
1042 + "xorps %3, %3 \n\t"
1043 + "testl %5, %5 \n\t"
1044 + "jz 2f \n\t"
1045 + "shufps $0x00, %4, %4 \n\t"
1046 + "pcmpeqd %1, %1 \n\t"
1047 + "psrld $1, %1 \n\t"
1048 +
1049 + "1: \n\t"
1050 + "pxor %0, %0 \n\t"
1051 + "movups (%6), %2 \n\t"
1052 + "pcmpeqd %0, %2 \n\t"
1053 + "pandn %4, %2 \n\t"
1054 +
1055 + "movups (%7), %0 \n\t"
1056 + "andps %1, %0 \n\t"
1057 + "subps %2, %0 \n\t"
1058 + "mulps %0, %0 \n\t"
1059 + "addps %0, %3 \n\t"
1060 +
1061 +#if defined(__x86_64__)
1062 + "addq $16, %6 \n\t"
1063 + "addq $16, %7 \n\t"
1064 +#else
1065 + "addl $16, %6 \n\t"
1066 + "addl $16, %7 \n\t"
1067 +#endif
1068 + "decl %5 \n\t"
1069 + "jnz 1b \n\t"
1070 + "movhlps %3, %0 \n\t"
1071 + "addps %0, %3 \n\t"
1072 +#if defined(__SSE3__)
1073 + "haddps %3, %3 \n\t"
1074 +#else
1075 + "movaps %3, %0 \n\t"
1076 + "shufps $0x01, %0, %0 \n\t"
1077 + "addps %0, %3 \n\t"
1078 +#endif
1079 + "2: \n\t"
1080 + : "=x" (v1), "=x" (v2), "=x" (v3), "=x" (v4), "+x" (v5),
1081 + "+r" (l), "+r" (ixp), "+r" (xrp)
1082 + );
1083 + _mm_store_ss(&noise, v4);
1084 + if (remaining) {
1085 + FLOAT ix01[2];
1086 + ix01[0] = 0;
1087 + ix01[1] = step;
1088 + FLOAT temp;
1089 + temp = fabs(cod_info->xr[j]) - ix01[ix[j]];
1090 + j++;
1091 + noise += temp * temp;
1092 + temp = fabs(cod_info->xr[j]) - ix01[ix[j]];
1093 + j++;
1094 + noise += temp * temp;
1095 + }
1096 +#else
1097 FLOAT ix01[2];
1098 ix01[0] = 0;
1099 ix01[1] = step;
1100 @@ -779,8 +847,95 @@ calc_noise_core_c(const gr_info * const
1101 j++;
1102 noise += temp * temp;
1103 }
1104 +#endif
1105 }
1106 else {
1107 +#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
1108 + __m128 v1, v2, v3, v4, v5, v6;
1109 + int remaining = l & 1;
1110 + l = l >> 1;
1111 +#if defined(_WIN64)
1112 + long long tmp;
1113 +#else
1114 + long tmp;
1115 +#endif
1116 + const int *ixp = ix+j;
1117 + const FLOAT *xrp = cod_info->xr+j;
1118 + j += 4*l;
1119 + v5 = _mm_set_ss(step);
1120 + __asm__ __volatile__ (
1121 + "xorps %5, %5 \n\t"
1122 + "testl %6, %6 \n\t"
1123 + "jz 2f \n\t"
1124 + "shufps $0x00, %4, %4 \n\t"
1125 + "1: \n\t"
1126 +
1127 +#if defined(__x86_64__)
1128 + "movslq (%7), %9 \n\t"
1129 + "movss (%10,%9,4), %2 \n\t"
1130 + "movslq 4(%7), %9 \n\t"
1131 + "movss (%10,%9,4), %1 \n\t"
1132 + "movslq 8(%7), %9 \n\t"
1133 + "movss (%10,%9,4), %0 \n\t"
1134 + "movslq 12(%7), %9 \n\t"
1135 + "movss (%10,%9,4), %3 \n\t"
1136 +#else
1137 + "movl (%7), %9 \n\t"
1138 + "movss (%10,%9,4), %2 \n\t"
1139 + "movl 4(%7), %9 \n\t"
1140 + "movss (%10,%9,4), %1 \n\t"
1141 + "movl 8(%7), %9 \n\t"
1142 + "movss (%10,%9,4), %0 \n\t"
1143 + "movl 12(%7), %9 \n\t"
1144 + "movss (%10,%9,4), %3 \n\t"
1145 +#endif
1146 + "movlhps %1, %2 \n\t"
1147 + "movlhps %3, %0 \n\t"
1148 + "shufps $0x88, %0, %2 \n\t"
1149 + "mulps %4, %2 \n\t"
1150 +
1151 + "movups (%8), %0 \n\t"
1152 + "xorps %1, %1 \n\t"
1153 + "subps %0, %1 \n\t"
1154 + "maxps %1, %0 \n\t"
1155 + "subps %2, %0 \n\t"
1156 + "mulps %0, %0 \n\t"
1157 + "addps %0, %5 \n\t"
1158 +
1159 +#if defined(__x86_64__)
1160 + "addq $16, %7 \n\t"
1161 + "addq $16, %8 \n\t"
1162 +#else
1163 + "addl $16, %7 \n\t"
1164 + "addl $16, %8 \n\t"
1165 +#endif
1166 + "decl %6 \n\t"
1167 + "jnz 1b \n\t"
1168 + "movhlps %5, %0 \n\t"
1169 + "addps %0, %5 \n\t"
1170 +#if defined(__SSE3__)
1171 + "haddps %5, %5 \n\t"
1172 +#else
1173 + "movaps %5, %0 \n\t"
1174 + "shufps $0x01, %0, %0 \n\t"
1175 + "addps %0, %5 \n\t"
1176 +#endif
1177 + "2: \n\t"
1178 + : "=x" (v1), "=x" (v2), "=x" (v3), "=x" (v4), "+x" (v5), "=x" (v6),
1179 + "+r" (l), "+r" (ixp), "+r" (xrp), "=&r" (tmp)
1180 + : "r" (pow43)
1181 + );
1182 + _mm_store_ss(&noise, v6);
1183 + if (remaining) {
1184 + FLOAT temp;
1185 + temp = fabs(cod_info->xr[j]) - pow43[ix[j]] * step;
1186 + j++;
1187 + noise += temp * temp;
1188 + temp = fabs(cod_info->xr[j]) - pow43[ix[j]] * step;
1189 + j++;
1190 + noise += temp * temp;
1191 + }
1192 +#else
1193 while (l--) {
1194 FLOAT temp;
1195 temp = fabs(cod_info->xr[j]) - pow43[ix[j]] * step;
1196 @@ -790,6 +945,7 @@ calc_noise_core_c(const gr_info * const
1197 j++;
1198 noise += temp * temp;
1199 }
1200 +#endif
1201 }
1202
1203 *startline = j;
1204 --- libmp3lame/takehiro.c.orig 2017-09-07 04:33:36.000000000 +0900
1205 +++ libmp3lame/takehiro.c 2017-10-14 12:03:44.000000000 +0900
1206 @@ -26,6 +26,7 @@
1207 # include <config.h>
1208 #endif
1209
1210 +#undef TAKEHIRO_IEEE754_HACK
1211
1212 #include "lame.h"
1213 #include "machine.h"
1214 @@ -34,6 +35,9 @@
1215 #include "quantize_pvt.h"
1216 #include "tables.h"
1217
1218 +#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
1219 +#include <xmmintrin.h>
1220 +#endif
1221
1222 static const struct {
1223 const int region0_count;
1224 @@ -229,6 +233,57 @@ quantize_lines_xrpow(unsigned int l, FLO
1225 l = l >> 1;
1226 remaining = l % 2;
1227 l = l >> 1;
1228 +#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
1229 + __m128 v1, v2, v3, v4, v5, v6;
1230 + v6 = _mm_set_ss(istep);
1231 +#if defined(_WIN64)
1232 + long long tmp;
1233 +#else
1234 + long tmp;
1235 +#endif
1236 + __asm__ __volatile__ (
1237 + "testl %6, %6 \n\t"
1238 + "jz 2f \n\t"
1239 + "shufps $0x00, %5, %5 \n\t"
1240 + "1: \n\t"
1241 + "movups (%7), %0 \n\t"
1242 + "mulps %5, %0 \n\t"
1243 +
1244 + "cvttss2si %0, %9 \n\t"
1245 + "movaps %0, %1 \n\t"
1246 + "shufps $0xe5, %1, %1 \n\t"
1247 + "movss (%10,%9,4), %2 \n\t"
1248 + "cvttss2si %1, %9 \n\t"
1249 + "movhlps %1, %1 \n\t"
1250 + "movss (%10,%9,4), %3 \n\t"
1251 + "cvttss2si %1, %9 \n\t"
1252 + "shufps $0x55, %1, %1 \n\t"
1253 + "movss (%10,%9,4), %4 \n\t"
1254 + "cvttss2si %1, %9 \n\t"
1255 + "movlhps %3, %2 \n\t"
1256 + "movss (%10,%9,4), %3 \n\t"
1257 + "movlhps %3, %4 \n\t"
1258 + "shufps $0x88, %4, %2 \n\t"
1259 + "addps %2, %0 \n\t"
1260 + "cvttps2dq %0, %0 \n\t"
1261 + "movups %0, (%8) \n\t"
1262 +
1263 +#if defined(__x86_64__)
1264 + "addq $16, %7 \n\t"
1265 + "addq $16, %8 \n\t"
1266 +#else
1267 + "addl $16, %7 \n\t"
1268 + "addl $16, %8 \n\t"
1269 +#endif
1270 + "decl %6 \n\t"
1271 + "jnz 1b \n\t"
1272 + "2: \n\t"
1273 + : "=x" (v1), "=x" (v2), "=x" (v3), "=x" (v4), "=x" (v5), "+x" (v6),
1274 + "+r" (l), "+r" (xr), "+r" (ix), "=&r" (tmp)
1275 + : "r" (adj43)
1276 + : "memory"
1277 + );
1278 +#else
1279 while (l--) {
1280 FLOAT x0, x1, x2, x3;
1281 int rx0, rx1, rx2, rx3;
1282 @@ -250,6 +305,7 @@ quantize_lines_xrpow(unsigned int l, FLO
1283 XRPOW_FTOI(x2, *ix++);
1284 XRPOW_FTOI(x3, *ix++);
1285 };
1286 +#endif
1287 if (remaining) {
1288 FLOAT x0, x1;
1289 int rx0, rx1;
1290 @@ -423,6 +479,80 @@ quantize_xrpow(const FLOAT * xp, int *pi
1291 static int
1292 ix_max(const int *ix, const int *end)
1293 {
1294 +#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
1295 + __m128 v1, v2, v3;
1296 + int max;
1297 + __asm__ __volatile__ (
1298 + "pxor %2, %2 \n\t"
1299 +#if defined(__x86_64__)
1300 + "subq $8, %4 \n\t"
1301 + "cmpq %4, %3 \n\t"
1302 +#else
1303 + "subl $8, %4 \n\t"
1304 + "cmpl %4, %3 \n\t"
1305 +#endif
1306 + "je 2f \n\t"
1307 + "1: \n\t"
1308 + "movups (%3), %0 \n\t"
1309 +#if defined(__SSE4_1__)
1310 + "pmaxud %0, %2 \n\t"
1311 +#else
1312 + "movdqa %2, %1 \n\t"
1313 + "pcmpgtd %0, %2 \n\t"
1314 + "pand %2, %1 \n\t"
1315 + "pandn %0, %2 \n\t"
1316 + "por %1, %2 \n\t"
1317 +#endif
1318 +#if defined(__x86_64__)
1319 + "addq $16, %3 \n\t"
1320 + "cmpq %4, %3 \n\t"
1321 +#else
1322 + "addl $16, %3 \n\t"
1323 + "cmpl %4, %3 \n\t"
1324 +#endif
1325 + "jl 1b \n\t"
1326 + "jne 3f \n\t"
1327 + "2: \n\t"
1328 + "movq (%3), %0 \n\t"
1329 +#if defined(__SSE4_1__)
1330 + "pmaxud %0, %2 \n\t"
1331 +#else
1332 + "movdqa %2, %1 \n\t"
1333 + "pcmpgtd %0, %2 \n\t"
1334 + "pand %2, %1 \n\t"
1335 + "pandn %0, %2 \n\t"
1336 + "por %1, %2 \n\t"
1337 +#endif
1338 + "3: \n\t"
1339 +#if defined(__SSE4_1__)
1340 + "movdqa %2, %0 \n\t"
1341 + "psrldq $8, %2 \n\t"
1342 + "pmaxud %0, %2 \n\t"
1343 + "movdqa %2, %0 \n\t"
1344 + "psrldq $4, %2 \n\t"
1345 + "pmaxud %2, %0 \n\t"
1346 +#else
1347 + "movdqa %2, %0 \n\t"
1348 + "movdqa %2, %1 \n\t"
1349 + "psrldq $8, %2 \n\t"
1350 + "pcmpgtd %2, %0 \n\t"
1351 + "pand %0, %1 \n\t"
1352 + "pandn %2, %0 \n\t"
1353 + "por %1, %0 \n\t"
1354 + "movdqa %0, %2 \n\t"
1355 + "movdqa %0, %1 \n\t"
1356 + "psrldq $4, %2 \n\t"
1357 + "pcmpgtd %2, %0 \n\t"
1358 + "pand %0, %1 \n\t"
1359 + "pandn %2, %0 \n\t"
1360 + "por %1, %0 \n\t"
1361 +#endif
1362 + "movd %0, %5 \n\t"
1363 + : "=x" (v1), "=x" (v2), "=x" (v3),
1364 + "+r" (ix), "+r" (end), "=r" (max)
1365 + );
1366 + return max;
1367 +#else
1368 int max1 = 0, max2 = 0;
1369
1370 do {
1371 @@ -437,6 +567,7 @@ ix_max(const int *ix, const int *end)
1372 if (max1 < max2)
1373 max1 = max2;
1374 return max1;
1375 +#endif
1376 }
1377
1378
1379 @@ -447,12 +578,74 @@ ix_max(const int *ix, const int *end)
1380
1381
1382 static int
1383 -count_bit_ESC(const int *ix, const int *const end, int t1, const int t2, unsigned int *const s)
1384 +count_bit_ESC(const int *ix, const int *end, int t1, const int t2, unsigned int *const s)
1385 {
1386 /* ESC-table is used */
1387 unsigned int const linbits = ht[t1].xlen * 65536u + ht[t2].xlen;
1388 unsigned int sum = 0, sum2;
1389
1390 +#if defined(__GNUC__) && (defined(__x86_64__))
1391 + unsigned int tmp;
1392 + static short mult[8] __attribute__ ((aligned (16))) = {16, 1, 16, 1, 16, 1, 16, 1};
1393 + __asm__ __volatile__ (
1394 + "movaps (%6), %%xmm4 \n\t"
1395 + "pcmpeqd %%xmm2, %%xmm2 \n\t"
1396 + "movdqa %%xmm2, %%xmm3 \n\t"
1397 + "psrlw $13, %%xmm2 \n\t"
1398 + "psllw $4, %%xmm3 \n\t"
1399 + "psllw $1, %%xmm2 \n\t"
1400 + "pxor %%xmm5, %%xmm5 \n\t"
1401 + "subq $8, %3 \n\t"
1402 + "cmpq %3, %0 \n\t"
1403 + "je 2f \n\t"
1404 +
1405 + "1: \n\t"
1406 + "movups (%0), %%xmm0 \n\t"
1407 + "packssdw %%xmm0, %%xmm0 \n\t"
1408 + "movdqa %%xmm0, %%xmm1 \n\t"
1409 + "paddusw %%xmm3, %%xmm1 \n\t"
1410 + "pcmpgtw %%xmm2, %%xmm0 \n\t"
1411 + "psubw %%xmm0, %%xmm5 \n\t"
1412 + "pmaddwd %%xmm4, %%xmm1 \n\t"
1413 + "movd %%xmm1, %2 \n\t"
1414 + "psrlq $32, %%xmm1 \n\t"
1415 + "cltq \n\t"
1416 + "addl 1088(%5,%%rax,4), %1 \n\t"
1417 + "movd %%xmm1, %2 \n\t"
1418 + "cltq \n\t"
1419 + "addl 1088(%5,%%rax,4), %1 \n\t"
1420 + "addq $16, %0 \n\t"
1421 + "cmpq %3, %0 \n\t"
1422 + "jl 1b \n\t"
1423 + "movdqa %%xmm5, %%xmm0 \n\t"
1424 + "psrlq $32, %%xmm0 \n\t"
1425 + "paddw %%xmm0, %%xmm5 \n\t"
1426 + "jne 3f \n\t"
1427 +
1428 + "2: \n\t"
1429 + "movq (%0), %%xmm0 \n\t"
1430 + "packssdw %%xmm0, %%xmm0 \n\t"
1431 + "movdqa %%xmm0, %%xmm1 \n\t"
1432 + "paddusw %%xmm3, %%xmm1 \n\t"
1433 + "pcmpgtw %%xmm2, %%xmm0 \n\t"
1434 + "psubw %%xmm0, %%xmm5 \n\t"
1435 + "pmaddwd %%xmm4, %%xmm1 \n\t"
1436 + "movd %%xmm1, %2 \n\t"
1437 + "cltq \n\t"
1438 + "addl 1088(%5,%%rax,4), %1 \n\t"
1439 +
1440 + "3: \n\t"
1441 + "movdqa %%xmm5, %%xmm0 \n\t"
1442 + "psrld $16, %%xmm0 \n\t"
1443 + "paddw %%xmm5, %%xmm0 \n\t"
1444 + "pextrw $0, %%xmm0, %2 \n\t"
1445 + "imull %4, %2 \n\t"
1446 + "addl %2, %1 \n\t"
1447 + : "+r" (ix), "+r" (sum), "=&a" (tmp), "+r" (end)
1448 + : "r" (linbits), "r" (largetbl), "r" (mult)
1449 + : "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"
1450 + );
1451 +#else
1452 do {
1453 unsigned int x = *ix++;
1454 unsigned int y = *ix++;
1455 @@ -469,6 +662,7 @@ count_bit_ESC(const int *ix, const int *
1456 x += y;
1457 sum += largetbl[x];
1458 } while (ix < end);
1459 +#endif
1460
1461 sum2 = sum & 0xffffu;
1462 sum >>= 16u;
1463 @@ -790,10 +984,178 @@ count_bits(lame_internal_flags const *co
1464 j += width;
1465 }
1466 else {
1467 +#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
1468 + __m128 v1, v2, v3, v4, v5;
1469 +#if defined(__x86_64__)
1470 +#if defined(_WIN64)
1471 + long long k = j;
1472 +#else
1473 + long k = j;
1474 +#endif
1475 + j += width;
1476 +#if defined(_WIN64)
1477 + long long l = j;
1478 +#else
1479 + long l = j;
1480 +#endif
1481 + v1 = _mm_set_ss(roundfac);
1482 + __asm__ __volatile__ (
1483 + "shufps $0x00, %0, %0 \n\t"
1484 +
1485 + "testq $0x3, %5 \n\t"
1486 + "jz 7f \n\t"
1487 + "cmpq %6, %5 \n\t"
1488 + "je 6f \n\t"
1489 + "8: \n\t"
1490 + "movss (%7,%5,4), %1 \n\t"
1491 + "cmpnltss %0, %1 \n\t"
1492 + "movss (%8,%5,4), %2 \n\t"
1493 + "andps %2, %1 \n\t"
1494 + "movss %1, (%8,%5,4) \n\t"
1495 + "incq %5 \n\t"
1496 + "testq $0x3, %5 \n\t"
1497 + "jz 7f \n\t"
1498 + "cmpq %6, %5 \n\t"
1499 + "jne 8b \n\t"
1500 + "7: \n\t"
1501 +
1502 + "subq $8, %6 \n\t"
1503 + "cmpq %6, %5 \n\t"
1504 + "jg 2f \n\t"
1505 + "1: \n\t"
1506 + "movaps (%7,%5,4), %1 \n\t"
1507 + "movaps 16(%7,%5,4), %2 \n\t"
1508 + "cmpnltps %0, %1 \n\t"
1509 + "cmpnltps %0, %2 \n\t"
1510 + "movaps (%8,%5,4), %3 \n\t"
1511 + "movaps 16(%8,%5,4), %4 \n\t"
1512 + "andps %3, %1 \n\t"
1513 + "andps %4, %2 \n\t"
1514 + "movaps %1, (%8,%5,4) \n\t"
1515 + "movaps %2, 16(%8,%5,4) \n\t"
1516 + "addq $8, %5 \n\t"
1517 + "cmpq %6, %5 \n\t"
1518 + "jle 1b \n\t"
1519 + "2: \n\t"
1520 + "addq $8, %6 \n\t"
1521 + "cmpq %6, %5 \n\t"
1522 + "je 6f \n\t"
1523 +
1524 + "subq $4, %6 \n\t"
1525 + "cmpq %6, %5 \n\t"
1526 + "jg 4f \n\t"
1527 + "3: \n\t"
1528 + "movaps (%7,%5,4), %1 \n\t"
1529 + "cmpnltps %0, %1 \n\t"
1530 + "movaps (%8,%5,4), %2 \n\t"
1531 + "andps %2, %1 \n\t"
1532 + "movaps %1, (%8,%5,4) \n\t"
1533 + "addq $4, %5 \n\t"
1534 + "cmpq %6, %5 \n\t"
1535 + "jle 3b \n\t"
1536 + "4: \n\t"
1537 + "addq $4, %6 \n\t"
1538 + "cmpq %6, %5 \n\t"
1539 + "je 6f \n\t"
1540 +
1541 + "5: \n\t"
1542 + "movss (%7,%5,4), %1 \n\t"
1543 + "cmpnltss %0, %1 \n\t"
1544 + "movss (%8,%5,4), %2 \n\t"
1545 + "andps %2, %1 \n\t"
1546 + "movss %1, (%8,%5,4) \n\t"
1547 + "incq %5 \n\t"
1548 + "cmpq %6, %5 \n\t"
1549 + "jne 5b \n\t"
1550 + "6: \n\t"
1551 + : "+x" (v1), "=x" (v2), "=x" (v3), "=x" (v4), "=x" (v5),
1552 + "+r" (k), "+r" (l)
1553 + : "r" (xr), "r" (ix)
1554 + );
1555 +#else
1556 + int k = j;
1557 + j += width;
1558 + v1 = _mm_set_ss(roundfac);
1559 + __asm__ __volatile__ (
1560 + "shufps $0x00, %0, %0 \n\t"
1561 +
1562 + "testl $0x3, %5 \n\t"
1563 + "jz 7f \n\t"
1564 + "cmpl %6, %5 \n\t"
1565 + "je 6f \n\t"
1566 + "8: \n\t"
1567 + "movss (%7,%5,4), %1 \n\t"
1568 + "cmpnltss %0, %1 \n\t"
1569 + "movss (%8,%5,4), %2 \n\t"
1570 + "andps %2, %1 \n\t"
1571 + "movss %1, (%8,%5,4) \n\t"
1572 + "incl %5 \n\t"
1573 + "testl $0x3, %5 \n\t"
1574 + "jz 7f \n\t"
1575 + "cmpl %6, %5 \n\t"
1576 + "jne 8b \n\t"
1577 + "7: \n\t"
1578 +
1579 + "subl $8, %6 \n\t"
1580 + "cmpl %6, %5 \n\t"
1581 + "jg 2f \n\t"
1582 + "1: \n\t"
1583 + "movaps (%7,%5,4), %1 \n\t"
1584 + "movaps 16(%7,%5,4), %2 \n\t"
1585 + "cmpnltps %0, %1 \n\t"
1586 + "cmpnltps %0, %2 \n\t"
1587 + "movaps (%8,%5,4), %3 \n\t"
1588 + "movaps 16(%8,%5,4), %4 \n\t"
1589 + "andps %3, %1 \n\t"
1590 + "andps %4, %2 \n\t"
1591 + "movaps %1, (%8,%5,4) \n\t"
1592 + "movaps %2, 16(%8,%5,4) \n\t"
1593 + "addl $8, %5 \n\t"
1594 + "cmpl %6, %5 \n\t"
1595 + "jle 1b \n\t"
1596 + "2: \n\t"
1597 + "addl $8, %6 \n\t"
1598 + "cmpl %6, %5 \n\t"
1599 + "je 6f \n\t"
1600 +
1601 + "subl $4, %6 \n\t"
1602 + "cmpl %6, %5 \n\t"
1603 + "jg 4f \n\t"
1604 + "3: \n\t"
1605 + "movaps (%7,%5,4), %1 \n\t"
1606 + "cmpnltps %0, %1 \n\t"
1607 + "movaps (%8,%5,4), %2 \n\t"
1608 + "andps %2, %1 \n\t"
1609 + "movaps %1, (%8,%5,4) \n\t"
1610 + "addl $4, %5 \n\t"
1611 + "cmpl %6, %5 \n\t"
1612 + "jle 3b \n\t"
1613 + "4: \n\t"
1614 + "addl $4, %6 \n\t"
1615 + "cmpl %6, %5 \n\t"
1616 + "je 6f \n\t"
1617 +
1618 + "5: \n\t"
1619 + "movss (%7,%5,4), %1 \n\t"
1620 + "cmpnltss %0, %1 \n\t"
1621 + "movss (%8,%5,4), %2 \n\t"
1622 + "andps %2, %1 \n\t"
1623 + "movss %1, (%8,%5,4) \n\t"
1624 + "incl %5 \n\t"
1625 + "cmpl %6, %5 \n\t"
1626 + "jne 5b \n\t"
1627 + "6: \n\t"
1628 + : "+x" (v1), "=x" (v2), "=x" (v3), "=x" (v4), "=x" (v5),
1629 + "+r" (k), "+r" (j)
1630 + : "r" (xr), "r" (ix)
1631 + );
1632 +#endif
1633 +#else
1634 int k;
1635 for (k = j, j += width; k < j; ++k) {
1636 ix[k] = (xr[k] >= roundfac) ? ix[k] : 0;
1637 }
1638 +#endif
1639 }
1640 }
1641 }
1642 --- libmp3lame/util.c.orig 2017-09-07 04:33:36.000000000 +0900
1643 +++ libmp3lame/util.c 2017-10-14 12:03:44.000000000 +0900
1644 @@ -140,7 +140,7 @@ freegfc(lame_internal_flags * const gfc)
1645 gfc->VBR_seek_table.size = 0;
1646 }
1647 if (gfc->ATH) {
1648 - free(gfc->ATH);
1649 + free_aligned16(gfc->ATH);
1650 }
1651 if (gfc->sv_rpg.rgdata) {
1652 free(gfc->sv_rpg.rgdata);
1653 @@ -162,7 +162,7 @@ freegfc(lame_internal_flags * const gfc)
1654
1655 free_global_data(gfc);
1656
1657 - free(gfc);
1658 + free_aligned16(gfc);
1659 }
1660
1661 void
1662 --- libmp3lame/util.h.orig 2017-09-07 04:33:36.000000000 +0900
1663 +++ libmp3lame/util.h 2017-10-14 12:03:44.000000000 +0900
1664 @@ -116,6 +116,36 @@ extern "C" {
1665 typedef struct plotting_data plotting_data;
1666 #endif
1667
1668 +#if defined(__APPLE__)
1669 +#define malloc_aligned16(size) malloc(size)
1670 +#define calloc_aligned16(n, size) calloc(n, size)
1671 +#define free_aligned16(ptr) free(ptr)
1672 +#elif defined(__MINGW32__) || defined(__MINGW64__) || defined(_MSC_VER)
1673 +#define malloc_aligned16(size) _aligned_malloc(size, 16)
1674 +static inline void * calloc_aligned16(size_t n, size_t size)
1675 +{
1676 + void *ptr = _aligned_malloc(n * size, 16);
1677 + if(ptr) memset(ptr, 0, n * size);
1678 + return ptr;
1679 +}
1680 +#define free_aligned16(ptr) _aligned_free(ptr)
1681 +#else
1682 +static inline void * malloc_aligned16(size_t size)
1683 +{
1684 + void *ptr;
1685 + int ret = posix_memalign(&ptr, 16, size);
1686 + return ret == 0 ? ptr : NULL;
1687 +}
1688 +static inline void * calloc_aligned16(size_t n, size_t size)
1689 +{
1690 + void *ptr;
1691 + int ret = posix_memalign(&ptr, 16, n * size);
1692 + if(!ret) memset(ptr, 0, n * size);
1693 + return ret == 0 ? ptr : NULL;
1694 +}
1695 +#define free_aligned16(ptr) free(ptr)
1696 +#endif
1697 +
1698 /***********************************************************************
1699 *
1700 * Global Type Definitions
1701 @@ -178,7 +208,7 @@ extern "C" {
1702 FLOAT psfb12[PSFB12]; /* ATH for partitionned sfb12 in short blocks */
1703 FLOAT cb_l[CBANDS]; /* ATH for long block convolution bands */
1704 FLOAT cb_s[CBANDS]; /* ATH for short block convolution bands */
1705 - FLOAT eql_w[BLKSIZE / 2]; /* equal loudness weights (based on ATH) */
1706 + FLOAT eql_w[BLKSIZE / 2] __attribute__ ((aligned (16))); /* equal loudness weights (based on ATH) */
1707 } ATH_t;
1708
1709 /**
1710 @@ -492,7 +522,7 @@ extern "C" {
1711
1712 /* variables used by lame.c */
1713 Bit_stream_struc bs;
1714 - III_side_info_t l3_side;
1715 + III_side_info_t l3_side __attribute__ ((aligned (16)));
1716
1717 scalefac_struct scalefac_band;
1718
1719 --- libmp3lame/vbrquantize.c.orig 2012-02-07 22:36:35.000000000 +0900
1720 +++ libmp3lame/vbrquantize.c 2017-10-14 12:03:44.000000000 +0900
1721 @@ -26,6 +26,7 @@
1722 # include <config.h>
1723 #endif
1724
1725 +#undef TAKEHIRO_IEEE754_HACK
1726
1727 #include "lame.h"
1728 #include "machine.h"
1729 @@ -34,7 +35,9 @@
1730 #include "vbrquantize.h"
1731 #include "quantize_pvt.h"
1732
1733 -
1734 +#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
1735 +#include <xmmintrin.h>
1736 +#endif
1737
1738
1739 struct algo_s;
1740 @@ -226,6 +229,81 @@ calc_sfb_noise_x34(const FLOAT * xr, con
1741 unsigned int i = bw >> 2u;
1742 unsigned int const remaining = (bw & 0x03u);
1743
1744 +#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
1745 + __m128 v1, v2, v3, v4, v5, v6, v7, v8;
1746 +#if defined(_WIN64)
1747 + long long tmp;
1748 +#else
1749 + long tmp;
1750 +#endif
1751 + v6 = _mm_set_ss(sfpow34);
1752 + v7 = _mm_set_ss(sfpow);
1753 + __asm__ __volatile__ (
1754 + "xorps %7, %7 \n\t"
1755 + "testl %8, %8 \n\t"
1756 + "jz 2f \n\t"
1757 + "shufps $0x00, %5, %5 \n\t"
1758 + "shufps $0x00, %6, %6 \n\t"
1759 + "pcmpeqd %4, %4 \n\t"
1760 + "psrld $1, %4 \n\t"
1761 +
1762 + "1: \n\t"
1763 + "movups (%10), %1 \n\t"
1764 + "mulps %5, %1 \n\t"
1765 + "cvttss2si %1, %11 \n\t"
1766 + "shufps $0xe5, %1, %1 \n\t"
1767 + "movlps (%12,%11,4), %2 \n\t"
1768 + "cvttss2si %1, %11 \n\t"
1769 + "movhlps %1, %1 \n\t"
1770 + "movhps (%12,%11,4), %2 \n\t"
1771 + "cvttss2si %1, %11 \n\t"
1772 + "shufps $0x55, %1, %1 \n\t"
1773 + "movlps (%12,%11,4), %3 \n\t"
1774 + "cvttss2si %1, %11 \n\t"
1775 + "movups (%9), %1 \n\t"
1776 + "movhps (%12,%11,4), %3 \n\t"
1777 + "mulps %6, %2 \n\t"
1778 + "mulps %6, %3 \n\t"
1779 + "movaps %2, %0 \n\t"
1780 + "shufps $0x88, %3, %0 \n\t"
1781 + "shufps $0xdd, %3, %2 \n\t"
1782 +
1783 + "andps %4, %1 \n\t"
1784 + "subps %1, %2 \n\t"
1785 + "subps %0, %1 \n\t"
1786 + "movaps %1, %0 \n\t"
1787 + "cmpltps %2, %1 \n\t"
1788 + "andps %1, %0 \n\t"
1789 + "andnps %2, %1 \n\t"
1790 + "orps %1, %0 \n\t"
1791 + "mulps %0, %0 \n\t"
1792 + "addps %0, %7 \n\t"
1793 +
1794 +#if defined(__x86_64__)
1795 + "addq $16, %9 \n\t"
1796 + "addq $16, %10 \n\t"
1797 +#else
1798 + "addl $16, %9 \n\t"
1799 + "addl $16, %10 \n\t"
1800 +#endif
1801 + "decl %8 \n\t"
1802 + "jnz 1b \n\t"
1803 + "movhlps %7, %0 \n\t"
1804 + "addps %0, %7 \n\t"
1805 +#if defined(__SSE3__)
1806 + "haddps %7, %7 \n\t"
1807 +#else
1808 + "movaps %7, %0 \n\t"
1809 + "shufps $0x01, %0, %0 \n\t"
1810 + "addps %0, %7 \n\t"
1811 +#endif
1812 + "2: \n\t"
1813 + : "=x" (v1), "=x" (v2), "=x" (v3), "=x" (v4), "=x" (v5), "+x" (v6), "+x" (v7), "=x" (v8),
1814 + "+r" (i), "+r" (xr), "+r" (xr34), "=&r" (tmp)
1815 + : "r" (pow43)
1816 + );
1817 + _mm_store_ss(&xfsf, v8);
1818 +#else
1819 while (i-- > 0) {
1820 x[0] = sfpow34 * xr34[0];
1821 x[1] = sfpow34 * xr34[1];
1822 @@ -243,6 +321,7 @@ calc_sfb_noise_x34(const FLOAT * xr, con
1823 xr += 4;
1824 xr34 += 4;
1825 }
1826 +#endif
1827 if (remaining) {
1828 x[0] = x[1] = x[2] = x[3] = 0;
1829 switch( remaining ) {