summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/vp9_quantize_test.cc8
-rw-r--r--vp9/common/vp9_rtcd_defs.pl2
-rw-r--r--vp9/encoder/x86/vp9_quantize_avx2.c140
-rw-r--r--vp9/vp9cx.mk1
-rw-r--r--vpx_dsp/x86/quantize_x86.h1
5 files changed, 150 insertions, 2 deletions
diff --git a/test/vp9_quantize_test.cc b/test/vp9_quantize_test.cc
index 8713ac655..f2234f045 100644
--- a/test/vp9_quantize_test.cc
+++ b/test/vp9_quantize_test.cc
@@ -532,6 +532,14 @@ INSTANTIATE_TEST_CASE_P(
false)));
#endif // HAVE_AVX && !CONFIG_VP9_HIGHBITDEPTH
+#if ARCH_X86_64 && HAVE_AVX2
+INSTANTIATE_TEST_CASE_P(
+ AVX2, VP9QuantizeTest,
+ ::testing::Values(make_tuple(&QuantFPWrapper<vp9_quantize_fp_avx2>,
+ &QuantFPWrapper<quantize_fp_nz_c>, VPX_BITS_8,
+ 16, true)));
+#endif // HAVE_AVX2 && !CONFIG_VP9_HIGHBITDEPTH
+
// TODO(webm:1448): dqcoeff is not handled correctly in HBD builds.
#if HAVE_NEON && !CONFIG_VP9_HIGHBITDEPTH
INSTANTIATE_TEST_CASE_P(
diff --git a/vp9/common/vp9_rtcd_defs.pl b/vp9/common/vp9_rtcd_defs.pl
index 7ee7ddaee..d25f9694d 100644
--- a/vp9/common/vp9_rtcd_defs.pl
+++ b/vp9/common/vp9_rtcd_defs.pl
@@ -129,7 +129,7 @@ add_proto qw/int64_t vp9_block_error/, "const tran_low_t *coeff, const tran_low_
add_proto qw/int64_t vp9_block_error_fp/, "const tran_low_t *coeff, const tran_low_t *dqcoeff, int block_size";
add_proto qw/void vp9_quantize_fp/, "const tran_low_t *coeff_ptr, intptr_t n_coeffs, int skip_block, const int16_t *round_ptr, const int16_t *quant_ptr, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const int16_t *scan, const int16_t *iscan";
-specialize qw/vp9_quantize_fp neon sse2/, "$ssse3_x86_64";
+specialize qw/vp9_quantize_fp neon sse2 avx2/, "$ssse3_x86_64";
add_proto qw/void vp9_quantize_fp_32x32/, "const tran_low_t *coeff_ptr, intptr_t n_coeffs, int skip_block, const int16_t *round_ptr, const int16_t *quant_ptr, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const int16_t *scan, const int16_t *iscan";
specialize qw/vp9_quantize_fp_32x32 neon/, "$ssse3_x86_64";
diff --git a/vp9/encoder/x86/vp9_quantize_avx2.c b/vp9/encoder/x86/vp9_quantize_avx2.c
new file mode 100644
index 000000000..4bebc34d6
--- /dev/null
+++ b/vp9/encoder/x86/vp9_quantize_avx2.c
@@ -0,0 +1,140 @@
+/*
+ * Copyright (c) 2017 The WebM project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include <assert.h>
+#include <immintrin.h> // AVX2
+
+#include "./vp9_rtcd.h"
+#include "vpx/vpx_integer.h"
+#include "vpx_dsp/vpx_dsp_common.h"
+#include "vpx_dsp/x86/bitdepth_conversion_avx2.h"
+#include "vpx_dsp/x86/quantize_x86.h"
+
+// Zero fill 8 positions in the output buffer.
+static INLINE void store_zero_tran_low(tran_low_t *a) {
+ const __m256i zero = _mm256_setzero_si256();
+#if CONFIG_VP9_HIGHBITDEPTH
+ _mm256_storeu_si256((__m256i *)(a), zero);
+ _mm256_storeu_si256((__m256i *)(a + 8), zero);
+#else
+ _mm256_storeu_si256((__m256i *)(a), zero);
+#endif
+}
+
+static INLINE __m256i scan_eob_256(const __m256i *iscan_ptr,
+ __m256i *coeff256) {
+ const __m256i iscan = _mm256_loadu_si256(iscan_ptr);
+ const __m256i zero256 = _mm256_setzero_si256();
+#if CONFIG_VP9_HIGHBITDEPTH
+ // The _mm256_packs_epi32() in load_tran_low() packs the 64 bit coeff as
+ // B1 A1 B0 A0. Shuffle to B1 B0 A1 A0 in order to scan eob correctly.
+ const __m256i _coeff256 = _mm256_permute4x64_epi64(*coeff256, 0xd8);
+ const __m256i zero_coeff0 = _mm256_cmpeq_epi16(_coeff256, zero256);
+#else
+ const __m256i zero_coeff0 = _mm256_cmpeq_epi16(*coeff256, zero256);
+#endif
+ const __m256i nzero_coeff0 = _mm256_cmpeq_epi16(zero_coeff0, zero256);
+ // Add one to convert from indices to counts
+ const __m256i iscan_plus_one = _mm256_sub_epi16(iscan, nzero_coeff0);
+ return _mm256_and_si256(iscan_plus_one, nzero_coeff0);
+}
+
+void vp9_quantize_fp_avx2(const tran_low_t *coeff_ptr, intptr_t n_coeffs,
+ int skip_block, const int16_t *round_ptr,
+ const int16_t *quant_ptr, tran_low_t *qcoeff_ptr,
+ tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr,
+ uint16_t *eob_ptr, const int16_t *scan_ptr,
+ const int16_t *iscan_ptr) {
+ __m128i eob;
+ __m256i round256, quant256, dequant256;
+ __m256i eob256, thr256;
+
+ (void)scan_ptr;
+ (void)skip_block;
+ assert(!skip_block);
+
+ coeff_ptr += n_coeffs;
+ iscan_ptr += n_coeffs;
+ qcoeff_ptr += n_coeffs;
+ dqcoeff_ptr += n_coeffs;
+ n_coeffs = -n_coeffs;
+
+ {
+ __m256i coeff256;
+
+ // Setup global values
+ {
+ const __m128i round = _mm_load_si128((const __m128i *)round_ptr);
+ const __m128i quant = _mm_load_si128((const __m128i *)quant_ptr);
+ const __m128i dequant = _mm_load_si128((const __m128i *)dequant_ptr);
+ round256 = _mm256_castsi128_si256(round);
+ round256 = _mm256_permute4x64_epi64(round256, 0x54);
+
+ quant256 = _mm256_castsi128_si256(quant);
+ quant256 = _mm256_permute4x64_epi64(quant256, 0x54);
+
+ dequant256 = _mm256_castsi128_si256(dequant);
+ dequant256 = _mm256_permute4x64_epi64(dequant256, 0x54);
+ }
+
+ {
+ __m256i qcoeff256;
+ __m256i qtmp256;
+ coeff256 = load_tran_low(coeff_ptr + n_coeffs);
+ qcoeff256 = _mm256_abs_epi16(coeff256);
+ qcoeff256 = _mm256_adds_epi16(qcoeff256, round256);
+ qtmp256 = _mm256_mulhi_epi16(qcoeff256, quant256);
+ qcoeff256 = _mm256_sign_epi16(qtmp256, coeff256);
+ store_tran_low(qcoeff256, qcoeff_ptr + n_coeffs);
+ coeff256 = _mm256_mullo_epi16(qcoeff256, dequant256);
+ store_tran_low(coeff256, dqcoeff_ptr + n_coeffs);
+ }
+
+ eob256 = scan_eob_256((const __m256i *)(iscan_ptr + n_coeffs), &coeff256);
+ n_coeffs += 8 * 2;
+ }
+
+ // remove dc constants
+ dequant256 = _mm256_permute2x128_si256(dequant256, dequant256, 0x31);
+ quant256 = _mm256_permute2x128_si256(quant256, quant256, 0x31);
+ round256 = _mm256_permute2x128_si256(round256, round256, 0x31);
+
+ thr256 = _mm256_srai_epi16(dequant256, 1);
+
+ // AC only loop
+ while (n_coeffs < 0) {
+ __m256i coeff256 = load_tran_low(coeff_ptr + n_coeffs);
+ __m256i qcoeff256 = _mm256_abs_epi16(coeff256);
+ int32_t nzflag =
+ _mm256_movemask_epi8(_mm256_cmpgt_epi16(qcoeff256, thr256));
+
+ if (nzflag) {
+ __m256i qtmp256;
+ qcoeff256 = _mm256_adds_epi16(qcoeff256, round256);
+ qtmp256 = _mm256_mulhi_epi16(qcoeff256, quant256);
+ qcoeff256 = _mm256_sign_epi16(qtmp256, coeff256);
+ store_tran_low(qcoeff256, qcoeff_ptr + n_coeffs);
+ coeff256 = _mm256_mullo_epi16(qcoeff256, dequant256);
+ store_tran_low(coeff256, dqcoeff_ptr + n_coeffs);
+ eob256 = _mm256_max_epi16(
+ eob256,
+ scan_eob_256((const __m256i *)(iscan_ptr + n_coeffs), &coeff256));
+ } else {
+ store_zero_tran_low(qcoeff_ptr + n_coeffs);
+ store_zero_tran_low(dqcoeff_ptr + n_coeffs);
+ }
+ n_coeffs += 8 * 2;
+ }
+
+ eob = _mm_max_epi16(_mm256_castsi256_si128(eob256),
+ _mm256_extracti128_si256(eob256, 1));
+
+ *eob_ptr = accumulate_eob(eob);
+}
diff --git a/vp9/vp9cx.mk b/vp9/vp9cx.mk
index d633ed142..6186d4614 100644
--- a/vp9/vp9cx.mk
+++ b/vp9/vp9cx.mk
@@ -103,6 +103,7 @@ VP9_CX_SRCS-yes += encoder/vp9_mbgraph.h
VP9_CX_SRCS-$(HAVE_SSE4_1) += encoder/x86/temporal_filter_sse4.c
VP9_CX_SRCS-$(HAVE_SSE2) += encoder/x86/vp9_quantize_sse2.c
+VP9_CX_SRCS-$(HAVE_AVX2) += encoder/x86/vp9_quantize_avx2.c
VP9_CX_SRCS-$(HAVE_AVX) += encoder/x86/vp9_diamond_search_sad_avx.c
ifeq ($(CONFIG_VP9_HIGHBITDEPTH),yes)
VP9_CX_SRCS-$(HAVE_SSE2) += encoder/x86/vp9_highbd_block_error_intrin_sse2.c
diff --git a/vpx_dsp/x86/quantize_x86.h b/vpx_dsp/x86/quantize_x86.h
index 34928fbb5..0e07a2ac5 100644
--- a/vpx_dsp/x86/quantize_x86.h
+++ b/vpx_dsp/x86/quantize_x86.h
@@ -12,7 +12,6 @@
#include "./vpx_config.h"
#include "vpx/vpx_integer.h"
-#include "vpx_dsp/x86/bitdepth_conversion_sse2.h"
static INLINE void load_b_values(const int16_t *zbin_ptr, __m128i *zbin,
const int16_t *round_ptr, __m128i *round,