Merge "VPX: Add vp9_highbd_quantize_fp_neon()." into main
authorScott LaVarnway <slavarnway@google.com>
Mon, 15 Aug 2022 21:34:42 +0000 (21:34 +0000)
committerGerrit Code Review <noreply-gerritcodereview@google.com>
Mon, 15 Aug 2022 21:34:42 +0000 (21:34 +0000)
1  2 
vp9/encoder/arm/neon/vp9_quantize_neon.c

@@@ -183,51 -205,161 +183,136 @@@ static VPX_FORCE_INLINE void quantize_f
                                                     vshrn_n_s32(dqcoeff_1, 1)));
  #endif
  
 -  eob_max = vandq_u16(vtstq_s16(qcoeff, neg_one), v_iscan);
 +  store_s16q_to_tran_low(qcoeff_ptr, v_qcoeff);
  
 -  store_s16q_to_tran_low(qcoeff_ptr, qcoeff);
 +  *v_eobmax = get_max_lane_eob(iscan_ptr, *v_eobmax, v_nz_mask);
 +}
  
 -  iscan += 8;
 -  coeff_ptr += 8;
 -  qcoeff_ptr += 8;
 -  dqcoeff_ptr += 8;
 +void vp9_quantize_fp_32x32_neon(const tran_low_t *coeff_ptr, intptr_t count,
 +                                const int16_t *round_ptr,
 +                                const int16_t *quant_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) {
 +  int16x8_t eob_max = vdupq_n_s16(-1);
 +  // ROUND_POWER_OF_TWO(round_ptr[], 1)
 +  int16x8_t round = vrshrq_n_s16(vld1q_s16(round_ptr), 1);
 +  int16x8_t quant = vld1q_s16(quant_ptr);
 +  int16x8_t dequant = vld1q_s16(dequant_ptr);
 +  // dequant >> 2 is used similar to zbin as a threshold.
 +  int16x8_t dequant_thresh = vshrq_n_s16(vld1q_s16(dequant_ptr), 2);
 +  int i;
  
 -  {
 -    int i;
 -    const int16x8_t round = vrshrq_n_s16(vmovq_n_s16(round_ptr[1]), 1);
 -    const int16x8_t quant = vmovq_n_s16(quant_ptr[1]);
 -    const int16x8_t dequant_thresh =
 -        vshrq_n_s16(vmovq_n_s16(dequant_ptr[1]), 2);
 -
 -    // Process the rest of the ac coeffs.
 -    for (i = 8; i < 32 * 32; i += 8) {
 -      const uint16x8_t v_iscan =
 -          vreinterpretq_u16_s16(vaddq_s16(vld1q_s16(iscan), one));
 -      const int16x8_t coeff = load_tran_low_to_s16q(coeff_ptr);
 -      const int16x8_t coeff_sign = vshrq_n_s16(coeff, 15);
 -      const int16x8_t coeff_abs = vabsq_s16(coeff);
 -      const int16x8_t dequant_mask =
 -          vreinterpretq_s16_u16(vcgeq_s16(coeff_abs, dequant_thresh));
 -
 -      int16x8_t qcoeff = vqaddq_s16(coeff_abs, round);
 -      int32x4_t dqcoeff_0, dqcoeff_1;
 -
 -      qcoeff = vqdmulhq_s16(qcoeff, quant);
 -      qcoeff = veorq_s16(qcoeff, coeff_sign);
 -      qcoeff = vsubq_s16(qcoeff, coeff_sign);
 -      qcoeff = vandq_s16(qcoeff, dequant_mask);
 -
 -      dqcoeff_0 = vmull_n_s16(vget_low_s16(qcoeff), dequant_ptr[1]);
 -      dqcoeff_1 = vmull_n_s16(vget_high_s16(qcoeff), dequant_ptr[1]);
 -
 -      dqcoeff_0 = vaddq_s32(dqcoeff_0, extract_sign_bit(dqcoeff_0));
 -      dqcoeff_1 = vaddq_s32(dqcoeff_1, extract_sign_bit(dqcoeff_1));
 +  (void)scan;
 +  (void)count;
  
 -#if CONFIG_VP9_HIGHBITDEPTH
 -      vst1q_s32(dqcoeff_ptr, vshrq_n_s32(dqcoeff_0, 1));
 -      vst1q_s32(dqcoeff_ptr + 4, vshrq_n_s32(dqcoeff_1, 1));
 -#else
 -      store_s16q_to_tran_low(
 -          dqcoeff_ptr,
 -          vcombine_s16(vshrn_n_s32(dqcoeff_0, 1), vshrn_n_s32(dqcoeff_1, 1)));
 -#endif
 +  // Process dc and the first seven ac coeffs.
 +  quantize_fp_32x32_8(&round, &quant, &dequant, &dequant_thresh, coeff_ptr,
 +                      iscan, qcoeff_ptr, dqcoeff_ptr, &eob_max);
  
 -      eob_max =
 -          vmaxq_u16(eob_max, vandq_u16(vtstq_s16(qcoeff, neg_one), v_iscan));
 +  update_fp_values(&round, &quant, &dequant);
 +  dequant_thresh = vdupq_lane_s16(vget_low_s16(dequant_thresh), 1);
  
 -      store_s16q_to_tran_low(qcoeff_ptr, qcoeff);
 +  iscan += 8;
 +  coeff_ptr += 8;
 +  qcoeff_ptr += 8;
 +  dqcoeff_ptr += 8;
  
 -      iscan += 8;
 -      coeff_ptr += 8;
 -      qcoeff_ptr += 8;
 -      dqcoeff_ptr += 8;
 -    }
 +  // Process the rest of the ac coeffs.
 +  for (i = 8; i < 32 * 32; i += 8) {
 +    quantize_fp_32x32_8(&round, &quant, &dequant, &dequant_thresh, coeff_ptr,
 +                        iscan, qcoeff_ptr, dqcoeff_ptr, &eob_max);
  
 -#ifdef __aarch64__
 -    *eob_ptr = vmaxvq_u16(eob_max);
 -#else
 -    {
 -      const uint16x4_t eob_max_0 =
 -          vmax_u16(vget_low_u16(eob_max), vget_high_u16(eob_max));
 -      const uint16x4_t eob_max_1 = vpmax_u16(eob_max_0, eob_max_0);
 -      const uint16x4_t eob_max_2 = vpmax_u16(eob_max_1, eob_max_1);
 -      vst1_lane_u16(eob_ptr, eob_max_2, 0);
 -    }
 -#endif  // __aarch64__
 +    iscan += 8;
 +    coeff_ptr += 8;
 +    qcoeff_ptr += 8;
 +    dqcoeff_ptr += 8;
    }
 +
 +  *eob_ptr = get_max_eob(eob_max);
  }
+ #if CONFIG_VP9_HIGHBITDEPTH
+ 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) {
+   const int32x4_t v_coeff = vld1q_s32(coeff_ptr);
+   const int32x4_t v_coeff_sign =
+       vreinterpretq_s32_u32(vcltq_s32(v_coeff, vdupq_n_s32(0)));
+   const int32x4_t v_abs_coeff = vabsq_s32(v_coeff);
+   const int32x4_t v_tmp = vaddq_s32(v_abs_coeff, v_round_s32);
+   //  const int abs_qcoeff = (int)((tmp * quant) >> 16);
+   const int32x4_t v_abs_qcoeff = vqdmulhq_s32(v_tmp, v_quant_s32);
+   //  qcoeff_ptr[rc] = (tran_low_t)((abs_qcoeff ^ coeff_sign) - coeff_sign);
+   const int32x4_t v_qcoeff =
+       vsubq_s32(veorq_s32(v_abs_qcoeff, v_coeff_sign), v_coeff_sign);
+   const int32x4_t v_abs_dqcoeff = vmulq_s32(v_abs_qcoeff, v_dequant_s32);
+   //  dqcoeff_ptr[rc] = (tran_low_t)((abs_dqcoeff ^ coeff_sign) - coeff_sign);
+   const int32x4_t v_dqcoeff =
+       vsubq_s32(veorq_s32(v_abs_dqcoeff, v_coeff_sign), v_coeff_sign);
+   vst1q_s32(qcoeff_ptr, v_qcoeff);
+   vst1q_s32(dqcoeff_ptr, v_dqcoeff);
+   // Packed nz_qcoeff_mask. Used to find eob.
+   return vmovn_u32(vceqq_s32(v_abs_qcoeff, vdupq_n_s32(0)));
+ }
+ void vp9_highbd_quantize_fp_neon(const tran_low_t *coeff_ptr, intptr_t count,
+                                  const int16_t *round_ptr,
+                                  const int16_t *quant_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 int16x4_t v_zero = vdup_n_s16(0);
+   const int16x4_t v_quant = vld1_s16(quant_ptr);
+   const int16x4_t v_dequant = vld1_s16(dequant_ptr);
+   const int16x4_t v_round = vld1_s16(round_ptr);
+   int32x4_t v_round_s32 = vaddl_s16(v_round, v_zero);
+   int32x4_t v_quant_s32 = vshlq_n_s32(vaddl_s16(v_quant, v_zero), 15);
+   int32x4_t v_dequant_s32 = vaddl_s16(v_dequant, v_zero);
+   uint16x4_t v_mask_lo, v_mask_hi;
+   int16x8_t v_eobmax = vdupq_n_s16(-1);
+   (void)scan;
+   // DC and first 3 AC
+   v_mask_lo = highbd_quantize_fp_4(coeff_ptr, qcoeff_ptr, dqcoeff_ptr,
+                                    v_quant_s32, v_dequant_s32, v_round_s32);
+   // overwrite the DC constants with AC constants
+   v_round_s32 = vdupq_lane_s32(vget_low_s32(v_round_s32), 1);
+   v_quant_s32 = vdupq_lane_s32(vget_low_s32(v_quant_s32), 1);
+   v_dequant_s32 = vdupq_lane_s32(vget_low_s32(v_dequant_s32), 1);
+   // 4 more AC
+   v_mask_hi =
+       highbd_quantize_fp_4(coeff_ptr + 4, qcoeff_ptr + 4, dqcoeff_ptr + 4,
+                            v_quant_s32, v_dequant_s32, v_round_s32);
+   // Find the max lane eob for the first 8 coeffs.
+   v_eobmax =
+       get_max_lane_eob(iscan, v_eobmax, vcombine_u16(v_mask_lo, v_mask_hi));
+   count -= 8;
+   do {
+     coeff_ptr += 8;
+     qcoeff_ptr += 8;
+     dqcoeff_ptr += 8;
+     iscan += 8;
+     v_mask_lo = highbd_quantize_fp_4(coeff_ptr, qcoeff_ptr, dqcoeff_ptr,
+                                      v_quant_s32, v_dequant_s32, v_round_s32);
+     v_mask_hi =
+         highbd_quantize_fp_4(coeff_ptr + 4, qcoeff_ptr + 4, dqcoeff_ptr + 4,
+                              v_quant_s32, v_dequant_s32, v_round_s32);
+     // Find the max lane eob for 8 coeffs.
+     v_eobmax =
+         get_max_lane_eob(iscan, v_eobmax, vcombine_u16(v_mask_lo, v_mask_hi));
+     count -= 8;
+   } while (count);
+   *eob_ptr = get_max_eob(v_eobmax);
+ }
+ #endif  // CONFIG_VP9_HIGHBITDEPTH