From patchwork Mon Oct 14 13:22:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: hwren X-Patchwork-Id: 15750 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 0F44D44823B for ; Mon, 14 Oct 2019 16:23:00 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E5F1568999F; Mon, 14 Oct 2019 16:22:59 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from m15-114.126.com (m15-114.126.com [220.181.15.114]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D038C6881FC for ; Mon, 14 Oct 2019 16:22:48 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:Subject:Date:Message-Id; bh=cuLRe7E4f5rcbj3jWK 75tQUOA6qu8n7CflZjVX8z4rA=; b=ZmrmgbAeEWRbiStfWjnu6PBn6kXq0DSVwe I2Un9AQYtLcJxo0WTZ2LLpec42fcRnxctN5n6Kcl5D3SIX8SIrwDeUPGCa2NLvEP sH6q4oBbFOHK1pRuCxZExtq5gYByYWnfdjgj2z5af/YjukCoKPpyx4HOh2MK9f7o nqc/r8+4U= Received: from localhost.localdomain (unknown [115.27.199.30]) by smtp7 (Coremail) with SMTP id DsmowABHJr+mdqRdNhTeCA--.41504S4; Mon, 14 Oct 2019 21:22:47 +0800 (CST) From: hwren To: ffmpeg-devel@ffmpeg.org Date: Mon, 14 Oct 2019 21:22:43 +0800 Message-Id: <1571059365-3263-2-git-send-email-hwrenx@126.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1571059365-3263-1-git-send-email-hwrenx@126.com> References: <4703a40a.8758.16dca6c60d6.Coremail.hwrenx@126.com> <1571059365-3263-1-git-send-email-hwrenx@126.com> X-CM-TRANSID: DsmowABHJr+mdqRdNhTeCA--.41504S4 X-Coremail-Antispam: 1Uf129KBjvJXoW7Ar47tw17Cryrtr1UZr17GFg_yoW8tw15p3 WfWrsxtw15W3WSkrZ3Jw1SqF43WFWkWw1xCrsrJr1vvFyYvFyUWry7GFZ7G3yUKrsrW34Y kF4kK3Z8GF1kA3DanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jn8nOUUUUU= X-Originating-IP: [115.27.199.30] X-CM-SenderInfo: pkzuv0b06rjloofrz/1tbiDwdO6VpD+eWt+wAAs8 Subject: [FFmpeg-devel] [PATCH v5 2/4] lavc/libxavs2: optimize data access 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" Optimize data access from multiplication to iteration. Signed-off-by: hwren --- libavcodec/libxavs2.c | 45 +++++++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/libavcodec/libxavs2.c b/libavcodec/libxavs2.c index 0179a1e..b5c07ec 100644 --- a/libavcodec/libxavs2.c +++ b/libavcodec/libxavs2.c @@ -132,29 +132,42 @@ static av_cold int xavs2_init(AVCodecContext *avctx) static void xavs2_copy_frame_with_shift(xavs2_picture_t *pic, const AVFrame *frame, const int shift_in) { - int j, k; - for (k = 0; k < 3; k++) { - int i_stride = pic->img.i_stride[k]; - for (j = 0; j < pic->img.i_lines[k]; j++) { - uint16_t *p_plane = (uint16_t *)&pic->img.img_planes[k][j * i_stride]; - int i; - uint8_t *p_buffer = frame->data[k] + frame->linesize[k] * j; - memset(p_plane, 0, i_stride); - for (i = 0; i < pic->img.i_width[k]; i++) { - p_plane[i] = p_buffer[i] << shift_in; + uint16_t *p_plane; + uint8_t *p_buffer; + int wIdx; + int hIdx; + int plane; + + for (plane = 0; plane < 3; ++plane) { + p_plane = (uint16_t *)pic->img.img_planes[plane]; + p_buffer = frame->data[plane]; + for (hIdx = 0; hIdx < pic->img.i_lines[plane]; ++hIdx) { + memset(p_plane, 0, pic->img.i_stride[plane]); + for (wIdx = 0; wIdx < pic->img.i_width[plane]; ++wIdx) { + p_plane[wIdx] = p_buffer[wIdx] << shift_in; } + p_plane += pic->img.i_stride[plane]; + p_buffer += frame->linesize[plane]; } } } static void xavs2_copy_frame(xavs2_picture_t *pic, const AVFrame *frame) { - int j, k; - for (k = 0; k < 3; k++) { - for (j = 0; j < pic->img.i_lines[k]; j++) { - memcpy( pic->img.img_planes[k] + pic->img.i_stride[k] * j, - frame->data[k]+frame->linesize[k] * j, - pic->img.i_width[k] * pic->img.in_sample_size); + uint8_t *p_plane; + uint8_t *p_buffer; + int hIdx; + int plane; + int stride; + + for (plane = 0; plane < 3; ++plane) { + p_plane = pic->img.img_planes[plane]; + p_buffer = frame->data[plane]; + stride = pic->img.i_width[plane] * pic->img.in_sample_size; + for (hIdx = 0; hIdx < pic->img.i_lines[plane]; ++hIdx) { + memcpy(p_plane, p_buffer, stride); + p_plane += pic->img.i_stride[plane]; + p_buffer += frame->linesize[plane]; } } }