FFmpeg
h264chroma_init.c
Go to the documentation of this file.
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, const 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, const 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, const uint8_t *src,
33  ptrdiff_t stride, int h, int x, int y);
34 void ff_avg_h264_chroma_mc4_mmxext (uint8_t *dst, const 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, const uint8_t *src,
38  ptrdiff_t stride, int h, int x, int y);
39 void ff_avg_h264_chroma_mc2_mmxext (uint8_t *dst, const 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, const uint8_t *src,
43  ptrdiff_t stride, int h, int x, int y);
44 void ff_put_h264_chroma_mc4_ssse3 (uint8_t *dst, const 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, const uint8_t *src,
48  ptrdiff_t stride, int h, int x, int y);
49 void ff_avg_h264_chroma_mc4_ssse3 (uint8_t *dst, const 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, const 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 
67 {
68  int high_bit_depth = bit_depth > 8;
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 }
cpu.h
CHROMA_MC
#define CHROMA_MC(OP, NUM, DEPTH, OPT)
Definition: h264chroma_init.c:52
ff_put_h264_chroma_mc8_rnd_ssse3
void ff_put_h264_chroma_mc8_rnd_ssse3(uint8_t *dst, const uint8_t *src, ptrdiff_t stride, int h, int x, int y)
ff_h264chroma_init_x86
av_cold void ff_h264chroma_init_x86(H264ChromaContext *c, int bit_depth)
Definition: h264chroma_init.c:66
av_get_cpu_flags
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition: cpu.c:103
bit_depth
static void bit_depth(AudioStatsContext *s, const uint64_t *const mask, uint8_t *depth)
Definition: af_astats.c:245
cpu_flags
static atomic_int cpu_flags
Definition: cpu.c:52
av_cold
#define av_cold
Definition: attributes.h:90
ff_avg_h264_chroma_mc4_ssse3
void ff_avg_h264_chroma_mc4_ssse3(uint8_t *dst, const uint8_t *src, ptrdiff_t stride, int h, int x, int y)
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
ff_avg_h264_chroma_mc8_rnd_ssse3
void ff_avg_h264_chroma_mc8_rnd_ssse3(uint8_t *dst, const uint8_t *src, ptrdiff_t stride, int h, int x, int y)
ff_avg_h264_chroma_mc8_rnd_mmxext
void ff_avg_h264_chroma_mc8_rnd_mmxext(uint8_t *dst, const uint8_t *src, ptrdiff_t stride, int h, int x, int y)
cpu.h
h264chroma.h
avg
#define avg(a, b, c, d)
Definition: colorspacedsp_template.c:28
ff_avg_h264_chroma_mc4_mmxext
void ff_avg_h264_chroma_mc4_mmxext(uint8_t *dst, const uint8_t *src, ptrdiff_t stride, int h, int x, int y)
attributes.h
EXTERNAL_SSE2
#define EXTERNAL_SSE2(flags)
Definition: cpu.h:59
ff_put_h264_chroma_mc4_ssse3
void ff_put_h264_chroma_mc4_ssse3(uint8_t *dst, const uint8_t *src, ptrdiff_t stride, int h, int x, int y)
ff_put_h264_chroma_mc2_mmxext
void ff_put_h264_chroma_mc2_mmxext(uint8_t *dst, const uint8_t *src, ptrdiff_t stride, int h, int x, int y)
stride
#define stride
Definition: h264pred_template.c:537
ff_put_h264_chroma_mc4_mmx
void ff_put_h264_chroma_mc4_mmx(uint8_t *dst, const uint8_t *src, ptrdiff_t stride, int h, int x, int y)
EXTERNAL_AVX
#define EXTERNAL_AVX(flags)
Definition: cpu.h:70
ff_put_h264_chroma_mc8_rnd_mmx
void ff_put_h264_chroma_mc8_rnd_mmx(uint8_t *dst, const uint8_t *src, ptrdiff_t stride, int h, int x, int y)
H264ChromaContext
Definition: h264chroma.h:27
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
ff_avg_h264_chroma_mc2_mmxext
void ff_avg_h264_chroma_mc2_mmxext(uint8_t *dst, const uint8_t *src, ptrdiff_t stride, int h, int x, int y)
h
h
Definition: vp9dsp_template.c:2038
EXTERNAL_SSSE3
#define EXTERNAL_SSSE3(flags)
Definition: cpu.h:65
EXTERNAL_MMX
#define EXTERNAL_MMX(flags)
Definition: cpu.h:56
EXTERNAL_MMXEXT
#define EXTERNAL_MMXEXT(flags)
Definition: cpu.h:57