From patchwork Mon Apr 19 20:20:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lynne X-Patchwork-Id: 27106 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:5014:0:0:0:0:0 with SMTP id e20csp836152iob; Mon, 19 Apr 2021 13:20:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzybzgs/IGUV2a4JK+HSnaNYcJazK1Slzeh9J+3moYAywxFFxShRzNP5cMAC5kL1pYigYMK X-Received: by 2002:a05:6402:1c84:: with SMTP id cy4mr15707542edb.260.1618863643818; Mon, 19 Apr 2021 13:20:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618863643; cv=none; d=google.com; s=arc-20160816; b=c4eg9fYd4zZxYqsOOkiggF/FU27+I8PxZ8w0ZiZvBJATD+IQ5A72TpATtB2cnPELy2 ChurwQoZBPIvpYvdy0FX89RwEjPrgHYjBsQSWPeocMzTdnCBL7xGgyNSp3+kEW6Opati JMUZE6f/aOtLL8zmTlS+144sDu638BqDEs0C6Wueq3tGYyWCQmMBga7Qze0CxVscyoA8 XZAW6hQsecs0kHAIvpZsm6ndCs/dSSWyzV/RSApElecpt9xUzhHp+jpT7OQd5wikIE9u 3+AFe1k+nVybR+lI1B/P9GvanGKvP2vFM08bZO9FRvMOvwVGm1eH2n9I+YLBfkmMDAng VfGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:to:from:date :dkim-signature:delivered-to; bh=I8Dz6bkK7keWj0CpJdqyMU1VKIgBB9yGgmrvYu3zrxQ=; b=z6J7iSGGf8WvDbos/YpFeYQpThyxaK1bDG1UggslaxSCtIS5V2uwUdNI0bb8kmWJuy 8PMWkM6Q5iOzQUoK+Tqy4MDQ4NiX/L9H30n9IQpjE3OE5Obf8HRPjaLs+Nt426SYSdDG gb4kRWjxJUYnsscLBBvbYgW1MQASTjhdNT99Ao4xvbw9aw3+Xi13zFXVu/CI9T2Y8dxj 8EpPGRG4owzaCj/PP7syHqwpgl2Ar/61rzNxE0sZ3tyy+LGvaDRJqwBgLWcQXU2Ka+Rd +RdP1Om8iroczq3Q2w4z7DzA+Q2OEx2YtyrN4hlquxAR/f48t3i9zJ2okLEZDAeEtGy1 iHZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@lynne.ee header.s=s1 header.b=g4Kujauc; 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=NONE dis=NONE) header.from=lynne.ee Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id i23si12709154ejy.659.2021.04.19.13.20.43; Mon, 19 Apr 2021 13:20:43 -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=@lynne.ee header.s=s1 header.b=g4Kujauc; 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=NONE dis=NONE) header.from=lynne.ee Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3C8EA680340; Mon, 19 Apr 2021 23:20:41 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from w4.tutanota.de (w4.tutanota.de [81.3.6.165]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E040C680340 for ; Mon, 19 Apr 2021 23:20:34 +0300 (EEST) Received: from w3.tutanota.de (unknown [192.168.1.164]) by w4.tutanota.de (Postfix) with ESMTP id 8E3C7106014C for ; Mon, 19 Apr 2021 20:20:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1618863634; s=s1; d=lynne.ee; h=From:From:To:To:Subject:Subject:Content-Description:Content-ID:Content-Type:Content-Type:Content-Transfer-Encoding:Cc:Date:Date:In-Reply-To:In-Reply-To:MIME-Version:MIME-Version:Message-ID:Message-ID:Reply-To:References:References:Sender; bh=wdsolWhwv0jLTOobJTwcbiqow1Q/mqv6iqh2BmLMiT4=; b=g4KujaucmmuPGJ/3LzGZ6z5W8HXkdNC+0SLP3LrJB9cycDiHd4Ik7MaHJ1ZNJQMC agSbtWFBCBQ9qk1behoccrULygBOBQ49YyjOKt8SWxSKqDsEpezUg1MEZx5HbGHtTCA BetaFirIbvGcYFOVlvkE4Zlfqk7p44A+tPedQLE1ragc++97r1AeTtflVWGzeWVSUkn b5Eb91UGmurau8n5FrN77EDbuqHniYB6bGznZjxmpxm5yAtyZ0TcxwjMRYRNocSYIgO 6ZnwRHLEppJpbZm79jWZ1lFDDDkyr4yBsAQsMZ/eZZ8GPaJ/aLrPqP8RpkpWytR1w7F h4Hl9QJPGQ== Date: Mon, 19 Apr 2021 22:20:34 +0200 (CEST) From: Lynne To: FFmpeg development discussions and patches Message-ID: In-Reply-To: References: MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 01/11] lavu/tx: minor code style improvements and additional comments 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: +m7m8Lg55W85 Patch attached. Subject: [PATCH 01/11] lavu/tx: minor code style improvements and additional comments --- libavutil/tx.c | 17 +++++++++++++- libavutil/tx.h | 2 ++ libavutil/tx_priv.h | 57 ++++++++++++++++++++++++--------------------- 3 files changed, 48 insertions(+), 28 deletions(-) diff --git a/libavutil/tx.c b/libavutil/tx.c index 1161df3285..05d4de30cc 100644 --- a/libavutil/tx.c +++ b/libavutil/tx.c @@ -30,7 +30,7 @@ int ff_tx_type_is_mdct(enum AVTXType type) } } -/* Calculates the modular multiplicative inverse, not fast, replace */ +/* Calculates the modular multiplicative inverse */ static av_always_inline int mulinv(int n, int m) { n = n % m; @@ -91,6 +91,17 @@ int ff_tx_gen_compound_mapping(AVTXContext *s) return 0; } +static inline int split_radix_permutation(int i, int m, int inverse) +{ + m >>= 1; + if (m <= 1) + return i & 1; + if (!(i & m)) + return (split_radix_permutation(i, m, inverse) << 1); + m >>= 1; + return (split_radix_permutation(i, m, inverse) << 2) + 1 - 2*(!(i & m) ^ inverse); +} + int ff_tx_gen_ptwo_revtab(AVTXContext *s, int invert_lookup) { const int m = s->m, inv = s->inv; @@ -117,6 +128,7 @@ int ff_tx_gen_ptwo_inplace_revtab_idx(AVTXContext *s) if (!(s->inplace_idx = av_malloc(s->m*sizeof(*s->inplace_idx)))) return AVERROR(ENOMEM); + /* The first coefficient is always already in-place */ for (int src = 1; src < s->m; src++) { int dst = s->revtab[src]; int found = 0; @@ -124,6 +136,9 @@ int ff_tx_gen_ptwo_inplace_revtab_idx(AVTXContext *s) if (dst <= src) continue; + /* This just checks if a closed loop has been encountered before, + * and if so, skips it, since to fully permute a loop we must only + * enter it once. */ do { for (int j = 0; j < nb_inplace_idx; j++) { if (dst == s->inplace_idx[j]) { diff --git a/libavutil/tx.h b/libavutil/tx.h index bfc0c7f2a3..fccded8bc3 100644 --- a/libavutil/tx.h +++ b/libavutil/tx.h @@ -49,9 +49,11 @@ enum AVTXType { * float. Length is the frame size, not the window size (which is 2x frame) * For forward transforms, the stride specifies the spacing between each * sample in the output array in bytes. The input must be a flat array. + * * For inverse transforms, the stride specifies the spacing between each * sample in the input array in bytes. The output will be a flat array. * Stride must be a non-zero multiple of sizeof(float). + * * NOTE: the inverse transform is half-length, meaning the output will not * contain redundant data. This is what most codecs work with. */ diff --git a/libavutil/tx_priv.h b/libavutil/tx_priv.h index e2f4314a4f..10d7ea3ade 100644 --- a/libavutil/tx_priv.h +++ b/libavutil/tx_priv.h @@ -20,9 +20,7 @@ #define AVUTIL_TX_PRIV_H #include "tx.h" -#include #include "thread.h" -#include "mem.h" #include "mem_internal.h" #include "avassert.h" #include "attributes.h" @@ -48,12 +46,14 @@ typedef void FFTComplex; #if defined(TX_FLOAT) || defined(TX_DOUBLE) -#define CMUL(dre, dim, are, aim, bre, bim) do { \ +#define CMUL(dre, dim, are, aim, bre, bim) \ + do { \ (dre) = (are) * (bre) - (aim) * (bim); \ (dim) = (are) * (bim) + (aim) * (bre); \ } while (0) -#define SMUL(dre, dim, are, aim, bre, bim) do { \ +#define SMUL(dre, dim, are, aim, bre, bim) \ + do { \ (dre) = (are) * (bre) - (aim) * (bim); \ (dim) = (are) * (bim) - (aim) * (bre); \ } while (0) @@ -66,7 +66,8 @@ typedef void FFTComplex; #elif defined(TX_INT32) /* Properly rounds the result */ -#define CMUL(dre, dim, are, aim, bre, bim) do { \ +#define CMUL(dre, dim, are, aim, bre, bim) \ + do { \ int64_t accu; \ (accu) = (int64_t)(bre) * (are); \ (accu) -= (int64_t)(bim) * (aim); \ @@ -76,7 +77,8 @@ typedef void FFTComplex; (dim) = (int)(((accu) + 0x40000000) >> 31); \ } while (0) -#define SMUL(dre, dim, are, aim, bre, bim) do { \ +#define SMUL(dre, dim, are, aim, bre, bim) \ + do { \ int64_t accu; \ (accu) = (int64_t)(bre) * (are); \ (accu) -= (int64_t)(bim) * (aim); \ @@ -93,7 +95,8 @@ typedef void FFTComplex; #endif -#define BF(x, y, a, b) do { \ +#define BF(x, y, a, b) \ + do { \ x = (a) - (b); \ y = (a) + (b); \ } while (0) @@ -101,7 +104,7 @@ typedef void FFTComplex; #define CMUL3(c, a, b) \ CMUL((c).re, (c).im, (a).re, (a).im, (b).re, (b).im) -#define COSTABLE(size) \ +#define COSTABLE(size) \ DECLARE_ALIGNED(32, FFTSample, TX_NAME(ff_cos_##size))[size/2] /* Used by asm, reorder with care */ @@ -114,35 +117,35 @@ struct AVTXContext { double scale; /* Scale */ FFTComplex *exptab; /* MDCT exptab */ - FFTComplex *tmp; /* Temporary buffer needed for all compound transforms */ + FFTComplex *tmp; /* Temporary buffer needed for all compound transforms */ int *pfatab; /* Input/Output mapping for compound transforms */ int *revtab; /* Input mapping for power of two transforms */ int *inplace_idx; /* Required indices to revtab for in-place transforms */ }; -/* Shared functions */ +/* Checks if type is an MDCT */ int ff_tx_type_is_mdct(enum AVTXType type); + +/* + * Generates the PFA permutation table into AVTXContext->pfatab. The end table + * is appended to the start table. + */ int ff_tx_gen_compound_mapping(AVTXContext *s); + +/* + * Generates a standard-ish (slightly modified) Split-Radix revtab into + * AVTXContext->revtab + */ int ff_tx_gen_ptwo_revtab(AVTXContext *s, int invert_lookup); + +/* + * Generates an index into AVTXContext->inplace_idx that if followed in the + * specific order, allows the revtab to be done in-place. AVTXContext->revtab + * must already exist. + */ int ff_tx_gen_ptwo_inplace_revtab_idx(AVTXContext *s); -/* Also used by SIMD init */ -static inline int split_radix_permutation(int i, int n, int inverse) -{ - int m; - if (n <= 2) - return i & 1; - m = n >> 1; - if (!(i & m)) - return split_radix_permutation(i, m, inverse)*2; - m >>= 1; - if (inverse == !(i & m)) - return split_radix_permutation(i, m, inverse)*4 + 1; - else - return split_radix_permutation(i, m, inverse)*4 - 1; -} - -/* Templated functions */ +/* Templated init functions */ int ff_tx_init_mdct_fft_float(AVTXContext *s, av_tx_fn *tx, enum AVTXType type, int inv, int len, const void *scale, uint64_t flags);