Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: James Almer <jamrial-at-gmail.com@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Subject: Re: [FFmpeg-devel] [PATCH v5 07/13] avfilter/x86/f_ebur128: add x86 AVX implementation
Date: Fri, 20 Jun 2025 10:49:23 -0300
Message-ID: <6b18427b-fac7-4cc4-9d20-444d4dd291d3@gmail.com> (raw)
In-Reply-To: <20250620132139.2431475-7-ffmpeg@haasn.xyz>


[-- Attachment #1.1.1: Type: text/plain, Size: 5399 bytes --]

On 6/20/2025 10:21 AM, Niklas Haas wrote:
> From: Niklas Haas <git@haasn.dev>
> 
> Processes two channels in parallel, using 128-bit XMM registers.
> 
> In theory, we could go up to YMM registers to process 4 channels, but this is
> not a gain except for relatively high channel counts (e.g. 7.1), and also
> complicates the sample load/store operations considerably.
> 
> I decided to only add an AVX variant, since the C code is not substantially
> slower enough to justify a separate function just for ancient CPUs.
> ---
>   libavfilter/f_ebur128.c          |  15 ++--
>   libavfilter/f_ebur128.h          |  16 ++++
>   libavfilter/x86/Makefile         |   4 +
>   libavfilter/x86/f_ebur128.asm    | 141 +++++++++++++++++++++++++++++++
>   libavfilter/x86/f_ebur128_init.c |  35 ++++++++
>   5 files changed, 206 insertions(+), 5 deletions(-)
>   create mode 100644 libavfilter/x86/f_ebur128.asm
>   create mode 100644 libavfilter/x86/f_ebur128_init.c
> 
> diff --git a/libavfilter/f_ebur128.c b/libavfilter/f_ebur128.c
> index b9e210c05a..2d94cefce7 100644
> --- a/libavfilter/f_ebur128.c
> +++ b/libavfilter/f_ebur128.c
> @@ -579,6 +579,11 @@ static av_cold int init(AVFilterContext *ctx)
>       /* summary */
>       av_log(ctx, AV_LOG_VERBOSE, "EBU +%d scale\n", ebur128->meter);
>   
> +    ebur128->dsp.filter_channels = ff_ebur128_filter_channels_c;
> +#if ARCH_X86
> +    ff_ebur128_init_x86(&ebur128->dsp);
> +#endif
> +
>       return 0;
>   }
>   
> @@ -692,11 +697,11 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
>           MOVE_TO_NEXT_CACHED_ENTRY(400);
>           MOVE_TO_NEXT_CACHED_ENTRY(3000);
>   
> -        ff_ebur128_filter_channels_c(dsp, &samples[idx_insample * nb_channels],
> -                                     &ebur128->i400.cache[bin_id_400 * nb_channels],
> -                                     &ebur128->i3000.cache[bin_id_3000 * nb_channels],
> -                                     ebur128->i400.sum, ebur128->i3000.sum,
> -                                     nb_channels);
> +        dsp->filter_channels(dsp, &samples[idx_insample * nb_channels],
> +                             &ebur128->i400.cache[bin_id_400 * nb_channels],
> +                             &ebur128->i3000.cache[bin_id_3000 * nb_channels],
> +                             ebur128->i400.sum, ebur128->i3000.sum,
> +                             nb_channels);
>   
>   #define FIND_PEAK(global, sp, ptype) do {                        \
>       int ch;                                                      \
> diff --git a/libavfilter/f_ebur128.h b/libavfilter/f_ebur128.h
> index 7b8e876576..1889e28bdd 100644
> --- a/libavfilter/f_ebur128.h
> +++ b/libavfilter/f_ebur128.h
> @@ -22,6 +22,9 @@
>   #ifndef AVFILTER_F_EBUR128_H
>   #define AVFILTER_F_EBUR128_H
>   
> +#include <assert.h>
> +#include <stddef.h>
> +
>   typedef struct EBUR128Biquad {
>       double b0, b1, b2;
>       double a1, a2;
> @@ -35,8 +38,21 @@ typedef struct EBUR128DSPContext {
>       /* Cache of 3 samples for each channel */
>       double *y; /* after pre-filter */
>       double *z; /* after RLB-filter */
> +
> +    /* DSP functions */
> +    void (*filter_channels)(const struct EBUR128DSPContext *dsp,
> +                            const double *samples,
> +                            double *cache_400, double *cache_3000,
> +                            double *sum_400, double *sum_3000,
> +                            int nb_channels);
>   } EBUR128DSPContext;
>   
> +static_assert(offsetof(EBUR128DSPContext, pre) == 0,                   "struct layout mismatch");
> +static_assert(offsetof(EBUR128DSPContext, rlb) == 5  * sizeof(double), "struct layout mismatch");
> +static_assert(offsetof(EBUR128DSPContext, y)   == 10 * sizeof(double), "struct layout mismatch");
> +
> +void ff_ebur128_init_x86(EBUR128DSPContext *dsp);
> +
>   void ff_ebur128_filter_channels_c(const EBUR128DSPContext *, const double *,
>                                     double *, double *, double *, double *, int);
>   
> diff --git a/libavfilter/x86/Makefile b/libavfilter/x86/Makefile
> index 0d9a28a935..e5f0c55a5e 100644
> --- a/libavfilter/x86/Makefile
> +++ b/libavfilter/x86/Makefile
> @@ -7,6 +7,7 @@ OBJS-$(CONFIG_BLEND_FILTER)                  += x86/vf_blend_init.o
>   OBJS-$(CONFIG_BWDIF_FILTER)                  += x86/vf_bwdif_init.o
>   OBJS-$(CONFIG_COLORSPACE_FILTER)             += x86/colorspacedsp_init.o
>   OBJS-$(CONFIG_CONVOLUTION_FILTER)            += x86/vf_convolution_init.o
> +OBJS-$(CONFIG_EBUR128_FILTER)                += x86/f_ebur128_init.o
>   OBJS-$(CONFIG_EQ_FILTER)                     += x86/vf_eq_init.o
>   OBJS-$(CONFIG_FSPP_FILTER)                   += x86/vf_fspp_init.o
>   OBJS-$(CONFIG_GBLUR_FILTER)                  += x86/vf_gblur_init.o
> @@ -52,6 +53,9 @@ X86ASM-OBJS-$(CONFIG_BLEND_FILTER)           += x86/vf_blend.o
>   X86ASM-OBJS-$(CONFIG_BWDIF_FILTER)           += x86/vf_bwdif.o
>   X86ASM-OBJS-$(CONFIG_COLORSPACE_FILTER)      += x86/colorspacedsp.o
>   X86ASM-OBJS-$(CONFIG_CONVOLUTION_FILTER)     += x86/vf_convolution.o
> +ifdef ARCH_X86_64

nit: The way we do this usually is by adding this check to the asm file, 
to cover whatever is needed after the x86util.asm include.

Also, a checkasm test would be nice.


[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

  reply	other threads:[~2025-06-20 13:49 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-20 13:21 [FFmpeg-devel] [PATCH v5 01/13] avfilter/f_ebur128: use transformed direct form II Niklas Haas
2025-06-20 13:21 ` [FFmpeg-devel] [PATCH v5 02/13] avfilter/f_ebur128: simplify sample cache array Niklas Haas
2025-06-20 13:21 ` [FFmpeg-devel] [PATCH v5 03/13] avfilter/f_ebur128: use structs for biquad weights Niklas Haas
2025-06-20 13:21 ` [FFmpeg-devel] [PATCH v5 04/13] avfilter/f_ebur128: use a single packed array for the integrator cache Niklas Haas
2025-06-20 13:21 ` [FFmpeg-devel] [PATCH v5 05/13] avfilter/f_ebur128: move weights and cache to EBUR128DSPContext Niklas Haas
2025-06-20 13:21 ` [FFmpeg-devel] [PATCH v5 06/13] avfilter/f_ebur128: split off C implementation to separate function Niklas Haas
2025-06-20 13:21 ` [FFmpeg-devel] [PATCH v5 07/13] avfilter/x86/f_ebur128: add x86 AVX implementation Niklas Haas
2025-06-20 13:49   ` James Almer [this message]
2025-06-20 13:21 ` [FFmpeg-devel] [PATCH v5 08/13] avfilter/f_ebur128: remove pointless macro Niklas Haas
2025-06-20 13:21 ` [FFmpeg-devel] [PATCH v5 09/13] avfilter/f_ebur128: move true peak calculation out of main loop Niklas Haas
2025-06-20 13:21 ` [FFmpeg-devel] [PATCH v5 10/13] avfilter/f_ebur128: lift sample " Niklas Haas
2025-06-20 13:21 ` [FFmpeg-devel] [PATCH v5 11/13] avfilter/f_ebur128: move variable declarations to usage site Niklas Haas
2025-06-20 13:21 ` [FFmpeg-devel] [PATCH v5 12/13] avfilter/f_ebur128: move peak detection to reusable DSP function Niklas Haas
2025-06-20 13:21 ` [FFmpeg-devel] [PATCH v5 13/13] avfilter/x86/f_ebur128: implement AVX peak calculation Niklas Haas
2025-06-20 13:23 ` [FFmpeg-devel] [PATCH v5 01/13] avfilter/f_ebur128: use transformed direct form II Niklas Haas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6b18427b-fac7-4cc4-9d20-444d4dd291d3@gmail.com \
    --to=jamrial-at-gmail.com@ffmpeg.org \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git