dct-test.c 14.3 KB
Newer Older
1 2
/*
 * (c) 2001 Fabrice Bellard
3
 *     2007 Marc Hoffman <marc.hoffman@analog.com>
4
 *
5
 * This file is part of Libav.
6
 *
7
 * Libav is free software; you can redistribute it and/or
8 9
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
10
 * version 2.1 of the License, or (at your option) any later version.
11
 *
12
 * Libav is distributed in the hope that it will be useful,
13 14 15 16 17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
18
 * License along with Libav; if not, write to the Free Software
19 20 21
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

Michael Niedermayer's avatar
Michael Niedermayer committed
22
/**
23
 * @file
24
 * DCT test (c) 2001 Fabrice Bellard
Michael Niedermayer's avatar
Michael Niedermayer committed
25 26 27
 * Started from sample code by Juan J. Sierralta P.
 */

28
#include "config.h"
Fabrice Bellard's avatar
Fabrice Bellard committed
29 30 31
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
32
#if HAVE_UNISTD_H
Fabrice Bellard's avatar
Fabrice Bellard committed
33
#include <unistd.h>
34
#endif
35
#include <math.h>
Fabrice Bellard's avatar
Fabrice Bellard committed
36

37
#include "libavutil/cpu.h"
38
#include "libavutil/common.h"
39
#include "libavutil/lfg.h"
40
#include "libavutil/time.h"
Fabrice Bellard's avatar
Fabrice Bellard committed
41

Michael Niedermayer's avatar
Michael Niedermayer committed
42
#include "simple_idct.h"
43
#include "aandcttab.h"
Michael Niedermayer's avatar
Michael Niedermayer committed
44
#include "faandct.h"
Michael Niedermayer's avatar
Michael Niedermayer committed
45
#include "faanidct.h"
46
#include "x86/idct_xvid.h"
47
#include "dctref.h"
48

49 50
#undef printf

51
// BFIN
52 53
void ff_bfin_idct(DCTELEM *block);
void ff_bfin_fdct(DCTELEM *block);
54 55

// ALTIVEC
56
void ff_fdct_altivec(DCTELEM *block);
57

Måns Rullgård's avatar
Måns Rullgård committed
58
// ARM
Måns Rullgård's avatar
Måns Rullgård committed
59 60 61
void ff_j_rev_dct_arm(DCTELEM *data);
void ff_simple_idct_arm(DCTELEM *data);
void ff_simple_idct_armv5te(DCTELEM *data);
Måns Rullgård's avatar
Måns Rullgård committed
62 63
void ff_simple_idct_armv6(DCTELEM *data);
void ff_simple_idct_neon(DCTELEM *data);
64

Måns Rullgård's avatar
Måns Rullgård committed
65 66
void ff_simple_idct_axp(DCTELEM *data);

67
struct algo {
Mans Rullgard's avatar
Mans Rullgard committed
68 69 70 71 72
    const char *name;
    void (*func)(DCTELEM *block);
    enum formattag { NO_PERM, MMX_PERM, MMX_SIMPLE_PERM, SCALE_PERM,
                     SSE2_PERM, PARTTRANS_PERM } format;
    int mm_support;
73
    int nonspec;
74 75
};

76 77
static int cpu_flags;

78
static const struct algo fdct_tab[] = {
79
    { "REF-DBL",        ff_ref_fdct,           NO_PERM    },
80
    { "FAAN",           ff_faandct,            NO_PERM    },
81
    { "IJG-AAN-INT",    ff_fdct_ifast,         SCALE_PERM },
Mans Rullgard's avatar
Mans Rullgard committed
82
    { "IJG-LLM-INT",    ff_jpeg_fdct_islow_8,  NO_PERM    },
83

84
#if HAVE_MMX_INLINE
85
    { "MMX",            ff_fdct_mmx,           NO_PERM,   AV_CPU_FLAG_MMX     },
86
    { "MMXEXT",         ff_fdct_mmxext,        NO_PERM,   AV_CPU_FLAG_MMXEXT  },
87
    { "SSE2",           ff_fdct_sse2,          NO_PERM,   AV_CPU_FLAG_SSE2    },
88
#endif
89

90
#if HAVE_ALTIVEC
91
    { "altivecfdct",    ff_fdct_altivec,       NO_PERM,   AV_CPU_FLAG_ALTIVEC },
92 93 94
#endif

#if ARCH_BFIN
95
    { "BFINfdct",       ff_bfin_fdct,          NO_PERM  },
96 97 98 99 100 101
#endif

    { 0 }
};

static const struct algo idct_tab[] = {
102 103
    { "FAANI",          ff_faanidct,           NO_PERM  },
    { "REF-DBL",        ff_ref_idct,           NO_PERM  },
104
    { "INT",            ff_j_rev_dct,          MMX_PERM },
105
    { "SIMPLE-C",       ff_simple_idct_8,      NO_PERM  },
106

107
#if HAVE_MMX_INLINE
108 109
    { "SIMPLE-MMX",     ff_simple_idct_mmx,  MMX_SIMPLE_PERM, AV_CPU_FLAG_MMX },
    { "XVID-MMX",       ff_idct_xvid_mmx,      NO_PERM,   AV_CPU_FLAG_MMX,  1 },
110
    { "XVID-MMXEXT",    ff_idct_xvid_mmxext,   NO_PERM,   AV_CPU_FLAG_MMXEXT, 1 },
111
    { "XVID-SSE2",      ff_idct_xvid_sse2,     SSE2_PERM, AV_CPU_FLAG_SSE2, 1 },
112 113
#endif

114
#if ARCH_BFIN
115
    { "BFINidct",       ff_bfin_idct,          NO_PERM  },
116 117
#endif

118
#if ARCH_ARM
119 120
    { "SIMPLE-ARM",     ff_simple_idct_arm,    NO_PERM  },
    { "INT-ARM",        ff_j_rev_dct_arm,      MMX_PERM },
121
#endif
122
#if HAVE_ARMV5TE
123
    { "SIMPLE-ARMV5TE", ff_simple_idct_armv5te,NO_PERM,   AV_CPU_FLAG_ARMV5TE },
Måns Rullgård's avatar
Måns Rullgård committed
124
#endif
125
#if HAVE_ARMV6
126
    { "SIMPLE-ARMV6",   ff_simple_idct_armv6,  MMX_PERM,  AV_CPU_FLAG_ARMV6   },
Måns Rullgård's avatar
Måns Rullgård committed
127
#endif
128
#if HAVE_NEON
129
    { "SIMPLE-NEON",    ff_simple_idct_neon, PARTTRANS_PERM, AV_CPU_FLAG_NEON },
Måns Rullgård's avatar
Måns Rullgård committed
130 131
#endif

Måns Rullgård's avatar
Måns Rullgård committed
132
#if ARCH_ALPHA
133
    { "SIMPLE-ALPHA",   ff_simple_idct_axp,    NO_PERM },
Måns Rullgård's avatar
Måns Rullgård committed
134 135
#endif

Mans Rullgard's avatar
Mans Rullgard committed
136
    { 0 }
137 138
};

Fabrice Bellard's avatar
Fabrice Bellard committed
139 140 141 142 143
#define AANSCALE_BITS 12

#define NB_ITS 20000
#define NB_ITS_SPEED 50000

144 145
static short idct_mmx_perm[64];

Mans Rullgard's avatar
Mans Rullgard committed
146 147 148 149 150 151 152 153 154
static short idct_simple_mmx_perm[64] = {
    0x00, 0x08, 0x04, 0x09, 0x01, 0x0C, 0x05, 0x0D,
    0x10, 0x18, 0x14, 0x19, 0x11, 0x1C, 0x15, 0x1D,
    0x20, 0x28, 0x24, 0x29, 0x21, 0x2C, 0x25, 0x2D,
    0x12, 0x1A, 0x16, 0x1B, 0x13, 0x1E, 0x17, 0x1F,
    0x02, 0x0A, 0x06, 0x0B, 0x03, 0x0E, 0x07, 0x0F,
    0x30, 0x38, 0x34, 0x39, 0x31, 0x3C, 0x35, 0x3D,
    0x22, 0x2A, 0x26, 0x2B, 0x23, 0x2E, 0x27, 0x2F,
    0x32, 0x3A, 0x36, 0x3B, 0x33, 0x3E, 0x37, 0x3F,
Michael Niedermayer's avatar
Michael Niedermayer committed
155 156
};

Mans Rullgard's avatar
Mans Rullgard committed
157
static const uint8_t idct_sse2_row_perm[8] = { 0, 4, 1, 5, 2, 6, 3, 7 };
158

159
static void idct_mmx_init(void)
160 161 162 163 164
{
    int i;

    /* the mmx/mmxext idct uses a reordered input, so we patch scan tables */
    for (i = 0; i < 64; i++) {
165
        idct_mmx_perm[i] = (i & 0x38) | ((i & 6) >> 1) | ((i & 1) << 2);
166 167 168
    }
}

169
DECLARE_ALIGNED(16, static DCTELEM, block)[64];
Mans Rullgard's avatar
Mans Rullgard committed
170
DECLARE_ALIGNED(8,  static DCTELEM, block1)[64];
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
static void init_block(DCTELEM block[64], int test, int is_idct, AVLFG *prng)
{
    int i, j;

    memset(block, 0, 64 * sizeof(*block));

    switch (test) {
    case 0:
        for (i = 0; i < 64; i++)
            block[i] = (av_lfg_get(prng) % 512) - 256;
        if (is_idct) {
            ff_ref_fdct(block);
            for (i = 0; i < 64; i++)
                block[i] >>= 3;
        }
        break;
    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:
        block[ 0] = av_lfg_get(prng) % 4096 - 2048;
        block[63] = (block[0] & 1) ^ 1;
        break;
    }
}

static void permute(DCTELEM dst[64], const DCTELEM src[64], int perm)
{
    int i;

    if (perm == MMX_PERM) {
        for (i = 0; i < 64; i++)
            dst[idct_mmx_perm[i]] = src[i];
    } else if (perm == MMX_SIMPLE_PERM) {
        for (i = 0; i < 64; i++)
            dst[idct_simple_mmx_perm[i]] = src[i];
    } else if (perm == SSE2_PERM) {
        for (i = 0; i < 64; i++)
            dst[(i & 0x38) | idct_sse2_row_perm[i & 7]] = src[i];
    } else if (perm == PARTTRANS_PERM) {
        for (i = 0; i < 64; i++)
            dst[(i & 0x24) | ((i & 3) << 3) | ((i >> 3) & 3)] = src[i];
    } else {
        for (i = 0; i < 64; i++)
            dst[i] = src[i];
    }
}

222
static int dct_error(const struct algo *dct, int test, int is_idct, int speed)
Fabrice Bellard's avatar
Fabrice Bellard committed
223
{
224
    void (*ref)(DCTELEM *block) = is_idct ? ff_ref_idct : ff_ref_fdct;
Fabrice Bellard's avatar
Fabrice Bellard committed
225 226
    int it, i, scale;
    int err_inf, v;
227
    int64_t err2, ti, ti1, it1, err_sum = 0;
Mans Rullgard's avatar
Mans Rullgard committed
228 229 230
    int64_t sysErr[64], sysErrMax = 0;
    int maxout = 0;
    int blockSumErrMax = 0, blockSumErr;
231
    AVLFG prng;
232 233
    double omse, ome;
    int spec_err;
Fabrice Bellard's avatar
Fabrice Bellard committed
234

235
    av_lfg_init(&prng, 1);
Fabrice Bellard's avatar
Fabrice Bellard committed
236 237 238

    err_inf = 0;
    err2 = 0;
Mans Rullgard's avatar
Mans Rullgard committed
239 240 241
    for (i = 0; i < 64; i++)
        sysErr[i] = 0;
    for (it = 0; it < NB_ITS; it++) {
242 243
        init_block(block1, test, is_idct, &prng);
        permute(block, block1, dct->format);
244

245
        dct->func(block);
246
        emms_c();
247

248
        if (dct->format == SCALE_PERM) {
Mans Rullgard's avatar
Mans Rullgard committed
249 250 251
            for (i = 0; i < 64; i++) {
                scale = 8 * (1 << (AANSCALE_BITS + 11)) / ff_aanscales[i];
                block[i] = (block[i] * scale) >> AANSCALE_BITS;
Michael Niedermayer's avatar
Michael Niedermayer committed
252 253 254
            }
        }

255
        ref(block1);
Fabrice Bellard's avatar
Fabrice Bellard committed
256

Mans Rullgard's avatar
Mans Rullgard committed
257 258
        blockSumErr = 0;
        for (i = 0; i < 64; i++) {
259 260 261
            int err = block[i] - block1[i];
            err_sum += err;
            v = abs(err);
Fabrice Bellard's avatar
Fabrice Bellard committed
262 263 264
            if (v > err_inf)
                err_inf = v;
            err2 += v * v;
265 266
            sysErr[i] += block[i] - block1[i];
            blockSumErr += v;
Mans Rullgard's avatar
Mans Rullgard committed
267 268
            if (abs(block[i]) > maxout)
                maxout = abs(block[i]);
Fabrice Bellard's avatar
Fabrice Bellard committed
269
        }
Mans Rullgard's avatar
Mans Rullgard committed
270 271
        if (blockSumErrMax < blockSumErr)
            blockSumErrMax = blockSumErr;
Michael Niedermayer's avatar
Michael Niedermayer committed
272
    }
Mans Rullgard's avatar
Mans Rullgard committed
273 274
    for (i = 0; i < 64; i++)
        sysErrMax = FFMAX(sysErrMax, FFABS(sysErr[i]));
275

Mans Rullgard's avatar
Mans Rullgard committed
276 277 278 279
    for (i = 0; i < 64; i++) {
        if (i % 8 == 0)
            printf("\n");
        printf("%7d ", (int) sysErr[i]);
Fabrice Bellard's avatar
Fabrice Bellard committed
280
    }
Michael Niedermayer's avatar
Michael Niedermayer committed
281
    printf("\n");
282

283 284 285 286 287 288
    omse = (double) err2 / NB_ITS / 64;
    ome  = (double) err_sum / NB_ITS / 64;

    spec_err = is_idct && (err_inf > 1 || omse > 0.02 || fabs(ome) > 0.0015);

    printf("%s %s: ppe=%d omse=%0.8f ome=%0.8f syserr=%0.8f maxout=%d blockSumErr=%d\n",
289
           is_idct ? "IDCT" : "DCT", dct->name, err_inf,
290
           omse, ome, (double) sysErrMax / NB_ITS,
Mans Rullgard's avatar
Mans Rullgard committed
291
           maxout, blockSumErrMax);
292

293 294 295
    if (spec_err && !dct->nonspec)
        return 1;

296
    if (!speed)
297
        return 0;
298

Fabrice Bellard's avatar
Fabrice Bellard committed
299
    /* speed test */
300 301
    init_block(block, test, is_idct, &prng);
    permute(block1, block, dct->format);
302

303
    ti = av_gettime();
Fabrice Bellard's avatar
Fabrice Bellard committed
304 305
    it1 = 0;
    do {
Mans Rullgard's avatar
Mans Rullgard committed
306
        for (it = 0; it < NB_ITS_SPEED; it++) {
307
            memcpy(block, block1, sizeof(block));
308
            dct->func(block);
Fabrice Bellard's avatar
Fabrice Bellard committed
309 310
        }
        it1 += NB_ITS_SPEED;
311
        ti1 = av_gettime() - ti;
Fabrice Bellard's avatar
Fabrice Bellard committed
312
    } while (ti1 < 1000000);
313
    emms_c();
Fabrice Bellard's avatar
Fabrice Bellard committed
314

315
    printf("%s %s: %0.1f kdct/s\n", is_idct ? "IDCT" : "DCT", dct->name,
Mans Rullgard's avatar
Mans Rullgard committed
316
           (double) it1 * 1000.0 / (double) ti1);
317 318

    return 0;
Fabrice Bellard's avatar
Fabrice Bellard committed
319 320
}

321 322
DECLARE_ALIGNED(8, static uint8_t, img_dest)[64];
DECLARE_ALIGNED(8, static uint8_t, img_dest1)[64];
Fabrice Bellard's avatar
Fabrice Bellard committed
323

324
static void idct248_ref(uint8_t *dest, int linesize, int16_t *block)
Fabrice Bellard's avatar
Fabrice Bellard committed
325 326 327 328 329 330 331 332 333 334 335
{
    static int init;
    static double c8[8][8];
    static double c4[4][4];
    double block1[64], block2[64], block3[64];
    double s, sum, v;
    int i, j, k;

    if (!init) {
        init = 1;

Mans Rullgard's avatar
Mans Rullgard committed
336
        for (i = 0; i < 8; i++) {
Fabrice Bellard's avatar
Fabrice Bellard committed
337
            sum = 0;
Mans Rullgard's avatar
Mans Rullgard committed
338 339
            for (j = 0; j < 8; j++) {
                s = (i == 0) ? sqrt(1.0 / 8.0) : sqrt(1.0 / 4.0);
Fabrice Bellard's avatar
Fabrice Bellard committed
340 341 342 343
                c8[i][j] = s * cos(M_PI * i * (j + 0.5) / 8.0);
                sum += c8[i][j] * c8[i][j];
            }
        }
344

Mans Rullgard's avatar
Mans Rullgard committed
345
        for (i = 0; i < 4; i++) {
Fabrice Bellard's avatar
Fabrice Bellard committed
346
            sum = 0;
Mans Rullgard's avatar
Mans Rullgard committed
347 348
            for (j = 0; j < 4; j++) {
                s = (i == 0) ? sqrt(1.0 / 4.0) : sqrt(1.0 / 2.0);
Fabrice Bellard's avatar
Fabrice Bellard committed
349 350 351 352 353 354 355
                c4[i][j] = s * cos(M_PI * i * (j + 0.5) / 4.0);
                sum += c4[i][j] * c4[i][j];
            }
        }
    }

    /* butterfly */
356
    s = 0.5 * sqrt(2.0);
Mans Rullgard's avatar
Mans Rullgard committed
357 358 359 360 361 362
    for (i = 0; i < 4; i++) {
        for (j = 0; j < 8; j++) {
            block1[8 * (2 * i) + j] =
                (block[8 * (2 * i) + j] + block[8 * (2 * i + 1) + j]) * s;
            block1[8 * (2 * i + 1) + j] =
                (block[8 * (2 * i) + j] - block[8 * (2 * i + 1) + j]) * s;
Fabrice Bellard's avatar
Fabrice Bellard committed
363 364 365 366
        }
    }

    /* idct8 on lines */
Mans Rullgard's avatar
Mans Rullgard committed
367 368
    for (i = 0; i < 8; i++) {
        for (j = 0; j < 8; j++) {
Fabrice Bellard's avatar
Fabrice Bellard committed
369
            sum = 0;
Mans Rullgard's avatar
Mans Rullgard committed
370 371 372
            for (k = 0; k < 8; k++)
                sum += c8[k][j] * block1[8 * i + k];
            block2[8 * i + j] = sum;
Fabrice Bellard's avatar
Fabrice Bellard committed
373 374 375 376
        }
    }

    /* idct4 */
Mans Rullgard's avatar
Mans Rullgard committed
377 378
    for (i = 0; i < 8; i++) {
        for (j = 0; j < 4; j++) {
Fabrice Bellard's avatar
Fabrice Bellard committed
379 380
            /* top */
            sum = 0;
Mans Rullgard's avatar
Mans Rullgard committed
381 382 383
            for (k = 0; k < 4; k++)
                sum += c4[k][j] * block2[8 * (2 * k) + i];
            block3[8 * (2 * j) + i] = sum;
Fabrice Bellard's avatar
Fabrice Bellard committed
384 385 386

            /* bottom */
            sum = 0;
Mans Rullgard's avatar
Mans Rullgard committed
387 388 389
            for (k = 0; k < 4; k++)
                sum += c4[k][j] * block2[8 * (2 * k + 1) + i];
            block3[8 * (2 * j + 1) + i] = sum;
Fabrice Bellard's avatar
Fabrice Bellard committed
390 391 392 393
        }
    }

    /* clamp and store the result */
Mans Rullgard's avatar
Mans Rullgard committed
394 395 396 397 398 399
    for (i = 0; i < 8; i++) {
        for (j = 0; j < 8; j++) {
            v = block3[8 * i + j];
            if      (v < 0)   v = 0;
            else if (v > 255) v = 255;
            dest[i * linesize + j] = (int) rint(v);
Fabrice Bellard's avatar
Fabrice Bellard committed
400 401 402 403
        }
    }
}

404
static void idct248_error(const char *name,
Mans Rullgard's avatar
Mans Rullgard committed
405
                          void (*idct248_put)(uint8_t *dest, int line_size,
406 407
                                              int16_t *block),
                          int speed)
Fabrice Bellard's avatar
Fabrice Bellard committed
408 409
{
    int it, i, it1, ti, ti1, err_max, v;
410
    AVLFG prng;
411

412
    av_lfg_init(&prng, 1);
413

Fabrice Bellard's avatar
Fabrice Bellard committed
414 415 416
    /* just one test to see if code is correct (precision is less
       important here) */
    err_max = 0;
Mans Rullgard's avatar
Mans Rullgard committed
417
    for (it = 0; it < NB_ITS; it++) {
418
        /* XXX: use forward transform to generate values */
Mans Rullgard's avatar
Mans Rullgard committed
419
        for (i = 0; i < 64; i++)
420
            block1[i] = av_lfg_get(&prng) % 256 - 128;
421 422
        block1[0] += 1024;

Mans Rullgard's avatar
Mans Rullgard committed
423 424
        for (i = 0; i < 64; i++)
            block[i] = block1[i];
Fabrice Bellard's avatar
Fabrice Bellard committed
425
        idct248_ref(img_dest1, 8, block);
426

Mans Rullgard's avatar
Mans Rullgard committed
427 428
        for (i = 0; i < 64; i++)
            block[i] = block1[i];
429
        idct248_put(img_dest, 8, block);
430

Mans Rullgard's avatar
Mans Rullgard committed
431 432
        for (i = 0; i < 64; i++) {
            v = abs((int) img_dest[i] - (int) img_dest1[i]);
433 434 435 436 437
            if (v == 255)
                printf("%d %d\n", img_dest[i], img_dest1[i]);
            if (v > err_max)
                err_max = v;
        }
Fabrice Bellard's avatar
Fabrice Bellard committed
438
    }
Mans Rullgard's avatar
Mans Rullgard committed
439
    printf("%s %s: err_inf=%d\n", 1 ? "IDCT248" : "DCT248", name, err_max);
Fabrice Bellard's avatar
Fabrice Bellard committed
440

441 442 443
    if (!speed)
        return;

444
    ti = av_gettime();
Fabrice Bellard's avatar
Fabrice Bellard committed
445 446
    it1 = 0;
    do {
Mans Rullgard's avatar
Mans Rullgard committed
447 448 449
        for (it = 0; it < NB_ITS_SPEED; it++) {
            for (i = 0; i < 64; i++)
                block[i] = block1[i];
Fabrice Bellard's avatar
Fabrice Bellard committed
450 451 452
            idct248_put(img_dest, 8, block);
        }
        it1 += NB_ITS_SPEED;
453
        ti1 = av_gettime() - ti;
Fabrice Bellard's avatar
Fabrice Bellard committed
454
    } while (ti1 < 1000000);
455
    emms_c();
Fabrice Bellard's avatar
Fabrice Bellard committed
456

Mans Rullgard's avatar
Mans Rullgard committed
457 458
    printf("%s %s: %0.1f kdct/s\n", 1 ? "IDCT248" : "DCT248", name,
           (double) it1 * 1000.0 / (double) ti1);
Fabrice Bellard's avatar
Fabrice Bellard committed
459 460
}

461
static void help(void)
462
{
Michael Niedermayer's avatar
Michael Niedermayer committed
463 464 465 466
    printf("dct-test [-i] [<test-number>]\n"
           "test-number 0 -> test with random matrixes\n"
           "            1 -> test with random sparse matrixes\n"
           "            2 -> do 3. test from mpeg4 std\n"
Fabrice Bellard's avatar
Fabrice Bellard committed
467
           "-i          test IDCT implementations\n"
468 469
           "-4          test IDCT248 implementations\n"
           "-t          speed test\n");
470 471
}

472 473 474 475
#if !HAVE_GETOPT
#include "compat/getopt.c"
#endif

Fabrice Bellard's avatar
Fabrice Bellard committed
476 477
int main(int argc, char **argv)
{
Fabrice Bellard's avatar
Fabrice Bellard committed
478
    int test_idct = 0, test_248_dct = 0;
Mans Rullgard's avatar
Mans Rullgard committed
479 480
    int c, i;
    int test = 1;
481
    int speed = 0;
482
    int err = 0;
Mans Rullgard's avatar
Mans Rullgard committed
483

484
    cpu_flags = av_get_cpu_flags();
485

486
    ff_ref_dct_init();
487
    idct_mmx_init();
488

Mans Rullgard's avatar
Mans Rullgard committed
489
    for (;;) {
490
        c = getopt(argc, argv, "ih4t");
491 492
        if (c == -1)
            break;
Mans Rullgard's avatar
Mans Rullgard committed
493
        switch (c) {
494 495 496
        case 'i':
            test_idct = 1;
            break;
Fabrice Bellard's avatar
Fabrice Bellard committed
497 498 499
        case '4':
            test_248_dct = 1;
            break;
500 501 502
        case 't':
            speed = 1;
            break;
Mans Rullgard's avatar
Mans Rullgard committed
503
        default:
504 505
        case 'h':
            help();
Marc Hoffman's avatar
Marc Hoffman committed
506
            return 0;
507 508
        }
    }
509

Mans Rullgard's avatar
Mans Rullgard committed
510 511
    if (optind < argc)
        test = atoi(argv[optind]);
512

513
    printf("Libav DCT/IDCT test\n");
514

Fabrice Bellard's avatar
Fabrice Bellard committed
515
    if (test_248_dct) {
516
        idct248_error("SIMPLE-C", ff_simple_idct248_put, speed);
517
    } else {
518
        const struct algo *algos = test_idct ? idct_tab : fdct_tab;
Mans Rullgard's avatar
Mans Rullgard committed
519
        for (i = 0; algos[i].name; i++)
520
            if (!(~cpu_flags & algos[i].mm_support)) {
521
                err |= dct_error(&algos[i], test, test_idct, speed);
Mans Rullgard's avatar
Mans Rullgard committed
522
            }
523
    }
524 525

    return err;
Fabrice Bellard's avatar
Fabrice Bellard committed
526
}