hwcontext_vulkan: fix VkImageToMemoryCopyEXT.sType
[ffmpeg.git] / tests / checkasm / takdsp.c
1 /*
2 * Copyright (c) 2023 Institute 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
39 static void test_decorrelate_ls(TAKDSPContext *s) {
40 declare_func(void, const int32_t *, int32_t *, int);
41
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]);
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
64 static void test_decorrelate_sr(TAKDSPContext *s) {
65 declare_func(void, int32_t *, const int32_t *, int);
66
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]);
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
89 static void test_decorrelate_sm(TAKDSPContext *s) {
90 declare_func(void, int32_t *, int32_t *, int);
91
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]);
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
117 static void test_decorrelate_sf(TAKDSPContext *s) {
118 declare_func(void, int32_t *, const int32_t *, int, int, int);
119
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]);
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
145 void checkasm_check_takdsp(void)
146 {
147 TAKDSPContext s = { 0 };
148 ff_takdsp_init(&s);
149
150 test_decorrelate_ls(&s);
151 test_decorrelate_sr(&s);
152 test_decorrelate_sm(&s);
153 test_decorrelate_sf(&s);
154 }