• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
11 #ifndef VPX_VPX_DSP_X86_QUANTIZE_SSE2_H_
12 #define VPX_VPX_DSP_X86_QUANTIZE_SSE2_H_
13 
14 #include <emmintrin.h>
15 
16 #include "./vpx_config.h"
17 #include "vpx/vpx_integer.h"
18 
load_b_values(const int16_t * zbin_ptr,__m128i * zbin,const int16_t * round_ptr,__m128i * round,const int16_t * quant_ptr,__m128i * quant,const int16_t * dequant_ptr,__m128i * dequant,const int16_t * shift_ptr,__m128i * shift)19 static INLINE void load_b_values(const int16_t *zbin_ptr, __m128i *zbin,
20                                  const int16_t *round_ptr, __m128i *round,
21                                  const int16_t *quant_ptr, __m128i *quant,
22                                  const int16_t *dequant_ptr, __m128i *dequant,
23                                  const int16_t *shift_ptr, __m128i *shift) {
24   *zbin = _mm_load_si128((const __m128i *)zbin_ptr);
25   *round = _mm_load_si128((const __m128i *)round_ptr);
26   *quant = _mm_load_si128((const __m128i *)quant_ptr);
27   *zbin = _mm_sub_epi16(*zbin, _mm_set1_epi16(1));
28   *dequant = _mm_load_si128((const __m128i *)dequant_ptr);
29   *shift = _mm_load_si128((const __m128i *)shift_ptr);
30 }
31 
32 // With ssse3 and later abs() and sign() are preferred.
invert_sign_sse2(__m128i a,__m128i sign)33 static INLINE __m128i invert_sign_sse2(__m128i a, __m128i sign) {
34   a = _mm_xor_si128(a, sign);
35   return _mm_sub_epi16(a, sign);
36 }
37 
calculate_qcoeff(__m128i * coeff,const __m128i round,const __m128i quant,const __m128i shift)38 static INLINE void calculate_qcoeff(__m128i *coeff, const __m128i round,
39                                     const __m128i quant, const __m128i shift) {
40   __m128i tmp, qcoeff;
41   qcoeff = _mm_adds_epi16(*coeff, round);
42   tmp = _mm_mulhi_epi16(qcoeff, quant);
43   qcoeff = _mm_add_epi16(tmp, qcoeff);
44   *coeff = _mm_mulhi_epi16(qcoeff, shift);
45 }
46 
calculate_dqcoeff_and_store(__m128i qcoeff,__m128i dequant,tran_low_t * dqcoeff)47 static INLINE void calculate_dqcoeff_and_store(__m128i qcoeff, __m128i dequant,
48                                                tran_low_t *dqcoeff) {
49 #if CONFIG_VP9_HIGHBITDEPTH
50   const __m128i low = _mm_mullo_epi16(qcoeff, dequant);
51   const __m128i high = _mm_mulhi_epi16(qcoeff, dequant);
52 
53   const __m128i dqcoeff32_0 = _mm_unpacklo_epi16(low, high);
54   const __m128i dqcoeff32_1 = _mm_unpackhi_epi16(low, high);
55 
56   _mm_store_si128((__m128i *)(dqcoeff), dqcoeff32_0);
57   _mm_store_si128((__m128i *)(dqcoeff + 4), dqcoeff32_1);
58 #else
59   const __m128i dqcoeff16 = _mm_mullo_epi16(qcoeff, dequant);
60 
61   _mm_store_si128((__m128i *)(dqcoeff), dqcoeff16);
62 #endif  // CONFIG_VP9_HIGHBITDEPTH
63 }
64 
65 // Scan 16 values for eob reference in scan. Use masks (-1) from comparing to
66 // zbin to add 1 to the index in 'scan'.
scan_for_eob(__m128i * coeff0,__m128i * coeff1,const __m128i zbin_mask0,const __m128i zbin_mask1,const int16_t * scan,const int index,const __m128i zero)67 static INLINE __m128i scan_for_eob(__m128i *coeff0, __m128i *coeff1,
68                                    const __m128i zbin_mask0,
69                                    const __m128i zbin_mask1,
70                                    const int16_t *scan, const int index,
71                                    const __m128i zero) {
72   const __m128i zero_coeff0 = _mm_cmpeq_epi16(*coeff0, zero);
73   const __m128i zero_coeff1 = _mm_cmpeq_epi16(*coeff1, zero);
74   __m128i scan0 = _mm_load_si128((const __m128i *)(scan + index));
75   __m128i scan1 = _mm_load_si128((const __m128i *)(scan + index + 8));
76   __m128i eob0, eob1;
77   // Add one to convert from indices to counts
78   scan0 = _mm_sub_epi16(scan0, zbin_mask0);
79   scan1 = _mm_sub_epi16(scan1, zbin_mask1);
80   eob0 = _mm_andnot_si128(zero_coeff0, scan0);
81   eob1 = _mm_andnot_si128(zero_coeff1, scan1);
82   return _mm_max_epi16(eob0, eob1);
83 }
84 
accumulate_eob(__m128i eob)85 static INLINE int16_t accumulate_eob(__m128i eob) {
86   __m128i eob_shuffled;
87   eob_shuffled = _mm_shuffle_epi32(eob, 0xe);
88   eob = _mm_max_epi16(eob, eob_shuffled);
89   eob_shuffled = _mm_shufflelo_epi16(eob, 0xe);
90   eob = _mm_max_epi16(eob, eob_shuffled);
91   eob_shuffled = _mm_shufflelo_epi16(eob, 0x1);
92   eob = _mm_max_epi16(eob, eob_shuffled);
93   return _mm_extract_epi16(eob, 1);
94 }
95 
96 #endif  // VPX_VPX_DSP_X86_QUANTIZE_SSE2_H_
97