blob: 6014895be9bb2927a7513305586750b05091b2f8 [file] [log] [blame]
Ravi Chaudharybe4dd102018-03-07 09:19:17 +05301/*
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
Jerome Jiangafa74192020-08-19 20:39:35 -070012#include "av1/common/resize.h"
13#include "config/av1_rtcd.h"
14#include "config/aom_scale_rtcd.h"
15
James Zerne1cbb132018-08-22 14:10:36 -070016#ifndef AOM_AOM_DSP_X86_CONVOLVE_SSE2_H_
17#define AOM_AOM_DSP_X86_CONVOLVE_SSE2_H_
Ravi Chaudharybe4dd102018-03-07 09:19:17 +053018
Cherma Rajan Aa7be3682018-03-20 10:00:51 +053019// Note:
20// This header file should be put below any x86 intrinsics head file
21
Ravi Chaudharybe4dd102018-03-07 09:19:17 +053022static INLINE void prepare_coeffs(const InterpFilterParams *const filter_params,
23 const int subpel_q4,
24 __m128i *const coeffs /* [4] */) {
25 const int16_t *filter = av1_get_interp_filter_subpel_kernel(
Peng Bin3a0c2ed2018-07-19 16:24:00 +080026 filter_params, subpel_q4 & SUBPEL_MASK);
Ravi Chaudharybe4dd102018-03-07 09:19:17 +053027 const __m128i coeff = _mm_loadu_si128((__m128i *)filter);
28
29 // coeffs 0 1 0 1 0 1 0 1
30 coeffs[0] = _mm_shuffle_epi32(coeff, 0x00);
31 // coeffs 2 3 2 3 2 3 2 3
32 coeffs[1] = _mm_shuffle_epi32(coeff, 0x55);
33 // coeffs 4 5 4 5 4 5 4 5
34 coeffs[2] = _mm_shuffle_epi32(coeff, 0xaa);
35 // coeffs 6 7 6 7 6 7 6 7
36 coeffs[3] = _mm_shuffle_epi32(coeff, 0xff);
37}
38
39static INLINE __m128i convolve(const __m128i *const s,
40 const __m128i *const coeffs) {
41 const __m128i res_0 = _mm_madd_epi16(s[0], coeffs[0]);
42 const __m128i res_1 = _mm_madd_epi16(s[1], coeffs[1]);
43 const __m128i res_2 = _mm_madd_epi16(s[2], coeffs[2]);
44 const __m128i res_3 = _mm_madd_epi16(s[3], coeffs[3]);
45
46 const __m128i res =
47 _mm_add_epi32(_mm_add_epi32(res_0, res_1), _mm_add_epi32(res_2, res_3));
48
49 return res;
50}
51
Cherma Rajan Aa7be3682018-03-20 10:00:51 +053052static INLINE __m128i convolve_lo_x(const __m128i *const s,
53 const __m128i *const coeffs) {
54 __m128i ss[4];
55 ss[0] = _mm_unpacklo_epi8(s[0], _mm_setzero_si128());
56 ss[1] = _mm_unpacklo_epi8(s[1], _mm_setzero_si128());
57 ss[2] = _mm_unpacklo_epi8(s[2], _mm_setzero_si128());
58 ss[3] = _mm_unpacklo_epi8(s[3], _mm_setzero_si128());
59 return convolve(ss, coeffs);
60}
61
62static INLINE __m128i convolve_lo_y(const __m128i *const s,
63 const __m128i *const coeffs) {
64 __m128i ss[4];
65 ss[0] = _mm_unpacklo_epi8(s[0], _mm_setzero_si128());
66 ss[1] = _mm_unpacklo_epi8(s[2], _mm_setzero_si128());
67 ss[2] = _mm_unpacklo_epi8(s[4], _mm_setzero_si128());
68 ss[3] = _mm_unpacklo_epi8(s[6], _mm_setzero_si128());
69 return convolve(ss, coeffs);
70}
71
72static INLINE __m128i convolve_hi_y(const __m128i *const s,
73 const __m128i *const coeffs) {
74 __m128i ss[4];
75 ss[0] = _mm_unpackhi_epi8(s[0], _mm_setzero_si128());
76 ss[1] = _mm_unpackhi_epi8(s[2], _mm_setzero_si128());
77 ss[2] = _mm_unpackhi_epi8(s[4], _mm_setzero_si128());
78 ss[3] = _mm_unpackhi_epi8(s[6], _mm_setzero_si128());
79 return convolve(ss, coeffs);
80}
81
Cherma Rajan Aa7be3682018-03-20 10:00:51 +053082static INLINE __m128i comp_avg(const __m128i *const data_ref_0,
83 const __m128i *const res_unsigned,
84 const __m128i *const wt,
Debargha Mukherjee0c96c112018-12-20 16:04:18 -080085 const int use_dist_wtd_avg) {
Cherma Rajan Aa7be3682018-03-20 10:00:51 +053086 __m128i res;
Debargha Mukherjee0c96c112018-12-20 16:04:18 -080087 if (use_dist_wtd_avg) {
Cherma Rajan Aa7be3682018-03-20 10:00:51 +053088 const __m128i data_lo = _mm_unpacklo_epi16(*data_ref_0, *res_unsigned);
89 const __m128i data_hi = _mm_unpackhi_epi16(*data_ref_0, *res_unsigned);
90
91 const __m128i wt_res_lo = _mm_madd_epi16(data_lo, *wt);
92 const __m128i wt_res_hi = _mm_madd_epi16(data_hi, *wt);
93
94 const __m128i res_lo = _mm_srai_epi32(wt_res_lo, DIST_PRECISION_BITS);
95 const __m128i res_hi = _mm_srai_epi32(wt_res_hi, DIST_PRECISION_BITS);
96
97 res = _mm_packs_epi32(res_lo, res_hi);
98 } else {
99 const __m128i wt_res = _mm_add_epi16(*data_ref_0, *res_unsigned);
100 res = _mm_srai_epi16(wt_res, 1);
101 }
102 return res;
103}
104
105static INLINE __m128i convolve_rounding(const __m128i *const res_unsigned,
106 const __m128i *const offset_const,
107 const __m128i *const round_const,
108 const int round_shift) {
109 const __m128i res_signed = _mm_sub_epi16(*res_unsigned, *offset_const);
110 const __m128i res_round =
111 _mm_srai_epi16(_mm_add_epi16(res_signed, *round_const), round_shift);
112 return res_round;
113}
Ravi Chaudhary23c1d632018-03-22 11:12:56 +0530114
115static INLINE __m128i highbd_convolve_rounding_sse2(
116 const __m128i *const res_unsigned, const __m128i *const offset_const,
117 const __m128i *const round_const, const int round_shift) {
118 const __m128i res_signed = _mm_sub_epi32(*res_unsigned, *offset_const);
119 const __m128i res_round =
120 _mm_srai_epi32(_mm_add_epi32(res_signed, *round_const), round_shift);
121
122 return res_round;
123}
124
James Zerne1cbb132018-08-22 14:10:36 -0700125#endif // AOM_AOM_DSP_X86_CONVOLVE_SSE2_H_