Ravi Chaudhary | be4dd10 | 2018-03-07 09:19:17 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018, Alliance for Open Media. All rights reserved |
| 3 | * |
| 4 | * This source code is subject to the terms of the BSD 2 Clause License and |
| 5 | * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License |
| 6 | * was not distributed with this source code in the LICENSE file, you can |
| 7 | * obtain it at www.aomedia.org/license/software. If the Alliance for Open |
| 8 | * Media Patent License 1.0 was not distributed with this source code in the |
| 9 | * PATENTS file, you can obtain it at www.aomedia.org/license/patent. |
| 10 | */ |
| 11 | |
| 12 | #ifndef AOM_DSP_X86_CONVOLVE_SSE2_H_ |
| 13 | #define AOM_DSP_X86_CONVOLVE_SSE2_H_ |
| 14 | |
Cherma Rajan A | a7be368 | 2018-03-20 10:00:51 +0530 | [diff] [blame] | 15 | // Note: |
| 16 | // This header file should be put below any x86 intrinsics head file |
| 17 | |
Ravi Chaudhary | be4dd10 | 2018-03-07 09:19:17 +0530 | [diff] [blame] | 18 | static INLINE void prepare_coeffs(const InterpFilterParams *const filter_params, |
| 19 | const int subpel_q4, |
| 20 | __m128i *const coeffs /* [4] */) { |
| 21 | const int16_t *filter = av1_get_interp_filter_subpel_kernel( |
| 22 | *filter_params, subpel_q4 & SUBPEL_MASK); |
| 23 | const __m128i coeff = _mm_loadu_si128((__m128i *)filter); |
| 24 | |
| 25 | // coeffs 0 1 0 1 0 1 0 1 |
| 26 | coeffs[0] = _mm_shuffle_epi32(coeff, 0x00); |
| 27 | // coeffs 2 3 2 3 2 3 2 3 |
| 28 | coeffs[1] = _mm_shuffle_epi32(coeff, 0x55); |
| 29 | // coeffs 4 5 4 5 4 5 4 5 |
| 30 | coeffs[2] = _mm_shuffle_epi32(coeff, 0xaa); |
| 31 | // coeffs 6 7 6 7 6 7 6 7 |
| 32 | coeffs[3] = _mm_shuffle_epi32(coeff, 0xff); |
| 33 | } |
| 34 | |
| 35 | static INLINE __m128i convolve(const __m128i *const s, |
| 36 | const __m128i *const coeffs) { |
| 37 | const __m128i res_0 = _mm_madd_epi16(s[0], coeffs[0]); |
| 38 | const __m128i res_1 = _mm_madd_epi16(s[1], coeffs[1]); |
| 39 | const __m128i res_2 = _mm_madd_epi16(s[2], coeffs[2]); |
| 40 | const __m128i res_3 = _mm_madd_epi16(s[3], coeffs[3]); |
| 41 | |
| 42 | const __m128i res = |
| 43 | _mm_add_epi32(_mm_add_epi32(res_0, res_1), _mm_add_epi32(res_2, res_3)); |
| 44 | |
| 45 | return res; |
| 46 | } |
| 47 | |
Cherma Rajan A | a7be368 | 2018-03-20 10:00:51 +0530 | [diff] [blame] | 48 | static INLINE __m128i convolve_lo_x(const __m128i *const s, |
| 49 | const __m128i *const coeffs) { |
| 50 | __m128i ss[4]; |
| 51 | ss[0] = _mm_unpacklo_epi8(s[0], _mm_setzero_si128()); |
| 52 | ss[1] = _mm_unpacklo_epi8(s[1], _mm_setzero_si128()); |
| 53 | ss[2] = _mm_unpacklo_epi8(s[2], _mm_setzero_si128()); |
| 54 | ss[3] = _mm_unpacklo_epi8(s[3], _mm_setzero_si128()); |
| 55 | return convolve(ss, coeffs); |
| 56 | } |
| 57 | |
| 58 | static INLINE __m128i convolve_lo_y(const __m128i *const s, |
| 59 | const __m128i *const coeffs) { |
| 60 | __m128i ss[4]; |
| 61 | ss[0] = _mm_unpacklo_epi8(s[0], _mm_setzero_si128()); |
| 62 | ss[1] = _mm_unpacklo_epi8(s[2], _mm_setzero_si128()); |
| 63 | ss[2] = _mm_unpacklo_epi8(s[4], _mm_setzero_si128()); |
| 64 | ss[3] = _mm_unpacklo_epi8(s[6], _mm_setzero_si128()); |
| 65 | return convolve(ss, coeffs); |
| 66 | } |
| 67 | |
| 68 | static INLINE __m128i convolve_hi_y(const __m128i *const s, |
| 69 | const __m128i *const coeffs) { |
| 70 | __m128i ss[4]; |
| 71 | ss[0] = _mm_unpackhi_epi8(s[0], _mm_setzero_si128()); |
| 72 | ss[1] = _mm_unpackhi_epi8(s[2], _mm_setzero_si128()); |
| 73 | ss[2] = _mm_unpackhi_epi8(s[4], _mm_setzero_si128()); |
| 74 | ss[3] = _mm_unpackhi_epi8(s[6], _mm_setzero_si128()); |
| 75 | return convolve(ss, coeffs); |
| 76 | } |
| 77 | |
Cherma Rajan A | a7be368 | 2018-03-20 10:00:51 +0530 | [diff] [blame] | 78 | static INLINE __m128i comp_avg(const __m128i *const data_ref_0, |
| 79 | const __m128i *const res_unsigned, |
| 80 | const __m128i *const wt, |
| 81 | const int use_jnt_comp_avg) { |
| 82 | __m128i res; |
| 83 | if (use_jnt_comp_avg) { |
| 84 | const __m128i data_lo = _mm_unpacklo_epi16(*data_ref_0, *res_unsigned); |
| 85 | const __m128i data_hi = _mm_unpackhi_epi16(*data_ref_0, *res_unsigned); |
| 86 | |
| 87 | const __m128i wt_res_lo = _mm_madd_epi16(data_lo, *wt); |
| 88 | const __m128i wt_res_hi = _mm_madd_epi16(data_hi, *wt); |
| 89 | |
| 90 | const __m128i res_lo = _mm_srai_epi32(wt_res_lo, DIST_PRECISION_BITS); |
| 91 | const __m128i res_hi = _mm_srai_epi32(wt_res_hi, DIST_PRECISION_BITS); |
| 92 | |
| 93 | res = _mm_packs_epi32(res_lo, res_hi); |
| 94 | } else { |
| 95 | const __m128i wt_res = _mm_add_epi16(*data_ref_0, *res_unsigned); |
| 96 | res = _mm_srai_epi16(wt_res, 1); |
| 97 | } |
| 98 | return res; |
| 99 | } |
| 100 | |
| 101 | static INLINE __m128i convolve_rounding(const __m128i *const res_unsigned, |
| 102 | const __m128i *const offset_const, |
| 103 | const __m128i *const round_const, |
| 104 | const int round_shift) { |
| 105 | const __m128i res_signed = _mm_sub_epi16(*res_unsigned, *offset_const); |
| 106 | const __m128i res_round = |
| 107 | _mm_srai_epi16(_mm_add_epi16(res_signed, *round_const), round_shift); |
| 108 | return res_round; |
| 109 | } |
Ravi Chaudhary | 23c1d63 | 2018-03-22 11:12:56 +0530 | [diff] [blame] | 110 | |
| 111 | static INLINE __m128i highbd_convolve_rounding_sse2( |
| 112 | const __m128i *const res_unsigned, const __m128i *const offset_const, |
| 113 | const __m128i *const round_const, const int round_shift) { |
| 114 | const __m128i res_signed = _mm_sub_epi32(*res_unsigned, *offset_const); |
| 115 | const __m128i res_round = |
| 116 | _mm_srai_epi32(_mm_add_epi32(res_signed, *round_const), round_shift); |
| 117 | |
| 118 | return res_round; |
| 119 | } |
| 120 | |
Cherma Rajan A | a7be368 | 2018-03-20 10:00:51 +0530 | [diff] [blame] | 121 | #endif |