FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
lossless_videoencdsp_init.c
Go to the documentation of this file.
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>
5  *
6  * MMX optimization by Nick Kurshev <nickols_k@mail.ru>
7  *
8  * This file is part of FFmpeg.
9  *
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.
14  *
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.
19  *
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
23  */
24 
25 #include "libavutil/attributes.h"
26 #include "libavutil/cpu.h"
27 #include "libavutil/x86/asm.h"
28 #include "libavutil/x86/cpu.h"
30 #include "libavcodec/mathops.h"
31 
32 void ff_diff_bytes_mmx(uint8_t *dst, const uint8_t *src1, const uint8_t *src2,
33  intptr_t w);
34 void ff_diff_bytes_sse2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2,
35  intptr_t w);
36 void ff_diff_bytes_avx2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2,
37  intptr_t w);
38 
40  ptrdiff_t stride, ptrdiff_t width, int height);
41 
42 #if HAVE_INLINE_ASM
43 
44 static void sub_median_pred_mmxext(uint8_t *dst, const uint8_t *src1,
45  const uint8_t *src2, intptr_t w,
46  int *left, int *left_top)
47 {
48  x86_reg i = 0;
49  uint8_t l, lt;
50 
51  __asm__ volatile (
52  "movq (%1, %0), %%mm0 \n\t" // LT
53  "psllq $8, %%mm0 \n\t"
54  "1: \n\t"
55  "movq (%1, %0), %%mm1 \n\t" // T
56  "movq -1(%2, %0), %%mm2 \n\t" // L
57  "movq (%2, %0), %%mm3 \n\t" // X
58  "movq %%mm2, %%mm4 \n\t" // L
59  "psubb %%mm0, %%mm2 \n\t"
60  "paddb %%mm1, %%mm2 \n\t" // L + T - LT
61  "movq %%mm4, %%mm5 \n\t" // L
62  "pmaxub %%mm1, %%mm4 \n\t" // max(T, L)
63  "pminub %%mm5, %%mm1 \n\t" // min(T, L)
64  "pminub %%mm2, %%mm4 \n\t"
65  "pmaxub %%mm1, %%mm4 \n\t"
66  "psubb %%mm4, %%mm3 \n\t" // dst - pred
67  "movq %%mm3, (%3, %0) \n\t"
68  "add $8, %0 \n\t"
69  "movq -1(%1, %0), %%mm0 \n\t" // LT
70  "cmp %4, %0 \n\t"
71  " jb 1b \n\t"
72  : "+r" (i)
73  : "r" (src1), "r" (src2), "r" (dst), "r" ((x86_reg) w));
74 
75  l = *left;
76  lt = *left_top;
77 
78  dst[0] = src2[0] - mid_pred(l, src1[0], (l + src1[0] - lt) & 0xFF);
79 
80  *left_top = src1[w - 1];
81  *left = src2[w - 1];
82 }
83 
84 #endif /* HAVE_INLINE_ASM */
85 
87 {
89 
90  if (ARCH_X86_32 && EXTERNAL_MMX(cpu_flags)) {
92  }
93 
94 #if HAVE_INLINE_ASM
95  if (INLINE_MMXEXT(cpu_flags)) {
96  c->sub_median_pred = sub_median_pred_mmxext;
97  }
98 #endif /* HAVE_INLINE_ASM */
99 
100  if (EXTERNAL_SSE2(cpu_flags)) {
102  }
103 
104  if (EXTERNAL_AVX(cpu_flags)) {
106  }
107 
108  if (EXTERNAL_AVX2_FAST(cpu_flags)) {
110  }
111 }
#define EXTERNAL_MMX(flags)
Definition: cpu.h:56
void ff_diff_bytes_mmx(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, intptr_t w)
static atomic_int cpu_flags
Definition: cpu.c:50
#define src
Definition: vp8dsp.c:254
Macro definitions for various function/variable attributes.
void(* diff_bytes)(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, intptr_t w)
av_cold void ff_llvidencdsp_init_x86(LLVidEncDSPContext *c)
uint8_t
#define av_cold
Definition: attributes.h:82
#define height
void ff_diff_bytes_avx2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, intptr_t w)
#define EXTERNAL_SSE2(flags)
Definition: cpu.h:59
#define EXTERNAL_AVX2_FAST(flags)
Definition: cpu.h:79
uint16_t width
Definition: gdv.c:47
void(* sub_median_pred)(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, intptr_t w, int *left, int *left_top)
Subtract HuffYUV's variant of median prediction.
uint8_t w
Definition: llviddspenc.c:38
void(* sub_left_predict)(uint8_t *dst, uint8_t *src, ptrdiff_t stride, ptrdiff_t width, int height)
#define src1
Definition: h264pred.c:139
#define mid_pred
Definition: mathops.h:97
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition: cpu.c:93
void ff_diff_bytes_sse2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, intptr_t w)
#define INLINE_MMXEXT(flags)
Definition: cpu.h:87
GLint GLenum GLboolean GLsizei stride
Definition: opengl_enc.c:105
static double c[64]
int x86_reg
Definition: asm.h:72
void ff_sub_left_predict_avx(uint8_t *dst, uint8_t *src, ptrdiff_t stride, ptrdiff_t width, int height)
#define EXTERNAL_AVX(flags)
Definition: cpu.h:70
#define av_unused
Definition: attributes.h:125