[FFmpeg-devel] [PATCH 22/26] lavc/fmtconvert: RISC-V V int32_to_float_fmul_scalar

Rémi Denis-Courmont remi at remlab.net
Tue Sep 20 18:12:17 EEST 2022


Le tiistaina 20. syyskuuta 2022, 18.00.09 EEST Andreas Rheinhardt a écrit :
> remi at remlab.net:
> > From: Rémi Denis-Courmont <remi at remlab.net>
> > 
> > ---
> > 
> >  libavcodec/fmtconvert.c            |  2 ++
> >  libavcodec/fmtconvert.h            |  1 +
> >  libavcodec/riscv/Makefile          |  2 ++
> >  libavcodec/riscv/fmtconvert_init.c | 41 ++++++++++++++++++++++++++++++
> >  libavcodec/riscv/fmtconvert_rvv.S  | 40 +++++++++++++++++++++++++++++
> >  5 files changed, 86 insertions(+)
> >  create mode 100644 libavcodec/riscv/fmtconvert_init.c
> >  create mode 100644 libavcodec/riscv/fmtconvert_rvv.S
> > 
> > diff --git a/libavcodec/fmtconvert.c b/libavcodec/fmtconvert.c
> > index 00f55f8f1e..8dcef82ee3 100644
> > --- a/libavcodec/fmtconvert.c
> > +++ b/libavcodec/fmtconvert.c
> > @@ -53,6 +53,8 @@ av_cold void ff_fmt_convert_init(FmtConvertContext *c,
> > AVCodecContext *avctx)> 
> >      ff_fmt_convert_init_arm(c, avctx);
> >  
> >  #elif ARCH_PPC
> >  
> >      ff_fmt_convert_init_ppc(c, avctx);
> > 
> > +#elif ARCH_RISCV
> > +    ff_fmt_convert_init_riscv(c, avctx);
> > 
> >  #elif ARCH_X86
> >  
> >      ff_fmt_convert_init_x86(c, avctx);
> >  
> >  #endif
> > 
> > diff --git a/libavcodec/fmtconvert.h b/libavcodec/fmtconvert.h
> > index b2df7a9629..ca51d0861a 100644
> > --- a/libavcodec/fmtconvert.h
> > +++ b/libavcodec/fmtconvert.h
> > @@ -61,6 +61,7 @@ void ff_fmt_convert_init(FmtConvertContext *c,
> > AVCodecContext *avctx);> 
> >  void ff_fmt_convert_init_aarch64(FmtConvertContext *c, AVCodecContext
> >  *avctx); void ff_fmt_convert_init_arm(FmtConvertContext *c,
> >  AVCodecContext *avctx); void ff_fmt_convert_init_ppc(FmtConvertContext
> >  *c, AVCodecContext *avctx);> 
> > +void ff_fmt_convert_init_riscv(FmtConvertContext *c, AVCodecContext
> > *avctx);> 
> >  void ff_fmt_convert_init_x86(FmtConvertContext *c, AVCodecContext
> >  *avctx);
> >  void ff_fmt_convert_init_mips(FmtConvertContext *c);
> > 
> > diff --git a/libavcodec/riscv/Makefile b/libavcodec/riscv/Makefile
> > index 99541b075e..682174e875 100644
> > --- a/libavcodec/riscv/Makefile
> > +++ b/libavcodec/riscv/Makefile
> > @@ -1,5 +1,7 @@
> > 
> >  OBJS-$(CONFIG_AUDIODSP) += riscv/audiodsp_init.o \
> >  
> >                             riscv/audiodsp_rvf.o
> >  
> >  RVV-OBJS-$(CONFIG_AUDIODSP) += riscv/audiodsp_rvv.o
> > 
> > +OBJS-$(CONFIG_FMTCONVERT) += riscv/fmtconvert_init.o
> > +RVV-OBJS-$(CONFIG_FMTCONVERT) += riscv/fmtconvert_rvv.o
> > 
> >  OBJS-$(CONFIG_PIXBLOCKDSP) += riscv/pixblockdsp_init.o \
> >  
> >                                riscv/pixblockdsp_rvi.o
> > 
> > diff --git a/libavcodec/riscv/fmtconvert_init.c
> > b/libavcodec/riscv/fmtconvert_init.c new file mode 100644
> > index 0000000000..aa7d44ff5a
> > --- /dev/null
> > +++ b/libavcodec/riscv/fmtconvert_init.c
> > @@ -0,0 +1,41 @@
> > +/*
> > + * Copyright © 2022 Rémi Denis-Courmont.
> > + *
> > + * 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 <stdint.h>
> > +
> > +#include "config.h"
> > +#include "libavutil/attributes.h"
> > +#include "libavutil/cpu.h"
> > +#include "libavcodec/avcodec.h"
> > +#include "libavcodec/fmtconvert.h"
> > +
> > +void ff_int32_to_float_fmul_scalar_rvv(float *dst, const int32_t *src,
> > +                                       float mul, int len);
> > +
> > +av_cold void ff_fmt_convert_init_riscv(FmtConvertContext *c,
> > +                                       AVCodecContext *avctx)
> > +{
> > +#ifdef HAVE_RVV
> > +    int flags = av_get_cpu_flags();
> > +
> > +    if (flags & AV_CPU_FLAG_RV_ZVE32F)
> > +        c->int32_to_float_fmul_scalar =
> > ff_int32_to_float_fmul_scalar_rvv;
> 
> If you added {} in this patch, you would not need to rewrite the if-line
> in the next patch.

I know, right... But in the review of the first version review, I was requested 
to stick to the coding style in an essentially identical scenario:
http://ffmpeg.org/pipermail/ffmpeg-devel/2022-September/300894.html

> 
> > +#endif
> > +}
> > diff --git a/libavcodec/riscv/fmtconvert_rvv.S
> > b/libavcodec/riscv/fmtconvert_rvv.S new file mode 100644
> > index 0000000000..c19b77e38a
> > --- /dev/null
> > +++ b/libavcodec/riscv/fmtconvert_rvv.S
> > @@ -0,0 +1,40 @@
> > +/*
> > + * Copyright © 2022 Rémi Denis-Courmont.
> > + *
> > + * 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/riscv/asm.S"
> > +
> > +func ff_int32_to_float_fmul_scalar_rvv, zve32f
> > +NOHWF   fmv.w.x     fa0, a2
> > +NOHWF   mv          a2, a3
> > +1:
> > +        vsetvli     t0, a2, e32, m1, ta, ma
> > +        vle32.v     v24, (a1)
> > +        slli        t1, t0, 2
> > +        vfcvt.f.x.v v24, v24
> > +        sub         a2, a2, t0
> > +        vfmul.vf    v24, v24, fa0
> > +        add         a1, a1, t1
> > +        vse32.v     v24, (a0)
> > +        add         a0, a0, t1
> > +        bnez        a2, 1b
> > +
> > +        ret
> > +endfunc
> 
> Notice that there will be a slight conflict with
> https://ffmpeg.org/pipermail/ffmpeg-devel/2022-September/301710.html;
> but it is trivial to fix. Just don't forget to remove the avcodec.h
> inclusion.
> 
> - Andreas
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".


-- 
Реми Дёни-Курмон
http://www.remlab.net/





More information about the ffmpeg-devel mailing list