From patchwork Mon Oct 17 01:34:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 38756 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4a86:b0:9d:28a3:170e with SMTP id fn6csp1375804pzb; Sun, 16 Oct 2022 18:35:05 -0700 (PDT) X-Google-Smtp-Source: AMsMyM54+Aq5oOy4JjSmYJ/7d6oT7jm69PDH0kQQmhQgJznf0qemERRNy4jNp7VTjXB+WE4RozG3 X-Received: by 2002:a05:6402:448b:b0:43b:5ec6:8863 with SMTP id er11-20020a056402448b00b0043b5ec68863mr7937266edb.377.1665970505709; Sun, 16 Oct 2022 18:35:05 -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 g5-20020a50d5c5000000b00457f31c1a10si5961986edj.584.2022.10.16.18.35.05; Sun, 16 Oct 2022 18:35:05 -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="gAlfct/H"; 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 2E06F68BC94; Mon, 17 Oct 2022 04:35:03 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-oln040092074068.outbound.protection.outlook.com [40.92.74.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A48E868BC8B for ; Mon, 17 Oct 2022 04:35:01 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dcLBbuK5fjgtbYLojrNk8r4QF8HmYNQ7ykIHz9JVcrRo5KUwqD8ARm7Dl8DK6bCV1K3rxc1XlBHN+KAnJElht7IQ32LnrGiN6jAywU+T/f4XzpK27G8qK+i3dFgr+ElQF5jsor7whEDV4X2KCSiStShHmuGCh0LRi56ZoynJWfz95dbd2MO2CwQ519pUwbBjBMvc8cTt2KkIOQTETPKC9p/KrHgfuP1t/7fC/I8lsXmqmMS5JyBbXVtmcd/Ldif6kcIXvO2RkK1Y59CrdaqYmia4wwv4jOYgRCyXOLcAAAE8Wi83tM/STpzCn44PcmXRXUIPHZEVjUyYipSNengOnw== 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=Z7OrYCRLSmtlDgnZuEo7nh6O+j7nN3q3b0NGXvuKUzk=; b=ZQROFY8y3dyJvQO4b4DqNn/SjCCaA183HQL9qSqf4DD2yRPF+xCpBQotBzcVBRkoHWqhxQ94wHv+2st1rVCLlIMT2q02tNwLvfMmLPEBsc3NsCOubDlfXHoEs3bOFx4qpvTfASdSALxANt1pHAgqbiQxFcHKrJ/l0nw+qJDGvlBZ++nPQ5t1co5cIkLFXDQ3/JA4Pv/L9lCaLB1ugXWxhKh5MbDiXBnpj0mZXEvvFTDiQbMIAxh4FwEBz0+s3mX3bID2KraPZMbxudtnjSarVl7TIjuj7ZmWQO1d2oXrQdnAzeOUBEhZb3n8/1quxhaKqID6vo/puI21vJR6FePSGg== 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=Z7OrYCRLSmtlDgnZuEo7nh6O+j7nN3q3b0NGXvuKUzk=; b=gAlfct/HUvpS905I3OFZgy3XEtyFGgFpzh/nAMmwwPYm4zlhVE1oX0JVCK6W7ChUJtrsfrqBTitcSGDg6jGQkM6BjreQ+XmtY0To2e/7SlOOr/Lx3IfpkmCx8Z8qhzap8cgs6ISH5DnQ60pW4l6vzIGj4qt+aMteZH02jdQslu2iurMVJm6aFMg/3qEhP37pgPElGH1nDkQ+wWCtSSrxdGEI/X3P5D4TlavfyuCbrSNMfM2umqNNaehfJ7WviffSXsxosZ7wMoG0T4NmkjXHCa9DFS/rmOgsGeSIXH2ky3hIqKlk50ar5YzW1Sl/aauGX1W45eAnc2egEy3u1puEQA== Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) by DU0P250MB0916.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:3ec::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.26; Mon, 17 Oct 2022 01:34:59 +0000 Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::20c0:9c9e:87f:79f]) by GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::20c0:9c9e:87f:79f%2]) with mapi id 15.20.5723.033; Mon, 17 Oct 2022 01:34:59 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 17 Oct 2022 03:34:39 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [Tyw6g+Tpi13aI2HYcC4WsX+sw4IrQ6ZujYLUNMYRHUU=] X-ClientProxiedBy: FR3P281CA0056.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:4b::6) To GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) X-Microsoft-Original-Message-ID: <20221017013442.944352-2-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: GV1P250MB0737:EE_|DU0P250MB0916:EE_ X-MS-Office365-Filtering-Correlation-Id: 73e3c662-a2d4-432f-8853-08daafdfcdc2 X-MS-Exchange-SLBlob-MailProps: AZnQBsB9XmriMkceEMr8g00cHUekKy/us0waovk5mOuuLfRBQZurUqJm00fPV6PkuaznKwOHSeRv1aJeakMQxAlPHAnwFBJ7iywMgLsfUsLGlz/Cdwcd3n/pLlcTmZHt76dYOlv2FaeDugI0Z1CHRn7y6Xva3rozjQVh6TczYVq+PQEekgL19S9ogAifmRZHtvQyLn9Prp0mgHdov8cRfgr4mDAh7f2iDvAhJZu9B7BY3ipPYJrmyMT64obA3VmmXHR//+wsWNAJs8ZsFwhjv0Vkk2oOTD2nTg2vNBy4uaK+sLB9vvp6hXHPrNeQl9ZtVvt8Xc6MAWAQVE9oxLhvZs9W00IX6eFzFxZcevzA3N8CwtlLQQj05EThvlX/aZhM7HHJvlaEVfwC7N4V0wKkzC5AMIaby2zR58xD0Sjhtw5y3b6aePZmw9xpH3Dczob7VIhgM4evrnUYwMPTFk7glYXIHSUiLqYCGPgVTMs4+O4Nj7IebYen+Eti4dTlo+xZUDwW3FkWfdd3BITtWj3l8iKVp2xqLxemz0di9Wu73QN55DH5INAQ/N7/EqXI6XDB3Gjb00+f/fCkrdVkabh/NrP1fcycOdnqpaxqxvFs2Ki+voeqDCzvq83RKjfU0kt5jvZVCeNEMUvhA78blA/yQMSeX2YRZZcyDbpMGF7q0cu5hsK5V1ATwaOqAYpI/ebW0FQJRjVRFZ8fGNQySRvAqJppih0N3BdihVHa/Vvu5A3zTBgdFioAoIa0MAZuQhf+icvPWnYC3Es= X-Microsoft-Antispam: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Org: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 73e3c662-a2d4-432f-8853-08daafdfcdc2 X-MS-Exchange-CrossTenant-AuthSource: GV1P250MB0737.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Oct 2022 01:34:59.2879 (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: DU0P250MB0916 Subject: [FFmpeg-devel] [PATCH 3/6] avcodec/mpegvideo: Inline is_encoder in mpv_reconstruct_mb_internal() 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: I10w3O3MZ0TT Up until now, we inlined lowres_flag as well as is_mpeg12 independently (unless CONFIG_SMALL was true); this commit changes this to instead inline mpv_reconstruct_mb_internal() (at most) four times, namely once for encoders, once for decoders using lowres and once for non-lowres mpeg-1/2 decoders and once for non-lowres non-mpeg-1/2 decoders (mpeg-1/2 is not inlined in case of CONFIG_SMALL). This is neutral performance-wise, but proved beneficial size-wise: It saved 1776B of .text for GCC 11 or 1344B for Clang 14 (both -O3 x64). Notice that inlining is_mpeg12 for is_encoder would not really be beneficial, as the encoder codepath does mostly not depend on is_mpeg12 at all. Signed-off-by: Andreas Rheinhardt --- libavcodec/mpegvideo.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index c2fedbfdaa..43f3ec5a47 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -1310,9 +1310,8 @@ void ff_clean_intra_table_entries(MpegEncContext *s) */ static av_always_inline void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64], - int lowres_flag, int is_mpeg12) + int lowres_flag, int is_mpeg12, int is_encoder) { -#define IS_ENCODER(s) (CONFIG_MPEGVIDEOENC && !lowres_flag && (s)->encoding) #define IS_MPEG12(s) (is_mpeg12 == MAY_BE_MPEG12 ? ((s)->out_format == FMT_MPEG1) : is_mpeg12) const int mb_xy = s->mb_y * s->mb_stride + s->mb_x; @@ -1331,7 +1330,7 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64], } else if (is_mpeg12 != DEFINITELY_MPEG12 && (s->h263_pred || s->h263_aic)) s->mbintra_table[mb_xy]=1; - if (!IS_ENCODER(s) || (s->avctx->flags & AV_CODEC_FLAG_PSNR) || s->frame_skip_threshold || s->frame_skip_factor || + if (!is_encoder || (s->avctx->flags & AV_CODEC_FLAG_PSNR) || s->frame_skip_threshold || s->frame_skip_factor || !((s->intra_only || s->pict_type == AV_PICTURE_TYPE_B) && s->avctx->mb_decision != FF_MB_DECISION_RD)) { // FIXME precalc uint8_t *dest_y, *dest_cb, *dest_cr; @@ -1340,12 +1339,12 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64], qpel_mc_func (*op_qpix)[16]; const int linesize = s->current_picture.f->linesize[0]; //not s->linesize as this would be wrong for field pics const int uvlinesize = s->current_picture.f->linesize[1]; - const int readable = s->pict_type != AV_PICTURE_TYPE_B || IS_ENCODER(s) || s->avctx->draw_horiz_band || lowres_flag; + const int readable = s->pict_type != AV_PICTURE_TYPE_B || is_encoder || s->avctx->draw_horiz_band || lowres_flag; const int block_size= lowres_flag ? 8>>s->avctx->lowres : 8; /* avoid copy if macroblock skipped in last frame too */ /* skip only during decoding as we might trash the buffers during encoding a bit */ - if (!IS_ENCODER(s)) { + if (!is_encoder) { uint8_t *mbskip_ptr = &s->mbskip_table[mb_xy]; if (s->mb_skipped) { @@ -1375,7 +1374,7 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64], if (!s->mb_intra) { /* motion handling */ /* decoding or more than one mb_type (MC was already done otherwise) */ - if (!IS_ENCODER(s)) { + if (!is_encoder) { if(HAVE_THREADS && s->avctx->active_thread_type&FF_THREAD_FRAME) { if (s->mv_dir & MV_DIR_FORWARD) { @@ -1427,7 +1426,7 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64], } /* add dct residue */ - if (IS_ENCODER(s) || !(IS_MPEG12(s) || s->msmpeg4_version + if (is_encoder || !(IS_MPEG12(s) || s->msmpeg4_version || (s->codec_id==AV_CODEC_ID_MPEG4 && !s->mpeg_quant))){ add_dequant_dct(s, block[0], 0, dest_y , dct_linesize, s->qscale); add_dequant_dct(s, block[1], 1, dest_y + block_size, dct_linesize, s->qscale); @@ -1480,14 +1479,14 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64], } else { /* Only MPEG-4 Simple Studio Profile is supported in > 8-bit mode. TODO: Integrate 10-bit properly into mpegvideo.c so that ER works properly */ - if (is_mpeg12 != DEFINITELY_MPEG12 && CONFIG_MPEG4_DECODER && + if (!is_encoder && is_mpeg12 != DEFINITELY_MPEG12 && CONFIG_MPEG4_DECODER && /* s->codec_id == AV_CODEC_ID_MPEG4 && */ s->avctx->bits_per_raw_sample > 8) { ff_mpeg4_decode_studio(s, dest_y, dest_cb, dest_cr, block_size, uvlinesize, dct_linesize, dct_offset); } /* dct only in intra block */ - else if (IS_ENCODER(s) || !IS_MPEG12(s)) { + else if (is_encoder || !IS_MPEG12(s)) { put_dct(s, block[0], 0, dest_y , dct_linesize, s->qscale); put_dct(s, block[1], 1, dest_y + block_size, dct_linesize, s->qscale); put_dct(s, block[2], 2, dest_y + dct_offset , dct_linesize, s->qscale); @@ -1560,18 +1559,19 @@ void ff_mpv_reconstruct_mb(MpegEncContext *s, int16_t block[12][64]) } } + if (s->encoding) { + mpv_reconstruct_mb_internal(s, block, 0, MAY_BE_MPEG12, 1); + } else if (!s->avctx->lowres) { #if !CONFIG_SMALL - if(s->out_format == FMT_MPEG1) { - if (s->avctx->lowres) mpv_reconstruct_mb_internal(s, block, 1, DEFINITELY_MPEG12); - else mpv_reconstruct_mb_internal(s, block, 0, DEFINITELY_MPEG12); - } else { - if (s->avctx->lowres) mpv_reconstruct_mb_internal(s, block, 1, NOT_MPEG12); - else mpv_reconstruct_mb_internal(s, block, 0, NOT_MPEG12); - } + if (s->out_format == FMT_MPEG1) + mpv_reconstruct_mb_internal(s, block, 0, DEFINITELY_MPEG12, 0); + else + mpv_reconstruct_mb_internal(s, block, 0, NOT_MPEG12, 0); #else - if (s->avctx->lowres) mpv_reconstruct_mb_internal(s, block, 1, MAY_BE_MPEG12); - else mpv_reconstruct_mb_internal(s, block, 0, MAY_BE_MPEG12); + mpv_reconstruct_mb_internal(s, block, 0, MAY_BE_MPEG12, 0); #endif + } else + mpv_reconstruct_mb_internal(s, block, 1, MAY_BE_MPEG12, 0); } void ff_init_block_index(MpegEncContext *s){ //FIXME maybe rename