quantize_ssse3.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Copyright (c) 2017 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. #ifndef VPX_VPX_DSP_X86_QUANTIZE_SSSE3_H_
  11. #define VPX_VPX_DSP_X86_QUANTIZE_SSSE3_H_
  12. #include <emmintrin.h>
  13. #include "./vpx_config.h"
  14. #include "vpx/vpx_integer.h"
  15. #include "vpx_dsp/x86/quantize_sse2.h"
  16. static INLINE void calculate_dqcoeff_and_store_32x32(const __m128i qcoeff,
  17. const __m128i dequant,
  18. const __m128i zero,
  19. tran_low_t *dqcoeff) {
  20. // Un-sign to bias rounding like C.
  21. const __m128i coeff = _mm_abs_epi16(qcoeff);
  22. const __m128i sign_0 = _mm_unpacklo_epi16(zero, qcoeff);
  23. const __m128i sign_1 = _mm_unpackhi_epi16(zero, qcoeff);
  24. const __m128i low = _mm_mullo_epi16(coeff, dequant);
  25. const __m128i high = _mm_mulhi_epi16(coeff, dequant);
  26. __m128i dqcoeff32_0 = _mm_unpacklo_epi16(low, high);
  27. __m128i dqcoeff32_1 = _mm_unpackhi_epi16(low, high);
  28. // "Divide" by 2.
  29. dqcoeff32_0 = _mm_srli_epi32(dqcoeff32_0, 1);
  30. dqcoeff32_1 = _mm_srli_epi32(dqcoeff32_1, 1);
  31. dqcoeff32_0 = _mm_sign_epi32(dqcoeff32_0, sign_0);
  32. dqcoeff32_1 = _mm_sign_epi32(dqcoeff32_1, sign_1);
  33. #if CONFIG_VP9_HIGHBITDEPTH
  34. _mm_store_si128((__m128i *)(dqcoeff), dqcoeff32_0);
  35. _mm_store_si128((__m128i *)(dqcoeff + 4), dqcoeff32_1);
  36. #else
  37. _mm_store_si128((__m128i *)(dqcoeff),
  38. _mm_packs_epi32(dqcoeff32_0, dqcoeff32_1));
  39. #endif // CONFIG_VP9_HIGHBITDEPTH
  40. }
  41. #endif // VPX_VPX_DSP_X86_QUANTIZE_SSSE3_H_