[FFmpeg-devel] [PATCH] ac3dsp: RISC-V V float_to_fixed24

James Almer jamrial at gmail.com
Wed Nov 22 19:18:05 EET 2023


On 11/22/2023 11:30 AM, flow gg wrote:
>> How did you test it?
> 
> I wrote a test, but it was a bit rough, so I want to modify it before
> submitting. I've added it to this reply.


> From 08a012d86db51275fd2cda8dd7ad47cc1f1481ce Mon Sep 17 00:00:00 2001
> From: sunyuechi <sunyuechi at iscas.ac.cn>
> Date: Wed, 22 Nov 2023 14:57:29 +0800
> Subject: [PATCH] lavc/ac3dsp: R-V V float_to_fixed24
> 
> ---
>  tests/checkasm/Makefile   |  1 +
>  tests/checkasm/ac3dsp.c   | 88 +++++++++++++++++++++++++++++++++++++++
>  tests/checkasm/checkasm.c |  3 ++
>  tests/checkasm/checkasm.h |  1 +
>  4 files changed, 93 insertions(+)
>  create mode 100644 tests/checkasm/ac3dsp.c
> 
> diff --git a/tests/checkasm/Makefile b/tests/checkasm/Makefile
> index 8bc241d29b..8c714c2a07 100644
> --- a/tests/checkasm/Makefile
> +++ b/tests/checkasm/Makefile
> @@ -5,6 +5,7 @@ AVCODECOBJS-$(CONFIG_BLOCKDSP)          += blockdsp.o
>  AVCODECOBJS-$(CONFIG_BSWAPDSP)          += bswapdsp.o
>  AVCODECOBJS-$(CONFIG_FMTCONVERT)        += fmtconvert.o
>  AVCODECOBJS-$(CONFIG_G722DSP)           += g722dsp.o
> +AVCODECOBJS-$(CONFIG_AC3DSP)            += ac3dsp.o
>  AVCODECOBJS-$(CONFIG_H264CHROMA)        += h264chroma.o
>  AVCODECOBJS-$(CONFIG_H264DSP)           += h264dsp.o
>  AVCODECOBJS-$(CONFIG_H264PRED)          += h264pred.o
> diff --git a/tests/checkasm/ac3dsp.c b/tests/checkasm/ac3dsp.c
> new file mode 100644
> index 0000000000..ebebe06990
> --- /dev/null
> +++ b/tests/checkasm/ac3dsp.c
> @@ -0,0 +1,88 @@
> +#include "checkasm.h"
> +#include <stdio.h>
> +
> +
> +#include <string.h>
> +
> +#include "libavutil/common.h"
> +#include "libavutil/intreadwrite.h"
> +#include "libavutil/mem.h"
> +#include "libavutil/mem_internal.h"
> +
> +#include "libavcodec/ac3dsp.h"
> +
> +/**
> + * Convert an array of float in range [-1.0,1.0] to int32_t with range
> + * [-(1<<24),(1<<24)]
> + *
> + * @param dst destination array of int32_t.
> + *            constraints: 16-byte aligned
> + * @param src source array of float.
> + *            constraints: 16-byte aligned
> + * @param len number of elements to convert.
> + *            constraints: multiple of 32 greater than zero
> + */
> +// void (*float_to_fixed24)(int32_t *dst, const float *src, unsigned int len);
> +
> +
> +#define randomize_float(buf, len)                               \
> +    do {                                                        \
> +        int i;                                                  \
> +        for (i = 0; i < len; i++) {                             \
> +            float f = (float)rnd() / (UINT_MAX >> 5) - 16.0f;   \
> +            buf[i] = f;                                         \
> +        }                                                       \
> +    } while (0)
> +
> +#define randomize_int(buf, len, size, bits)                         \
> +    do {                                                            \
> +        int i;                                                      \
> +        for (i = 0; i < len; i++) {                                 \
> +            uint ## size ## _t r = rnd() & ((1LL << bits) - 1);     \
> +            AV_WN ## size ## A(buf + i, -(1LL << (bits - 1)) + r);  \
> +        }                                                           \
> +    } while (0)
> +
> +static void check_float_to_fixed24(AC3DSPContext *c) {
> +#define BUF_SIZE 800

800, if this is meant to be used as len, is not a multiple of 32.

> +    LOCAL_ALIGNED_32(int32_t, v1, [BUF_SIZE]);
> +    LOCAL_ALIGNED_32(float, v2, [BUF_SIZE]);
> +
> +    declare_func(void, int32_t *, const float *, unsigned int);
> +
> +    randomize_int(v1, BUF_SIZE, 32, 10);

This is not really used at all. The input is floats, and the output is 
write only.

> +    randomize_float(v2, BUF_SIZE);
> +
> +    if (check_func(c->float_to_fixed24, "float_to_fixed24")) {
> +        LOCAL_ALIGNED_32(int32_t, dst, [BUF_SIZE]);
> +        LOCAL_ALIGNED_32(int32_t, dst2, [BUF_SIZE]);

The requirement is 16 byte alignment.

> +
> +        call_ref(dst, v2, 80);

This should be BUF_SIZE. And 80 is also not a multiple of 32.

> +        call_new(dst2, v2, 80);
> +
> +				if (memcmp(dst, dst2, sizeof(*dst) * 10) != 0){

memcmp(dst, dst2, sizeof(dst))

> +						puts(">>>>>>>>>>>>>> fail --------------------");

No puts(), please. This line is also not needed.

> +						for(int i = 0 ; i < 10; i++){
> +							printf("dst[%d] = %d, dst2[%d] = %d\n", i, dst[i], i, dst2[i]);

fprintf(stderr, ...);

> +						}
> +						puts("");
> +
> +            fail();
> +				} else {
> +					puts(">>>>>>>>>>>>>> ok --------------------");

Same.

> +				}
> +
> +        bench_new(v1, v2, 80);

bench_new(dst2, v2...

> +    }
> +
> +
> +	report("float_to_fixed24");
> +}
> +
> +void checkasm_check_ac3dsp(void)
> +{
> +	AC3DSPContext c;
> +	ff_ac3dsp_init(&c);
> +
> +	check_float_to_fixed24(&c);
> +}
> diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c
> index 708119e7c6..9502e372a1 100644
> --- a/tests/checkasm/checkasm.c
> +++ b/tests/checkasm/checkasm.c
> @@ -105,6 +105,9 @@ static const struct {
>      #if CONFIG_G722DSP
>          { "g722dsp", checkasm_check_g722dsp },
>      #endif
> +    #if CONFIG_AC3DSP
> +        { "ac3dsp", checkasm_check_ac3dsp },
> +    #endif
>      #if CONFIG_H264CHROMA
>          { "h264chroma", checkasm_check_h264chroma },
>      #endif
> diff --git a/tests/checkasm/checkasm.h b/tests/checkasm/checkasm.h
> index cfea868ff1..4c73589606 100644
> --- a/tests/checkasm/checkasm.h
> +++ b/tests/checkasm/checkasm.h
> @@ -96,6 +96,7 @@ void checkasm_check_vp8dsp(void);
>  void checkasm_check_vp9dsp(void);
>  void checkasm_check_videodsp(void);
>  void checkasm_check_vorbisdsp(void);
> +void checkasm_check_ac3dsp(void);
>  
>  struct CheckasmPerf;
>  
> -- 
> 2.43.0
> 


More information about the ffmpeg-devel mailing list