Mercurial > libavcodec.hg
annotate dct-test.c @ 633:e7b72c1dfa1b libavcodec
dct-test update
test simple-idct and ijg int DCT too
do tests with random & sparse matrixes
print systematic error matrixes
author | michaelni |
---|---|
date | Sun, 01 Sep 2002 09:33:05 +0000 |
parents | 11dbd00682fc |
children | 3e0f62e5eed6 |
rev | line source |
---|---|
429 | 1 /* DCT test. (c) 2001 Fabrice Bellard. |
0 | 2 Started from sample code by Juan J. Sierralta P. |
3 */ | |
4 #include <stdlib.h> | |
5 #include <stdio.h> | |
6 #include <string.h> | |
7 #include <sys/time.h> | |
8 #include <unistd.h> | |
33 | 9 #include <getopt.h> |
0 | 10 |
11 #include "dsputil.h" | |
12 | |
33 | 13 #include "i386/mmx.h" |
633 | 14 #include "simple_idct.h" |
33 | 15 |
16 /* reference fdct/idct */ | |
0 | 17 extern void fdct(DCTELEM *block); |
33 | 18 extern void idct(DCTELEM *block); |
0 | 19 extern void init_fdct(); |
20 | |
33 | 21 extern void j_rev_dct(DCTELEM *data); |
22 extern void ff_mmx_idct(DCTELEM *data); | |
23 extern void ff_mmxext_idct(DCTELEM *data); | |
24 | |
633 | 25 extern void odivx_idct_c (short *block); |
26 | |
0 | 27 #define AANSCALE_BITS 12 |
28 static const unsigned short aanscales[64] = { | |
29 /* precomputed values scaled up by 14 bits */ | |
30 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, | |
31 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270, | |
32 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906, | |
33 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315, | |
34 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, | |
35 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552, | |
36 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446, | |
37 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247 | |
38 }; | |
39 | |
633 | 40 UINT8 cropTbl[256 + 2 * MAX_NEG_CROP]; |
41 | |
0 | 42 INT64 gettime(void) |
43 { | |
44 struct timeval tv; | |
45 gettimeofday(&tv,NULL); | |
46 return (INT64)tv.tv_sec * 1000000 + tv.tv_usec; | |
47 } | |
48 | |
49 #define NB_ITS 20000 | |
50 #define NB_ITS_SPEED 50000 | |
51 | |
33 | 52 static short idct_mmx_perm[64]; |
53 | |
633 | 54 static short idct_simple_mmx_perm[64]={ |
55 0x00, 0x08, 0x04, 0x09, 0x01, 0x0C, 0x05, 0x0D, | |
56 0x10, 0x18, 0x14, 0x19, 0x11, 0x1C, 0x15, 0x1D, | |
57 0x20, 0x28, 0x24, 0x29, 0x21, 0x2C, 0x25, 0x2D, | |
58 0x12, 0x1A, 0x16, 0x1B, 0x13, 0x1E, 0x17, 0x1F, | |
59 0x02, 0x0A, 0x06, 0x0B, 0x03, 0x0E, 0x07, 0x0F, | |
60 0x30, 0x38, 0x34, 0x39, 0x31, 0x3C, 0x35, 0x3D, | |
61 0x22, 0x2A, 0x26, 0x2B, 0x23, 0x2E, 0x27, 0x2F, | |
62 0x32, 0x3A, 0x36, 0x3B, 0x33, 0x3E, 0x37, 0x3F, | |
63 }; | |
64 | |
33 | 65 void idct_mmx_init(void) |
66 { | |
67 int i; | |
68 | |
69 /* the mmx/mmxext idct uses a reordered input, so we patch scan tables */ | |
70 for (i = 0; i < 64; i++) { | |
71 idct_mmx_perm[i] = (i & 0x38) | ((i & 6) >> 1) | ((i & 1) << 2); | |
633 | 72 // idct_simple_mmx_perm[i] = simple_block_permute_op(i); |
33 | 73 } |
74 } | |
75 | |
76 static DCTELEM block[64] __attribute__ ((aligned (8))); | |
77 static DCTELEM block1[64] __attribute__ ((aligned (8))); | |
633 | 78 static DCTELEM block_org[64] __attribute__ ((aligned (8))); |
33 | 79 |
80 void dct_error(const char *name, int is_idct, | |
81 void (*fdct_func)(DCTELEM *block), | |
633 | 82 void (*fdct_ref)(DCTELEM *block), int test) |
0 | 83 { |
84 int it, i, scale; | |
85 int err_inf, v; | |
86 INT64 err2, ti, ti1, it1; | |
633 | 87 INT64 sysErr[64], sysErrMax=0; |
88 int maxout=0; | |
89 int max_sum=0; | |
90 int blockSumErrMax=0, blockSumErr; | |
0 | 91 |
92 srandom(0); | |
93 | |
94 err_inf = 0; | |
95 err2 = 0; | |
633 | 96 for(i=0; i<64; i++) sysErr[i]=0; |
0 | 97 for(it=0;it<NB_ITS;it++) { |
633 | 98 for(i=0;i<64;i++) |
99 block1[i] = 0; | |
100 switch(test){ | |
101 case 0: | |
102 for(i=0;i<64;i++) | |
103 block1[i] = (random() % 512) -256; | |
104 if (is_idct) | |
105 fdct(block1); | |
106 break; | |
107 case 1:{ | |
108 int num= (random()%10)+1; | |
109 for(i=0;i<num;i++) | |
110 block1[random()%64] = (random() % 512) -256; | |
111 }break; | |
112 case 2: | |
113 block1[0]= (random()%4096)-2048; | |
114 block1[63]= (block1[0]&1)^1; | |
115 break; | |
116 } | |
33 | 117 |
633 | 118 #if 0 // simulate mismatch control |
119 { int sum=0; | |
120 for(i=0;i<64;i++) | |
121 sum+=block1[i]; | |
122 | |
123 if((sum&1)==0) block1[63]^=1; | |
124 } | |
125 #endif | |
126 | |
127 for(i=0; i<64; i++) | |
128 block_org[i]= block1[i]; | |
33 | 129 |
130 if (fdct_func == ff_mmx_idct || | |
633 | 131 fdct_func == j_rev_dct || fdct_func == ff_mmxext_idct) { |
132 for(i=0;i<64;i++) | |
33 | 133 block[idct_mmx_perm[i]] = block1[i]; |
633 | 134 } else if(fdct_func == simple_idct_mmx ) { |
135 for(i=0;i<64;i++) | |
136 block[idct_simple_mmx_perm[i]] = block1[i]; | |
137 | |
138 } else { | |
139 for(i=0; i<64; i++) | |
140 block[i]= block1[i]; | |
33 | 141 } |
633 | 142 #if 0 // simulate mismatch control for tested IDCT but not the ref |
143 { int sum=0; | |
144 for(i=0;i<64;i++) | |
145 sum+=block[i]; | |
146 | |
147 if((sum&1)==0) block[63]^=1; | |
148 } | |
149 #endif | |
33 | 150 |
0 | 151 fdct_func(block); |
33 | 152 emms(); /* for ff_mmx_idct */ |
153 | |
474
11dbd00682fc
avoid name clash with libjpeg - added missing externs
bellard
parents:
429
diff
changeset
|
154 if (fdct_func == fdct_ifast) { |
0 | 155 for(i=0; i<64; i++) { |
156 scale = (1 << (AANSCALE_BITS + 11)) / aanscales[i]; | |
633 | 157 block[i] = (block[i] * scale /*+ (1<<(AANSCALE_BITS-1))*/) >> AANSCALE_BITS; |
158 } | |
159 } | |
160 | |
161 if (fdct_func == ff_jpeg_fdct_islow) { | |
162 for(i=0; i<64; i++) { | |
163 block[i] = (block[i]+3)>>3; | |
0 | 164 } |
165 } | |
166 | |
33 | 167 fdct_ref(block1); |
0 | 168 |
633 | 169 blockSumErr=0; |
0 | 170 for(i=0;i<64;i++) { |
171 v = abs(block[i] - block1[i]); | |
172 if (v > err_inf) | |
173 err_inf = v; | |
174 err2 += v * v; | |
633 | 175 sysErr[i] += block[i] - block1[i]; |
176 blockSumErr += v; | |
177 if( abs(block[i])>maxout) maxout=abs(block[i]); | |
0 | 178 } |
633 | 179 if(blockSumErrMax < blockSumErr) blockSumErrMax= blockSumErr; |
180 #if 0 // print different matrix pairs | |
181 if(blockSumErr){ | |
182 printf("\n"); | |
183 for(i=0; i<64; i++){ | |
184 if((i&7)==0) printf("\n"); | |
185 printf("%4d ", block_org[i]); | |
186 } | |
187 for(i=0; i<64; i++){ | |
188 if((i&7)==0) printf("\n"); | |
189 printf("%4d ", block[i] - block1[i]); | |
190 } | |
191 } | |
192 #endif | |
0 | 193 } |
633 | 194 for(i=0; i<64; i++) sysErrMax= MAX(sysErrMax, ABS(sysErr[i])); |
195 | |
196 #if 1 // dump systematic errors | |
197 for(i=0; i<64; i++){ | |
198 if(i%8==0) printf("\n"); | |
199 printf("%5d ", (int)sysErr[i]); | |
200 } | |
201 printf("\n"); | |
202 #endif | |
203 | |
204 printf("%s %s: err_inf=%d err2=%0.8f syserr=%0.8f maxout=%d blockSumErr=%d\n", | |
33 | 205 is_idct ? "IDCT" : "DCT", |
633 | 206 name, err_inf, (double)err2 / NB_ITS / 64.0, (double)sysErrMax / NB_ITS, maxout, blockSumErrMax); |
207 #if 1 //Speed test | |
0 | 208 /* speed test */ |
633 | 209 for(i=0;i<64;i++) |
210 block1[i] = 0; | |
211 switch(test){ | |
212 case 0: | |
213 for(i=0;i<64;i++) | |
214 block1[i] = (random() % 512) -256; | |
215 if (is_idct) | |
216 fdct(block1); | |
217 break; | |
218 case 1:{ | |
219 case 2: | |
220 block1[0] = (random() % 512) -256; | |
221 block1[1] = (random() % 512) -256; | |
222 block1[2] = (random() % 512) -256; | |
223 block1[3] = (random() % 512) -256; | |
224 }break; | |
225 } | |
0 | 226 |
33 | 227 if (fdct_func == ff_mmx_idct || |
633 | 228 fdct_func == j_rev_dct || fdct_func == ff_mmxext_idct) { |
229 for(i=0;i<64;i++) | |
33 | 230 block[idct_mmx_perm[i]] = block1[i]; |
633 | 231 } else if(fdct_func == simple_idct_mmx ) { |
232 for(i=0;i<64;i++) | |
233 block[idct_simple_mmx_perm[i]] = block1[i]; | |
234 } else { | |
235 for(i=0; i<64; i++) | |
236 block[i]= block1[i]; | |
33 | 237 } |
238 | |
0 | 239 ti = gettime(); |
240 it1 = 0; | |
241 do { | |
242 for(it=0;it<NB_ITS_SPEED;it++) { | |
633 | 243 for(i=0; i<64; i++) |
244 block[i]= block1[i]; | |
245 // memcpy(block, block1, sizeof(DCTELEM) * 64); | |
246 // dont memcpy especially not fastmemcpy because it does movntq !!! | |
0 | 247 fdct_func(block); |
248 } | |
249 it1 += NB_ITS_SPEED; | |
250 ti1 = gettime() - ti; | |
251 } while (ti1 < 1000000); | |
33 | 252 emms(); |
0 | 253 |
633 | 254 printf("%s %s: %0.1f kdct/s\n", |
33 | 255 is_idct ? "IDCT" : "DCT", |
0 | 256 name, (double)it1 * 1000.0 / (double)ti1); |
633 | 257 #endif |
0 | 258 } |
259 | |
33 | 260 void help(void) |
261 { | |
633 | 262 printf("dct-test [-i] [<test-number>]\n" |
263 "test-number 0 -> test with random matrixes\n" | |
264 " 1 -> test with random sparse matrixes\n" | |
265 " 2 -> do 3. test from mpeg4 std\n" | |
266 "-i test IDCT implementations\n"); | |
33 | 267 exit(1); |
268 } | |
269 | |
0 | 270 int main(int argc, char **argv) |
271 { | |
33 | 272 int test_idct = 0; |
633 | 273 int c,i; |
274 int test=1; | |
33 | 275 |
0 | 276 init_fdct(); |
33 | 277 idct_mmx_init(); |
0 | 278 |
633 | 279 for(i=0;i<256;i++) cropTbl[i + MAX_NEG_CROP] = i; |
280 for(i=0;i<MAX_NEG_CROP;i++) { | |
281 cropTbl[i] = 0; | |
282 cropTbl[i + MAX_NEG_CROP + 256] = 255; | |
283 } | |
284 | |
33 | 285 for(;;) { |
286 c = getopt(argc, argv, "ih"); | |
287 if (c == -1) | |
288 break; | |
289 switch(c) { | |
290 case 'i': | |
291 test_idct = 1; | |
292 break; | |
633 | 293 default : |
33 | 294 case 'h': |
295 help(); | |
296 break; | |
297 } | |
298 } | |
633 | 299 |
300 if(optind <argc) test= atoi(argv[optind]); | |
33 | 301 |
302 printf("ffmpeg DCT/IDCT test\n"); | |
303 | |
304 if (!test_idct) { | |
633 | 305 dct_error("REF-DBL", 0, fdct, fdct, test); /* only to verify code ! */ |
306 dct_error("IJG-AAN-INT", 0, fdct_ifast, fdct, test); | |
307 dct_error("IJG-LLM-INT", 0, ff_jpeg_fdct_islow, fdct, test); | |
308 dct_error("MMX", 0, fdct_mmx, fdct, test); | |
33 | 309 } else { |
633 | 310 dct_error("REF-DBL", 1, idct, idct, test); |
311 dct_error("INT", 1, j_rev_dct, idct, test); | |
312 dct_error("LIBMPEG2-MMX", 1, ff_mmx_idct, idct, test); | |
313 dct_error("LIBMPEG2-MMXEXT", 1, ff_mmxext_idct, idct, test); | |
314 dct_error("SIMPLE-C", 1, simple_idct, idct, test); | |
315 dct_error("SIMPLE-MMX", 1, simple_idct_mmx, idct, test); | |
316 // dct_error("ODIVX-C", 1, odivx_idct_c, idct); | |
317 //printf(" test against odivx idct\n"); | |
318 // dct_error("REF", 1, idct, odivx_idct_c); | |
319 // dct_error("INT", 1, j_rev_dct, odivx_idct_c); | |
320 // dct_error("MMX", 1, ff_mmx_idct, odivx_idct_c); | |
321 // dct_error("MMXEXT", 1, ff_mmxext_idct, odivx_idct_c); | |
322 // dct_error("SIMPLE-C", 1, simple_idct, odivx_idct_c); | |
323 // dct_error("SIMPLE-MMX", 1, simple_idct_mmx, odivx_idct_c); | |
324 // dct_error("ODIVX-C", 1, odivx_idct_c, odivx_idct_c); | |
33 | 325 } |
0 | 326 return 0; |
327 } |