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 #include <emmintrin.h>
12
13 #include "./vpx_config.h"
14 #include "vpx/vpx_integer.h"
15 #include "vpx_dsp/x86/bitdepth_conversion_sse2.h"
16
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)17 static INLINE void load_b_values(const int16_t *zbin_ptr, __m128i *zbin,
18 const int16_t *round_ptr, __m128i *round,
19 const int16_t *quant_ptr, __m128i *quant,
20 const int16_t *dequant_ptr, __m128i *dequant,
21 const int16_t *shift_ptr, __m128i *shift) {
22 *zbin = _mm_load_si128((const __m128i *)zbin_ptr);
23 *round = _mm_load_si128((const __m128i *)round_ptr);
24 *quant = _mm_load_si128((const __m128i *)quant_ptr);
25 *zbin = _mm_sub_epi16(*zbin, _mm_set1_epi16(1));
26 *dequant = _mm_load_si128((const __m128i *)dequant_ptr);
27 *shift = _mm_load_si128((const __m128i *)shift_ptr);
28 }
29
30 // With ssse3 and later abs() and sign() are preferred.
invert_sign_sse2(__m128i a,__m128i sign)31 static INLINE __m128i invert_sign_sse2(__m128i a, __m128i sign) {
32 a = _mm_xor_si128(a, sign);
33 return _mm_sub_epi16(a, sign);
34 }
35
calculate_qcoeff(__m128i * coeff,const __m128i round,const __m128i quant,const __m128i shift)36 static INLINE void calculate_qcoeff(__m128i *coeff, const __m128i round,
37 const __m128i quant, const __m128i shift) {
38 __m128i tmp, qcoeff;
39 qcoeff = _mm_adds_epi16(*coeff, round);
40 tmp = _mm_mulhi_epi16(qcoeff, quant);
41 qcoeff = _mm_add_epi16(tmp, qcoeff);
42 *coeff = _mm_mulhi_epi16(qcoeff, shift);
43 }
44
calculate_dqcoeff(__m128i qcoeff,__m128i dequant)45 static INLINE __m128i calculate_dqcoeff(__m128i qcoeff, __m128i dequant) {
46 return _mm_mullo_epi16(qcoeff, dequant);
47 }
48
49 // Scan 16 values for eob reference in scan_ptr. Use masks (-1) from comparing
50 // to 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_ptr,const int index,const __m128i zero)51 static INLINE __m128i scan_for_eob(__m128i *coeff0, __m128i *coeff1,
52 const __m128i zbin_mask0,
53 const __m128i zbin_mask1,
54 const int16_t *scan_ptr, const int index,
55 const __m128i zero) {
56 const __m128i zero_coeff0 = _mm_cmpeq_epi16(*coeff0, zero);
57 const __m128i zero_coeff1 = _mm_cmpeq_epi16(*coeff1, zero);
58 __m128i scan0 = _mm_load_si128((const __m128i *)(scan_ptr + index));
59 __m128i scan1 = _mm_load_si128((const __m128i *)(scan_ptr + index + 8));
60 __m128i eob0, eob1;
61 // Add one to convert from indices to counts
62 scan0 = _mm_sub_epi16(scan0, zbin_mask0);
63 scan1 = _mm_sub_epi16(scan1, zbin_mask1);
64 eob0 = _mm_andnot_si128(zero_coeff0, scan0);
65 eob1 = _mm_andnot_si128(zero_coeff1, scan1);
66 return _mm_max_epi16(eob0, eob1);
67 }
68
accumulate_eob(__m128i eob)69 static INLINE int16_t accumulate_eob(__m128i eob) {
70 __m128i eob_shuffled;
71 eob_shuffled = _mm_shuffle_epi32(eob, 0xe);
72 eob = _mm_max_epi16(eob, eob_shuffled);
73 eob_shuffled = _mm_shufflelo_epi16(eob, 0xe);
74 eob = _mm_max_epi16(eob, eob_shuffled);
75 eob_shuffled = _mm_shufflelo_epi16(eob, 0x1);
76 eob = _mm_max_epi16(eob, eob_shuffled);
77 return _mm_extract_epi16(eob, 1);
78 }
79