1 /*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include <stdint.h>
20
21 #include "config.h"
22
23 #include "libavutil/attributes.h"
24 #include "libavutil/cpu.h"
25 #include "libavutil/x86/cpu.h"
26 #include "libavcodec/h264chroma.h"
27
28 void ff_put_h264_chroma_mc8_rnd_mmx (uint8_t *dst, uint8_t *src,
29 int stride, int h, int x, int y);
30 void ff_avg_h264_chroma_mc8_rnd_mmxext(uint8_t *dst, uint8_t *src,
31 int stride, int h, int x, int y);
32 void ff_avg_h264_chroma_mc8_rnd_3dnow(uint8_t *dst, uint8_t *src,
33 int stride, int h, int x, int y);
34
35 void ff_put_h264_chroma_mc4_mmx (uint8_t *dst, uint8_t *src,
36 int stride, int h, int x, int y);
37 void ff_avg_h264_chroma_mc4_mmxext (uint8_t *dst, uint8_t *src,
38 int stride, int h, int x, int y);
39 void ff_avg_h264_chroma_mc4_3dnow (uint8_t *dst, uint8_t *src,
40 int stride, int h, int x, int y);
41
42 void ff_put_h264_chroma_mc2_mmxext (uint8_t *dst, uint8_t *src,
43 int stride, int h, int x, int y);
44 void ff_avg_h264_chroma_mc2_mmxext (uint8_t *dst, uint8_t *src,
45 int stride, int h, int x, int y);
46
47 void ff_put_h264_chroma_mc8_rnd_ssse3(uint8_t *dst, uint8_t *src,
48 int stride, int h, int x, int y);
49 void ff_put_h264_chroma_mc4_ssse3 (uint8_t *dst, uint8_t *src,
50 int stride, int h, int x, int y);
51
52 void ff_avg_h264_chroma_mc8_rnd_ssse3(uint8_t *dst, uint8_t *src,
53 int stride, int h, int x, int y);
54 void ff_avg_h264_chroma_mc4_ssse3 (uint8_t *dst, uint8_t *src,
55 int stride, int h, int x, int y);
56
57 #define CHROMA_MC(OP, NUM, DEPTH, OPT) \
58 void ff_ ## OP ## _h264_chroma_mc ## NUM ## _ ## DEPTH ## _ ## OPT \
59 (uint8_t *dst, uint8_t *src, \
60 int stride, int h, int x, int y);
61
62 CHROMA_MC(put, 2, 10, mmxext)
63 CHROMA_MC(avg, 2, 10, mmxext)
64 CHROMA_MC(put, 4, 10, mmxext)
65 CHROMA_MC(avg, 4, 10, mmxext)
66 CHROMA_MC(put, 8, 10, sse2)
67 CHROMA_MC(avg, 8, 10, sse2)
68 CHROMA_MC(put, 8, 10, avx)
69 CHROMA_MC(avg, 8, 10, avx)
70
ff_h264chroma_init_x86(H264ChromaContext * c,int bit_depth)71 av_cold void ff_h264chroma_init_x86(H264ChromaContext *c, int bit_depth)
72 {
73 int high_bit_depth = bit_depth > 8;
74 int cpu_flags = av_get_cpu_flags();
75
76 #if (HAVE_MMX_EXTERNAL == 1)
77 if (EXTERNAL_MMX(cpu_flags) && !high_bit_depth) {
78 c->put_h264_chroma_pixels_tab[0] = ff_put_h264_chroma_mc8_rnd_mmx;
79 c->put_h264_chroma_pixels_tab[1] = ff_put_h264_chroma_mc4_mmx;
80 }
81 #endif
82
83 #if (HAVE_AMD3DNOW_EXTERNAL == 1)
84 if (EXTERNAL_AMD3DNOW(cpu_flags) && !high_bit_depth) {
85 c->avg_h264_chroma_pixels_tab[0] = ff_avg_h264_chroma_mc8_rnd_3dnow;
86 c->avg_h264_chroma_pixels_tab[1] = ff_avg_h264_chroma_mc4_3dnow;
87 }
88 #endif
89
90 #if (HAVE_MMXEXT_EXTERNAL == 1)
91 if (EXTERNAL_MMXEXT(cpu_flags) && !high_bit_depth) {
92 c->avg_h264_chroma_pixels_tab[0] = ff_avg_h264_chroma_mc8_rnd_mmxext;
93 c->avg_h264_chroma_pixels_tab[1] = ff_avg_h264_chroma_mc4_mmxext;
94 c->avg_h264_chroma_pixels_tab[2] = ff_avg_h264_chroma_mc2_mmxext;
95 c->put_h264_chroma_pixels_tab[2] = ff_put_h264_chroma_mc2_mmxext;
96 }
97
98 if (EXTERNAL_MMXEXT(cpu_flags) && bit_depth > 8 && bit_depth <= 10) {
99 c->put_h264_chroma_pixels_tab[2] = ff_put_h264_chroma_mc2_10_mmxext;
100 c->avg_h264_chroma_pixels_tab[2] = ff_avg_h264_chroma_mc2_10_mmxext;
101 c->put_h264_chroma_pixels_tab[1] = ff_put_h264_chroma_mc4_10_mmxext;
102 c->avg_h264_chroma_pixels_tab[1] = ff_avg_h264_chroma_mc4_10_mmxext;
103 }
104 #endif
105
106 #if (HAVE_SSE2_EXTERNAL == 1)
107 if (EXTERNAL_SSE2(cpu_flags) && bit_depth > 8 && bit_depth <= 10) {
108 c->put_h264_chroma_pixels_tab[0] = ff_put_h264_chroma_mc8_10_sse2;
109 c->avg_h264_chroma_pixels_tab[0] = ff_avg_h264_chroma_mc8_10_sse2;
110 }
111 #endif
112
113 #if (HAVE_SSSE3_EXTERNAL == 1)
114 if (EXTERNAL_SSSE3(cpu_flags) && !high_bit_depth) {
115 c->put_h264_chroma_pixels_tab[0] = ff_put_h264_chroma_mc8_rnd_ssse3;
116 c->avg_h264_chroma_pixels_tab[0] = ff_avg_h264_chroma_mc8_rnd_ssse3;
117 c->put_h264_chroma_pixels_tab[1] = ff_put_h264_chroma_mc4_ssse3;
118 c->avg_h264_chroma_pixels_tab[1] = ff_avg_h264_chroma_mc4_ssse3;
119 }
120 #endif
121
122 #if (HAVE_AVX_EXTERNAL == 1)
123 if (EXTERNAL_AVX(cpu_flags) && bit_depth > 8 && bit_depth <= 10) {
124 // AVX implies !cache64.
125 // TODO: Port cache(32|64) detection from x264.
126 c->put_h264_chroma_pixels_tab[0] = ff_put_h264_chroma_mc8_10_avx;
127 c->avg_h264_chroma_pixels_tab[0] = ff_avg_h264_chroma_mc8_10_avx;
128 }
129 #endif
130 }
131