History

vp8 quantize: use native abs/sign implementations

~4% improvement with a very rudimentary speed test

Johann committed 7 years ago

Commit e3f12b51 parent dff4d372 files · +23 −19Browse files

Unified · Split

2 files
  1. test/quantize_test.cc +15 −2
  2. vp8/encoder/x86/quantize_sse4.c +8 −17
test/quantize_test.cc+15−2
@@ -13,9 +13,10 @@ · 12 unmodified lines
13 13
14#include "third_party/googletest/src/include/gtest/gtest.h"14#include "third_party/googletest/src/include/gtest/gtest.h"
15 15
16#include "./vpx_config.h"
17#include "./vp8_rtcd.h"16#include "./vp8_rtcd.h"
17#include "./vpx_config.h"
18#include "test/acm_random.h"18#include "test/acm_random.h"
19#include "test/bench.h"
19#include "test/clear_system_state.h"20#include "test/clear_system_state.h"
20#include "test/register_state_check.h"21#include "test/register_state_check.h"
21#include "test/util.h"22#include "test/util.h"
@@ -117,7 +118,8 @@ class QuantizeTestBase { · 95 unmodified lines
117};118};
118 119
119class QuantizeTest : public QuantizeTestBase,120class QuantizeTest : public QuantizeTestBase,
120 public ::testing::TestWithParam<VP8QuantizeParam> {121 public ::testing::TestWithParam<VP8QuantizeParam>,
122 public AbstractBench {
121 protected:123 protected:
122 virtual void SetUp() {124 virtual void SetUp() {
123 SetupCompressor();125 SetupCompressor();
@@ -125,6 +127,10 @@ class QuantizeTest : public QuantizeTestBase, · 1 unmodified line
125 c_quant_ = GET_PARAM(1);127 c_quant_ = GET_PARAM(1);
126 }128 }
127 129
130 virtual void Run() {
131 asm_quant_(&vp8_comp_->mb.block[0], &macroblockd_dst_->block[0]);
132 }
133
128 void RunComparison() {134 void RunComparison() {
129 for (int i = 0; i < kNumBlocks; ++i) {135 for (int i = 0; i < kNumBlocks; ++i) {
130 ASM_REGISTER_STATE_CHECK(136 ASM_REGISTER_STATE_CHECK(
@@ -167,6 +173,13 @@ TEST_P(QuantizeTest, TestMultipleQ) { · 36 unmodified lines
167 }173 }
168}174}
169 175
176TEST_P(QuantizeTest, DISABLED_Speed) {
177 FillCoeffRandom();
178
179 RunNTimes(10000000);
180 PrintMedian("vp8 quantize");
181}
182
170#if HAVE_SSE2183#if HAVE_SSE2
171INSTANTIATE_TEST_CASE_P(184INSTANTIATE_TEST_CASE_P(
172 SSE2, QuantizeTest,185 SSE2, QuantizeTest,
vp8/encoder/x86/quantize_sse4.c+8−17
@@ -11,8 +11,8 @@ · 10 unmodified lines
11#include <smmintrin.h> /* SSE4.1 */11#include <smmintrin.h> /* SSE4.1 */
12 12
13#include "./vp8_rtcd.h"13#include "./vp8_rtcd.h"
14#include "vp8/encoder/block.h"
15#include "vp8/common/entropy.h" /* vp8_default_inv_zig_zag */14#include "vp8/common/entropy.h" /* vp8_default_inv_zig_zag */
15#include "vp8/encoder/block.h"
16 16
17#define SELECT_EOB(i, z, x, y, q) \17#define SELECT_EOB(i, z, x, y, q) \
18 do { \18 do { \
@@ -31,8 +31,7 @@ void vp8_regular_quantize_b_sse4_1(BLOCK *b, BLOCKD *d) { · 12 unmodified lines
31 char eob = 0;31 char eob = 0;
32 short *zbin_boost_ptr = b->zrun_zbin_boost;32 short *zbin_boost_ptr = b->zrun_zbin_boost;
33 33
34 __m128i sz0, x0, sz1, x1, y0, y1, x_minus_zbin0, x_minus_zbin1, dqcoeff0,34 __m128i x0, x1, y0, y1, x_minus_zbin0, x_minus_zbin1, dqcoeff0, dqcoeff1;
35 dqcoeff1;
36 __m128i quant_shift0 = _mm_load_si128((__m128i *)(b->quant_shift));35 __m128i quant_shift0 = _mm_load_si128((__m128i *)(b->quant_shift));
37 __m128i quant_shift1 = _mm_load_si128((__m128i *)(b->quant_shift + 8));36 __m128i quant_shift1 = _mm_load_si128((__m128i *)(b->quant_shift + 8));
38 __m128i z0 = _mm_load_si128((__m128i *)(b->coeff));37 __m128i z0 = _mm_load_si128((__m128i *)(b->coeff));
@@ -53,15 +52,9 @@ void vp8_regular_quantize_b_sse4_1(BLOCK *b, BLOCKD *d) { · 14 unmodified lines
53 zbin_extra = _mm_shufflelo_epi16(zbin_extra, 0);52 zbin_extra = _mm_shufflelo_epi16(zbin_extra, 0);
54 zbin_extra = _mm_unpacklo_epi16(zbin_extra, zbin_extra);53 zbin_extra = _mm_unpacklo_epi16(zbin_extra, zbin_extra);
55 54
56 /* Sign of z: z >> 15 */55 /* x = abs(z) */
57 sz0 = _mm_srai_epi16(z0, 15);56 x0 = _mm_abs_epi16(z0);
58 sz1 = _mm_srai_epi16(z1, 15);57 x1 = _mm_abs_epi16(z1);
59
60 /* x = abs(z): (z ^ sz) - sz */
61 x0 = _mm_xor_si128(z0, sz0);
62 x1 = _mm_xor_si128(z1, sz1);
63 x0 = _mm_sub_epi16(x0, sz0);
64 x1 = _mm_sub_epi16(x1, sz1);
65 58
66 /* zbin[] + zbin_extra */59 /* zbin[] + zbin_extra */
67 zbin0 = _mm_add_epi16(zbin0, zbin_extra);60 zbin0 = _mm_add_epi16(zbin0, zbin_extra);
@@ -89,11 +82,9 @@ void vp8_regular_quantize_b_sse4_1(BLOCK *b, BLOCKD *d) { · 21 unmodified lines
89 y0 = _mm_mulhi_epi16(y0, quant_shift0);82 y0 = _mm_mulhi_epi16(y0, quant_shift0);
90 y1 = _mm_mulhi_epi16(y1, quant_shift1);83 y1 = _mm_mulhi_epi16(y1, quant_shift1);
91 84
92 /* Return the sign: (y ^ sz) - sz */85 /* Restore the sign. */
93 y0 = _mm_xor_si128(y0, sz0);86 y0 = _mm_sign_epi16(y0, z0);
94 y1 = _mm_xor_si128(y1, sz1);87 y1 = _mm_sign_epi16(y1, z1);
95 y0 = _mm_sub_epi16(y0, sz0);
96 y1 = _mm_sub_epi16(y1, sz1);
97 88
98 /* The loop gets unrolled anyway. Avoid the vp8_default_zig_zag1d lookup. */89 /* The loop gets unrolled anyway. Avoid the vp8_default_zig_zag1d lookup. */
99 SELECT_EOB(1, 0, x_minus_zbin0, y0, qcoeff0);90 SELECT_EOB(1, 0, x_minus_zbin0, y0, qcoeff0);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t