35 #define randomize_struct(TYPE, s) do { \
36 static_assert(!(_Alignof(TYPE) % 4), \
37 "can't use aligned stores"); \
38 unsigned char *ptr = (unsigned char*)s; \
39 for (size_t i = 0; i < sizeof(*s) & ~3; i += 4) \
40 AV_WN32A(ptr + i, rnd()); \
41 for (size_t i = sizeof(*s) & ~3; i < sizeof(*s); ++i) \
56 #if ARCH_X86_32 && HAVE_X86ASM
59 #if ARCH_PPC || ARCH_X86
62 #if ARCH_ARM || ARCH_AARCH64
65 #if ARCH_X86 && HAVE_X86ASM
71 { 0x00, 0x08, 0x01, 0x02, 0x09, 0x10, 0x18, 0x11,
72 0x0A, 0x03, 0x04, 0x0B, 0x12, 0x19, 0x20, 0x28,
73 0x30, 0x38, 0x29, 0x21, 0x1A, 0x13, 0x0C, 0x05,
74 0x06, 0x0D, 0x14, 0x1B, 0x22, 0x31, 0x39, 0x3A,
75 0x32, 0x2A, 0x23, 0x1C, 0x15, 0x0E, 0x07, 0x0F,
76 0x16, 0x1D, 0x24, 0x2B, 0x33, 0x3B, 0x3C, 0x34,
77 0x2C, 0x25, 0x1E, 0x17, 0x1F, 0x26, 0x2D, 0x35,
78 0x3D, 0x3E, 0x36, 0x2E, 0x27, 0x2F, 0x37, 0x3F, },
79 { 0x00, 0x08, 0x01, 0x02, 0x09, 0x10, 0x18, 0x11,
80 0x0A, 0x03, 0x04, 0x0B, 0x12, 0x19, 0x20, 0x28,
81 0x21, 0x30, 0x1A, 0x13, 0x0C, 0x05, 0x06, 0x0D,
82 0x14, 0x1B, 0x22, 0x29, 0x38, 0x31, 0x39, 0x2A,
83 0x23, 0x1C, 0x15, 0x0E, 0x07, 0x0F, 0x16, 0x1D,
84 0x24, 0x2B, 0x32, 0x3A, 0x33, 0x3B, 0x2C, 0x25,
85 0x1E, 0x17, 0x1F, 0x26, 0x2D, 0x34, 0x3C, 0x35,
86 0x3D, 0x2E, 0x27, 0x2F, 0x36, 0x3E, 0x37, 0x3F, },
87 { 0x00, 0x01, 0x08, 0x02, 0x03, 0x09, 0x10, 0x18,
88 0x11, 0x0A, 0x04, 0x05, 0x0B, 0x12, 0x19, 0x20,
89 0x28, 0x30, 0x21, 0x1A, 0x13, 0x0C, 0x06, 0x07,
90 0x0D, 0x14, 0x1B, 0x22, 0x29, 0x38, 0x31, 0x39,
91 0x2A, 0x23, 0x1C, 0x15, 0x0E, 0x0F, 0x16, 0x1D,
92 0x24, 0x2B, 0x32, 0x3A, 0x33, 0x2C, 0x25, 0x1E,
93 0x17, 0x1F, 0x26, 0x2D, 0x34, 0x3B, 0x3C, 0x35,
94 0x2E, 0x27, 0x2F, 0x36, 0x3D, 0x3E, 0x37, 0x3F, },
95 { 0x00, 0x08, 0x10, 0x01, 0x18, 0x20, 0x28, 0x09,
96 0x02, 0x03, 0x0A, 0x11, 0x19, 0x30, 0x38, 0x29,
97 0x21, 0x1A, 0x12, 0x0B, 0x04, 0x05, 0x0C, 0x13,
98 0x1B, 0x22, 0x31, 0x39, 0x32, 0x2A, 0x23, 0x1C,
99 0x14, 0x0D, 0x06, 0x07, 0x0E, 0x15, 0x1D, 0x24,
100 0x2B, 0x33, 0x3A, 0x3B, 0x34, 0x2C, 0x25, 0x1E,
101 0x16, 0x0F, 0x17, 0x1F, 0x26, 0x2D, 0x3C, 0x35,
102 0x2E, 0x27, 0x2F, 0x36, 0x3D, 0x3E, 0x37, 0x3F, }
105 static const uint8_t *
const scantables[] = {
114 static const uint8_t *scantable =
NULL;
123 intra_scantable ? &
s->intra_scantable : &
s->inter_scantable,
128 int last_nonzero_coeff,
int qscale,
int intra)
130 const uint8_t *permutation =
s->inter_scantable.permutated;
132 permutation =
s->intra_scantable.permutated;
134 static int h263_aic = -1, ac_pred;
136 h263_aic =
rnd() & 1;
139 s->h263_aic = h263_aic;
140 s->ac_pred = ac_pred;
142 last_nonzero_coeff = 63;
144 for (
int i = intra;
i <= last_nonzero_coeff; ++
i) {
156 int last_nonzero_coeff,
int qscale,
int intra,
159 uint16_t *
matrix = intra ?
s->intra_matrix :
s->inter_matrix;
164 for (
int i = 0;
i < 64; ++
i)
167 const uint8_t *permutation =
s->intra_scantable.permutated;
170 for (
int i = 1;
i <= last_nonzero_coeff; ++
i) {
171 int j = permutation[
i];
172 unsigned random =
rnd();
184 for (
int i = 0;
i <= last_nonzero_coeff; ++
i) {
185 int j = permutation[
i];
186 unsigned random =
rnd();
198 static const struct {
201 int intra, intra_scantable;
204 #define TEST(NAME, INTRA, INTRA_SCANTABLE, TYPE) \
205 { .name = #NAME, .offset = offsetof(MPVUnquantDSPContext, NAME), \
206 .intra = INTRA, .intra_scantable = INTRA_SCANTABLE, .type = TYPE }
207 TEST(dct_unquantize_mpeg1_intra, 1, 1,
MPEG1),
208 TEST(dct_unquantize_mpeg1_inter, 0, 1,
MPEG1),
209 TEST(dct_unquantize_mpeg2_intra, 1, 1,
MPEG2),
210 TEST(dct_unquantize_mpeg2_inter, 0, 1,
MPEG2),
211 TEST(dct_unquantize_h263_intra, 1, 1,
H263),
212 TEST(dct_unquantize_h263_inter, 0, 0,
H263),
215 int q_scale_type =
rnd() & 1;
221 void (*
func)(
const MPVContext *
s, int16_t *
block,
int n,
int qscale) =
222 *(
void (**)(
const MPVContext *, int16_t *, int, int))((
char*)&unquant_dsp_ctx +
tests[
i].
offset);
227 static int block_last_index = -1;
231 ref.q_scale_type = q_scale_type;
235 if (block_last_index < 0)
236 block_last_index =
rnd() % 64;
238 memset(block_ref, 0,
sizeof(block_ref));
242 ref.y_dc_scale = 1 +
rnd() % 64;
243 ref.c_dc_scale = 1 +
rnd() % 64;
246 static int qscale = 0;
249 qscale = 1 +
rnd() % 31;
259 ref.block_last_index[n] = block_last_index;
261 memcpy(&
new, &
ref,
sizeof(
new));
262 memcpy(block_new, block_ref,
sizeof(block_new));
265 call_new(&
new, block_new, n, qscale);
267 if (memcmp(&
ref, &
new,
sizeof(
new)) || memcmp(block_new, block_ref,
sizeof(block_new)))