threadprogress: reorder instructions to fix race.
[ffmpeg.git] / libavcodec / x86 / lossless_videoencdsp_init.c
blob22a4014ef19753c16d650785c7775d1f69200535
1 /*
2 * SIMD-optimized lossless video encoding functions
3 * Copyright (c) 2000, 2001 Fabrice Bellard
4 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
6 * MMX optimization by Nick Kurshev <nickols_k@mail.ru>
8 * This file is part of FFmpeg.
10 * FFmpeg is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * FFmpeg is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with FFmpeg; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 #include "libavutil/attributes.h"
26 #include "libavutil/cpu.h"
27 #include "libavutil/x86/asm.h"
28 #include "libavutil/x86/cpu.h"
29 #include "libavcodec/lossless_videoencdsp.h"
30 #include "libavcodec/mathops.h"
32 void ff_diff_bytes_sse2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2,
33 intptr_t w);
34 void ff_diff_bytes_avx2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2,
35 intptr_t w);
37 void ff_sub_left_predict_avx(uint8_t *dst, const uint8_t *src,
38 ptrdiff_t stride, ptrdiff_t width, int height);
40 #if HAVE_INLINE_ASM
42 static void sub_median_pred_mmxext(uint8_t *dst, const uint8_t *src1,
43 const uint8_t *src2, intptr_t w,
44 int *left, int *left_top)
46 x86_reg i = 0;
47 uint8_t l, lt;
49 __asm__ volatile (
50 "movq (%1, %0), %%mm0 \n\t" // LT
51 "psllq $8, %%mm0 \n\t"
52 "1: \n\t"
53 "movq (%1, %0), %%mm1 \n\t" // T
54 "movq -1(%2, %0), %%mm2 \n\t" // L
55 "movq (%2, %0), %%mm3 \n\t" // X
56 "movq %%mm2, %%mm4 \n\t" // L
57 "psubb %%mm0, %%mm2 \n\t"
58 "paddb %%mm1, %%mm2 \n\t" // L + T - LT
59 "movq %%mm4, %%mm5 \n\t" // L
60 "pmaxub %%mm1, %%mm4 \n\t" // max(T, L)
61 "pminub %%mm5, %%mm1 \n\t" // min(T, L)
62 "pminub %%mm2, %%mm4 \n\t"
63 "pmaxub %%mm1, %%mm4 \n\t"
64 "psubb %%mm4, %%mm3 \n\t" // dst - pred
65 "movq %%mm3, (%3, %0) \n\t"
66 "add $8, %0 \n\t"
67 "movq -1(%1, %0), %%mm0 \n\t" // LT
68 "cmp %4, %0 \n\t"
69 " jb 1b \n\t"
70 : "+r" (i)
71 : "r" (src1), "r" (src2), "r" (dst), "r" ((x86_reg) w));
73 l = *left;
74 lt = *left_top;
76 dst[0] = src2[0] - mid_pred(l, src1[0], (l + src1[0] - lt) & 0xFF);
78 *left_top = src1[w - 1];
79 *left = src2[w - 1];
82 #endif /* HAVE_INLINE_ASM */
84 av_cold void ff_llvidencdsp_init_x86(LLVidEncDSPContext *c)
86 av_unused int cpu_flags = av_get_cpu_flags();
88 #if HAVE_INLINE_ASM
89 if (INLINE_MMXEXT(cpu_flags)) {
90 c->sub_median_pred = sub_median_pred_mmxext;
92 #endif /* HAVE_INLINE_ASM */
94 if (EXTERNAL_SSE2(cpu_flags)) {
95 c->diff_bytes = ff_diff_bytes_sse2;
98 if (EXTERNAL_AVX(cpu_flags)) {
99 c->sub_left_predict = ff_sub_left_predict_avx;
102 if (EXTERNAL_AVX2_FAST(cpu_flags)) {
103 c->diff_bytes = ff_diff_bytes_avx2;