hpeldsp_template: Merge some declarations and initializations
[libav.git] / libavcodec / hpeldsp_template.c
CommitLineData
68d8238c 1/*
2539cf1c
DB
2 * Half-pel DSP functions
3 *
68d8238c
RB
4 * Copyright (c) 2000, 2001 Fabrice Bellard
5 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
6 *
7 * gmc & q-pel & 32/64 bit based MC by Michael Niedermayer <michaelni@gmx.at>
8 *
9 * This file is part of Libav.
10 *
11 * Libav is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
15 *
16 * Libav is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with Libav; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26/**
27 * @file
2539cf1c 28 * Half-pel DSP functions
68d8238c
RB
29 */
30
31#include "bit_depth_template.c"
32
33#include "hpel_template.c"
34
2539cf1c
DB
35#define PIXOP2(OPNAME, OP) \
36static inline void FUNC(OPNAME ## _no_rnd_pixels8_l2)(uint8_t *dst, \
37 const uint8_t *src1, \
38 const uint8_t *src2, \
39 int dst_stride, \
40 int src_stride1, \
41 int src_stride2, \
42 int h) \
43{ \
44 int i; \
45 \
46 for (i = 0; i < h; i++) { \
47 pixel4 a, b; \
48 a = AV_RN4P(&src1[i * src_stride1]); \
49 b = AV_RN4P(&src2[i * src_stride2]); \
50 OP(*((pixel4 *) &dst[i * dst_stride]), \
51 no_rnd_avg_pixel4(a, b)); \
52 a = AV_RN4P(&src1[i * src_stride1 + 4 * sizeof(pixel)]); \
53 b = AV_RN4P(&src2[i * src_stride2 + 4 * sizeof(pixel)]); \
54 OP(*((pixel4 *) &dst[i * dst_stride + 4 * sizeof(pixel)]), \
55 no_rnd_avg_pixel4(a, b)); \
56 } \
57} \
58 \
59static inline void FUNCC(OPNAME ## _no_rnd_pixels8_x2)(uint8_t *block, \
60 const uint8_t *pixels, \
61 ptrdiff_t line_size, \
62 int h) \
63{ \
64 FUNC(OPNAME ## _no_rnd_pixels8_l2)(block, pixels, pixels + sizeof(pixel), \
65 line_size, line_size, line_size, h); \
66} \
67 \
68static inline void FUNCC(OPNAME ## _pixels8_x2)(uint8_t *block, \
69 const uint8_t *pixels, \
70 ptrdiff_t line_size, \
71 int h) \
72{ \
73 FUNC(OPNAME ## _pixels8_l2)(block, pixels, pixels + sizeof(pixel), \
74 line_size, line_size, line_size, h); \
75} \
76 \
77static inline void FUNCC(OPNAME ## _no_rnd_pixels8_y2)(uint8_t *block, \
78 const uint8_t *pixels, \
79 ptrdiff_t line_size, \
80 int h) \
81{ \
82 FUNC(OPNAME ## _no_rnd_pixels8_l2)(block, pixels, pixels + line_size, \
83 line_size, line_size, line_size, h); \
84} \
85 \
86static inline void FUNCC(OPNAME ## _pixels8_y2)(uint8_t *block, \
87 const uint8_t *pixels, \
88 ptrdiff_t line_size, \
89 int h) \
90{ \
91 FUNC(OPNAME ## _pixels8_l2)(block, pixels, pixels + line_size, \
92 line_size, line_size, line_size, h); \
93} \
94 \
95static inline void FUNCC(OPNAME ## _pixels4_x2)(uint8_t *block, \
96 const uint8_t *pixels, \
97 ptrdiff_t line_size, \
98 int h) \
99{ \
100 FUNC(OPNAME ## _pixels4_l2)(block, pixels, pixels + sizeof(pixel), \
101 line_size, line_size, line_size, h); \
102} \
103 \
104static inline void FUNCC(OPNAME ## _pixels4_y2)(uint8_t *block, \
105 const uint8_t *pixels, \
106 ptrdiff_t line_size, \
107 int h) \
108{ \
109 FUNC(OPNAME ## _pixels4_l2)(block, pixels, pixels + line_size, \
110 line_size, line_size, line_size, h); \
111} \
112 \
113static inline void FUNCC(OPNAME ## _pixels2_x2)(uint8_t *block, \
114 const uint8_t *pixels, \
115 ptrdiff_t line_size, \
116 int h) \
117{ \
118 FUNC(OPNAME ## _pixels2_l2)(block, pixels, pixels + sizeof(pixel), \
119 line_size, line_size, line_size, h); \
120} \
121 \
122static inline void FUNCC(OPNAME ## _pixels2_y2)(uint8_t *block, \
123 const uint8_t *pixels, \
124 ptrdiff_t line_size, \
125 int h) \
126{ \
127 FUNC(OPNAME ## _pixels2_l2)(block, pixels, pixels + line_size, \
128 line_size, line_size, line_size, h); \
129} \
130 \
131static inline void FUNCC(OPNAME ## _pixels2_xy2)(uint8_t *_block, \
132 const uint8_t *_pixels, \
133 ptrdiff_t line_size, \
134 int h) \
135{ \
2539cf1c
DB
136 pixel *block = (pixel *) _block; \
137 const pixel *pixels = (const pixel *) _pixels; \
cce791b1
DB
138 int i, a1, b1; \
139 int a0 = pixels[0]; \
140 int b0 = pixels[1] + 2; \
141 \
2539cf1c
DB
142 a0 += b0; \
143 b0 += pixels[2]; \
2539cf1c
DB
144 line_size /= sizeof(pixel); \
145 pixels += line_size; \
146 for (i = 0; i < h; i += 2) { \
147 a1 = pixels[0]; \
148 b1 = pixels[1]; \
149 a1 += b1; \
150 b1 += pixels[2]; \
151 \
152 block[0] = (a1 + a0) >> 2; /* FIXME non put */ \
153 block[1] = (b1 + b0) >> 2; \
154 \
155 pixels += line_size; \
156 block += line_size; \
157 \
158 a0 = pixels[0]; \
159 b0 = pixels[1] + 2; \
160 a0 += b0; \
161 b0 += pixels[2]; \
162 \
163 block[0] = (a1 + a0) >> 2; \
164 block[1] = (b1 + b0) >> 2; \
165 pixels += line_size; \
166 block += line_size; \
167 } \
168} \
169 \
170static inline void FUNCC(OPNAME ## _pixels4_xy2)(uint8_t *block, \
171 const uint8_t *pixels, \
172 ptrdiff_t line_size, \
173 int h) \
174{ \
175 /* FIXME HIGH BIT DEPTH */ \
176 int i; \
177 const uint32_t a = AV_RN32(pixels); \
178 const uint32_t b = AV_RN32(pixels + 1); \
179 uint32_t l0 = (a & 0x03030303UL) + \
180 (b & 0x03030303UL) + \
181 0x02020202UL; \
182 uint32_t h0 = ((a & 0xFCFCFCFCUL) >> 2) + \
183 ((b & 0xFCFCFCFCUL) >> 2); \
184 uint32_t l1, h1; \
185 \
186 pixels += line_size; \
187 for (i = 0; i < h; i += 2) { \
188 uint32_t a = AV_RN32(pixels); \
189 uint32_t b = AV_RN32(pixels + 1); \
190 l1 = (a & 0x03030303UL) + \
191 (b & 0x03030303UL); \
192 h1 = ((a & 0xFCFCFCFCUL) >> 2) + \
193 ((b & 0xFCFCFCFCUL) >> 2); \
194 OP(*((uint32_t *) block), h0 + h1 + \
195 (((l0 + l1) >> 2) & 0x0F0F0F0FUL)); \
196 pixels += line_size; \
197 block += line_size; \
198 a = AV_RN32(pixels); \
199 b = AV_RN32(pixels + 1); \
200 l0 = (a & 0x03030303UL) + \
201 (b & 0x03030303UL) + \
202 0x02020202UL; \
203 h0 = ((a & 0xFCFCFCFCUL) >> 2) + \
204 ((b & 0xFCFCFCFCUL) >> 2); \
205 OP(*((uint32_t *) block), h0 + h1 + \
206 (((l0 + l1) >> 2) & 0x0F0F0F0FUL)); \
207 pixels += line_size; \
208 block += line_size; \
209 } \
210} \
211 \
212static inline void FUNCC(OPNAME ## _pixels8_xy2)(uint8_t *block, \
213 const uint8_t *pixels, \
214 ptrdiff_t line_size, \
215 int h) \
216{ \
217 /* FIXME HIGH BIT DEPTH */ \
218 int j; \
219 \
220 for (j = 0; j < 2; j++) { \
221 int i; \
222 const uint32_t a = AV_RN32(pixels); \
223 const uint32_t b = AV_RN32(pixels + 1); \
224 uint32_t l0 = (a & 0x03030303UL) + \
225 (b & 0x03030303UL) + \
226 0x02020202UL; \
227 uint32_t h0 = ((a & 0xFCFCFCFCUL) >> 2) + \
228 ((b & 0xFCFCFCFCUL) >> 2); \
229 uint32_t l1, h1; \
230 \
231 pixels += line_size; \
232 for (i = 0; i < h; i += 2) { \
233 uint32_t a = AV_RN32(pixels); \
234 uint32_t b = AV_RN32(pixels + 1); \
235 l1 = (a & 0x03030303UL) + \
236 (b & 0x03030303UL); \
237 h1 = ((a & 0xFCFCFCFCUL) >> 2) + \
238 ((b & 0xFCFCFCFCUL) >> 2); \
239 OP(*((uint32_t *) block), h0 + h1 + \
240 (((l0 + l1) >> 2) & 0x0F0F0F0FUL)); \
241 pixels += line_size; \
242 block += line_size; \
243 a = AV_RN32(pixels); \
244 b = AV_RN32(pixels + 1); \
245 l0 = (a & 0x03030303UL) + \
246 (b & 0x03030303UL) + \
247 0x02020202UL; \
248 h0 = ((a & 0xFCFCFCFCUL) >> 2) + \
249 ((b & 0xFCFCFCFCUL) >> 2); \
250 OP(*((uint32_t *) block), h0 + h1 + \
251 (((l0 + l1) >> 2) & 0x0F0F0F0FUL)); \
252 pixels += line_size; \
253 block += line_size; \
254 } \
255 pixels += 4 - line_size * (h + 1); \
256 block += 4 - line_size * h; \
257 } \
258} \
259 \
260static inline void FUNCC(OPNAME ## _no_rnd_pixels8_xy2)(uint8_t *block, \
261 const uint8_t *pixels, \
262 ptrdiff_t line_size, \
263 int h) \
264{ \
265 /* FIXME HIGH BIT DEPTH */ \
266 int j; \
267 \
268 for (j = 0; j < 2; j++) { \
269 int i; \
270 const uint32_t a = AV_RN32(pixels); \
271 const uint32_t b = AV_RN32(pixels + 1); \
272 uint32_t l0 = (a & 0x03030303UL) + \
273 (b & 0x03030303UL) + \
274 0x01010101UL; \
275 uint32_t h0 = ((a & 0xFCFCFCFCUL) >> 2) + \
276 ((b & 0xFCFCFCFCUL) >> 2); \
277 uint32_t l1, h1; \
278 \
279 pixels += line_size; \
280 for (i = 0; i < h; i += 2) { \
281 uint32_t a = AV_RN32(pixels); \
282 uint32_t b = AV_RN32(pixels + 1); \
283 l1 = (a & 0x03030303UL) + \
284 (b & 0x03030303UL); \
285 h1 = ((a & 0xFCFCFCFCUL) >> 2) + \
286 ((b & 0xFCFCFCFCUL) >> 2); \
287 OP(*((uint32_t *) block), h0 + h1 + \
288 (((l0 + l1) >> 2) & 0x0F0F0F0FUL)); \
289 pixels += line_size; \
290 block += line_size; \
291 a = AV_RN32(pixels); \
292 b = AV_RN32(pixels + 1); \
293 l0 = (a & 0x03030303UL) + \
294 (b & 0x03030303UL) + \
295 0x01010101UL; \
296 h0 = ((a & 0xFCFCFCFCUL) >> 2) + \
297 ((b & 0xFCFCFCFCUL) >> 2); \
298 OP(*((uint32_t *) block), h0 + h1 + \
299 (((l0 + l1) >> 2) & 0x0F0F0F0FUL)); \
300 pixels += line_size; \
301 block += line_size; \
302 } \
303 pixels += 4 - line_size * (h + 1); \
304 block += 4 - line_size * h; \
305 } \
306} \
307 \
308CALL_2X_PIXELS(FUNCC(OPNAME ## _pixels16_x2), \
309 FUNCC(OPNAME ## _pixels8_x2), \
310 8 * sizeof(pixel)) \
311CALL_2X_PIXELS(FUNCC(OPNAME ## _pixels16_y2), \
312 FUNCC(OPNAME ## _pixels8_y2), \
313 8 * sizeof(pixel)) \
314CALL_2X_PIXELS(FUNCC(OPNAME ## _pixels16_xy2), \
315 FUNCC(OPNAME ## _pixels8_xy2), \
316 8 * sizeof(pixel)) \
317av_unused CALL_2X_PIXELS(FUNCC(OPNAME ## _no_rnd_pixels16), \
318 FUNCC(OPNAME ## _pixels8), \
319 8 * sizeof(pixel)) \
320CALL_2X_PIXELS(FUNCC(OPNAME ## _no_rnd_pixels16_x2), \
321 FUNCC(OPNAME ## _no_rnd_pixels8_x2), \
322 8 * sizeof(pixel)) \
323CALL_2X_PIXELS(FUNCC(OPNAME ## _no_rnd_pixels16_y2), \
324 FUNCC(OPNAME ## _no_rnd_pixels8_y2), \
325 8 * sizeof(pixel)) \
326CALL_2X_PIXELS(FUNCC(OPNAME ## _no_rnd_pixels16_xy2), \
327 FUNCC(OPNAME ## _no_rnd_pixels8_xy2), \
328 8 * sizeof(pixel)) \
68d8238c
RB
329
330#define op_avg(a, b) a = rnd_avg_pixel4(a, b)
331#define op_put(a, b) a = b
332#if BIT_DEPTH == 8
333#define put_no_rnd_pixels8_8_c put_pixels8_8_c
334PIXOP2(avg, op_avg)
335PIXOP2(put, op_put)
336#endif
337#undef op_avg
338#undef op_put