1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
|
/*
* Copyright (c) 2023-2024 Nuo Mi
* Copyright (c) 2023-2024 Wu Jianhua
*
* 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/vvc/ctu.h"
#include "libavcodec/vvc/data.h"
#include "libavcodec/vvc/dsp.h"
#include "libavutil/common.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mem_internal.h"
static const uint32_t pixel_mask[] = { 0xffffffff, 0x03ff03ff, 0x0fff0fff, 0x3fff3fff, 0xffffffff };
static const int sizes[] = { 2, 4, 8, 16, 32, 64, 128 };
#define SIZEOF_PIXEL ((bit_depth + 7) / 8)
#define PIXEL_STRIDE (MAX_CTU_SIZE * 2)
#define EXTRA_BEFORE 3
#define EXTRA_AFTER 4
#define SRC_EXTRA (EXTRA_BEFORE + EXTRA_AFTER) * 2
#define SRC_BUF_SIZE (PIXEL_STRIDE + SRC_EXTRA) * (PIXEL_STRIDE + SRC_EXTRA)
#define DST_BUF_SIZE (MAX_CTU_SIZE * MAX_CTU_SIZE * 2)
#define SRC_OFFSET ((PIXEL_STRIDE + EXTRA_BEFORE * 2) * EXTRA_BEFORE)
#define randomize_buffers(buf0, buf1, size, mask) \
do { \
int k; \
for (k = 0; k < size; k += 4 / sizeof(*buf0)) { \
uint32_t r = rnd() & mask; \
AV_WN32A(buf0 + k, r); \
AV_WN32A(buf1 + k, r); \
} \
} while (0)
#define randomize_pixels(buf0, buf1, size) \
do { \
uint32_t mask = pixel_mask[(bit_depth - 8) >> 1]; \
randomize_buffers(buf0, buf1, size, mask); \
} while (0)
#define randomize_avg_src(buf0, buf1, size) \
do { \
uint32_t mask = 0x3fff3fff; \
randomize_buffers(buf0, buf1, size, mask); \
} while (0)
static void check_put_vvc_luma(void)
{
LOCAL_ALIGNED_32(int16_t, dst0, [DST_BUF_SIZE / 2]);
LOCAL_ALIGNED_32(int16_t, dst1, [DST_BUF_SIZE / 2]);
LOCAL_ALIGNED_32(uint8_t, src0, [SRC_BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, src1, [SRC_BUF_SIZE]);
VVCDSPContext c;
declare_func(void, int16_t *dst, const uint8_t *src, const ptrdiff_t src_stride,
const int height, const int8_t *hf, const int8_t *vf, const int width);
for (int bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
randomize_pixels(src0, src1, SRC_BUF_SIZE);
ff_vvc_dsp_init(&c, bit_depth);
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
for (int h = 4; h <= MAX_CTU_SIZE; h *= 2) {
for (int w = 4; w <= MAX_CTU_SIZE; w *= 2) {
const int idx = av_log2(w) - 1;
const int mx = rnd() % 16;
const int my = rnd() % 16;
const int8_t *hf = ff_vvc_inter_luma_filters[rnd() % 3][mx];
const int8_t *vf = ff_vvc_inter_luma_filters[rnd() % 3][my];
const char *type;
switch ((j << 1) | i) {
case 0: type = "put_luma_pixels"; break; // 0 0
case 1: type = "put_luma_h"; break; // 0 1
case 2: type = "put_luma_v"; break; // 1 0
case 3: type = "put_luma_hv"; break; // 1 1
}
if (check_func(c.inter.put[LUMA][idx][j][i], "%s_%d_%dx%d", type, bit_depth, w, h)) {
memset(dst0, 0, DST_BUF_SIZE);
memset(dst1, 0, DST_BUF_SIZE);
call_ref(dst0, src0 + SRC_OFFSET, PIXEL_STRIDE, h, hf, vf, w);
call_new(dst1, src1 + SRC_OFFSET, PIXEL_STRIDE, h, hf, vf, w);
if (memcmp(dst0, dst1, DST_BUF_SIZE))
fail();
if (w == h)
bench_new(dst1, src1 + SRC_OFFSET, PIXEL_STRIDE, h, hf, vf, w);
}
}
}
}
}
}
report("put_luma");
}
static void check_put_vvc_luma_uni(void)
{
LOCAL_ALIGNED_32(uint8_t, dst0, [DST_BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, dst1, [DST_BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, src0, [SRC_BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, src1, [SRC_BUF_SIZE]);
VVCDSPContext c;
declare_func(void, uint8_t *dst, ptrdiff_t dststride,
const uint8_t *src, ptrdiff_t srcstride, int height,
const int8_t *hf, const int8_t *vf, int width);
for (int bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
ff_vvc_dsp_init(&c, bit_depth);
randomize_pixels(src0, src1, SRC_BUF_SIZE);
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
for (int h = 4; h <= MAX_CTU_SIZE; h *= 2) {
for (int w = 4; w <= MAX_CTU_SIZE; w *= 2) {
const int idx = av_log2(w) - 1;
const int mx = rnd() % VVC_INTER_LUMA_FACTS;
const int my = rnd() % VVC_INTER_LUMA_FACTS;
const int8_t *hf = ff_vvc_inter_luma_filters[rnd() % VVC_INTER_LUMA_FILTER_TYPES][mx];
const int8_t *vf = ff_vvc_inter_luma_filters[rnd() % VVC_INTER_LUMA_FILTER_TYPES][my];
const char *type;
switch ((j << 1) | i) {
case 0: type = "put_uni_pixels"; break; // 0 0
case 1: type = "put_uni_h"; break; // 0 1
case 2: type = "put_uni_v"; break; // 1 0
case 3: type = "put_uni_hv"; break; // 1 1
}
if (check_func(c.inter.put_uni[LUMA][idx][j][i], "%s_luma_%d_%dx%d", type, bit_depth, w, h)) {
memset(dst0, 0, DST_BUF_SIZE);
memset(dst1, 0, DST_BUF_SIZE);
call_ref(dst0, PIXEL_STRIDE, src0 + SRC_OFFSET, PIXEL_STRIDE, h, hf, vf, w);
call_new(dst1, PIXEL_STRIDE, src1 + SRC_OFFSET, PIXEL_STRIDE, h, hf, vf, w);
if (memcmp(dst0, dst1, DST_BUF_SIZE))
fail();
if (w == h)
bench_new(dst1, PIXEL_STRIDE, src1 + SRC_OFFSET, PIXEL_STRIDE, h, hf, vf, w);
}
}
}
}
}
}
report("put_uni_luma");
}
static void check_put_vvc_chroma(void)
{
LOCAL_ALIGNED_32(int16_t, dst0, [DST_BUF_SIZE / 2]);
LOCAL_ALIGNED_32(int16_t, dst1, [DST_BUF_SIZE / 2]);
LOCAL_ALIGNED_32(uint8_t, src0, [SRC_BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, src1, [SRC_BUF_SIZE]);
VVCDSPContext c;
declare_func(void, int16_t *dst, const uint8_t *src, const ptrdiff_t src_stride,
const int height, const int8_t *hf, const int8_t *vf, const int width);
for (int bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
randomize_pixels(src0, src1, SRC_BUF_SIZE);
ff_vvc_dsp_init(&c, bit_depth);
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
for (int h = 2; h <= MAX_CTU_SIZE; h *= 2) {
for (int w = 2; w <= MAX_CTU_SIZE; w *= 2) {
const int idx = av_log2(w) - 1;
const int mx = rnd() % VVC_INTER_CHROMA_FACTS;
const int my = rnd() % VVC_INTER_CHROMA_FACTS;
const int8_t *hf = ff_vvc_inter_chroma_filters[rnd() % VVC_INTER_CHROMA_FILTER_TYPES][mx];
const int8_t *vf = ff_vvc_inter_chroma_filters[rnd() % VVC_INTER_CHROMA_FILTER_TYPES][my];
const char *type;
switch ((j << 1) | i) {
case 0: type = "put_chroma_pixels"; break; // 0 0
case 1: type = "put_chroma_h"; break; // 0 1
case 2: type = "put_chroma_v"; break; // 1 0
case 3: type = "put_chroma_hv"; break; // 1 1
}
if (check_func(c.inter.put[CHROMA][idx][j][i], "%s_%d_%dx%d", type, bit_depth, w, h)) {
memset(dst0, 0, DST_BUF_SIZE);
memset(dst1, 0, DST_BUF_SIZE);
call_ref(dst0, src0 + SRC_OFFSET, PIXEL_STRIDE, h, hf, vf, w);
call_new(dst1, src1 + SRC_OFFSET, PIXEL_STRIDE, h, hf, vf, w);
if (memcmp(dst0, dst1, DST_BUF_SIZE))
fail();
if (w == h)
bench_new(dst1, src1 + SRC_OFFSET, PIXEL_STRIDE, h, hf, vf, w);
}
}
}
}
}
}
report("put_chroma");
}
static void check_put_vvc_chroma_uni(void)
{
LOCAL_ALIGNED_32(uint8_t, dst0, [DST_BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, dst1, [DST_BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, src0, [SRC_BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, src1, [SRC_BUF_SIZE]);
VVCDSPContext c;
declare_func(void, uint8_t *dst, ptrdiff_t dststride,
const uint8_t *src, ptrdiff_t srcstride, int height,
const int8_t *hf, const int8_t *vf, int width);
for (int bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
ff_vvc_dsp_init(&c, bit_depth);
randomize_pixels(src0, src1, SRC_BUF_SIZE);
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
for (int h = 4; h <= MAX_CTU_SIZE; h *= 2) {
for (int w = 4; w <= MAX_CTU_SIZE; w *= 2) {
const int idx = av_log2(w) - 1;
const int mx = rnd() % VVC_INTER_CHROMA_FACTS;
const int my = rnd() % VVC_INTER_CHROMA_FACTS;
const int8_t *hf = ff_vvc_inter_chroma_filters[rnd() % VVC_INTER_CHROMA_FILTER_TYPES][mx];
const int8_t *vf = ff_vvc_inter_chroma_filters[rnd() % VVC_INTER_CHROMA_FILTER_TYPES][my];
const char *type;
switch ((j << 1) | i) {
case 0: type = "put_uni_pixels"; break; // 0 0
case 1: type = "put_uni_h"; break; // 0 1
case 2: type = "put_uni_v"; break; // 1 0
case 3: type = "put_uni_hv"; break; // 1 1
}
if (check_func(c.inter.put_uni[CHROMA][idx][j][i], "%s_chroma_%d_%dx%d", type, bit_depth, w, h)) {
memset(dst0, 0, DST_BUF_SIZE);
memset(dst1, 0, DST_BUF_SIZE);
call_ref(dst0, PIXEL_STRIDE, src0 + SRC_OFFSET, PIXEL_STRIDE, h, hf, vf, w);
call_new(dst1, PIXEL_STRIDE, src1 + SRC_OFFSET, PIXEL_STRIDE, h, hf, vf, w);
if (memcmp(dst0, dst1, DST_BUF_SIZE))
fail();
if (w == h)
bench_new(dst1, PIXEL_STRIDE, src1 + SRC_OFFSET, PIXEL_STRIDE, h, hf, vf, w);
}
}
}
}
}
}
report("put_uni_chroma");
}
#define AVG_SRC_BUF_SIZE (MAX_CTU_SIZE * MAX_CTU_SIZE)
#define AVG_DST_BUF_SIZE (MAX_PB_SIZE * MAX_PB_SIZE * 2)
static void check_avg(void)
{
LOCAL_ALIGNED_32(int16_t, src00, [AVG_SRC_BUF_SIZE]);
LOCAL_ALIGNED_32(int16_t, src01, [AVG_SRC_BUF_SIZE]);
LOCAL_ALIGNED_32(int16_t, src10, [AVG_SRC_BUF_SIZE]);
LOCAL_ALIGNED_32(int16_t, src11, [AVG_SRC_BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, dst0, [AVG_DST_BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, dst1, [AVG_DST_BUF_SIZE]);
VVCDSPContext c;
for (int bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
randomize_avg_src((uint8_t*)src00, (uint8_t*)src10, AVG_SRC_BUF_SIZE * sizeof(int16_t));
randomize_avg_src((uint8_t*)src01, (uint8_t*)src11, AVG_SRC_BUF_SIZE * sizeof(int16_t));
ff_vvc_dsp_init(&c, bit_depth);
for (int h = 2; h <= MAX_CTU_SIZE; h *= 2) {
for (int w = 2; w <= MAX_CTU_SIZE; w *= 2) {
{
declare_func(void, uint8_t *dst, ptrdiff_t dst_stride,
const int16_t *src0, const int16_t *src1, int width, int height);
if (check_func(c.inter.avg, "avg_%d_%dx%d", bit_depth, w, h)) {
memset(dst0, 0, AVG_DST_BUF_SIZE);
memset(dst1, 0, AVG_DST_BUF_SIZE);
call_ref(dst0, MAX_CTU_SIZE * SIZEOF_PIXEL, src00, src01, w, h);
call_new(dst1, MAX_CTU_SIZE * SIZEOF_PIXEL, src10, src11, w, h);
if (memcmp(dst0, dst1, DST_BUF_SIZE))
fail();
if (w == h)
bench_new(dst0, MAX_CTU_SIZE * SIZEOF_PIXEL, src00, src01, w, h);
}
}
{
declare_func(void, uint8_t *dst, ptrdiff_t dst_stride,
const int16_t *src0, const int16_t *src1, int width, int height,
int denom, int w0, int w1, int o0, int o1);
{
const int denom = rnd() % 8;
const int w0 = rnd() % 256 - 128;
const int w1 = rnd() % 256 - 128;
const int o0 = rnd() % 256 - 128;
const int o1 = rnd() % 256 - 128;
if (check_func(c.inter.w_avg, "w_avg_%d_%dx%d", bit_depth, w, h)) {
memset(dst0, 0, AVG_DST_BUF_SIZE);
memset(dst1, 0, AVG_DST_BUF_SIZE);
call_ref(dst0, MAX_CTU_SIZE * SIZEOF_PIXEL, src00, src01, w, h, denom, w0, w1, o0, o1);
call_new(dst1, MAX_CTU_SIZE * SIZEOF_PIXEL, src10, src11, w, h, denom, w0, w1, o0, o1);
if (memcmp(dst0, dst1, DST_BUF_SIZE))
fail();
if (w == h)
bench_new(dst0, MAX_CTU_SIZE * SIZEOF_PIXEL, src00, src01, w, h, denom, w0, w1, o0, o1);
}
}
}
}
}
}
report("avg");
}
static void check_vvc_sad(void)
{
const int bit_depth = 10;
VVCDSPContext c;
LOCAL_ALIGNED_32(uint16_t, src0, [MAX_CTU_SIZE * MAX_CTU_SIZE * 4]);
LOCAL_ALIGNED_32(uint16_t, src1, [MAX_CTU_SIZE * MAX_CTU_SIZE * 4]);
declare_func(int, const int16_t *src0, const int16_t *src1, int dx, int dy, int block_w, int block_h);
ff_vvc_dsp_init(&c, bit_depth);
randomize_pixels(src0, src1, MAX_CTU_SIZE * MAX_CTU_SIZE * 4);
for (int h = 8; h <= 16; h *= 2) {
for (int w = 8; w <= 16; w *= 2) {
for(int offy = 0; offy <= 4; offy++) {
for(int offx = 0; offx <= 4; offx++) {
if (w * h < 128)
continue;
if (check_func(c.inter.sad, "sad_%dx%d", w, h)) {
int result0;
int result1;
result0 = call_ref(src0 + PIXEL_STRIDE * 2 + 2, src1 + PIXEL_STRIDE * 2 + 2, offx, offy, w, h);
result1 = call_new(src0 + PIXEL_STRIDE * 2 + 2, src1 + PIXEL_STRIDE * 2 + 2, offx, offy, w, h);
if (result1 != result0)
fail();
if(offx == 0 && offy == 0)
bench_new(src0 + PIXEL_STRIDE * 2 + 2, src1 + PIXEL_STRIDE * 2 + 2, offx, offy, w, h);
}
}
}
}
}
report("sad");
}
void checkasm_check_vvc_mc(void)
{
check_vvc_sad();
check_put_vvc_luma();
check_put_vvc_luma_uni();
check_put_vvc_chroma();
check_put_vvc_chroma_uni();
check_avg();
}
|