FFmpeg
rv40dsp_init.c
Go to the documentation of this file.
1 /*
2  * RV40 decoder motion compensation functions x86-optimised
3  * Copyright (c) 2008 Konstantin Shishkov
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 /**
23  * @file
24  * RV40 decoder motion compensation functions x86-optimised
25  * 2,0 and 0,2 have h264 equivalents.
26  * 3,3 is bugged in the rv40 format and maps to _xy2 version
27  */
28 
29 #include "libavcodec/rv34dsp.h"
30 #include "libavutil/attributes.h"
31 #include "libavutil/mem_internal.h"
32 #include "libavutil/x86/cpu.h"
33 #include "hpeldsp.h"
34 
35 #define DEFINE_FN(op, size, insn) \
36 static void op##_rv40_qpel##size##_mc33_##insn(uint8_t *dst, const uint8_t *src, \
37  ptrdiff_t stride) \
38 { \
39  ff_##op##_pixels##size##_xy2_##insn(dst, src, stride, size); \
40 }
41 
42 #define DECLARE_WEIGHT(opt) \
43 void ff_rv40_weight_func_rnd_16_##opt(uint8_t *dst, uint8_t *src1, uint8_t *src2, \
44  int w1, int w2, ptrdiff_t stride); \
45 void ff_rv40_weight_func_rnd_8_##opt (uint8_t *dst, uint8_t *src1, uint8_t *src2, \
46  int w1, int w2, ptrdiff_t stride); \
47 void ff_rv40_weight_func_nornd_16_##opt(uint8_t *dst, uint8_t *src1, uint8_t *src2, \
48  int w1, int w2, ptrdiff_t stride); \
49 void ff_rv40_weight_func_nornd_8_##opt (uint8_t *dst, uint8_t *src1, uint8_t *src2, \
50  int w1, int w2, ptrdiff_t stride);
51 DECLARE_WEIGHT(sse2)
52 DECLARE_WEIGHT(ssse3)
53 
54 /** @{ */
55 /**
56  * Define one qpel function.
57  * LOOPSIZE must be already set to the number of pixels processed per
58  * iteration in the inner loop of the called functions.
59  * COFF(x) must be already defined so as to provide the offset into any
60  * array of coeffs used by the called function for the qpel position x.
61  */
62 #define QPEL_FUNC_DECL(OP, SIZE, PH, PV, OPT) \
63 static void OP ## rv40_qpel ##SIZE ##_mc ##PH ##PV ##OPT(uint8_t *dst, \
64  const uint8_t *src, \
65  ptrdiff_t stride) \
66 { \
67  int i; \
68  if (PH && PV) { \
69  LOCAL_ALIGNED(16, uint8_t, tmp, [SIZE * (SIZE + 5)]); \
70  uint8_t *tmpptr = tmp + SIZE * 2; \
71  src -= stride * 2; \
72  \
73  for (i = 0; i < SIZE; i += LOOPSIZE) \
74  ff_put_rv40_qpel_h ##OPT(tmp + i, SIZE, src + i, stride, \
75  SIZE + 5, HCOFF(PH)); \
76  for (i = 0; i < SIZE; i += LOOPSIZE) \
77  ff_ ##OP ##rv40_qpel_v ##OPT(dst + i, stride, tmpptr + i, \
78  SIZE, SIZE, VCOFF(PV)); \
79  } else if (PV) { \
80  for (i = 0; i < SIZE; i += LOOPSIZE) \
81  ff_ ##OP ##rv40_qpel_v ## OPT(dst + i, stride, src + i, \
82  stride, SIZE, VCOFF(PV)); \
83  } else { \
84  for (i = 0; i < SIZE; i += LOOPSIZE) \
85  ff_ ##OP ##rv40_qpel_h ## OPT(dst + i, stride, src + i, \
86  stride, SIZE, HCOFF(PH)); \
87  } \
88 }
89 
90 /** Declare functions for sizes 8 and 16 and given operations
91  * and qpel position. */
92 #define QPEL_FUNCS_DECL(OP, PH, PV, OPT) \
93  QPEL_FUNC_DECL(OP, 8, PH, PV, OPT) \
94  QPEL_FUNC_DECL(OP, 16, PH, PV, OPT)
95 
96 /** Declare all functions for all sizes and qpel positions */
97 #define QPEL_MC_DECL(OP, OPT) \
98 void ff_ ##OP ##rv40_qpel_h ##OPT(uint8_t *dst, ptrdiff_t dstStride, \
99  const uint8_t *src, \
100  ptrdiff_t srcStride, \
101  int len, int m); \
102 void ff_ ##OP ##rv40_qpel_v ##OPT(uint8_t *dst, ptrdiff_t dstStride, \
103  const uint8_t *src, \
104  ptrdiff_t srcStride, \
105  int len, int m); \
106 QPEL_FUNCS_DECL(OP, 0, 1, OPT) \
107 QPEL_FUNCS_DECL(OP, 0, 3, OPT) \
108 QPEL_FUNCS_DECL(OP, 1, 0, OPT) \
109 QPEL_FUNCS_DECL(OP, 1, 1, OPT) \
110 QPEL_FUNCS_DECL(OP, 1, 2, OPT) \
111 QPEL_FUNCS_DECL(OP, 1, 3, OPT) \
112 QPEL_FUNCS_DECL(OP, 2, 1, OPT) \
113 QPEL_FUNCS_DECL(OP, 2, 2, OPT) \
114 QPEL_FUNCS_DECL(OP, 2, 3, OPT) \
115 QPEL_FUNCS_DECL(OP, 3, 0, OPT) \
116 QPEL_FUNCS_DECL(OP, 3, 1, OPT) \
117 QPEL_FUNCS_DECL(OP, 3, 2, OPT)
118 /** @} */
119 
120 #define LOOPSIZE 8
121 #define HCOFF(x) (32 * ((x) - 1))
122 #define VCOFF(x) (32 * ((x) - 1))
123 QPEL_MC_DECL(put_, _ssse3)
124 QPEL_MC_DECL(avg_, _ssse3)
125 
126 #undef LOOPSIZE
127 #undef HCOFF
128 #undef VCOFF
129 #define LOOPSIZE 8
130 #define HCOFF(x) (64 * ((x) - 1))
131 #define VCOFF(x) (64 * ((x) - 1))
132 QPEL_MC_DECL(put_, _sse2)
133 QPEL_MC_DECL(avg_, _sse2)
134 
135 /** @{ */
136 /** Set one function */
137 #define QPEL_FUNC_SET(OP, SIZE, PH, PV, OPT) \
138  c-> OP ## pixels_tab[2 - SIZE / 8][4 * PV + PH] = OP ## rv40_qpel ##SIZE ## _mc ##PH ##PV ##OPT;
139 
140 /** Set functions put and avg for sizes 8 and 16 and a given qpel position */
141 #define QPEL_FUNCS_SET(OP, PH, PV, OPT) \
142  QPEL_FUNC_SET(OP, 8, PH, PV, OPT) \
143  QPEL_FUNC_SET(OP, 16, PH, PV, OPT)
144 
145 /** Set all functions for all sizes and qpel positions */
146 #define QPEL_MC_SET(OP, OPT) \
147 QPEL_FUNCS_SET (OP, 0, 1, OPT) \
148 QPEL_FUNCS_SET (OP, 0, 3, OPT) \
149 QPEL_FUNCS_SET (OP, 1, 0, OPT) \
150 QPEL_FUNCS_SET (OP, 1, 1, OPT) \
151 QPEL_FUNCS_SET (OP, 1, 2, OPT) \
152 QPEL_FUNCS_SET (OP, 1, 3, OPT) \
153 QPEL_FUNCS_SET (OP, 2, 1, OPT) \
154 QPEL_FUNCS_SET (OP, 2, 2, OPT) \
155 QPEL_FUNCS_SET (OP, 2, 3, OPT) \
156 QPEL_FUNCS_SET (OP, 3, 0, OPT) \
157 QPEL_FUNCS_SET (OP, 3, 1, OPT) \
158 QPEL_FUNCS_SET (OP, 3, 2, OPT)
159 /** @} */
160 
161 DEFINE_FN(put, 8, ssse3)
162 
163 DEFINE_FN(put, 16, sse2)
164 DEFINE_FN(put, 16, ssse3)
165 
166 DEFINE_FN(avg, 8, ssse3)
167 
168 DEFINE_FN(avg, 16, sse2)
169 DEFINE_FN(avg, 16, ssse3)
170 
171 #define CHROMA_MC_FUNC(OP, SIZE, XMM) \
172 void ff_rv40_ ## OP ## _chroma_mc ## SIZE ## _ ## XMM(uint8_t *dst, const uint8_t *src, \
173  ptrdiff_t stride, int h, int x, int y);\
174  c->OP ## _chroma_pixels_tab[SIZE == 4] = ff_rv40_ ## OP ## _chroma_mc ## SIZE ## _ ## XMM
175 
177 {
179 
180  if (EXTERNAL_SSE2(cpu_flags)) {
181  c->put_pixels_tab[0][15] = put_rv40_qpel16_mc33_sse2;
182  c->avg_pixels_tab[0][15] = avg_rv40_qpel16_mc33_sse2;
183  c->rv40_weight_pixels_tab[0][0] = ff_rv40_weight_func_rnd_16_sse2;
184  c->rv40_weight_pixels_tab[0][1] = ff_rv40_weight_func_rnd_8_sse2;
185  c->rv40_weight_pixels_tab[1][0] = ff_rv40_weight_func_nornd_16_sse2;
186  c->rv40_weight_pixels_tab[1][1] = ff_rv40_weight_func_nornd_8_sse2;
187  QPEL_MC_SET(put_, _sse2)
188  QPEL_MC_SET(avg_, _sse2)
189  }
190  if (EXTERNAL_SSSE3(cpu_flags)) {
191  CHROMA_MC_FUNC(put, 8, ssse3);
192  CHROMA_MC_FUNC(put, 4, ssse3);
193  CHROMA_MC_FUNC(avg, 8, ssse3);
194  CHROMA_MC_FUNC(avg, 4, ssse3);
195  c->put_pixels_tab[0][15] = put_rv40_qpel16_mc33_ssse3;
196  c->put_pixels_tab[1][15] = put_rv40_qpel8_mc33_ssse3;
197  c->avg_pixels_tab[0][15] = avg_rv40_qpel16_mc33_ssse3;
198  c->avg_pixels_tab[1][15] = avg_rv40_qpel8_mc33_ssse3;
199  c->rv40_weight_pixels_tab[0][0] = ff_rv40_weight_func_rnd_16_ssse3;
200  c->rv40_weight_pixels_tab[0][1] = ff_rv40_weight_func_rnd_8_ssse3;
201  c->rv40_weight_pixels_tab[1][0] = ff_rv40_weight_func_nornd_16_ssse3;
202  c->rv40_weight_pixels_tab[1][1] = ff_rv40_weight_func_nornd_8_ssse3;
203  QPEL_MC_SET(put_, _ssse3)
204  QPEL_MC_SET(avg_, _ssse3)
205  }
206 }
cpu.h
mem_internal.h
av_unused
#define av_unused
Definition: attributes.h:151
av_get_cpu_flags
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition: cpu.c:109
cpu_flags
static atomic_int cpu_flags
Definition: cpu.c:56
CHROMA_MC_FUNC
#define CHROMA_MC_FUNC(OP, SIZE, XMM)
Definition: rv40dsp_init.c:171
av_cold
#define av_cold
Definition: attributes.h:106
DEFINE_FN
#define DEFINE_FN(op, size, insn)
Definition: rv40dsp_init.c:35
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
RV34DSPContext
Definition: rv34dsp.h:57
rv34dsp.h
avg
#define avg(a, b, c, d)
Definition: colorspacedsp_template.c:28
ff_rv40dsp_init_x86
av_cold void ff_rv40dsp_init_x86(RV34DSPContext *c)
Definition: rv40dsp_init.c:176
attributes.h
EXTERNAL_SSE2
#define EXTERNAL_SSE2(flags)
Definition: cpu.h:52
QPEL_MC_SET
#define QPEL_MC_SET(OP, OPT)
Set all functions for all sizes and qpel positions.
Definition: rv40dsp_init.c:146
hpeldsp.h
DECLARE_WEIGHT
#define DECLARE_WEIGHT(opt)
Definition: rv40dsp_init.c:42
QPEL_MC_DECL
#define QPEL_MC_DECL(OP, OPT)
Declare all functions for all sizes and qpel positions.
Definition: rv40dsp_init.c:97
EXTERNAL_SSSE3
#define EXTERNAL_SSSE3(flags)
Definition: cpu.h:58