Commit ae2e8971 authored by Mans Rullgard's avatar Mans Rullgard

dct-test: factor out some common code and do whas was likely intended

This fixes some nonsensical code by moving some should-be-shared
code to separate functions and using these.
Signed-off-by: 's avatarMans Rullgard <mans@mansr.com>
parent dd8d808b
......@@ -199,67 +199,78 @@ static inline void mmx_emms(void)
#endif
}
static int dct_error(const struct algo *dct, int test, int is_idct, int speed)
static void init_block(DCTELEM block[64], int test, int is_idct, AVLFG *prng)
{
void (*ref)(DCTELEM *block) = is_idct ? ff_ref_idct : ff_ref_fdct;
int it, i, scale;
int err_inf, v;
int64_t err2, ti, ti1, it1, err_sum = 0;
int64_t sysErr[64], sysErrMax = 0;
int maxout = 0;
int blockSumErrMax = 0, blockSumErr;
AVLFG prng;
double omse, ome;
int spec_err;
int i, j;
av_lfg_init(&prng, 1);
memset(block, 0, 64 * sizeof(*block));
err_inf = 0;
err2 = 0;
for (i = 0; i < 64; i++)
sysErr[i] = 0;
for (it = 0; it < NB_ITS; it++) {
for (i = 0; i < 64; i++)
block1[i] = 0;
switch (test) {
case 0:
for (i = 0; i < 64; i++)
block1[i] = (av_lfg_get(&prng) % 512) - 256;
block[i] = (av_lfg_get(prng) % 512) - 256;
if (is_idct) {
ff_ref_fdct(block1);
ff_ref_fdct(block);
for (i = 0; i < 64; i++)
block1[i] >>= 3;
block[i] >>= 3;
}
break;
case 1: {
int num = av_lfg_get(&prng) % 10 + 1;
for (i = 0; i < num; i++)
block1[av_lfg_get(&prng) % 64] =
av_lfg_get(&prng) % 512 - 256;
}
case 1:
j = av_lfg_get(prng) % 10 + 1;
for (i = 0; i < j; i++)
block[av_lfg_get(prng) % 64] = av_lfg_get(prng) % 512 - 256;
break;
case 2:
block1[0] = av_lfg_get(&prng) % 4096 - 2048;
block1[63] = (block1[0] & 1) ^ 1;
block[ 0] = av_lfg_get(prng) % 4096 - 2048;
block[63] = (block[0] & 1) ^ 1;
break;
}
}
if (dct->format == MMX_PERM) {
static void permute(DCTELEM dst[64], const DCTELEM src[64], int perm)
{
int i;
if (perm == MMX_PERM) {
for (i = 0; i < 64; i++)
block[idct_mmx_perm[i]] = block1[i];
} else if (dct->format == MMX_SIMPLE_PERM) {
dst[idct_mmx_perm[i]] = src[i];
} else if (perm == MMX_SIMPLE_PERM) {
for (i = 0; i < 64; i++)
block[idct_simple_mmx_perm[i]] = block1[i];
} else if (dct->format == SSE2_PERM) {
dst[idct_simple_mmx_perm[i]] = src[i];
} else if (perm == SSE2_PERM) {
for (i = 0; i < 64; i++)
block[(i & 0x38) | idct_sse2_row_perm[i & 7]] = block1[i];
} else if (dct->format == PARTTRANS_PERM) {
dst[(i & 0x38) | idct_sse2_row_perm[i & 7]] = src[i];
} else if (perm == PARTTRANS_PERM) {
for (i = 0; i < 64; i++)
block[(i & 0x24) | ((i & 3) << 3) | ((i >> 3) & 3)] = block1[i];
dst[(i & 0x24) | ((i & 3) << 3) | ((i >> 3) & 3)] = src[i];
} else {
for (i = 0; i < 64; i++)
block[i] = block1[i];
dst[i] = src[i];
}
}
static int dct_error(const struct algo *dct, int test, int is_idct, int speed)
{
void (*ref)(DCTELEM *block) = is_idct ? ff_ref_idct : ff_ref_fdct;
int it, i, scale;
int err_inf, v;
int64_t err2, ti, ti1, it1, err_sum = 0;
int64_t sysErr[64], sysErrMax = 0;
int maxout = 0;
int blockSumErrMax = 0, blockSumErr;
AVLFG prng;
double omse, ome;
int spec_err;
av_lfg_init(&prng, 1);
err_inf = 0;
err2 = 0;
for (i = 0; i < 64; i++)
sysErr[i] = 0;
for (it = 0; it < NB_ITS; it++) {
init_block(block1, test, is_idct, &prng);
permute(block, block1, dct->format);
dct->func(block);
mmx_emms();
......@@ -316,45 +327,14 @@ static int dct_error(const struct algo *dct, int test, int is_idct, int speed)
return 0;
/* speed test */
for (i = 0; i < 64; i++)
block1[i] = 0;
switch (test) {
case 0:
for (i = 0; i < 64; i++)
block1[i] = av_lfg_get(&prng) % 512 - 256;
if (is_idct) {
ff_ref_fdct(block1);
for (i = 0; i < 64; i++)
block1[i] >>= 3;
}
break;
case 1:
case 2:
block1[0] = av_lfg_get(&prng) % 512 - 256;
block1[1] = av_lfg_get(&prng) % 512 - 256;
block1[2] = av_lfg_get(&prng) % 512 - 256;
block1[3] = av_lfg_get(&prng) % 512 - 256;
break;
}
if (dct->format == MMX_PERM) {
for (i = 0; i < 64; i++)
block[idct_mmx_perm[i]] = block1[i];
} else if (dct->format == MMX_SIMPLE_PERM) {
for (i = 0; i < 64; i++)
block[idct_simple_mmx_perm[i]] = block1[i];
} else {
for (i = 0; i < 64; i++)
block[i] = block1[i];
}
init_block(block, test, is_idct, &prng);
permute(block1, block, dct->format);
ti = gettime();
it1 = 0;
do {
for (it = 0; it < NB_ITS_SPEED; it++) {
for (i = 0; i < 64; i++)
block[i] = block1[i];
memcpy(block, block1, sizeof(block));
dct->func(block);
}
it1 += NB_ITS_SPEED;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment