FFmpeg
cavsdsp.c
Go to the documentation of this file.
1 /*
2  * Chinese AVS video (AVS1-P2, JiZhun profile) decoder.
3  * Copyright (c) 2006 Stefan Gehrer <stefan.gehrer@gmx.de>
4  *
5  * MMX-optimized DSP functions, based on H.264 optimizations by
6  * Michael Niedermayer and Loren Merritt
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/mem_internal.h"
28 #include "libavutil/x86/cpu.h"
29 #include "libavcodec/cavsdsp.h"
30 #include "libavcodec/idctdsp.h"
31 #include "fpel.h"
32 #include "idctdsp.h"
33 #include "config.h"
34 
35 
36 #if HAVE_SSE2_EXTERNAL
37 
38 void ff_cavs_idct8_sse2(int16_t *out, const int16_t *in);
39 
40 static void cavs_idct8_add_sse2(uint8_t *dst, int16_t *block, ptrdiff_t stride)
41 {
42  LOCAL_ALIGNED(16, int16_t, b2, [64]);
43  ff_cavs_idct8_sse2(b2, block);
45 }
46 
47 #define DEF_QPEL(OPNAME) \
48  void ff_ ## OPNAME ## _cavs_qpel8_mc20_sse2(uint8_t *dst, const uint8_t *src, ptrdiff_t stride); \
49  void ff_ ## OPNAME ## _cavs_qpel8_mc02_sse2(uint8_t *dst, const uint8_t *src, ptrdiff_t stride); \
50  void ff_ ## OPNAME ## _cavs_qpel8_mc03_sse2(uint8_t *dst, const uint8_t *src, ptrdiff_t stride); \
51  void ff_ ## OPNAME ## _cavs_qpel8_h_sse2(uint8_t *dst, const uint8_t *src, ptrdiff_t stride, int h); \
52  void ff_ ## OPNAME ## _cavs_qpel8_v2_sse2(uint8_t *dst, const uint8_t *src, ptrdiff_t stride, int h);\
53  void ff_ ## OPNAME ## _cavs_qpel8_v3_sse2(uint8_t *dst, const uint8_t *src, ptrdiff_t stride, int h);\
54 
55 DEF_QPEL(put)
57 
58 #define QPEL_CAVS_XMM(OPNAME, XMM) \
59 static void OPNAME ## _cavs_qpel16_mc02_ ## XMM(uint8_t *dst, const uint8_t *src, ptrdiff_t stride) \
60 { \
61  ff_ ## OPNAME ## _cavs_qpel8_v2_ ## XMM(dst, src, stride, 16); \
62  ff_ ## OPNAME ## _cavs_qpel8_v2_ ## XMM(dst + 8, src + 8, stride, 16); \
63 } \
64 static void OPNAME ## _cavs_qpel16_mc03_ ## XMM(uint8_t *dst, const uint8_t *src, ptrdiff_t stride) \
65 { \
66  ff_ ## OPNAME ## _cavs_qpel8_v3_ ## XMM(dst, src, stride, 16); \
67  ff_ ## OPNAME ## _cavs_qpel8_v3_ ## XMM(dst + 8, src + 8, stride, 16); \
68 } \
69 static void OPNAME ## _cavs_qpel8_mc01_ ## XMM(uint8_t *dst, const uint8_t *src, ptrdiff_t stride) \
70 { \
71  ff_ ## OPNAME ## _cavs_qpel8_mc03_ ## XMM(dst + 7 * stride, src + 8 * stride, -stride); \
72 } \
73 static void OPNAME ## _cavs_qpel16_mc01_ ## XMM(uint8_t *dst, const uint8_t *src, ptrdiff_t stride) \
74 { \
75  OPNAME ## _cavs_qpel16_mc03_ ## XMM(dst + 15 * stride, src + 16 * stride, -stride); \
76 } \
77 static void OPNAME ## _cavs_qpel16_mc20_ ## XMM(uint8_t *dst, const uint8_t *src, ptrdiff_t stride) \
78 { \
79  ff_ ## OPNAME ## _cavs_qpel8_h_ ## XMM(dst, src, stride, 16); \
80  ff_ ## OPNAME ## _cavs_qpel8_h_ ## XMM(dst + 8, src + 8, stride, 16); \
81 }
82 
83 QPEL_CAVS_XMM(put, sse2)
84 QPEL_CAVS_XMM(avg, sse2)
85 #endif
86 
88 {
89 #if HAVE_SSE2_EXTERNAL
91 
92  if (EXTERNAL_SSE2(cpu_flags)) {
93  c->put_cavs_qpel_pixels_tab[0][ 0] = ff_put_pixels16x16_sse2;
94  c->put_cavs_qpel_pixels_tab[0][ 2] = put_cavs_qpel16_mc20_sse2;
95  c->put_cavs_qpel_pixels_tab[0][ 4] = put_cavs_qpel16_mc01_sse2;
96  c->put_cavs_qpel_pixels_tab[0][ 8] = put_cavs_qpel16_mc02_sse2;
97  c->put_cavs_qpel_pixels_tab[0][12] = put_cavs_qpel16_mc03_sse2;
98  c->put_cavs_qpel_pixels_tab[1][ 0] = ff_put_pixels8x8_sse2;
99  c->put_cavs_qpel_pixels_tab[1][ 2] = ff_put_cavs_qpel8_mc20_sse2;
100  c->put_cavs_qpel_pixels_tab[1][ 4] = put_cavs_qpel8_mc01_sse2;
101  c->put_cavs_qpel_pixels_tab[1][ 8] = ff_put_cavs_qpel8_mc02_sse2;
102  c->put_cavs_qpel_pixels_tab[1][12] = ff_put_cavs_qpel8_mc03_sse2;
103 
104  c->avg_cavs_qpel_pixels_tab[0][ 0] = ff_avg_pixels16x16_sse2;
105  c->avg_cavs_qpel_pixels_tab[0][ 2] = avg_cavs_qpel16_mc20_sse2;
106  c->avg_cavs_qpel_pixels_tab[0][ 4] = avg_cavs_qpel16_mc01_sse2;
107  c->avg_cavs_qpel_pixels_tab[0][ 8] = avg_cavs_qpel16_mc02_sse2;
108  c->avg_cavs_qpel_pixels_tab[0][12] = avg_cavs_qpel16_mc03_sse2;
109  c->avg_cavs_qpel_pixels_tab[1][ 0] = ff_avg_pixels8x8_sse2;
110  c->avg_cavs_qpel_pixels_tab[1][ 2] = ff_avg_cavs_qpel8_mc20_sse2;
111  c->avg_cavs_qpel_pixels_tab[1][ 4] = avg_cavs_qpel8_mc01_sse2;
112  c->avg_cavs_qpel_pixels_tab[1][ 8] = ff_avg_cavs_qpel8_mc02_sse2;
113  c->avg_cavs_qpel_pixels_tab[1][12] = ff_avg_cavs_qpel8_mc03_sse2;
114 
115  c->cavs_idct8_add = cavs_idct8_add_sse2;
116  c->idct_perm = FF_IDCT_PERM_TRANSPOSE;
117  }
118 #endif
119 }
mem_internal.h
out
static FILE * out
Definition: movenc.c:55
av_cold
#define av_cold
Definition: attributes.h:119
ff_avg_pixels16x16_sse2
void ff_avg_pixels16x16_sse2(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size)
cpu.h
ff_cavsdsp_init_x86
av_cold void ff_cavsdsp_init_x86(CAVSDSPContext *c)
Definition: cavsdsp.c:87
CAVSDSPContext
Definition: cavsdsp.h:30
LOCAL_ALIGNED
#define LOCAL_ALIGNED(a, t, v,...)
Definition: mem_internal.h:124
av_get_cpu_flags
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition: cpu.c:109
ff_put_pixels16x16_sse2
void ff_put_pixels16x16_sse2(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size)
attributes.h
ff_put_pixels8x8_sse2
void ff_put_pixels8x8_sse2(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size)
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:87
avg
#define avg(a, b, c, d)
Definition: colorspacedsp_template.c:28
b2
static double b2(void *priv, double x, double y)
Definition: vf_xfade.c:2035
cpu_flags
CheckasmCpu cpu_flags
Definition: checkasm.c:84
EXTERNAL_SSE2
#define EXTERNAL_SSE2(flags)
Definition: cpu.h:53
ff_add_pixels_clamped_sse2
void ff_add_pixels_clamped_sse2(const int16_t *block, uint8_t *restrict pixels, ptrdiff_t line_size)
ff_avg_pixels8x8_sse2
void ff_avg_pixels8x8_sse2(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size)
idctdsp.h
FF_IDCT_PERM_TRANSPOSE
@ FF_IDCT_PERM_TRANSPOSE
Definition: idctdsp.h:31
fpel.h
DEF_QPEL
#define DEF_QPEL(OPNAME)
Definition: h264_qpel.c:45
cpu.h
block
The exact code depends on how similar the blocks are and how related they are to the block
Definition: filter_design.txt:207
stride
#define stride
Definition: h264pred_template.c:536
cavsdsp.h