From patchwork Mon Aug 31 21:09:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22034 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 D2E5B44B3A0 for ; Tue, 1 Sep 2020 00:10:08 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B6C4968ACD0; Tue, 1 Sep 2020 00:10:08 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 919C1687F68 for ; Tue, 1 Sep 2020 00:10:02 +0300 (EEST) Received: by mail-wm1-f65.google.com with SMTP id a65so774881wme.5 for ; Mon, 31 Aug 2020 14:10:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ti7bqAmwrUCT7lci8xUEtMJ7f3TZdYjWaIjnCDGhbNI=; b=UloVFGlNk4QCsyKJe3MBWR1fBPhmwPKnI2Mw+PvFjvZUE6BYpNZLDXLOsF1ullZkJK xOvcU6KaPQHNuBC8MjEBWqo2VUKpx+pYEY4gl+VZvnOdbMwFlH/v3Few8717J+vp/Pe3 RE+oyuPBfJ3rWw+SL60GFmR+oFRtskcIwnX3BrT+6YlYEm6lYOypCkAw8Ql/KKfb4Suv q9LUucL5rXkUaSLH27b6c+4Mi7Z0MAKcJ7gJu1k6emI1BCF+Z61+x2YBJOeNFo0oKeL1 KGJJFjukDa1Ghbl3bwjSrTDXYhAlTu3+5zyV9mXDGFEKXX3disX7aP84UxFS/jlx8i5p Sjqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ti7bqAmwrUCT7lci8xUEtMJ7f3TZdYjWaIjnCDGhbNI=; b=OC/TkkJ+d3Yx3m1TTaggzBE3MUyf74pEUdrbcdI2Q3NypkvNq5j50S9MPgISFQF1Lb Ac/muxydRDi5BibTqfOTCAs2j08lQurF/ir7Mwa4yWaQxoAP/3IMatIY2FtT1oyu8Dmj BIvZ2neejx5GCYAIk8WcbBw8LoOsnCJl9Wfsrbph4uBht0bStfobfrTf4WF21xdBiCcD 2EjPV4Btfd4n4UqWFmMr2W92CAJsA3IbVu3HO85kjhITE7n+bFkKyEVVUvMQgmcLdtQV u9qveE/0tclbb+7byQAwkOd2RP0HViLV7z/HK0ov0P81FRXE7wjbwi3GsDZIhU1lIxpr p5ug== X-Gm-Message-State: AOAM532Mgc1At4k25FPTTaUFiBOBUgVkdXcl6LtNQSs5R6Pg4vPg2zyW N20IXBfcqU3in400y1q0nUMndmJZveE= X-Google-Smtp-Source: ABdhPJyOwkrAO0PnR5msfJDCCv8IdZKdth44MbVVSbRODOGOXhhEKZ07TN9myZQEwkUUueGyX0cLrg== X-Received: by 2002:a1c:7912:: with SMTP id l18mr1044234wme.124.1598908201609; Mon, 31 Aug 2020 14:10:01 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1fb0f.dynamic.kabel-deutschland.de. [188.193.251.15]) by smtp.gmail.com with ESMTPSA id s124sm1035798wme.29.2020.08.31.14.10.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Aug 2020 14:10:01 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 31 Aug 2020 23:09:24 +0200 Message-Id: <20200831210930.18900-2-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200831210930.18900-1-andreas.rheinhardt@gmail.com> References: <20200831210930.18900-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/8] avcodec/magicyuv: Avoid copying values around pointlessly 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" When parsing Huffman tables, an array of HuffEntries (a struct containing a code's bitlength, its bits and its symbol) is used as intermediate tables in order to sort the entries (the order depends on both the length of the entries as well on their symbols). After ordering them, the symbol and len components are copied into other arrays (the HuffEntries' code has never been set or used, despite using quite a lot of stack space) and the codes are generated. Afterwards, the VLC is created. Yet ff_init_vlc_sparse() can handle non-continuous arrays as input; there is no need to copy the entries at all. This commit implements this. Signed-off-by: Andreas Rheinhardt --- libavcodec/magicyuv.c | 39 ++++++++++++--------------------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/libavcodec/magicyuv.c b/libavcodec/magicyuv.c index 32d744add2..f630464162 100644 --- a/libavcodec/magicyuv.c +++ b/libavcodec/magicyuv.c @@ -97,9 +97,6 @@ static int huff_cmp_len12(const void *a, const void *b) static int huff_build10(VLC *vlc, uint8_t *len) { HuffEntry he[1024]; - uint32_t codes[1024]; - uint8_t bits[1024]; - uint16_t syms[1024]; uint32_t code; int i; @@ -113,25 +110,20 @@ static int huff_build10(VLC *vlc, uint8_t *len) code = 1; for (i = 1023; i >= 0; i--) { - codes[i] = code >> (32 - he[i].len); - bits[i] = he[i].len; - syms[i] = he[i].sym; + he[i].code = code >> (32 - he[i].len); code += 0x80000000u >> (he[i].len - 1); } ff_free_vlc(vlc); return ff_init_vlc_sparse(vlc, FFMIN(he[1023].len, 12), 1024, - bits, sizeof(*bits), sizeof(*bits), - codes, sizeof(*codes), sizeof(*codes), - syms, sizeof(*syms), sizeof(*syms), 0); + &he[0].len, sizeof(he[0]), sizeof(he[0].len), + &he[0].code, sizeof(he[0]), sizeof(he[0].code), + &he[0].sym, sizeof(he[0]), sizeof(he[0].sym), 0); } static int huff_build12(VLC *vlc, uint8_t *len) { HuffEntry he[4096]; - uint32_t codes[4096]; - uint8_t bits[4096]; - uint16_t syms[4096]; uint32_t code; int i; @@ -145,25 +137,20 @@ static int huff_build12(VLC *vlc, uint8_t *len) code = 1; for (i = 4095; i >= 0; i--) { - codes[i] = code >> (32 - he[i].len); - bits[i] = he[i].len; - syms[i] = he[i].sym; + he[i].code = code >> (32 - he[i].len); code += 0x80000000u >> (he[i].len - 1); } ff_free_vlc(vlc); return ff_init_vlc_sparse(vlc, FFMIN(he[4095].len, 12), 4096, - bits, sizeof(*bits), sizeof(*bits), - codes, sizeof(*codes), sizeof(*codes), - syms, sizeof(*syms), sizeof(*syms), 0); + &he[0].len, sizeof(he[0]), sizeof(he[0].len), + &he[0].code, sizeof(he[0]), sizeof(he[0].code), + &he[0].sym, sizeof(he[0]), sizeof(he[0].sym), 0); } static int huff_build(VLC *vlc, uint8_t *len) { HuffEntry he[256]; - uint32_t codes[256]; - uint8_t bits[256]; - uint8_t syms[256]; uint32_t code; int i; @@ -177,17 +164,15 @@ static int huff_build(VLC *vlc, uint8_t *len) code = 1; for (i = 255; i >= 0; i--) { - codes[i] = code >> (32 - he[i].len); - bits[i] = he[i].len; - syms[i] = he[i].sym; + he[i].code = code >> (32 - he[i].len); code += 0x80000000u >> (he[i].len - 1); } ff_free_vlc(vlc); return ff_init_vlc_sparse(vlc, FFMIN(he[255].len, 12), 256, - bits, sizeof(*bits), sizeof(*bits), - codes, sizeof(*codes), sizeof(*codes), - syms, sizeof(*syms), sizeof(*syms), 0); + &he[0].len, sizeof(he[0]), sizeof(he[0].len), + &he[0].code, sizeof(he[0]), sizeof(he[0].code), + &he[0].sym, sizeof(he[0]), sizeof(he[0].sym), 0); } static void magicyuv_median_pred16(uint16_t *dst, const uint16_t *src1,