FFmpeg
hpeldsp_init.c
Go to the documentation of this file.
1 /*
2  * SIMD-optimized halfpel functions
3  * Copyright (c) 2000, 2001 Fabrice Bellard
4  * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  *
22  * MMX optimization by Nick Kurshev <nickols_k@mail.ru>
23  */
24 
25 #include "libavutil/attributes.h"
26 #include "libavutil/cpu.h"
27 #include "libavutil/x86/cpu.h"
28 #include "libavcodec/avcodec.h"
29 #include "libavcodec/hpeldsp.h"
30 #include "libavcodec/pixels.h"
31 #include "fpel.h"
32 #include "hpeldsp.h"
33 
34 void ff_put_pixels8_x2_mmxext(uint8_t *block, const uint8_t *pixels,
35  ptrdiff_t line_size, int h);
36 void ff_put_pixels16_x2_mmxext(uint8_t *block, const uint8_t *pixels,
37  ptrdiff_t line_size, int h);
38 void ff_put_pixels16_x2_sse2(uint8_t *block, const uint8_t *pixels,
39  ptrdiff_t line_size, int h);
40 void ff_avg_pixels16_x2_sse2(uint8_t *block, const uint8_t *pixels,
41  ptrdiff_t line_size, int h);
42 void ff_put_pixels16_y2_sse2(uint8_t *block, const uint8_t *pixels,
43  ptrdiff_t line_size, int h);
44 void ff_avg_pixels16_y2_sse2(uint8_t *block, const uint8_t *pixels,
45  ptrdiff_t line_size, int h);
46 void ff_put_no_rnd_pixels8_x2_mmxext(uint8_t *block, const uint8_t *pixels,
47  ptrdiff_t line_size, int h);
49  const uint8_t *pixels,
50  ptrdiff_t line_size, int h);
51 void ff_put_pixels8_y2_mmxext(uint8_t *block, const uint8_t *pixels,
52  ptrdiff_t line_size, int h);
53 void ff_put_no_rnd_pixels8_y2_mmxext(uint8_t *block, const uint8_t *pixels,
54  ptrdiff_t line_size, int h);
56  const uint8_t *pixels,
57  ptrdiff_t line_size, int h);
58 void ff_avg_pixels8_x2_mmxext(uint8_t *block, const uint8_t *pixels,
59  ptrdiff_t line_size, int h);
60 void ff_avg_pixels8_y2_mmxext(uint8_t *block, const uint8_t *pixels,
61  ptrdiff_t line_size, int h);
62 void ff_avg_approx_pixels8_xy2_mmxext(uint8_t *block, const uint8_t *pixels,
63  ptrdiff_t line_size, int h);
64 
65 #define avg_pixels16_mmx ff_avg_pixels16_mmx
66 #define put_pixels8_mmx ff_put_pixels8_mmx
67 #define put_pixels16_mmx ff_put_pixels16_mmx
68 #define put_pixels8_xy2_mmx ff_put_pixels8_xy2_mmx
69 #define avg_no_rnd_pixels16_mmx ff_avg_pixels16_mmx
70 #define put_no_rnd_pixels8_mmx ff_put_pixels8_mmx
71 #define put_no_rnd_pixels16_mmx ff_put_pixels16_mmx
72 
73 #if HAVE_INLINE_ASM
74 
75 /***********************************/
76 /* MMX no rounding */
77 #define DEF(x, y) x ## _no_rnd_ ## y ## _mmx
78 #define SET_RND MOVQ_WONE
79 #define PAVGBP(a, b, c, d, e, f) PAVGBP_MMX_NO_RND(a, b, c, d, e, f)
80 #define PAVGB(a, b, c, e) PAVGB_MMX_NO_RND(a, b, c, e)
81 #define STATIC static
82 
83 #include "rnd_template.c"
84 #include "hpeldsp_rnd_template.c"
85 
86 #undef DEF
87 #undef SET_RND
88 #undef PAVGBP
89 #undef PAVGB
90 #undef STATIC
91 
92 #if HAVE_MMX
93 CALL_2X_PIXELS(avg_no_rnd_pixels16_y2_mmx, avg_no_rnd_pixels8_y2_mmx, 8)
94 CALL_2X_PIXELS(put_no_rnd_pixels16_y2_mmx, put_no_rnd_pixels8_y2_mmx, 8)
95 
96 CALL_2X_PIXELS(avg_no_rnd_pixels16_xy2_mmx, avg_no_rnd_pixels8_xy2_mmx, 8)
97 CALL_2X_PIXELS(put_no_rnd_pixels16_xy2_mmx, put_no_rnd_pixels8_xy2_mmx, 8)
98 #endif
99 
100 /***********************************/
101 /* MMX rounding */
102 
103 #define SET_RND MOVQ_WTWO
104 #define DEF(x, y) ff_ ## x ## _ ## y ## _mmx
105 #define STATIC
106 #define NO_AVG
107 
108 #include "rnd_template.c"
109 
110 #undef NO_AVG
111 #undef DEF
112 #undef SET_RND
113 
114 #if HAVE_MMX
115 CALL_2X_PIXELS(put_pixels16_xy2_mmx, ff_put_pixels8_xy2_mmx, 8)
116 #endif
117 
118 #endif /* HAVE_INLINE_ASM */
119 
120 
121 #if HAVE_X86ASM
122 
123 #define HPELDSP_AVG_PIXELS16(CPUEXT) \
124  CALL_2X_PIXELS(put_no_rnd_pixels16_x2 ## CPUEXT, ff_put_no_rnd_pixels8_x2 ## CPUEXT, 8) \
125  CALL_2X_PIXELS(put_pixels16_y2 ## CPUEXT, ff_put_pixels8_y2 ## CPUEXT, 8) \
126  CALL_2X_PIXELS(put_no_rnd_pixels16_y2 ## CPUEXT, ff_put_no_rnd_pixels8_y2 ## CPUEXT, 8) \
127  CALL_2X_PIXELS(avg_pixels16 ## CPUEXT, ff_avg_pixels8 ## CPUEXT, 8) \
128  CALL_2X_PIXELS(avg_pixels16_x2 ## CPUEXT, ff_avg_pixels8_x2 ## CPUEXT, 8) \
129  CALL_2X_PIXELS(avg_pixels16_y2 ## CPUEXT, ff_avg_pixels8_y2 ## CPUEXT, 8) \
130  CALL_2X_PIXELS(avg_pixels16_xy2 ## CPUEXT, ff_avg_pixels8_xy2 ## CPUEXT, 8) \
131  CALL_2X_PIXELS(avg_approx_pixels16_xy2## CPUEXT, ff_avg_approx_pixels8_xy2## CPUEXT, 8)
132 
133 HPELDSP_AVG_PIXELS16(_mmxext)
134 
135 #endif /* HAVE_X86ASM */
136 
137 #define SET_HPEL_FUNCS_EXT(PFX, IDX, SIZE, CPU) \
138  if (HAVE_MMX_EXTERNAL) \
139  c->PFX ## _pixels_tab IDX [0] = PFX ## _pixels ## SIZE ## _ ## CPU
140 
141 #if HAVE_MMX_INLINE
142 #define SET_HPEL_FUNCS03(PFX, IDX, SIZE, CPU) \
143  do { \
144  SET_HPEL_FUNCS_EXT(PFX, IDX, SIZE, CPU); \
145  c->PFX ## _pixels_tab IDX [3] = PFX ## _pixels ## SIZE ## _xy2_ ## CPU; \
146  } while (0)
147 #define SET_HPEL_FUNCS12(PFX, IDX, SIZE, CPU) \
148  do { \
149  c->PFX ## _pixels_tab IDX [1] = PFX ## _pixels ## SIZE ## _x2_ ## CPU; \
150  c->PFX ## _pixels_tab IDX [2] = PFX ## _pixels ## SIZE ## _y2_ ## CPU; \
151  } while (0)
152 #else
153 #define SET_HPEL_FUNCS03(PFX, IDX, SIZE, CPU) SET_HPEL_FUNCS_EXT(PFX, IDX, SIZE, CPU)
154 #define SET_HPEL_FUNCS12(PFX, IDX, SIZE, CPU) ((void)0)
155 #endif
156 #define SET_HPEL_FUNCS(PFX, IDX, SIZE, CPU) \
157  do { \
158  SET_HPEL_FUNCS03(PFX, IDX, SIZE, CPU); \
159  SET_HPEL_FUNCS12(PFX, IDX, SIZE, CPU); \
160  } while (0)
161 
163 {
164  SET_HPEL_FUNCS03(put, [0], 16, mmx);
165  SET_HPEL_FUNCS(put_no_rnd, [0], 16, mmx);
166  SET_HPEL_FUNCS(avg_no_rnd, , 16, mmx);
167  SET_HPEL_FUNCS03(put, [1], 8, mmx);
168  SET_HPEL_FUNCS(put_no_rnd, [1], 8, mmx);
169 }
170 
172 {
173 #if HAVE_MMXEXT_EXTERNAL
174  c->put_pixels_tab[0][1] = ff_put_pixels16_x2_mmxext;
175  c->put_pixels_tab[0][2] = put_pixels16_y2_mmxext;
176 
177  c->avg_pixels_tab[0][0] = avg_pixels16_mmxext;
178  c->avg_pixels_tab[0][1] = avg_pixels16_x2_mmxext;
179  c->avg_pixels_tab[0][2] = avg_pixels16_y2_mmxext;
180  c->avg_pixels_tab[0][3] = avg_pixels16_xy2_mmxext;
181 
182  c->put_pixels_tab[1][1] = ff_put_pixels8_x2_mmxext;
183  c->put_pixels_tab[1][2] = ff_put_pixels8_y2_mmxext;
184 
185  c->avg_pixels_tab[1][0] = ff_avg_pixels8_mmxext;
186  c->avg_pixels_tab[1][1] = ff_avg_pixels8_x2_mmxext;
187  c->avg_pixels_tab[1][2] = ff_avg_pixels8_y2_mmxext;
188  c->avg_pixels_tab[1][3] = ff_avg_pixels8_xy2_mmxext;
189 
190  c->put_no_rnd_pixels_tab[1][1] = ff_put_no_rnd_pixels8_x2_exact_mmxext;
191  c->put_no_rnd_pixels_tab[1][2] = ff_put_no_rnd_pixels8_y2_exact_mmxext;
192 
193  if (!(flags & AV_CODEC_FLAG_BITEXACT)) {
194  c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_mmxext;
195  c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_mmxext;
196  c->put_no_rnd_pixels_tab[1][1] = ff_put_no_rnd_pixels8_x2_mmxext;
197  c->put_no_rnd_pixels_tab[1][2] = ff_put_no_rnd_pixels8_y2_mmxext;
198 
199  c->avg_pixels_tab[0][3] = avg_approx_pixels16_xy2_mmxext;
200  c->avg_pixels_tab[1][3] = ff_avg_approx_pixels8_xy2_mmxext;
201  }
202 #endif /* HAVE_MMXEXT_EXTERNAL */
203 }
204 
206 {
207 #if HAVE_SSE2_EXTERNAL
208  c->put_pixels_tab[0][0] = ff_put_pixels16_sse2;
209  c->put_no_rnd_pixels_tab[0][0] = ff_put_pixels16_sse2;
210  c->put_pixels_tab[0][1] = ff_put_pixels16_x2_sse2;
211  c->put_pixels_tab[0][2] = ff_put_pixels16_y2_sse2;
212  c->put_pixels_tab[0][3] = ff_put_pixels16_xy2_sse2;
213  c->avg_pixels_tab[0][0] = ff_avg_pixels16_sse2;
214  c->avg_pixels_tab[0][1] = ff_avg_pixels16_x2_sse2;
215  c->avg_pixels_tab[0][2] = ff_avg_pixels16_y2_sse2;
216  c->avg_pixels_tab[0][3] = ff_avg_pixels16_xy2_sse2;
217 #endif /* HAVE_SSE2_EXTERNAL */
218 }
219 
221 {
222 #if HAVE_SSSE3_EXTERNAL
223  c->put_pixels_tab[0][3] = ff_put_pixels16_xy2_ssse3;
224  c->avg_pixels_tab[0][3] = ff_avg_pixels16_xy2_ssse3;
225  c->put_pixels_tab[1][3] = ff_put_pixels8_xy2_ssse3;
226  c->avg_pixels_tab[1][3] = ff_avg_pixels8_xy2_ssse3;
227 #endif
228 }
229 
231 {
232  int cpu_flags = av_get_cpu_flags();
233 
234  if (INLINE_MMX(cpu_flags))
236 
239 
242 
245 }
INLINE_MMX
#define INLINE_MMX(flags)
Definition: cpu.h:87
cpu.h
EXTERNAL_SSE2_FAST
#define EXTERNAL_SSE2_FAST(flags)
Definition: cpu.h:60
ff_put_pixels16_y2_sse2
void ff_put_pixels16_y2_sse2(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
ff_put_no_rnd_pixels8_x2_exact_mmxext
void ff_put_no_rnd_pixels8_x2_exact_mmxext(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
ff_put_pixels8_xy2_ssse3
void ff_put_pixels8_xy2_ssse3(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
pixels.h
av_get_cpu_flags
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition: cpu.c:103
cpu_flags
static atomic_int cpu_flags
Definition: cpu.c:52
ff_avg_pixels8_xy2_mmxext
void ff_avg_pixels8_xy2_mmxext(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
hpeldsp_init_ssse3
static void hpeldsp_init_ssse3(HpelDSPContext *c, int flags)
Definition: hpeldsp_init.c:220
ff_put_no_rnd_pixels8_y2_exact_mmxext
void ff_put_no_rnd_pixels8_y2_exact_mmxext(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
rnd_template.c
ff_hpeldsp_init_x86
av_cold void ff_hpeldsp_init_x86(HpelDSPContext *c, int flags)
Definition: hpeldsp_init.c:230
ff_avg_pixels8_y2_mmxext
void ff_avg_pixels8_y2_mmxext(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
ff_put_pixels8_xy2_mmx
void ff_put_pixels8_xy2_mmx(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
av_cold
#define av_cold
Definition: attributes.h:90
ff_avg_pixels8_x2_mmxext
void ff_avg_pixels8_x2_mmxext(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
hpeldsp_init_mmxext
static void hpeldsp_init_mmxext(HpelDSPContext *c, int flags)
Definition: hpeldsp_init.c:171
ff_avg_pixels8_mmxext
void ff_avg_pixels8_mmxext(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
SET_HPEL_FUNCS03
#define SET_HPEL_FUNCS03(PFX, IDX, SIZE, CPU)
Definition: hpeldsp_init.c:153
ff_put_pixels16_sse2
void ff_put_pixels16_sse2(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
ff_avg_pixels16_y2_sse2
void ff_avg_pixels16_y2_sse2(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
hpeldsp_rnd_template.c
ff_avg_pixels16_xy2_sse2
void ff_avg_pixels16_xy2_sse2(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
hpeldsp_init_sse2_fast
static void hpeldsp_init_sse2_fast(HpelDSPContext *c, int flags)
Definition: hpeldsp_init.c:205
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
ff_avg_approx_pixels8_xy2_mmxext
void ff_avg_approx_pixels8_xy2_mmxext(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
ff_put_pixels16_xy2_ssse3
void ff_put_pixels16_xy2_ssse3(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
HpelDSPContext
Half-pel DSP context.
Definition: hpeldsp.h:45
ff_put_pixels16_x2_sse2
void ff_put_pixels16_x2_sse2(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
hpeldsp_init_mmx
static void hpeldsp_init_mmx(HpelDSPContext *c, int flags)
Definition: hpeldsp_init.c:162
ff_avg_pixels16_sse2
void ff_avg_pixels16_sse2(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
cpu.h
ff_put_pixels16_x2_mmxext
void ff_put_pixels16_x2_mmxext(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
attributes.h
ff_put_pixels16_xy2_sse2
void ff_put_pixels16_xy2_sse2(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
ff_put_pixels8_x2_mmxext
void ff_put_pixels8_x2_mmxext(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
avcodec.h
ff_avg_pixels16_xy2_ssse3
void ff_avg_pixels16_xy2_ssse3(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
SET_HPEL_FUNCS
#define SET_HPEL_FUNCS(PFX, IDX, SIZE, CPU)
Definition: hpeldsp_init.c:156
CALL_2X_PIXELS
#define CALL_2X_PIXELS(a, b, n)
Definition: pixels.h:34
ff_avg_pixels16_x2_sse2
void ff_avg_pixels16_x2_sse2(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
ff_put_pixels8_y2_mmxext
void ff_put_pixels8_y2_mmxext(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
fpel.h
AV_CODEC_FLAG_BITEXACT
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
Definition: avcodec.h:338
ff_put_no_rnd_pixels8_y2_mmxext
void ff_put_no_rnd_pixels8_y2_mmxext(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
hpeldsp.h
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:474
block
The exact code depends on how similar the blocks are and how related they are to the block
Definition: filter_design.txt:207
ff_avg_pixels8_xy2_ssse3
void ff_avg_pixels8_xy2_ssse3(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
h
h
Definition: vp9dsp_template.c:2038
EXTERNAL_SSSE3
#define EXTERNAL_SSSE3(flags)
Definition: cpu.h:65
ff_put_no_rnd_pixels8_x2_mmxext
void ff_put_no_rnd_pixels8_x2_mmxext(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
EXTERNAL_MMXEXT
#define EXTERNAL_MMXEXT(flags)
Definition: cpu.h:57