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