From patchwork Sat Oct 22 13:59:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 38910 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4a86:b0:9d:28a3:170e with SMTP id fn6csp1302481pzb; Sat, 22 Oct 2022 06:59:37 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6voQiFVot5RXJbmi05kGcpBK9xHt7rgFLULe1qB8oEdVODjSGYNMbl6G81OwnKLGeOmgAS X-Received: by 2002:a05:6402:4301:b0:45d:422b:5d5d with SMTP id m1-20020a056402430100b0045d422b5d5dmr21650104edc.153.1666447177048; Sat, 22 Oct 2022 06:59:37 -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 hb10-20020a170907160a00b0078341b2e269si20706497ejc.886.2022.10.22.06.59.36; Sat, 22 Oct 2022 06:59:37 -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=k3mWwdYr; 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 91B5568BEE3; Sat, 22 Oct 2022 16:59:26 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05olkn2017.outbound.protection.outlook.com [40.92.91.17]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 25E1B68BEE5 for ; Sat, 22 Oct 2022 16:59:20 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZnNJnwwT+fxDHnDchA3c5jJAP2ScRvkiSb++616GCHwbEX/FQkGodPdOap38YHfoAqtL43ZKUmd3LzoLHr5ew5imzeFbroG/D0C+QyCPLdSVMYutKGP7NHIXnlTIJb3rf4B5p0Hd+69/qlFYOt3w6Rn8y1WWU3Vb5FiqiMMd2HrOR2D2kchhUbrrXwsjWdcXFhRbpHFQ114ygEXF36awJpZwBg+d6oPhjhWXVfJbew9Bj+hhyFBkYLgDgeQCOBu+C7os1fkk5Wv5lbRNBzIJhnu0Vw1M1QcwWZfQjmq4GFOYrFXAIWO7IglYVLdqGIzzTH4dEd7EwqTncKejoNsC4A== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=27LHObESt0ItIUTXd2p63F0Ctzj7no5QM2skyZowBKI=; b=PUg9GDGRaLguY8l07CSTNCP2QSokDsRGeGEJvxfCSBOzc3jlJbuMVzeSBGO1tBpqLFc/oFnsyQOps1Uj7nY6nowlKp5EwIycHbu9L8z/J6CAFuvid2bCLyK/dZlplA5e7sfRM6zAugxijqmg1Im/f+j0eTbJrHZ0qq7pDIEHe1fqaDbuKynUGXclB0aYasnu4XrTrxgFIYVRGCOc6x4rMECVqoWXNe87rkpuvLbuep4X++PS8V4Qyj3/A8UuR1RdAjc7GwAx5pN5PrguMxvcvpk3Uy0GEDOVImJlG5H9MC51GLXyjf04KEtmR7S0vWw6D+XqrFCJMal1VDoK+cgTgQ== 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=27LHObESt0ItIUTXd2p63F0Ctzj7no5QM2skyZowBKI=; b=k3mWwdYrSwtf2fR5qXXEJD1+h3Nb5SPFC8LP+KeZJtRwmiCoTUPcipRafLmjnDC5GiH7mLvpzvAxdsuz/SthO/f7ffG75NXoNF10qDMtMdOsw+Zlj6tENaedTEDIIuD4N132glxUQBA9rkPFA/htpX48ELGfzJ/9qoweurgY5VaN31Ag80nEbAUtKINLggGOed1OHvum8PHzMgnorslYseftn3EGxK+sChD1mvEElJHuEwYvLCAzPObl8zNNPaX05jF3dAGC53Z1kD8ZSUrOVlGH5IAwTpnmyUtVMeNrDGVdATCJeOQnPUesDnggrlyzT4sIyBxJFR61j+jQ8TXXyg== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by AS8P250MB0268.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:37f::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5746.21; Sat, 22 Oct 2022 13:59:15 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::f9d7:680f:70c4:44fe]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::f9d7:680f:70c4:44fe%7]) with mapi id 15.20.5709.015; Sat, 22 Oct 2022 13:59:15 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 22 Oct 2022 15:59:03 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [zP2Qs+DyyAh9nKtC0SY+o3mWuOhodKAxjBIUvEXhnEs=] X-ClientProxiedBy: AS9PR06CA0368.eurprd06.prod.outlook.com (2603:10a6:20b:460::32) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20221022135903.3949890-4-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|AS8P250MB0268:EE_ X-MS-Office365-Filtering-Correlation-Id: 59431be6-3173-4c15-da09-08dab4359b13 X-MS-Exchange-SLBlob-MailProps: EgT5Wr3QDKwCpSu33t8D+CngGjAPqiYXuEUB2P88lYm3vnoEqyodkghkSiOs9NYzGUDbWDM7+8qcBBCAmqdlkaEnQSkw6XAVNsMdSYSWfBzDwGceyOrKg/V/K5jbaVATcr1ls2EL6/gLHDfIjRece/Y125tZ83W9uu6/lDale4TN1oshDWnJLzY2JUs2elW/jJ6YdGgA0stZl/waygNcKaRdr7IYlHMZY/jQ5yvZqvMSegFfKEjHkdfCLcJEE9xFqPzqav6r0iYhRfwACK3nQn8iwR4h666PmMrSiEYLM0wWo+cDT4lB3tjTTx0LTQyH7BafqE9pxuafDRjH749MUjuHxWgLI2Z/cd4A9dg/AFFxQxh15dWi/RmdH4iYJWU022nhfWXYxGEoPLURagWHlFs/yRL/LK5XQ+vGLCqYoMwnuXvHveCYNOBARnXNq4HkqC5TX/ek8sFUlmZUlnOY87AY1bo9LgxWSZPpirjMrVSZtA063fFkIMBfJfr1zFCcUHsRZNbuIzCXnMLH1FJAMlFyUath1gjBBm6TaUJgQK1HUuASSX+oaPbM+E5RzQApc4ht9szjLc+/W/v/VsrpbkAYpRmwNDugBCYL2hSyRFzJDcGrHls5Q8oHTixVhxTuwo3qryu41uigMM49AMtfdi9y+3DdaWHwuGkiv6spb2gsqdSHz0669EdoOqKH4pUmUXTlU3h/GkOJT3T9TdKX89tStCxeLj6zcx7lKChJEKI= X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: excayU30WLTxrNqb52q2BOTQ1ZwIpMeDyHvYp+oCJuFV7xe8F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1yuuMJNeYPY+UczeaX/sEJ3Ry8XVcpF3vJ2ZDC214HmMY8YZufhD1dp4+9GBH2yYsIiZ45hN4fMQ443R24g0dtsVC7QdA3AAvhoviuYZRjeLLUdWkhtEYdL0+esg3g1jS1WaUvtm7tv16sBL7PDl6bulKE50IlWl+GXPNn9sY4pVpKxctl5qI+0aDhKgQdHINEX/SqNVwfV+PSgZ06ntUhgVj+QmxmUTHxr/1/qJsCu7nIzHNHdK46/1a/lbDFyrzLRPjryvtgmWErmwVyD49jFMPnVPZ0kNh4ZFVIv7inQFEgwMmCT2bFCFREmS9DvLMuhYh7wNFVviKTaIV6LWT4KUSMxoWsqC0gcs10AcveVN/2IjEM8+mfb6GT3B3fMR1WTSUXyTdNWJ199YsHfZjVxB8qopkiYPgisY+XT6UpC4/8a927T838YODXrnKJQ1aeUZFz25XWDw2mYNgsfcozePRKAF2vzwl8yElf1WudupoR7Za62tYkyYgGHzaF1ZcNXLOF7Nqzb1NKPtv6EnyDMStKTcc9fllWBDchQ2OcDf0xK49M/GaBNzWD/OhJXmAfCEJaaDHaygYDwCbn4xvbjEeph2zkNqtUsDOKBb1V1EbwMCkGCTTKvtdPYMYIElnTE5mtypMOY4QhLZh4GE+Sglh+gfgDqVCkejWRHW0xIf9O3NvLbOO0KPbSmlG+8DI8b+pZ6NJueGoxVvhSFum0+ZrVcUw1/rFiuBev+wtxxusOeAOUO1D9kL7cBQf9dvMZrRAQb/VxVb+9lSZ/4XS1l3DffD6Xyjsok2dwJuF4VLXNkSPLZA1J8BzdYb6CXbgjZfoq13bSxLJLJmRFd3br8Qt/WxSLojdTGmcD0SPrl9Nb/n8glRAc+WEQ2F/370sTNLMuEescIalvZ9nTFYUrp2Wob/spxjOD0Ip+jksFR//Pw4Nz6NiLoEdFVdmhfU6290VH1sD35S8 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 59431be6-3173-4c15-da09-08dab4359b13 X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Oct 2022 13:59:15.6255 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8P250MB0268 Subject: [FFmpeg-devel] [PATCH 5/5] avutil/tx_template: Move function pointers to const memory 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: KPprAAqYvPWu This can be achieved by moving the AVOnce out of the structure containing the function pointers; the latter can then be made const. This also has the advantage of eliminating padding in the structure (sizeof(AVOnce) is four here) and allowing the AVOnces to be put into .bss (dependening upon the implementation). Signed-off-by: Andreas Rheinhardt --- libavutil/tx_template.c | 47 +++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/libavutil/tx_template.c b/libavutil/tx_template.c index c15dc2ea27..56e9a6aa98 100644 --- a/libavutil/tx_template.c +++ b/libavutil/tx_template.c @@ -55,16 +55,10 @@ TABLE_DEF(53, 12); TABLE_DEF( 7, 6); TABLE_DEF( 9, 8); -typedef struct FFSRTabsInitOnce { +typedef struct FFSRTabsInitData { void (*func)(void); - AVOnce control; -} FFSRTabsInitOnce; - -typedef struct FFSRTabsInitOnceExt { - void (*func)(void); - AVOnce control; int factors[TX_MAX_SUB]; /* Must be sorted high -> low */ -} FFSRTabsInitOnceExt; +} FFSRTabsInitData; #define SR_TABLE(len) \ static av_cold void TX_TAB(ff_tx_init_tab_ ##len)(void) \ @@ -80,9 +74,14 @@ static av_cold void TX_TAB(ff_tx_init_tab_ ##len)(void) \ SR_POW2_TABLES #undef SR_TABLE -static FFSRTabsInitOnce sr_tabs_init_once[] = { -#define SR_TABLE(len) \ - { TX_TAB(ff_tx_init_tab_ ## len), AV_ONCE_INIT }, +static void (*const sr_tabs_init_funcs[])(void) = { +#define SR_TABLE(len) TX_TAB(ff_tx_init_tab_ ##len), + SR_POW2_TABLES +#undef SR_TABLE +}; + +static AVOnce sr_tabs_init_once[] = { +#define SR_TABLE(len) AV_ONCE_INIT, SR_POW2_TABLES #undef SR_TABLE }; @@ -128,10 +127,16 @@ static av_cold void TX_TAB(ff_tx_init_tab_9)(void) TX_TAB(ff_tx_tab_9)[7] = TX_TAB(ff_tx_tab_9)[3] - TX_TAB(ff_tx_tab_9)[4]; } -static FFSRTabsInitOnceExt nptwo_tabs_init_once[] = { - { TX_TAB(ff_tx_init_tab_53), AV_ONCE_INIT, { 15, 5, 3 } }, - { TX_TAB(ff_tx_init_tab_9), AV_ONCE_INIT, { 9 } }, - { TX_TAB(ff_tx_init_tab_7), AV_ONCE_INIT, { 7 } }, +static const FFSRTabsInitData nptwo_tabs_init_data[] = { + { TX_TAB(ff_tx_init_tab_53), { 15, 5, 3 } }, + { TX_TAB(ff_tx_init_tab_9), { 9 } }, + { TX_TAB(ff_tx_init_tab_7), { 7 } }, +}; + +static AVOnce nptwo_tabs_init_once[] = { + AV_ONCE_INIT, + AV_ONCE_INIT, + AV_ONCE_INIT, }; av_cold void TX_TAB(ff_tx_init_tabs)(int len) @@ -140,23 +145,23 @@ av_cold void TX_TAB(ff_tx_init_tabs)(int len) if (factor_2) { int idx = factor_2 - 3; for (int i = 0; i <= idx; i++) - ff_thread_once(&sr_tabs_init_once[i].control, - sr_tabs_init_once[i].func); + ff_thread_once(&sr_tabs_init_once[i], + sr_tabs_init_funcs[i]); len >>= factor_2; } - for (int i = 0; i < FF_ARRAY_ELEMS(nptwo_tabs_init_once); i++) { + for (int i = 0; i < FF_ARRAY_ELEMS(nptwo_tabs_init_data); i++) { int f, f_idx = 0; if (len <= 1) return; - while ((f = nptwo_tabs_init_once[i].factors[f_idx++])) { + while ((f = nptwo_tabs_init_data[i].factors[f_idx++])) { if (f % len) continue; - ff_thread_once(&nptwo_tabs_init_once[i].control, - nptwo_tabs_init_once[i].func); + ff_thread_once(&nptwo_tabs_init_once[i], + nptwo_tabs_init_data[i].func); len /= f; break; }