[FFmpeg-devel] [PATCH] lavc/flacdsp: implement wasted32 DSP function for VSX on POWER

Rémi Denis-Courmont remi at remlab.net
Sat Jul 13 11:51:28 EEST 2024


Le sunnuntaina 7. heinäkuuta 2024, 21.21.26 EEST Sean McGovern a écrit :
> RaptorCS POWER9 (8c4t) @ 2.2GHz:
> flac_wasted_32_c: 50.1
> flac_wasted_32_vsx: 14.1
> ---
>  libavcodec/flacdsp.c          |  2 ++
>  libavcodec/flacdsp.h          |  1 +
>  libavcodec/ppc/Makefile       |  2 ++
>  libavcodec/ppc/flacdsp_init.c | 38 +++++++++++++++++++++++++
>  libavcodec/ppc/flacdsp_vsx.c  | 53 +++++++++++++++++++++++++++++++++++
>  5 files changed, 96 insertions(+)
>  create mode 100644 libavcodec/ppc/flacdsp_init.c
>  create mode 100644 libavcodec/ppc/flacdsp_vsx.c
> 
> diff --git a/libavcodec/flacdsp.c b/libavcodec/flacdsp.c
> index f5362bf66f..b63d55ddcd 100644
> --- a/libavcodec/flacdsp.c
> +++ b/libavcodec/flacdsp.c
> @@ -156,5 +156,7 @@ av_cold void ff_flacdsp_init(FLACDSPContext *c, enum
> AVSampleFormat fmt, int cha ff_flacdsp_init_riscv(c, fmt, channels);
>  #elif ARCH_X86
>      ff_flacdsp_init_x86(c, fmt, channels);
> +#elif ARCH_PPC
> +    ff_flacdsp_init_ppc(c, fmt, channels);
>  #endif
>  }
> diff --git a/libavcodec/flacdsp.h b/libavcodec/flacdsp.h
> index 3b7b35a112..941536ef16 100644
> --- a/libavcodec/flacdsp.h
> +++ b/libavcodec/flacdsp.h
> @@ -45,5 +45,6 @@ void ff_flacdsp_init(FLACDSPContext *c, enum
> AVSampleFormat fmt, int channels); void ff_flacdsp_init_arm(FLACDSPContext
> *c, enum AVSampleFormat fmt, int channels); void
> ff_flacdsp_init_riscv(FLACDSPContext *c, enum AVSampleFormat fmt, int
> channels); void ff_flacdsp_init_x86(FLACDSPContext *c, enum AVSampleFormat
> fmt, int channels); +void ff_flacdsp_init_ppc(FLACDSPContext *c, enum
> AVSampleFormat fmt, int channels);
> 
>  #endif /* AVCODEC_FLACDSP_H */
> diff --git a/libavcodec/ppc/Makefile b/libavcodec/ppc/Makefile
> index 10b9ca60da..7f81a8aa34 100644
> --- a/libavcodec/ppc/Makefile
> +++ b/libavcodec/ppc/Makefile
> @@ -2,6 +2,8 @@
>  OBJS-$(CONFIG_AUDIODSP)                += ppc/audiodsp.o
>  OBJS-$(CONFIG_BLOCKDSP)                += ppc/blockdsp.o
>  OBJS-$(CONFIG_FDCTDSP)                 += ppc/fdctdsp.o
> +OBJS-$(CONFIG_FLAC_DECODER)            += ppc/flacdsp_init.o
> +VSX-OBJS-$(CONFIG_FLAC_DECODER)        += ppc/flacdsp_vsx.o
>  OBJS-$(CONFIG_FMTCONVERT)              += ppc/fmtconvert_altivec.o
>  OBJS-$(CONFIG_H264CHROMA)              += ppc/h264chroma_init.o
>  OBJS-$(CONFIG_H264DSP)                 += ppc/h264dsp.o
> ppc/hpeldsp_altivec.o diff --git a/libavcodec/ppc/flacdsp_init.c
> b/libavcodec/ppc/flacdsp_init.c new file mode 100644
> index 0000000000..526bddddbf
> --- /dev/null
> +++ b/libavcodec/ppc/flacdsp_init.c
> @@ -0,0 +1,38 @@
> +/*
> + * Copyright (c) 2024 Sean McGovern <gseanmcg at gmail.com>
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
> USA + */
> +
> +#include "config.h"
> +
> +#include "libavutil/attributes.h"
> +#include "libavutil/cpu.h"
> +#include "libavutil/ppc/cpu.h"
> +#include "libavcodec/flacdsp.h"
> +
> +void ff_flac_wasted32_vsx(int32_t *, int wasted, int len);
> +
> +av_cold void ff_flacdsp_init_ppc(FLACDSPContext *c, enum AVSampleFormat
> fmt, int channels) +{
> +#if HAVE_VSX
> +    if (!PPC_VSX(av_get_cpu_flags()))
> +        return;
> +
> +    c->wasted32 = ff_flac_wasted32_vsx;
> +#endif
> +}
> diff --git a/libavcodec/ppc/flacdsp_vsx.c b/libavcodec/ppc/flacdsp_vsx.c
> new file mode 100644
> index 0000000000..7464108c45
> --- /dev/null
> +++ b/libavcodec/ppc/flacdsp_vsx.c
> @@ -0,0 +1,53 @@
> +/*
> + * Copyright (c) 2024 Sean McGovern <gseanmcg at gmail.com>
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
> USA + */
> +
> +#include "config.h"
> +
> +#include "libavutil/attributes.h"
> +#include "libavutil/cpu.h"
> +#include "libavutil/ppc/cpu.h"
> +#include "libavutil/ppc/util_altivec.h"
> +#include "libavcodec/flacdsp.h"
> +
> +void ff_flac_wasted32_vsx(int32_t *, int wasted, int len);
> +
> +#if HAVE_VSX
> +
> +void ff_flac_wasted32_vsx(int32_t *decoded, int wasted, int len)
> +{
> +    register vec_s32 vec1, vec2;
> +    const register vec_u32 vwasted = vec_splats((unsigned)wasted);
> +
> +    for (int i = 0; i < len; i+=8 /* increment is by # elements, not bytes

You could do:

for (int32_t *const end = decoded + len; decoded < end; decoded += 8)

to keep just one counter rather than two. That said, maybe the C compiler 
performs that optimisation automatically anyway (?).

> */) {
> +	/* that said, we have some extra bandwidth so let's unroll it
> slightly */
> +        vec1 = vec_xl(0, decoded);
> +        vec2 = vec_xl(16, decoded);
> +
> +        vec1 = vec_sl(vec1, vwasted);
> +        vec2 = vec_sl(vec2, vwasted);
> +
> +        vec_xst(vec1, 0, decoded);
> +        vec_xst(vec2, 16, decoded);
> +
> +        decoded += 8;
> +    }
> +}
> +
> +#endif /* HAVE_VSX */


-- 
レミ・デニ-クールモン
http://www.remlab.net/





More information about the ffmpeg-devel mailing list