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 #include "libavutil/attributes.h"
23 #include "libavutil/cpu.h"
24 #include "libavutil/x86/cpu.h"
25 #include "libavcodec/h264chroma.h"
26
27 void ff_put_h264_chroma_mc8_rnd_mmx (uint8_t *dst, uint8_t *src,
28 ptrdiff_t stride, int h, int x, int y);
29 void ff_avg_h264_chroma_mc8_rnd_mmxext(uint8_t *dst, uint8_t *src,
30 ptrdiff_t stride, int h, int x, int y);
31
32 void ff_put_h264_chroma_mc4_mmx (uint8_t *dst, uint8_t *src,
33 ptrdiff_t stride, int h, int x, int y);
34 void ff_avg_h264_chroma_mc4_mmxext (uint8_t *dst, uint8_t *src,
35 ptrdiff_t stride, int h, int x, int y);
36
37 void ff_put_h264_chroma_mc2_mmxext (uint8_t *dst, uint8_t *src,
38 ptrdiff_t stride, int h, int x, int y);
39 void ff_avg_h264_chroma_mc2_mmxext (uint8_t *dst, uint8_t *src,
40 ptrdiff_t stride, int h, int x, int y);
41
42 void ff_put_h264_chroma_mc8_rnd_ssse3(uint8_t *dst, uint8_t *src,
43 ptrdiff_t stride, int h, int x, int y);
44 void ff_put_h264_chroma_mc4_ssse3 (uint8_t *dst, uint8_t *src,
45 ptrdiff_t stride, int h, int x, int y);
46
47 void ff_avg_h264_chroma_mc8_rnd_ssse3(uint8_t *dst, uint8_t *src,
48 ptrdiff_t stride, int h, int x, int y);
49 void ff_avg_h264_chroma_mc4_ssse3 (uint8_t *dst, uint8_t *src,
50 ptrdiff_t stride, int h, int x, int y);
51
52 #define CHROMA_MC(OP, NUM, DEPTH, OPT) \
53 void ff_ ## OP ## _h264_chroma_mc ## NUM ## _ ## DEPTH ## _ ## OPT \
54 (uint8_t *dst, uint8_t *src, \
55 ptrdiff_t stride, int h, int x, int y);
56
57 CHROMA_MC(put, 2, 10, mmxext)
58 CHROMA_MC(avg, 2, 10, mmxext)
59 CHROMA_MC(put, 4, 10, mmxext)
60 CHROMA_MC(avg, 4, 10, mmxext)
61 CHROMA_MC(put, 8, 10, sse2)
62 CHROMA_MC(avg, 8, 10, sse2)
63 CHROMA_MC(put, 8, 10, avx)
64 CHROMA_MC(avg, 8, 10, avx)
65
ff_h264chroma_init_x86(H264ChromaContext *c, int bit_depth)66 av_cold void ff_h264chroma_init_x86(H264ChromaContext *c, int bit_depth)
67 {
68 int high_bit_depth = bit_depth > 8;
69 int cpu_flags = av_get_cpu_flags();
70
71 if (EXTERNAL_MMX(cpu_flags) && !high_bit_depth) {
72 c->put_h264_chroma_pixels_tab[0] = ff_put_h264_chroma_mc8_rnd_mmx;
73 c->put_h264_chroma_pixels_tab[1] = ff_put_h264_chroma_mc4_mmx;
74 }
75
76 if (EXTERNAL_MMXEXT(cpu_flags) && !high_bit_depth) {
77 c->avg_h264_chroma_pixels_tab[0] = ff_avg_h264_chroma_mc8_rnd_mmxext;
78 c->avg_h264_chroma_pixels_tab[1] = ff_avg_h264_chroma_mc4_mmxext;
79 c->avg_h264_chroma_pixels_tab[2] = ff_avg_h264_chroma_mc2_mmxext;
80 c->put_h264_chroma_pixels_tab[2] = ff_put_h264_chroma_mc2_mmxext;
81 }
82
83 if (EXTERNAL_MMXEXT(cpu_flags) && bit_depth > 8 && bit_depth <= 10) {
84 c->put_h264_chroma_pixels_tab[2] = ff_put_h264_chroma_mc2_10_mmxext;
85 c->avg_h264_chroma_pixels_tab[2] = ff_avg_h264_chroma_mc2_10_mmxext;
86 c->put_h264_chroma_pixels_tab[1] = ff_put_h264_chroma_mc4_10_mmxext;
87 c->avg_h264_chroma_pixels_tab[1] = ff_avg_h264_chroma_mc4_10_mmxext;
88 }
89
90 if (EXTERNAL_SSE2(cpu_flags) && bit_depth > 8 && bit_depth <= 10) {
91 c->put_h264_chroma_pixels_tab[0] = ff_put_h264_chroma_mc8_10_sse2;
92 c->avg_h264_chroma_pixels_tab[0] = ff_avg_h264_chroma_mc8_10_sse2;
93 }
94
95 if (EXTERNAL_SSSE3(cpu_flags) && !high_bit_depth) {
96 c->put_h264_chroma_pixels_tab[0] = ff_put_h264_chroma_mc8_rnd_ssse3;
97 c->avg_h264_chroma_pixels_tab[0] = ff_avg_h264_chroma_mc8_rnd_ssse3;
98 c->put_h264_chroma_pixels_tab[1] = ff_put_h264_chroma_mc4_ssse3;
99 c->avg_h264_chroma_pixels_tab[1] = ff_avg_h264_chroma_mc4_ssse3;
100 }
101
102 if (EXTERNAL_AVX(cpu_flags) && bit_depth > 8 && bit_depth <= 10) {
103 // AVX implies !cache64.
104 // TODO: Port cache(32|64) detection from x264.
105 c->put_h264_chroma_pixels_tab[0] = ff_put_h264_chroma_mc8_10_avx;
106 c->avg_h264_chroma_pixels_tab[0] = ff_avg_h264_chroma_mc8_10_avx;
107 }
108 }
109