1 /*
2 * Copyright (c) 2022, Alliance for Open Media. All rights reserved
3 *
4 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10 */
11
12 #include <arm_neon.h>
13 #include <assert.h>
14
15 #include "aom_dsp/quantize.h"
16 #include "aom_dsp/arm/mem_neon.h"
17
18 #include "av1/common/quant_common.h"
19 #include "av1/encoder/av1_quantize.h"
20
sum_abs_coeff(const uint32x4_t a)21 static INLINE uint32_t sum_abs_coeff(const uint32x4_t a) {
22 #if defined(__aarch64__)
23 return vaddvq_u32(a);
24 #else
25 const uint64x2_t b = vpaddlq_u32(a);
26 const uint64x1_t c = vadd_u64(vget_low_u64(b), vget_high_u64(b));
27 return (uint32_t)vget_lane_u64(c, 0);
28 #endif
29 }
30
31 static INLINE uint16x4_t
quantize_4(const tran_low_t * coeff_ptr,tran_low_t * qcoeff_ptr,tran_low_t * dqcoeff_ptr,int32x4_t v_quant_s32,int32x4_t v_dequant_s32,int32x4_t v_round_s32,int32x4_t v_zbin_s32,int32x4_t v_quant_shift_s32,int log_scale)32 quantize_4(const tran_low_t *coeff_ptr, tran_low_t *qcoeff_ptr,
33 tran_low_t *dqcoeff_ptr, int32x4_t v_quant_s32,
34 int32x4_t v_dequant_s32, int32x4_t v_round_s32, int32x4_t v_zbin_s32,
35 int32x4_t v_quant_shift_s32, int log_scale) {
36 const int32x4_t v_coeff = vld1q_s32(coeff_ptr);
37 const int32x4_t v_coeff_sign =
38 vreinterpretq_s32_u32(vcltq_s32(v_coeff, vdupq_n_s32(0)));
39 const int32x4_t v_abs_coeff = vabsq_s32(v_coeff);
40 // if (abs_coeff < zbins[rc != 0]),
41 const uint32x4_t v_zbin_mask = vcgeq_s32(v_abs_coeff, v_zbin_s32);
42 const int32x4_t v_log_scale = vdupq_n_s32(log_scale);
43 // const int64_t tmp = (int64_t)abs_coeff + log_scaled_round;
44 const int32x4_t v_tmp = vaddq_s32(v_abs_coeff, v_round_s32);
45 // const int32_t tmpw32 = tmp * wt;
46 const int32x4_t v_tmpw32 = vmulq_s32(v_tmp, vdupq_n_s32((1 << AOM_QM_BITS)));
47 // const int32_t tmp2 = (int32_t)((tmpw32 * quant64) >> 16);
48 const int32x4_t v_tmp2 = vqdmulhq_s32(v_tmpw32, v_quant_s32);
49 // const int32_t tmp3 =
50 // ((((tmp2 + tmpw32)<< log_scale) * (int64_t)(quant_shift << 15)) >> 32);
51 const int32x4_t v_tmp3 = vqdmulhq_s32(
52 vshlq_s32(vaddq_s32(v_tmp2, v_tmpw32), v_log_scale), v_quant_shift_s32);
53 // const int abs_qcoeff = vmask ? (int)tmp3 >> AOM_QM_BITS : 0;
54 const int32x4_t v_abs_qcoeff = vandq_s32(vreinterpretq_s32_u32(v_zbin_mask),
55 vshrq_n_s32(v_tmp3, AOM_QM_BITS));
56 // const tran_low_t abs_dqcoeff = (abs_qcoeff * dequant_iwt) >> log_scale;
57 // vshlq_s32 will shift right if shift value is negative.
58 const int32x4_t v_abs_dqcoeff =
59 vshlq_s32(vmulq_s32(v_abs_qcoeff, v_dequant_s32), vnegq_s32(v_log_scale));
60 // qcoeff_ptr[rc] = (tran_low_t)((abs_qcoeff ^ coeff_sign) - coeff_sign);
61 const int32x4_t v_qcoeff =
62 vsubq_s32(veorq_s32(v_abs_qcoeff, v_coeff_sign), v_coeff_sign);
63 // dqcoeff_ptr[rc] = (tran_low_t)((abs_dqcoeff ^ coeff_sign) - coeff_sign);
64 const int32x4_t v_dqcoeff =
65 vsubq_s32(veorq_s32(v_abs_dqcoeff, v_coeff_sign), v_coeff_sign);
66
67 vst1q_s32(qcoeff_ptr, v_qcoeff);
68 vst1q_s32(dqcoeff_ptr, v_dqcoeff);
69
70 // Used to find eob.
71 const uint32x4_t nz_qcoeff_mask = vcgtq_s32(v_abs_qcoeff, vdupq_n_s32(0));
72 return vmovn_u32(nz_qcoeff_mask);
73 }
74
get_max_lane_eob(const int16_t * iscan,int16x8_t v_eobmax,uint16x8_t v_mask)75 static INLINE int16x8_t get_max_lane_eob(const int16_t *iscan,
76 int16x8_t v_eobmax,
77 uint16x8_t v_mask) {
78 const int16x8_t v_iscan = vld1q_s16(&iscan[0]);
79 const int16x8_t v_iscan_plus1 = vaddq_s16(v_iscan, vdupq_n_s16(1));
80 const int16x8_t v_nz_iscan = vbslq_s16(v_mask, v_iscan_plus1, vdupq_n_s16(0));
81 return vmaxq_s16(v_eobmax, v_nz_iscan);
82 }
83
get_min_max_lane_eob(const int16_t * iscan,int16x8_t * v_eobmin,int16x8_t * v_eobmax,uint16x8_t v_mask,intptr_t n_coeffs)84 static INLINE void get_min_max_lane_eob(const int16_t *iscan,
85 int16x8_t *v_eobmin,
86 int16x8_t *v_eobmax, uint16x8_t v_mask,
87 intptr_t n_coeffs) {
88 const int16x8_t v_iscan = vld1q_s16(&iscan[0]);
89 const int16x8_t v_nz_iscan_max = vbslq_s16(v_mask, v_iscan, vdupq_n_s16(-1));
90 #if SKIP_EOB_FACTOR_ADJUST
91 const int16x8_t v_nz_iscan_min =
92 vbslq_s16(v_mask, v_iscan, vdupq_n_s16(n_coeffs));
93 *v_eobmin = vminq_s16(*v_eobmin, v_nz_iscan_min);
94 #else
95 (void)v_eobmin;
96 #endif
97 *v_eobmax = vmaxq_s16(*v_eobmax, v_nz_iscan_max);
98 }
99
get_max_eob(int16x8_t v_eobmax)100 static INLINE uint16_t get_max_eob(int16x8_t v_eobmax) {
101 #ifdef __aarch64__
102 return (uint16_t)vmaxvq_s16(v_eobmax);
103 #else
104 const int16x4_t v_eobmax_3210 =
105 vmax_s16(vget_low_s16(v_eobmax), vget_high_s16(v_eobmax));
106 const int64x1_t v_eobmax_xx32 =
107 vshr_n_s64(vreinterpret_s64_s16(v_eobmax_3210), 32);
108 const int16x4_t v_eobmax_tmp =
109 vmax_s16(v_eobmax_3210, vreinterpret_s16_s64(v_eobmax_xx32));
110 const int64x1_t v_eobmax_xxx3 =
111 vshr_n_s64(vreinterpret_s64_s16(v_eobmax_tmp), 16);
112 const int16x4_t v_eobmax_final =
113 vmax_s16(v_eobmax_tmp, vreinterpret_s16_s64(v_eobmax_xxx3));
114 return (uint16_t)vget_lane_s16(v_eobmax_final, 0);
115 #endif
116 }
117
get_min_eob(int16x8_t v_eobmin)118 static INLINE uint16_t get_min_eob(int16x8_t v_eobmin) {
119 #ifdef __aarch64__
120 return (uint16_t)vminvq_s16(v_eobmin);
121 #else
122 const int16x4_t v_eobmin_3210 =
123 vmin_s16(vget_low_s16(v_eobmin), vget_high_s16(v_eobmin));
124 const int64x1_t v_eobmin_xx32 =
125 vshr_n_s64(vreinterpret_s64_s16(v_eobmin_3210), 32);
126 const int16x4_t v_eobmin_tmp =
127 vmin_s16(v_eobmin_3210, vreinterpret_s16_s64(v_eobmin_xx32));
128 const int64x1_t v_eobmin_xxx3 =
129 vshr_n_s64(vreinterpret_s64_s16(v_eobmin_tmp), 16);
130 const int16x4_t v_eobmin_final =
131 vmin_s16(v_eobmin_tmp, vreinterpret_s16_s64(v_eobmin_xxx3));
132 return (uint16_t)vget_lane_s16(v_eobmin_final, 0);
133 #endif
134 }
135
highbd_quantize_b_neon(const tran_low_t * coeff_ptr,intptr_t n_coeffs,const int16_t * zbin_ptr,const int16_t * round_ptr,const int16_t * quant_ptr,const int16_t * quant_shift_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,const int log_scale)136 static void highbd_quantize_b_neon(
137 const tran_low_t *coeff_ptr, intptr_t n_coeffs, const int16_t *zbin_ptr,
138 const int16_t *round_ptr, const int16_t *quant_ptr,
139 const int16_t *quant_shift_ptr, tran_low_t *qcoeff_ptr,
140 tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr,
141 const int16_t *scan, const int16_t *iscan, const int log_scale) {
142 (void)scan;
143 const int16x4_t v_quant = vld1_s16(quant_ptr);
144 const int16x4_t v_dequant = vld1_s16(dequant_ptr);
145 const int16x4_t v_zero = vdup_n_s16(0);
146 const uint16x4_t v_round_select = vcgt_s16(vdup_n_s16(log_scale), v_zero);
147 const int16x4_t v_round_no_scale = vld1_s16(round_ptr);
148 const int16x4_t v_round_log_scale =
149 vqrdmulh_n_s16(v_round_no_scale, (int16_t)(1 << (15 - log_scale)));
150 const int16x4_t v_round =
151 vbsl_s16(v_round_select, v_round_log_scale, v_round_no_scale);
152 const int16x4_t v_quant_shift = vld1_s16(quant_shift_ptr);
153 const int16x4_t v_zbin_no_scale = vld1_s16(zbin_ptr);
154 const int16x4_t v_zbin_log_scale =
155 vqrdmulh_n_s16(v_zbin_no_scale, (int16_t)(1 << (15 - log_scale)));
156 const int16x4_t v_zbin =
157 vbsl_s16(v_round_select, v_zbin_log_scale, v_zbin_no_scale);
158 int32x4_t v_round_s32 = vmovl_s16(v_round);
159 int32x4_t v_quant_s32 = vshlq_n_s32(vmovl_s16(v_quant), 15);
160 int32x4_t v_dequant_s32 = vmovl_s16(v_dequant);
161 int32x4_t v_quant_shift_s32 = vshlq_n_s32(vmovl_s16(v_quant_shift), 15);
162 int32x4_t v_zbin_s32 = vmovl_s16(v_zbin);
163 uint16x4_t v_mask_lo, v_mask_hi;
164 int16x8_t v_eobmax = vdupq_n_s16(-1);
165
166 intptr_t non_zero_count = n_coeffs;
167
168 assert(n_coeffs > 8);
169 // Pre-scan pass
170 const int32x4_t v_zbin_s32x = vdupq_lane_s32(vget_low_s32(v_zbin_s32), 1);
171 intptr_t i = n_coeffs;
172 do {
173 const int32x4_t v_coeff_a = vld1q_s32(coeff_ptr + i - 4);
174 const int32x4_t v_coeff_b = vld1q_s32(coeff_ptr + i - 8);
175 const int32x4_t v_abs_coeff_a = vabsq_s32(v_coeff_a);
176 const int32x4_t v_abs_coeff_b = vabsq_s32(v_coeff_b);
177 const uint32x4_t v_mask_a = vcgeq_s32(v_abs_coeff_a, v_zbin_s32x);
178 const uint32x4_t v_mask_b = vcgeq_s32(v_abs_coeff_b, v_zbin_s32x);
179 // If the coefficient is in the base ZBIN range, then discard.
180 if (sum_abs_coeff(v_mask_a) + sum_abs_coeff(v_mask_b) == 0) {
181 non_zero_count -= 8;
182 } else {
183 break;
184 }
185 i -= 8;
186 } while (i > 0);
187
188 const intptr_t remaining_zcoeffs = n_coeffs - non_zero_count;
189 memset(qcoeff_ptr + non_zero_count, 0,
190 remaining_zcoeffs * sizeof(*qcoeff_ptr));
191 memset(dqcoeff_ptr + non_zero_count, 0,
192 remaining_zcoeffs * sizeof(*dqcoeff_ptr));
193
194 // DC and first 3 AC
195 v_mask_lo =
196 quantize_4(coeff_ptr, qcoeff_ptr, dqcoeff_ptr, v_quant_s32, v_dequant_s32,
197 v_round_s32, v_zbin_s32, v_quant_shift_s32, log_scale);
198
199 // overwrite the DC constants with AC constants
200 v_round_s32 = vdupq_lane_s32(vget_low_s32(v_round_s32), 1);
201 v_quant_s32 = vdupq_lane_s32(vget_low_s32(v_quant_s32), 1);
202 v_dequant_s32 = vdupq_lane_s32(vget_low_s32(v_dequant_s32), 1);
203 v_quant_shift_s32 = vdupq_lane_s32(vget_low_s32(v_quant_shift_s32), 1);
204 v_zbin_s32 = vdupq_lane_s32(vget_low_s32(v_zbin_s32), 1);
205
206 // 4 more AC
207 v_mask_hi = quantize_4(coeff_ptr + 4, qcoeff_ptr + 4, dqcoeff_ptr + 4,
208 v_quant_s32, v_dequant_s32, v_round_s32, v_zbin_s32,
209 v_quant_shift_s32, log_scale);
210
211 v_eobmax =
212 get_max_lane_eob(iscan, v_eobmax, vcombine_u16(v_mask_lo, v_mask_hi));
213
214 intptr_t count = non_zero_count - 8;
215 for (; count > 0; count -= 8) {
216 coeff_ptr += 8;
217 qcoeff_ptr += 8;
218 dqcoeff_ptr += 8;
219 iscan += 8;
220 v_mask_lo = quantize_4(coeff_ptr, qcoeff_ptr, dqcoeff_ptr, v_quant_s32,
221 v_dequant_s32, v_round_s32, v_zbin_s32,
222 v_quant_shift_s32, log_scale);
223 v_mask_hi = quantize_4(coeff_ptr + 4, qcoeff_ptr + 4, dqcoeff_ptr + 4,
224 v_quant_s32, v_dequant_s32, v_round_s32, v_zbin_s32,
225 v_quant_shift_s32, log_scale);
226 // Find the max lane eob for 8 coeffs.
227 v_eobmax =
228 get_max_lane_eob(iscan, v_eobmax, vcombine_u16(v_mask_lo, v_mask_hi));
229 }
230
231 *eob_ptr = get_max_eob(v_eobmax);
232 }
233
aom_highbd_quantize_b_neon(const tran_low_t * coeff_ptr,intptr_t n_coeffs,const int16_t * zbin_ptr,const int16_t * round_ptr,const int16_t * quant_ptr,const int16_t * quant_shift_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)234 void aom_highbd_quantize_b_neon(const tran_low_t *coeff_ptr, intptr_t n_coeffs,
235 const int16_t *zbin_ptr,
236 const int16_t *round_ptr,
237 const int16_t *quant_ptr,
238 const int16_t *quant_shift_ptr,
239 tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr,
240 const int16_t *dequant_ptr, uint16_t *eob_ptr,
241 const int16_t *scan, const int16_t *iscan) {
242 highbd_quantize_b_neon(coeff_ptr, n_coeffs, zbin_ptr, round_ptr, quant_ptr,
243 quant_shift_ptr, qcoeff_ptr, dqcoeff_ptr, dequant_ptr,
244 eob_ptr, scan, iscan, 0);
245 }
246
aom_highbd_quantize_b_32x32_neon(const tran_low_t * coeff_ptr,intptr_t n_coeffs,const int16_t * zbin_ptr,const int16_t * round_ptr,const int16_t * quant_ptr,const int16_t * quant_shift_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)247 void aom_highbd_quantize_b_32x32_neon(
248 const tran_low_t *coeff_ptr, intptr_t n_coeffs, const int16_t *zbin_ptr,
249 const int16_t *round_ptr, const int16_t *quant_ptr,
250 const int16_t *quant_shift_ptr, tran_low_t *qcoeff_ptr,
251 tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr,
252 const int16_t *scan, const int16_t *iscan) {
253 highbd_quantize_b_neon(coeff_ptr, n_coeffs, zbin_ptr, round_ptr, quant_ptr,
254 quant_shift_ptr, qcoeff_ptr, dqcoeff_ptr, dequant_ptr,
255 eob_ptr, scan, iscan, 1);
256 }
257
aom_highbd_quantize_b_64x64_neon(const tran_low_t * coeff_ptr,intptr_t n_coeffs,const int16_t * zbin_ptr,const int16_t * round_ptr,const int16_t * quant_ptr,const int16_t * quant_shift_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)258 void aom_highbd_quantize_b_64x64_neon(
259 const tran_low_t *coeff_ptr, intptr_t n_coeffs, const int16_t *zbin_ptr,
260 const int16_t *round_ptr, const int16_t *quant_ptr,
261 const int16_t *quant_shift_ptr, tran_low_t *qcoeff_ptr,
262 tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr,
263 const int16_t *scan, const int16_t *iscan) {
264 highbd_quantize_b_neon(coeff_ptr, n_coeffs, zbin_ptr, round_ptr, quant_ptr,
265 quant_shift_ptr, qcoeff_ptr, dqcoeff_ptr, dequant_ptr,
266 eob_ptr, scan, iscan, 2);
267 }
268
269 #if !CONFIG_REALTIME_ONLY
highbd_quantize_b_adaptive_neon(const tran_low_t * coeff_ptr,intptr_t n_coeffs,const int16_t * zbin_ptr,const int16_t * round_ptr,const int16_t * quant_ptr,const int16_t * quant_shift_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,const int log_scale)270 static void highbd_quantize_b_adaptive_neon(
271 const tran_low_t *coeff_ptr, intptr_t n_coeffs, const int16_t *zbin_ptr,
272 const int16_t *round_ptr, const int16_t *quant_ptr,
273 const int16_t *quant_shift_ptr, tran_low_t *qcoeff_ptr,
274 tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr,
275 const int16_t *scan, const int16_t *iscan, const int log_scale) {
276 (void)scan;
277 const int16x4_t v_quant = vld1_s16(quant_ptr);
278 const int16x4_t v_dequant = vld1_s16(dequant_ptr);
279 const int16x4_t v_zero = vdup_n_s16(0);
280 const uint16x4_t v_round_select = vcgt_s16(vdup_n_s16(log_scale), v_zero);
281 const int16x4_t v_round_no_scale = vld1_s16(round_ptr);
282 const int16x4_t v_round_log_scale =
283 vqrdmulh_n_s16(v_round_no_scale, (int16_t)(1 << (15 - log_scale)));
284 const int16x4_t v_round =
285 vbsl_s16(v_round_select, v_round_log_scale, v_round_no_scale);
286 const int16x4_t v_quant_shift = vld1_s16(quant_shift_ptr);
287 const int16x4_t v_zbin_no_scale = vld1_s16(zbin_ptr);
288 const int16x4_t v_zbin_log_scale =
289 vqrdmulh_n_s16(v_zbin_no_scale, (int16_t)(1 << (15 - log_scale)));
290 const int16x4_t v_zbin =
291 vbsl_s16(v_round_select, v_zbin_log_scale, v_zbin_no_scale);
292 int32x4_t v_round_s32 = vmovl_s16(v_round);
293 int32x4_t v_quant_s32 = vshlq_n_s32(vmovl_s16(v_quant), 15);
294 int32x4_t v_dequant_s32 = vmovl_s16(v_dequant);
295 int32x4_t v_quant_shift_s32 = vshlq_n_s32(vmovl_s16(v_quant_shift), 15);
296 int32x4_t v_zbin_s32 = vmovl_s16(v_zbin);
297 uint16x4_t v_mask_lo, v_mask_hi;
298 int16x8_t v_eobmax = vdupq_n_s16(-1);
299 int16x8_t v_eobmin = vdupq_n_s16(n_coeffs);
300
301 assert(n_coeffs > 8);
302 // Pre-scan pass
303 const int32x4_t v_zbin_s32x = vdupq_lane_s32(vget_low_s32(v_zbin_s32), 1);
304 const int prescan_add_1 =
305 ROUND_POWER_OF_TWO(dequant_ptr[1] * EOB_FACTOR, 7 + AOM_QM_BITS);
306 const int32x4_t v_zbin_prescan =
307 vaddq_s32(v_zbin_s32x, vdupq_n_s32(prescan_add_1));
308 intptr_t non_zero_count = n_coeffs;
309 intptr_t i = n_coeffs;
310 do {
311 const int32x4_t v_coeff_a = vld1q_s32(coeff_ptr + i - 4);
312 const int32x4_t v_coeff_b = vld1q_s32(coeff_ptr + i - 8);
313 const int32x4_t v_abs_coeff_a = vabsq_s32(v_coeff_a);
314 const int32x4_t v_abs_coeff_b = vabsq_s32(v_coeff_b);
315 const uint32x4_t v_mask_a = vcgeq_s32(v_abs_coeff_a, v_zbin_prescan);
316 const uint32x4_t v_mask_b = vcgeq_s32(v_abs_coeff_b, v_zbin_prescan);
317 // If the coefficient is in the base ZBIN range, then discard.
318 if (sum_abs_coeff(v_mask_a) + sum_abs_coeff(v_mask_b) == 0) {
319 non_zero_count -= 8;
320 } else {
321 break;
322 }
323 i -= 8;
324 } while (i > 0);
325
326 const intptr_t remaining_zcoeffs = n_coeffs - non_zero_count;
327 memset(qcoeff_ptr + non_zero_count, 0,
328 remaining_zcoeffs * sizeof(*qcoeff_ptr));
329 memset(dqcoeff_ptr + non_zero_count, 0,
330 remaining_zcoeffs * sizeof(*dqcoeff_ptr));
331
332 // DC and first 3 AC
333 v_mask_lo =
334 quantize_4(coeff_ptr, qcoeff_ptr, dqcoeff_ptr, v_quant_s32, v_dequant_s32,
335 v_round_s32, v_zbin_s32, v_quant_shift_s32, log_scale);
336
337 // overwrite the DC constants with AC constants
338 v_round_s32 = vdupq_lane_s32(vget_low_s32(v_round_s32), 1);
339 v_quant_s32 = vdupq_lane_s32(vget_low_s32(v_quant_s32), 1);
340 v_dequant_s32 = vdupq_lane_s32(vget_low_s32(v_dequant_s32), 1);
341 v_quant_shift_s32 = vdupq_lane_s32(vget_low_s32(v_quant_shift_s32), 1);
342 v_zbin_s32 = vdupq_lane_s32(vget_low_s32(v_zbin_s32), 1);
343
344 // 4 more AC
345 v_mask_hi = quantize_4(coeff_ptr + 4, qcoeff_ptr + 4, dqcoeff_ptr + 4,
346 v_quant_s32, v_dequant_s32, v_round_s32, v_zbin_s32,
347 v_quant_shift_s32, log_scale);
348
349 get_min_max_lane_eob(iscan, &v_eobmin, &v_eobmax,
350 vcombine_u16(v_mask_lo, v_mask_hi), n_coeffs);
351
352 intptr_t count = non_zero_count - 8;
353 for (; count > 0; count -= 8) {
354 coeff_ptr += 8;
355 qcoeff_ptr += 8;
356 dqcoeff_ptr += 8;
357 iscan += 8;
358 v_mask_lo = quantize_4(coeff_ptr, qcoeff_ptr, dqcoeff_ptr, v_quant_s32,
359 v_dequant_s32, v_round_s32, v_zbin_s32,
360 v_quant_shift_s32, log_scale);
361 v_mask_hi = quantize_4(coeff_ptr + 4, qcoeff_ptr + 4, dqcoeff_ptr + 4,
362 v_quant_s32, v_dequant_s32, v_round_s32, v_zbin_s32,
363 v_quant_shift_s32, log_scale);
364
365 get_min_max_lane_eob(iscan, &v_eobmin, &v_eobmax,
366 vcombine_u16(v_mask_lo, v_mask_hi), n_coeffs);
367 }
368
369 int eob = get_max_eob(v_eobmax);
370
371 #if SKIP_EOB_FACTOR_ADJUST
372 const int first = get_min_eob(v_eobmin);
373 if (eob >= 0 && first == eob) {
374 const int rc = scan[eob];
375 if (qcoeff_ptr[rc] == 1 || qcoeff_ptr[rc] == -1) {
376 const int zbins[2] = { ROUND_POWER_OF_TWO(zbin_ptr[0], log_scale),
377 ROUND_POWER_OF_TWO(zbin_ptr[1], log_scale) };
378 const int nzbins[2] = { zbins[0] * -1, zbins[1] * -1 };
379 const qm_val_t wt = (1 << AOM_QM_BITS);
380 const int coeff = coeff_ptr[rc] * wt;
381 const int factor = EOB_FACTOR + SKIP_EOB_FACTOR_ADJUST;
382 const int prescan_add_val =
383 ROUND_POWER_OF_TWO(dequant_ptr[rc != 0] * factor, 7);
384 if (coeff < (zbins[rc != 0] * (1 << AOM_QM_BITS) + prescan_add_val) &&
385 coeff > (nzbins[rc != 0] * (1 << AOM_QM_BITS) - prescan_add_val)) {
386 qcoeff_ptr[rc] = 0;
387 dqcoeff_ptr[rc] = 0;
388 eob = -1;
389 }
390 }
391 }
392 #endif // SKIP_EOB_FACTOR_ADJUST
393 *eob_ptr = eob + 1;
394 }
395
aom_highbd_quantize_b_adaptive_neon(const tran_low_t * coeff_ptr,intptr_t n_coeffs,const int16_t * zbin_ptr,const int16_t * round_ptr,const int16_t * quant_ptr,const int16_t * quant_shift_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)396 void aom_highbd_quantize_b_adaptive_neon(
397 const tran_low_t *coeff_ptr, intptr_t n_coeffs, const int16_t *zbin_ptr,
398 const int16_t *round_ptr, const int16_t *quant_ptr,
399 const int16_t *quant_shift_ptr, tran_low_t *qcoeff_ptr,
400 tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr,
401 const int16_t *scan, const int16_t *iscan) {
402 highbd_quantize_b_adaptive_neon(
403 coeff_ptr, n_coeffs, zbin_ptr, round_ptr, quant_ptr, quant_shift_ptr,
404 qcoeff_ptr, dqcoeff_ptr, dequant_ptr, eob_ptr, scan, iscan, 0);
405 }
406
aom_highbd_quantize_b_32x32_adaptive_neon(const tran_low_t * coeff_ptr,intptr_t n_coeffs,const int16_t * zbin_ptr,const int16_t * round_ptr,const int16_t * quant_ptr,const int16_t * quant_shift_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)407 void aom_highbd_quantize_b_32x32_adaptive_neon(
408 const tran_low_t *coeff_ptr, intptr_t n_coeffs, const int16_t *zbin_ptr,
409 const int16_t *round_ptr, const int16_t *quant_ptr,
410 const int16_t *quant_shift_ptr, tran_low_t *qcoeff_ptr,
411 tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr,
412 const int16_t *scan, const int16_t *iscan) {
413 highbd_quantize_b_adaptive_neon(
414 coeff_ptr, n_coeffs, zbin_ptr, round_ptr, quant_ptr, quant_shift_ptr,
415 qcoeff_ptr, dqcoeff_ptr, dequant_ptr, eob_ptr, scan, iscan, 1);
416 }
417
aom_highbd_quantize_b_64x64_adaptive_neon(const tran_low_t * coeff_ptr,intptr_t n_coeffs,const int16_t * zbin_ptr,const int16_t * round_ptr,const int16_t * quant_ptr,const int16_t * quant_shift_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)418 void aom_highbd_quantize_b_64x64_adaptive_neon(
419 const tran_low_t *coeff_ptr, intptr_t n_coeffs, const int16_t *zbin_ptr,
420 const int16_t *round_ptr, const int16_t *quant_ptr,
421 const int16_t *quant_shift_ptr, tran_low_t *qcoeff_ptr,
422 tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr,
423 const int16_t *scan, const int16_t *iscan) {
424 highbd_quantize_b_adaptive_neon(
425 coeff_ptr, n_coeffs, zbin_ptr, round_ptr, quant_ptr, quant_shift_ptr,
426 qcoeff_ptr, dqcoeff_ptr, dequant_ptr, eob_ptr, scan, iscan, 2);
427 }
428 #endif // !CONFIG_REALTIME_ONLY
429