FFmpeg
vf_idet_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 "libavutil/attributes.h"
20 #include "libavutil/cpu.h"
21 #include "libavutil/x86/asm.h"
22 #include "libavutil/x86/cpu.h"
23 #include "libavfilter/vf_idet.h"
24 
25 #if HAVE_X86ASM
26 
27 /* declares main callable idet_filter_line_{mmx,mmxext,sse2}() */
28 #define FUNC_MAIN_DECL(KIND, SPAN) \
29 int ff_idet_filter_line_##KIND(const uint8_t *a, const uint8_t *b, \
30  const uint8_t *c, int w); \
31 static int idet_filter_line_##KIND(const uint8_t *a, const uint8_t *b, \
32  const uint8_t *c, int w) { \
33  int sum = 0; \
34  const int left_over = w & (SPAN - 1); \
35  w -= left_over; \
36  if (w > 0) \
37  sum += ff_idet_filter_line_##KIND(a, b, c, w); \
38  if (left_over > 0) \
39  sum += ff_idet_filter_line_c(a + w, b + w, c + w, left_over); \
40  return sum; \
41 }
42 
43 
44 #define FUNC_MAIN_DECL_16bit(KIND, SPAN) \
45 int ff_idet_filter_line_16bit_##KIND(const uint16_t *a, const uint16_t *b, \
46  const uint16_t *c, int w); \
47 static int idet_filter_line_16bit_##KIND(const uint16_t *a, const uint16_t *b, \
48  const uint16_t *c, int w) { \
49  int sum = 0; \
50  const int left_over = w & (SPAN - 1); \
51  w -= left_over; \
52  if (w > 0) \
53  sum += ff_idet_filter_line_16bit_##KIND(a, b, c, w); \
54  if (left_over > 0) \
55  sum += ff_idet_filter_line_c_16bit(a + w, b + w, c + w, left_over); \
56  return sum; \
57 }
58 
59 FUNC_MAIN_DECL(sse2, 16)
60 FUNC_MAIN_DECL_16bit(sse2, 8)
61 #if ARCH_X86_32
62 FUNC_MAIN_DECL(mmx, 8)
63 FUNC_MAIN_DECL(mmxext, 8)
64 FUNC_MAIN_DECL_16bit(mmx, 4)
65 #endif
66 
67 #endif
68 av_cold void ff_idet_init_x86(IDETContext *idet, int for_16b)
69 {
70 #if HAVE_X86ASM
71  const int cpu_flags = av_get_cpu_flags();
72 
73 #if ARCH_X86_32
74  if (EXTERNAL_MMX(cpu_flags)) {
75  idet->filter_line = for_16b ? (ff_idet_filter_func)idet_filter_line_16bit_mmx : idet_filter_line_mmx;
76  }
78  idet->filter_line = for_16b ? (ff_idet_filter_func)idet_filter_line_16bit_mmx : idet_filter_line_mmxext;
79  }
80 #endif // ARCH_x86_32
81 
82  if (EXTERNAL_SSE2(cpu_flags)) {
83  idet->filter_line = for_16b ? (ff_idet_filter_func)idet_filter_line_16bit_sse2 : idet_filter_line_sse2;
84  }
85 #endif // HAVE_X86ASM
86 }
cpu.h
IDETContext::filter_line
ff_idet_filter_func filter_line
Definition: vf_idet.h:64
av_get_cpu_flags
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition: cpu.c:96
cpu_flags
static atomic_int cpu_flags
Definition: cpu.c:50
IDETContext
Definition: vf_idet.h:42
vf_idet.h
av_cold
#define av_cold
Definition: attributes.h:90
ff_idet_init_x86
av_cold void ff_idet_init_x86(IDETContext *idet, int for_16b)
Definition: vf_idet_init.c:68
cpu.h
asm.h
ff_idet_filter_func
int(* ff_idet_filter_func)(const uint8_t *a, const uint8_t *b, const uint8_t *c, int w)
Definition: vf_idet.h:27
attributes.h
EXTERNAL_SSE2
#define EXTERNAL_SSE2(flags)
Definition: cpu.h:59
EXTERNAL_MMX
#define EXTERNAL_MMX(flags)
Definition: cpu.h:56
EXTERNAL_MMXEXT
#define EXTERNAL_MMXEXT(flags)
Definition: cpu.h:57