]> git.sesse.net Git - ffmpeg/commitdiff
avcodec/scpr: optimize shift loop.
authorMichael Niedermayer <michael@niedermayer.cc>
Fri, 8 Sep 2017 21:29:13 +0000 (23:29 +0200)
committerMichael Niedermayer <michael@niedermayer.cc>
Sun, 10 Sep 2017 17:08:23 +0000 (19:08 +0200)
Speeds code up from 50sec to 15sec

Fixes Timeout
Fixes: 3242/clusterfuzz-testcase-5811951672229888
Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
libavcodec/scpr.c

index 37fbe7a106469b4961ab305a784bab64be7336d6..cbe1bc40d9c8162e933c25aa855c6949e70cb7eb 100644 (file)
@@ -826,8 +826,19 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
         if (ret < 0)
             return ret;
 
+        // scale up each sample by 8
         for (y = 0; y < avctx->height; y++) {
-            for (x = 0; x < avctx->width * 4; x++) {
+            // If the image is sufficiently aligned, compute 8 samples at once
+            if (!(((uintptr_t)dst) & 7)) {
+                uint64_t *dst64 = (uint64_t *)dst;
+                int w = avctx->width>>1;
+                for (x = 0; x < w; x++) {
+                    dst64[x] = (dst64[x] << 3) & 0xFCFCFCFCFCFCFCFCULL;
+                }
+                x *= 8;
+            } else
+                x = 0;
+            for (; x < avctx->width * 4; x++) {
                 dst[x] = dst[x] << 3;
             }
             dst += frame->linesize[0];