FFmpeg
Loading...
Searching...
No Matches
cavsdsp.c
Go to the documentation of this file.
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19#include <assert.h>
20#include <stddef.h>
21#include <string.h>
22
23#include "checkasm.h"
25#include "libavutil/macros.h"
27#include "libavcodec/cavsdsp.h"
28#include "libavcodec/idctdsp.h"
29
30
31enum {
32// DECLARE_ALIGNED can't handle enum constants.
33#define MAX_BLOCK_SIZE 16
35 /// BUF_SIZE is bigger than necessary in order to test strides > block width.
37 /**
38 * The qpel interpolation code accesses two lines above and three lines
39 * below the actual src block; it also accesses two pixels to the left
40 * and three to the right.
41 * The input is not subject to alignment requirements; making the input buffer
42 * bigger (by MAX_BLOCK_SIZE - 1) allows us to use a random misalignment.
43 */
45};
46
47#define randomize_buffers(buf0, buf1) \
48 do { \
49 static_assert(sizeof(buf0) == sizeof(buf1), "Incompatible buffers"); \
50 static_assert(!(sizeof(buf0) % 4), "Tail handling needed"); \
51 static_assert(sizeof(buf0[0]) == 1 && sizeof(buf1[0]) == 1, \
52 "Pointer arithmetic needs to be adapted"); \
53 for (size_t k = 0; k < sizeof(buf0); k += 4) { \
54 uint32_t r = rnd(); \
55 AV_WN32A(buf0 + k, r); \
56 AV_WN32A(buf1 + k, r); \
57 } \
58 } while (0)
59
60
61static void check_cavs_qpeldsp(void)
62{
65 DECLARE_ALIGNED(MAX_BLOCK_SIZE, uint8_t, dstbuf0)[BUF_SIZE];
66 DECLARE_ALIGNED(MAX_BLOCK_SIZE, uint8_t, dstbuf1)[BUF_SIZE];
67 CAVSDSPContext cavsdsp;
68 static const struct {
69 const char *name;
70 size_t offset;
71 } tests[] = {
72#define TEST(NAME) { .name = #NAME, .offset = offsetof(CAVSDSPContext, NAME) }
73 TEST(put_cavs_qpel_pixels_tab),
74 TEST(avg_cavs_qpel_pixels_tab),
75 };
76 declare_func(void, uint8_t *dst, const uint8_t *src, ptrdiff_t stride);
77
78 ff_cavsdsp_init(&cavsdsp);
79
80 for (size_t i = 0; i < FF_ARRAY_ELEMS(tests); ++i) {
81 qpel_mc_func (*func_tab)[16] = (qpel_mc_func (*)[16])((char*)&cavsdsp + tests[i].offset);
82 for (unsigned j = 0; j < 2; ++j) {
83 const unsigned blocksize = MAX_BLOCK_SIZE >> j;
84
85 for (unsigned dxy = 0; dxy < 16; ++dxy) {
86 if (check_func(func_tab[j][dxy], "%s[%u][%u]", tests[i].name, j, dxy)) {
87 // Don't always use output that is 16-aligned.
88 size_t dst_offset = (rnd() % (MAX_BLOCK_SIZE / blocksize)) * blocksize;
89 ptrdiff_t stride = (rnd() % (MAX_STRIDE / blocksize) + 1) * blocksize;
90 size_t src_offset = 2 + 2 * stride + rnd() % MAX_BLOCK_SIZE;
91 const uint8_t *src0 = srcbuf0 + src_offset, *src1 = srcbuf1 + src_offset;
92 uint8_t *dst0 = dstbuf0 + dst_offset, *dst1 = dstbuf1 + dst_offset;
93
94 if (rnd() & 1) {
95 // Flip stride.
96 dst1 += (blocksize - 1) * stride;
97 dst0 += (blocksize - 1) * stride;
98 // We need two lines above src and three lines below the block,
99 // hence blocksize * stride.
100 src0 += blocksize * stride;
101 src1 += blocksize * stride;
102 stride = -stride;
103 }
104
105 randomize_buffers(srcbuf0, srcbuf1);
106 randomize_buffers(dstbuf0, dstbuf1);
107 call_ref(dst0, src0, stride);
108 call_new(dst1, src1, stride);
109 if (memcmp(srcbuf0, srcbuf1, sizeof(srcbuf0)) || memcmp(dstbuf0, dstbuf1, sizeof(dstbuf0)))
110 fail();
111 bench_new(dst0, src0, stride);
112 }
113 }
114 }
115 }
116}
117
118static void check_cavs_idct8_add(void)
119{
120 DECLARE_ALIGNED(16, int16_t, block0)[64];
121 DECLARE_ALIGNED(16, int16_t, block1)[64];
122 DECLARE_ALIGNED(16, uint8_t, dstbuf0)[8 * 16];
123 DECLARE_ALIGNED(16, uint8_t, dstbuf1)[8 * 16];
124 uint8_t permutation[64];
125 CAVSDSPContext cavsdsp;
126 declare_func(void, uint8_t *dst, int16_t *block, ptrdiff_t stride);
127
128 ff_cavsdsp_init(&cavsdsp);
129 ff_init_scantable_permutation(permutation, cavsdsp.idct_perm);
130
131 if (check_func(cavsdsp.cavs_idct8_add, "cavs_idct8_add")) {
132 for (int iter = 0; iter < 64; iter++) {
133 int n = 1 + rnd() % 64;
134
135 memset(block0, 0, sizeof(block0));
136 /* magnitudes from the whole int16_t range down to single digits */
137 for (int k = 0; k < n; k++)
138 block0[rnd() % 64] = (int16_t)rnd() >> (rnd() % 16);
139 /* the reference is the C version, which takes natural order */
140 for (int i = 0; i < 64; i++)
141 block1[permutation[i]] = block0[i];
142
143 randomize_buffers(dstbuf0, dstbuf1);
144 call_ref(dstbuf0, block0, 16);
145 call_new(dstbuf1, block1, 16);
146 if (memcmp(dstbuf0, dstbuf1, sizeof(dstbuf0)))
147 fail();
148 }
149 bench_new(dstbuf1, block1, 16);
150 }
151}
152
154{
156 report("qpeldsp");
158 report("idct8");
159}
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:97
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define rnd
Definition checkasm.h:140
static int16_t block[64]
Definition dct.c:125
static int16_t block1[64]
Definition dct.c:126
static const struct @213162273235257122266207155164174051374107224106 func_tab[]
const TestCase tests[]
Definition fifo_muxer.c:363
#define declare_func
Definition test.h:489
#define fail
Definition test.h:479
#define bench_new
Definition test.h:487
#define check_func
Definition test.h:481
#define call_new
Definition test.h:486
#define call_ref
Definition test.h:485
#define report
Definition test.h:480
#define MAX_BLOCK_SIZE
Definition imgutils.c:580
unsigned offset
Definition libaomenc.c:763
av_cold void ff_cavsdsp_init(CAVSDSPContext *c)
Definition cavsdsp.c:551
av_cold void ff_init_scantable_permutation(uint8_t *idct_permutation, enum idct_permutation_type perm_type)
Definition idctdsp.c:39
Utility Preprocessor macros.
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
#define MAX_STRIDE
void(* qpel_mc_func)(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)
Definition qpeldsp.h:65
const char * name
Definition qsvenc.c:142
#define BUF_SIZE
Definition setpts.c:159
#define FF_ARRAY_ELEMS(a)
void(* cavs_idct8_add)(uint8_t *dst, int16_t *block, ptrdiff_t stride)
Definition cavsdsp.h:37
#define stride
#define TEST(NAME)
void checkasm_check_cavsdsp(void)
Definition cavsdsp.c:153
#define randomize_buffers(buf0, buf1)
Definition cavsdsp.c:47
static void check_cavs_idct8_add(void)
Definition cavsdsp.c:118
static void check_cavs_qpeldsp(void)
Definition cavsdsp.c:61
#define src1
Definition h264pred.c:141
#define src0
Definition h264pred.c:140
#define INPUT_BUF_SIZE
Definition hpeldsp.c:38
#define src
Definition vp8dsp.c:248