[FFmpeg-devel] [PATCH] swresample: add swri_resample_float_sse
James Almer
jamrial at gmail.com
Thu Mar 20 05:40:56 CET 2014
At least two times faster than the C version.
Signed-off-by: James Almer <jamrial at gmail.com>
---
libswresample/resample.c | 10 ++++++++++
libswresample/resample_template.c | 12 ++++++++++--
libswresample/x86/resample_mmx.h | 23 +++++++++++++++++++++++
3 files changed, 43 insertions(+), 2 deletions(-)
diff --git a/libswresample/resample.c b/libswresample/resample.c
index 034b47a..581382f 100644
--- a/libswresample/resample.c
+++ b/libswresample/resample.c
@@ -302,6 +302,12 @@ static int set_compensation(ResampleContext *c, int sample_delta, int compensati
#include "resample_template.c"
#undef TEMPLATE_RESAMPLE_S16_MMX2
+#if HAVE_SSE_INLINE
+#define TEMPLATE_RESAMPLE_FLT_SSE
+#include "resample_template.c"
+#undef TEMPLATE_RESAMPLE_FLT_SSE
+#endif
+
#if HAVE_SSE2_INLINE
#define TEMPLATE_RESAMPLE_S16_SSE2
#include "resample_template.c"
@@ -328,6 +334,10 @@ static int multiple_resample(ResampleContext *c, AudioData *dst, int dst_size, A
#endif
if(c->format == AV_SAMPLE_FMT_S16P) ret= swri_resample_int16(c, (int16_t*)dst->ch[i], (const int16_t*)src->ch[i], consumed, src_size, dst_size, i+1==dst->ch_count);
else if(c->format == AV_SAMPLE_FMT_S32P) ret= swri_resample_int32(c, (int32_t*)dst->ch[i], (const int32_t*)src->ch[i], consumed, src_size, dst_size, i+1==dst->ch_count);
+#if HAVE_SSE_INLINE
+ else if(c->format == AV_SAMPLE_FMT_FLTP && (mm_flags&AV_CPU_FLAG_SSE))
+ ret= swri_resample_float_sse (c, (float*)dst->ch[i], (const float*)src->ch[i], consumed, src_size, dst_size, i+1==dst->ch_count);
+#endif
else if(c->format == AV_SAMPLE_FMT_FLTP) ret= swri_resample_float(c, (float *)dst->ch[i], (const float *)src->ch[i], consumed, src_size, dst_size, i+1==dst->ch_count);
else if(c->format == AV_SAMPLE_FMT_DBLP) ret= swri_resample_double(c,(double *)dst->ch[i], (const double *)src->ch[i], consumed, src_size, dst_size, i+1==dst->ch_count);
}
diff --git a/libswresample/resample_template.c b/libswresample/resample_template.c
index f11053d..8d5ff4d 100644
--- a/libswresample/resample_template.c
+++ b/libswresample/resample_template.c
@@ -34,8 +34,9 @@
# define FELEML double
# define OUT(d, v) d = v
-#elif defined(TEMPLATE_RESAMPLE_FLT)
-# define RENAME(N) N ## _float
+#elif defined(TEMPLATE_RESAMPLE_FLT) \
+ || defined(TEMPLATE_RESAMPLE_FLT_SSE)
+
# define FILTER_SHIFT 0
# define DELEM float
# define FELEM float
@@ -43,6 +44,13 @@
# define FELEML float
# define OUT(d, v) d = v
+# if defined(TEMPLATE_RESAMPLE_FLT)
+# define RENAME(N) N ## _float
+# elif defined(TEMPLATE_RESAMPLE_FLT_SSE)
+# define COMMON_CORE COMMON_CORE_FLT_SSE
+# define RENAME(N) N ## _float_sse
+# endif
+
#elif defined(TEMPLATE_RESAMPLE_S32)
# define RENAME(N) N ## _int32
# define FILTER_SHIFT 30
diff --git a/libswresample/x86/resample_mmx.h b/libswresample/x86/resample_mmx.h
index f366cc7..ba36de9 100644
--- a/libswresample/x86/resample_mmx.h
+++ b/libswresample/x86/resample_mmx.h
@@ -24,6 +24,7 @@
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);
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);
+int swri_resample_float_sse (struct ResampleContext *c, float *dst, const float *src, int *consumed, int src_size, int dst_size, int update_ctx);
DECLARE_ALIGNED(16, const uint64_t, ff_resample_int16_rounder)[2] = { 0x0000000000004000ULL, 0x0000000000000000ULL};
@@ -72,3 +73,25 @@ __asm__ volatile(\
"r" (dst+dst_index)\
NAMED_CONSTRAINTS_ADD(ff_resample_int16_rounder)\
);
+
+#define COMMON_CORE_FLT_SSE \
+ x86_reg len= -4*c->filter_length;\
+__asm__ volatile(\
+ "xorps %%xmm0, %%xmm0 \n\t"\
+ "1: \n\t"\
+ "movups (%1, %0), %%xmm1 \n\t"\
+ "mulps (%2, %0), %%xmm1 \n\t"\
+ "addps %%xmm1, %%xmm0 \n\t"\
+ "add $16, %0 \n\t"\
+ " js 1b \n\t"\
+ "movhlps %%xmm0, %%xmm1 \n\t"\
+ "addps %%xmm1, %%xmm0 \n\t"\
+ "movss %%xmm0, %%xmm1 \n\t"\
+ "shufps $1, %%xmm0, %%xmm0 \n\t"\
+ "addps %%xmm1, %%xmm0 \n\t"\
+ "movss %%xmm0, (%3) \n\t"\
+ : "+r" (len)\
+ : "r" (((uint8_t*)(src+sample_index))-len),\
+ "r" (((uint8_t*)filter)-len),\
+ "r" (dst+dst_index)\
+);
--
1.8.3.2
More information about the ffmpeg-devel
mailing list