qpeldsp_init.c 36.4 KB
Newer Older
1 2
/*
 * quarterpel DSP functions
3 4
 * Copyright (c) 2000, 2001 Fabrice Bellard
 * 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 10 11 12
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
13
 * FFmpeg is distributed in the hope that it will be useful,
14 15 16 17 18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * 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 21 22 23 24 25 26 27 28 29 30 31 32 33
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

#include <stddef.h>
#include <stdint.h>

#include "config.h"
#include "libavutil/attributes.h"
#include "libavutil/cpu.h"
#include "libavutil/x86/cpu.h"
#include "libavcodec/pixels.h"
#include "libavcodec/qpeldsp.h"
#include "fpel.h"

34 35
void ff_put_pixels8_l2_mmxext(uint8_t *dst,
                              const uint8_t *src1, const uint8_t *src2,
36
                              int dstStride, int src1Stride, int h);
37 38 39 40 41
void ff_put_no_rnd_pixels8_l2_mmxext(uint8_t *dst,
                                     const uint8_t *src1, const uint8_t *src2,
                                     int dstStride, int src1Stride, int h);
void ff_avg_pixels8_l2_mmxext(uint8_t *dst,
                              const uint8_t *src1, const uint8_t *src2,
42
                              int dstStride, int src1Stride, int h);
43 44
void ff_put_pixels16_l2_mmxext(uint8_t *dst,
                               const uint8_t *src1, const uint8_t *src2,
45
                               int dstStride, int src1Stride, int h);
46 47
void ff_avg_pixels16_l2_mmxext(uint8_t *dst,
                               const uint8_t *src1, const uint8_t *src2,
48
                               int dstStride, int src1Stride, int h);
49 50
void ff_put_no_rnd_pixels16_l2_mmxext(uint8_t *dst,
                                      const uint8_t *src1, const uint8_t *src2,
51
                                      int dstStride, int src1Stride, int h);
52
void ff_put_mpeg4_qpel16_h_lowpass_mmxext(uint8_t *dst, const uint8_t *src,
53
                                          int dstStride, int srcStride, int h);
54
void ff_avg_mpeg4_qpel16_h_lowpass_mmxext(uint8_t *dst, const uint8_t *src,
55
                                          int dstStride, int srcStride, int h);
56 57
void ff_put_no_rnd_mpeg4_qpel16_h_lowpass_mmxext(uint8_t *dst,
                                                 const uint8_t *src,
58 59
                                                 int dstStride, int srcStride,
                                                 int h);
60
void ff_put_mpeg4_qpel8_h_lowpass_mmxext(uint8_t *dst, const uint8_t *src,
61
                                         int dstStride, int srcStride, int h);
62
void ff_avg_mpeg4_qpel8_h_lowpass_mmxext(uint8_t *dst, const uint8_t *src,
63
                                         int dstStride, int srcStride, int h);
64 65
void ff_put_no_rnd_mpeg4_qpel8_h_lowpass_mmxext(uint8_t *dst,
                                                const uint8_t *src,
66 67
                                                int dstStride, int srcStride,
                                                int h);
68
void ff_put_mpeg4_qpel16_v_lowpass_mmxext(uint8_t *dst, const uint8_t *src,
69
                                          int dstStride, int srcStride);
70
void ff_avg_mpeg4_qpel16_v_lowpass_mmxext(uint8_t *dst, const uint8_t *src,
71
                                          int dstStride, int srcStride);
72 73
void ff_put_no_rnd_mpeg4_qpel16_v_lowpass_mmxext(uint8_t *dst,
                                                 const uint8_t *src,
74
                                                 int dstStride, int srcStride);
75
void ff_put_mpeg4_qpel8_v_lowpass_mmxext(uint8_t *dst, const uint8_t *src,
76
                                         int dstStride, int srcStride);
77
void ff_avg_mpeg4_qpel8_v_lowpass_mmxext(uint8_t *dst, const uint8_t *src,
78
                                         int dstStride, int srcStride);
79 80
void ff_put_no_rnd_mpeg4_qpel8_v_lowpass_mmxext(uint8_t *dst,
                                                const uint8_t *src,
81
                                                int dstStride, int srcStride);
82 83
#define ff_put_no_rnd_pixels16_mmxext ff_put_pixels16_mmx
#define ff_put_no_rnd_pixels8_mmxext ff_put_pixels8_mmx
84

85
#if HAVE_X86ASM
86

87 88
#define ff_put_pixels16_mmxext ff_put_pixels16_mmx
#define ff_put_pixels8_mmxext  ff_put_pixels8_mmx
89 90

#define QPEL_OP(OPNAME, RND, MMX)                                       \
91 92
static void OPNAME ## qpel8_mc00_ ## MMX(uint8_t *dst,                  \
                                         const uint8_t *src,            \
93 94 95 96 97
                                         ptrdiff_t stride)              \
{                                                                       \
    ff_ ## OPNAME ## pixels8_ ## MMX(dst, src, stride, 8);              \
}                                                                       \
                                                                        \
98 99
static void OPNAME ## qpel8_mc10_ ## MMX(uint8_t *dst,                  \
                                         const uint8_t *src,            \
100 101 102 103 104 105 106 107 108 109
                                         ptrdiff_t stride)              \
{                                                                       \
    uint64_t temp[8];                                                   \
    uint8_t *const half = (uint8_t *) temp;                             \
    ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(half, src, 8,        \
                                                   stride, 8);          \
    ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, src, half,                 \
                                        stride, stride, 8);             \
}                                                                       \
                                                                        \
110 111
static void OPNAME ## qpel8_mc20_ ## MMX(uint8_t *dst,                  \
                                         const uint8_t *src,            \
112 113 114 115 116 117
                                         ptrdiff_t stride)              \
{                                                                       \
    ff_ ## OPNAME ## mpeg4_qpel8_h_lowpass_ ## MMX(dst, src, stride,    \
                                                   stride, 8);          \
}                                                                       \
                                                                        \
118 119
static void OPNAME ## qpel8_mc30_ ## MMX(uint8_t *dst,                  \
                                         const uint8_t *src,            \
120 121 122 123 124 125 126 127 128 129
                                         ptrdiff_t stride)              \
{                                                                       \
    uint64_t temp[8];                                                   \
    uint8_t *const half = (uint8_t *) temp;                             \
    ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(half, src, 8,        \
                                                   stride, 8);          \
    ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, src + 1, half, stride,     \
                                        stride, 8);                     \
}                                                                       \
                                                                        \
130 131
static void OPNAME ## qpel8_mc01_ ## MMX(uint8_t *dst,                  \
                                         const uint8_t *src,            \
132 133 134 135 136 137 138 139 140 141
                                         ptrdiff_t stride)              \
{                                                                       \
    uint64_t temp[8];                                                   \
    uint8_t *const half = (uint8_t *) temp;                             \
    ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(half, src,           \
                                                   8, stride);          \
    ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, src, half,                 \
                                        stride, stride, 8);             \
}                                                                       \
                                                                        \
142 143
static void OPNAME ## qpel8_mc02_ ## MMX(uint8_t *dst,                  \
                                         const uint8_t *src,            \
144 145 146 147 148 149
                                         ptrdiff_t stride)              \
{                                                                       \
    ff_ ## OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, src,            \
                                                   stride, stride);     \
}                                                                       \
                                                                        \
150 151
static void OPNAME ## qpel8_mc03_ ## MMX(uint8_t *dst,                  \
                                         const uint8_t *src,            \
152 153 154 155 156 157 158 159 160 161
                                         ptrdiff_t stride)              \
{                                                                       \
    uint64_t temp[8];                                                   \
    uint8_t *const half = (uint8_t *) temp;                             \
    ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(half, src,           \
                                                   8, stride);          \
    ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, src + stride, half, stride,\
                                        stride, 8);                     \
}                                                                       \
                                                                        \
162 163
static void OPNAME ## qpel8_mc11_ ## MMX(uint8_t *dst,                  \
                                         const uint8_t *src,            \
164 165 166 167 168 169 170 171 172 173 174 175 176 177
                                         ptrdiff_t stride)              \
{                                                                       \
    uint64_t half[8 + 9];                                               \
    uint8_t *const halfH  = (uint8_t *) half + 64;                      \
    uint8_t *const halfHV = (uint8_t *) half;                           \
    ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8,       \
                                                   stride, 9);          \
    ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8,           \
                                        stride, 9);                     \
    ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
    ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV,             \
                                        stride, 8, 8);                  \
}                                                                       \
                                                                        \
178 179
static void OPNAME ## qpel8_mc31_ ## MMX(uint8_t *dst,                  \
                                         const uint8_t *src,            \
180 181 182 183 184 185 186 187 188 189 190 191 192 193
                                         ptrdiff_t stride)              \
{                                                                       \
    uint64_t half[8 + 9];                                               \
    uint8_t *const halfH  = (uint8_t *) half + 64;                      \
    uint8_t *const halfHV = (uint8_t *) half;                           \
    ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8,       \
                                                   stride, 9);          \
    ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src + 1, halfH, 8,       \
                                        stride, 9);                     \
    ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
    ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV,             \
                                        stride, 8, 8);                  \
}                                                                       \
                                                                        \
194 195
static void OPNAME ## qpel8_mc13_ ## MMX(uint8_t *dst,                  \
                                         const uint8_t *src,            \
196 197 198 199 200 201 202 203 204 205 206 207 208 209
                                         ptrdiff_t stride)              \
{                                                                       \
    uint64_t half[8 + 9];                                               \
    uint8_t *const halfH  = (uint8_t *) half + 64;                      \
    uint8_t *const halfHV = (uint8_t *) half;                           \
    ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8,       \
                                                   stride, 9);          \
    ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH, 8,           \
                                        stride, 9);                     \
    ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
    ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH + 8, halfHV,         \
                                        stride, 8, 8);                  \
}                                                                       \
                                                                        \
210 211
static void OPNAME ## qpel8_mc33_ ## MMX(uint8_t *dst,                  \
                                         const uint8_t *src,            \
212 213 214 215 216 217 218 219 220 221 222 223 224 225
                                         ptrdiff_t stride)              \
{                                                                       \
    uint64_t half[8 + 9];                                               \
    uint8_t *const halfH  = (uint8_t *) half + 64;                      \
    uint8_t *const halfHV = (uint8_t *) half;                           \
    ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8,       \
                                                   stride, 9);          \
    ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src + 1, halfH, 8,       \
                                        stride, 9);                     \
    ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
    ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH + 8, halfHV,         \
                                        stride, 8, 8);                  \
}                                                                       \
                                                                        \
226 227
static void OPNAME ## qpel8_mc21_ ## MMX(uint8_t *dst,                  \
                                         const uint8_t *src,            \
228 229 230 231 232 233 234 235 236 237 238 239
                                         ptrdiff_t stride)              \
{                                                                       \
    uint64_t half[8 + 9];                                               \
    uint8_t *const halfH  = (uint8_t *) half + 64;                      \
    uint8_t *const halfHV = (uint8_t *) half;                           \
    ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8,       \
                                                   stride, 9);          \
    ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
    ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH, halfHV,             \
                                        stride, 8, 8);                  \
}                                                                       \
                                                                        \
240 241
static void OPNAME ## qpel8_mc23_ ## MMX(uint8_t *dst,                  \
                                         const uint8_t *src,            \
242 243 244 245 246 247 248 249 250 251 252 253
                                         ptrdiff_t stride)              \
{                                                                       \
    uint64_t half[8 + 9];                                               \
    uint8_t *const halfH  = (uint8_t *) half + 64;                      \
    uint8_t *const halfHV = (uint8_t *) half;                           \
    ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8,       \
                                                   stride, 9);          \
    ff_put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
    ff_ ## OPNAME ## pixels8_l2_ ## MMX(dst, halfH + 8, halfHV,         \
                                        stride, 8, 8);                  \
}                                                                       \
                                                                        \
254 255
static void OPNAME ## qpel8_mc12_ ## MMX(uint8_t *dst,                  \
                                         const uint8_t *src,            \
256 257 258 259 260 261 262 263 264 265 266 267
                                         ptrdiff_t stride)              \
{                                                                       \
    uint64_t half[8 + 9];                                               \
    uint8_t *const halfH = (uint8_t *) half;                            \
    ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8,       \
                                                   stride, 9);          \
    ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src, halfH,              \
                                        8, stride, 9);                  \
    ff_ ## OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH,          \
                                                   stride, 8);          \
}                                                                       \
                                                                        \
268 269
static void OPNAME ## qpel8_mc32_ ## MMX(uint8_t *dst,                  \
                                         const uint8_t *src,            \
270 271 272 273 274 275 276 277 278 279 280 281
                                         ptrdiff_t stride)              \
{                                                                       \
    uint64_t half[8 + 9];                                               \
    uint8_t *const halfH = (uint8_t *) half;                            \
    ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8,       \
                                                   stride, 9);          \
    ff_put ## RND ## pixels8_l2_ ## MMX(halfH, src + 1, halfH, 8,       \
                                        stride, 9);                     \
    ff_ ## OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH,          \
                                                   stride, 8);          \
}                                                                       \
                                                                        \
282 283
static void OPNAME ## qpel8_mc22_ ## MMX(uint8_t *dst,                  \
                                         const uint8_t *src,            \
284 285 286 287 288 289 290 291 292 293
                                         ptrdiff_t stride)              \
{                                                                       \
    uint64_t half[9];                                                   \
    uint8_t *const halfH = (uint8_t *) half;                            \
    ff_put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8,       \
                                                   stride, 9);          \
    ff_ ## OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH,          \
                                                   stride, 8);          \
}                                                                       \
                                                                        \
294 295
static void OPNAME ## qpel16_mc00_ ## MMX(uint8_t *dst,                 \
                                          const uint8_t *src,           \
296 297 298 299 300
                                          ptrdiff_t stride)             \
{                                                                       \
    ff_ ## OPNAME ## pixels16_ ## MMX(dst, src, stride, 16);            \
}                                                                       \
                                                                        \
301 302
static void OPNAME ## qpel16_mc10_ ## MMX(uint8_t *dst,                 \
                                          const uint8_t *src,           \
303 304 305 306 307 308 309 310 311 312
                                          ptrdiff_t stride)             \
{                                                                       \
    uint64_t temp[32];                                                  \
    uint8_t *const half = (uint8_t *) temp;                             \
    ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(half, src, 16,      \
                                                    stride, 16);        \
    ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, src, half, stride,        \
                                         stride, 16);                   \
}                                                                       \
                                                                        \
313 314
static void OPNAME ## qpel16_mc20_ ## MMX(uint8_t *dst,                 \
                                          const uint8_t *src,           \
315 316 317 318 319 320
                                          ptrdiff_t stride)             \
{                                                                       \
    ff_ ## OPNAME ## mpeg4_qpel16_h_lowpass_ ## MMX(dst, src,           \
                                                    stride, stride, 16);\
}                                                                       \
                                                                        \
321 322
static void OPNAME ## qpel16_mc30_ ## MMX(uint8_t *dst,                 \
                                          const uint8_t *src,           \
323 324 325 326 327 328 329 330 331 332
                                          ptrdiff_t stride)             \
{                                                                       \
    uint64_t temp[32];                                                  \
    uint8_t *const half = (uint8_t*) temp;                              \
    ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(half, src, 16,      \
                                                    stride, 16);        \
    ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, src + 1, half,            \
                                         stride, stride, 16);           \
}                                                                       \
                                                                        \
333 334
static void OPNAME ## qpel16_mc01_ ## MMX(uint8_t *dst,                 \
                                          const uint8_t *src,           \
335 336 337 338 339 340 341 342 343 344
                                          ptrdiff_t stride)             \
{                                                                       \
    uint64_t temp[32];                                                  \
    uint8_t *const half = (uint8_t *) temp;                             \
    ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(half, src, 16,      \
                                                    stride);            \
    ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, src, half, stride,        \
                                         stride, 16);                   \
}                                                                       \
                                                                        \
345 346
static void OPNAME ## qpel16_mc02_ ## MMX(uint8_t *dst,                 \
                                          const uint8_t *src,           \
347 348 349 350 351 352
                                          ptrdiff_t stride)             \
{                                                                       \
    ff_ ## OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, src,           \
                                                    stride, stride);    \
}                                                                       \
                                                                        \
353 354
static void OPNAME ## qpel16_mc03_ ## MMX(uint8_t *dst,                 \
                                          const uint8_t *src,           \
355 356 357 358 359 360 361 362 363 364
                                          ptrdiff_t stride)             \
{                                                                       \
    uint64_t temp[32];                                                  \
    uint8_t *const half = (uint8_t *) temp;                             \
    ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(half, src, 16,      \
                                                    stride);            \
    ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, src+stride, half,         \
                                         stride, stride, 16);           \
}                                                                       \
                                                                        \
365 366
static void OPNAME ## qpel16_mc11_ ## MMX(uint8_t *dst,                 \
                                          const uint8_t *src,           \
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381
                                          ptrdiff_t stride)             \
{                                                                       \
    uint64_t half[16 * 2 + 17 * 2];                                     \
    uint8_t *const halfH  = (uint8_t *) half + 256;                     \
    uint8_t *const halfHV = (uint8_t *) half;                           \
    ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16,     \
                                                    stride, 17);        \
    ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16,         \
                                         stride, 17);                   \
    ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH,      \
                                                    16, 16);            \
    ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV,            \
                                         stride, 16, 16);               \
}                                                                       \
                                                                        \
382 383
static void OPNAME ## qpel16_mc31_ ## MMX(uint8_t *dst,                 \
                                          const uint8_t *src,           \
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
                                          ptrdiff_t stride)             \
{                                                                       \
    uint64_t half[16 * 2 + 17 * 2];                                     \
    uint8_t *const halfH  = (uint8_t *) half + 256;                     \
    uint8_t *const halfHV = (uint8_t *) half;                           \
    ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16,     \
                                                    stride, 17);        \
    ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src + 1, halfH, 16,     \
                                         stride, 17);                   \
    ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH,      \
                                                    16, 16);            \
    ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV,            \
                                         stride, 16, 16);               \
}                                                                       \
                                                                        \
399 400
static void OPNAME ## qpel16_mc13_ ## MMX(uint8_t *dst,                 \
                                          const uint8_t *src,           \
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415
                                          ptrdiff_t stride)             \
{                                                                       \
    uint64_t half[16 * 2 + 17 * 2];                                     \
    uint8_t *const halfH  = (uint8_t *) half + 256;                     \
    uint8_t *const halfHV = (uint8_t *) half;                           \
    ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16,     \
                                                    stride, 17);        \
    ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16,         \
                                         stride, 17);                   \
    ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH,      \
                                                    16, 16);            \
    ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH + 16, halfHV,       \
                                         stride, 16, 16);               \
}                                                                       \
                                                                        \
416 417
static void OPNAME ## qpel16_mc33_ ## MMX(uint8_t *dst,                 \
                                          const uint8_t *src,           \
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432
                                          ptrdiff_t stride)             \
{                                                                       \
    uint64_t half[16 * 2 + 17 * 2];                                     \
    uint8_t *const halfH  = (uint8_t *) half + 256;                     \
    uint8_t *const halfHV = (uint8_t *) half;                           \
    ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16,     \
                                                    stride, 17);        \
    ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src + 1, halfH, 16,     \
                                         stride, 17);                   \
    ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH,      \
                                                    16, 16);            \
    ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH + 16, halfHV,       \
                                         stride, 16, 16);               \
}                                                                       \
                                                                        \
433 434
static void OPNAME ## qpel16_mc21_ ## MMX(uint8_t *dst,                 \
                                          const uint8_t *src,           \
435 436 437 438 439 440 441 442 443 444 445 446 447
                                          ptrdiff_t stride)             \
{                                                                       \
    uint64_t half[16 * 2 + 17 * 2];                                     \
    uint8_t *const halfH  = (uint8_t *) half + 256;                     \
    uint8_t *const halfHV = (uint8_t *) half;                           \
    ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16,     \
                                                    stride, 17);        \
    ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH,      \
                                                    16, 16);            \
    ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH, halfHV,            \
                                         stride, 16, 16);               \
}                                                                       \
                                                                        \
448 449
static void OPNAME ## qpel16_mc23_ ## MMX(uint8_t *dst,                 \
                                          const uint8_t *src,           \
450 451 452 453 454 455 456 457 458 459 460 461 462
                                          ptrdiff_t stride)             \
{                                                                       \
    uint64_t half[16 * 2 + 17 * 2];                                     \
    uint8_t *const halfH  = (uint8_t *) half + 256;                     \
    uint8_t *const halfHV = (uint8_t *) half;                           \
    ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16,     \
                                                    stride, 17);        \
    ff_put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH,      \
                                                    16, 16);            \
    ff_ ## OPNAME ## pixels16_l2_ ## MMX(dst, halfH + 16, halfHV,       \
                                         stride, 16, 16);               \
}                                                                       \
                                                                        \
463 464
static void OPNAME ## qpel16_mc12_ ## MMX(uint8_t *dst,                 \
                                          const uint8_t *src,           \
465 466 467 468 469 470 471 472 473 474 475 476
                                          ptrdiff_t stride)             \
{                                                                       \
    uint64_t half[17 * 2];                                              \
    uint8_t *const halfH = (uint8_t *) half;                            \
    ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16,     \
                                                    stride, 17);        \
    ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src, halfH, 16,         \
                                         stride, 17);                   \
    ff_ ## OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH,         \
                                                    stride, 16);        \
}                                                                       \
                                                                        \
477 478
static void OPNAME ## qpel16_mc32_ ## MMX(uint8_t *dst,                 \
                                          const uint8_t *src,           \
479 480 481 482 483 484 485 486 487 488 489 490
                                          ptrdiff_t stride)             \
{                                                                       \
    uint64_t half[17 * 2];                                              \
    uint8_t *const halfH = (uint8_t *) half;                            \
    ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16,     \
                                                    stride, 17);        \
    ff_put ## RND ## pixels16_l2_ ## MMX(halfH, src + 1, halfH, 16,     \
                                         stride, 17);                   \
    ff_ ## OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH,         \
                                                    stride, 16);        \
}                                                                       \
                                                                        \
491 492
static void OPNAME ## qpel16_mc22_ ## MMX(uint8_t *dst,                 \
                                          const uint8_t *src,           \
493 494 495 496 497 498 499 500 501 502 503 504 505 506
                                          ptrdiff_t stride)             \
{                                                                       \
    uint64_t half[17 * 2];                                              \
    uint8_t *const halfH = (uint8_t *) half;                            \
    ff_put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16,     \
                                                    stride, 17);        \
    ff_ ## OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH,         \
                                                    stride, 16);        \
}

QPEL_OP(put_,        _,        mmxext)
QPEL_OP(avg_,        _,        mmxext)
QPEL_OP(put_no_rnd_, _no_rnd_, mmxext)

507
#endif /* HAVE_X86ASM */
508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544

#define SET_QPEL_FUNCS(PFX, IDX, SIZE, CPU, PREFIX)                          \
do {                                                                         \
    c->PFX ## _pixels_tab[IDX][ 0] = PREFIX ## PFX ## SIZE ## _mc00_ ## CPU; \
    c->PFX ## _pixels_tab[IDX][ 1] = PREFIX ## PFX ## SIZE ## _mc10_ ## CPU; \
    c->PFX ## _pixels_tab[IDX][ 2] = PREFIX ## PFX ## SIZE ## _mc20_ ## CPU; \
    c->PFX ## _pixels_tab[IDX][ 3] = PREFIX ## PFX ## SIZE ## _mc30_ ## CPU; \
    c->PFX ## _pixels_tab[IDX][ 4] = PREFIX ## PFX ## SIZE ## _mc01_ ## CPU; \
    c->PFX ## _pixels_tab[IDX][ 5] = PREFIX ## PFX ## SIZE ## _mc11_ ## CPU; \
    c->PFX ## _pixels_tab[IDX][ 6] = PREFIX ## PFX ## SIZE ## _mc21_ ## CPU; \
    c->PFX ## _pixels_tab[IDX][ 7] = PREFIX ## PFX ## SIZE ## _mc31_ ## CPU; \
    c->PFX ## _pixels_tab[IDX][ 8] = PREFIX ## PFX ## SIZE ## _mc02_ ## CPU; \
    c->PFX ## _pixels_tab[IDX][ 9] = PREFIX ## PFX ## SIZE ## _mc12_ ## CPU; \
    c->PFX ## _pixels_tab[IDX][10] = PREFIX ## PFX ## SIZE ## _mc22_ ## CPU; \
    c->PFX ## _pixels_tab[IDX][11] = PREFIX ## PFX ## SIZE ## _mc32_ ## CPU; \
    c->PFX ## _pixels_tab[IDX][12] = PREFIX ## PFX ## SIZE ## _mc03_ ## CPU; \
    c->PFX ## _pixels_tab[IDX][13] = PREFIX ## PFX ## SIZE ## _mc13_ ## CPU; \
    c->PFX ## _pixels_tab[IDX][14] = PREFIX ## PFX ## SIZE ## _mc23_ ## CPU; \
    c->PFX ## _pixels_tab[IDX][15] = PREFIX ## PFX ## SIZE ## _mc33_ ## CPU; \
} while (0)

av_cold void ff_qpeldsp_init_x86(QpelDSPContext *c)
{
    int cpu_flags = av_get_cpu_flags();

    if (X86_MMXEXT(cpu_flags)) {
#if HAVE_MMXEXT_EXTERNAL
        SET_QPEL_FUNCS(avg_qpel,        0, 16, mmxext, );
        SET_QPEL_FUNCS(avg_qpel,        1,  8, mmxext, );

        SET_QPEL_FUNCS(put_qpel,        0, 16, mmxext, );
        SET_QPEL_FUNCS(put_qpel,        1,  8, mmxext, );
        SET_QPEL_FUNCS(put_no_rnd_qpel, 0, 16, mmxext, );
        SET_QPEL_FUNCS(put_no_rnd_qpel, 1,  8, mmxext, );
#endif /* HAVE_MMXEXT_EXTERNAL */
    }
}