[FFmpeg-devel] [PATCH] swresample: add swri_resample_double_sse2

James Almer jamrial at gmail.com
Fri Apr 25 09:52:31 CEST 2014


Signed-off-by: James Almer <jamrial at gmail.com>
---
 libswresample/resample.c          |  8 +++++++
 libswresample/resample_template.c | 13 +++++++++--
 libswresample/x86/resample_mmx.h  | 49 +++++++++++++++++++++++++++++++++++++++
 tests/fate/libswresample.mak      | 19 +++++++++++++++
 4 files changed, 87 insertions(+), 2 deletions(-)

diff --git a/libswresample/resample.c b/libswresample/resample.c
index ac87671..0ce74d0 100644
--- a/libswresample/resample.c
+++ b/libswresample/resample.c
@@ -317,6 +317,10 @@ static int set_compensation(ResampleContext *c, int sample_delta, int compensati
 #define TEMPLATE_RESAMPLE_S16_SSE2
 #include "resample_template.c"
 #undef TEMPLATE_RESAMPLE_S16_SSE2
+
+#define TEMPLATE_RESAMPLE_DBL_SSE2
+#include "resample_template.c"
+#undef TEMPLATE_RESAMPLE_DBL_SSE2
 #endif
 
 #endif // HAVE_MMXEXT_INLINE
@@ -344,6 +348,10 @@ static int multiple_resample(ResampleContext *c, AudioData *dst, int dst_size, A
                                                  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);
+#if HAVE_SSE2_INLINE
+        else if(c->format == AV_SAMPLE_FMT_DBLP && (mm_flags&AV_CPU_FLAG_SSE2))
+                                                 ret= swri_resample_double_sse2(c,(double *)dst->ch[i], (const double *)src->ch[i], consumed, src_size, dst_size, i+1==dst->ch_count);
+#endif
         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);
     }
     if(need_emms)
diff --git a/libswresample/resample_template.c b/libswresample/resample_template.c
index f42846a..7624d92 100644
--- a/libswresample/resample_template.c
+++ b/libswresample/resample_template.c
@@ -25,8 +25,9 @@
  * @author Michael Niedermayer <michaelni at gmx.at>
  */
 
-#if defined(TEMPLATE_RESAMPLE_DBL)
-#    define RENAME(N) N ## _double
+#if    defined(TEMPLATE_RESAMPLE_DBL)     \
+    || defined(TEMPLATE_RESAMPLE_DBL_SSE2)
+
 #    define FILTER_SHIFT 0
 #    define DELEM  double
 #    define FELEM  double
@@ -34,6 +35,14 @@
 #    define FELEML double
 #    define OUT(d, v) d = v
 
+#    if defined(TEMPLATE_RESAMPLE_DBL)
+#        define RENAME(N) N ## _double
+#    elif defined(TEMPLATE_RESAMPLE_DBL_SSE2)
+#        define COMMON_CORE COMMON_CORE_DBL_SSE2
+#        define LINEAR_CORE LINEAR_CORE_DBL_SSE2
+#        define RENAME(N) N ## _double_sse2
+#    endif
+
 #elif    defined(TEMPLATE_RESAMPLE_FLT)     \
       || defined(TEMPLATE_RESAMPLE_FLT_SSE)
 
diff --git a/libswresample/x86/resample_mmx.h b/libswresample/x86/resample_mmx.h
index a0df6e1..1d47266 100644
--- a/libswresample/x86/resample_mmx.h
+++ b/libswresample/x86/resample_mmx.h
@@ -25,6 +25,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);
+int swri_resample_double_sse2(struct ResampleContext *c,  double *dst, const  double *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};
 
@@ -191,3 +192,51 @@ __asm__ volatile(\
       "r" (((uint8_t*)(filter+c->filter_alloc))-len)\
     XMM_CLOBBERS_ONLY("%xmm0", "%xmm1", "%xmm2", "%xmm3")\
 );
+
+#define COMMON_CORE_DBL_SSE2 \
+    x86_reg len= -8*c->filter_length;\
+__asm__ volatile(\
+    "xorpd     %%xmm0, %%xmm0     \n\t"\
+    "1:                           \n\t"\
+    "movupd  (%1, %0), %%xmm1     \n\t"\
+    "mulpd   (%2, %0), %%xmm1     \n\t"\
+    "addpd     %%xmm1, %%xmm0     \n\t"\
+    "add       $16, %0            \n\t"\
+    " js 1b                       \n\t"\
+    "movhlps   %%xmm0, %%xmm1     \n\t"\
+    "addpd     %%xmm1, %%xmm0     \n\t"\
+    "movsd     %%xmm0, (%3)       \n\t"\
+    : "+r" (len)\
+    : "r" (((uint8_t*)(src+sample_index))-len),\
+      "r" (((uint8_t*)filter)-len),\
+      "r" (dst+dst_index)\
+);
+
+#define LINEAR_CORE_DBL_SSE2 \
+    x86_reg len= -8*c->filter_length;\
+__asm__ volatile(\
+    "xorpd      %%xmm0, %%xmm0    \n\t"\
+    "xorpd      %%xmm2, %%xmm2    \n\t"\
+    "1:                           \n\t"\
+    "movupd   (%3, %0), %%xmm1    \n\t"\
+    "movapd     %%xmm1, %%xmm3    \n\t"\
+    "mulpd    (%4, %0), %%xmm1    \n\t"\
+    "mulpd    (%5, %0), %%xmm3    \n\t"\
+    "addpd      %%xmm1, %%xmm0    \n\t"\
+    "addpd      %%xmm3, %%xmm2    \n\t"\
+    "add           $16, %0        \n\t"\
+    " js 1b                       \n\t"\
+    "movhlps    %%xmm0, %%xmm1    \n\t"\
+    "movhlps    %%xmm2, %%xmm3    \n\t"\
+    "addpd      %%xmm1, %%xmm0    \n\t"\
+    "addpd      %%xmm3, %%xmm2    \n\t"\
+    "movsd      %%xmm0, %1        \n\t"\
+    "movsd      %%xmm2, %2        \n\t"\
+    : "+r" (len),\
+      "=m" (val),\
+      "=m" (v2)\
+    : "r" (((uint8_t*)(src+sample_index))-len),\
+      "r" (((uint8_t*)filter)-len),\
+      "r" (((uint8_t*)(filter+c->filter_alloc))-len)\
+    XMM_CLOBBERS_ONLY("%xmm0", "%xmm1", "%xmm2", "%xmm3")\
+);
diff --git a/tests/fate/libswresample.mak b/tests/fate/libswresample.mak
index 6a5c314..0c617bf 100644
--- a/tests/fate/libswresample.mak
+++ b/tests/fate/libswresample.mak
@@ -311,6 +311,24 @@ fate-swr-resample_lin-fltp-48000-8000: SIZE_TOLERANCE = 576000 - 20484
 
 fate-swr-resample_lin-fltp-48000-44100: CMP_TARGET = 0.63
 fate-swr-resample_lin-fltp-48000-44100: SIZE_TOLERANCE = 576000 - 20480
+
+fate-swr-resample_lin-dblp-8000-44100: CMP_TARGET = 14.61
+fate-swr-resample_lin-dblp-8000-44100: SIZE_TOLERANCE = 96000 - 20480
+
+fate-swr-resample_lin-dblp-8000-48000: CMP_TARGET = 14.50
+fate-swr-resample_lin-dblp-8000-48000: SIZE_TOLERANCE = 96000 - 20480
+
+fate-swr-resample_lin-dblp-44100-8000: CMP_TARGET = 75.45
+fate-swr-resample_lin-dblp-44100-8000: SIZE_TOLERANCE = 529200 - 20486
+
+fate-swr-resample_lin-dblp-44100-48000: CMP_TARGET = 9.67
+fate-swr-resample_lin-dblp-44100-48000: SIZE_TOLERANCE = 529200 - 20482
+
+fate-swr-resample_lin-dblp-48000-8000: CMP_TARGET = 62.41
+fate-swr-resample_lin-dblp-48000-8000: SIZE_TOLERANCE = 576000 - 20484
+
+fate-swr-resample_lin-dblp-48000-44100: CMP_TARGET = 0.63
+fate-swr-resample_lin-dblp-48000-44100: SIZE_TOLERANCE = 576000 - 20480
 endef
 
 define ARESAMPLE_NN
@@ -343,6 +361,7 @@ $(call CROSS_TEST,$(SAMPLERATES),ARESAMPLE,dblp,f64le,s16)
 
 $(call CROSS_TEST,$(SAMPLERATES_LITE),ARESAMPLE_LIN,s16p,s16le,s16)
 $(call CROSS_TEST,$(SAMPLERATES_LITE),ARESAMPLE_LIN,fltp,f32le,s16)
+$(call CROSS_TEST,$(SAMPLERATES_LITE),ARESAMPLE_LIN,dblp,f64le,s16)
 
 $(call CROSS_TEST,$(SAMPLERATES_NN),ARESAMPLE_NN,s16p,s16le,s16)
 $(call CROSS_TEST,$(SAMPLERATES_NN),ARESAMPLE_NN,fltp,f32le,s16)
-- 
1.8.3.2



More information about the ffmpeg-devel mailing list