From patchwork Fri Sep 8 08:15:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Gisquet X-Patchwork-Id: 43659 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4e27:b0:149:dfde:5c0a with SMTP id gk39csp324922pzb; Fri, 8 Sep 2023 01:16:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGoezY8HjWuJb+FlDzDmGYdkHYyUxIol/S9BJp4mJUKWlWKLEknQH1cA+XWSSf9lI5tZyZC X-Received: by 2002:aa7:c999:0:b0:529:fa63:ef80 with SMTP id c25-20020aa7c999000000b00529fa63ef80mr1314571edt.28.1694160989157; Fri, 08 Sep 2023 01:16:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694160989; cv=none; d=google.com; s=arc-20160816; b=smHPFhdifWKWx/l+MmAC4UUbfIFEpPAJp8iJq2RgrOZxxCiT+WckeTrEENtLv3Cszp 2cNKalNqNMHjVd8fre4NN2KZKrL4kpgnQub6XJgoUszvPknknCmyZco9vqla1u9PCNrV U4jqLmQf9wHel/nQdrnH+MTNHKKGDXDzYWiM5dycG60yeXKMWnJ/5ysDA2xIrimVthu3 JabCqxhHxK820MU3QgxWdrlehSCMoFfS4dOXMvT5CLfkE12X5e/8XbZ8lXYKsso+osjc MkT5bPk5mblTqOJYSEpDuwGLqENLO0lydfxio/U/aJWQZUy4CdTvPZjl8a5tsZJmmIAz bYfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=3k0SOsy2hofwhaZzrmIH5rCNUpo7ffeRzyd1daAJU7M=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=CnFeTtASI5UsAaQ9Na5gPJvJuDakFffRuCGuvA6HUoPw6AZX2ZIizQEtjPQVpbrTBj dn3OWLKpDsAb6SlubLl72mRNXDDBObTs2FP92ZVP9jEqXKs1d7L6F3hoTr5D7wwI4z3e 1VaCnlcwEFH3FoISbwD59UDCLi9vJy1H/aA45GczIw3UCLlITh7NN8fVOryeQIt06dsb mPxGcvMWCBQgxOiYO8xNidRNdzQLT24Qa4p0lgfEXwVx2HmL0JP7ft6JRn9tWI22M3m8 2tLF4h84mfpzn/L0POQH4ASExvDD3+LJpaWmcZZTYBQwTKzGSvSTeAziIHljpJidFRFh Ks6A== 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id u5-20020a056402110500b00523372ace05si1029364edv.530.2023.09.08.01.16.28; Fri, 08 Sep 2023 01:16: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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D712968C8B7; Fri, 8 Sep 2023 11:15:32 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from smtp1-g21.free.fr (unknown [212.27.42.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0F79D68C896 for ; Fri, 8 Sep 2023 11:15:25 +0300 (EEST) Received: from localhost.localdomain (unknown [IPv6:2a01:e0a:8a7:6440:5540:d7b2:7ae2:c181]) (Authenticated sender: christophe.gisquet@free.fr) by smtp1-g21.free.fr (Postfix) with ESMTPSA id A51EBB00535 for ; Fri, 8 Sep 2023 10:15:23 +0200 (CEST) From: Christophe Gisquet To: ffmpeg-devel@ffmpeg.org Date: Fri, 8 Sep 2023 10:15:08 +0200 Message-ID: <20230908081508.510-7-christophe.gisquet@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230908081508.510-1-christophe.gisquet@gmail.com> References: <20230908081508.510-1-christophe.gisquet@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 7/7] prores: use VLC LUTs X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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" X-TUID: v4b1jl8JjLSe One indirection less, around 1% speedup. --- libavcodec/proresdec2.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/libavcodec/proresdec2.c b/libavcodec/proresdec2.c index b20021c622..85f81d92d3 100644 --- a/libavcodec/proresdec2.c +++ b/libavcodec/proresdec2.c @@ -561,12 +561,18 @@ static av_always_inline int decode_dc_coeffs(GetBitContext *gb, int16_t *out, prev_dc += (((code + 1) >> 1) ^ sign) - sign; out[0] = prev_dc; } - return 0; + return 0; } +#include "libavutil/timer.h" + + static av_always_inline int decode_ac_coeffs(AVCodecContext *avctx, GetBitContext *gb, int16_t *out, int blocks_per_slice) { + static VLC* lvl_vlc[9] = { &ac_vlc[0], &ac_vlc[1], &ac_vlc[2], &ac_vlc[3], &ac_vlc[0], &ac_vlc[4], &ac_vlc[4], &ac_vlc[4], &ac_vlc[4], }; + static VLC* run_vlc[15] = { &ac_vlc[3], &ac_vlc[3], &ac_vlc[2], &ac_vlc[2], &ac_vlc[0], &ac_vlc[5], &ac_vlc[5], &ac_vlc[5], &ac_vlc[5], + &ac_vlc[4], &ac_vlc[4], &ac_vlc[4], &ac_vlc[4], &ac_vlc[4], &ac_vlc[4], }; const ProresContext *ctx = avctx->priv_data; int block_mask, sign; unsigned pos, run, level; @@ -585,9 +591,7 @@ static av_always_inline int decode_ac_coeffs(AVCodecContext *avctx, GetBitContex break; if (run < 15) { - static const uint8_t ctx_to_tbl[] = { 3, 3, 2, 2, 0, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4 }; - const VLC* tbl = ac_vlc + ctx_to_tbl[run]; - run = get_vlc2(gb, tbl->table, PRORES_LEV_BITS, 3); + run = get_vlc2(gb, run_vlc[run]->table, PRORES_LEV_BITS, 3); } else { unsigned int bits = 21 - 2*av_log2(show_bits(gb, 10)); run = READ_BITS(gb, bits) - 4; // up to 17 bits @@ -599,9 +603,7 @@ static av_always_inline int decode_ac_coeffs(AVCodecContext *avctx, GetBitContex } if (level < 9) { - static const uint8_t ctx_to_tbl[] = { 0, 1, 2, 3, 0, 4, 4, 4, 4 }; - const VLC* tbl = ac_vlc + ctx_to_tbl[level]; - level = 1+get_vlc2(gb, tbl->table, PRORES_LEV_BITS, 3); + level = 1+get_vlc2(gb, lvl_vlc[level]->table, PRORES_LEV_BITS, 3); } else { unsigned int bits = 25 - 2*av_log2(show_bits(gb, 12)); level = READ_BITS(gb, bits) - 4 + 1; // up to 21 bits