From patchwork Fri Nov 20 07:32:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23878 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 D69E7449298 for ; Fri, 20 Nov 2020 09:49:24 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3907068BD3D; Fri, 20 Nov 2020 09:34:44 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f67.google.com (mail-ej1-f67.google.com [209.85.218.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 957EE68BCDD for ; Fri, 20 Nov 2020 09:34:32 +0200 (EET) Received: by mail-ej1-f67.google.com with SMTP id f23so11549015ejk.2 for ; Thu, 19 Nov 2020 23:34:32 -0800 (PST) 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:reply-to :mime-version:content-transfer-encoding; bh=KY8rfgmj6ueVsA2ZIALtb5f3Iq8PAspeA5NdidS6KlM=; b=SMyGqNIw87wL0WCv8ZcnHzLFq1GdtZqumV61pCnJriU0mAMg5eq6nCNIZXGkMKEgvX KpViVlVTqpF+YC+3xQ4etE1xSc2wqfh0AIrgpA2KoVPEWUQRjRyuqKVa2LNMqG5LIceN wooeFcbKbb+rO9h+BTEfSpXN3+7i59aNaZC2uDAdcwVmEYFjh9/UNxIFYBw7BSPXCEew QrPOPMUkir/T8xXzoK8dQPJXbgS39of4HvyKDrfJ8oFig0PkintZRXaexFYqopoi8y45 BjVvwgQSbSYlwO0NGc8ocp9yPaGEMwwLZvqZforFmjwLU9bYga3O3Kxy1htKEe8K5ABS 0JmQ== 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:reply-to:mime-version:content-transfer-encoding; bh=KY8rfgmj6ueVsA2ZIALtb5f3Iq8PAspeA5NdidS6KlM=; b=ISsXqXQPN1cxV1QEBeTas+NBAEpVgvSl11UK/rUwoIoDgzJkjAyV3TfNhssuYMitRr 3szYzb0uz/gnBNU/pV0iyyP0XrrcuEAo6zk/w0E1VgklEJ5QURY7b74j1JvKq77jBW5b r+5me+siggWqP3/IlBAUs2G4dVuQz2+j8yX+YPARTA3FTTyZhCkZCJOghqszW15cP+wG 7FKG+ViWWMCESVLPLX/ytYBc7q4PnpA/sEs6g0h9xlsI8m8bzj3JOCWV7yW6IUTmXl/q 7D3l/MnTw8RdTNjGeeDZxXOXrgqHT2jTepLbSRqTzEWMKB6ayVH7vgxBS+QgVsd6Avtx qN+Q== X-Gm-Message-State: AOAM532tMjkhtmKVG2Fw1dEh5EPArqkj1Y0LWITfJqkuukrKljpYNl4H H5ygyKNAOEb9fdmYCqHlO7xmGgkWnFvayg== X-Google-Smtp-Source: ABdhPJzecYj0MU7nHLES2+ifN0AGXVP1TH1g4BbnaHWExGhuWRriQRlT0CNu1d5DQg7OOmBEc7AY7A== X-Received: by 2002:a17:906:5017:: with SMTP id s23mr33426733ejj.359.1605857671744; Thu, 19 Nov 2020 23:34:31 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id i13sm769110ejv.84.2020.11.19.23.34.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Nov 2020 23:34:31 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 20 Nov 2020 08:32:53 +0100 Message-Id: <20201120073327.820745-29-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201120072116.818090-1-andreas.rheinhardt@gmail.com> References: <20201120072116.818090-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 128/162] avcodec/intrax8: Avoid code duplication when initializing VLCs 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" Signed-off-by: Andreas Rheinhardt --- libavcodec/intrax8.c | 46 ++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/libavcodec/intrax8.c b/libavcodec/intrax8.c index 2a93e5efd7..9a2984c15b 100644 --- a/libavcodec/intrax8.c +++ b/libavcodec/intrax8.c @@ -31,6 +31,8 @@ #include "intrax8dsp.h" #include "mpegutils.h" +#define VLC_BUFFER_SIZE 28150 + #define MAX_TABLE_DEPTH(table_bits, max_bits) \ ((max_bits + table_bits - 1) / table_bits) @@ -46,21 +48,27 @@ static VLC j_ac_vlc[2][2][8]; // [quant < 13], [intra / inter], [select] static VLC j_dc_vlc[2][8]; // [quant], [select] static VLC j_orient_vlc[2][4]; // [quant], [select] +static av_cold void x8_init_vlc(VLC *vlc, int nb_bits, int nb_codes, + int *offset, const uint16_t table[][2]) +{ + static VLC_TYPE vlc_buf[VLC_BUFFER_SIZE][2]; + + vlc->table = &vlc_buf[*offset]; + vlc->table_allocated = VLC_BUFFER_SIZE - *offset; + init_vlc(vlc, nb_bits, nb_codes, &table[0][1], 4, 2, + &table[0][0], 4, 2, INIT_VLC_STATIC_OVERLONG); + *offset += vlc->table_size; +} + static av_cold void x8_vlc_init(void) { int i; int offset = 0; - static VLC_TYPE table[28150][2]; - // set ac tables #define init_ac_vlc(dst, src) \ do { \ - dst.table = &table[offset]; \ - dst.table_allocated = FF_ARRAY_ELEMS(table) - offset; \ - init_vlc(&dst, AC_VLC_BITS, 77, &src[1], 4, 2, &src[0], 4, 2, \ - INIT_VLC_STATIC_OVERLONG); \ - offset += dst.table_size; \ + x8_init_vlc(&dst, AC_VLC_BITS, 77, &offset, &src); \ } while(0) for (i = 0; i < 8; i++) { @@ -74,11 +82,7 @@ static av_cold void x8_vlc_init(void) // set dc tables #define init_dc_vlc(dst, src) \ do { \ - dst.table = &table[offset]; \ - dst.table_allocated = FF_ARRAY_ELEMS(table) - offset; \ - init_vlc(&dst, DC_VLC_BITS, 34, &src[1], 4, 2, &src[0], 4, 2, \ - INIT_VLC_STATIC_OVERLONG); \ - offset += dst.table_size; \ + x8_init_vlc(&dst, DC_VLC_BITS, 34, &offset, &src); \ } while(0) for (i = 0; i < 8; i++) { @@ -88,22 +92,14 @@ static av_cold void x8_vlc_init(void) #undef init_dc_vlc // set orient tables -#define init_or_vlc(dst, src) \ - do { \ - dst.table = &table[offset]; \ - dst.table_allocated = FF_ARRAY_ELEMS(table) - offset; \ - init_vlc(&dst, OR_VLC_BITS, 12, &src[1], 4, 2, &src[0], 4, 2, \ - INIT_VLC_STATIC_OVERLONG); \ - offset += dst.table_size; \ - } while(0) - for (i = 0; i < 2; i++) - init_or_vlc(j_orient_vlc[0][i], x8_orient_highquant_table[i][0]); + x8_init_vlc(&j_orient_vlc[0][i], OR_VLC_BITS, 12, + &offset, x8_orient_highquant_table[i]); for (i = 0; i < 4; i++) - init_or_vlc(j_orient_vlc[1][i], x8_orient_lowquant_table[i][0]); -#undef init_or_vlc + x8_init_vlc(&j_orient_vlc[1][i], OR_VLC_BITS, 12, + &offset, x8_orient_lowquant_table[i]); - av_assert2(offset == FF_ARRAY_ELEMS(table)); + av_assert2(offset == VLC_BUFFER_SIZE); } static void x8_reset_vlc_tables(IntraX8Context *w)