FFmpeg
takdsp.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023 Institue of Software Chinese Academy of Sciences (ISCAS).
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 "libavutil/mem.h"
24 #include "libavutil/mem_internal.h"
25 
26 #include "libavcodec/takdsp.h"
27 #include "libavcodec/mathops.h"
28 
29 #include "checkasm.h"
30 
31 #define randomize(buf, len) \
32  do { \
33  for (int i = 0; i < len; i++) \
34  buf[i] = rnd(); \
35  } while (0)
36 
37 #define BUF_SIZE 1024
38 
40  declare_func(void, const int32_t *, int32_t *, int);
41 
42  if (check_func(s->decorrelate_ls, "decorrelate_ls")) {
46 
47  randomize(p1, BUF_SIZE);
48  randomize(p2, BUF_SIZE);
49  memcpy(p2_2, p2, BUF_SIZE * sizeof(*p2));
50 
51  call_ref(p1, p2, BUF_SIZE);
52  call_new(p1, p2_2, BUF_SIZE);
53 
54  if (memcmp(p2, p2_2, BUF_SIZE * sizeof(*p2)) != 0) {
55  fail();
56  }
57 
58  bench_new(p1, p2, BUF_SIZE);
59  }
60 
61  report("decorrelate_ls");
62 }
63 
65  declare_func(void, int32_t *, const int32_t *, int);
66 
67  if (check_func(s->decorrelate_sr, "decorrelate_sr")) {
71 
72  randomize(p1, BUF_SIZE);
73  memcpy(p1_2, p1, BUF_SIZE * sizeof(*p1));
74  randomize(p2, BUF_SIZE);
75 
76  call_ref(p1, p2, BUF_SIZE);
77  call_new(p1_2, p2, BUF_SIZE);
78 
79  if (memcmp(p1, p1_2, BUF_SIZE * sizeof(*p1)) != 0) {
80  fail();
81  }
82 
83  bench_new(p1, p2, BUF_SIZE);
84  }
85 
86  report("decorrelate_sr");
87 }
88 
90  declare_func(void, int32_t *, int32_t *, int);
91 
92  if (check_func(s->decorrelate_sm, "decorrelate_sm")) {
97 
98  randomize(p1, BUF_SIZE);
99  memcpy(p1_2, p1, BUF_SIZE * sizeof(*p1));
100  randomize(p2, BUF_SIZE);
101  memcpy(p2_2, p2, BUF_SIZE * sizeof(*p2));
102 
103  call_ref(p1, p2, BUF_SIZE);
104  call_new(p1_2, p2_2, BUF_SIZE);
105 
106  if (memcmp(p1, p1_2, BUF_SIZE * sizeof(*p1)) != 0 ||
107  memcmp(p2, p2_2, BUF_SIZE * sizeof(*p2)) != 0) {
108  fail();
109  }
110 
111  bench_new(p1, p2, BUF_SIZE);
112  }
113 
114  report("decorrelate_sm");
115 }
116 
118  declare_func(void, int32_t *, const int32_t *, int, int, int);
119 
120  if (check_func(s->decorrelate_sf, "decorrelate_sf")) {
124  int dshift, dfactor;
125 
126  randomize(p1, BUF_SIZE);
127  memcpy(p1_2, p1, BUF_SIZE * sizeof(*p1));
128  randomize(p2, BUF_SIZE);
129  dshift = (rnd() & 0xF) + 1;
130  dfactor = sign_extend(rnd(), 10);
131 
132  call_ref(p1, p2, BUF_SIZE, dshift, dfactor);
133  call_new(p1_2, p2, BUF_SIZE, dshift, dfactor);
134 
135  if (memcmp(p1, p1_2, BUF_SIZE * sizeof(*p1)) != 0) {
136  fail();
137  }
138 
139  bench_new(p1, p2, BUF_SIZE, dshift, dfactor);
140  }
141 
142  report("decorrelate_sf");
143 }
144 
146 {
147  TAKDSPContext s = { 0 };
148  ff_takdsp_init(&s);
149 
154 }
test_decorrelate_ls
static void test_decorrelate_ls(TAKDSPContext *s)
Definition: takdsp.c:39
mem_internal.h
check_func
#define check_func(func,...)
Definition: checkasm.h:174
TAKDSPContext
Definition: takdsp.h:24
call_ref
#define call_ref(...)
Definition: checkasm.h:189
ff_takdsp_init
av_cold void ff_takdsp_init(TAKDSPContext *c)
Definition: takdsp.c:73
fail
#define fail()
Definition: checkasm.h:183
checkasm.h
rnd
#define rnd()
Definition: checkasm.h:167
test_decorrelate_sf
static void test_decorrelate_sf(TAKDSPContext *s)
Definition: takdsp.c:117
s
#define s(width, name)
Definition: cbs_vp9.c:198
randomize
#define randomize(buf, len)
Definition: takdsp.c:31
call_new
#define call_new(...)
Definition: checkasm.h:292
LOCAL_ALIGNED_32
#define LOCAL_ALIGNED_32(t, v,...)
Definition: mem_internal.h:156
mathops.h
takdsp.h
report
#define report
Definition: checkasm.h:186
bench_new
#define bench_new(...)
Definition: checkasm.h:363
test_decorrelate_sr
static void test_decorrelate_sr(TAKDSPContext *s)
Definition: takdsp.c:64
checkasm_check_takdsp
void checkasm_check_takdsp(void)
Definition: takdsp.c:145
sign_extend
static av_const int sign_extend(int val, unsigned bits)
Definition: mathops.h:133
test_decorrelate_sm
static void test_decorrelate_sm(TAKDSPContext *s)
Definition: takdsp.c:89
BUF_SIZE
#define BUF_SIZE
Definition: takdsp.c:37
mem.h
declare_func
#define declare_func(ret,...)
Definition: checkasm.h:178
int32_t
int32_t
Definition: audioconvert.c:56