2 * This file is part of FFmpeg.
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.
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.
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
19 #include "libavutil/cpu.h"
20 #include "libavutil/x86/cpu.h"
21 #include "libavfilter/scene_sad.h"
23 #define SCENE_SAD_FUNC(FUNC_NAME, ASM_FUNC_NAME, MMSIZE) \
24 void ASM_FUNC_NAME(SCENE_SAD_PARAMS); \
26 static void FUNC_NAME(SCENE_SAD_PARAMS) { \
27 uint64_t sad[MMSIZE / 8] = {0}; \
28 ptrdiff_t awidth = width & ~(MMSIZE - 1); \
30 ASM_FUNC_NAME(src1, stride1, src2, stride2, awidth, height, sad); \
31 for (int i = 0; i < MMSIZE / 8; i++) \
33 ff_scene_sad_c(src1 + awidth, stride1, \
34 src2 + awidth, stride2, \
35 width - awidth, height, sad); \
40 SCENE_SAD_FUNC(scene_sad_sse2, ff_scene_sad_sse2, 16)
41 #if HAVE_AVX2_EXTERNAL
42 SCENE_SAD_FUNC(scene_sad_avx2, ff_scene_sad_avx2, 32)
46 ff_scene_sad_fn ff_scene_sad_get_fn_x86(int depth)
49 int cpu_flags = av_get_cpu_flags();
51 #if HAVE_AVX2_EXTERNAL
52 if (EXTERNAL_AVX2_FAST(cpu_flags))
53 return scene_sad_avx2;
55 if (EXTERNAL_SSE2(cpu_flags))
56 return scene_sad_sse2;