diff mbox series

[FFmpeg-devel,v3,1/2] checkasm: add test for fdct

Message ID 20240417180138.21864-2-ramiro.polla@gmail.com
State New
Headers show
Series lavc/aarch64/fdct: add neon-optimized fdct for aarch64 | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Ramiro Polla April 17, 2024, 6:01 p.m. UTC
Reviewed-by: Martin Storsjö <martin@martin.st>
---
 tests/checkasm/Makefile   |  1 +
 tests/checkasm/checkasm.c |  3 ++
 tests/checkasm/checkasm.h |  1 +
 tests/checkasm/fdctdsp.c  | 68 +++++++++++++++++++++++++++++++++++++++
 tests/fate/checkasm.mak   |  1 +
 5 files changed, 74 insertions(+)
 create mode 100644 tests/checkasm/fdctdsp.c

Comments

Rémi Denis-Courmont May 2, 2024, 6:04 p.m. UTC | #1
Le keskiviikkona 17. huhtikuuta 2024, 21.01.37 EEST Ramiro Polla a écrit :
> Reviewed-by: Martin Storsjö <martin@martin.st>
> ---
>  tests/checkasm/Makefile   |  1 +
>  tests/checkasm/checkasm.c |  3 ++
>  tests/checkasm/checkasm.h |  1 +
>  tests/checkasm/fdctdsp.c  | 68 +++++++++++++++++++++++++++++++++++++++
>  tests/fate/checkasm.mak   |  1 +
>  5 files changed, 74 insertions(+)
>  create mode 100644 tests/checkasm/fdctdsp.c
> 
> diff --git a/tests/checkasm/Makefile b/tests/checkasm/Makefile
> index 2673e1d098..70a6120c70 100644
> --- a/tests/checkasm/Makefile
> +++ b/tests/checkasm/Makefile
> @@ -4,6 +4,7 @@ AVCODECOBJS-$(CONFIG_AC3DSP)            += ac3dsp.o
>  AVCODECOBJS-$(CONFIG_AUDIODSP)          += audiodsp.o
>  AVCODECOBJS-$(CONFIG_BLOCKDSP)          += blockdsp.o
>  AVCODECOBJS-$(CONFIG_BSWAPDSP)          += bswapdsp.o
> +AVCODECOBJS-$(CONFIG_FDCTDSP)           += fdctdsp.o
>  AVCODECOBJS-$(CONFIG_FMTCONVERT)        += fmtconvert.o
>  AVCODECOBJS-$(CONFIG_G722DSP)           += g722dsp.o
>  AVCODECOBJS-$(CONFIG_H264CHROMA)        += h264chroma.o
> diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c
> index 8be6cb0f55..92c3a30ad3 100644
> --- a/tests/checkasm/checkasm.c
> +++ b/tests/checkasm/checkasm.c
> @@ -106,6 +106,9 @@ static const struct {
>      #if CONFIG_EXR_DECODER
>          { "exrdsp", checkasm_check_exrdsp },
>      #endif
> +    #if CONFIG_FDCTDSP
> +        { "fdctdsp", checkasm_check_fdctdsp },
> +    #endif
>      #if CONFIG_FLAC_DECODER
>          { "flacdsp", checkasm_check_flacdsp },
>      #endif
> diff --git a/tests/checkasm/checkasm.h b/tests/checkasm/checkasm.h
> index f90920dee7..d3e8f9a37a 100644
> --- a/tests/checkasm/checkasm.h
> +++ b/tests/checkasm/checkasm.h
> @@ -85,6 +85,7 @@ void checkasm_check_blockdsp(void);
>  void checkasm_check_bswapdsp(void);
>  void checkasm_check_colorspace(void);
>  void checkasm_check_exrdsp(void);
> +void checkasm_check_fdctdsp(void);
>  void checkasm_check_fixed_dsp(void);
>  void checkasm_check_flacdsp(void);
>  void checkasm_check_float_dsp(void);
> diff --git a/tests/checkasm/fdctdsp.c b/tests/checkasm/fdctdsp.c
> new file mode 100644
> index 0000000000..68a9b5e435
> --- /dev/null
> +++ b/tests/checkasm/fdctdsp.c
> @@ -0,0 +1,68 @@
> +/*
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 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 General Public License for more details.
> + *
> + * You should have received a copy of the GNU 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 <string.h>
> +
> +#include "checkasm.h"
> +
> +#include "libavcodec/avcodec.h"
> +#include "libavcodec/fdctdsp.h"
> +
> +#include "libavutil/common.h"
> +#include "libavutil/internal.h"
> +#include "libavutil/mem_internal.h"
> +
> +static int int16_cmp_off_by_n(const int16_t *ref, const int16_t *test,
> size_t n, int accuracy) +{
> +    for (size_t i = 0; i < n; i++) {
> +        if (abs(ref[i] - test[i]) > accuracy)
> +            return 1;
> +    }
> +    return 0;
> +}
> +
> +static void check_fdct(void)
> +{
> +    LOCAL_ALIGNED_16(int16_t, block0, [64]);
> +    LOCAL_ALIGNED_16(int16_t, block1, [64]);
> +
> +    AVCodecContext avctx = { 0 };

AFAICT, that is not a legal context for ff_fdctdst_init(), which expect 
bits_per_raw_sample to be one of 8, 9 or 10. It would also be good manners to 
initialise dct_algo.

> +    FDCTDSPContext h;
> +
> +    ff_fdctdsp_init(&h, &avctx);
> +
> +    if (check_func(h.fdct, "fdct")) {
> +        declare_func(void, int16_t *);
> +        for (int i = 0; i < 64; i++) {
> +            uint8_t r = rnd();
> +            block0[i] = r;
> +            block1[i] = r;
> +        }
> +        call_ref(block0);
> +        call_new(block1);
> +        if (int16_cmp_off_by_n(block0, block1, 64, 2))
> +            fail();
> +        bench_new(block1);
> +    }
> +}
> +
> +void checkasm_check_fdctdsp(void)
> +{
> +    check_fdct();
> +    report("fdctdsp");
> +}
> diff --git a/tests/fate/checkasm.mak b/tests/fate/checkasm.mak
> index 3b5b867a97..10a42f2f9d 100644
> --- a/tests/fate/checkasm.mak
> +++ b/tests/fate/checkasm.mak
> @@ -8,6 +8,7 @@ FATE_CHECKASM = fate-checkasm-aacencdsp                     
>            \ fate-checkasm-blockdsp                                  \
> fate-checkasm-bswapdsp                                  \
> fate-checkasm-exrdsp                                    \ +               
> fate-checkasm-fdctdsp                                   \
> fate-checkasm-fixed_dsp                                 \
> fate-checkasm-flacdsp                                   \
> fate-checkasm-float_dsp                                 \
Ramiro Polla May 6, 2024, 5:18 p.m. UTC | #2
On Thu, May 2, 2024 at 8:05 PM Rémi Denis-Courmont <remi@remlab.net> wrote:
> Le keskiviikkona 17. huhtikuuta 2024, 21.01.37 EEST Ramiro Polla a écrit :
[...]
> > +static void check_fdct(void)
> > +{
> > +    LOCAL_ALIGNED_16(int16_t, block0, [64]);
> > +    LOCAL_ALIGNED_16(int16_t, block1, [64]);
> > +
> > +    AVCodecContext avctx = { 0 };
>
> AFAICT, that is not a legal context for ff_fdctdst_init(), which expect
> bits_per_raw_sample to be one of 8, 9 or 10. It would also be good manners to
> initialise dct_algo.

Thanks for spotting it. New patch coming up in a while.

I'll send a similar patch to fix checkasm/idctdsp after this is merged.
Rémi Denis-Courmont May 6, 2024, 5:49 p.m. UTC | #3
Le maanantaina 6. toukokuuta 2024, 20.18.11 EEST Ramiro Polla a écrit :
> I'll send a similar patch to fix checkasm/idctdsp after this is merged.

The idctdsp test does not actually test the iDCT, but only the trivial-ish 
add/put helpers, so it does not care about the context. You're welcome to fix 
it anyway of course.
James Almer May 13, 2024, 4:49 p.m. UTC | #4
On 5/6/2024 2:49 PM, Rémi Denis-Courmont wrote:
> Le maanantaina 6. toukokuuta 2024, 20.18.11 EEST Ramiro Polla a écrit :
>> I'll send a similar patch to fix checkasm/idctdsp after this is merged.
> 
> The idctdsp test does not actually test the iDCT, but only the trivial-ish
> add/put helpers, so it does not care about the context. You're welcome to fix
> it anyway of course.

I personally find it ugly how we're storing a whole AVCodecContext on 
stack in these tests just to pass two ints to an init function.
Maybe we can make said values be input parameters for these instead of a 
pointer to avctx.
Ramiro Polla May 13, 2024, 7:14 p.m. UTC | #5
On Mon, May 13, 2024 at 6:49 PM James Almer <jamrial@gmail.com> wrote:
> On 5/6/2024 2:49 PM, Rémi Denis-Courmont wrote:
> > Le maanantaina 6. toukokuuta 2024, 20.18.11 EEST Ramiro Polla a écrit :
> >> I'll send a similar patch to fix checkasm/idctdsp after this is merged.
> >
> > The idctdsp test does not actually test the iDCT, but only the trivial-ish
> > add/put helpers, so it does not care about the context. You're welcome to fix
> > it anyway of course.
>
> I personally find it ugly how we're storing a whole AVCodecContext on
> stack in these tests just to pass two ints to an init function.
> Maybe we can make said values be input parameters for these instead of a
> pointer to avctx.

It could make sense for fdct, but for idct we need a few more
parameters (bits_per_raw_sample, codec_id, flags, idct_algo, lowres).
That would make the function calls much longer, and in that case I'd
prefer just keeping AVCodecContext.
Or having an input parameter structure for each *dsp context, but that
seems a bit overkill.
diff mbox series

Patch

diff --git a/tests/checkasm/Makefile b/tests/checkasm/Makefile
index 2673e1d098..70a6120c70 100644
--- a/tests/checkasm/Makefile
+++ b/tests/checkasm/Makefile
@@ -4,6 +4,7 @@  AVCODECOBJS-$(CONFIG_AC3DSP)            += ac3dsp.o
 AVCODECOBJS-$(CONFIG_AUDIODSP)          += audiodsp.o
 AVCODECOBJS-$(CONFIG_BLOCKDSP)          += blockdsp.o
 AVCODECOBJS-$(CONFIG_BSWAPDSP)          += bswapdsp.o
+AVCODECOBJS-$(CONFIG_FDCTDSP)           += fdctdsp.o
 AVCODECOBJS-$(CONFIG_FMTCONVERT)        += fmtconvert.o
 AVCODECOBJS-$(CONFIG_G722DSP)           += g722dsp.o
 AVCODECOBJS-$(CONFIG_H264CHROMA)        += h264chroma.o
diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c
index 8be6cb0f55..92c3a30ad3 100644
--- a/tests/checkasm/checkasm.c
+++ b/tests/checkasm/checkasm.c
@@ -106,6 +106,9 @@  static const struct {
     #if CONFIG_EXR_DECODER
         { "exrdsp", checkasm_check_exrdsp },
     #endif
+    #if CONFIG_FDCTDSP
+        { "fdctdsp", checkasm_check_fdctdsp },
+    #endif
     #if CONFIG_FLAC_DECODER
         { "flacdsp", checkasm_check_flacdsp },
     #endif
diff --git a/tests/checkasm/checkasm.h b/tests/checkasm/checkasm.h
index f90920dee7..d3e8f9a37a 100644
--- a/tests/checkasm/checkasm.h
+++ b/tests/checkasm/checkasm.h
@@ -85,6 +85,7 @@  void checkasm_check_blockdsp(void);
 void checkasm_check_bswapdsp(void);
 void checkasm_check_colorspace(void);
 void checkasm_check_exrdsp(void);
+void checkasm_check_fdctdsp(void);
 void checkasm_check_fixed_dsp(void);
 void checkasm_check_flacdsp(void);
 void checkasm_check_float_dsp(void);
diff --git a/tests/checkasm/fdctdsp.c b/tests/checkasm/fdctdsp.c
new file mode 100644
index 0000000000..68a9b5e435
--- /dev/null
+++ b/tests/checkasm/fdctdsp.c
@@ -0,0 +1,68 @@ 
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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 <string.h>
+
+#include "checkasm.h"
+
+#include "libavcodec/avcodec.h"
+#include "libavcodec/fdctdsp.h"
+
+#include "libavutil/common.h"
+#include "libavutil/internal.h"
+#include "libavutil/mem_internal.h"
+
+static int int16_cmp_off_by_n(const int16_t *ref, const int16_t *test, size_t n, int accuracy)
+{
+    for (size_t i = 0; i < n; i++) {
+        if (abs(ref[i] - test[i]) > accuracy)
+            return 1;
+    }
+    return 0;
+}
+
+static void check_fdct(void)
+{
+    LOCAL_ALIGNED_16(int16_t, block0, [64]);
+    LOCAL_ALIGNED_16(int16_t, block1, [64]);
+
+    AVCodecContext avctx = { 0 };
+    FDCTDSPContext h;
+
+    ff_fdctdsp_init(&h, &avctx);
+
+    if (check_func(h.fdct, "fdct")) {
+        declare_func(void, int16_t *);
+        for (int i = 0; i < 64; i++) {
+            uint8_t r = rnd();
+            block0[i] = r;
+            block1[i] = r;
+        }
+        call_ref(block0);
+        call_new(block1);
+        if (int16_cmp_off_by_n(block0, block1, 64, 2))
+            fail();
+        bench_new(block1);
+    }
+}
+
+void checkasm_check_fdctdsp(void)
+{
+    check_fdct();
+    report("fdctdsp");
+}
diff --git a/tests/fate/checkasm.mak b/tests/fate/checkasm.mak
index 3b5b867a97..10a42f2f9d 100644
--- a/tests/fate/checkasm.mak
+++ b/tests/fate/checkasm.mak
@@ -8,6 +8,7 @@  FATE_CHECKASM = fate-checkasm-aacencdsp                                 \
                 fate-checkasm-blockdsp                                  \
                 fate-checkasm-bswapdsp                                  \
                 fate-checkasm-exrdsp                                    \
+                fate-checkasm-fdctdsp                                   \
                 fate-checkasm-fixed_dsp                                 \
                 fate-checkasm-flacdsp                                   \
                 fate-checkasm-float_dsp                                 \