2 * Lossless video DSP utils
4 * This file is part of FFmpeg.
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "libavutil/x86/asm.h"
23 #include "../lossless_videodsp.h"
24 #include "libavutil/x86/cpu.h"
26 void ff_add_bytes_mmx(uint8_t *dst, uint8_t *src, ptrdiff_t w);
27 void ff_add_bytes_sse2(uint8_t *dst, uint8_t *src, ptrdiff_t w);
28 void ff_add_bytes_avx2(uint8_t *dst, uint8_t *src, ptrdiff_t w);
30 void ff_add_median_pred_mmxext(uint8_t *dst, const uint8_t *top,
31 const uint8_t *diff, ptrdiff_t w,
32 int *left, int *left_top);
33 void ff_add_median_pred_sse2(uint8_t *dst, const uint8_t *top,
34 const uint8_t *diff, ptrdiff_t w,
35 int *left, int *left_top);
37 int ff_add_left_pred_ssse3(uint8_t *dst, const uint8_t *src,
38 ptrdiff_t w, int left);
39 int ff_add_left_pred_unaligned_ssse3(uint8_t *dst, const uint8_t *src,
40 ptrdiff_t w, int left);
42 int ff_add_left_pred_int16_ssse3(uint16_t *dst, const uint16_t *src, unsigned mask, ptrdiff_t w, unsigned acc);
43 int ff_add_left_pred_int16_sse4(uint16_t *dst, const uint16_t *src, unsigned mask, ptrdiff_t w, unsigned acc);
45 #if HAVE_INLINE_ASM && HAVE_7REGS && ARCH_X86_32
46 static void add_median_pred_cmov(uint8_t *dst, const uint8_t *top,
47 const uint8_t *diff, ptrdiff_t w,
48 int *left, int *left_top)
53 int tl = *left_top & 0xff;
58 "movzbl (%3, %4), %2 \n"
71 "add (%6, %4), %b0 \n"
72 "mov %b0, (%5, %4) \n"
75 : "+&q"(l), "+&q"(tl), "=&r"(t), "=&q"(x), "+&r"(w2)
76 : "r"(dst + w), "r"(diff + w), "rm"(top + w)
83 void ff_llviddsp_init_x86(LLVidDSPContext *c)
85 int cpu_flags = av_get_cpu_flags();
87 #if HAVE_INLINE_ASM && HAVE_7REGS && ARCH_X86_32
88 if (cpu_flags & AV_CPU_FLAG_CMOV)
89 c->add_median_pred = add_median_pred_cmov;
92 if (ARCH_X86_32 && EXTERNAL_MMX(cpu_flags)) {
93 c->add_bytes = ff_add_bytes_mmx;
96 if (ARCH_X86_32 && EXTERNAL_MMXEXT(cpu_flags)) {
97 /* slower than cmov version on AMD */
98 if (!(cpu_flags & AV_CPU_FLAG_3DNOW))
99 c->add_median_pred = ff_add_median_pred_mmxext;
102 if (EXTERNAL_SSE2(cpu_flags)) {
103 c->add_bytes = ff_add_bytes_sse2;
104 c->add_median_pred = ff_add_median_pred_sse2;
107 if (EXTERNAL_SSSE3(cpu_flags)) {
108 c->add_left_pred = ff_add_left_pred_ssse3;
109 c->add_left_pred_int16 = ff_add_left_pred_int16_ssse3;
112 if (EXTERNAL_SSSE3_FAST(cpu_flags)) {
113 c->add_left_pred = ff_add_left_pred_unaligned_ssse3;
116 if (EXTERNAL_SSE4(cpu_flags)) {
117 c->add_left_pred_int16 = ff_add_left_pred_int16_sse4;
119 if (EXTERNAL_AVX2_FAST(cpu_flags)) {
120 c->add_bytes = ff_add_bytes_avx2;