xref: /aosp_15_r20/external/libvpx/vp9/encoder/arm/neon/vp9_quantize_neon.c (revision fb1b10ab9aebc7c7068eedab379b749d7e3900be)
1 /*
2  *  Copyright (c) 2014 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 <arm_neon.h>
12 #include <assert.h>
13 #include <math.h>
14 #include <stdint.h>
15 
16 #include "./vpx_config.h"
17 #include "vpx_mem/vpx_mem.h"
18 
19 #include "vp9/common/vp9_quant_common.h"
20 #include "vp9/common/vp9_scan.h"
21 #include "vp9/common/vp9_seg_common.h"
22 
23 #include "vp9/encoder/vp9_encoder.h"
24 #include "vp9/encoder/vp9_quantize.h"
25 #include "vp9/encoder/vp9_rd.h"
26 
27 #include "vpx_dsp/arm/idct_neon.h"
28 #include "vpx_dsp/arm/mem_neon.h"
29 #include "vpx_dsp/vpx_dsp_common.h"
30 
calculate_dqcoeff_and_store(const int16x8_t qcoeff,const int16x8_t dequant,tran_low_t * dqcoeff)31 static VPX_FORCE_INLINE void calculate_dqcoeff_and_store(
32     const int16x8_t qcoeff, const int16x8_t dequant, tran_low_t *dqcoeff) {
33   const int32x4_t dqcoeff_0 =
34       vmull_s16(vget_low_s16(qcoeff), vget_low_s16(dequant));
35   const int32x4_t dqcoeff_1 =
36       vmull_s16(vget_high_s16(qcoeff), vget_high_s16(dequant));
37 
38 #if CONFIG_VP9_HIGHBITDEPTH
39   vst1q_s32(dqcoeff, dqcoeff_0);
40   vst1q_s32(dqcoeff + 4, dqcoeff_1);
41 #else
42   vst1q_s16(dqcoeff, vcombine_s16(vmovn_s32(dqcoeff_0), vmovn_s32(dqcoeff_1)));
43 #endif  // CONFIG_VP9_HIGHBITDEPTH
44 }
45 
get_max_lane_eob(const int16_t * iscan_ptr,int16x8_t v_eobmax,uint16x8_t v_nz_mask)46 static VPX_FORCE_INLINE int16x8_t get_max_lane_eob(const int16_t *iscan_ptr,
47                                                    int16x8_t v_eobmax,
48                                                    uint16x8_t v_nz_mask) {
49   const int16x8_t v_iscan = vld1q_s16(&iscan_ptr[0]);
50   const int16x8_t v_nz_iscan = vbslq_s16(v_nz_mask, vdupq_n_s16(0), v_iscan);
51   return vmaxq_s16(v_eobmax, v_nz_iscan);
52 }
53 
get_max_eob(int16x8_t v_eobmax)54 static VPX_FORCE_INLINE uint16_t get_max_eob(int16x8_t v_eobmax) {
55 #if VPX_ARCH_AARCH64
56   return (uint16_t)vmaxvq_s16(v_eobmax);
57 #else
58   const int16x4_t v_eobmax_3210 =
59       vmax_s16(vget_low_s16(v_eobmax), vget_high_s16(v_eobmax));
60   const int64x1_t v_eobmax_xx32 =
61       vshr_n_s64(vreinterpret_s64_s16(v_eobmax_3210), 32);
62   const int16x4_t v_eobmax_tmp =
63       vmax_s16(v_eobmax_3210, vreinterpret_s16_s64(v_eobmax_xx32));
64   const int64x1_t v_eobmax_xxx3 =
65       vshr_n_s64(vreinterpret_s64_s16(v_eobmax_tmp), 16);
66   const int16x4_t v_eobmax_final =
67       vmax_s16(v_eobmax_tmp, vreinterpret_s16_s64(v_eobmax_xxx3));
68 
69   return (uint16_t)vget_lane_s16(v_eobmax_final, 0);
70 #endif  // VPX_ARCH_AARCH64
71 }
72 
load_fp_values(const struct macroblock_plane * mb_plane,const int16_t * dequant_ptr,int16x8_t * round,int16x8_t * quant,int16x8_t * dequant)73 static VPX_FORCE_INLINE void load_fp_values(
74     const struct macroblock_plane *mb_plane, const int16_t *dequant_ptr,
75     int16x8_t *round, int16x8_t *quant, int16x8_t *dequant) {
76   *round = vld1q_s16(mb_plane->round_fp);
77   *quant = vld1q_s16(mb_plane->quant_fp);
78   *dequant = vld1q_s16(dequant_ptr);
79 }
80 
update_fp_values(int16x8_t * v_round,int16x8_t * v_quant,int16x8_t * v_dequant)81 static VPX_FORCE_INLINE void update_fp_values(int16x8_t *v_round,
82                                               int16x8_t *v_quant,
83                                               int16x8_t *v_dequant) {
84 #if VPX_ARCH_AARCH64
85   *v_round = vdupq_laneq_s16(*v_round, 1);
86   *v_quant = vdupq_laneq_s16(*v_quant, 1);
87   *v_dequant = vdupq_laneq_s16(*v_dequant, 1);
88 #else
89   *v_round = vdupq_lane_s16(vget_low_s16(*v_round), 1);
90   *v_quant = vdupq_lane_s16(vget_low_s16(*v_quant), 1);
91   *v_dequant = vdupq_lane_s16(vget_low_s16(*v_dequant), 1);
92 #endif
93 }
94 
quantize_fp_8(const int16x8_t * v_round,const int16x8_t * v_quant,const int16x8_t * v_dequant,const tran_low_t * coeff_ptr,const int16_t * iscan_ptr,tran_low_t * qcoeff_ptr,tran_low_t * dqcoeff_ptr,int16x8_t * v_eobmax)95 static VPX_FORCE_INLINE void quantize_fp_8(
96     const int16x8_t *v_round, const int16x8_t *v_quant,
97     const int16x8_t *v_dequant, const tran_low_t *coeff_ptr,
98     const int16_t *iscan_ptr, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr,
99     int16x8_t *v_eobmax) {
100   const int16x8_t v_zero = vdupq_n_s16(0);
101   const int16x8_t v_coeff = load_tran_low_to_s16q(coeff_ptr);
102   const int16x8_t v_coeff_sign = vshrq_n_s16(v_coeff, 15);
103   const int16x8_t v_abs = vabsq_s16(v_coeff);
104   const int16x8_t v_tmp = vqaddq_s16(v_abs, *v_round);
105   const int32x4_t v_tmp_lo =
106       vmull_s16(vget_low_s16(v_tmp), vget_low_s16(*v_quant));
107   const int32x4_t v_tmp_hi =
108       vmull_s16(vget_high_s16(v_tmp), vget_high_s16(*v_quant));
109   const int16x8_t v_tmp2 =
110       vcombine_s16(vshrn_n_s32(v_tmp_lo, 16), vshrn_n_s32(v_tmp_hi, 16));
111   const uint16x8_t v_nz_mask = vceqq_s16(v_tmp2, v_zero);
112   const int16x8_t v_qcoeff_a = veorq_s16(v_tmp2, v_coeff_sign);
113   const int16x8_t v_qcoeff = vsubq_s16(v_qcoeff_a, v_coeff_sign);
114   calculate_dqcoeff_and_store(v_qcoeff, *v_dequant, dqcoeff_ptr);
115   store_s16q_to_tran_low(qcoeff_ptr, v_qcoeff);
116 
117   *v_eobmax = get_max_lane_eob(iscan_ptr, *v_eobmax, v_nz_mask);
118 }
119 
vp9_quantize_fp_neon(const tran_low_t * coeff_ptr,intptr_t n_coeffs,const struct macroblock_plane * mb_plane,tran_low_t * qcoeff_ptr,tran_low_t * dqcoeff_ptr,const int16_t * dequant_ptr,uint16_t * eob_ptr,const struct ScanOrder * const scan_order)120 void vp9_quantize_fp_neon(const tran_low_t *coeff_ptr, intptr_t n_coeffs,
121                           const struct macroblock_plane *mb_plane,
122                           tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr,
123                           const int16_t *dequant_ptr, uint16_t *eob_ptr,
124                           const struct ScanOrder *const scan_order) {
125   // Quantization pass: All coefficients with index >= zero_flag are
126   // skippable. Note: zero_flag can be zero.
127   int i;
128   int16x8_t v_eobmax = vdupq_n_s16(-1);
129   int16x8_t v_round, v_quant, v_dequant;
130   const int16_t *iscan = scan_order->iscan;
131 
132   load_fp_values(mb_plane, dequant_ptr, &v_round, &v_quant, &v_dequant);
133   // process dc and the first seven ac coeffs
134   quantize_fp_8(&v_round, &v_quant, &v_dequant, coeff_ptr, iscan, qcoeff_ptr,
135                 dqcoeff_ptr, &v_eobmax);
136 
137   // now process the rest of the ac coeffs
138   update_fp_values(&v_round, &v_quant, &v_dequant);
139   for (i = 8; i < n_coeffs; i += 8) {
140     quantize_fp_8(&v_round, &v_quant, &v_dequant, coeff_ptr + i, iscan + i,
141                   qcoeff_ptr + i, dqcoeff_ptr + i, &v_eobmax);
142   }
143 
144   *eob_ptr = get_max_eob(v_eobmax);
145 }
146 
extract_sign_bit(int32x4_t a)147 static INLINE int32x4_t extract_sign_bit(int32x4_t a) {
148   return vreinterpretq_s32_u32(vshrq_n_u32(vreinterpretq_u32_s32(a), 31));
149 }
150 
quantize_fp_32x32_8(const int16x8_t * v_round,const int16x8_t * v_quant,const int16x8_t * v_dequant,const int16x8_t * dequant_thresh,const tran_low_t * coeff_ptr,const int16_t * iscan_ptr,tran_low_t * qcoeff_ptr,tran_low_t * dqcoeff_ptr,int16x8_t * v_eobmax)151 static VPX_FORCE_INLINE void quantize_fp_32x32_8(
152     const int16x8_t *v_round, const int16x8_t *v_quant,
153     const int16x8_t *v_dequant, const int16x8_t *dequant_thresh,
154     const tran_low_t *coeff_ptr, const int16_t *iscan_ptr,
155     tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, int16x8_t *v_eobmax) {
156   const int16x8_t v_coeff = load_tran_low_to_s16q(coeff_ptr);
157   const int16x8_t v_coeff_sign = vshrq_n_s16(v_coeff, 15);
158   const int16x8_t v_coeff_abs = vabsq_s16(v_coeff);
159   const int16x8_t v_thr_mask =
160       vreinterpretq_s16_u16(vcgeq_s16(v_coeff_abs, *dequant_thresh));
161   const int16x8_t v_tmp_rnd =
162       vandq_s16(vqaddq_s16(v_coeff_abs, *v_round), v_thr_mask);
163   const int16x8_t v_abs_qcoeff = vqdmulhq_s16(v_tmp_rnd, *v_quant);
164   const int16x8_t v_qcoeff =
165       vsubq_s16(veorq_s16(v_abs_qcoeff, v_coeff_sign), v_coeff_sign);
166   const uint16x8_t v_nz_mask = vceqq_s16(v_abs_qcoeff, vdupq_n_s16(0));
167 
168   int32x4_t dqcoeff_0, dqcoeff_1;
169   dqcoeff_0 = vmull_s16(vget_low_s16(v_qcoeff), vget_low_s16(*v_dequant));
170   dqcoeff_1 = vmull_s16(vget_high_s16(v_qcoeff), vget_high_s16(*v_dequant));
171   // Add 1 if negative to round towards zero because the C uses division.
172   dqcoeff_0 = vaddq_s32(dqcoeff_0, extract_sign_bit(dqcoeff_0));
173   dqcoeff_1 = vaddq_s32(dqcoeff_1, extract_sign_bit(dqcoeff_1));
174 
175 #if CONFIG_VP9_HIGHBITDEPTH
176   vst1q_s32(dqcoeff_ptr, vshrq_n_s32(dqcoeff_0, 1));
177   vst1q_s32(dqcoeff_ptr + 4, vshrq_n_s32(dqcoeff_1, 1));
178 #else
179   store_s16q_to_tran_low(dqcoeff_ptr, vcombine_s16(vshrn_n_s32(dqcoeff_0, 1),
180                                                    vshrn_n_s32(dqcoeff_1, 1)));
181 #endif
182 
183   store_s16q_to_tran_low(qcoeff_ptr, v_qcoeff);
184 
185   *v_eobmax = get_max_lane_eob(iscan_ptr, *v_eobmax, v_nz_mask);
186 }
187 
vp9_quantize_fp_32x32_neon(const tran_low_t * coeff_ptr,intptr_t n_coeffs,const struct macroblock_plane * mb_plane,tran_low_t * qcoeff_ptr,tran_low_t * dqcoeff_ptr,const int16_t * dequant_ptr,uint16_t * eob_ptr,const struct ScanOrder * const scan_order)188 void vp9_quantize_fp_32x32_neon(const tran_low_t *coeff_ptr, intptr_t n_coeffs,
189                                 const struct macroblock_plane *mb_plane,
190                                 tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr,
191                                 const int16_t *dequant_ptr, uint16_t *eob_ptr,
192                                 const struct ScanOrder *const scan_order) {
193   int16x8_t eob_max = vdupq_n_s16(-1);
194   // ROUND_POWER_OF_TWO(round_ptr[], 1)
195   int16x8_t round = vrshrq_n_s16(vld1q_s16(mb_plane->round_fp), 1);
196   int16x8_t quant = vld1q_s16(mb_plane->quant_fp);
197   int16x8_t dequant = vld1q_s16(dequant_ptr);
198   // dequant >> 2 is used similar to zbin as a threshold.
199   int16x8_t dequant_thresh = vshrq_n_s16(vld1q_s16(dequant_ptr), 2);
200   int i;
201   const int16_t *iscan = scan_order->iscan;
202 
203   (void)n_coeffs;
204 
205   // Process dc and the first seven ac coeffs.
206   quantize_fp_32x32_8(&round, &quant, &dequant, &dequant_thresh, coeff_ptr,
207                       iscan, qcoeff_ptr, dqcoeff_ptr, &eob_max);
208 
209   update_fp_values(&round, &quant, &dequant);
210   dequant_thresh = vdupq_lane_s16(vget_low_s16(dequant_thresh), 1);
211 
212   iscan += 8;
213   coeff_ptr += 8;
214   qcoeff_ptr += 8;
215   dqcoeff_ptr += 8;
216 
217   // Process the rest of the ac coeffs.
218   for (i = 8; i < 32 * 32; i += 8) {
219     quantize_fp_32x32_8(&round, &quant, &dequant, &dequant_thresh, coeff_ptr,
220                         iscan, qcoeff_ptr, dqcoeff_ptr, &eob_max);
221 
222     iscan += 8;
223     coeff_ptr += 8;
224     qcoeff_ptr += 8;
225     dqcoeff_ptr += 8;
226   }
227 
228   *eob_ptr = get_max_eob(eob_max);
229 }
230 
231 #if CONFIG_VP9_HIGHBITDEPTH
232 static VPX_FORCE_INLINE uint16x4_t
highbd_quantize_fp_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)233 highbd_quantize_fp_4(const tran_low_t *coeff_ptr, tran_low_t *qcoeff_ptr,
234                      tran_low_t *dqcoeff_ptr, int32x4_t v_quant_s32,
235                      int32x4_t v_dequant_s32, int32x4_t v_round_s32) {
236   const int32x4_t v_coeff = vld1q_s32(coeff_ptr);
237   const int32x4_t v_coeff_sign =
238       vreinterpretq_s32_u32(vcltq_s32(v_coeff, vdupq_n_s32(0)));
239   const int32x4_t v_abs_coeff = vabsq_s32(v_coeff);
240   const int32x4_t v_tmp = vaddq_s32(v_abs_coeff, v_round_s32);
241   //  const int abs_qcoeff = (int)((tmp * quant) >> 16);
242   const int32x4_t v_abs_qcoeff = vqdmulhq_s32(v_tmp, v_quant_s32);
243   //  qcoeff_ptr[rc] = (tran_low_t)((abs_qcoeff ^ coeff_sign) - coeff_sign);
244   const int32x4_t v_qcoeff =
245       vsubq_s32(veorq_s32(v_abs_qcoeff, v_coeff_sign), v_coeff_sign);
246   const int32x4_t v_abs_dqcoeff = vmulq_s32(v_abs_qcoeff, v_dequant_s32);
247   //  dqcoeff_ptr[rc] = (tran_low_t)((abs_dqcoeff ^ coeff_sign) - coeff_sign);
248   const int32x4_t v_dqcoeff =
249       vsubq_s32(veorq_s32(v_abs_dqcoeff, v_coeff_sign), v_coeff_sign);
250 
251   vst1q_s32(qcoeff_ptr, v_qcoeff);
252   vst1q_s32(dqcoeff_ptr, v_dqcoeff);
253 
254   // Packed nz_qcoeff_mask. Used to find eob.
255   return vmovn_u32(vceqq_s32(v_abs_qcoeff, vdupq_n_s32(0)));
256 }
257 
vp9_highbd_quantize_fp_neon(const tran_low_t * coeff_ptr,intptr_t n_coeffs,const struct macroblock_plane * mb_plane,tran_low_t * qcoeff_ptr,tran_low_t * dqcoeff_ptr,const int16_t * dequant_ptr,uint16_t * eob_ptr,const struct ScanOrder * const scan_order)258 void vp9_highbd_quantize_fp_neon(const tran_low_t *coeff_ptr, intptr_t n_coeffs,
259                                  const struct macroblock_plane *mb_plane,
260                                  tran_low_t *qcoeff_ptr,
261                                  tran_low_t *dqcoeff_ptr,
262                                  const int16_t *dequant_ptr, uint16_t *eob_ptr,
263                                  const struct ScanOrder *const scan_order) {
264   const int16x4_t v_zero = vdup_n_s16(0);
265   const int16x4_t v_quant = vld1_s16(mb_plane->quant_fp);
266   const int16x4_t v_dequant = vld1_s16(dequant_ptr);
267   const int16x4_t v_round = vld1_s16(mb_plane->round_fp);
268   int32x4_t v_round_s32 = vaddl_s16(v_round, v_zero);
269   int32x4_t v_quant_s32 = vshlq_n_s32(vaddl_s16(v_quant, v_zero), 15);
270   int32x4_t v_dequant_s32 = vaddl_s16(v_dequant, v_zero);
271   uint16x4_t v_mask_lo, v_mask_hi;
272   int16x8_t v_eobmax = vdupq_n_s16(-1);
273   const int16_t *iscan = scan_order->iscan;
274 
275   // DC and first 3 AC
276   v_mask_lo = highbd_quantize_fp_4(coeff_ptr, qcoeff_ptr, dqcoeff_ptr,
277                                    v_quant_s32, v_dequant_s32, v_round_s32);
278 
279   // overwrite the DC constants with AC constants
280   v_round_s32 = vdupq_lane_s32(vget_low_s32(v_round_s32), 1);
281   v_quant_s32 = vdupq_lane_s32(vget_low_s32(v_quant_s32), 1);
282   v_dequant_s32 = vdupq_lane_s32(vget_low_s32(v_dequant_s32), 1);
283 
284   // 4 more AC
285   v_mask_hi =
286       highbd_quantize_fp_4(coeff_ptr + 4, qcoeff_ptr + 4, dqcoeff_ptr + 4,
287                            v_quant_s32, v_dequant_s32, v_round_s32);
288 
289   // Find the max lane eob for the first 8 coeffs.
290   v_eobmax =
291       get_max_lane_eob(iscan, v_eobmax, vcombine_u16(v_mask_lo, v_mask_hi));
292 
293   n_coeffs -= 8;
294   do {
295     coeff_ptr += 8;
296     qcoeff_ptr += 8;
297     dqcoeff_ptr += 8;
298     iscan += 8;
299     v_mask_lo = highbd_quantize_fp_4(coeff_ptr, qcoeff_ptr, dqcoeff_ptr,
300                                      v_quant_s32, v_dequant_s32, v_round_s32);
301     v_mask_hi =
302         highbd_quantize_fp_4(coeff_ptr + 4, qcoeff_ptr + 4, dqcoeff_ptr + 4,
303                              v_quant_s32, v_dequant_s32, v_round_s32);
304     // Find the max lane eob for 8 coeffs.
305     v_eobmax =
306         get_max_lane_eob(iscan, v_eobmax, vcombine_u16(v_mask_lo, v_mask_hi));
307     n_coeffs -= 8;
308   } while (n_coeffs);
309 
310   *eob_ptr = get_max_eob(v_eobmax);
311 }
312 
313 static VPX_FORCE_INLINE uint16x4_t
highbd_quantize_fp_32x32_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)314 highbd_quantize_fp_32x32_4(const tran_low_t *coeff_ptr, tran_low_t *qcoeff_ptr,
315                            tran_low_t *dqcoeff_ptr, int32x4_t v_quant_s32,
316                            int32x4_t v_dequant_s32, int32x4_t v_round_s32) {
317   const int32x4_t v_coeff = vld1q_s32(coeff_ptr);
318   const int32x4_t v_coeff_sign =
319       vreinterpretq_s32_u32(vcltq_s32(v_coeff, vdupq_n_s32(0)));
320   const int32x4_t v_abs_coeff = vabsq_s32(v_coeff);
321   // ((abs_coeff << (1 + log_scale)) >= dequant_ptr[rc01])
322   const int32x4_t v_abs_coeff_scaled = vshlq_n_s32(v_abs_coeff, 2);
323   const uint32x4_t v_mask = vcgeq_s32(v_abs_coeff_scaled, v_dequant_s32);
324   // const int64_t tmp = vmask ? (int64_t)abs_coeff + log_scaled_round : 0
325   const int32x4_t v_tmp = vandq_s32(vaddq_s32(v_abs_coeff, v_round_s32),
326                                     vreinterpretq_s32_u32(v_mask));
327   //  const int abs_qcoeff = (int)((tmp * quant) >> (16 - log_scale));
328   const int32x4_t v_abs_qcoeff =
329       vqdmulhq_s32(vshlq_n_s32(v_tmp, 1), v_quant_s32);
330   //  qcoeff_ptr[rc] = (tran_low_t)((abs_qcoeff ^ coeff_sign) - coeff_sign);
331   const int32x4_t v_qcoeff =
332       vsubq_s32(veorq_s32(v_abs_qcoeff, v_coeff_sign), v_coeff_sign);
333   // vshlq_s32 will shift right if shift value is negative.
334   const int32x4_t v_abs_dqcoeff =
335       vshrq_n_s32(vmulq_s32(v_abs_qcoeff, v_dequant_s32), 1);
336   //  dqcoeff_ptr[rc] = (tran_low_t)((abs_dqcoeff ^ coeff_sign) - coeff_sign);
337   const int32x4_t v_dqcoeff =
338       vsubq_s32(veorq_s32(v_abs_dqcoeff, v_coeff_sign), v_coeff_sign);
339 
340   vst1q_s32(qcoeff_ptr, v_qcoeff);
341   vst1q_s32(dqcoeff_ptr, v_dqcoeff);
342 
343   // Packed nz_qcoeff_mask. Used to find eob.
344   return vmovn_u32(vceqq_s32(v_abs_qcoeff, vdupq_n_s32(0)));
345 }
346 
vp9_highbd_quantize_fp_32x32_neon(const tran_low_t * coeff_ptr,intptr_t n_coeffs,const struct macroblock_plane * mb_plane,tran_low_t * qcoeff_ptr,tran_low_t * dqcoeff_ptr,const int16_t * dequant_ptr,uint16_t * eob_ptr,const struct ScanOrder * const scan_order)347 void vp9_highbd_quantize_fp_32x32_neon(
348     const tran_low_t *coeff_ptr, intptr_t n_coeffs,
349     const struct macroblock_plane *mb_plane, tran_low_t *qcoeff_ptr,
350     tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr,
351     const struct ScanOrder *const scan_order) {
352   const int16x4_t v_quant = vld1_s16(mb_plane->quant_fp);
353   const int16x4_t v_dequant = vld1_s16(dequant_ptr);
354   const int16x4_t v_zero = vdup_n_s16(0);
355   const int16x4_t v_round =
356       vqrdmulh_n_s16(vld1_s16(mb_plane->round_fp), (int16_t)(1 << 14));
357   int32x4_t v_round_s32 = vaddl_s16(v_round, v_zero);
358   int32x4_t v_quant_s32 = vshlq_n_s32(vaddl_s16(v_quant, v_zero), 15);
359   int32x4_t v_dequant_s32 = vaddl_s16(v_dequant, v_zero);
360   uint16x4_t v_mask_lo, v_mask_hi;
361   int16x8_t v_eobmax = vdupq_n_s16(-1);
362   const int16_t *iscan = scan_order->iscan;
363 
364   // DC and first 3 AC
365   v_mask_lo =
366       highbd_quantize_fp_32x32_4(coeff_ptr, qcoeff_ptr, dqcoeff_ptr,
367                                  v_quant_s32, v_dequant_s32, v_round_s32);
368 
369   // overwrite the DC constants with AC constants
370   v_round_s32 = vdupq_lane_s32(vget_low_s32(v_round_s32), 1);
371   v_quant_s32 = vdupq_lane_s32(vget_low_s32(v_quant_s32), 1);
372   v_dequant_s32 = vdupq_lane_s32(vget_low_s32(v_dequant_s32), 1);
373 
374   // 4 more AC
375   v_mask_hi =
376       highbd_quantize_fp_32x32_4(coeff_ptr + 4, qcoeff_ptr + 4, dqcoeff_ptr + 4,
377                                  v_quant_s32, v_dequant_s32, v_round_s32);
378 
379   // Find the max lane eob for the first 8 coeffs.
380   v_eobmax =
381       get_max_lane_eob(iscan, v_eobmax, vcombine_u16(v_mask_lo, v_mask_hi));
382 
383   n_coeffs -= 8;
384   do {
385     coeff_ptr += 8;
386     qcoeff_ptr += 8;
387     dqcoeff_ptr += 8;
388     iscan += 8;
389     v_mask_lo =
390         highbd_quantize_fp_32x32_4(coeff_ptr, qcoeff_ptr, dqcoeff_ptr,
391                                    v_quant_s32, v_dequant_s32, v_round_s32);
392     v_mask_hi = highbd_quantize_fp_32x32_4(coeff_ptr + 4, qcoeff_ptr + 4,
393                                            dqcoeff_ptr + 4, v_quant_s32,
394                                            v_dequant_s32, v_round_s32);
395     // Find the max lane eob for 8 coeffs.
396     v_eobmax =
397         get_max_lane_eob(iscan, v_eobmax, vcombine_u16(v_mask_lo, v_mask_hi));
398     n_coeffs -= 8;
399   } while (n_coeffs);
400 
401   *eob_ptr = get_max_eob(v_eobmax);
402 }
403 #endif  // CONFIG_VP9_HIGHBITDEPTH
404