vp9_quantize_neon.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. #include <arm_neon.h>
  11. #include <math.h>
  12. #include "vpx_mem/vpx_mem.h"
  13. #include "vp9/common/vp9_quant_common.h"
  14. #include "vp9/common/vp9_seg_common.h"
  15. #include "vp9/encoder/vp9_encoder.h"
  16. #include "vp9/encoder/vp9_quantize.h"
  17. #include "vp9/encoder/vp9_rd.h"
  18. void vp9_quantize_fp_neon(const int16_t *coeff_ptr, intptr_t count,
  19. int skip_block, const int16_t *zbin_ptr,
  20. const int16_t *round_ptr, const int16_t *quant_ptr,
  21. const int16_t *quant_shift_ptr, int16_t *qcoeff_ptr,
  22. int16_t *dqcoeff_ptr, const int16_t *dequant_ptr,
  23. uint16_t *eob_ptr, const int16_t *scan,
  24. const int16_t *iscan) {
  25. // TODO(jingning) Decide the need of these arguments after the
  26. // quantization process is completed.
  27. (void)zbin_ptr;
  28. (void)quant_shift_ptr;
  29. (void)scan;
  30. if (!skip_block) {
  31. // Quantization pass: All coefficients with index >= zero_flag are
  32. // skippable. Note: zero_flag can be zero.
  33. int i;
  34. const int16x8_t v_zero = vdupq_n_s16(0);
  35. const int16x8_t v_one = vdupq_n_s16(1);
  36. int16x8_t v_eobmax_76543210 = vdupq_n_s16(-1);
  37. int16x8_t v_round = vmovq_n_s16(round_ptr[1]);
  38. int16x8_t v_quant = vmovq_n_s16(quant_ptr[1]);
  39. int16x8_t v_dequant = vmovq_n_s16(dequant_ptr[1]);
  40. // adjust for dc
  41. v_round = vsetq_lane_s16(round_ptr[0], v_round, 0);
  42. v_quant = vsetq_lane_s16(quant_ptr[0], v_quant, 0);
  43. v_dequant = vsetq_lane_s16(dequant_ptr[0], v_dequant, 0);
  44. // process dc and the first seven ac coeffs
  45. {
  46. const int16x8_t v_iscan = vld1q_s16(&iscan[0]);
  47. const int16x8_t v_coeff = vld1q_s16(&coeff_ptr[0]);
  48. const int16x8_t v_coeff_sign = vshrq_n_s16(v_coeff, 15);
  49. const int16x8_t v_tmp = vabaq_s16(v_round, v_coeff, v_zero);
  50. const int32x4_t v_tmp_lo =
  51. vmull_s16(vget_low_s16(v_tmp), vget_low_s16(v_quant));
  52. const int32x4_t v_tmp_hi =
  53. vmull_s16(vget_high_s16(v_tmp), vget_high_s16(v_quant));
  54. const int16x8_t v_tmp2 =
  55. vcombine_s16(vshrn_n_s32(v_tmp_lo, 16), vshrn_n_s32(v_tmp_hi, 16));
  56. const uint16x8_t v_nz_mask = vceqq_s16(v_tmp2, v_zero);
  57. const int16x8_t v_iscan_plus1 = vaddq_s16(v_iscan, v_one);
  58. const int16x8_t v_nz_iscan = vbslq_s16(v_nz_mask, v_zero, v_iscan_plus1);
  59. const int16x8_t v_qcoeff_a = veorq_s16(v_tmp2, v_coeff_sign);
  60. const int16x8_t v_qcoeff = vsubq_s16(v_qcoeff_a, v_coeff_sign);
  61. const int16x8_t v_dqcoeff = vmulq_s16(v_qcoeff, v_dequant);
  62. v_eobmax_76543210 = vmaxq_s16(v_eobmax_76543210, v_nz_iscan);
  63. vst1q_s16(&qcoeff_ptr[0], v_qcoeff);
  64. vst1q_s16(&dqcoeff_ptr[0], v_dqcoeff);
  65. v_round = vmovq_n_s16(round_ptr[1]);
  66. v_quant = vmovq_n_s16(quant_ptr[1]);
  67. v_dequant = vmovq_n_s16(dequant_ptr[1]);
  68. }
  69. // now process the rest of the ac coeffs
  70. for (i = 8; i < count; i += 8) {
  71. const int16x8_t v_iscan = vld1q_s16(&iscan[i]);
  72. const int16x8_t v_coeff = vld1q_s16(&coeff_ptr[i]);
  73. const int16x8_t v_coeff_sign = vshrq_n_s16(v_coeff, 15);
  74. const int16x8_t v_tmp = vabaq_s16(v_round, v_coeff, v_zero);
  75. const int32x4_t v_tmp_lo =
  76. vmull_s16(vget_low_s16(v_tmp), vget_low_s16(v_quant));
  77. const int32x4_t v_tmp_hi =
  78. vmull_s16(vget_high_s16(v_tmp), vget_high_s16(v_quant));
  79. const int16x8_t v_tmp2 =
  80. vcombine_s16(vshrn_n_s32(v_tmp_lo, 16), vshrn_n_s32(v_tmp_hi, 16));
  81. const uint16x8_t v_nz_mask = vceqq_s16(v_tmp2, v_zero);
  82. const int16x8_t v_iscan_plus1 = vaddq_s16(v_iscan, v_one);
  83. const int16x8_t v_nz_iscan = vbslq_s16(v_nz_mask, v_zero, v_iscan_plus1);
  84. const int16x8_t v_qcoeff_a = veorq_s16(v_tmp2, v_coeff_sign);
  85. const int16x8_t v_qcoeff = vsubq_s16(v_qcoeff_a, v_coeff_sign);
  86. const int16x8_t v_dqcoeff = vmulq_s16(v_qcoeff, v_dequant);
  87. v_eobmax_76543210 = vmaxq_s16(v_eobmax_76543210, v_nz_iscan);
  88. vst1q_s16(&qcoeff_ptr[i], v_qcoeff);
  89. vst1q_s16(&dqcoeff_ptr[i], v_dqcoeff);
  90. }
  91. {
  92. const int16x4_t v_eobmax_3210 = vmax_s16(
  93. vget_low_s16(v_eobmax_76543210), vget_high_s16(v_eobmax_76543210));
  94. const int64x1_t v_eobmax_xx32 =
  95. vshr_n_s64(vreinterpret_s64_s16(v_eobmax_3210), 32);
  96. const int16x4_t v_eobmax_tmp =
  97. vmax_s16(v_eobmax_3210, vreinterpret_s16_s64(v_eobmax_xx32));
  98. const int64x1_t v_eobmax_xxx3 =
  99. vshr_n_s64(vreinterpret_s64_s16(v_eobmax_tmp), 16);
  100. const int16x4_t v_eobmax_final =
  101. vmax_s16(v_eobmax_tmp, vreinterpret_s16_s64(v_eobmax_xxx3));
  102. *eob_ptr = (uint16_t)vget_lane_s16(v_eobmax_final, 0);
  103. }
  104. } else {
  105. memset(qcoeff_ptr, 0, count * sizeof(int16_t));
  106. memset(dqcoeff_ptr, 0, count * sizeof(int16_t));
  107. *eob_ptr = 0;
  108. }
  109. }