From patchwork Fri May 7 06:46:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 27642 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:b214:0:0:0:0:0 with SMTP id b20csp273488iof; Thu, 6 May 2021 23:47:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxUatglRm5kKwcLd1Y7VShoFMdE1GIFOx5++IqyNs+peG9LlBHAUFhewrCcWxN3zy6CiYvL X-Received: by 2002:a17:906:a18e:: with SMTP id s14mr6913266ejy.311.1620370076059; Thu, 06 May 2021 23:47:56 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id cx25si4256113edb.167.2021.05.06.23.47.55; Thu, 06 May 2021 23:47:56 -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; dkim=neutral (body hash did not verify) header.i=@outlook.com header.s=selector1 header.b=iVmPTuX3; arc=fail (body hash mismatch); 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=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5CC57680843; Fri, 7 May 2021 09:47:19 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR02-HE1-obe.outbound.protection.outlook.com (mail-oln040092068080.outbound.protection.outlook.com [40.92.68.80]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E1B3A680843 for ; Fri, 7 May 2021 09:47:16 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UJiSApojF2ycyHpwZA8W0MgT6KJQ1G+a650SNiq/F7AisW2bG6uKeFqoISrXk/OjeaLNSryHUl6iW46/G03o6PP0I+tCAPE68ynn0t82Pty66ygPPv2f1DKhlSWUxO6x6uiYJqxpkcsQQTrn+AAF9O6qZlqendYlv+xSy3JrcPQGx6P+uSNKQRVQZ8onO87/pgLUwIvA6gL2O6Mbeh9J5PYQ2FCN0So1ScdunX1JNuiDs9FMZwyuMjJ7zcR3rVjIBE54ekwItsvApZAbYHblFFOGGCFKfvJp6fWSRCDKObUGYBk6NPZhL2U452mto57weDtNdLvkGOo6CL+sSMYYlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pwVkpV4PN/DH6CMf5qunj2ANijjYl8Fss7vZViopjDE=; b=ETdc0LHSTZQeZYjtT2aHFTJLKnO3zf4LoTfEQagVROizeSPTCQq9dSTxM3Hl65KwKJ+ENEIXH9C0ZgjIMxoJc9ZpqXJ2766+zzzDS+0iBOr93ejI/L1ozCnckbJVp+u0iZDaehpI+gBL/jwSRjLwLJChC1S1P3w4JvmJrpirTj/54LbXmkyCmRCxAvUZH0wPsltUU4RsZGSYZh2SrGC7CWuUXvIkMfkhJsmUj6ETOk9Y/dWLKliFS5crIckeEMoJvoJsgzvXUvSsFCOQv5Yi4Hsbgvl067jCZDXsOrdfwzCK85i2aYHzDnPnMQbGzQjCtedavHU+M721TmBCsn0V5g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pwVkpV4PN/DH6CMf5qunj2ANijjYl8Fss7vZViopjDE=; b=iVmPTuX3PwUq2VJ0An3MA+YGmsWCqytAOu+KFmlEVrMDUJMkWHfAcOKnTwEcYQ1gxcuWmz75i0XuR+0eadT0k1iI/98l5oKeN1dNabVKo35VkA42pjcB4IZjJy6R6nTCD0cMQ/vA7DOrQPSHDA0kGz5w/nBFqUAs1x8r7oB8pd+A9hsEvlFBsGH5HW1RSQ5ndjCqQz4WpMzhcyK4oKo21xWHHzYvNdMHGhDeSGHA6p7OOe0/3NLCQw9N128X0aHZO83nNPRBYR/QGHygDWHFCxsXjjCKF/TPImklYUJloRXdYJaV6CcKX6zdpB+h0hEig19RBbyTewLTZXgulEwNfw== Received: from HE1EUR02FT024.eop-EUR02.prod.protection.outlook.com (2a01:111:e400:7e1d::4e) by HE1EUR02HT079.eop-EUR02.prod.protection.outlook.com (2a01:111:e400:7e1d::371) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.25; Fri, 7 May 2021 06:47:15 +0000 Received: from HE1PR0301MB2154.eurprd03.prod.outlook.com (2a01:111:e400:7e1d::52) by HE1EUR02FT024.mail.protection.outlook.com (2a01:111:e400:7e1d::181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.25 via Frontend Transport; Fri, 7 May 2021 06:47:15 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:824FBDE5AF787CD8B26454140D8FE76E886D66E0C3367946D3E02AC63C0548BE; UpperCasedChecksum:6454FC0EB30C0FAB76E438C1CE0903121F3D3940C7E697C79F703CF23E20C8EF; SizeAsReceived:7597; Count:48 Received: from HE1PR0301MB2154.eurprd03.prod.outlook.com ([fe80::45bb:c44f:2b75:23b7]) by HE1PR0301MB2154.eurprd03.prod.outlook.com ([fe80::45bb:c44f:2b75:23b7%5]) with mapi id 15.20.4108.027; Fri, 7 May 2021 06:47:15 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 7 May 2021 08:46:39 +0200 Message-ID: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-TMN: [QP6J6tNgM2z3vsH78mD0NKHgm3iAvwfj+q/GQuv2nIk=] X-ClientProxiedBy: AM0PR06CA0117.eurprd06.prod.outlook.com (2603:10a6:208:ab::22) To HE1PR0301MB2154.eurprd03.prod.outlook.com (2603:10a6:3:2a::22) X-Microsoft-Original-Message-ID: <20210507064647.362502-11-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.193.170.150) by AM0PR06CA0117.eurprd06.prod.outlook.com (2603:10a6:208:ab::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.25 via Frontend Transport; Fri, 7 May 2021 06:47:15 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 48 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 31b640e7-bfac-40ac-2ea8-08d91123f372 X-MS-Exchange-SLBlob-MailProps: q+fD6XS3/UKDSr/w16Yq9FOBxSZ3+PPFLyNJT+PTaEQmHvqUT3FL5DUfWU1VVZ+epmLHJcSb9t46pIfMEC9MZb9zAUftGwzxMLp1y3gtSY/wzizUIJ3CUCFlt6i0gl2BWdWrtp4DffO6TJQW5f1bPGeLhpluJQtGaTsDVaWWK/29J/PIzcGAx23xq48DDJWTqRGb6IEAtgNSfwEf3GE0raaBiDp8eki144rH8o8jjAGNUTa0t1R1iYzPbwdjw1/yCdd7tOE8IpkOXncjkxVXPmJdOsEq3piCen+44BpyHn5mVXiQUdHtvQy91EBHGMN7iqkepZtmXrAuHYdjE+cu1vHgZ2lAOjwgfv4Gh8brsMFGiGrvA9Aan39oyJuCABq4OQ/pHjwn8DucIXh5FuV2GrF6dNjjKLv/jVsguZNNPy8wiIQaywJhyF66l82aKTpfXVTDqQhdCCYiRrp5K4fTqhxr8O9TnlF6DIn9cjYiq+XOlqk8lNkQdfAm/NUFoN42tPwEIudoXCOehkVW/Gdc+2vUOpYHhMAMlHAj6Znce8c7nmhMM4DMtrBrlyi9TobdPtbzMvABedOWYNFySmt4fiP/qg3+KECtP9JSkZ7cVktfDqeiBZAJh6O6zjUAAPQqvAIi8Ng54Vc0wJkz9OunSO1KV+Kv5ttLT0IvDB6lGlJmvpe/zCBPNZ7PBMTGI1wWLQcDxKLFGw6ZHZxoXiMJyg== X-MS-TrafficTypeDiagnostic: HE1EUR02HT079: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2VxYeBKP5iYpc3QS8GWc4HIBGq/VTPoRWDELzTusWNxEGJIatyQd3LdO8AgRW5Lx2rKo4Jj/n9jcDiBS5Q2qYxSjS1449cL2D/l1uUiSxgod2W0PjTpKHbvlWx48okdrsOWbMqQH+qrKxWyywzaHVd3y2E9MOqj4u/ub7BP+RuIfCA/CsHthJVgHU6nAh6WEHRtdI6ad6WZF6KbQXrM6fK+g9FKX6vDx5ZswN0R/2wDcDya6swuqbwVB/Ujw98ixBEYrzhIveOKe9WQr1u9j4qashPaI4UsyJf40+juvtcISb34Fh3aS98lxUHLJKs9sa93c8eoNEgZZRmQ2ZQTMHEsWTNjuppy8zfkdaP9ZGHZ96HdxAaFPMDLAw2a7hLyeQm0uupuw79yvNJ25FgEiFA== X-MS-Exchange-AntiSpam-MessageData: qheHgyr2dtki9rPTkerMVWD2XDmD2QmtvXaI8u0K9G/0EkgYVtTfxQgpGG3NiVbaoMRsxze8a7ACiyHwIXhnXaMCs3n3Rmx9or4oG2lgEk1K1VmYqnn0N1NXKcmh9eyoxv99Zs6yC6M/w14+BgZy8Q== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 31b640e7-bfac-40ac-2ea8-08d91123f372 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 May 2021 06:47:15.7778 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: HE1EUR02FT024.eop-EUR02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1EUR02HT079 Subject: [FFmpeg-devel] [PATCH 12/20] avcodec/mqc: Hardcode tables to save space 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: cQb+F16zdxNf mqc currently initializes three arrays at runtime; each of them has 2 * 47 elements, one is uint16_t, two are uint8_t, so that their combined size is 8 * 47. The source data for these initializations is contained in an array of 47 elements of size six. Said array is only used in order to initialize the other arrays, so the savings are just 2 * 47B. Yet this is dwarfed by the size of the code for performing the initializations: It is 109B (GCC 10.2, x64, -O3 albeit in an av_cold function); this does not even include the size of the code in the callers. So just hardcode these tables. This also fixes a data race, because the encoder always initialized these tables during init, although they might already be used at the same time by already running encoder/decoder instances. Signed-off-by: Andreas Rheinhardt --- libavcodec/j2kenc.c | 1 - libavcodec/jpeg2000dec.c | 1 - libavcodec/mqc.c | 105 +++++++++++---------------------------- libavcodec/mqc.h | 11 ++-- 4 files changed, 32 insertions(+), 86 deletions(-) diff --git a/libavcodec/j2kenc.c b/libavcodec/j2kenc.c index c51adadd13..17eb959d73 100644 --- a/libavcodec/j2kenc.c +++ b/libavcodec/j2kenc.c @@ -1780,7 +1780,6 @@ static av_cold int j2kenc_init(AVCodecContext *avctx) } ff_jpeg2000_init_tier1_luts(); - ff_mqc_init_context_tables(); init_luts(); init_quantization(s); diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c index 5364631432..1295c96305 100644 --- a/libavcodec/jpeg2000dec.c +++ b/libavcodec/jpeg2000dec.c @@ -2476,7 +2476,6 @@ static int jp2_find_codestream(Jpeg2000DecoderContext *s) static av_cold void jpeg2000_init_static_data(void) { ff_jpeg2000_init_tier1_luts(); - ff_mqc_init_context_tables(); } static av_cold int jpeg2000_decode_init(AVCodecContext *avctx) diff --git a/libavcodec/mqc.c b/libavcodec/mqc.c index f2d1e3b838..6f7088ec48 100644 --- a/libavcodec/mqc.c +++ b/libavcodec/mqc.c @@ -28,85 +28,38 @@ #include #include -#include "libavutil/attributes.h" - #include "mqc.h" -/* MQ coder context state structure */ -typedef struct MqcCxState { - uint16_t qe; - uint8_t nmps; - uint8_t nlps; - uint8_t sw; -} MqcCxState; - -static const MqcCxState cx_states[47] = { - { 0x5601, 1, 1, 1 }, - { 0x3401, 2, 6, 0 }, - { 0x1801, 3, 9, 0 }, - { 0x0AC1, 4, 12, 0 }, - { 0x0521, 5, 29, 0 }, - { 0x0221, 38, 33, 0 }, - { 0x5601, 7, 6, 1 }, - { 0x5401, 8, 14, 0 }, - { 0x4801, 9, 14, 0 }, - { 0x3801, 10, 14, 0 }, - { 0x3001, 11, 17, 0 }, - { 0x2401, 12, 18, 0 }, - { 0x1C01, 13, 20, 0 }, - { 0x1601, 29, 21, 0 }, - { 0x5601, 15, 14, 1 }, - { 0x5401, 16, 14, 0 }, - { 0x5101, 17, 15, 0 }, - { 0x4801, 18, 16, 0 }, - { 0x3801, 19, 17, 0 }, - { 0x3401, 20, 18, 0 }, - { 0x3001, 21, 19, 0 }, - { 0x2801, 22, 19, 0 }, - { 0x2401, 23, 20, 0 }, - { 0x2201, 24, 21, 0 }, - { 0x1C01, 25, 22, 0 }, - { 0x1801, 26, 23, 0 }, - { 0x1601, 27, 24, 0 }, - { 0x1401, 28, 25, 0 }, - { 0x1201, 29, 26, 0 }, - { 0x1101, 30, 27, 0 }, - { 0x0AC1, 31, 28, 0 }, - { 0x09C1, 32, 29, 0 }, - { 0x08A1, 33, 30, 0 }, - { 0x0521, 34, 31, 0 }, - { 0x0441, 35, 32, 0 }, - { 0x02A1, 36, 33, 0 }, - { 0x0221, 37, 34, 0 }, - { 0x0141, 38, 35, 0 }, - { 0x0111, 39, 36, 0 }, - { 0x0085, 40, 37, 0 }, - { 0x0049, 41, 38, 0 }, - { 0x0025, 42, 39, 0 }, - { 0x0015, 43, 40, 0 }, - { 0x0009, 44, 41, 0 }, - { 0x0005, 45, 42, 0 }, - { 0x0001, 45, 43, 0 }, - { 0x5601, 46, 46, 0 } +const uint16_t ff_mqc_qe[2 * 47] = { + 0x5601, 0x5601, 0x3401, 0x3401, 0x1801, 0x1801, 0x0ac1, 0x0ac1, + 0x0521, 0x0521, 0x0221, 0x0221, 0x5601, 0x5601, 0x5401, 0x5401, + 0x4801, 0x4801, 0x3801, 0x3801, 0x3001, 0x3001, 0x2401, 0x2401, + 0x1c01, 0x1c01, 0x1601, 0x1601, 0x5601, 0x5601, 0x5401, 0x5401, + 0x5101, 0x5101, 0x4801, 0x4801, 0x3801, 0x3801, 0x3401, 0x3401, + 0x3001, 0x3001, 0x2801, 0x2801, 0x2401, 0x2401, 0x2201, 0x2201, + 0x1c01, 0x1c01, 0x1801, 0x1801, 0x1601, 0x1601, 0x1401, 0x1401, + 0x1201, 0x1201, 0x1101, 0x1101, 0x0ac1, 0x0ac1, 0x09c1, 0x09c1, + 0x08a1, 0x08a1, 0x0521, 0x0521, 0x0441, 0x0441, 0x02a1, 0x02a1, + 0x0221, 0x0221, 0x0141, 0x0141, 0x0111, 0x0111, 0x0085, 0x0085, + 0x0049, 0x0049, 0x0025, 0x0025, 0x0015, 0x0015, 0x0009, 0x0009, + 0x0005, 0x0005, 0x0001, 0x0001, 0x5601, 0x5601 +}; +const uint8_t ff_mqc_nlps[2 * 47] = { + 3, 2, 12, 13, 18, 19, 24, 25, 58, 59, 66, 67, 13, 12, 28, 29, + 28, 29, 28, 29, 34, 35, 36, 37, 40, 41, 42, 43, 29, 28, 28, 29, + 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 38, 39, 40, 41, 42, 43, + 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, + 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, + 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 92, 93 +}; +const uint8_t ff_mqc_nmps[2 * 47] = { + 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 76, 77, 14, 15, 16, 17, + 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 58, 59, 30, 31, 32, 33, + 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, + 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, + 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, + 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 90, 91, 92, 93 }; - -uint16_t ff_mqc_qe [2 * 47]; -uint8_t ff_mqc_nlps[2 * 47]; -uint8_t ff_mqc_nmps[2 * 47]; - -void av_cold ff_mqc_init_context_tables(void) -{ - int i; - for (i = 0; i < 47; i++) { - ff_mqc_qe[2 * i] = - ff_mqc_qe[2 * i + 1] = cx_states[i].qe; - - ff_mqc_nlps[2 * i] = 2 * cx_states[i].nlps + cx_states[i].sw; - ff_mqc_nlps[2 * i + 1] = 2 * cx_states[i].nlps + 1 - cx_states[i].sw; - ff_mqc_nmps[2 * i] = 2 * cx_states[i].nmps; - ff_mqc_nmps[2 * i + 1] = 2 * cx_states[i].nmps + 1; - } -} void ff_mqc_init_contexts(MqcState *mqc) { diff --git a/libavcodec/mqc.h b/libavcodec/mqc.h index 73604d5efe..ad80fe9228 100644 --- a/libavcodec/mqc.h +++ b/libavcodec/mqc.h @@ -33,9 +33,9 @@ #define MQC_CX_UNI 17 #define MQC_CX_RL 18 -extern uint16_t ff_mqc_qe[2 * 47]; -extern uint8_t ff_mqc_nlps[2 * 47]; -extern uint8_t ff_mqc_nmps[2 * 47]; +extern const uint16_t ff_mqc_qe[2 * 47]; +extern const uint8_t ff_mqc_nlps[2 * 47]; +extern const uint8_t ff_mqc_nmps[2 * 47]; typedef struct MqcState { uint8_t *bp, *bpstart; @@ -79,11 +79,6 @@ int ff_mqc_decode(MqcState *mqc, uint8_t *cxstate); /* common */ -/** - * MQ-coder Initialize context tables (QE, NLPS, NMPS) - */ -void ff_mqc_init_context_tables(void); - /** * MQ-coder context initialisations. * @param mqc MQ-coder context