FFmpeg
Loading...
Searching...
No Matches
scene_sad_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/cpu.h"
20#include "libavutil/x86/cpu.h"
22
23#define SCENE_SAD_FUNC(FUNC_NAME, ASM_FUNC_NAME, MMSIZE) \
24void ASM_FUNC_NAME(SCENE_SAD_PARAMS); \
25 \
26static void FUNC_NAME(SCENE_SAD_PARAMS) { \
27 uint64_t sad[MMSIZE / 8] = {0}; \
28 ptrdiff_t awidth = width & ~(MMSIZE - 1); \
29 *sum = 0; \
30 ASM_FUNC_NAME(src1, stride1, src2, stride2, awidth, height, sad); \
31 for (int i = 0; i < MMSIZE / 8; i++) \
32 *sum += sad[i]; \
33 ff_scene_sad_c(src1 + awidth, stride1, \
34 src2 + awidth, stride2, \
35 width - awidth, height, sad); \
36 *sum += sad[0]; \
37}
38
39#define SCENE_SAD16_FUNC(FUNC_NAME, ASM_FUNC_NAME, MMSIZE) \
40void ASM_FUNC_NAME(SCENE_SAD_PARAMS); \
41 \
42static void FUNC_NAME(SCENE_SAD_PARAMS) { \
43 uint64_t sad[MMSIZE / 8] = {0}; \
44 ptrdiff_t bytes = (width << 1) & ~(MMSIZE - 1); \
45 *sum = 0; \
46 ASM_FUNC_NAME(src1, stride1, src2, stride2, bytes, height, sad); \
47 for (int i = 0; i < MMSIZE / 8; i++) \
48 *sum += sad[i]; \
49 ff_scene_sad16_c(src1 + bytes, stride1, \
50 src2 + bytes, stride2, \
51 width - (bytes >> 1), height, sad); \
52 *sum += sad[0]; \
53}
54
55SCENE_SAD_FUNC(scene_sad_sse2, ff_scene_sad8_sse2, 16)
56#if HAVE_AVX2_EXTERNAL
57SCENE_SAD_FUNC(scene_sad_avx2, ff_scene_sad8_avx2, 32)
58SCENE_SAD16_FUNC(scene_sad16_avx2, ff_scene_sad16_avx2, 32)
59#endif
60#if HAVE_AVX512_EXTERNAL
61SCENE_SAD_FUNC(scene_sad_avx512, ff_scene_sad8_avx512, 64)
62SCENE_SAD16_FUNC(scene_sad16_avx512, ff_scene_sad16_avx512, 64)
63#endif
64
66{
68 if (depth <= 8) {
69#if HAVE_AVX512_EXTERNAL
71 return scene_sad_avx512;
72#endif
73#if HAVE_AVX2_EXTERNAL
75 return scene_sad_avx2;
76#endif
78 return scene_sad_sse2;
79 } else if (depth < 16) { /* this routine is only safe up to 15 bits */
80#if HAVE_AVX512_EXTERNAL
82 return scene_sad16_avx512;
83#endif
84#if HAVE_AVX2_EXTERNAL
86 return scene_sad16_avx2;
87#endif
88 }
89 return NULL;
90}
#define NULL
Definition coverity.c:32
static atomic_int cpu_flags
Definition cpu.c:56
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition cpu.c:109
#define EXTERNAL_AVX2_FAST(flags)
Definition cpu.h:73
#define EXTERNAL_AVX512(flags)
Definition cpu.h:77
#define EXTERNAL_SSE2(flags)
Definition cpu.h:53
Scene SAD functions.
void(* ff_scene_sad_fn)(SCENE_SAD_PARAMS)
Definition scene_sad.h:34
ff_scene_sad_fn ff_scene_sad_get_fn_x86(int depth)
#define SCENE_SAD16_FUNC(FUNC_NAME, ASM_FUNC_NAME, MMSIZE)
#define SCENE_SAD_FUNC(FUNC_NAME, ASM_FUNC_NAME, MMSIZE)