summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik de Castro Lopo <erikd@mega-nerd.com>2014-10-04 09:42:54 +1000
committerErik de Castro Lopo <erikd@mega-nerd.com>2014-10-04 09:42:57 +1000
commit11b5d51b63710efbfaf913ad08570c8d9c1db36a (patch)
treef5b29292b41b177bf11d3643af911afd5b9ce20a
parenta75b87059213a130e5dcdaae0969d9e89a822262 (diff)
downloadflac-11b5d51b63710efbfaf913ad08570c8d9c1db36a.tar.gz
Add AVX2 CPU support stream encoder.
Patch-from: lvqcl <lvqcl.mail@gmail.com>
-rw-r--r--src/libFLAC/Makefile.am2
-rw-r--r--src/libFLAC/Makefile.lite2
-rw-r--r--src/libFLAC/include/private/lpc.h5
-rw-r--r--src/libFLAC/include/private/stream_encoder.h5
-rw-r--r--src/libFLAC/libFLAC_dynamic.vcxproj12
-rw-r--r--src/libFLAC/libFLAC_dynamic.vcxproj.filters6
-rw-r--r--src/libFLAC/libFLAC_static.vcxproj12
-rw-r--r--src/libFLAC/libFLAC_static.vcxproj.filters6
-rw-r--r--src/libFLAC/lpc_intrin_avx2.c1120
-rw-r--r--src/libFLAC/stream_encoder.c22
-rw-r--r--src/libFLAC/stream_encoder_intrin_avx2.c142
11 files changed, 1334 insertions, 0 deletions
diff --git a/src/libFLAC/Makefile.am b/src/libFLAC/Makefile.am
index 473473d3..a5d0d48e 100644
--- a/src/libFLAC/Makefile.am
+++ b/src/libFLAC/Makefile.am
@@ -112,6 +112,7 @@ libFLAC_sources = \
lpc_intrin_sse.c \
lpc_intrin_sse2.c \
lpc_intrin_sse41.c \
+ lpc_intrin_avx2.c \
md5.c \
memory.c \
metadata_iterators.c \
@@ -120,6 +121,7 @@ libFLAC_sources = \
stream_encoder.c \
stream_encoder_intrin_sse2.c \
stream_encoder_intrin_ssse3.c \
+ stream_encoder_intrin_avx2.c \
stream_encoder_framing.c \
window.c \
$(extra_ogg_sources)
diff --git a/src/libFLAC/Makefile.lite b/src/libFLAC/Makefile.lite
index b1eee24a..a9f1d845 100644
--- a/src/libFLAC/Makefile.lite
+++ b/src/libFLAC/Makefile.lite
@@ -90,6 +90,7 @@ SRCS_C = \
lpc_intrin_sse.c \
lpc_intrin_sse2.c \
lpc_intrin_sse41.c \
+ lpc_intrin_avx2.c \
md5.c \
memory.c \
metadata_iterators.c \
@@ -98,6 +99,7 @@ SRCS_C = \
stream_encoder.c \
stream_encoder_intrin_sse2.c \
stream_encoder_intrin_ssse3.c \
+ stream_encoder_intrin_avx2.c \
stream_encoder_framing.c \
window.c \
$(OGG_SRCS)
diff --git a/src/libFLAC/include/private/lpc.h b/src/libFLAC/include/private/lpc.h
index 2aa604f5..7b3652fd 100644
--- a/src/libFLAC/include/private/lpc.h
+++ b/src/libFLAC/include/private/lpc.h
@@ -166,6 +166,11 @@ void FLAC__lpc_compute_residual_from_qlp_coefficients_intrin_sse2(const FLAC__in
void FLAC__lpc_compute_residual_from_qlp_coefficients_intrin_sse41(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
void FLAC__lpc_compute_residual_from_qlp_coefficients_wide_intrin_sse41(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
# endif
+# ifdef FLAC__AVX2_SUPPORTED
+void FLAC__lpc_compute_residual_from_qlp_coefficients_16_intrin_avx2(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
+void FLAC__lpc_compute_residual_from_qlp_coefficients_intrin_avx2(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
+void FLAC__lpc_compute_residual_from_qlp_coefficients_wide_intrin_avx2(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
+# endif
# endif
#endif
diff --git a/src/libFLAC/include/private/stream_encoder.h b/src/libFLAC/include/private/stream_encoder.h
index 8147f9ed..3d231054 100644
--- a/src/libFLAC/include/private/stream_encoder.h
+++ b/src/libFLAC/include/private/stream_encoder.h
@@ -57,6 +57,11 @@ extern void FLAC__precompute_partition_info_sums_intrin_ssse3(const FLAC__int32
unsigned residual_samples, unsigned predictor_order, unsigned min_partition_order, unsigned max_partition_order, unsigned bps);
#endif
+#ifdef FLAC__AVX2_SUPPORTED
+extern void FLAC__precompute_partition_info_sums_intrin_avx2(const FLAC__int32 residual[], FLAC__uint64 abs_residual_partition_sums[],
+ unsigned residual_samples, unsigned predictor_order, unsigned min_partition_order, unsigned max_partition_order, unsigned bps);
+#endif
+
#endif
#endif
diff --git a/src/libFLAC/libFLAC_dynamic.vcxproj b/src/libFLAC/libFLAC_dynamic.vcxproj
index f15b2b57..58599dea 100644
--- a/src/libFLAC/libFLAC_dynamic.vcxproj
+++ b/src/libFLAC/libFLAC_dynamic.vcxproj
@@ -221,6 +221,12 @@
<ClCompile Include="float.c" />
<ClCompile Include="format.c" />
<ClCompile Include="lpc.c" />
+ <ClCompile Include="lpc_intrin_avx2.c">
+ <AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">/arch:AVX %(AdditionalOptions)</AdditionalOptions>
+ <AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">/arch:AVX %(AdditionalOptions)</AdditionalOptions>
+ <AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">/arch:AVX %(AdditionalOptions)</AdditionalOptions>
+ <AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Release|x64'">/arch:AVX %(AdditionalOptions)</AdditionalOptions>
+ </ClCompile>
<ClCompile Include="lpc_intrin_sse.c" />
<ClCompile Include="lpc_intrin_sse2.c" />
<ClCompile Include="lpc_intrin_sse41.c" />
@@ -235,6 +241,12 @@
<ClCompile Include="stream_decoder.c" />
<ClCompile Include="stream_encoder.c" />
<ClCompile Include="stream_encoder_framing.c" />
+ <ClCompile Include="stream_encoder_intrin_avx2.c">
+ <AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">/arch:AVX %(AdditionalOptions)</AdditionalOptions>
+ <AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">/arch:AVX %(AdditionalOptions)</AdditionalOptions>
+ <AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">/arch:AVX %(AdditionalOptions)</AdditionalOptions>
+ <AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Release|x64'">/arch:AVX %(AdditionalOptions)</AdditionalOptions>
+ </ClCompile>
<ClCompile Include="stream_encoder_intrin_sse2.c" />
<ClCompile Include="stream_encoder_intrin_ssse3.c" />
<ClCompile Include="window.c" />
diff --git a/src/libFLAC/libFLAC_dynamic.vcxproj.filters b/src/libFLAC/libFLAC_dynamic.vcxproj.filters
index bc18b149..fa79a8dc 100644
--- a/src/libFLAC/libFLAC_dynamic.vcxproj.filters
+++ b/src/libFLAC/libFLAC_dynamic.vcxproj.filters
@@ -157,6 +157,9 @@
<ClCompile Include="lpc_intrin_sse41.c">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="lpc_intrin_avx2.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
<ClCompile Include="md5.c">
<Filter>Source Files</Filter>
</ClCompile>
@@ -196,6 +199,9 @@
<ClCompile Include="stream_encoder_intrin_ssse3.c">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="stream_encoder_intrin_avx2.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
<ClCompile Include="window.c">
<Filter>Source Files</Filter>
</ClCompile>
diff --git a/src/libFLAC/libFLAC_static.vcxproj b/src/libFLAC/libFLAC_static.vcxproj
index 3487d4a2..da5719de 100644
--- a/src/libFLAC/libFLAC_static.vcxproj
+++ b/src/libFLAC/libFLAC_static.vcxproj
@@ -181,6 +181,12 @@
<ClCompile Include="float.c" />
<ClCompile Include="format.c" />
<ClCompile Include="lpc.c" />
+ <ClCompile Include="lpc_intrin_avx2.c">
+ <AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">/arch:AVX %(AdditionalOptions)</AdditionalOptions>
+ <AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">/arch:AVX %(AdditionalOptions)</AdditionalOptions>
+ <AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">/arch:AVX %(AdditionalOptions)</AdditionalOptions>
+ <AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Release|x64'">/arch:AVX %(AdditionalOptions)</AdditionalOptions>
+ </ClCompile>
<ClCompile Include="lpc_intrin_sse.c" />
<ClCompile Include="lpc_intrin_sse2.c" />
<ClCompile Include="lpc_intrin_sse41.c" />
@@ -195,6 +201,12 @@
<ClCompile Include="stream_decoder.c" />
<ClCompile Include="stream_encoder.c" />
<ClCompile Include="stream_encoder_framing.c" />
+ <ClCompile Include="stream_encoder_intrin_avx2.c">
+ <AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">/arch:AVX %(AdditionalOptions)</AdditionalOptions>
+ <AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">/arch:AVX %(AdditionalOptions)</AdditionalOptions>
+ <AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">/arch:AVX %(AdditionalOptions)</AdditionalOptions>
+ <AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Release|x64'">/arch:AVX %(AdditionalOptions)</AdditionalOptions>
+ </ClCompile>
<ClCompile Include="stream_encoder_intrin_sse2.c" />
<ClCompile Include="stream_encoder_intrin_ssse3.c" />
<ClCompile Include="window.c" />
diff --git a/src/libFLAC/libFLAC_static.vcxproj.filters b/src/libFLAC/libFLAC_static.vcxproj.filters
index d5c82589..bc99bf3b 100644
--- a/src/libFLAC/libFLAC_static.vcxproj.filters
+++ b/src/libFLAC/libFLAC_static.vcxproj.filters
@@ -157,6 +157,9 @@
<ClCompile Include="lpc_intrin_sse41.c">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="lpc_intrin_avx2.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
<ClCompile Include="md5.c">
<Filter>Source Files</Filter>
</ClCompile>
@@ -196,6 +199,9 @@
<ClCompile Include="stream_encoder_intrin_ssse3.c">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="stream_encoder_intrin_avx2.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
<ClCompile Include="window.c">
<Filter>Source Files</Filter>
</ClCompile>
diff --git a/src/libFLAC/lpc_intrin_avx2.c b/src/libFLAC/lpc_intrin_avx2.c
new file mode 100644
index 00000000..8eec85e1
--- /dev/null
+++ b/src/libFLAC/lpc_intrin_avx2.c
@@ -0,0 +1,1120 @@
+/* libFLAC - Free Lossless Audio Codec library
+ * Copyright (C) 2000-2009 Josh Coalson
+ * Copyright (C) 2011-2014 Xiph.Org Foundation
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - Neither the name of the Xiph.org Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#ifndef FLAC__INTEGER_ONLY_LIBRARY
+#ifndef FLAC__NO_ASM
+#if (defined FLAC__CPU_IA32 || defined FLAC__CPU_X86_64) && defined FLAC__HAS_X86INTRIN
+#include "private/lpc.h"
+#ifdef FLAC__AVX2_SUPPORTED
+
+#include "FLAC/assert.h"
+#include "FLAC/format.h"
+
+#include <immintrin.h> /* AVX2 */
+
+FLAC__SSE_TARGET("avx2")
+void FLAC__lpc_compute_residual_from_qlp_coefficients_16_intrin_avx2(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[])
+{
+ int i;
+ FLAC__int32 sum;
+ __m128i cnt = _mm_cvtsi32_si128(lp_quantization);
+
+ FLAC__ASSERT(order > 0);
+ FLAC__ASSERT(order <= 32);
+
+ if(order <= 12) {
+ if(order > 8) {
+ if(order > 10) {
+ if(order == 12) {
+ __m256i q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11;
+ q0 = _mm256_set1_epi32(0xffff & qlp_coeff[0 ]);
+ q1 = _mm256_set1_epi32(0xffff & qlp_coeff[1 ]);
+ q2 = _mm256_set1_epi32(0xffff & qlp_coeff[2 ]);
+ q3 = _mm256_set1_epi32(0xffff & qlp_coeff[3 ]);
+ q4 = _mm256_set1_epi32(0xffff & qlp_coeff[4 ]);
+ q5 = _mm256_set1_epi32(0xffff & qlp_coeff[5 ]);
+ q6 = _mm256_set1_epi32(0xffff & qlp_coeff[6 ]);
+ q7 = _mm256_set1_epi32(0xffff & qlp_coeff[7 ]);
+ q8 = _mm256_set1_epi32(0xffff & qlp_coeff[8 ]);
+ q9 = _mm256_set1_epi32(0xffff & qlp_coeff[9 ]);
+ q10 = _mm256_set1_epi32(0xffff & qlp_coeff[10]);
+ q11 = _mm256_set1_epi32(0xffff & qlp_coeff[11]);
+
+ for(i = 0; i < (int)data_len-7; i+=8) {
+ __m256i summ, mull;
+ summ = _mm256_madd_epi16(q11, _mm256_loadu_si256((const __m256i*)(data+i-12)));
+ mull = _mm256_madd_epi16(q10, _mm256_loadu_si256((const __m256i*)(data+i-11))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q9, _mm256_loadu_si256((const __m256i*)(data+i-10))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q8, _mm256_loadu_si256((const __m256i*)(data+i-9 ))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q7, _mm256_loadu_si256((const __m256i*)(data+i-8 ))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q6, _mm256_loadu_si256((const __m256i*)(data+i-7 ))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q5, _mm256_loadu_si256((const __m256i*)(data+i-6 ))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q4, _mm256_loadu_si256((const __m256i*)(data+i-5 ))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q3, _mm256_loadu_si256((const __m256i*)(data+i-4 ))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q2, _mm256_loadu_si256((const __m256i*)(data+i-3 ))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q1, _mm256_loadu_si256((const __m256i*)(data+i-2 ))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q0, _mm256_loadu_si256((const __m256i*)(data+i-1 ))); summ = _mm256_add_epi32(summ, mull);
+ summ = _mm256_sra_epi32(summ, cnt);
+ _mm256_storeu_si256((__m256i*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(data+i)), summ));
+ }
+ }
+ else { /* order == 11 */
+ __m256i q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10;
+ q0 = _mm256_set1_epi32(0xffff & qlp_coeff[0 ]);
+ q1 = _mm256_set1_epi32(0xffff & qlp_coeff[1 ]);
+ q2 = _mm256_set1_epi32(0xffff & qlp_coeff[2 ]);
+ q3 = _mm256_set1_epi32(0xffff & qlp_coeff[3 ]);
+ q4 = _mm256_set1_epi32(0xffff & qlp_coeff[4 ]);
+ q5 = _mm256_set1_epi32(0xffff & qlp_coeff[5 ]);
+ q6 = _mm256_set1_epi32(0xffff & qlp_coeff[6 ]);
+ q7 = _mm256_set1_epi32(0xffff & qlp_coeff[7 ]);
+ q8 = _mm256_set1_epi32(0xffff & qlp_coeff[8 ]);
+ q9 = _mm256_set1_epi32(0xffff & qlp_coeff[9 ]);
+ q10 = _mm256_set1_epi32(0xffff & qlp_coeff[10]);
+
+ for(i = 0; i < (int)data_len-7; i+=8) {
+ __m256i summ, mull;
+ summ = _mm256_madd_epi16(q10, _mm256_loadu_si256((const __m256i*)(data+i-11)));
+ mull = _mm256_madd_epi16(q9, _mm256_loadu_si256((const __m256i*)(data+i-10))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q8, _mm256_loadu_si256((const __m256i*)(data+i-9 ))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q7, _mm256_loadu_si256((const __m256i*)(data+i-8 ))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q6, _mm256_loadu_si256((const __m256i*)(data+i-7 ))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q5, _mm256_loadu_si256((const __m256i*)(data+i-6 ))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q4, _mm256_loadu_si256((const __m256i*)(data+i-5 ))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q3, _mm256_loadu_si256((const __m256i*)(data+i-4 ))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q2, _mm256_loadu_si256((const __m256i*)(data+i-3 ))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q1, _mm256_loadu_si256((const __m256i*)(data+i-2 ))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q0, _mm256_loadu_si256((const __m256i*)(data+i-1 ))); summ = _mm256_add_epi32(summ, mull);
+ summ = _mm256_sra_epi32(summ, cnt);
+ _mm256_storeu_si256((__m256i*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(data+i)), summ));
+ }
+ }
+ }
+ else {
+ if(order == 10) {
+ __m256i q0, q1, q2, q3, q4, q5, q6, q7, q8, q9;
+ q0 = _mm256_set1_epi32(0xffff & qlp_coeff[0 ]);
+ q1 = _mm256_set1_epi32(0xffff & qlp_coeff[1 ]);
+ q2 = _mm256_set1_epi32(0xffff & qlp_coeff[2 ]);
+ q3 = _mm256_set1_epi32(0xffff & qlp_coeff[3 ]);
+ q4 = _mm256_set1_epi32(0xffff & qlp_coeff[4 ]);
+ q5 = _mm256_set1_epi32(0xffff & qlp_coeff[5 ]);
+ q6 = _mm256_set1_epi32(0xffff & qlp_coeff[6 ]);
+ q7 = _mm256_set1_epi32(0xffff & qlp_coeff[7 ]);
+ q8 = _mm256_set1_epi32(0xffff & qlp_coeff[8 ]);
+ q9 = _mm256_set1_epi32(0xffff & qlp_coeff[9 ]);
+
+ for(i = 0; i < (int)data_len-7; i+=8) {
+ __m256i summ, mull;
+ summ = _mm256_madd_epi16(q9, _mm256_loadu_si256((const __m256i*)(data+i-10)));
+ mull = _mm256_madd_epi16(q8, _mm256_loadu_si256((const __m256i*)(data+i-9 ))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q7, _mm256_loadu_si256((const __m256i*)(data+i-8 ))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q6, _mm256_loadu_si256((const __m256i*)(data+i-7 ))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q5, _mm256_loadu_si256((const __m256i*)(data+i-6 ))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q4, _mm256_loadu_si256((const __m256i*)(data+i-5 ))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q3, _mm256_loadu_si256((const __m256i*)(data+i-4 ))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q2, _mm256_loadu_si256((const __m256i*)(data+i-3 ))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q1, _mm256_loadu_si256((const __m256i*)(data+i-2 ))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q0, _mm256_loadu_si256((const __m256i*)(data+i-1 ))); summ = _mm256_add_epi32(summ, mull);
+ summ = _mm256_sra_epi32(summ, cnt);
+ _mm256_storeu_si256((__m256i*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(data+i)), summ));
+ }
+ }
+ else { /* order == 9 */
+ __m256i q0, q1, q2, q3, q4, q5, q6, q7, q8;
+ q0 = _mm256_set1_epi32(0xffff & qlp_coeff[0 ]);
+ q1 = _mm256_set1_epi32(0xffff & qlp_coeff[1 ]);
+ q2 = _mm256_set1_epi32(0xffff & qlp_coeff[2 ]);
+ q3 = _mm256_set1_epi32(0xffff & qlp_coeff[3 ]);
+ q4 = _mm256_set1_epi32(0xffff & qlp_coeff[4 ]);
+ q5 = _mm256_set1_epi32(0xffff & qlp_coeff[5 ]);
+ q6 = _mm256_set1_epi32(0xffff & qlp_coeff[6 ]);
+ q7 = _mm256_set1_epi32(0xffff & qlp_coeff[7 ]);
+ q8 = _mm256_set1_epi32(0xffff & qlp_coeff[8 ]);
+
+ for(i = 0; i < (int)data_len-7; i+=8) {
+ __m256i summ, mull;
+ summ = _mm256_madd_epi16(q8, _mm256_loadu_si256((const __m256i*)(data+i-9 )));
+ mull = _mm256_madd_epi16(q7, _mm256_loadu_si256((const __m256i*)(data+i-8 ))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q6, _mm256_loadu_si256((const __m256i*)(data+i-7 ))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q5, _mm256_loadu_si256((const __m256i*)(data+i-6 ))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q4, _mm256_loadu_si256((const __m256i*)(data+i-5 ))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q3, _mm256_loadu_si256((const __m256i*)(data+i-4 ))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q2, _mm256_loadu_si256((const __m256i*)(data+i-3 ))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q1, _mm256_loadu_si256((const __m256i*)(data+i-2 ))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q0, _mm256_loadu_si256((const __m256i*)(data+i-1 ))); summ = _mm256_add_epi32(summ, mull);
+ summ = _mm256_sra_epi32(summ, cnt);
+ _mm256_storeu_si256((__m256i*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(data+i)), summ));
+ }
+ }
+ }
+ }
+ else if(order > 4) {
+ if(order > 6) {
+ if(order == 8) {
+ __m256i q0, q1, q2, q3, q4, q5, q6, q7;
+ q0 = _mm256_set1_epi32(0xffff & qlp_coeff[0 ]);
+ q1 = _mm256_set1_epi32(0xffff & qlp_coeff[1 ]);
+ q2 = _mm256_set1_epi32(0xffff & qlp_coeff[2 ]);
+ q3 = _mm256_set1_epi32(0xffff & qlp_coeff[3 ]);
+ q4 = _mm256_set1_epi32(0xffff & qlp_coeff[4 ]);
+ q5 = _mm256_set1_epi32(0xffff & qlp_coeff[5 ]);
+ q6 = _mm256_set1_epi32(0xffff & qlp_coeff[6 ]);
+ q7 = _mm256_set1_epi32(0xffff & qlp_coeff[7 ]);
+
+ for(i = 0; i < (int)data_len-7; i+=8) {
+ __m256i summ, mull;
+ summ = _mm256_madd_epi16(q7, _mm256_loadu_si256((const __m256i*)(data+i-8 )));
+ mull = _mm256_madd_epi16(q6, _mm256_loadu_si256((const __m256i*)(data+i-7 ))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q5, _mm256_loadu_si256((const __m256i*)(data+i-6 ))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q4, _mm256_loadu_si256((const __m256i*)(data+i-5 ))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q3, _mm256_loadu_si256((const __m256i*)(data+i-4 ))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q2, _mm256_loadu_si256((const __m256i*)(data+i-3 ))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q1, _mm256_loadu_si256((const __m256i*)(data+i-2 ))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q0, _mm256_loadu_si256((const __m256i*)(data+i-1 ))); summ = _mm256_add_epi32(summ, mull);
+ summ = _mm256_sra_epi32(summ, cnt);
+ _mm256_storeu_si256((__m256i*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(data+i)), summ));
+ }
+ }
+ else { /* order == 7 */
+ __m256i q0, q1, q2, q3, q4, q5, q6;
+ q0 = _mm256_set1_epi32(0xffff & qlp_coeff[0 ]);
+ q1 = _mm256_set1_epi32(0xffff & qlp_coeff[1 ]);
+ q2 = _mm256_set1_epi32(0xffff & qlp_coeff[2 ]);
+ q3 = _mm256_set1_epi32(0xffff & qlp_coeff[3 ]);
+ q4 = _mm256_set1_epi32(0xffff & qlp_coeff[4 ]);
+ q5 = _mm256_set1_epi32(0xffff & qlp_coeff[5 ]);
+ q6 = _mm256_set1_epi32(0xffff & qlp_coeff[6 ]);
+
+ for(i = 0; i < (int)data_len-7; i+=8) {
+ __m256i summ, mull;
+ summ = _mm256_madd_epi16(q6, _mm256_loadu_si256((const __m256i*)(data+i-7 )));
+ mull = _mm256_madd_epi16(q5, _mm256_loadu_si256((const __m256i*)(data+i-6 ))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q4, _mm256_loadu_si256((const __m256i*)(data+i-5 ))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q3, _mm256_loadu_si256((const __m256i*)(data+i-4 ))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q2, _mm256_loadu_si256((const __m256i*)(data+i-3 ))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q1, _mm256_loadu_si256((const __m256i*)(data+i-2 ))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q0, _mm256_loadu_si256((const __m256i*)(data+i-1 ))); summ = _mm256_add_epi32(summ, mull);
+ summ = _mm256_sra_epi32(summ, cnt);
+ _mm256_storeu_si256((__m256i*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(data+i)), summ));
+ }
+ }
+ }
+ else {
+ if(order == 6) {
+ __m256i q0, q1, q2, q3, q4, q5;
+ q0 = _mm256_set1_epi32(0xffff & qlp_coeff[0 ]);
+ q1 = _mm256_set1_epi32(0xffff & qlp_coeff[1 ]);
+ q2 = _mm256_set1_epi32(0xffff & qlp_coeff[2 ]);
+ q3 = _mm256_set1_epi32(0xffff & qlp_coeff[3 ]);
+ q4 = _mm256_set1_epi32(0xffff & qlp_coeff[4 ]);
+ q5 = _mm256_set1_epi32(0xffff & qlp_coeff[5 ]);
+
+ for(i = 0; i < (int)data_len-7; i+=8) {
+ __m256i summ, mull;
+ summ = _mm256_madd_epi16(q5, _mm256_loadu_si256((const __m256i*)(data+i-6 )));
+ mull = _mm256_madd_epi16(q4, _mm256_loadu_si256((const __m256i*)(data+i-5 ))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q3, _mm256_loadu_si256((const __m256i*)(data+i-4 ))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q2, _mm256_loadu_si256((const __m256i*)(data+i-3 ))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q1, _mm256_loadu_si256((const __m256i*)(data+i-2 ))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q0, _mm256_loadu_si256((const __m256i*)(data+i-1 ))); summ = _mm256_add_epi32(summ, mull);
+ summ = _mm256_sra_epi32(summ, cnt);
+ _mm256_storeu_si256((__m256i*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(data+i)), summ));
+ }
+ }
+ else { /* order == 5 */
+ __m256i q0, q1, q2, q3, q4;
+ q0 = _mm256_set1_epi32(0xffff & qlp_coeff[0 ]);
+ q1 = _mm256_set1_epi32(0xffff & qlp_coeff[1 ]);
+ q2 = _mm256_set1_epi32(0xffff & qlp_coeff[2 ]);
+ q3 = _mm256_set1_epi32(0xffff & qlp_coeff[3 ]);
+ q4 = _mm256_set1_epi32(0xffff & qlp_coeff[4 ]);
+
+ for(i = 0; i < (int)data_len-7; i+=8) {
+ __m256i summ, mull;
+ summ = _mm256_madd_epi16(q4, _mm256_loadu_si256((const __m256i*)(data+i-5 )));
+ mull = _mm256_madd_epi16(q3, _mm256_loadu_si256((const __m256i*)(data+i-4 ))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q2, _mm256_loadu_si256((const __m256i*)(data+i-3 ))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q1, _mm256_loadu_si256((const __m256i*)(data+i-2 ))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q0, _mm256_loadu_si256((const __m256i*)(data+i-1 ))); summ = _mm256_add_epi32(summ, mull);
+ summ = _mm256_sra_epi32(summ, cnt);
+ _mm256_storeu_si256((__m256i*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(data+i)), summ));
+ }
+ }
+ }
+ }
+ else {
+ if(order > 2) {
+ if(order == 4) {
+ __m256i q0, q1, q2, q3;
+ q0 = _mm256_set1_epi32(0xffff & qlp_coeff[0 ]);
+ q1 = _mm256_set1_epi32(0xffff & qlp_coeff[1 ]);
+ q2 = _mm256_set1_epi32(0xffff & qlp_coeff[2 ]);
+ q3 = _mm256_set1_epi32(0xffff & qlp_coeff[3 ]);
+
+ for(i = 0; i < (int)data_len-7; i+=8) {
+ __m256i summ, mull;
+ summ = _mm256_madd_epi16(q3, _mm256_loadu_si256((const __m256i*)(data+i-4 )));
+ mull = _mm256_madd_epi16(q2, _mm256_loadu_si256((const __m256i*)(data+i-3 ))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q1, _mm256_loadu_si256((const __m256i*)(data+i-2 ))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q0, _mm256_loadu_si256((const __m256i*)(data+i-1 ))); summ = _mm256_add_epi32(summ, mull);
+ summ = _mm256_sra_epi32(summ, cnt);
+ _mm256_storeu_si256((__m256i*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(data+i)), summ));
+ }
+ }
+ else { /* order == 3 */
+ __m256i q0, q1, q2;
+ q0 = _mm256_set1_epi32(0xffff & qlp_coeff[0 ]);
+ q1 = _mm256_set1_epi32(0xffff & qlp_coeff[1 ]);
+ q2 = _mm256_set1_epi32(0xffff & qlp_coeff[2 ]);
+
+ for(i = 0; i < (int)data_len-7; i+=8) {
+ __m256i summ, mull;
+ summ = _mm256_madd_epi16(q2, _mm256_loadu_si256((const __m256i*)(data+i-3 )));
+ mull = _mm256_madd_epi16(q1, _mm256_loadu_si256((const __m256i*)(data+i-2 ))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_madd_epi16(q0, _mm256_loadu_si256((const __m256i*)(data+i-1 ))); summ = _mm256_add_epi32(summ, mull);
+ summ = _mm256_sra_epi32(summ, cnt);
+ _mm256_storeu_si256((__m256i*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(data+i)), summ));
+ }
+ }
+ }
+ else {
+ if(order == 2) {
+ __m256i q0, q1;
+ q0 = _mm256_set1_epi32(0xffff & qlp_coeff[0 ]);
+ q1 = _mm256_set1_epi32(0xffff & qlp_coeff[1 ]);
+
+ for(i = 0; i < (int)data_len-7; i+=8) {
+ __m256i summ, mull;
+ summ = _mm256_madd_epi16(q1, _mm256_loadu_si256((const __m256i*)(data+i-2 )));
+ mull = _mm256_madd_epi16(q0, _mm256_loadu_si256((const __m256i*)(data+i-1 ))); summ = _mm256_add_epi32(summ, mull);
+ summ = _mm256_sra_epi32(summ, cnt);
+ _mm256_storeu_si256((__m256i*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(data+i)), summ));
+ }
+ }
+ else { /* order == 1 */
+ __m256i q0;
+ q0 = _mm256_set1_epi32(0xffff & qlp_coeff[0 ]);
+
+ for(i = 0; i < (int)data_len-7; i+=8) {
+ __m256i summ;
+ summ = _mm256_madd_epi16(q0, _mm256_loadu_si256((const __m256i*)(data+i-1 )));
+ summ = _mm256_sra_epi32(summ, cnt);
+ _mm256_storeu_si256((__m256i*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(data+i)), summ));
+ }
+ }
+ }
+ }
+ for(; i < (int)data_len; i++) {
+ sum = 0;
+ switch(order) {
+ case 12: sum += qlp_coeff[11] * data[i-12];
+ case 11: sum += qlp_coeff[10] * data[i-11];
+ case 10: sum += qlp_coeff[ 9] * data[i-10];
+ case 9: sum += qlp_coeff[ 8] * data[i- 9];
+ case 8: sum += qlp_coeff[ 7] * data[i- 8];
+ case 7: sum += qlp_coeff[ 6] * data[i- 7];
+ case 6: sum += qlp_coeff[ 5] * data[i- 6];
+ case 5: sum += qlp_coeff[ 4] * data[i- 5];
+ case 4: sum += qlp_coeff[ 3] * data[i- 4];
+ case 3: sum += qlp_coeff[ 2] * data[i- 3];
+ case 2: sum += qlp_coeff[ 1] * data[i- 2];
+ case 1: sum += qlp_coeff[ 0] * data[i- 1];
+ }
+ residual[i] = data[i] - (sum >> lp_quantization);
+ }
+ }
+ else { /* order > 12 */
+ for(i = 0; i < (int)data_len; i++) {
+ sum = 0;
+ switch(order) {
+ case 32: sum += qlp_coeff[31] * data[i-32];
+ case 31: sum += qlp_coeff[30] * data[i-31];
+ case 30: sum += qlp_coeff[29] * data[i-30];
+ case 29: sum += qlp_coeff[28] * data[i-29];
+ case 28: sum += qlp_coeff[27] * data[i-28];
+ case 27: sum += qlp_coeff[26] * data[i-27];
+ case 26: sum += qlp_coeff[25] * data[i-26];
+ case 25: sum += qlp_coeff[24] * data[i-25];
+ case 24: sum += qlp_coeff[23] * data[i-24];
+ case 23: sum += qlp_coeff[22] * data[i-23];
+ case 22: sum += qlp_coeff[21] * data[i-22];
+ case 21: sum += qlp_coeff[20] * data[i-21];
+ case 20: sum += qlp_coeff[19] * data[i-20];
+ case 19: sum += qlp_coeff[18] * data[i-19];
+ case 18: sum += qlp_coeff[17] * data[i-18];
+ case 17: sum += qlp_coeff[16] * data[i-17];
+ case 16: sum += qlp_coeff[15] * data[i-16];
+ case 15: sum += qlp_coeff[14] * data[i-15];
+ case 14: sum += qlp_coeff[13] * data[i-14];
+ case 13: sum += qlp_coeff[12] * data[i-13];
+ sum += qlp_coeff[11] * data[i-12];
+ sum += qlp_coeff[10] * data[i-11];
+ sum += qlp_coeff[ 9] * data[i-10];
+ sum += qlp_coeff[ 8] * data[i- 9];
+ sum += qlp_coeff[ 7] * data[i- 8];
+ sum += qlp_coeff[ 6] * data[i- 7];
+ sum += qlp_coeff[ 5] * data[i- 6];
+ sum += qlp_coeff[ 4] * data[i- 5];
+ sum += qlp_coeff[ 3] * data[i- 4];
+ sum += qlp_coeff[ 2] * data[i- 3];
+ sum += qlp_coeff[ 1] * data[i- 2];
+ sum += qlp_coeff[ 0] * data[i- 1];
+ }
+ residual[i] = data[i] - (sum >> lp_quantization);
+ }
+ }
+ _mm256_zeroupper();
+}
+
+FLAC__SSE_TARGET("avx2")
+void FLAC__lpc_compute_residual_from_qlp_coefficients_intrin_avx2(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[])
+{
+ int i;
+ FLAC__int32 sum;
+ __m128i cnt = _mm_cvtsi32_si128(lp_quantization);
+
+ FLAC__ASSERT(order > 0);
+ FLAC__ASSERT(order <= 32);
+
+ if(order <= 12) {
+ if(order > 8) {
+ if(order > 10) {
+ if(order == 12) {
+ __m256i q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11;
+ q0 = _mm256_set1_epi32(qlp_coeff[0 ]);
+ q1 = _mm256_set1_epi32(qlp_coeff[1 ]);
+ q2 = _mm256_set1_epi32(qlp_coeff[2 ]);
+ q3 = _mm256_set1_epi32(qlp_coeff[3 ]);
+ q4 = _mm256_set1_epi32(qlp_coeff[4 ]);
+ q5 = _mm256_set1_epi32(qlp_coeff[5 ]);
+ q6 = _mm256_set1_epi32(qlp_coeff[6 ]);
+ q7 = _mm256_set1_epi32(qlp_coeff[7 ]);
+ q8 = _mm256_set1_epi32(qlp_coeff[8 ]);
+ q9 = _mm256_set1_epi32(qlp_coeff[9 ]);
+ q10 = _mm256_set1_epi32(qlp_coeff[10]);
+ q11 = _mm256_set1_epi32(qlp_coeff[11]);
+
+ for(i = 0; i < (int)data_len-7; i+=8) {
+ __m256i summ, mull;
+ summ = _mm256_mullo_epi32(q11, _mm256_loadu_si256((const __m256i*)(data+i-12)));
+ mull = _mm256_mullo_epi32(q10, _mm256_loadu_si256((const __m256i*)(data+i-11))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q9, _mm256_loadu_si256((const __m256i*)(data+i-10))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q8, _mm256_loadu_si256((const __m256i*)(data+i-9))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q7, _mm256_loadu_si256((const __m256i*)(data+i-8))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q6, _mm256_loadu_si256((const __m256i*)(data+i-7))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q5, _mm256_loadu_si256((const __m256i*)(data+i-6))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q4, _mm256_loadu_si256((const __m256i*)(data+i-5))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q3, _mm256_loadu_si256((const __m256i*)(data+i-4))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q2, _mm256_loadu_si256((const __m256i*)(data+i-3))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q1, _mm256_loadu_si256((const __m256i*)(data+i-2))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q0, _mm256_loadu_si256((const __m256i*)(data+i-1))); summ = _mm256_add_epi32(summ, mull);
+ summ = _mm256_sra_epi32(summ, cnt);
+ _mm256_storeu_si256((__m256i*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(data+i)), summ));
+ }
+ }
+ else { /* order == 11 */
+ __m256i q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10;
+ q0 = _mm256_set1_epi32(qlp_coeff[0 ]);
+ q1 = _mm256_set1_epi32(qlp_coeff[1 ]);
+ q2 = _mm256_set1_epi32(qlp_coeff[2 ]);
+ q3 = _mm256_set1_epi32(qlp_coeff[3 ]);
+ q4 = _mm256_set1_epi32(qlp_coeff[4 ]);
+ q5 = _mm256_set1_epi32(qlp_coeff[5 ]);
+ q6 = _mm256_set1_epi32(qlp_coeff[6 ]);
+ q7 = _mm256_set1_epi32(qlp_coeff[7 ]);
+ q8 = _mm256_set1_epi32(qlp_coeff[8 ]);
+ q9 = _mm256_set1_epi32(qlp_coeff[9 ]);
+ q10 = _mm256_set1_epi32(qlp_coeff[10]);
+
+ for(i = 0; i < (int)data_len-7; i+=8) {
+ __m256i summ, mull;
+ summ = _mm256_mullo_epi32(q10, _mm256_loadu_si256((const __m256i*)(data+i-11)));
+ mull = _mm256_mullo_epi32(q9, _mm256_loadu_si256((const __m256i*)(data+i-10))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q8, _mm256_loadu_si256((const __m256i*)(data+i-9))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q7, _mm256_loadu_si256((const __m256i*)(data+i-8))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q6, _mm256_loadu_si256((const __m256i*)(data+i-7))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q5, _mm256_loadu_si256((const __m256i*)(data+i-6))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q4, _mm256_loadu_si256((const __m256i*)(data+i-5))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q3, _mm256_loadu_si256((const __m256i*)(data+i-4))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q2, _mm256_loadu_si256((const __m256i*)(data+i-3))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q1, _mm256_loadu_si256((const __m256i*)(data+i-2))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q0, _mm256_loadu_si256((const __m256i*)(data+i-1))); summ = _mm256_add_epi32(summ, mull);
+ summ = _mm256_sra_epi32(summ, cnt);
+ _mm256_storeu_si256((__m256i*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(data+i)), summ));
+ }
+ }
+ }
+ else {
+ if(order == 10) {
+ __m256i q0, q1, q2, q3, q4, q5, q6, q7, q8, q9;
+ q0 = _mm256_set1_epi32(qlp_coeff[0 ]);
+ q1 = _mm256_set1_epi32(qlp_coeff[1 ]);
+ q2 = _mm256_set1_epi32(qlp_coeff[2 ]);
+ q3 = _mm256_set1_epi32(qlp_coeff[3 ]);
+ q4 = _mm256_set1_epi32(qlp_coeff[4 ]);
+ q5 = _mm256_set1_epi32(qlp_coeff[5 ]);
+ q6 = _mm256_set1_epi32(qlp_coeff[6 ]);
+ q7 = _mm256_set1_epi32(qlp_coeff[7 ]);
+ q8 = _mm256_set1_epi32(qlp_coeff[8 ]);
+ q9 = _mm256_set1_epi32(qlp_coeff[9 ]);
+
+ for(i = 0; i < (int)data_len-7; i+=8) {
+ __m256i summ, mull;
+ summ = _mm256_mullo_epi32(q9, _mm256_loadu_si256((const __m256i*)(data+i-10)));
+ mull = _mm256_mullo_epi32(q8, _mm256_loadu_si256((const __m256i*)(data+i-9))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q7, _mm256_loadu_si256((const __m256i*)(data+i-8))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q6, _mm256_loadu_si256((const __m256i*)(data+i-7))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q5, _mm256_loadu_si256((const __m256i*)(data+i-6))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q4, _mm256_loadu_si256((const __m256i*)(data+i-5))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q3, _mm256_loadu_si256((const __m256i*)(data+i-4))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q2, _mm256_loadu_si256((const __m256i*)(data+i-3))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q1, _mm256_loadu_si256((const __m256i*)(data+i-2))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q0, _mm256_loadu_si256((const __m256i*)(data+i-1))); summ = _mm256_add_epi32(summ, mull);
+ summ = _mm256_sra_epi32(summ, cnt);
+ _mm256_storeu_si256((__m256i*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(data+i)), summ));
+ }
+ }
+ else { /* order == 9 */
+ __m256i q0, q1, q2, q3, q4, q5, q6, q7, q8;
+ q0 = _mm256_set1_epi32(qlp_coeff[0 ]);
+ q1 = _mm256_set1_epi32(qlp_coeff[1 ]);
+ q2 = _mm256_set1_epi32(qlp_coeff[2 ]);
+ q3 = _mm256_set1_epi32(qlp_coeff[3 ]);
+ q4 = _mm256_set1_epi32(qlp_coeff[4 ]);
+ q5 = _mm256_set1_epi32(qlp_coeff[5 ]);
+ q6 = _mm256_set1_epi32(qlp_coeff[6 ]);
+ q7 = _mm256_set1_epi32(qlp_coeff[7 ]);
+ q8 = _mm256_set1_epi32(qlp_coeff[8 ]);
+
+ for(i = 0; i < (int)data_len-7; i+=8) {
+ __m256i summ, mull;
+ summ = _mm256_mullo_epi32(q8, _mm256_loadu_si256((const __m256i*)(data+i-9)));
+ mull = _mm256_mullo_epi32(q7, _mm256_loadu_si256((const __m256i*)(data+i-8))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q6, _mm256_loadu_si256((const __m256i*)(data+i-7))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q5, _mm256_loadu_si256((const __m256i*)(data+i-6))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q4, _mm256_loadu_si256((const __m256i*)(data+i-5))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q3, _mm256_loadu_si256((const __m256i*)(data+i-4))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q2, _mm256_loadu_si256((const __m256i*)(data+i-3))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q1, _mm256_loadu_si256((const __m256i*)(data+i-2))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q0, _mm256_loadu_si256((const __m256i*)(data+i-1))); summ = _mm256_add_epi32(summ, mull);
+ summ = _mm256_sra_epi32(summ, cnt);
+ _mm256_storeu_si256((__m256i*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(data+i)), summ));
+ }
+ }
+ }
+ }
+ else if(order > 4) {
+ if(order > 6) {
+ if(order == 8) {
+ __m256i q0, q1, q2, q3, q4, q5, q6, q7;
+ q0 = _mm256_set1_epi32(qlp_coeff[0 ]);
+ q1 = _mm256_set1_epi32(qlp_coeff[1 ]);
+ q2 = _mm256_set1_epi32(qlp_coeff[2 ]);
+ q3 = _mm256_set1_epi32(qlp_coeff[3 ]);
+ q4 = _mm256_set1_epi32(qlp_coeff[4 ]);
+ q5 = _mm256_set1_epi32(qlp_coeff[5 ]);
+ q6 = _mm256_set1_epi32(qlp_coeff[6 ]);
+ q7 = _mm256_set1_epi32(qlp_coeff[7 ]);
+
+ for(i = 0; i < (int)data_len-7; i+=8) {
+ __m256i summ, mull;
+ summ = _mm256_mullo_epi32(q7, _mm256_loadu_si256((const __m256i*)(data+i-8)));
+ mull = _mm256_mullo_epi32(q6, _mm256_loadu_si256((const __m256i*)(data+i-7))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q5, _mm256_loadu_si256((const __m256i*)(data+i-6))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q4, _mm256_loadu_si256((const __m256i*)(data+i-5))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q3, _mm256_loadu_si256((const __m256i*)(data+i-4))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q2, _mm256_loadu_si256((const __m256i*)(data+i-3))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q1, _mm256_loadu_si256((const __m256i*)(data+i-2))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q0, _mm256_loadu_si256((const __m256i*)(data+i-1))); summ = _mm256_add_epi32(summ, mull);
+ summ = _mm256_sra_epi32(summ, cnt);
+ _mm256_storeu_si256((__m256i*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(data+i)), summ));
+ }
+ }
+ else { /* order == 7 */
+ __m256i q0, q1, q2, q3, q4, q5, q6;
+ q0 = _mm256_set1_epi32(qlp_coeff[0 ]);
+ q1 = _mm256_set1_epi32(qlp_coeff[1 ]);
+ q2 = _mm256_set1_epi32(qlp_coeff[2 ]);
+ q3 = _mm256_set1_epi32(qlp_coeff[3 ]);
+ q4 = _mm256_set1_epi32(qlp_coeff[4 ]);
+ q5 = _mm256_set1_epi32(qlp_coeff[5 ]);
+ q6 = _mm256_set1_epi32(qlp_coeff[6 ]);
+
+ for(i = 0; i < (int)data_len-7; i+=8) {
+ __m256i summ, mull;
+ summ = _mm256_mullo_epi32(q6, _mm256_loadu_si256((const __m256i*)(data+i-7)));
+ mull = _mm256_mullo_epi32(q5, _mm256_loadu_si256((const __m256i*)(data+i-6))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q4, _mm256_loadu_si256((const __m256i*)(data+i-5))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q3, _mm256_loadu_si256((const __m256i*)(data+i-4))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q2, _mm256_loadu_si256((const __m256i*)(data+i-3))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q1, _mm256_loadu_si256((const __m256i*)(data+i-2))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q0, _mm256_loadu_si256((const __m256i*)(data+i-1))); summ = _mm256_add_epi32(summ, mull);
+ summ = _mm256_sra_epi32(summ, cnt);
+ _mm256_storeu_si256((__m256i*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(data+i)), summ));
+ }
+ }
+ }
+ else {
+ if(order == 6) {
+ __m256i q0, q1, q2, q3, q4, q5;
+ q0 = _mm256_set1_epi32(qlp_coeff[0 ]);
+ q1 = _mm256_set1_epi32(qlp_coeff[1 ]);
+ q2 = _mm256_set1_epi32(qlp_coeff[2 ]);
+ q3 = _mm256_set1_epi32(qlp_coeff[3 ]);
+ q4 = _mm256_set1_epi32(qlp_coeff[4 ]);
+ q5 = _mm256_set1_epi32(qlp_coeff[5 ]);
+
+ for(i = 0; i < (int)data_len-7; i+=8) {
+ __m256i summ, mull;
+ summ = _mm256_mullo_epi32(q5, _mm256_loadu_si256((const __m256i*)(data+i-6)));
+ mull = _mm256_mullo_epi32(q4, _mm256_loadu_si256((const __m256i*)(data+i-5))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q3, _mm256_loadu_si256((const __m256i*)(data+i-4))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q2, _mm256_loadu_si256((const __m256i*)(data+i-3))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q1, _mm256_loadu_si256((const __m256i*)(data+i-2))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q0, _mm256_loadu_si256((const __m256i*)(data+i-1))); summ = _mm256_add_epi32(summ, mull);
+ summ = _mm256_sra_epi32(summ, cnt);
+ _mm256_storeu_si256((__m256i*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(data+i)), summ));
+ }
+ }
+ else { /* order == 5 */
+ __m256i q0, q1, q2, q3, q4;
+ q0 = _mm256_set1_epi32(qlp_coeff[0 ]);
+ q1 = _mm256_set1_epi32(qlp_coeff[1 ]);
+ q2 = _mm256_set1_epi32(qlp_coeff[2 ]);
+ q3 = _mm256_set1_epi32(qlp_coeff[3 ]);
+ q4 = _mm256_set1_epi32(qlp_coeff[4 ]);
+
+ for(i = 0; i < (int)data_len-7; i+=8) {
+ __m256i summ, mull;
+ summ = _mm256_mullo_epi32(q4, _mm256_loadu_si256((const __m256i*)(data+i-5)));
+ mull = _mm256_mullo_epi32(q3, _mm256_loadu_si256((const __m256i*)(data+i-4))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q2, _mm256_loadu_si256((const __m256i*)(data+i-3))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q1, _mm256_loadu_si256((const __m256i*)(data+i-2))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q0, _mm256_loadu_si256((const __m256i*)(data+i-1))); summ = _mm256_add_epi32(summ, mull);
+ summ = _mm256_sra_epi32(summ, cnt);
+ _mm256_storeu_si256((__m256i*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(data+i)), summ));
+ }
+ }
+ }
+ }
+ else {
+ if(order > 2) {
+ if(order == 4) {
+ __m256i q0, q1, q2, q3;
+ q0 = _mm256_set1_epi32(qlp_coeff[0 ]);
+ q1 = _mm256_set1_epi32(qlp_coeff[1 ]);
+ q2 = _mm256_set1_epi32(qlp_coeff[2 ]);
+ q3 = _mm256_set1_epi32(qlp_coeff[3 ]);
+
+ for(i = 0; i < (int)data_len-7; i+=8) {
+ __m256i summ, mull;
+ summ = _mm256_mullo_epi32(q3, _mm256_loadu_si256((const __m256i*)(data+i-4)));
+ mull = _mm256_mullo_epi32(q2, _mm256_loadu_si256((const __m256i*)(data+i-3))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q1, _mm256_loadu_si256((const __m256i*)(data+i-2))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q0, _mm256_loadu_si256((const __m256i*)(data+i-1))); summ = _mm256_add_epi32(summ, mull);
+ summ = _mm256_sra_epi32(summ, cnt);
+ _mm256_storeu_si256((__m256i*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(data+i)), summ));
+ }
+ }
+ else { /* order == 3 */
+ __m256i q0, q1, q2;
+ q0 = _mm256_set1_epi32(qlp_coeff[0 ]);
+ q1 = _mm256_set1_epi32(qlp_coeff[1 ]);
+ q2 = _mm256_set1_epi32(qlp_coeff[2 ]);
+
+ for(i = 0; i < (int)data_len-7; i+=8) {
+ __m256i summ, mull;
+ summ = _mm256_mullo_epi32(q2, _mm256_loadu_si256((const __m256i*)(data+i-3)));
+ mull = _mm256_mullo_epi32(q1, _mm256_loadu_si256((const __m256i*)(data+i-2))); summ = _mm256_add_epi32(summ, mull);
+ mull = _mm256_mullo_epi32(q0, _mm256_loadu_si256((const __m256i*)(data+i-1))); summ = _mm256_add_epi32(summ, mull);
+ summ = _mm256_sra_epi32(summ, cnt);
+ _mm256_storeu_si256((__m256i*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(data+i)), summ));
+ }
+ }
+ }
+ else {
+ if(order == 2) {
+ __m256i q0, q1;
+ q0 = _mm256_set1_epi32(qlp_coeff[0 ]);
+ q1 = _mm256_set1_epi32(qlp_coeff[1 ]);
+
+ for(i = 0; i < (int)data_len-7; i+=8) {
+ __m256i summ, mull;
+ summ = _mm256_mullo_epi32(q1, _mm256_loadu_si256((const __m256i*)(data+i-2)));
+ mull = _mm256_mullo_epi32(q0, _mm256_loadu_si256((const __m256i*)(data+i-1))); summ = _mm256_add_epi32(summ, mull);
+ summ = _mm256_sra_epi32(summ, cnt);
+ _mm256_storeu_si256((__m256i*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(data+i)), summ));
+ }
+ }
+ else { /* order == 1 */
+ __m256i q0;
+ q0 = _mm256_set1_epi32(qlp_coeff[0 ]);
+
+ for(i = 0; i < (int)data_len-7; i+=8) {
+ __m256i summ;
+ summ = _mm256_mullo_epi32(q0, _mm256_loadu_si256((const __m256i*)(data+i-1)));
+ summ = _mm256_sra_epi32(summ, cnt);
+ _mm256_storeu_si256((__m256i*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(data+i)), summ));
+ }
+ }
+ }
+ }
+ for(; i < (int)data_len; i++) {
+ sum = 0;
+ switch(order) {
+ case 12: sum += qlp_coeff[11] * data[i-12];
+ case 11: sum += qlp_coeff[10] * data[i-11];
+ case 10: sum += qlp_coeff[ 9] * data[i-10];
+ case 9: sum += qlp_coeff[ 8] * data[i- 9];
+ case 8: sum += qlp_coeff[ 7] * data[i- 8];
+ case 7: sum += qlp_coeff[ 6] * data[i- 7];
+ case 6: sum += qlp_coeff[ 5] * data[i- 6];
+ case 5: sum += qlp_coeff[ 4] * data[i- 5];
+ case 4: sum += qlp_coeff[ 3] * data[i- 4];
+ case 3: sum += qlp_coeff[ 2] * data[i- 3];
+ case 2: sum += qlp_coeff[ 1] * data[i- 2];
+ case 1: sum += qlp_coeff[ 0] * data[i- 1];
+ }
+ residual[i] = data[i] - (sum >> lp_quantization);
+ }
+ }
+ else { /* order > 12 */
+ for(i = 0; i < (int)data_len; i++) {
+ sum = 0;
+ switch(order) {
+ case 32: sum += qlp_coeff[31] * data[i-32];
+ case 31: sum += qlp_coeff[30] * data[i-31];
+ case 30: sum += qlp_coeff[29] * data[i-30];
+ case 29: sum += qlp_coeff[28] * data[i-29];
+ case 28: sum += qlp_coeff[27] * data[i-28];
+ case 27: sum += qlp_coeff[26] * data[i-27];
+ case 26: sum += qlp_coeff[25] * data[i-26];
+ case 25: sum += qlp_coeff[24] * data[i-25];
+ case 24: sum += qlp_coeff[23] * data[i-24];
+ case 23: sum += qlp_coeff[22] * data[i-23];
+ case 22: sum += qlp_coeff[21] * data[i-22];
+ case 21: sum += qlp_coeff[20] * data[i-21];
+ case 20: sum += qlp_coeff[19] * data[i-20];
+ case 19: sum += qlp_coeff[18] * data[i-19];
+ case 18: sum += qlp_coeff[17] * data[i-18];
+ case 17: sum += qlp_coeff[16] * data[i-17];
+ case 16: sum += qlp_coeff[15] * data[i-16];
+ case 15: sum += qlp_coeff[14] * data[i-15];
+ case 14: sum += qlp_coeff[13] * data[i-14];
+ case 13: sum += qlp_coeff[12] * data[i-13];
+ sum += qlp_coeff[11] * data[i-12];
+ sum += qlp_coeff[10] * data[i-11];
+ sum += qlp_coeff[ 9] * data[i-10];
+ sum += qlp_coeff[ 8] * data[i- 9];
+ sum += qlp_coeff[ 7] * data[i- 8];
+ sum += qlp_coeff[ 6] * data[i- 7];
+ sum += qlp_coeff[ 5] * data[i- 6];
+ sum += qlp_coeff[ 4] * data[i- 5];
+ sum += qlp_coeff[ 3] * data[i- 4];
+ sum += qlp_coeff[ 2] * data[i- 3];
+ sum += qlp_coeff[ 1] * data[i- 2];
+ sum += qlp_coeff[ 0] * data[i- 1];
+ }
+ residual[i] = data[i] - (sum >> lp_quantization);
+ }
+ }
+ _mm256_zeroupper();
+}
+
+static FLAC__int32 pack_arr[8] = { 0, 2, 4, 6, 1, 3, 5, 7 };
+
+FLAC__SSE_TARGET("avx2")
+void FLAC__lpc_compute_residual_from_qlp_coefficients_wide_intrin_avx2(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[])
+{
+ int i;
+ FLAC__int64 sum;
+ __m128i cnt = _mm_cvtsi32_si128(lp_quantization);
+ __m256i pack = _mm256_loadu_si256((const __m256i *)pack_arr);
+
+ FLAC__ASSERT(order > 0);
+ FLAC__ASSERT(order <= 32);
+ FLAC__ASSERT(lp_quantization <= 32); /* there's no _mm256_sra_epi64() so we have to use _mm256_srl_epi64() */
+
+ if(order <= 12) {
+ if(order > 8) {
+ if(order > 10) {
+ if(order == 12) {
+ __m256i q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11;
+ q0 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[0 ]));
+ q1 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[1 ]));
+ q2 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[2 ]));
+ q3 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[3 ]));
+ q4 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[4 ]));
+ q5 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[5 ]));
+ q6 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[6 ]));
+ q7 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[7 ]));
+ q8 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[8 ]));
+ q9 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[9 ]));
+ q10 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[10]));
+ q11 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[11]));
+
+ for(i = 0; i < (int)data_len-3; i+=4) {
+ __m256i summ, mull;
+ summ = _mm256_mul_epi32(q11, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-12))));
+ mull = _mm256_mul_epi32(q10, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-11)))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q9, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-10)))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q8, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-9 )))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q7, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-8 )))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q6, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-7 )))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q5, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-6 )))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q4, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-5 )))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q3, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-4 )))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q2, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-3 )))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q1, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-2 )))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q0, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-1 )))); summ = _mm256_add_epi64(summ, mull);
+ summ = _mm256_permutevar8x32_epi32(_mm256_srl_epi64(summ, cnt), pack);
+ _mm_storeu_si128((__m128i*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(data+i)), _mm256_castsi256_si128(summ)));
+ }
+ }
+ else { /* order == 11 */
+ __m256i q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10;
+ q0 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[0 ]));
+ q1 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[1 ]));
+ q2 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[2 ]));
+ q3 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[3 ]));
+ q4 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[4 ]));
+ q5 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[5 ]));
+ q6 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[6 ]));
+ q7 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[7 ]));
+ q8 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[8 ]));
+ q9 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[9 ]));
+ q10 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[10]));
+
+ for(i = 0; i < (int)data_len-3; i+=4) {
+ __m256i summ, mull;
+ summ = _mm256_mul_epi32(q10, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-11))));
+ mull = _mm256_mul_epi32(q9, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-10)))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q8, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-9 )))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q7, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-8 )))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q6, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-7 )))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q5, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-6 )))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q4, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-5 )))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q3, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-4 )))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q2, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-3 )))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q1, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-2 )))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q0, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-1 )))); summ = _mm256_add_epi64(summ, mull);
+ summ = _mm256_permutevar8x32_epi32(_mm256_srl_epi64(summ, cnt), pack);
+ _mm_storeu_si128((__m128i*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(data+i)), _mm256_castsi256_si128(summ)));
+ }
+ }
+ }
+ else {
+ if(order == 10) {
+ __m256i q0, q1, q2, q3, q4, q5, q6, q7, q8, q9;
+ q0 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[0 ]));
+ q1 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[1 ]));
+ q2 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[2 ]));
+ q3 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[3 ]));
+ q4 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[4 ]));
+ q5 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[5 ]));
+ q6 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[6 ]));
+ q7 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[7 ]));
+ q8 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[8 ]));
+ q9 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[9 ]));
+
+ for(i = 0; i < (int)data_len-3; i+=4) {
+ __m256i summ, mull;
+ summ = _mm256_mul_epi32(q9, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-10))));
+ mull = _mm256_mul_epi32(q8, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-9 )))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q7, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-8 )))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q6, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-7 )))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q5, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-6 )))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q4, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-5 )))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q3, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-4 )))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q2, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-3 )))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q1, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-2 )))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q0, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-1 )))); summ = _mm256_add_epi64(summ, mull);
+ summ = _mm256_permutevar8x32_epi32(_mm256_srl_epi64(summ, cnt), pack);
+ _mm_storeu_si128((__m128i*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(data+i)), _mm256_castsi256_si128(summ)));
+ }
+ }
+ else { /* order == 9 */
+ __m256i q0, q1, q2, q3, q4, q5, q6, q7, q8;
+ q0 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[0 ]));
+ q1 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[1 ]));
+ q2 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[2 ]));
+ q3 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[3 ]));
+ q4 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[4 ]));
+ q5 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[5 ]));
+ q6 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[6 ]));
+ q7 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[7 ]));
+ q8 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[8 ]));
+
+ for(i = 0; i < (int)data_len-3; i+=4) {
+ __m256i summ, mull;
+ summ = _mm256_mul_epi32(q8, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-9 ))));
+ mull = _mm256_mul_epi32(q7, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-8 )))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q6, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-7 )))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q5, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-6 )))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q4, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-5 )))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q3, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-4 )))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q2, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-3 )))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q1, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-2 )))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q0, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-1 )))); summ = _mm256_add_epi64(summ, mull);
+ summ = _mm256_permutevar8x32_epi32(_mm256_srl_epi64(summ, cnt), pack);
+ _mm_storeu_si128((__m128i*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(data+i)), _mm256_castsi256_si128(summ)));
+ }
+ }
+ }
+ }
+ else if(order > 4) {
+ if(order > 6) {
+ if(order == 8) {
+ __m256i q0, q1, q2, q3, q4, q5, q6, q7;
+ q0 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[0 ]));
+ q1 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[1 ]));
+ q2 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[2 ]));
+ q3 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[3 ]));
+ q4 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[4 ]));
+ q5 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[5 ]));
+ q6 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[6 ]));
+ q7 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[7 ]));
+
+ for(i = 0; i < (int)data_len-3; i+=4) {
+ __m256i summ, mull;
+ summ = _mm256_mul_epi32(q7, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-8 ))));
+ mull = _mm256_mul_epi32(q6, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-7 )))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q5, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-6 )))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q4, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-5 )))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q3, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-4 )))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q2, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-3 )))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q1, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-2 )))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q0, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-1 )))); summ = _mm256_add_epi64(summ, mull);
+ summ = _mm256_permutevar8x32_epi32(_mm256_srl_epi64(summ, cnt), pack);
+ _mm_storeu_si128((__m128i*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(data+i)), _mm256_castsi256_si128(summ)));
+ }
+ }
+ else { /* order == 7 */
+ __m256i q0, q1, q2, q3, q4, q5, q6;
+ q0 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[0 ]));
+ q1 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[1 ]));
+ q2 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[2 ]));
+ q3 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[3 ]));
+ q4 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[4 ]));
+ q5 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[5 ]));
+ q6 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[6 ]));
+
+ for(i = 0; i < (int)data_len-3; i+=4) {
+ __m256i summ, mull;
+ summ = _mm256_mul_epi32(q6, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-7 ))));
+ mull = _mm256_mul_epi32(q5, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-6 )))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q4, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-5 )))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q3, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-4 )))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q2, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-3 )))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q1, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-2 )))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q0, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-1 )))); summ = _mm256_add_epi64(summ, mull);
+ summ = _mm256_permutevar8x32_epi32(_mm256_srl_epi64(summ, cnt), pack);
+ _mm_storeu_si128((__m128i*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(data+i)), _mm256_castsi256_si128(summ)));
+ }
+ }
+ }
+ else {
+ if(order == 6) {
+ __m256i q0, q1, q2, q3, q4, q5;
+ q0 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[0 ]));
+ q1 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[1 ]));
+ q2 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[2 ]));
+ q3 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[3 ]));
+ q4 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[4 ]));
+ q5 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[5 ]));
+
+ for(i = 0; i < (int)data_len-3; i+=4) {
+ __m256i summ, mull;
+ summ = _mm256_mul_epi32(q5, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-6 ))));
+ mull = _mm256_mul_epi32(q4, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-5 )))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q3, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-4 )))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q2, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-3 )))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q1, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-2 )))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q0, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-1 )))); summ = _mm256_add_epi64(summ, mull);
+ summ = _mm256_permutevar8x32_epi32(_mm256_srl_epi64(summ, cnt), pack);
+ _mm_storeu_si128((__m128i*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(data+i)), _mm256_castsi256_si128(summ)));
+ }
+ }
+ else { /* order == 5 */
+ __m256i q0, q1, q2, q3, q4;
+ q0 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[0 ]));
+ q1 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[1 ]));
+ q2 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[2 ]));
+ q3 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[3 ]));
+ q4 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[4 ]));
+
+ for(i = 0; i < (int)data_len-3; i+=4) {
+ __m256i summ, mull;
+ summ = _mm256_mul_epi32(q4, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-5 ))));
+ mull = _mm256_mul_epi32(q3, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-4 )))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q2, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-3 )))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q1, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-2 )))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q0, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-1 )))); summ = _mm256_add_epi64(summ, mull);
+ summ = _mm256_permutevar8x32_epi32(_mm256_srl_epi64(summ, cnt), pack);
+ _mm_storeu_si128((__m128i*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(data+i)), _mm256_castsi256_si128(summ)));
+ }
+ }
+ }
+ }
+ else {
+ if(order > 2) {
+ if(order == 4) {
+ __m256i q0, q1, q2, q3;
+ q0 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[0 ]));
+ q1 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[1 ]));
+ q2 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[2 ]));
+ q3 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[3 ]));
+
+ for(i = 0; i < (int)data_len-3; i+=4) {
+ __m256i summ, mull;
+ summ = _mm256_mul_epi32(q3, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-4 ))));
+ mull = _mm256_mul_epi32(q2, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-3 )))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q1, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-2 )))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q0, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-1 )))); summ = _mm256_add_epi64(summ, mull);
+ summ = _mm256_permutevar8x32_epi32(_mm256_srl_epi64(summ, cnt), pack);
+ _mm_storeu_si128((__m128i*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(data+i)), _mm256_castsi256_si128(summ)));
+ }
+ }
+ else { /* order == 3 */
+ __m256i q0, q1, q2;
+ q0 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[0 ]));
+ q1 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[1 ]));
+ q2 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[2 ]));
+
+ for(i = 0; i < (int)data_len-3; i+=4) {
+ __m256i summ, mull;
+ summ = _mm256_mul_epi32(q2, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-3 ))));
+ mull = _mm256_mul_epi32(q1, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-2 )))); summ = _mm256_add_epi64(summ, mull);
+ mull = _mm256_mul_epi32(q0, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-1 )))); summ = _mm256_add_epi64(summ, mull);
+ summ = _mm256_permutevar8x32_epi32(_mm256_srl_epi64(summ, cnt), pack);
+ _mm_storeu_si128((__m128i*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(data+i)), _mm256_castsi256_si128(summ)));
+ }
+ }
+ }
+ else {
+ if(order == 2) {
+ __m256i q0, q1;
+ q0 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[0 ]));
+ q1 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[1 ]));
+
+ for(i = 0; i < (int)data_len-3; i+=4) {
+ __m256i summ, mull;
+ summ = _mm256_mul_epi32(q1, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-2 ))));
+ mull = _mm256_mul_epi32(q0, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-1 )))); summ = _mm256_add_epi64(summ, mull);
+ summ = _mm256_permutevar8x32_epi32(_mm256_srl_epi64(summ, cnt), pack);
+ _mm_storeu_si128((__m128i*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(data+i)), _mm256_castsi256_si128(summ)));
+ }
+ }
+ else { /* order == 1 */
+ __m256i q0;
+ q0 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[0 ]));
+
+ for(i = 0; i < (int)data_len-3; i+=4) {
+ __m256i summ;
+ summ = _mm256_mul_epi32(q0, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(data+i-1 ))));
+ summ = _mm256_permutevar8x32_epi32(_mm256_srl_epi64(summ, cnt), pack);
+ _mm_storeu_si128((__m128i*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(data+i)), _mm256_castsi256_si128(summ)));
+ }
+ }
+ }
+ }
+ for(; i < (int)data_len; i++) {
+ sum = 0;
+ switch(order) {
+ case 12: sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
+ case 11: sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
+ case 10: sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10];
+ case 9: sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9];
+ case 8: sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8];
+ case 7: sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7];
+ case 6: sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6];
+ case 5: sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5];
+ case 4: sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4];
+ case 3: sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3];
+ case 2: sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2];
+ case 1: sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1];
+ }
+ residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
+ }
+ }
+ else { /* order > 12 */
+ for(i = 0; i < (int)data_len; i++) {
+ sum = 0;
+ switch(order) {
+ case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32];
+ case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31];
+ case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30];
+ case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29];
+ case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28];
+ case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27];
+ case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26];
+ case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25];
+ case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24];
+ case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23];
+ case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22];
+ case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21];
+ case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20];
+ case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19];
+ case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18];
+ case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17];
+ case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16];
+ case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15];
+ case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14];
+ case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13];
+ sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
+ sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
+ sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10];
+ sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9];
+ sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8];
+ sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7];
+ sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6];
+ sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5];
+ sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4];
+ sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3];
+ sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2];
+ sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1];
+ }
+ residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
+ }
+ }
+ _mm256_zeroupper();
+}
+
+#endif /* FLAC__AVX2_SUPPORTED */
+#endif /* (FLAC__CPU_IA32 || FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN */
+#endif /* FLAC__NO_ASM */
+#endif /* FLAC__INTEGER_ONLY_LIBRARY */
diff --git a/src/libFLAC/stream_encoder.c b/src/libFLAC/stream_encoder.c
index b860bfd8..c0430def 100644
--- a/src/libFLAC/stream_encoder.c
+++ b/src/libFLAC/stream_encoder.c
@@ -950,6 +950,13 @@ static FLAC__StreamEncoderInitStatus init_stream_internal_(
encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit = FLAC__lpc_compute_residual_from_qlp_coefficients_wide_intrin_sse41;
}
# endif
+# ifdef FLAC__AVX2_SUPPORTED
+ if(encoder->private_->cpuinfo.ia32.avx2) {
+ encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_16_intrin_avx2;
+ encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_intrin_avx2;
+ encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit = FLAC__lpc_compute_residual_from_qlp_coefficients_wide_intrin_avx2;
+ }
+# endif
# ifdef FLAC__SSE2_SUPPORTED
if (encoder->private_->cpuinfo.ia32.sse2) {
@@ -986,6 +993,13 @@ static FLAC__StreamEncoderInitStatus init_stream_internal_(
encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_intrin_sse41;
}
# endif
+# ifdef FLAC__AVX2_SUPPORTED
+ if(encoder->private_->cpuinfo.x86.avx2) {
+ encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_16_intrin_avx2;
+ encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_intrin_avx2;
+ encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit = FLAC__lpc_compute_residual_from_qlp_coefficients_wide_intrin_avx2;
+ }
+# endif
# ifdef FLAC__SSE2_SUPPORTED
encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor_intrin_sse2;
@@ -1013,6 +1027,10 @@ static FLAC__StreamEncoderInitStatus init_stream_internal_(
if(encoder->private_->cpuinfo.ia32.ssse3)
encoder->private_->local_precompute_partition_info_sums = FLAC__precompute_partition_info_sums_intrin_ssse3;
# endif
+# ifdef FLAC__AVX2_SUPPORTED
+ if(encoder->private_->cpuinfo.ia32.avx2)
+ encoder->private_->local_precompute_partition_info_sums = FLAC__precompute_partition_info_sums_intrin_avx2;
+# endif
# elif defined FLAC__CPU_X86_64
# ifdef FLAC__SSE2_SUPPORTED
encoder->private_->local_precompute_partition_info_sums = FLAC__precompute_partition_info_sums_intrin_sse2;
@@ -1021,6 +1039,10 @@ static FLAC__StreamEncoderInitStatus init_stream_internal_(
if(encoder->private_->cpuinfo.x86.ssse3)
encoder->private_->local_precompute_partition_info_sums = FLAC__precompute_partition_info_sums_intrin_ssse3;
# endif
+# ifdef FLAC__AVX2_SUPPORTED
+ if(encoder->private_->cpuinfo.x86.avx2)
+ encoder->private_->local_precompute_partition_info_sums = FLAC__precompute_partition_info_sums_intrin_avx2;
+# endif
# endif /* FLAC__CPU_... */
}
#endif /* !FLAC__NO_ASM && FLAC__HAS_X86INTRIN */
diff --git a/src/libFLAC/stream_encoder_intrin_avx2.c b/src/libFLAC/stream_encoder_intrin_avx2.c
new file mode 100644
index 00000000..3aa31972
--- /dev/null
+++ b/src/libFLAC/stream_encoder_intrin_avx2.c
@@ -0,0 +1,142 @@
+/* libFLAC - Free Lossless Audio Codec library
+ * Copyright (C) 2000-2009 Josh Coalson
+ * Copyright (C) 2011-2014 Xiph.Org Foundation
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - Neither the name of the Xiph.org Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#ifndef FLAC__NO_ASM
+#if (defined FLAC__CPU_IA32 || defined FLAC__CPU_X86_64) && defined FLAC__HAS_X86INTRIN
+#include "private/stream_encoder.h"
+#include "private/bitmath.h"
+#ifdef FLAC__AVX2_SUPPORTED
+
+#include <stdlib.h> /* for abs() */
+#include <immintrin.h> /* AVX2 */
+#include "FLAC/assert.h"
+
+FLAC__SSE_TARGET("avx2")
+void FLAC__precompute_partition_info_sums_intrin_avx2(const FLAC__int32 residual[], FLAC__uint64 abs_residual_partition_sums[],
+ unsigned residual_samples, unsigned predictor_order, unsigned min_partition_order, unsigned max_partition_order, unsigned bps)
+{
+ const unsigned default_partition_samples = (residual_samples + predictor_order) >> max_partition_order;
+ unsigned partitions = 1u << max_partition_order;
+
+ FLAC__ASSERT(default_partition_samples > predictor_order);
+
+ /* first do max_partition_order */
+ {
+ unsigned partition, residual_sample, end = (unsigned)(-(int)predictor_order);
+ __m256i res256, sum256;
+ __m128i res128, sum128;
+
+ if(FLAC__bitmath_ilog2(default_partition_samples) + bps + FLAC__MAX_EXTRA_RESIDUAL_BPS < 32) {
+ for(partition = residual_sample = 0; partition < partitions; partition++) {
+ end += default_partition_samples;
+ sum256 = _mm256_setzero_si256();
+
+ for( ; (int)residual_sample < (int)end-7; residual_sample+=8) {
+ res256 = _mm256_abs_epi32(_mm256_loadu_si256((const __m256i*)(residual+residual_sample)));
+ sum256 = _mm256_add_epi32(sum256, res256);
+ }
+
+ sum128 = _mm_add_epi32(_mm256_extracti128_si256(sum256, 1), _mm256_castsi256_si128(sum256));
+
+ for( ; (int)residual_sample < (int)end-3; residual_sample+=4) {
+ res128 = _mm_abs_epi32(_mm_loadu_si128((const __m128i*)(residual+residual_sample)));
+ sum128 = _mm_add_epi32(sum128, res128);
+ }
+
+ for( ; residual_sample < end; residual_sample++) {
+ res128 = _mm_cvtsi32_si128(residual[residual_sample]);
+ res128 = _mm_abs_epi32(res128);
+ sum128 = _mm_add_epi32(sum128, res128);
+ }
+
+ sum128 = _mm_hadd_epi32(sum128, sum128);
+ sum128 = _mm_hadd_epi32(sum128, sum128);
+ abs_residual_partition_sums[partition] = (FLAC__uint32)_mm_cvtsi128_si32(sum128);
+ }
+ }
+ else { /* have to pessimistically use 64 bits for accumulator */
+ for(partition = residual_sample = 0; partition < partitions; partition++) {
+ end += default_partition_samples;
+ sum256 = _mm256_setzero_si256();
+
+ for( ; (int)residual_sample < (int)end-3; residual_sample+=4) {
+ res128 = _mm_abs_epi32(_mm_loadu_si128((const __m128i*)(residual+residual_sample)));
+ res256 = _mm256_cvtepu32_epi64(res128);
+ sum256 = _mm256_add_epi64(sum256, res256);
+ }
+
+ sum128 = _mm_add_epi64(_mm256_extracti128_si256(sum256, 1), _mm256_castsi256_si128(sum256));
+
+ for( ; (int)residual_sample < (int)end-1; residual_sample+=2) {
+ res128 = _mm_loadl_epi64((const __m128i*)(residual+residual_sample));
+ res128 = _mm_abs_epi32(res128);
+ res128 = _mm_cvtepu32_epi64(res128);
+ sum128 = _mm_add_epi64(sum128, res128);
+ }
+
+ for( ; residual_sample < end; residual_sample++) {
+ res128 = _mm_cvtsi32_si128(residual[residual_sample]);
+ res128 = _mm_abs_epi32(res128);
+ sum128 = _mm_add_epi64(sum128, res128);
+ }
+
+ sum128 = _mm_add_epi64(sum128, _mm_srli_si128(sum128, 8));
+ _mm_storel_epi64((__m128i*)(abs_residual_partition_sums+partition), sum128);
+ }
+ }
+ }
+
+ /* now merge partitions for lower orders */
+ {
+ unsigned from_partition = 0, to_partition = partitions;
+ int partition_order;
+ for(partition_order = (int)max_partition_order - 1; partition_order >= (int)min_partition_order; partition_order--) {
+ unsigned i;
+ partitions >>= 1;
+ for(i = 0; i < partitions; i++) {
+ abs_residual_partition_sums[to_partition++] =
+ abs_residual_partition_sums[from_partition ] +
+ abs_residual_partition_sums[from_partition+1];
+ from_partition += 2;
+ }
+ }
+ }
+ _mm256_zeroupper();
+}
+
+#endif /* FLAC__AVX2_SUPPORTED */
+#endif /* (FLAC__CPU_IA32 || FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN */
+#endif /* FLAC__NO_ASM */