From patchwork Sat Sep 9 18:27:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 5066 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.36.26 with SMTP id f26csp1422789jaa; Sat, 9 Sep 2017 11:28:30 -0700 (PDT) X-Google-Smtp-Source: ADKCNb7c65l5r5ojKPLKOYnTg2wp0QV5t2QvMnaY/nJAq+xGiqFxhFtLYDEzG3Ltu6FO/Zwd029p X-Received: by 10.223.157.204 with SMTP id q12mr4217402wre.12.1504981709906; Sat, 09 Sep 2017 11:28:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504981709; cv=none; d=google.com; s=arc-20160816; b=Xv9mlBjnhFeQNqBtk8ESD99WK1zh5BTuEzHVtMxhS22mSD6q59A7V92MwJLrfgOgt1 s0/+8y+cIiB42aFPxt5Y+YDYk0uBovMN/tL+NkIaVcPUagq7Zi2UOAb1zZiM7hRNZf1N EXpaychdWJkNerCTeL9VZUU6DEFeNncA/qkRtvH564Pk0RyTCqi9OzKwT5Upe5PjmAo2 3/dvcNOl75Pi5wmY8psoP9hWPumCbrlQdnz/EWYhsqZy+Fm0lC7opuIR//NOPXa+8gqY cPZxuo16yu+kLEjaFpjZTyF4fmtieKiOjAj5oNHs4kPTSP0/BDkwVMf8qCVJrmYvn6Pm jRBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:delivered-to :arc-authentication-results; bh=KFDTaIrnBtIPiXQ8IaRVKfGaPcor5FrcX7Pgmpb3nds=; b=I9YIgyLAwCDhJoUf1hE7LV90jBnCaLn+tFwynVKVa4qbMS6IOYotIibJv4lnAmueGw 19PkFU7Fj12HSE4Nmi3zFuaZqbFmNLYqniosn5evPL9Z+NAToVyAkkq0zr9bQqOJQZFq 7AxknAE/NWckd7XjnovE2mHgvmnPb+2Jte6SlvFeDxirg55m1KZnqIZNERj46OEqrXHr uSaRmByFL5ZgxTXYxJiy7eAMKtzpO2OYQ4BVqA6xa/yeh0I8ChjGpKM808HMoLIdf4Ox Q3xPRxrZ42z/CTqWIG6GNw7o6If4G9GFpogqo+PsSclltAy5opPauYV8JTVUk+MDksyK 0qWQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 29si3944470wrz.280.2017.09.09.11.28.28; Sat, 09 Sep 2017 11:28:29 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4F65A689208; Sat, 9 Sep 2017 21:28:23 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-qmta-pe01-3.mx.upcmail.net (vie01a-qmta-pe01-3.mx.upcmail.net [62.179.121.180]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A9F66680595 for ; Sat, 9 Sep 2017 21:28:17 +0300 (EEST) Received: from [172.31.218.43] (helo=vie01a-dmta-pe05-1.mx.upcmail.net) by vie01a-pqmta-pe01.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1dqkUP-0006y9-Td for ffmpeg-devel@ffmpeg.org; Sat, 09 Sep 2017 20:28:21 +0200 Received: from [172.31.216.43] (helo=vie01a-pemc-psmtp-pe01) by vie01a-dmta-pe05.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1dqkUK-0005oL-69 for ffmpeg-devel@ffmpeg.org; Sat, 09 Sep 2017 20:28:16 +0200 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe01 with SMTP @ mailcloud.upcmail.net id 7WTg1w02T0S5wYM01WTi49; Sat, 09 Sep 2017 20:27:42 +0200 X-SourceIP: 213.47.41.20 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sat, 9 Sep 2017 20:27:40 +0200 Message-Id: <20170909182740.11094-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.14.1 Subject: [FFmpeg-devel] [PATCH] avcodec/scpr: optimize shift loop. X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" 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 Signed-off-by: Michael Niedermayer --- libavcodec/scpr.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/libavcodec/scpr.c b/libavcodec/scpr.c index 37fbe7a106..cbe1bc40d9 100644 --- a/libavcodec/scpr.c +++ b/libavcodec/scpr.c @@ -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];