hpeldsp_template: Drop av_unused attribute from *_no_rnd_pixels16_8_c functions
[ffmpeg.git] / libavcodec / hpeldsp_template.c
1 /*
2  * Half-pel DSP functions
3  *
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
28  * Half-pel DSP functions
29  */
30
31 #include "pixels.h"
32
33 #define PIXOP2(OPNAME, OP)                                              \
34 static inline void OPNAME ## _no_rnd_pixels8_l2_8(uint8_t *dst,         \
35                                                   const uint8_t *src1,  \
36                                                   const uint8_t *src2,  \
37                                                   int dst_stride,       \
38                                                   int src_stride1,      \
39                                                   int src_stride2,      \
40                                                   int h)                \
41 {                                                                       \
42     int i;                                                              \
43                                                                         \
44     for (i = 0; i < h; i++) {                                           \
45         uint32_t a, b;                                                  \
46         a = AV_RN32(&src1[i * src_stride1]);                            \
47         b = AV_RN32(&src2[i * src_stride2]);                            \
48         OP(*((uint32_t *) &dst[i * dst_stride]),                        \
49            no_rnd_avg32(a, b));                                         \
50         a = AV_RN32(&src1[i * src_stride1 + 4]);                        \
51         b = AV_RN32(&src2[i * src_stride2 + 4]);                        \
52         OP(*((uint32_t *) &dst[i * dst_stride + 4]),                    \
53            no_rnd_avg32(a, b));                                         \
54     }                                                                   \
55 }                                                                       \
56                                                                         \
57 static inline void OPNAME ## _no_rnd_pixels8_x2_8_c(uint8_t *block,     \
58                                                     const uint8_t *pixels, \
59                                                     ptrdiff_t line_size, \
60                                                     int h)              \
61 {                                                                       \
62     OPNAME ## _no_rnd_pixels8_l2_8(block, pixels, pixels + 1,           \
63                                    line_size, line_size, line_size, h); \
64 }                                                                       \
65                                                                         \
66 static inline void OPNAME ## _pixels8_x2_8_c(uint8_t *block,            \
67                                              const uint8_t *pixels,     \
68                                              ptrdiff_t line_size,       \
69                                              int h)                     \
70 {                                                                       \
71     OPNAME ## _pixels8_l2_8(block, pixels, pixels + 1,                  \
72                             line_size, line_size, line_size, h);        \
73 }                                                                       \
74                                                                         \
75 static inline void OPNAME ## _no_rnd_pixels8_y2_8_c(uint8_t *block,     \
76                                                     const uint8_t *pixels, \
77                                                     ptrdiff_t line_size, \
78                                                     int h)              \
79 {                                                                       \
80     OPNAME ## _no_rnd_pixels8_l2_8(block, pixels, pixels + line_size,   \
81                                    line_size, line_size, line_size, h); \
82 }                                                                       \
83                                                                         \
84 static inline void OPNAME ## _pixels8_y2_8_c(uint8_t *block,            \
85                                              const uint8_t *pixels,     \
86                                              ptrdiff_t line_size,       \
87                                              int h)                     \
88 {                                                                       \
89     OPNAME ## _pixels8_l2_8(block, pixels, pixels + line_size,          \
90                             line_size, line_size, line_size, h);        \
91 }                                                                       \
92                                                                         \
93 static inline void OPNAME ## _pixels4_x2_8_c(uint8_t *block,            \
94                                              const uint8_t *pixels,     \
95                                              ptrdiff_t line_size,       \
96                                              int h)                     \
97 {                                                                       \
98     OPNAME ## _pixels4_l2_8(block, pixels, pixels + 1,                  \
99                             line_size, line_size, line_size, h);        \
100 }                                                                       \
101                                                                         \
102 static inline void OPNAME ## _pixels4_y2_8_c(uint8_t *block,            \
103                                              const uint8_t *pixels,     \
104                                              ptrdiff_t line_size,       \
105                                              int h)                     \
106 {                                                                       \
107     OPNAME ## _pixels4_l2_8(block, pixels, pixels + line_size,          \
108                             line_size, line_size, line_size, h);        \
109 }                                                                       \
110                                                                         \
111 static inline void OPNAME ## _pixels2_x2_8_c(uint8_t *block,            \
112                                              const uint8_t *pixels,     \
113                                              ptrdiff_t line_size,       \
114                                              int h)                     \
115 {                                                                       \
116     OPNAME ## _pixels2_l2_8(block, pixels, pixels + 1,                  \
117                             line_size, line_size, line_size, h);        \
118 }                                                                       \
119                                                                         \
120 static inline void OPNAME ## _pixels2_y2_8_c(uint8_t *block,            \
121                                              const uint8_t *pixels,     \
122                                              ptrdiff_t line_size,       \
123                                              int h)                     \
124 {                                                                       \
125     OPNAME ## _pixels2_l2_8(block, pixels, pixels + line_size,          \
126                             line_size, line_size, line_size, h);        \
127 }                                                                       \
128                                                                         \
129 static inline void OPNAME ## _pixels2_xy2_8_c(uint8_t *block,           \
130                                               const uint8_t *pixels,    \
131                                               ptrdiff_t line_size,      \
132                                               int h)                    \
133 {                                                                       \
134     int i, a1, b1;                                                      \
135     int a0 = pixels[0];                                                 \
136     int b0 = pixels[1] + 2;                                             \
137                                                                         \
138     a0 += b0;                                                           \
139     b0 += pixels[2];                                                    \
140     pixels += line_size;                                                \
141     for (i = 0; i < h; i += 2) {                                        \
142         a1  = pixels[0];                                                \
143         b1  = pixels[1];                                                \
144         a1 += b1;                                                       \
145         b1 += pixels[2];                                                \
146                                                                         \
147         block[0] = (a1 + a0) >> 2; /* FIXME non put */                  \
148         block[1] = (b1 + b0) >> 2;                                      \
149                                                                         \
150         pixels += line_size;                                            \
151         block  += line_size;                                            \
152                                                                         \
153         a0  = pixels[0];                                                \
154         b0  = pixels[1] + 2;                                            \
155         a0 += b0;                                                       \
156         b0 += pixels[2];                                                \
157                                                                         \
158         block[0] = (a1 + a0) >> 2;                                      \
159         block[1] = (b1 + b0) >> 2;                                      \
160         pixels  += line_size;                                           \
161         block   += line_size;                                           \
162     }                                                                   \
163 }                                                                       \
164                                                                         \
165 static inline void OPNAME ## _pixels4_xy2_8_c(uint8_t *block,           \
166                                               const uint8_t *pixels,    \
167                                               ptrdiff_t line_size,      \
168                                               int h)                    \
169 {                                                                       \
170     /* FIXME HIGH BIT DEPTH */                                          \
171     int i;                                                              \
172     const uint32_t a = AV_RN32(pixels);                                 \
173     const uint32_t b = AV_RN32(pixels + 1);                             \
174     uint32_t l0 = (a & 0x03030303UL) +                                  \
175                   (b & 0x03030303UL) +                                  \
176                        0x02020202UL;                                    \
177     uint32_t h0 = ((a & 0xFCFCFCFCUL) >> 2) +                           \
178                   ((b & 0xFCFCFCFCUL) >> 2);                            \
179     uint32_t l1, h1;                                                    \
180                                                                         \
181     pixels += line_size;                                                \
182     for (i = 0; i < h; i += 2) {                                        \
183         uint32_t a = AV_RN32(pixels);                                   \
184         uint32_t b = AV_RN32(pixels + 1);                               \
185         l1 = (a & 0x03030303UL) +                                       \
186              (b & 0x03030303UL);                                        \
187         h1 = ((a & 0xFCFCFCFCUL) >> 2) +                                \
188              ((b & 0xFCFCFCFCUL) >> 2);                                 \
189         OP(*((uint32_t *) block), h0 + h1 +                             \
190            (((l0 + l1) >> 2) & 0x0F0F0F0FUL));                          \
191         pixels += line_size;                                            \
192         block  += line_size;                                            \
193         a  = AV_RN32(pixels);                                           \
194         b  = AV_RN32(pixels + 1);                                       \
195         l0 = (a & 0x03030303UL) +                                       \
196              (b & 0x03030303UL) +                                       \
197                   0x02020202UL;                                         \
198         h0 = ((a & 0xFCFCFCFCUL) >> 2) +                                \
199              ((b & 0xFCFCFCFCUL) >> 2);                                 \
200         OP(*((uint32_t *) block), h0 + h1 +                             \
201            (((l0 + l1) >> 2) & 0x0F0F0F0FUL));                          \
202         pixels += line_size;                                            \
203         block  += line_size;                                            \
204     }                                                                   \
205 }                                                                       \
206                                                                         \
207 static inline void OPNAME ## _pixels8_xy2_8_c(uint8_t *block,           \
208                                               const uint8_t *pixels,    \
209                                               ptrdiff_t line_size,      \
210                                               int h)                    \
211 {                                                                       \
212     /* FIXME HIGH BIT DEPTH */                                          \
213     int j;                                                              \
214                                                                         \
215     for (j = 0; j < 2; j++) {                                           \
216         int i;                                                          \
217         const uint32_t a = AV_RN32(pixels);                             \
218         const uint32_t b = AV_RN32(pixels + 1);                         \
219         uint32_t l0 = (a & 0x03030303UL) +                              \
220                       (b & 0x03030303UL) +                              \
221                            0x02020202UL;                                \
222         uint32_t h0 = ((a & 0xFCFCFCFCUL) >> 2) +                       \
223                       ((b & 0xFCFCFCFCUL) >> 2);                        \
224         uint32_t l1, h1;                                                \
225                                                                         \
226         pixels += line_size;                                            \
227         for (i = 0; i < h; i += 2) {                                    \
228             uint32_t a = AV_RN32(pixels);                               \
229             uint32_t b = AV_RN32(pixels + 1);                           \
230             l1 = (a & 0x03030303UL) +                                   \
231                  (b & 0x03030303UL);                                    \
232             h1 = ((a & 0xFCFCFCFCUL) >> 2) +                            \
233                  ((b & 0xFCFCFCFCUL) >> 2);                             \
234             OP(*((uint32_t *) block), h0 + h1 +                         \
235                (((l0 + l1) >> 2) & 0x0F0F0F0FUL));                      \
236             pixels += line_size;                                        \
237             block  += line_size;                                        \
238             a  = AV_RN32(pixels);                                       \
239             b  = AV_RN32(pixels + 1);                                   \
240             l0 = (a & 0x03030303UL) +                                   \
241                  (b & 0x03030303UL) +                                   \
242                       0x02020202UL;                                     \
243             h0 = ((a & 0xFCFCFCFCUL) >> 2) +                            \
244                  ((b & 0xFCFCFCFCUL) >> 2);                             \
245             OP(*((uint32_t *) block), h0 + h1 +                         \
246                (((l0 + l1) >> 2) & 0x0F0F0F0FUL));                      \
247             pixels += line_size;                                        \
248             block  += line_size;                                        \
249         }                                                               \
250         pixels += 4 - line_size * (h + 1);                              \
251         block  += 4 - line_size * h;                                    \
252     }                                                                   \
253 }                                                                       \
254                                                                         \
255 static inline void OPNAME ## _no_rnd_pixels8_xy2_8_c(uint8_t *block,    \
256                                                      const uint8_t *pixels, \
257                                                      ptrdiff_t line_size, \
258                                                      int h)             \
259 {                                                                       \
260     /* FIXME HIGH BIT DEPTH */                                          \
261     int j;                                                              \
262                                                                         \
263     for (j = 0; j < 2; j++) {                                           \
264         int i;                                                          \
265         const uint32_t a = AV_RN32(pixels);                             \
266         const uint32_t b = AV_RN32(pixels + 1);                         \
267         uint32_t l0 = (a & 0x03030303UL) +                              \
268                       (b & 0x03030303UL) +                              \
269                            0x01010101UL;                                \
270         uint32_t h0 = ((a & 0xFCFCFCFCUL) >> 2) +                       \
271                       ((b & 0xFCFCFCFCUL) >> 2);                        \
272         uint32_t l1, h1;                                                \
273                                                                         \
274         pixels += line_size;                                            \
275         for (i = 0; i < h; i += 2) {                                    \
276             uint32_t a = AV_RN32(pixels);                               \
277             uint32_t b = AV_RN32(pixels + 1);                           \
278             l1 = (a & 0x03030303UL) +                                   \
279                  (b & 0x03030303UL);                                    \
280             h1 = ((a & 0xFCFCFCFCUL) >> 2) +                            \
281                  ((b & 0xFCFCFCFCUL) >> 2);                             \
282             OP(*((uint32_t *) block), h0 + h1 +                         \
283                (((l0 + l1) >> 2) & 0x0F0F0F0FUL));                      \
284             pixels += line_size;                                        \
285             block  += line_size;                                        \
286             a  = AV_RN32(pixels);                                       \
287             b  = AV_RN32(pixels + 1);                                   \
288             l0 = (a & 0x03030303UL) +                                   \
289                  (b & 0x03030303UL) +                                   \
290                       0x01010101UL;                                     \
291             h0 = ((a & 0xFCFCFCFCUL) >> 2) +                            \
292                  ((b & 0xFCFCFCFCUL) >> 2);                             \
293             OP(*((uint32_t *) block), h0 + h1 +                         \
294                (((l0 + l1) >> 2) & 0x0F0F0F0FUL));                      \
295             pixels += line_size;                                        \
296             block  += line_size;                                        \
297         }                                                               \
298         pixels += 4 - line_size * (h + 1);                              \
299         block  += 4 - line_size * h;                                    \
300     }                                                                   \
301 }                                                                       \
302                                                                         \
303 CALL_2X_PIXELS(OPNAME ## _pixels16_x2_8_c,                              \
304                OPNAME ## _pixels8_x2_8_c,                               \
305                8)                                                       \
306 CALL_2X_PIXELS(OPNAME ## _pixels16_y2_8_c,                              \
307                OPNAME ## _pixels8_y2_8_c,                               \
308                8)                                                       \
309 CALL_2X_PIXELS(OPNAME ## _pixels16_xy2_8_c,                             \
310                OPNAME ## _pixels8_xy2_8_c,                              \
311                8)                                                       \
312 CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_8_c,                          \
313                OPNAME ## _pixels8_8_c,                                  \
314                8)                                                       \
315 CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_x2_8_c,                       \
316                OPNAME ## _no_rnd_pixels8_x2_8_c,                        \
317                8)                                                       \
318 CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_y2_8_c,                       \
319                OPNAME ## _no_rnd_pixels8_y2_8_c,                        \
320                8)                                                       \
321 CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_xy2_8_c,                      \
322                OPNAME ## _no_rnd_pixels8_xy2_8_c,                       \
323                8)                                                       \
324
325 #define op_avg(a, b) a = rnd_avg32(a, b)
326 #define op_put(a, b) a = b
327 #define put_no_rnd_pixels8_8_c put_pixels8_8_c
328 PIXOP2(avg, op_avg)
329 PIXOP2(put, op_put)
330 #undef op_avg
331 #undef op_put