Line data Source code
1 : /*
2 : * Copyright (c) 2016 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 <tmmintrin.h> // SSSE3
12 :
13 : #include "./vp9_rtcd.h"
14 : #include "./vpx_dsp_rtcd.h"
15 : #include "./vpx_scale_rtcd.h"
16 : #include "vpx_scale/yv12config.h"
17 :
18 : extern void vp9_scale_and_extend_frame_c(const YV12_BUFFER_CONFIG *src,
19 : YV12_BUFFER_CONFIG *dst);
20 :
21 0 : static void downsample_2_to_1_ssse3(const uint8_t *src, ptrdiff_t src_stride,
22 : uint8_t *dst, ptrdiff_t dst_stride, int w,
23 : int h) {
24 0 : const __m128i mask = _mm_set1_epi16(0x00FF);
25 0 : const int max_width = w & ~15;
26 : int y;
27 0 : for (y = 0; y < h; ++y) {
28 : int x;
29 0 : for (x = 0; x < max_width; x += 16) {
30 0 : const __m128i a = _mm_loadu_si128((const __m128i *)(src + x * 2 + 0));
31 0 : const __m128i b = _mm_loadu_si128((const __m128i *)(src + x * 2 + 16));
32 0 : const __m128i a_and = _mm_and_si128(a, mask);
33 0 : const __m128i b_and = _mm_and_si128(b, mask);
34 0 : const __m128i c = _mm_packus_epi16(a_and, b_and);
35 0 : _mm_storeu_si128((__m128i *)(dst + x), c);
36 : }
37 0 : for (; x < w; ++x) dst[x] = src[x * 2];
38 0 : src += src_stride * 2;
39 0 : dst += dst_stride;
40 : }
41 0 : }
42 :
43 0 : static INLINE __m128i filter(const __m128i *const a, const __m128i *const b,
44 : const __m128i *const c, const __m128i *const d,
45 : const __m128i *const e, const __m128i *const f,
46 : const __m128i *const g, const __m128i *const h) {
47 0 : const __m128i coeffs_ab =
48 : _mm_set_epi8(6, -1, 6, -1, 6, -1, 6, -1, 6, -1, 6, -1, 6, -1, 6, -1);
49 0 : const __m128i coeffs_cd = _mm_set_epi8(78, -19, 78, -19, 78, -19, 78, -19, 78,
50 : -19, 78, -19, 78, -19, 78, -19);
51 0 : const __m128i const64_x16 = _mm_set1_epi16(64);
52 0 : const __m128i ab = _mm_unpacklo_epi8(*a, *b);
53 0 : const __m128i cd = _mm_unpacklo_epi8(*c, *d);
54 0 : const __m128i fe = _mm_unpacklo_epi8(*f, *e);
55 0 : const __m128i hg = _mm_unpacklo_epi8(*h, *g);
56 0 : const __m128i ab_terms = _mm_maddubs_epi16(ab, coeffs_ab);
57 0 : const __m128i cd_terms = _mm_maddubs_epi16(cd, coeffs_cd);
58 0 : const __m128i fe_terms = _mm_maddubs_epi16(fe, coeffs_cd);
59 0 : const __m128i hg_terms = _mm_maddubs_epi16(hg, coeffs_ab);
60 : // can not overflow
61 0 : const __m128i abcd_terms = _mm_add_epi16(ab_terms, cd_terms);
62 : // can not overflow
63 0 : const __m128i fehg_terms = _mm_add_epi16(fe_terms, hg_terms);
64 : // can overflow, use saturating add
65 0 : const __m128i terms = _mm_adds_epi16(abcd_terms, fehg_terms);
66 0 : const __m128i round = _mm_adds_epi16(terms, const64_x16);
67 0 : const __m128i shift = _mm_srai_epi16(round, 7);
68 0 : return _mm_packus_epi16(shift, shift);
69 : }
70 :
71 0 : static void eight_tap_row_ssse3(const uint8_t *src, uint8_t *dst, int w) {
72 0 : const int max_width = w & ~7;
73 0 : int x = 0;
74 0 : for (; x < max_width; x += 8) {
75 0 : const __m128i a = _mm_loadl_epi64((const __m128i *)(src + x + 0));
76 0 : const __m128i b = _mm_loadl_epi64((const __m128i *)(src + x + 1));
77 0 : const __m128i c = _mm_loadl_epi64((const __m128i *)(src + x + 2));
78 0 : const __m128i d = _mm_loadl_epi64((const __m128i *)(src + x + 3));
79 0 : const __m128i e = _mm_loadl_epi64((const __m128i *)(src + x + 4));
80 0 : const __m128i f = _mm_loadl_epi64((const __m128i *)(src + x + 5));
81 0 : const __m128i g = _mm_loadl_epi64((const __m128i *)(src + x + 6));
82 0 : const __m128i h = _mm_loadl_epi64((const __m128i *)(src + x + 7));
83 0 : const __m128i pack = filter(&a, &b, &c, &d, &e, &f, &g, &h);
84 0 : _mm_storel_epi64((__m128i *)(dst + x), pack);
85 : }
86 0 : }
87 :
88 0 : static void upsample_1_to_2_ssse3(const uint8_t *src, ptrdiff_t src_stride,
89 : uint8_t *dst, ptrdiff_t dst_stride, int dst_w,
90 : int dst_h) {
91 0 : dst_w /= 2;
92 0 : dst_h /= 2;
93 : {
94 : DECLARE_ALIGNED(16, uint8_t, tmp[1920 * 8]);
95 0 : uint8_t *tmp0 = tmp + dst_w * 0;
96 0 : uint8_t *tmp1 = tmp + dst_w * 1;
97 0 : uint8_t *tmp2 = tmp + dst_w * 2;
98 0 : uint8_t *tmp3 = tmp + dst_w * 3;
99 0 : uint8_t *tmp4 = tmp + dst_w * 4;
100 0 : uint8_t *tmp5 = tmp + dst_w * 5;
101 0 : uint8_t *tmp6 = tmp + dst_w * 6;
102 0 : uint8_t *tmp7 = tmp + dst_w * 7;
103 0 : uint8_t *tmp8 = NULL;
104 0 : const int max_width = dst_w & ~7;
105 : int y;
106 0 : eight_tap_row_ssse3(src - src_stride * 3 - 3, tmp0, dst_w);
107 0 : eight_tap_row_ssse3(src - src_stride * 2 - 3, tmp1, dst_w);
108 0 : eight_tap_row_ssse3(src - src_stride * 1 - 3, tmp2, dst_w);
109 0 : eight_tap_row_ssse3(src + src_stride * 0 - 3, tmp3, dst_w);
110 0 : eight_tap_row_ssse3(src + src_stride * 1 - 3, tmp4, dst_w);
111 0 : eight_tap_row_ssse3(src + src_stride * 2 - 3, tmp5, dst_w);
112 0 : eight_tap_row_ssse3(src + src_stride * 3 - 3, tmp6, dst_w);
113 0 : for (y = 0; y < dst_h; y++) {
114 : int x;
115 0 : eight_tap_row_ssse3(src + src_stride * 4 - 3, tmp7, dst_w);
116 0 : for (x = 0; x < max_width; x += 8) {
117 0 : const __m128i A = _mm_loadl_epi64((const __m128i *)(src + x));
118 0 : const __m128i B = _mm_loadl_epi64((const __m128i *)(tmp3 + x));
119 0 : const __m128i AB = _mm_unpacklo_epi8(A, B);
120 : __m128i C, D, CD;
121 0 : _mm_storeu_si128((__m128i *)(dst + x * 2), AB);
122 : {
123 0 : const __m128i a =
124 0 : _mm_loadl_epi64((const __m128i *)(src + x - src_stride * 3));
125 0 : const __m128i b =
126 0 : _mm_loadl_epi64((const __m128i *)(src + x - src_stride * 2));
127 0 : const __m128i c =
128 0 : _mm_loadl_epi64((const __m128i *)(src + x - src_stride * 1));
129 0 : const __m128i d =
130 0 : _mm_loadl_epi64((const __m128i *)(src + x + src_stride * 0));
131 0 : const __m128i e =
132 0 : _mm_loadl_epi64((const __m128i *)(src + x + src_stride * 1));
133 0 : const __m128i f =
134 0 : _mm_loadl_epi64((const __m128i *)(src + x + src_stride * 2));
135 0 : const __m128i g =
136 0 : _mm_loadl_epi64((const __m128i *)(src + x + src_stride * 3));
137 0 : const __m128i h =
138 0 : _mm_loadl_epi64((const __m128i *)(src + x + src_stride * 4));
139 0 : C = filter(&a, &b, &c, &d, &e, &f, &g, &h);
140 : }
141 : {
142 0 : const __m128i a = _mm_loadl_epi64((const __m128i *)(tmp0 + x));
143 0 : const __m128i b = _mm_loadl_epi64((const __m128i *)(tmp1 + x));
144 0 : const __m128i c = _mm_loadl_epi64((const __m128i *)(tmp2 + x));
145 0 : const __m128i d = _mm_loadl_epi64((const __m128i *)(tmp3 + x));
146 0 : const __m128i e = _mm_loadl_epi64((const __m128i *)(tmp4 + x));
147 0 : const __m128i f = _mm_loadl_epi64((const __m128i *)(tmp5 + x));
148 0 : const __m128i g = _mm_loadl_epi64((const __m128i *)(tmp6 + x));
149 0 : const __m128i h = _mm_loadl_epi64((const __m128i *)(tmp7 + x));
150 0 : D = filter(&a, &b, &c, &d, &e, &f, &g, &h);
151 : }
152 0 : CD = _mm_unpacklo_epi8(C, D);
153 0 : _mm_storeu_si128((__m128i *)(dst + x * 2 + dst_stride), CD);
154 : }
155 0 : src += src_stride;
156 0 : dst += dst_stride * 2;
157 0 : tmp8 = tmp0;
158 0 : tmp0 = tmp1;
159 0 : tmp1 = tmp2;
160 0 : tmp2 = tmp3;
161 0 : tmp3 = tmp4;
162 0 : tmp4 = tmp5;
163 0 : tmp5 = tmp6;
164 0 : tmp6 = tmp7;
165 0 : tmp7 = tmp8;
166 : }
167 : }
168 0 : }
169 :
170 0 : void vp9_scale_and_extend_frame_ssse3(const YV12_BUFFER_CONFIG *src,
171 : YV12_BUFFER_CONFIG *dst) {
172 0 : const int src_w = src->y_crop_width;
173 0 : const int src_h = src->y_crop_height;
174 0 : const int dst_w = dst->y_crop_width;
175 0 : const int dst_h = dst->y_crop_height;
176 0 : const int dst_uv_w = dst_w / 2;
177 0 : const int dst_uv_h = dst_h / 2;
178 :
179 0 : if (dst_w * 2 == src_w && dst_h * 2 == src_h) {
180 0 : downsample_2_to_1_ssse3(src->y_buffer, src->y_stride, dst->y_buffer,
181 0 : dst->y_stride, dst_w, dst_h);
182 0 : downsample_2_to_1_ssse3(src->u_buffer, src->uv_stride, dst->u_buffer,
183 0 : dst->uv_stride, dst_uv_w, dst_uv_h);
184 0 : downsample_2_to_1_ssse3(src->v_buffer, src->uv_stride, dst->v_buffer,
185 0 : dst->uv_stride, dst_uv_w, dst_uv_h);
186 0 : vpx_extend_frame_borders(dst);
187 0 : } else if (dst_w == src_w * 2 && dst_h == src_h * 2) {
188 : // The upsample() supports widths up to 1920 * 2. If greater, fall back
189 : // to vp9_scale_and_extend_frame_c().
190 0 : if (dst_w / 2 <= 1920) {
191 0 : upsample_1_to_2_ssse3(src->y_buffer, src->y_stride, dst->y_buffer,
192 0 : dst->y_stride, dst_w, dst_h);
193 0 : upsample_1_to_2_ssse3(src->u_buffer, src->uv_stride, dst->u_buffer,
194 0 : dst->uv_stride, dst_uv_w, dst_uv_h);
195 0 : upsample_1_to_2_ssse3(src->v_buffer, src->uv_stride, dst->v_buffer,
196 0 : dst->uv_stride, dst_uv_w, dst_uv_h);
197 0 : vpx_extend_frame_borders(dst);
198 : } else {
199 0 : vp9_scale_and_extend_frame_c(src, dst);
200 : }
201 : } else {
202 0 : vp9_scale_and_extend_frame_c(src, dst);
203 : }
204 0 : }
|