2 * Copyright (c) 2023 Institute of Software Chinese Academy of Sciences (ISCAS).
4 * This file is part of FFmpeg.
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.
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.
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.
23 #include "libavutil/mem.h"
24 #include "libavutil/mem_internal.h"
26 #include "libavcodec/takdsp.h"
27 #include "libavcodec/mathops.h"
31 #define randomize(buf, len) \
33 for (int i = 0; i < len; i++) \
39 static void test_decorrelate_ls(TAKDSPContext
*s
) {
40 declare_func(void, const int32_t *, int32_t *, int);
42 if (check_func(s
->decorrelate_ls
, "decorrelate_ls")) {
43 LOCAL_ALIGNED_32(int32_t, p1
, [BUF_SIZE
]);
44 LOCAL_ALIGNED_32(int32_t, p2
, [BUF_SIZE
]);
45 LOCAL_ALIGNED_32(int32_t, p2_2
, [BUF_SIZE
]);
47 randomize(p1
, BUF_SIZE
);
48 randomize(p2
, BUF_SIZE
);
49 memcpy(p2_2
, p2
, BUF_SIZE
* sizeof(*p2
));
51 call_ref(p1
, p2
, BUF_SIZE
);
52 call_new(p1
, p2_2
, BUF_SIZE
);
54 if (memcmp(p2
, p2_2
, BUF_SIZE
* sizeof(*p2
)) != 0) {
58 bench_new(p1
, p2
, BUF_SIZE
);
61 report("decorrelate_ls");
64 static void test_decorrelate_sr(TAKDSPContext
*s
) {
65 declare_func(void, int32_t *, const int32_t *, int);
67 if (check_func(s
->decorrelate_sr
, "decorrelate_sr")) {
68 LOCAL_ALIGNED_32(int32_t, p1
, [BUF_SIZE
]);
69 LOCAL_ALIGNED_32(int32_t, p1_2
, [BUF_SIZE
]);
70 LOCAL_ALIGNED_32(int32_t, p2
, [BUF_SIZE
]);
72 randomize(p1
, BUF_SIZE
);
73 memcpy(p1_2
, p1
, BUF_SIZE
* sizeof(*p1
));
74 randomize(p2
, BUF_SIZE
);
76 call_ref(p1
, p2
, BUF_SIZE
);
77 call_new(p1_2
, p2
, BUF_SIZE
);
79 if (memcmp(p1
, p1_2
, BUF_SIZE
* sizeof(*p1
)) != 0) {
83 bench_new(p1
, p2
, BUF_SIZE
);
86 report("decorrelate_sr");
89 static void test_decorrelate_sm(TAKDSPContext
*s
) {
90 declare_func(void, int32_t *, int32_t *, int);
92 if (check_func(s
->decorrelate_sm
, "decorrelate_sm")) {
93 LOCAL_ALIGNED_32(int32_t, p1
, [BUF_SIZE
]);
94 LOCAL_ALIGNED_32(int32_t, p1_2
, [BUF_SIZE
]);
95 LOCAL_ALIGNED_32(int32_t, p2
, [BUF_SIZE
]);
96 LOCAL_ALIGNED_32(int32_t, p2_2
, [BUF_SIZE
]);
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
));
103 call_ref(p1
, p2
, BUF_SIZE
);
104 call_new(p1_2
, p2_2
, BUF_SIZE
);
106 if (memcmp(p1
, p1_2
, BUF_SIZE
* sizeof(*p1
)) != 0 ||
107 memcmp(p2
, p2_2
, BUF_SIZE
* sizeof(*p2
)) != 0) {
111 bench_new(p1
, p2
, BUF_SIZE
);
114 report("decorrelate_sm");
117 static void test_decorrelate_sf(TAKDSPContext
*s
) {
118 declare_func(void, int32_t *, const int32_t *, int, int, int);
120 if (check_func(s
->decorrelate_sf
, "decorrelate_sf")) {
121 LOCAL_ALIGNED_32(int32_t, p1
, [BUF_SIZE
]);
122 LOCAL_ALIGNED_32(int32_t, p1_2
, [BUF_SIZE
]);
123 LOCAL_ALIGNED_32(int32_t, p2
, [BUF_SIZE
]);
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);
132 call_ref(p1
, p2
, BUF_SIZE
, dshift
, dfactor
);
133 call_new(p1_2
, p2
, BUF_SIZE
, dshift
, dfactor
);
135 if (memcmp(p1
, p1_2
, BUF_SIZE
* sizeof(*p1
)) != 0) {
139 bench_new(p1
, p2
, BUF_SIZE
, dshift
, dfactor
);
142 report("decorrelate_sf");
145 void checkasm_check_takdsp(void)
147 TAKDSPContext s
= { 0 };
150 test_decorrelate_ls(&s
);
151 test_decorrelate_sr(&s
);
152 test_decorrelate_sm(&s
);
153 test_decorrelate_sf(&s
);