Coverage Report

Created: 2024-09-06 07:53

/src/libvpx/vp9/encoder/x86/vp9_quantize_ssse3.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 *  Copyright (c) 2022 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 <tmmintrin.h>
13
14
#include "./vp9_rtcd.h"
15
#include "vpx/vpx_integer.h"
16
#include "vpx_dsp/vpx_dsp_common.h"
17
#include "vpx_dsp/x86/bitdepth_conversion_sse2.h"
18
#include "vpx_dsp/x86/quantize_sse2.h"
19
#include "vpx_dsp/x86/quantize_ssse3.h"
20
#include "vp9/common/vp9_scan.h"
21
#include "vp9/encoder/vp9_block.h"
22
23
void vp9_quantize_fp_ssse3(const tran_low_t *coeff_ptr, intptr_t n_coeffs,
24
                           const struct macroblock_plane *const mb_plane,
25
                           tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr,
26
                           const int16_t *dequant_ptr, uint16_t *eob_ptr,
27
0
                           const struct ScanOrder *const scan_order) {
28
0
  const __m128i zero = _mm_setzero_si128();
29
0
  __m128i thr;
30
0
  int nzflag;
31
0
  int index = 16;
32
0
  __m128i round, quant, dequant;
33
0
  __m128i coeff0, coeff1;
34
0
  __m128i qcoeff0, qcoeff1;
35
0
  __m128i eob;
36
0
  const int16_t *iscan = scan_order->iscan;
37
38
  // Setup global values.
39
0
  load_fp_values(mb_plane, &round, &quant, dequant_ptr, &dequant);
40
41
  // Do DC and first 15 AC.
42
0
  coeff0 = load_tran_low(coeff_ptr);
43
0
  coeff1 = load_tran_low(coeff_ptr + 8);
44
45
0
  qcoeff0 = _mm_abs_epi16(coeff0);
46
0
  qcoeff1 = _mm_abs_epi16(coeff1);
47
48
0
  qcoeff0 = _mm_adds_epi16(qcoeff0, round);
49
0
  qcoeff0 = _mm_mulhi_epi16(qcoeff0, quant);
50
51
0
  round = _mm_unpackhi_epi64(round, round);
52
0
  quant = _mm_unpackhi_epi64(quant, quant);
53
54
0
  qcoeff1 = _mm_adds_epi16(qcoeff1, round);
55
0
  qcoeff1 = _mm_mulhi_epi16(qcoeff1, quant);
56
57
  // Reinsert signs.
58
0
  qcoeff0 = _mm_sign_epi16(qcoeff0, coeff0);
59
0
  qcoeff1 = _mm_sign_epi16(qcoeff1, coeff1);
60
61
0
  store_tran_low(qcoeff0, qcoeff_ptr);
62
0
  store_tran_low(qcoeff1, qcoeff_ptr + 8);
63
64
0
  qcoeff0 = _mm_mullo_epi16(qcoeff0, dequant);
65
0
  dequant = _mm_unpackhi_epi64(dequant, dequant);
66
0
  qcoeff1 = _mm_mullo_epi16(qcoeff1, dequant);
67
68
0
  store_tran_low(qcoeff0, dqcoeff_ptr);
69
0
  store_tran_low(qcoeff1, dqcoeff_ptr + 8);
70
71
0
  eob = scan_for_eob(&qcoeff0, &qcoeff1, iscan, 0, zero);
72
73
0
  thr = _mm_srai_epi16(dequant, 1);
74
75
  // AC only loop.
76
0
  while (index < n_coeffs) {
77
0
    coeff0 = load_tran_low(coeff_ptr + index);
78
0
    coeff1 = load_tran_low(coeff_ptr + index + 8);
79
80
0
    qcoeff0 = _mm_abs_epi16(coeff0);
81
0
    qcoeff1 = _mm_abs_epi16(coeff1);
82
83
0
    nzflag = _mm_movemask_epi8(_mm_cmpgt_epi16(qcoeff0, thr)) |
84
0
             _mm_movemask_epi8(_mm_cmpgt_epi16(qcoeff1, thr));
85
86
0
    if (nzflag) {
87
0
      __m128i eob0;
88
0
      qcoeff0 = _mm_adds_epi16(qcoeff0, round);
89
0
      qcoeff1 = _mm_adds_epi16(qcoeff1, round);
90
0
      qcoeff0 = _mm_mulhi_epi16(qcoeff0, quant);
91
0
      qcoeff1 = _mm_mulhi_epi16(qcoeff1, quant);
92
93
      // Reinsert signs.
94
0
      qcoeff0 = _mm_sign_epi16(qcoeff0, coeff0);
95
0
      qcoeff1 = _mm_sign_epi16(qcoeff1, coeff1);
96
97
0
      store_tran_low(qcoeff0, qcoeff_ptr + index);
98
0
      store_tran_low(qcoeff1, qcoeff_ptr + index + 8);
99
100
0
      qcoeff0 = _mm_mullo_epi16(qcoeff0, dequant);
101
0
      qcoeff1 = _mm_mullo_epi16(qcoeff1, dequant);
102
103
0
      store_tran_low(qcoeff0, dqcoeff_ptr + index);
104
0
      store_tran_low(qcoeff1, 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
0
    } else {
109
0
      store_zero_tran_low(qcoeff_ptr + index);
110
0
      store_zero_tran_low(qcoeff_ptr + index + 8);
111
112
0
      store_zero_tran_low(dqcoeff_ptr + index);
113
0
      store_zero_tran_low(dqcoeff_ptr + index + 8);
114
0
    }
115
116
0
    index += 16;
117
0
  }
118
119
0
  *eob_ptr = accumulate_eob(eob);
120
0
}
121
122
void vp9_quantize_fp_32x32_ssse3(const tran_low_t *coeff_ptr, intptr_t n_coeffs,
123
                                 const struct macroblock_plane *const mb_plane,
124
                                 tran_low_t *qcoeff_ptr,
125
                                 tran_low_t *dqcoeff_ptr,
126
                                 const int16_t *dequant_ptr, uint16_t *eob_ptr,
127
0
                                 const struct ScanOrder *const scan_order) {
128
0
  const __m128i zero = _mm_setzero_si128();
129
0
  const __m128i one_s16 = _mm_set1_epi16(1);
130
0
  __m128i thr;
131
0
  int nzflag;
132
0
  int index = 16;
133
0
  __m128i round, quant, dequant;
134
0
  __m128i coeff0, coeff1;
135
0
  __m128i qcoeff0, qcoeff1;
136
0
  __m128i eob;
137
0
  const int16_t *iscan = scan_order->iscan;
138
139
  // Setup global values.
140
0
  load_fp_values(mb_plane, &round, &quant, dequant_ptr, &dequant);
141
  // The 32x32 halves round.
142
0
  round = _mm_add_epi16(round, one_s16);
143
0
  round = _mm_srli_epi16(round, 1);
144
145
  // The 16x16 shifts by 16, the 32x32 shifts by 15. We want to use pmulhw so
146
  // upshift quant to account for this.
147
0
  quant = _mm_slli_epi16(quant, 1);
148
149
  // Do DC and first 15 AC.
150
0
  coeff0 = load_tran_low(coeff_ptr);
151
0
  coeff1 = load_tran_low(coeff_ptr + 8);
152
153
0
  qcoeff0 = _mm_abs_epi16(coeff0);
154
0
  qcoeff1 = _mm_abs_epi16(coeff1);
155
156
0
  qcoeff0 = _mm_adds_epi16(qcoeff0, round);
157
0
  qcoeff0 = _mm_mulhi_epi16(qcoeff0, quant);
158
159
0
  round = _mm_unpackhi_epi64(round, round);
160
0
  quant = _mm_unpackhi_epi64(quant, quant);
161
162
0
  qcoeff1 = _mm_adds_epi16(qcoeff1, round);
163
0
  qcoeff1 = _mm_mulhi_epi16(qcoeff1, quant);
164
165
  // Reinsert signs.
166
0
  qcoeff0 = _mm_sign_epi16(qcoeff0, coeff0);
167
0
  qcoeff1 = _mm_sign_epi16(qcoeff1, coeff1);
168
169
0
  store_tran_low(qcoeff0, qcoeff_ptr);
170
0
  store_tran_low(qcoeff1, qcoeff_ptr + 8);
171
172
  // Get the abs value of qcoeff again so we can use shifts for division.
173
0
  qcoeff0 = _mm_abs_epi16(qcoeff0);
174
0
  qcoeff1 = _mm_abs_epi16(qcoeff1);
175
176
0
  qcoeff0 = _mm_mullo_epi16(qcoeff0, dequant);
177
0
  dequant = _mm_unpackhi_epi64(dequant, dequant);
178
0
  qcoeff1 = _mm_mullo_epi16(qcoeff1, dequant);
179
180
  // Divide by 2.
181
0
  qcoeff0 = _mm_srli_epi16(qcoeff0, 1);
182
0
  qcoeff1 = _mm_srli_epi16(qcoeff1, 1);
183
184
  // Reinsert signs.
185
0
  qcoeff0 = _mm_sign_epi16(qcoeff0, coeff0);
186
0
  qcoeff1 = _mm_sign_epi16(qcoeff1, coeff1);
187
188
0
  store_tran_low(qcoeff0, dqcoeff_ptr);
189
0
  store_tran_low(qcoeff1, dqcoeff_ptr + 8);
190
191
0
  eob = scan_for_eob(&qcoeff0, &qcoeff1, iscan, 0, zero);
192
193
0
  thr = _mm_srai_epi16(dequant, 2);
194
195
  // AC only loop.
196
0
  while (index < n_coeffs) {
197
0
    coeff0 = load_tran_low(coeff_ptr + index);
198
0
    coeff1 = load_tran_low(coeff_ptr + index + 8);
199
200
0
    qcoeff0 = _mm_abs_epi16(coeff0);
201
0
    qcoeff1 = _mm_abs_epi16(coeff1);
202
203
0
    nzflag = _mm_movemask_epi8(_mm_cmpgt_epi16(qcoeff0, thr)) |
204
0
             _mm_movemask_epi8(_mm_cmpgt_epi16(qcoeff1, thr));
205
206
0
    if (nzflag) {
207
0
      qcoeff0 = _mm_adds_epi16(qcoeff0, round);
208
0
      qcoeff1 = _mm_adds_epi16(qcoeff1, round);
209
0
      qcoeff0 = _mm_mulhi_epi16(qcoeff0, quant);
210
0
      qcoeff1 = _mm_mulhi_epi16(qcoeff1, quant);
211
212
      // Reinsert signs.
213
0
      qcoeff0 = _mm_sign_epi16(qcoeff0, coeff0);
214
0
      qcoeff1 = _mm_sign_epi16(qcoeff1, coeff1);
215
216
0
      store_tran_low(qcoeff0, qcoeff_ptr + index);
217
0
      store_tran_low(qcoeff1, qcoeff_ptr + index + 8);
218
219
      // Get the abs value of qcoeff again so we can use shifts for division.
220
0
      qcoeff0 = _mm_abs_epi16(qcoeff0);
221
0
      qcoeff1 = _mm_abs_epi16(qcoeff1);
222
223
0
      qcoeff0 = _mm_mullo_epi16(qcoeff0, dequant);
224
0
      qcoeff1 = _mm_mullo_epi16(qcoeff1, dequant);
225
226
      // Divide by 2.
227
0
      qcoeff0 = _mm_srli_epi16(qcoeff0, 1);
228
0
      qcoeff1 = _mm_srli_epi16(qcoeff1, 1);
229
230
      // Reinsert signs.
231
0
      qcoeff0 = _mm_sign_epi16(qcoeff0, coeff0);
232
0
      qcoeff1 = _mm_sign_epi16(qcoeff1, coeff1);
233
234
0
      store_tran_low(qcoeff0, dqcoeff_ptr + index);
235
0
      store_tran_low(qcoeff1, dqcoeff_ptr + index + 8);
236
0
    } else {
237
0
      store_zero_tran_low(qcoeff_ptr + index);
238
0
      store_zero_tran_low(qcoeff_ptr + index + 8);
239
240
0
      store_zero_tran_low(dqcoeff_ptr + index);
241
0
      store_zero_tran_low(dqcoeff_ptr + index + 8);
242
0
    }
243
244
0
    if (nzflag) {
245
0
      const __m128i eob0 = scan_for_eob(&qcoeff0, &qcoeff1, iscan, index, zero);
246
0
      eob = _mm_max_epi16(eob, eob0);
247
0
    }
248
0
    index += 16;
249
0
  }
250
251
0
  *eob_ptr = accumulate_eob(eob);
252
0
}