annotate dct-test.c @ 22:c31fb57d17a6 libavcodec

Suppressing external gas stuff to improve portability to Win32
author nickols_k
date Sun, 05 Aug 2001 16:49:57 +0000
parents 986e461dc072
children 7cf705a32d1c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1 /* DCT test. (c) 2001 Gerard Lantau.
986e461dc072 Initial revision
glantau
parents:
diff changeset
2 Started from sample code by Juan J. Sierralta P.
986e461dc072 Initial revision
glantau
parents:
diff changeset
3 */
986e461dc072 Initial revision
glantau
parents:
diff changeset
4 #include <stdlib.h>
986e461dc072 Initial revision
glantau
parents:
diff changeset
5 #include <stdio.h>
986e461dc072 Initial revision
glantau
parents:
diff changeset
6 #include <string.h>
986e461dc072 Initial revision
glantau
parents:
diff changeset
7 #include <sys/time.h>
986e461dc072 Initial revision
glantau
parents:
diff changeset
8 #include <unistd.h>
986e461dc072 Initial revision
glantau
parents:
diff changeset
9
986e461dc072 Initial revision
glantau
parents:
diff changeset
10 #include "dsputil.h"
986e461dc072 Initial revision
glantau
parents:
diff changeset
11
986e461dc072 Initial revision
glantau
parents:
diff changeset
12 extern void fdct(DCTELEM *block);
986e461dc072 Initial revision
glantau
parents:
diff changeset
13 extern void init_fdct();
986e461dc072 Initial revision
glantau
parents:
diff changeset
14
986e461dc072 Initial revision
glantau
parents:
diff changeset
15 #define AANSCALE_BITS 12
986e461dc072 Initial revision
glantau
parents:
diff changeset
16 static const unsigned short aanscales[64] = {
986e461dc072 Initial revision
glantau
parents:
diff changeset
17 /* precomputed values scaled up by 14 bits */
986e461dc072 Initial revision
glantau
parents:
diff changeset
18 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
986e461dc072 Initial revision
glantau
parents:
diff changeset
19 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
986e461dc072 Initial revision
glantau
parents:
diff changeset
20 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
986e461dc072 Initial revision
glantau
parents:
diff changeset
21 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
986e461dc072 Initial revision
glantau
parents:
diff changeset
22 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
986e461dc072 Initial revision
glantau
parents:
diff changeset
23 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
986e461dc072 Initial revision
glantau
parents:
diff changeset
24 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
986e461dc072 Initial revision
glantau
parents:
diff changeset
25 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
986e461dc072 Initial revision
glantau
parents:
diff changeset
26 };
986e461dc072 Initial revision
glantau
parents:
diff changeset
27
986e461dc072 Initial revision
glantau
parents:
diff changeset
28 INT64 gettime(void)
986e461dc072 Initial revision
glantau
parents:
diff changeset
29 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
30 struct timeval tv;
986e461dc072 Initial revision
glantau
parents:
diff changeset
31 gettimeofday(&tv,NULL);
986e461dc072 Initial revision
glantau
parents:
diff changeset
32 return (INT64)tv.tv_sec * 1000000 + tv.tv_usec;
986e461dc072 Initial revision
glantau
parents:
diff changeset
33 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
34
986e461dc072 Initial revision
glantau
parents:
diff changeset
35 #define NB_ITS 20000
986e461dc072 Initial revision
glantau
parents:
diff changeset
36 #define NB_ITS_SPEED 50000
986e461dc072 Initial revision
glantau
parents:
diff changeset
37
986e461dc072 Initial revision
glantau
parents:
diff changeset
38 void dct_error(const char *name,
986e461dc072 Initial revision
glantau
parents:
diff changeset
39 void (*fdct_func)(DCTELEM *block))
986e461dc072 Initial revision
glantau
parents:
diff changeset
40 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
41 int it, i, scale;
986e461dc072 Initial revision
glantau
parents:
diff changeset
42 DCTELEM block[64], block1[64];
986e461dc072 Initial revision
glantau
parents:
diff changeset
43 int err_inf, v;
986e461dc072 Initial revision
glantau
parents:
diff changeset
44 INT64 err2, ti, ti1, it1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
45
986e461dc072 Initial revision
glantau
parents:
diff changeset
46 srandom(0);
986e461dc072 Initial revision
glantau
parents:
diff changeset
47
986e461dc072 Initial revision
glantau
parents:
diff changeset
48 err_inf = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
49 err2 = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
50 for(it=0;it<NB_ITS;it++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
51 for(i=0;i<64;i++)
986e461dc072 Initial revision
glantau
parents:
diff changeset
52 block1[i] = random() % 256;
986e461dc072 Initial revision
glantau
parents:
diff changeset
53 memcpy(block, block1, sizeof(DCTELEM) * 64);
986e461dc072 Initial revision
glantau
parents:
diff changeset
54
986e461dc072 Initial revision
glantau
parents:
diff changeset
55 fdct_func(block);
986e461dc072 Initial revision
glantau
parents:
diff changeset
56 if (fdct_func == jpeg_fdct_ifast) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
57 for(i=0; i<64; i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
58 scale = (1 << (AANSCALE_BITS + 11)) / aanscales[i];
986e461dc072 Initial revision
glantau
parents:
diff changeset
59 block[i] = (block[i] * scale) >> AANSCALE_BITS;
986e461dc072 Initial revision
glantau
parents:
diff changeset
60 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
61 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
62
986e461dc072 Initial revision
glantau
parents:
diff changeset
63 fdct(block1);
986e461dc072 Initial revision
glantau
parents:
diff changeset
64
986e461dc072 Initial revision
glantau
parents:
diff changeset
65 for(i=0;i<64;i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
66 v = abs(block[i] - block1[i]);
986e461dc072 Initial revision
glantau
parents:
diff changeset
67 if (v > err_inf)
986e461dc072 Initial revision
glantau
parents:
diff changeset
68 err_inf = v;
986e461dc072 Initial revision
glantau
parents:
diff changeset
69 err2 += v * v;
986e461dc072 Initial revision
glantau
parents:
diff changeset
70 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
71 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
72 printf("DCT %s: err_inf=%d err2=%0.2f\n",
986e461dc072 Initial revision
glantau
parents:
diff changeset
73 name, err_inf, (double)err2 / NB_ITS / 64.0);
986e461dc072 Initial revision
glantau
parents:
diff changeset
74
986e461dc072 Initial revision
glantau
parents:
diff changeset
75 /* speed test */
986e461dc072 Initial revision
glantau
parents:
diff changeset
76 for(i=0;i<64;i++)
986e461dc072 Initial revision
glantau
parents:
diff changeset
77 block1[i] = 255 - 63 + i;
986e461dc072 Initial revision
glantau
parents:
diff changeset
78
986e461dc072 Initial revision
glantau
parents:
diff changeset
79 ti = gettime();
986e461dc072 Initial revision
glantau
parents:
diff changeset
80 it1 = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
81 do {
986e461dc072 Initial revision
glantau
parents:
diff changeset
82 for(it=0;it<NB_ITS_SPEED;it++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
83 memcpy(block, block1, sizeof(DCTELEM) * 64);
986e461dc072 Initial revision
glantau
parents:
diff changeset
84 fdct_func(block);
986e461dc072 Initial revision
glantau
parents:
diff changeset
85 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
86 it1 += NB_ITS_SPEED;
986e461dc072 Initial revision
glantau
parents:
diff changeset
87 ti1 = gettime() - ti;
986e461dc072 Initial revision
glantau
parents:
diff changeset
88 } while (ti1 < 1000000);
986e461dc072 Initial revision
glantau
parents:
diff changeset
89
986e461dc072 Initial revision
glantau
parents:
diff changeset
90 printf("DCT %s: %0.1f kdct/s\n",
986e461dc072 Initial revision
glantau
parents:
diff changeset
91 name, (double)it1 * 1000.0 / (double)ti1);
986e461dc072 Initial revision
glantau
parents:
diff changeset
92 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
93
986e461dc072 Initial revision
glantau
parents:
diff changeset
94 int main(int argc, char **argv)
986e461dc072 Initial revision
glantau
parents:
diff changeset
95 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
96 init_fdct();
986e461dc072 Initial revision
glantau
parents:
diff changeset
97
986e461dc072 Initial revision
glantau
parents:
diff changeset
98 printf("ffmpeg DCT test\n");
986e461dc072 Initial revision
glantau
parents:
diff changeset
99
986e461dc072 Initial revision
glantau
parents:
diff changeset
100 dct_error("REF", fdct); /* only to verify code ! */
986e461dc072 Initial revision
glantau
parents:
diff changeset
101 dct_error("AAN", jpeg_fdct_ifast);
986e461dc072 Initial revision
glantau
parents:
diff changeset
102 dct_error("MMX", fdct_mmx);
986e461dc072 Initial revision
glantau
parents:
diff changeset
103 return 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
104 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
105