From patchwork Sun Mar 24 22:44:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 12425 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 73E0E447CB4 for ; Mon, 25 Mar 2019 00:46:44 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6003068AAFB; Mon, 25 Mar 2019 00:46:44 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe06-3.mx.upcmail.net (vie01a-dmta-pe06-3.mx.upcmail.net [84.116.36.16]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1D52468AACF for ; Mon, 25 Mar 2019 00:46:36 +0200 (EET) Received: from [172.31.216.235] (helo=vie01a-pemc-psmtp-pe12.mail.upcmail.net) by vie01a-dmta-pe06.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1h8Bsx-0004Kv-7s for ffmpeg-devel@ffmpeg.org; Sun, 24 Mar 2019 23:46:35 +0100 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id 8BryhXMGLxLwq8BryhnPut; Sun, 24 Mar 2019 23:45:35 +0100 X-Env-Mailfrom: michael@niedermayer.cc X-Env-Rcptto: ffmpeg-devel@ffmpeg.org X-SourceIP: 213.47.41.20 X-CNFS-Analysis: v=2.3 cv=WaxylHpX c=1 sm=1 tr=0 a=I1eytVlZLDX1BM2VTtTtSw==:117 a=I1eytVlZLDX1BM2VTtTtSw==:17 a=jpOVt7BSZ2e4Z31A5e1TngXxSK0=:19 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=GEAsPZ9sns4A:10 a=ZZnuYtJkoWoA:10 a=nZOtpAppAAAA:20 a=C-yDDkFT1SdnN6AH2GIA:9 a=OhkPC1fLFldwfuuS:21 a=jAqO_sG5gWrti2h6:21 a=1fhp2MxaeJtTNGEnv6mo:22 a=pHzHmUro8NiASowvMSCR:22 a=n87TN5wuljxrRezIQYnT:22 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sun, 24 Mar 2019 23:44:26 +0100 Message-Id: <20190324224426.24868-5-michael@niedermayer.cc> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190324224426.24868-1-michael@niedermayer.cc> References: <20190324224426.24868-1-michael@niedermayer.cc> MIME-Version: 1.0 X-CMAE-Envelope: MS4wfNKO331X6+iL74VjXNqpVAWOdQuQGsKROuQYDptvwa4NrVP4vm/qa5AJ5keg0587BSu33aaOhS7+M4y/UCYEOT6la+jd2UhwcjnTZDq7hLP8fUulsMpI 2urJrqJthGXYc+MmklTomRXRE+IYRyRBH8TkpAQfBcLFLj/9oOIIINUD Subject: [FFmpeg-devel] [PATCH 5/5] avcodec/ivi: Reduce dereferencing structs in inner loop of ivi_process_empty_tile() 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This speeds the code up by about 15% Testcase: 13779/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_INDEO4_fuzzer-5699589711069184 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/ivi.c | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/libavcodec/ivi.c b/libavcodec/ivi.c index f87964afd4..0f77873a83 100644 --- a/libavcodec/ivi.c +++ b/libavcodec/ivi.c @@ -775,24 +775,29 @@ static int ivi_process_empty_tile(AVCodecContext *avctx, const IVIBandDesc *band const int16_t *src; int16_t *dst; ivi_mc_func mc_no_delta_func; + int clear_first = !band->qdelta_present && !band->plane && !band->band_num; + int mb_size = band->mb_size; + int xend = tile->xpos + tile->width; + int is_halfpel = band->is_halfpel; + int pitch = band->pitch; - if (tile->num_MBs != IVI_MBs_PER_TILE(tile->width, tile->height, band->mb_size)) { + if (tile->num_MBs != IVI_MBs_PER_TILE(tile->width, tile->height, mb_size)) { av_log(avctx, AV_LOG_ERROR, "Allocated tile size %d mismatches " "parameters %d in ivi_process_empty_tile()\n", - tile->num_MBs, IVI_MBs_PER_TILE(tile->width, tile->height, band->mb_size)); + tile->num_MBs, IVI_MBs_PER_TILE(tile->width, tile->height, mb_size)); return AVERROR_INVALIDDATA; } - offs = tile->ypos * band->pitch + tile->xpos; + offs = tile->ypos * pitch + tile->xpos; mb = tile->mbs; ref_mb = tile->ref_mbs; - row_offset = band->mb_size * band->pitch; + row_offset = mb_size * pitch; need_mc = 0; /* reset the mc tracking flag */ - for (y = tile->ypos; y < (tile->ypos + tile->height); y += band->mb_size) { + for (y = tile->ypos; y < (tile->ypos + tile->height); y += mb_size) { mb_offset = offs; - for (x = tile->xpos; x < (tile->xpos + tile->width); x += band->mb_size) { + for (x = tile->xpos; x < xend; x += mb_size) { mb->xpos = x; mb->ypos = y; mb->buf_offs = mb_offset; @@ -800,7 +805,7 @@ static int ivi_process_empty_tile(AVCodecContext *avctx, const IVIBandDesc *band mb->type = 1; /* set the macroblocks type = INTER */ mb->cbp = 0; /* all blocks are empty */ - if (!band->qdelta_present && !band->plane && !band->band_num) { + if (clear_first) { mb->q_delta = band->glob_quant; mb->mv_x = 0; mb->mv_y = 0; @@ -823,15 +828,15 @@ static int ivi_process_empty_tile(AVCodecContext *avctx, const IVIBandDesc *band { int dmv_x, dmv_y, cx, cy; - dmv_x = mb->mv_x >> band->is_halfpel; - dmv_y = mb->mv_y >> band->is_halfpel; - cx = mb->mv_x & band->is_halfpel; - cy = mb->mv_y & band->is_halfpel; + dmv_x = mb->mv_x >> is_halfpel; + dmv_y = mb->mv_y >> is_halfpel; + cx = mb->mv_x & is_halfpel; + cy = mb->mv_y & is_halfpel; if ( mb->xpos + dmv_x < 0 - || mb->xpos + dmv_x + band->mb_size + cx > band->pitch + || mb->xpos + dmv_x + mb_size + cx > pitch || mb->ypos + dmv_y < 0 - || mb->ypos + dmv_y + band->mb_size + cy > band->aheight) { + || mb->ypos + dmv_y + mb_size + cy > band->aheight) { av_log(avctx, AV_LOG_ERROR, "MV out of bounds\n"); return AVERROR_INVALIDDATA; } @@ -841,13 +846,13 @@ static int ivi_process_empty_tile(AVCodecContext *avctx, const IVIBandDesc *band } mb++; - mb_offset += band->mb_size; + mb_offset += mb_size; } // for x offs += row_offset; } // for y if (band->inherit_mv && need_mc) { /* apply motion compensation if there is at least one non-zero motion vector */ - num_blocks = (band->mb_size != band->blk_size) ? 4 : 1; /* number of blocks per mb */ + num_blocks = (mb_size != band->blk_size) ? 4 : 1; /* number of blocks per mb */ mc_no_delta_func = (band->blk_size == 8) ? ff_ivi_mc_8x8_no_delta : ff_ivi_mc_4x4_no_delta; @@ -864,7 +869,7 @@ static int ivi_process_empty_tile(AVCodecContext *avctx, const IVIBandDesc *band for (blk = 0; blk < num_blocks; blk++) { /* adjust block position in the buffer according with its number */ - offs = mb->buf_offs + band->blk_size * ((blk & 1) + !!(blk & 2) * band->pitch); + offs = mb->buf_offs + band->blk_size * ((blk & 1) + !!(blk & 2) * pitch); ret = ivi_mc(band, mc_no_delta_func, 0, offs, mv_x, mv_y, 0, 0, mc_type, -1); if (ret < 0) @@ -873,12 +878,12 @@ static int ivi_process_empty_tile(AVCodecContext *avctx, const IVIBandDesc *band } } else { /* copy data from the reference tile into the current one */ - src = band->ref_buf + tile->ypos * band->pitch + tile->xpos; - dst = band->buf + tile->ypos * band->pitch + tile->xpos; + src = band->ref_buf + tile->ypos * pitch + tile->xpos; + dst = band->buf + tile->ypos * pitch + tile->xpos; for (y = 0; y < tile->height; y++) { memcpy(dst, src, tile->width*sizeof(band->buf[0])); - src += band->pitch; - dst += band->pitch; + src += pitch; + dst += pitch; } }