[FFmpeg-cvslog] swresample/resample_template: Reorder operations to avoid one addition

Michael Niedermayer git at videolan.org
Sat Dec 10 03:46:50 EET 2016


ffmpeg | branch: master | Michael Niedermayer <michael at niedermayer.cc> | Sat Dec 10 01:54:13 2016 +0100| [34db650784fbc6120631c2fc9bd25c083b4be02b] | committer: Michael Niedermayer

swresample/resample_template: Reorder operations to avoid one addition

Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=34db650784fbc6120631c2fc9bd25c083b4be02b
---

 libswresample/resample_template.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/libswresample/resample_template.c b/libswresample/resample_template.c
index 1636f4e..31cf350 100644
--- a/libswresample/resample_template.c
+++ b/libswresample/resample_template.c
@@ -32,6 +32,7 @@
 #    define DELEM  double
 #    define FELEM  double
 #    define FELEM2 double
+#    define FOFFSET 0
 #    define OUT(d, v) d = v
 
 #elif    defined(TEMPLATE_RESAMPLE_FLT)
@@ -41,6 +42,7 @@
 #    define DELEM  float
 #    define FELEM  float
 #    define FELEM2 float
+#    define FOFFSET 0
 #    define OUT(d, v) d = v
 
 #elif defined(TEMPLATE_RESAMPLE_S32)
@@ -52,8 +54,8 @@
 #    define FELEM2 int64_t
 #    define FELEM_MAX INT32_MAX
 #    define FELEM_MIN INT32_MIN
-#    define OUT(d, v) (v) = ((v) + (1<<(FILTER_SHIFT-1)))>>FILTER_SHIFT;\
-                      (d) = av_clipl_int32(v)
+#    define FOFFSET (1<<(FILTER_SHIFT-1))
+#    define OUT(d, v) (d) = av_clipl_int32((v)>>FILTER_SHIFT)
 
 #elif    defined(TEMPLATE_RESAMPLE_S16)
 
@@ -65,8 +67,8 @@
 #    define FELEML int64_t
 #    define FELEM_MAX INT16_MAX
 #    define FELEM_MIN INT16_MIN
-#    define OUT(d, v) (v) = ((v) + (1<<(FILTER_SHIFT-1)))>>FILTER_SHIFT;\
-                      (d) = av_clip_int16(v)
+#    define FOFFSET (1<<(FILTER_SHIFT-1))
+#    define OUT(d, v) (d) = av_clip_int16((v)>>FILTER_SHIFT)
 
 #endif
 
@@ -102,7 +104,7 @@ static int RENAME(resample_common)(ResampleContext *c,
     for (dst_index = 0; dst_index < n; dst_index++) {
         FELEM *filter = ((FELEM *) c->filter_bank) + c->filter_alloc * index;
 
-        FELEM2 val=0;
+        FELEM2 val= FOFFSET;
         int i;
         for (i = 0; i < c->filter_length; i++) {
             val += src[sample_index + i] * (FELEM2)filter[i];
@@ -151,7 +153,7 @@ static int RENAME(resample_linear)(ResampleContext *c,
 
     for (dst_index = 0; dst_index < n; dst_index++) {
         FELEM *filter = ((FELEM *) c->filter_bank) + c->filter_alloc * index;
-        FELEM2 val=0, v2 = 0;
+        FELEM2 val = FOFFSET, v2 = FOFFSET;
 
         int i;
         for (i = 0; i < c->filter_length; i++) {
@@ -199,3 +201,4 @@ static int RENAME(resample_linear)(ResampleContext *c,
 #undef FELEM_MAX
 #undef FELEM_MIN
 #undef OUT
+#undef FOFFSET



More information about the ffmpeg-cvslog mailing list