/src/libvpx/vpx_dsp/x86/quantize_sse2.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2015 The WebM project authors. All Rights Reserved. |
3 | | * |
4 | | * Use of this source code is governed by a BSD-style license |
5 | | * that can be found in the LICENSE file in the root of the source |
6 | | * tree. An additional intellectual property rights grant can be found |
7 | | * in the file PATENTS. All contributing project authors may |
8 | | * be found in the AUTHORS file in the root of the source tree. |
9 | | */ |
10 | | |
11 | | #include <assert.h> |
12 | | #include <emmintrin.h> |
13 | | #include <xmmintrin.h> |
14 | | |
15 | | #include "./vpx_dsp_rtcd.h" |
16 | | #include "vpx/vpx_integer.h" |
17 | | #include "vpx_dsp/x86/bitdepth_conversion_sse2.h" |
18 | | #include "vpx_dsp/x86/quantize_sse2.h" |
19 | | #include "vp9/common/vp9_scan.h" |
20 | | |
21 | | void vpx_quantize_b_sse2(const tran_low_t *coeff_ptr, intptr_t n_coeffs, |
22 | | const struct macroblock_plane *const mb_plane, |
23 | | tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, |
24 | | const int16_t *dequant_ptr, uint16_t *eob_ptr, |
25 | 0 | const struct ScanOrder *const scan_order) { |
26 | 0 | const __m128i zero = _mm_setzero_si128(); |
27 | 0 | int index = 16; |
28 | 0 | const int16_t *iscan = scan_order->iscan; |
29 | |
|
30 | 0 | __m128i zbin, round, quant, dequant, shift; |
31 | 0 | __m128i coeff0, coeff1, coeff0_sign, coeff1_sign; |
32 | 0 | __m128i qcoeff0, qcoeff1; |
33 | 0 | __m128i cmp_mask0, cmp_mask1; |
34 | 0 | __m128i eob, eob0; |
35 | | |
36 | | // Setup global values. |
37 | 0 | load_b_values(mb_plane, &zbin, &round, &quant, dequant_ptr, &dequant, &shift); |
38 | | |
39 | | // Do DC and first 15 AC. |
40 | 0 | coeff0 = load_tran_low(coeff_ptr); |
41 | 0 | coeff1 = load_tran_low(coeff_ptr + 8); |
42 | | |
43 | | // Poor man's abs(). |
44 | 0 | coeff0_sign = _mm_srai_epi16(coeff0, 15); |
45 | 0 | coeff1_sign = _mm_srai_epi16(coeff1, 15); |
46 | 0 | qcoeff0 = invert_sign_sse2(coeff0, coeff0_sign); |
47 | 0 | qcoeff1 = invert_sign_sse2(coeff1, coeff1_sign); |
48 | |
|
49 | 0 | cmp_mask0 = _mm_cmpgt_epi16(qcoeff0, zbin); |
50 | 0 | zbin = _mm_unpackhi_epi64(zbin, zbin); // Switch DC to AC |
51 | 0 | cmp_mask1 = _mm_cmpgt_epi16(qcoeff1, zbin); |
52 | |
|
53 | 0 | calculate_qcoeff(&qcoeff0, round, quant, shift); |
54 | |
|
55 | 0 | round = _mm_unpackhi_epi64(round, round); |
56 | 0 | quant = _mm_unpackhi_epi64(quant, quant); |
57 | 0 | shift = _mm_unpackhi_epi64(shift, shift); |
58 | |
|
59 | 0 | calculate_qcoeff(&qcoeff1, round, quant, shift); |
60 | | |
61 | | // Reinsert signs |
62 | 0 | qcoeff0 = invert_sign_sse2(qcoeff0, coeff0_sign); |
63 | 0 | qcoeff1 = invert_sign_sse2(qcoeff1, coeff1_sign); |
64 | | |
65 | | // Mask out zbin threshold coeffs |
66 | 0 | qcoeff0 = _mm_and_si128(qcoeff0, cmp_mask0); |
67 | 0 | qcoeff1 = _mm_and_si128(qcoeff1, cmp_mask1); |
68 | |
|
69 | 0 | store_tran_low(qcoeff0, qcoeff_ptr); |
70 | 0 | store_tran_low(qcoeff1, qcoeff_ptr + 8); |
71 | |
|
72 | 0 | calculate_dqcoeff_and_store(qcoeff0, dequant, dqcoeff_ptr); |
73 | 0 | dequant = _mm_unpackhi_epi64(dequant, dequant); |
74 | 0 | calculate_dqcoeff_and_store(qcoeff1, dequant, dqcoeff_ptr + 8); |
75 | |
|
76 | 0 | eob = scan_for_eob(&qcoeff0, &qcoeff1, iscan, 0, zero); |
77 | | |
78 | | // AC only loop. |
79 | 0 | while (index < n_coeffs) { |
80 | 0 | coeff0 = load_tran_low(coeff_ptr + index); |
81 | 0 | coeff1 = load_tran_low(coeff_ptr + index + 8); |
82 | |
|
83 | 0 | coeff0_sign = _mm_srai_epi16(coeff0, 15); |
84 | 0 | coeff1_sign = _mm_srai_epi16(coeff1, 15); |
85 | 0 | qcoeff0 = invert_sign_sse2(coeff0, coeff0_sign); |
86 | 0 | qcoeff1 = invert_sign_sse2(coeff1, coeff1_sign); |
87 | |
|
88 | 0 | cmp_mask0 = _mm_cmpgt_epi16(qcoeff0, zbin); |
89 | 0 | cmp_mask1 = _mm_cmpgt_epi16(qcoeff1, zbin); |
90 | |
|
91 | 0 | calculate_qcoeff(&qcoeff0, round, quant, shift); |
92 | 0 | calculate_qcoeff(&qcoeff1, round, quant, shift); |
93 | |
|
94 | 0 | qcoeff0 = invert_sign_sse2(qcoeff0, coeff0_sign); |
95 | 0 | qcoeff1 = invert_sign_sse2(qcoeff1, coeff1_sign); |
96 | |
|
97 | 0 | qcoeff0 = _mm_and_si128(qcoeff0, cmp_mask0); |
98 | 0 | qcoeff1 = _mm_and_si128(qcoeff1, cmp_mask1); |
99 | |
|
100 | 0 | store_tran_low(qcoeff0, qcoeff_ptr + index); |
101 | 0 | store_tran_low(qcoeff1, qcoeff_ptr + index + 8); |
102 | |
|
103 | 0 | calculate_dqcoeff_and_store(qcoeff0, dequant, dqcoeff_ptr + index); |
104 | 0 | calculate_dqcoeff_and_store(qcoeff1, dequant, dqcoeff_ptr + index + 8); |
105 | |
|
106 | 0 | eob0 = scan_for_eob(&qcoeff0, &qcoeff1, iscan, index, zero); |
107 | 0 | eob = _mm_max_epi16(eob, eob0); |
108 | |
|
109 | 0 | index += 16; |
110 | 0 | } |
111 | |
|
112 | 0 | *eob_ptr = accumulate_eob(eob); |
113 | 0 | } |