configure: Add -D_CRT_NONSTDC_NO_WARNINGS when building with msvc
[ffmpeg.git] / libavcodec / qpel_template.c
1 /*
2  * quarterpel DSP function templates
3  *
4  * This file is part of Libav.
5  *
6  * Libav is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * Libav is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with Libav; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20
21 /**
22  * @file
23  * quarterpel DSP function templates
24  */
25
26 #define PIXOP2(OPNAME, OP)                                              \
27 static inline void OPNAME ## _no_rnd_pixels8_l2_8(uint8_t *dst,         \
28                                                   const uint8_t *src1,  \
29                                                   const uint8_t *src2,  \
30                                                   int dst_stride,       \
31                                                   int src_stride1,      \
32                                                   int src_stride2,      \
33                                                   int h)                \
34 {                                                                       \
35     int i;                                                              \
36                                                                         \
37     for (i = 0; i < h; i++) {                                           \
38         uint32_t a, b;                                                  \
39         a = AV_RN32(&src1[i * src_stride1]);                            \
40         b = AV_RN32(&src2[i * src_stride2]);                            \
41         OP(*((uint32_t *) &dst[i * dst_stride]),                        \
42            no_rnd_avg32(a, b));                                         \
43         a = AV_RN32(&src1[i * src_stride1 + 4]);                        \
44         b = AV_RN32(&src2[i * src_stride2 + 4]);                        \
45         OP(*((uint32_t *) &dst[i * dst_stride + 4]),                    \
46            no_rnd_avg32(a, b));                                         \
47     }                                                                   \
48 }                                                                       \
49                                                                         \
50 static inline void OPNAME ## _no_rnd_pixels16_l2_8(uint8_t *dst,        \
51                                                    const uint8_t *src1, \
52                                                    const uint8_t *src2, \
53                                                    int dst_stride,      \
54                                                    int src_stride1,     \
55                                                    int src_stride2,     \
56                                                    int h)               \
57 {                                                                       \
58     OPNAME ## _no_rnd_pixels8_l2_8(dst, src1, src2, dst_stride,         \
59                                    src_stride1, src_stride2, h);        \
60     OPNAME ## _no_rnd_pixels8_l2_8(dst  + 8,                            \
61                                    src1 + 8,                            \
62                                    src2 + 8,                            \
63                                    dst_stride, src_stride1,             \
64                                    src_stride2, h);                     \
65 }                                                                       \
66                                                                         \
67 static inline void OPNAME ## _pixels8_l4_8(uint8_t *dst,                \
68                                            const uint8_t *src1,         \
69                                            const uint8_t *src2,         \
70                                            const uint8_t *src3,         \
71                                            const uint8_t *src4,         \
72                                            int dst_stride,              \
73                                            int src_stride1,             \
74                                            int src_stride2,             \
75                                            int src_stride3,             \
76                                            int src_stride4,             \
77                                            int h)                       \
78 {                                                                       \
79     /* FIXME HIGH BIT DEPTH */                                          \
80     int i;                                                              \
81                                                                         \
82     for (i = 0; i < h; i++) {                                           \
83         uint32_t a, b, c, d, l0, l1, h0, h1;                            \
84         a  = AV_RN32(&src1[i * src_stride1]);                           \
85         b  = AV_RN32(&src2[i * src_stride2]);                           \
86         c  = AV_RN32(&src3[i * src_stride3]);                           \
87         d  = AV_RN32(&src4[i * src_stride4]);                           \
88         l0 = (a & 0x03030303UL) +                                       \
89              (b & 0x03030303UL) +                                       \
90                   0x02020202UL;                                         \
91         h0 = ((a & 0xFCFCFCFCUL) >> 2) +                                \
92              ((b & 0xFCFCFCFCUL) >> 2);                                 \
93         l1 = (c & 0x03030303UL) +                                       \
94              (d & 0x03030303UL);                                        \
95         h1 = ((c & 0xFCFCFCFCUL) >> 2) +                                \
96              ((d & 0xFCFCFCFCUL) >> 2);                                 \
97         OP(*((uint32_t *) &dst[i * dst_stride]),                        \
98            h0 + h1 + (((l0 + l1) >> 2) & 0x0F0F0F0FUL));                \
99         a  = AV_RN32(&src1[i * src_stride1 + 4]);                       \
100         b  = AV_RN32(&src2[i * src_stride2 + 4]);                       \
101         c  = AV_RN32(&src3[i * src_stride3 + 4]);                       \
102         d  = AV_RN32(&src4[i * src_stride4 + 4]);                       \
103         l0 = (a & 0x03030303UL) +                                       \
104              (b & 0x03030303UL) +                                       \
105                   0x02020202UL;                                         \
106         h0 = ((a & 0xFCFCFCFCUL) >> 2) +                                \
107              ((b & 0xFCFCFCFCUL) >> 2);                                 \
108         l1 = (c & 0x03030303UL) +                                       \
109              (d & 0x03030303UL);                                        \
110         h1 = ((c & 0xFCFCFCFCUL) >> 2) +                                \
111              ((d & 0xFCFCFCFCUL) >> 2);                                 \
112         OP(*((uint32_t *) &dst[i * dst_stride + 4]),                    \
113            h0 + h1 + (((l0 + l1) >> 2) & 0x0F0F0F0FUL));                \
114     }                                                                   \
115 }                                                                       \
116                                                                         \
117 static inline void OPNAME ## _no_rnd_pixels8_l4_8(uint8_t *dst,         \
118                                                   const uint8_t *src1,  \
119                                                   const uint8_t *src2,  \
120                                                   const uint8_t *src3,  \
121                                                   const uint8_t *src4,  \
122                                                   int dst_stride,       \
123                                                   int src_stride1,      \
124                                                   int src_stride2,      \
125                                                   int src_stride3,      \
126                                                   int src_stride4,      \
127                                                   int h)                \
128 {                                                                       \
129     /* FIXME HIGH BIT DEPTH */                                          \
130     int i;                                                              \
131                                                                         \
132     for (i = 0; i < h; i++) {                                           \
133         uint32_t a, b, c, d, l0, l1, h0, h1;                            \
134         a  = AV_RN32(&src1[i * src_stride1]);                           \
135         b  = AV_RN32(&src2[i * src_stride2]);                           \
136         c  = AV_RN32(&src3[i * src_stride3]);                           \
137         d  = AV_RN32(&src4[i * src_stride4]);                           \
138         l0 = (a & 0x03030303UL) +                                       \
139              (b & 0x03030303UL) +                                       \
140                   0x01010101UL;                                         \
141         h0 = ((a & 0xFCFCFCFCUL) >> 2) +                                \
142              ((b & 0xFCFCFCFCUL) >> 2);                                 \
143         l1 = (c & 0x03030303UL) +                                       \
144              (d & 0x03030303UL);                                        \
145         h1 = ((c & 0xFCFCFCFCUL) >> 2) +                                \
146              ((d & 0xFCFCFCFCUL) >> 2);                                 \
147         OP(*((uint32_t *) &dst[i * dst_stride]),                        \
148            h0 + h1 + (((l0 + l1) >> 2) & 0x0F0F0F0FUL));                \
149         a  = AV_RN32(&src1[i * src_stride1 + 4]);                       \
150         b  = AV_RN32(&src2[i * src_stride2 + 4]);                       \
151         c  = AV_RN32(&src3[i * src_stride3 + 4]);                       \
152         d  = AV_RN32(&src4[i * src_stride4 + 4]);                       \
153         l0 = (a & 0x03030303UL) +                                       \
154              (b & 0x03030303UL) +                                       \
155                   0x01010101UL;                                         \
156         h0 = ((a & 0xFCFCFCFCUL) >> 2) +                                \
157              ((b & 0xFCFCFCFCUL) >> 2);                                 \
158         l1 = (c & 0x03030303UL) +                                       \
159              (d & 0x03030303UL);                                        \
160         h1 = ((c & 0xFCFCFCFCUL) >> 2) +                                \
161              ((d & 0xFCFCFCFCUL) >> 2);                                 \
162         OP(*((uint32_t *) &dst[i * dst_stride + 4]),                    \
163            h0 + h1 + (((l0 + l1) >> 2) & 0x0F0F0F0FUL));                \
164     }                                                                   \
165 }                                                                       \
166                                                                         \
167 static inline void OPNAME ## _pixels16_l4_8(uint8_t *dst,               \
168                                             const uint8_t *src1,        \
169                                             const uint8_t *src2,        \
170                                             const uint8_t *src3,        \
171                                             const uint8_t *src4,        \
172                                             int dst_stride,             \
173                                             int src_stride1,            \
174                                             int src_stride2,            \
175                                             int src_stride3,            \
176                                             int src_stride4,            \
177                                             int h)                      \
178 {                                                                       \
179     OPNAME ## _pixels8_l4_8(dst, src1, src2, src3, src4, dst_stride,    \
180                             src_stride1, src_stride2, src_stride3,      \
181                             src_stride4, h);                            \
182     OPNAME ## _pixels8_l4_8(dst  + 8,                                   \
183                             src1 + 8, src2 + 8,                         \
184                             src3 + 8, src4 + 8,                         \
185                             dst_stride, src_stride1, src_stride2,       \
186                             src_stride3, src_stride4, h);               \
187 }                                                                       \
188                                                                         \
189 static inline void OPNAME ## _no_rnd_pixels16_l4_8(uint8_t *dst,        \
190                                                    const uint8_t *src1, \
191                                                    const uint8_t *src2, \
192                                                    const uint8_t *src3, \
193                                                    const uint8_t *src4, \
194                                                    int dst_stride,      \
195                                                    int src_stride1,     \
196                                                    int src_stride2,     \
197                                                    int src_stride3,     \
198                                                    int src_stride4,     \
199                                                    int h)               \
200 {                                                                       \
201     OPNAME ## _no_rnd_pixels8_l4_8(dst, src1, src2, src3, src4,         \
202                                    dst_stride, src_stride1,             \
203                                    src_stride2, src_stride3,            \
204                                    src_stride4, h);                     \
205     OPNAME ## _no_rnd_pixels8_l4_8(dst  + 8,                            \
206                                    src1 + 8, src2 + 8,                  \
207                                    src3 + 8, src4 + 8,                  \
208                                    dst_stride, src_stride1,             \
209                                    src_stride2, src_stride3,            \
210                                    src_stride4, h);                     \
211 }                                                                       \
212
213 #define op_avg(a, b) a = rnd_avg32(a, b)
214 #define op_put(a, b) a = b
215 #define put_no_rnd_pixels8_8_c put_pixels8_8_c
216 PIXOP2(avg, op_avg)
217 PIXOP2(put, op_put)
218 #undef op_avg
219 #undef op_put