FFmpeg
idctdsp.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2022 Ben Avison
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 #include <string.h>
22 
23 #include "checkasm.h"
24 
25 #include "libavcodec/idctdsp.h"
26 
27 #include "libavutil/common.h"
28 #include "libavutil/internal.h"
29 #include "libavutil/intreadwrite.h"
30 #include "libavutil/mem_internal.h"
31 
32 #define IDCTDSP_TEST(func) { #func, offsetof(IDCTDSPContext, func) },
33 
34 typedef struct {
35  const char *name;
36  size_t offset;
37 } test;
38 
39 #define RANDOMIZE_BUFFER16(name, size) \
40  do { \
41  int i; \
42  for (i = 0; i < size; ++i) { \
43  uint16_t r = rnd() % 0x201 - 0x100; \
44  AV_WN16A(name##0 + i, r); \
45  AV_WN16A(name##1 + i, r); \
46  } \
47  } while (0)
48 
49 #define RANDOMIZE_BUFFER8(name, size) \
50  do { \
51  int i; \
52  for (i = 0; i < size; ++i) { \
53  uint8_t r = rnd(); \
54  name##0[i] = r; \
55  name##1[i] = r; \
56  } \
57  } while (0)
58 
59 static void check_add_put_clamped(void)
60 {
61  /* Source buffers are only as big as needed, since any over-read won't affect results */
62  LOCAL_ALIGNED_16(int16_t, src0, [64]);
63  LOCAL_ALIGNED_16(int16_t, src1, [64]);
64  /* Destination buffers have borders of one row above/below and 8 columns left/right to catch overflows */
65  LOCAL_ALIGNED_8(uint8_t, dst0, [10 * 24]);
66  LOCAL_ALIGNED_8(uint8_t, dst1, [10 * 24]);
67 
68  AVCodecContext avctx = { 0 };
70 
71  const test tests[] = {
72  IDCTDSP_TEST(add_pixels_clamped)
73  IDCTDSP_TEST(put_pixels_clamped)
74  IDCTDSP_TEST(put_signed_pixels_clamped)
75  };
76 
77  ff_idctdsp_init(&h, &avctx);
78 
79  for (size_t t = 0; t < FF_ARRAY_ELEMS(tests); ++t) {
80  void (*func)(const int16_t *, uint8_t * ptrdiff_t) = *(void **)((intptr_t) &h + tests[t].offset);
81  if (check_func(func, "idctdsp.%s", tests[t].name)) {
82  declare_func(void, const int16_t *, uint8_t *, ptrdiff_t);
84  RANDOMIZE_BUFFER8(dst, 10 * 24);
85  call_ref(src0, dst0 + 24 + 8, 24);
86  call_new(src1, dst1 + 24 + 8, 24);
87  if (memcmp(dst0, dst1, 10 * 24))
88  fail();
89  bench_new(src1, dst1 + 24 + 8, 24);
90  }
91  }
92 }
93 
95 {
97  report("idctdsp");
98 }
func
int(* func)(AVBPrint *dst, const char *in, const char *arg)
Definition: jacosubdec.c:68
name
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
mem_internal.h
src1
const pixel * src1
Definition: h264pred_template.c:421
check_func
#define check_func(func,...)
Definition: checkasm.h:125
test
Definition: idctdsp.c:34
call_ref
#define call_ref(...)
Definition: checkasm.h:140
ff_idctdsp_init
av_cold void ff_idctdsp_init(IDCTDSPContext *c, AVCodecContext *avctx)
Definition: idctdsp.c:228
fail
#define fail()
Definition: checkasm.h:134
checkasm.h
check_add_put_clamped
static void check_add_put_clamped(void)
Definition: idctdsp.c:59
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
intreadwrite.h
LOCAL_ALIGNED_16
#define LOCAL_ALIGNED_16(t, v,...)
Definition: mem_internal.h:129
LOCAL_ALIGNED_8
#define LOCAL_ALIGNED_8(t, v,...)
Definition: mem_internal.h:123
call_new
#define call_new(...)
Definition: checkasm.h:222
test::name
const char * name
Definition: idctdsp.c:35
RANDOMIZE_BUFFER16
#define RANDOMIZE_BUFFER16(name, size)
Definition: idctdsp.c:39
offset
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Definition: writing_filters.txt:86
IDCTDSP_TEST
#define IDCTDSP_TEST(func)
Definition: idctdsp.c:32
tests
const TestCase tests[]
Definition: fifo_muxer.c:242
report
#define report
Definition: checkasm.h:137
bench_new
#define bench_new(...)
Definition: checkasm.h:287
internal.h
test::offset
size_t offset
Definition: idctdsp.c:36
common.h
idctdsp.h
checkasm_check_idctdsp
void checkasm_check_idctdsp(void)
Definition: idctdsp.c:94
IDCTDSPContext
Definition: idctdsp.h:44
AVCodecContext
main external API structure.
Definition: avcodec.h:426
test
static int test(void)
Definition: dnn-layer-dense.c:28
src0
const pixel *const src0
Definition: h264pred_template.c:420
declare_func
#define declare_func(ret,...)
Definition: checkasm.h:129
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
h
h
Definition: vp9dsp_template.c:2038
RANDOMIZE_BUFFER8
#define RANDOMIZE_BUFFER8(name, size)
Definition: idctdsp.c:49