FFmpeg
vf_noise.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2002 Michael Niedermayer <michaelni@gmx.at>
3  * Copyright (c) 2013 Paul B Mahol
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include "libavutil/attributes.h"
23 #include "libavutil/x86/cpu.h"
24 #include "libavutil/x86/asm.h"
25 #include "libavfilter/vf_noise.h"
26 
27 #if HAVE_INLINE_ASM
28 #if HAVE_6REGS
29 static void line_noise_avg_mmx(uint8_t *dst, const uint8_t *src,
30  int len, const int8_t * const *shift)
31 {
32  x86_reg mmx_len = len & (~7);
33 
34  __asm__ volatile(
35  "mov %5, %%"FF_REG_a" \n\t"
36  ".p2align 4 \n\t"
37  "1: \n\t"
38  "movq (%1, %%"FF_REG_a"), %%mm1 \n\t"
39  "movq (%0, %%"FF_REG_a"), %%mm0 \n\t"
40  "paddb (%2, %%"FF_REG_a"), %%mm1\n\t"
41  "paddb (%3, %%"FF_REG_a"), %%mm1\n\t"
42  "movq %%mm0, %%mm2 \n\t"
43  "movq %%mm1, %%mm3 \n\t"
44  "punpcklbw %%mm0, %%mm0 \n\t"
45  "punpckhbw %%mm2, %%mm2 \n\t"
46  "punpcklbw %%mm1, %%mm1 \n\t"
47  "punpckhbw %%mm3, %%mm3 \n\t"
48  "pmulhw %%mm0, %%mm1 \n\t"
49  "pmulhw %%mm2, %%mm3 \n\t"
50  "paddw %%mm1, %%mm1 \n\t"
51  "paddw %%mm3, %%mm3 \n\t"
52  "paddw %%mm0, %%mm1 \n\t"
53  "paddw %%mm2, %%mm3 \n\t"
54  "psrlw $8, %%mm1 \n\t"
55  "psrlw $8, %%mm3 \n\t"
56  "packuswb %%mm3, %%mm1 \n\t"
57  "movq %%mm1, (%4, %%"FF_REG_a") \n\t"
58  "add $8, %%"FF_REG_a" \n\t"
59  " js 1b \n\t"
60  :: "r" (src+mmx_len), "r" (shift[0]+mmx_len), "r" (shift[1]+mmx_len), "r" (shift[2]+mmx_len),
61  "r" (dst+mmx_len), "g" (-mmx_len)
62  : "%"FF_REG_a
63  );
64 
65  if (mmx_len != len){
66  const int8_t *shift2[3] = { shift[0]+mmx_len, shift[1]+mmx_len, shift[2]+mmx_len };
67  ff_line_noise_avg_c(dst+mmx_len, src+mmx_len, len-mmx_len, shift2);
68  }
69 }
70 #endif /* HAVE_6REGS */
71 
72 static void line_noise_mmxext(uint8_t *dst, const uint8_t *src,
73  const int8_t *noise, int len, int shift)
74 {
75  x86_reg mmx_len = len & (~7);
76  noise += shift;
77 
78  __asm__ volatile(
79  "mov %3, %%"FF_REG_a" \n\t"
80  "pcmpeqb %%mm7, %%mm7 \n\t"
81  "psllw $15, %%mm7 \n\t"
82  "packsswb %%mm7, %%mm7 \n\t"
83  ".p2align 4 \n\t"
84  "1: \n\t"
85  "movq (%0, %%"FF_REG_a"), %%mm0 \n\t"
86  "movq (%1, %%"FF_REG_a"), %%mm1 \n\t"
87  "pxor %%mm7, %%mm0 \n\t"
88  "paddsb %%mm1, %%mm0 \n\t"
89  "pxor %%mm7, %%mm0 \n\t"
90  "movntq %%mm0, (%2, %%"FF_REG_a") \n\t"
91  "add $8, %%"FF_REG_a" \n\t"
92  " js 1b \n\t"
93  :: "r" (src+mmx_len), "r" (noise+mmx_len), "r" (dst+mmx_len), "g" (-mmx_len)
94  : "%"FF_REG_a
95  );
96  if (mmx_len != len)
97  ff_line_noise_c(dst+mmx_len, src+mmx_len, noise+mmx_len, len-mmx_len, 0);
98 }
99 #endif /* HAVE_INLINE_ASM */
100 
102 {
103 #if HAVE_INLINE_ASM
104  int cpu_flags = av_get_cpu_flags();
105 
106  if (INLINE_MMX(cpu_flags)) {
107 #if HAVE_6REGS
108  n->line_noise_avg = line_noise_avg_mmx;
109 #endif
110  }
111  if (INLINE_MMXEXT(cpu_flags)) {
112  n->line_noise = line_noise_mmxext;
113  }
114 #endif
115 }
INLINE_MMX
#define INLINE_MMX(flags)
Definition: cpu.h:87
cpu.h
noise
static void noise(uint8_t *dst, const uint8_t *src, int dst_linesize, int src_linesize, int width, int start, int end, NoiseContext *n, int comp)
Definition: vf_noise.c:190
av_get_cpu_flags
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition: cpu.c:101
vf_noise.h
cpu_flags
static atomic_int cpu_flags
Definition: cpu.c:52
NoiseContext
Definition: noise_bsf.c:62
av_cold
#define av_cold
Definition: attributes.h:90
NoiseContext::line_noise
void(* line_noise)(uint8_t *dst, const uint8_t *src, const int8_t *noise, int len, int shift)
Definition: vf_noise.h:55
ff_noise_init_x86
av_cold void ff_noise_init_x86(NoiseContext *n)
Definition: vf_noise.c:101
asm.h
attributes.h
shift2
static const int shift2[6]
Definition: dxa.c:52
ff_line_noise_avg_c
void ff_line_noise_avg_c(uint8_t *dst, const uint8_t *src, int len, const int8_t *const *shift)
Definition: vf_noise.c:178
len
int len
Definition: vorbis_enc_data.h:426
__asm__
__asm__(".macro parse_r var r\n\t" "\\var = -1\n\t" _IFC_REG(0) _IFC_REG(1) _IFC_REG(2) _IFC_REG(3) _IFC_REG(4) _IFC_REG(5) _IFC_REG(6) _IFC_REG(7) _IFC_REG(8) _IFC_REG(9) _IFC_REG(10) _IFC_REG(11) _IFC_REG(12) _IFC_REG(13) _IFC_REG(14) _IFC_REG(15) _IFC_REG(16) _IFC_REG(17) _IFC_REG(18) _IFC_REG(19) _IFC_REG(20) _IFC_REG(21) _IFC_REG(22) _IFC_REG(23) _IFC_REG(24) _IFC_REG(25) _IFC_REG(26) _IFC_REG(27) _IFC_REG(28) _IFC_REG(29) _IFC_REG(30) _IFC_REG(31) ".iflt \\var\n\t" ".error \"Unable to parse register name \\r\"\n\t" ".endif\n\t" ".endm")
ff_line_noise_c
void ff_line_noise_c(uint8_t *dst, const uint8_t *src, const int8_t *noise, int len, int shift)
Definition: vf_noise.c:165
NoiseContext::line_noise_avg
void(* line_noise_avg)(uint8_t *dst, const uint8_t *src, int len, const int8_t *const *shift)
Definition: vf_noise.h:56
INLINE_MMXEXT
#define INLINE_MMXEXT(flags)
Definition: cpu.h:88
shift
static int shift(int a, int b)
Definition: sonic.c:88
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
x86_reg
int x86_reg
Definition: asm.h:72