2 * Copyright (c) 2012 Michael Niedermayer <michaelni@gmx.at>
4 * This file is part of FFmpeg.
6 * FFmpeg 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.
11 * FFmpeg 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.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #include "libavutil/x86/asm.h"
22 #include "libavutil/cpu.h"
23 #include "libswresample/swresample_internal.h"
25 int swri_resample_int16_mmx2 (struct ResampleContext *c, int16_t *dst, const int16_t *src, int *consumed, int src_size, int dst_size, int update_ctx);
26 int swri_resample_int16_sse2 (struct ResampleContext *c, int16_t *dst, const int16_t *src, int *consumed, int src_size, int dst_size, int update_ctx);
27 int swri_resample_float_sse (struct ResampleContext *c, float *dst, const float *src, int *consumed, int src_size, int dst_size, int update_ctx);
29 DECLARE_ALIGNED(16, const uint64_t, ff_resample_int16_rounder)[2] = { 0x0000000000004000ULL, 0x0000000000000000ULL};
31 #define COMMON_CORE_INT16_MMX2 \
32 x86_reg len= -2*c->filter_length;\
34 "movq "MANGLE(ff_resample_int16_rounder)", %%mm0 \n\t"\
36 "movq (%1, %0), %%mm1 \n\t"\
37 "pmaddwd (%2, %0), %%mm1 \n\t"\
38 "paddd %%mm1, %%mm0 \n\t"\
41 "pshufw $0x0E, %%mm0, %%mm1 \n\t"\
42 "paddd %%mm1, %%mm0 \n\t"\
43 "psrad $15, %%mm0 \n\t"\
44 "packssdw %%mm0, %%mm0 \n\t"\
45 "movd %%mm0, (%3) \n\t"\
47 : "r" (((uint8_t*)(src+sample_index))-len),\
48 "r" (((uint8_t*)filter)-len),\
50 NAMED_CONSTRAINTS_ADD(ff_resample_int16_rounder)\
53 #define COMMON_CORE_INT16_SSE2 \
54 x86_reg len= -2*c->filter_length;\
56 "movdqa "MANGLE(ff_resample_int16_rounder)", %%xmm0 \n\t"\
58 "movdqu (%1, %0), %%xmm1 \n\t"\
59 "pmaddwd (%2, %0), %%xmm1 \n\t"\
60 "paddd %%xmm1, %%xmm0 \n\t"\
63 "pshufd $0x0E, %%xmm0, %%xmm1 \n\t"\
64 "paddd %%xmm1, %%xmm0 \n\t"\
65 "pshufd $0x01, %%xmm0, %%xmm1 \n\t"\
66 "paddd %%xmm1, %%xmm0 \n\t"\
67 "psrad $15, %%xmm0 \n\t"\
68 "packssdw %%xmm0, %%xmm0 \n\t"\
69 "movd %%xmm0, (%3) \n\t"\
71 : "r" (((uint8_t*)(src+sample_index))-len),\
72 "r" (((uint8_t*)filter)-len),\
74 NAMED_CONSTRAINTS_ADD(ff_resample_int16_rounder)\
77 #define COMMON_CORE_FLT_SSE \
78 x86_reg len= -4*c->filter_length;\
80 "xorps %%xmm0, %%xmm0 \n\t"\
82 "movups (%1, %0), %%xmm1 \n\t"\
83 "mulps (%2, %0), %%xmm1 \n\t"\
84 "addps %%xmm1, %%xmm0 \n\t"\
87 "movhlps %%xmm0, %%xmm1 \n\t"\
88 "addps %%xmm1, %%xmm0 \n\t"\
89 "movss %%xmm0, %%xmm1 \n\t"\
90 "shufps $1, %%xmm0, %%xmm0 \n\t"\
91 "addps %%xmm1, %%xmm0 \n\t"\
92 "movss %%xmm0, (%3) \n\t"\
94 : "r" (((uint8_t*)(src+sample_index))-len),\
95 "r" (((uint8_t*)filter)-len),\