comparison x86/vp8dsp-init.c @ 11975:c3afb5be0d9b libavcodec

First shot at VP8 optimizations: - MMXEXT, SSE2 and SSSE3 MC functions - MMX and SSE4 IDCT dc_add functions Patch by Jason Garrett-Glaser <darkshikari gmail com> and myself.
author rbultje
date Sun, 27 Jun 2010 02:01:45 +0000
parents
children 19374f2992bf
comparison
equal deleted inserted replaced
11974:356b20a6566d 11975:c3afb5be0d9b
1 /*
2 * VP8 DSP functions x86-optimized
3 * Copyright (c) 2010 Ronald S. Bultje <rsbultje@gmail.com>
4 * Copyright (c) 2010 Jason Garrett-Glaser <darkshikari@gmail.com>
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #include "libavutil/x86_cpu.h"
24 #include "libavcodec/vp8dsp.h"
25
26 /*
27 * MC functions
28 */
29 extern void ff_put_vp8_epel4_h4_mmxext(uint8_t *dst, int dststride,
30 uint8_t *src, int srcstride,
31 int height, int mx, int my);
32 extern void ff_put_vp8_epel4_h6_mmxext(uint8_t *dst, int dststride,
33 uint8_t *src, int srcstride,
34 int height, int mx, int my);
35 extern void ff_put_vp8_epel4_v4_mmxext(uint8_t *dst, int dststride,
36 uint8_t *src, int srcstride,
37 int height, int mx, int my);
38 extern void ff_put_vp8_epel4_v6_mmxext(uint8_t *dst, int dststride,
39 uint8_t *src, int srcstride,
40 int height, int mx, int my);
41
42 extern void ff_put_vp8_epel8_h4_sse2 (uint8_t *dst, int dststride,
43 uint8_t *src, int srcstride,
44 int height, int mx, int my);
45 extern void ff_put_vp8_epel8_h6_sse2 (uint8_t *dst, int dststride,
46 uint8_t *src, int srcstride,
47 int height, int mx, int my);
48 extern void ff_put_vp8_epel8_v4_sse2 (uint8_t *dst, int dststride,
49 uint8_t *src, int srcstride,
50 int height, int mx, int my);
51 extern void ff_put_vp8_epel8_v6_sse2 (uint8_t *dst, int dststride,
52 uint8_t *src, int srcstride,
53 int height, int mx, int my);
54
55 extern void ff_put_vp8_epel8_h4_ssse3 (uint8_t *dst, int dststride,
56 uint8_t *src, int srcstride,
57 int height, int mx, int my);
58 extern void ff_put_vp8_epel8_h6_ssse3 (uint8_t *dst, int dststride,
59 uint8_t *src, int srcstride,
60 int height, int mx, int my);
61 extern void ff_put_vp8_epel8_v4_ssse3 (uint8_t *dst, int dststride,
62 uint8_t *src, int srcstride,
63 int height, int mx, int my);
64 extern void ff_put_vp8_epel8_v6_ssse3 (uint8_t *dst, int dststride,
65 uint8_t *src, int srcstride,
66 int height, int mx, int my);
67
68 #define TAP_W16(OPT, TAPTYPE) \
69 static void ff_put_vp8_epel16_ ## TAPTYPE ## _ ## OPT(uint8_t *dst, \
70 int dststride, \
71 uint8_t *src, \
72 int srcstride, \
73 int height, \
74 int mx, int my) \
75 { \
76 ff_put_vp8_epel8_ ## TAPTYPE ## _ ## OPT(dst, dststride, \
77 src, srcstride, \
78 height, mx, my); \
79 ff_put_vp8_epel8_ ## TAPTYPE ## _ ## OPT(dst + 8, dststride, \
80 src + 8, srcstride, \
81 height, mx, my); \
82 }
83 #define TAP_W8(OPT, TAPTYPE) \
84 static void ff_put_vp8_epel8_ ## TAPTYPE ## _ ## OPT(uint8_t *dst, \
85 int dststride, \
86 uint8_t *src, \
87 int srcstride, \
88 int height, \
89 int mx, int my) \
90 { \
91 ff_put_vp8_epel4_ ## TAPTYPE ## _ ## OPT(dst, dststride, \
92 src, srcstride, \
93 height, mx, my); \
94 ff_put_vp8_epel4_ ## TAPTYPE ## _ ## OPT(dst + 4, dststride, \
95 src + 4, srcstride, \
96 height, mx, my); \
97 }
98
99 TAP_W8 (mmxext, h4)
100 TAP_W8 (mmxext, h6)
101 TAP_W16(mmxext, h6)
102 TAP_W8 (mmxext, v4)
103 TAP_W8 (mmxext, v6)
104 TAP_W16(mmxext, v6)
105
106 TAP_W16(sse2, h6)
107 TAP_W16(sse2, v6)
108
109 TAP_W16(ssse3, h6)
110 TAP_W16(ssse3, v6)
111
112 #define HVTAP(OPT, ALIGN, TAPNUMX, TAPNUMY, SIZE, MAXHEIGHT) \
113 static void ff_put_vp8_epel ## SIZE ## _h ## TAPNUMX ## v ## TAPNUMY ## _ ## OPT \
114 (uint8_t *dst, int dststride, \
115 uint8_t *src, int srcstride, \
116 int height, int mx, int my) \
117 { \
118 DECLARE_ALIGNED(ALIGN, uint8_t, tmp)[SIZE * (MAXHEIGHT + TAPNUMY - 1)]; \
119 uint8_t *tmpptr = tmp + SIZE * (TAPNUMY / 2 - 1); \
120 src -= srcstride * (TAPNUMY / 2 - 1); \
121 ff_put_vp8_epel ## SIZE ## _h ## TAPNUMX ## _ ## OPT(tmp, SIZE, \
122 src, srcstride, \
123 height + TAPNUMY - 1, \
124 mx, my); \
125 ff_put_vp8_epel ## SIZE ## _v ## TAPNUMY ## _ ## OPT(dst, dststride, \
126 tmpptr, SIZE, \
127 height, mx, my); \
128 }
129
130 #define HVTAPMMX(x, y) \
131 HVTAP(mmxext, 8, x, y, 4, 8) \
132 HVTAP(mmxext, 8, x, y, 8, 16)
133
134 HVTAPMMX(4, 4)
135 HVTAPMMX(4, 6)
136 HVTAPMMX(6, 4)
137 HVTAPMMX(6, 6)
138 HVTAP(mmxext, 8, 6, 6, 16, 16)
139
140 #define HVTAPSSE2(x, y, w) \
141 HVTAP(sse2, 16, x, y, w, 16) \
142 HVTAP(ssse3, 16, x, y, w, 16)
143
144 HVTAPSSE2(4, 4, 8)
145 HVTAPSSE2(4, 6, 8)
146 HVTAPSSE2(6, 4, 8)
147 HVTAPSSE2(6, 6, 8)
148 HVTAPSSE2(6, 6, 16)
149
150 extern void ff_vp8_idct_dc_add_mmx(uint8_t *dst, DCTELEM block[16], int stride);
151 extern void ff_vp8_idct_dc_add_sse4(uint8_t *dst, DCTELEM block[16], int stride);
152
153 av_cold void ff_vp8dsp_init_x86(VP8DSPContext* c)
154 {
155 mm_flags = mm_support();
156
157 if (mm_flags & FF_MM_MMX) {
158 c->vp8_idct_dc_add = ff_vp8_idct_dc_add_mmx;
159 }
160
161 /* note that 4-tap width=16 functions are missing because w=16
162 * is only used for luma, and luma is always a copy or sixtap. */
163 if (mm_flags & FF_MM_MMXEXT) {
164 c->put_vp8_epel_pixels_tab[0][0][2] = ff_put_vp8_epel16_h6_mmxext;
165 c->put_vp8_epel_pixels_tab[0][2][0] = ff_put_vp8_epel16_v6_mmxext;
166 c->put_vp8_epel_pixels_tab[0][2][2] = ff_put_vp8_epel16_h6v6_mmxext;
167 c->put_vp8_epel_pixels_tab[1][0][1] = ff_put_vp8_epel8_h4_mmxext;
168 c->put_vp8_epel_pixels_tab[1][0][2] = ff_put_vp8_epel8_h6_mmxext;
169 c->put_vp8_epel_pixels_tab[1][1][0] = ff_put_vp8_epel8_v4_mmxext;
170 c->put_vp8_epel_pixels_tab[1][1][1] = ff_put_vp8_epel8_h4v4_mmxext;
171 c->put_vp8_epel_pixels_tab[1][1][2] = ff_put_vp8_epel8_h6v4_mmxext;
172 c->put_vp8_epel_pixels_tab[1][2][0] = ff_put_vp8_epel8_v6_mmxext;
173 c->put_vp8_epel_pixels_tab[1][2][1] = ff_put_vp8_epel8_h4v6_mmxext;
174 c->put_vp8_epel_pixels_tab[1][2][2] = ff_put_vp8_epel8_h6v6_mmxext;
175 c->put_vp8_epel_pixels_tab[2][0][1] = ff_put_vp8_epel4_h4_mmxext;
176 c->put_vp8_epel_pixels_tab[2][0][2] = ff_put_vp8_epel4_h6_mmxext;
177 c->put_vp8_epel_pixels_tab[2][1][0] = ff_put_vp8_epel4_v4_mmxext;
178 c->put_vp8_epel_pixels_tab[2][1][1] = ff_put_vp8_epel4_h4v4_mmxext;
179 c->put_vp8_epel_pixels_tab[2][1][2] = ff_put_vp8_epel4_h6v4_mmxext;
180 c->put_vp8_epel_pixels_tab[2][2][0] = ff_put_vp8_epel4_v6_mmxext;
181 c->put_vp8_epel_pixels_tab[2][2][1] = ff_put_vp8_epel4_h4v6_mmxext;
182 c->put_vp8_epel_pixels_tab[2][2][2] = ff_put_vp8_epel4_h6v6_mmxext;
183 }
184
185 if (mm_flags & FF_MM_SSE2) {
186 c->put_vp8_epel_pixels_tab[0][0][2] = ff_put_vp8_epel16_h6_sse2;
187 c->put_vp8_epel_pixels_tab[0][2][0] = ff_put_vp8_epel16_v6_sse2;
188 c->put_vp8_epel_pixels_tab[0][2][2] = ff_put_vp8_epel16_h6v6_sse2;
189 c->put_vp8_epel_pixels_tab[1][0][1] = ff_put_vp8_epel8_h4_sse2;
190 c->put_vp8_epel_pixels_tab[1][0][2] = ff_put_vp8_epel8_h6_sse2;
191 c->put_vp8_epel_pixels_tab[1][1][0] = ff_put_vp8_epel8_v4_sse2;
192 c->put_vp8_epel_pixels_tab[1][1][1] = ff_put_vp8_epel8_h4v4_sse2;
193 c->put_vp8_epel_pixels_tab[1][1][2] = ff_put_vp8_epel8_h6v4_sse2;
194 c->put_vp8_epel_pixels_tab[1][2][0] = ff_put_vp8_epel8_v6_sse2;
195 c->put_vp8_epel_pixels_tab[1][2][1] = ff_put_vp8_epel8_h4v6_sse2;
196 c->put_vp8_epel_pixels_tab[1][2][2] = ff_put_vp8_epel8_h6v6_sse2;
197 }
198
199 if (mm_flags & FF_MM_SSSE3) {
200 c->put_vp8_epel_pixels_tab[0][0][2] = ff_put_vp8_epel16_h6_ssse3;
201 c->put_vp8_epel_pixels_tab[0][2][0] = ff_put_vp8_epel16_v6_ssse3;
202 c->put_vp8_epel_pixels_tab[0][2][2] = ff_put_vp8_epel16_h6v6_ssse3;
203 c->put_vp8_epel_pixels_tab[1][0][1] = ff_put_vp8_epel8_h4_ssse3;
204 c->put_vp8_epel_pixels_tab[1][0][2] = ff_put_vp8_epel8_h6_ssse3;
205 c->put_vp8_epel_pixels_tab[1][1][0] = ff_put_vp8_epel8_v4_ssse3;
206 c->put_vp8_epel_pixels_tab[1][1][1] = ff_put_vp8_epel8_h4v4_ssse3;
207 c->put_vp8_epel_pixels_tab[1][1][2] = ff_put_vp8_epel8_h6v4_ssse3;
208 c->put_vp8_epel_pixels_tab[1][2][0] = ff_put_vp8_epel8_v6_ssse3;
209 c->put_vp8_epel_pixels_tab[1][2][1] = ff_put_vp8_epel8_h4v6_ssse3;
210 c->put_vp8_epel_pixels_tab[1][2][2] = ff_put_vp8_epel8_h6v6_ssse3;
211 }
212
213 if (mm_flags & FF_MM_SSE4) {
214 c->vp8_idct_dc_add = ff_vp8_idct_dc_add_sse4;
215 }
216 }