From patchwork Sun Dec 6 18:08:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 24370 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 A7616449B7F for ; Sun, 6 Dec 2020 20:09:00 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 741CA68A912; Sun, 6 Dec 2020 20:09:00 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f68.google.com (mail-ej1-f68.google.com [209.85.218.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 19BBD68084A for ; Sun, 6 Dec 2020 20:08:54 +0200 (EET) Received: by mail-ej1-f68.google.com with SMTP id d17so16200013ejy.9 for ; Sun, 06 Dec 2020 10:08:54 -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 :mime-version:content-transfer-encoding; bh=EuJCKuX+V1yTStPMxQ0BrX1HonVzR7931AHqrxJ6ixQ=; b=Y9gAewGm6ftlTlEYZM7Fu5n6MLD4UsHWe8DOySdaQwWaVPFe7lOTJ8DeoA0+3jQVWA DAgCLsGYpP18ObVgypZD9FAhUPDSRmKqh3Mr2QddMXMEVA6RUGeotJnrR5BKvhvXr+c5 R6FIR3GAzXMmgGPC+hvb7F8RCCjJZF9UXpyhwIH6IOxt6h8yRgllb1zThSD4XOuX0RHQ Za7NfmaZdZ8qG6XNbPu+Eq3lvwq7AMIzuLzQ0XNnFt4VFsuXiNQEKgB1Q2vPO+PI9Cnq 9n1ElsgoNnaR7MqW8CdtOwhPlk5332oCty0+J5bSJGnw2PzKi2bHJeOzO/GwONUjM9KN 2zWQ== 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=EuJCKuX+V1yTStPMxQ0BrX1HonVzR7931AHqrxJ6ixQ=; b=Xgm0GFCCztaFYDpGLsc4yOcbmv+WlBRK7e+6KXoimeUIiU47eKOdJxcRKhxZQxG3NF w+jQoFUf8qiALWRoTuBvS19xEJHW7IaaGjPhPiRAyySAuq+lfKQ+yoa8pMiRM5nRWtNX AoBMsroibc4T55cO7XRGNm4F7OUHzIDFNsHOmZtjf/GBSAslkcSlV/27pLIx60w5ktQt QiSoVKCKqWt7bJ6jZ+VEDzoFFl0ImacrSh2V5CFnjmvS4vR/vRtVlNkIrZXTbHdj5DFo PB/ZoS9PloCzll5Tccpf/KlitJFlEkUW7omg4AlFhQQ7s/hGHc/taeiR7mRQRm6Gx5Dc p8Fg== X-Gm-Message-State: AOAM5320JjQHf9Ns0pdkIFjCcyeFBZZhoy6CuF3elRfN+US2fF0UtnQq p7InW/fL8v8VK2MUYQcGfJKU/hqQDHuKzg== X-Google-Smtp-Source: ABdhPJyXNm06AicRuxailDpSGC3kGOacamPopwwW495oiBmjoOBld+a4xi+/Qnq7ocJxQUtmSOZRNw== X-Received: by 2002:a17:906:d784:: with SMTP id pj4mr11481857ejb.360.1607278133140; Sun, 06 Dec 2020 10:08:53 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id n17sm8803811ejh.49.2020.12.06.10.08.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Dec 2020 10:08:52 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 6 Dec 2020 19:08:38 +0100 Message-Id: <20201206180838.408561-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201120073327.820745-62-andreas.rheinhardt@gmail.com> References: <20201120073327.820745-62-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 161/191] avcodec/mpegaudiodec: Hardcode tables to save space 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" The csa_tables (which always consist of 32 entries of four byte each, but the type depends upon whether the decoder is fixed or floating-point) are currently initialized once during decoder initialization; yet it turns out that this is actually no benefit: The code used to initialize these tables takes up 153 (fixed point) and 122 (floating point) bytes when compiled with GCC 9.3 with -O3 on x64, so it is better to just hardcode these tables. Essentially the same applies to the is_tables: They have a size or 128 each and the code to initialize them occupies 149 (fixed point) resp. 140 (floating point) bytes. So hardcode them, too. To make the origin of the tables clear, references to the code used to create them have been added. Signed-off-by: Andreas Rheinhardt --- Hope the references are fine now libavcodec/mips/compute_antialias_fixed.h | 3 +- libavcodec/mips/compute_antialias_float.h | 2 +- libavcodec/mpegaudiodata.h | 3 -- libavcodec/mpegaudiodec_common.c | 4 --- libavcodec/mpegaudiodec_fixed.c | 20 ++++++++++++ libavcodec/mpegaudiodec_float.c | 33 +++++++++++++++++++ libavcodec/mpegaudiodec_template.c | 39 ++--------------------- 7 files changed, 58 insertions(+), 46 deletions(-) diff --git a/libavcodec/mips/compute_antialias_fixed.h b/libavcodec/mips/compute_antialias_fixed.h index a967f67de7..1f395d2302 100644 --- a/libavcodec/mips/compute_antialias_fixed.h +++ b/libavcodec/mips/compute_antialias_fixed.h @@ -59,7 +59,8 @@ static void compute_antialias_mips_fixed(MPADecodeContext *s, GranuleDef *g) { - int32_t *ptr, *csa; + const int32_t *csa; + int32_t *ptr; int n, i; int MAX_lo = 0xffffffff; diff --git a/libavcodec/mips/compute_antialias_float.h b/libavcodec/mips/compute_antialias_float.h index e2b4f29f4a..633eb9589d 100644 --- a/libavcodec/mips/compute_antialias_float.h +++ b/libavcodec/mips/compute_antialias_float.h @@ -63,7 +63,7 @@ static void compute_antialias_mips_float(MPADecodeContext *s, GranuleDef *g) { float *ptr, *ptr_end; - float *csa = &csa_table[0][0]; + const float *csa = &csa_table[0][0]; /* temporary variables */ float in1, in2, in3, in4, in5, in6, in7, in8; float out1, out2, out3, out4; diff --git a/libavcodec/mpegaudiodata.h b/libavcodec/mpegaudiodata.h index ec969353f3..01b1f88cd0 100644 --- a/libavcodec/mpegaudiodata.h +++ b/libavcodec/mpegaudiodata.h @@ -65,9 +65,6 @@ extern uint16_t ff_scale_factor_modshift[64]; extern const uint8_t ff_mpa_pretab[2][22]; -/* table for alias reduction (XXX: store it as integer !) */ -extern const float ff_ci_table[8]; - /* Initialize tables shared between the fixed and * floating point MPEG audio decoders. */ void ff_mpegaudiodec_common_init_static(void); diff --git a/libavcodec/mpegaudiodec_common.c b/libavcodec/mpegaudiodec_common.c index 2ac9bb95bc..4333746e9a 100644 --- a/libavcodec/mpegaudiodec_common.c +++ b/libavcodec/mpegaudiodec_common.c @@ -396,10 +396,6 @@ const uint8_t ff_mpa_pretab[2][22] = { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3, 2, 0 }, }; -const float ff_ci_table[8] = { - -0.6, -0.535, -0.33, -0.185, -0.095, -0.041, -0.0142, -0.0037, -}; - static av_cold void mpegaudiodec_common_init_static(void) { const uint8_t *huff_sym = mpa_huffsymbols, *huff_lens = mpa_hufflens; diff --git a/libavcodec/mpegaudiodec_fixed.c b/libavcodec/mpegaudiodec_fixed.c index 99d7156764..6eb57c8354 100644 --- a/libavcodec/mpegaudiodec_fixed.c +++ b/libavcodec/mpegaudiodec_fixed.c @@ -36,6 +36,26 @@ #define OUT_FMT AV_SAMPLE_FMT_S16 #define OUT_FMT_P AV_SAMPLE_FMT_S16P +/* Intensity stereo table. See commit b91d46614df189e7905538e7f5c4ed9c7ed0d274 + * (float based mp1/mp2/mp3 decoders.) for how they were created. */ +static const int32_t is_table[2][16] = { + { 0x000000, 0x1B0CB1, 0x2ED9EC, 0x400000, 0x512614, 0x64F34F, 0x800000 }, + { 0x800000, 0x64F34F, 0x512614, 0x400000, 0x2ED9EC, 0x1B0CB1, 0x000000 } +}; + +/* Antialiasing table. See commit ce4a29c066cddfc180979ed86396812f24337985 + * (optimize antialias) for how they were created. */ +static const int32_t csa_table[8][4] = { + { 0x36E129F8, 0xDF128056, 0x15F3AA4E, 0xA831565E }, + { 0x386E75F2, 0xE1CF24A5, 0x1A3D9A97, 0xA960AEB3 }, + { 0x3CC6B73A, 0xEBF19FA6, 0x28B856E0, 0xAF2AE86C }, + { 0x3EEEA054, 0xF45B88BC, 0x334A2910, 0xB56CE868 }, + { 0x3FB6905C, 0xF9F27F18, 0x39A90F74, 0xBA3BEEBC }, + { 0x3FF23F20, 0xFD60D1E4, 0x3D531104, 0xBD6E92C4 }, + { 0x3FFE5932, 0xFF175EE4, 0x3F15B816, 0xBF1905B2 }, + { 0x3FFFE34A, 0xFFC3612F, 0x3FC34479, 0xBFC37DE5 } +}; + #include "mpegaudiodec_template.c" #if CONFIG_MP1_DECODER diff --git a/libavcodec/mpegaudiodec_float.c b/libavcodec/mpegaudiodec_float.c index b8f2c25cac..9633393590 100644 --- a/libavcodec/mpegaudiodec_float.c +++ b/libavcodec/mpegaudiodec_float.c @@ -36,6 +36,39 @@ #define OUT_FMT AV_SAMPLE_FMT_FLT #define OUT_FMT_P AV_SAMPLE_FMT_FLTP +/* Intensity stereo table. See commit b91d46614df189e7905538e7f5c4ed9c7ed0d274 + * (float based mp1/mp2/mp3 decoders.) for how they were created. */ +static const float is_table[2][16] = { + { 0.000000000000000000e+00, 2.113248705863952637e-01, 3.660253882408142090e-01, + 5.000000000000000000e-01, 6.339746117591857910e-01, 7.886751294136047363e-01, + 1.000000000000000000e+00 }, + { 1.000000000000000000e+00, 7.886751294136047363e-01, 6.339746117591857910e-01, + 5.000000000000000000e-01, 3.660253882408142090e-01, 2.113248705863952637e-01, + 0.000000000000000000e+00 } +}; + +/* Antialiasing table. See commit 6f1ec38ce2193d3d4cacd87edb452c6d7ba751ec + * (mpegaudio: clean up compute_antialias() definition) for how they were + * created. */ +static const float csa_table[8][4] = { + { 8.574929237365722656e-01, -5.144957900047302246e-01, + 3.429971337318420410e-01, -1.371988654136657715e+00 }, + { 8.817420005798339844e-01, -4.717319905757904053e-01, + 4.100100100040435791e-01, -1.353474020957946777e+00 }, + { 9.496286511421203613e-01, -3.133774697780609131e-01, + 6.362511515617370605e-01, -1.263006091117858887e+00 }, + { 9.833145737648010254e-01, -1.819131970405578613e-01, + 8.014013767242431641e-01, -1.165227770805358887e+00 }, + { 9.955177903175354004e-01, -9.457419067621231079e-02, + 9.009436368942260742e-01, -1.090092062950134277e+00 }, + { 9.991605877876281738e-01, -4.096558317542076111e-02, + 9.581949710845947266e-01, -1.040126085281372070e+00 }, + { 9.998992085456848145e-01, -1.419856864959001541e-02, + 9.857006072998046875e-01, -1.014097809791564941e+00 }, + { 9.999931454658508301e-01, -3.699974622577428818e-03, + 9.962931871414184570e-01, -1.003693103790283203e+00 } +}; + #include "mpegaudiodec_template.c" #if CONFIG_MP1FLOAT_DECODER diff --git a/libavcodec/mpegaudiodec_template.c b/libavcodec/mpegaudiodec_template.c index fa75445036..1e8fd6064f 100644 --- a/libavcodec/mpegaudiodec_template.c +++ b/libavcodec/mpegaudiodec_template.c @@ -99,9 +99,7 @@ typedef struct MPADecodeContext { #include "mpegaudio_tablegen.h" /* intensity stereo coef table */ -static INTFLOAT is_table[2][16]; static INTFLOAT is_table_lsf[2][2][16]; -static INTFLOAT csa_table[8][4]; /* [i][j]: 2^(-j/3) * FRAC_ONE * 2^(i+2) / (2^(i+2) - 1) */ static int32_t scale_factor_mult[15][3]; @@ -258,22 +256,6 @@ static av_cold void decode_init_static(void) mpegaudio_tableinit(); - for (i = 0; i < 7; i++) { - float f; - INTFLOAT v; - if (i != 6) { - f = tan((double)i * M_PI / 12.0); - v = FIXR(f / (1.0 + f)); - } else { - v = FIXR(1.0); - } - is_table[0][ i] = v; - is_table[1][6 - i] = v; - } - /* invalid values */ - for (i = 7; i < 16; i++) - is_table[0][i] = is_table[1][i] = 0.0; - for (i = 0; i < 16; i++) { double f; int e, k; @@ -289,24 +271,6 @@ static av_cold void decode_init_static(void) (float) is_table_lsf[j][1][i]); } } - - for (i = 0; i < 8; i++) { - double ci, cs, ca; - ci = ff_ci_table[i]; - cs = 1.0 / sqrt(1.0 + ci * ci); - ca = cs * ci; -#if !USE_FLOATS - csa_table[i][0] = FIXHR(cs/4); - csa_table[i][1] = FIXHR(ca/4); - csa_table[i][2] = FIXHR(ca/4) + FIXHR(cs/4); - csa_table[i][3] = FIXHR(ca/4) - FIXHR(cs/4); -#else - csa_table[i][0] = cs; - csa_table[i][1] = ca; - csa_table[i][2] = ca + cs; - csa_table[i][3] = ca - cs; -#endif - } RENAME(ff_mpa_synth_init)(); ff_mpegaudiodec_common_init_static(); } @@ -970,7 +934,8 @@ static void compute_stereo(MPADecodeContext *s, GranuleDef *g0, GranuleDef *g1) { int i, j, k, l; int sf_max, sf, len, non_zero_found; - INTFLOAT (*is_tab)[16], *tab0, *tab1, v1, v2; + INTFLOAT *tab0, *tab1, v1, v2; + const INTFLOAT (*is_tab)[16]; SUINTFLOAT tmp0, tmp1; int non_zero_found_short[3];