annotate dct-test.c @ 323:68cc7650c645 libavcodec

* minor - slightly modified debug message
author kabi
date Mon, 15 Apr 2002 12:52:21 +0000
parents 7cf705a32d1c
children 718a22dc121f
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>
33
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
9 #include <getopt.h>
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
10
986e461dc072 Initial revision
glantau
parents:
diff changeset
11 #include "dsputil.h"
986e461dc072 Initial revision
glantau
parents:
diff changeset
12
33
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
13 #include "i386/mmx.h"
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
14
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
15 /* reference fdct/idct */
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
16 extern void fdct(DCTELEM *block);
33
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
17 extern void idct(DCTELEM *block);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
18 extern void init_fdct();
986e461dc072 Initial revision
glantau
parents:
diff changeset
19
33
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
20 extern void j_rev_dct(DCTELEM *data);
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
21 extern void ff_mmx_idct(DCTELEM *data);
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
22 extern void ff_mmxext_idct(DCTELEM *data);
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
23
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
24 #define AANSCALE_BITS 12
986e461dc072 Initial revision
glantau
parents:
diff changeset
25 static const unsigned short aanscales[64] = {
986e461dc072 Initial revision
glantau
parents:
diff changeset
26 /* precomputed values scaled up by 14 bits */
986e461dc072 Initial revision
glantau
parents:
diff changeset
27 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
986e461dc072 Initial revision
glantau
parents:
diff changeset
28 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
986e461dc072 Initial revision
glantau
parents:
diff changeset
29 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
986e461dc072 Initial revision
glantau
parents:
diff changeset
30 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
986e461dc072 Initial revision
glantau
parents:
diff changeset
31 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
986e461dc072 Initial revision
glantau
parents:
diff changeset
32 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
986e461dc072 Initial revision
glantau
parents:
diff changeset
33 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
986e461dc072 Initial revision
glantau
parents:
diff changeset
34 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
986e461dc072 Initial revision
glantau
parents:
diff changeset
35 };
986e461dc072 Initial revision
glantau
parents:
diff changeset
36
986e461dc072 Initial revision
glantau
parents:
diff changeset
37 INT64 gettime(void)
986e461dc072 Initial revision
glantau
parents:
diff changeset
38 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
39 struct timeval tv;
986e461dc072 Initial revision
glantau
parents:
diff changeset
40 gettimeofday(&tv,NULL);
986e461dc072 Initial revision
glantau
parents:
diff changeset
41 return (INT64)tv.tv_sec * 1000000 + tv.tv_usec;
986e461dc072 Initial revision
glantau
parents:
diff changeset
42 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
43
986e461dc072 Initial revision
glantau
parents:
diff changeset
44 #define NB_ITS 20000
986e461dc072 Initial revision
glantau
parents:
diff changeset
45 #define NB_ITS_SPEED 50000
986e461dc072 Initial revision
glantau
parents:
diff changeset
46
33
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
47 static short idct_mmx_perm[64];
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
48
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
49 void idct_mmx_init(void)
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
50 {
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
51 int i;
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
52
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
53 /* the mmx/mmxext idct uses a reordered input, so we patch scan tables */
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
54 for (i = 0; i < 64; i++) {
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
55 idct_mmx_perm[i] = (i & 0x38) | ((i & 6) >> 1) | ((i & 1) << 2);
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
56 }
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
57 }
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
58
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
59 static DCTELEM block[64] __attribute__ ((aligned (8)));
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
60 static DCTELEM block1[64] __attribute__ ((aligned (8)));
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
61
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
62 void dct_error(const char *name, int is_idct,
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
63 void (*fdct_func)(DCTELEM *block),
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
64 void (*fdct_ref)(DCTELEM *block))
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
65 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
66 int it, i, scale;
986e461dc072 Initial revision
glantau
parents:
diff changeset
67 int err_inf, v;
986e461dc072 Initial revision
glantau
parents:
diff changeset
68 INT64 err2, ti, ti1, it1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
69
986e461dc072 Initial revision
glantau
parents:
diff changeset
70 srandom(0);
986e461dc072 Initial revision
glantau
parents:
diff changeset
71
986e461dc072 Initial revision
glantau
parents:
diff changeset
72 err_inf = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
73 err2 = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
74 for(it=0;it<NB_ITS;it++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
75 for(i=0;i<64;i++)
986e461dc072 Initial revision
glantau
parents:
diff changeset
76 block1[i] = random() % 256;
33
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
77
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
78 /* for idct test, generate inverse idct data */
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
79 if (is_idct)
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
80 fdct(block1);
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
81
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
82 if (fdct_func == ff_mmx_idct ||
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
83 fdct_func == j_rev_dct) {
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
84 for(i=0;i<64;i++)
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
85 block[idct_mmx_perm[i]] = block1[i];
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
86 } else {
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
87 memcpy(block, block1, sizeof(DCTELEM) * 64);
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
88 }
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
89
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
90 fdct_func(block);
33
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
91 emms(); /* for ff_mmx_idct */
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
92
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
93 if (fdct_func == jpeg_fdct_ifast) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
94 for(i=0; i<64; i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
95 scale = (1 << (AANSCALE_BITS + 11)) / aanscales[i];
986e461dc072 Initial revision
glantau
parents:
diff changeset
96 block[i] = (block[i] * scale) >> AANSCALE_BITS;
986e461dc072 Initial revision
glantau
parents:
diff changeset
97 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
98 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
99
33
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
100 fdct_ref(block1);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
101
986e461dc072 Initial revision
glantau
parents:
diff changeset
102 for(i=0;i<64;i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
103 v = abs(block[i] - block1[i]);
986e461dc072 Initial revision
glantau
parents:
diff changeset
104 if (v > err_inf)
986e461dc072 Initial revision
glantau
parents:
diff changeset
105 err_inf = v;
986e461dc072 Initial revision
glantau
parents:
diff changeset
106 err2 += v * v;
986e461dc072 Initial revision
glantau
parents:
diff changeset
107 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
108 }
33
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
109 printf("%s %s: err_inf=%d err2=%0.2f\n",
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
110 is_idct ? "IDCT" : "DCT",
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
111 name, err_inf, (double)err2 / NB_ITS / 64.0);
986e461dc072 Initial revision
glantau
parents:
diff changeset
112
986e461dc072 Initial revision
glantau
parents:
diff changeset
113 /* speed test */
986e461dc072 Initial revision
glantau
parents:
diff changeset
114 for(i=0;i<64;i++)
986e461dc072 Initial revision
glantau
parents:
diff changeset
115 block1[i] = 255 - 63 + i;
986e461dc072 Initial revision
glantau
parents:
diff changeset
116
33
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
117 /* for idct test, generate inverse idct data */
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
118 if (is_idct)
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
119 fdct(block1);
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
120 if (fdct_func == ff_mmx_idct ||
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
121 fdct_func == j_rev_dct) {
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
122 for(i=0;i<64;i++)
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
123 block[idct_mmx_perm[i]] = block1[i];
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
124 }
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
125
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
126 ti = gettime();
986e461dc072 Initial revision
glantau
parents:
diff changeset
127 it1 = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
128 do {
986e461dc072 Initial revision
glantau
parents:
diff changeset
129 for(it=0;it<NB_ITS_SPEED;it++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
130 memcpy(block, block1, sizeof(DCTELEM) * 64);
986e461dc072 Initial revision
glantau
parents:
diff changeset
131 fdct_func(block);
986e461dc072 Initial revision
glantau
parents:
diff changeset
132 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
133 it1 += NB_ITS_SPEED;
986e461dc072 Initial revision
glantau
parents:
diff changeset
134 ti1 = gettime() - ti;
986e461dc072 Initial revision
glantau
parents:
diff changeset
135 } while (ti1 < 1000000);
33
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
136 emms();
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
137
33
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
138 printf("%s %s: %0.1f kdct/s\n",
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
139 is_idct ? "IDCT" : "DCT",
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
140 name, (double)it1 * 1000.0 / (double)ti1);
986e461dc072 Initial revision
glantau
parents:
diff changeset
141 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
142
33
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
143 void help(void)
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
144 {
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
145 printf("dct-test [-i]\n"
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
146 "test DCT implementations\n");
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
147 exit(1);
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
148 }
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
149
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
150 int main(int argc, char **argv)
986e461dc072 Initial revision
glantau
parents:
diff changeset
151 {
33
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
152 int test_idct = 0;
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
153 int c;
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
154
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
155 init_fdct();
33
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
156 idct_mmx_init();
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
157
33
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
158 for(;;) {
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
159 c = getopt(argc, argv, "ih");
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
160 if (c == -1)
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
161 break;
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
162 switch(c) {
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
163 case 'i':
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
164 test_idct = 1;
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
165 break;
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
166 case 'h':
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
167 help();
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
168 break;
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
169 }
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
170 }
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
171
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
172 printf("ffmpeg DCT/IDCT test\n");
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
173
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
174 if (!test_idct) {
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
175 dct_error("REF", 0, fdct, fdct); /* only to verify code ! */
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
176 dct_error("AAN", 0, jpeg_fdct_ifast, fdct);
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
177 dct_error("MMX", 0, fdct_mmx, fdct);
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
178 } else {
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
179 dct_error("REF", 1, idct, idct);
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
180 dct_error("INT", 1, j_rev_dct, idct);
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
181 dct_error("MMX", 1, ff_mmx_idct, idct);
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
182 // dct_error("MMX", 1, ff_mmxext_idct, idct);
7cf705a32d1c updated dct-test to test IDCTs too
glantau
parents: 0
diff changeset
183 }
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
184 return 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
185 }