Mercurial > libavcodec.hg
annotate dct-test.c @ 4991:b77f43ff3991 libavcodec
Remove redundant extern declaration of j_rev_dct that is already
present in the #included header file dsputil.h.
author | diego |
---|---|
date | Sat, 12 May 2007 10:53:33 +0000 |
parents | b7c27288e509 |
children | ffff8f4a0601 |
rev | line source |
---|---|
3699
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
3398
diff
changeset
|
1 /* |
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
3398
diff
changeset
|
2 * (c) 2001 Fabrice Bellard |
4755
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
3 * 2007 Marc Hoffman <marc.hoffman@analog.com> |
3699
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
3398
diff
changeset
|
4 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3699
diff
changeset
|
5 * This file is part of FFmpeg. |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3699
diff
changeset
|
6 * |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3699
diff
changeset
|
7 * FFmpeg is free software; you can redistribute it and/or |
3699
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
3398
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public |
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
3398
diff
changeset
|
9 * License as published by the Free Software Foundation; either |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3699
diff
changeset
|
10 * version 2.1 of the License, or (at your option) any later version. |
3699
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
3398
diff
changeset
|
11 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3699
diff
changeset
|
12 * FFmpeg is distributed in the hope that it will be useful, |
3699
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
3398
diff
changeset
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
3398
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
3398
diff
changeset
|
15 * Lesser General Public License for more details. |
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
3398
diff
changeset
|
16 * |
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
3398
diff
changeset
|
17 * You should have received a copy of the GNU Lesser General Public |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3699
diff
changeset
|
18 * License along with FFmpeg; if not, write to the Free Software |
3699
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
3398
diff
changeset
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
3398
diff
changeset
|
20 */ |
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
3398
diff
changeset
|
21 |
1106 | 22 /** |
23 * @file dct-test.c | |
2967 | 24 * DCT test. (c) 2001 Fabrice Bellard. |
1106 | 25 * Started from sample code by Juan J. Sierralta P. |
26 */ | |
27 | |
0 | 28 #include <stdlib.h> |
29 #include <stdio.h> | |
30 #include <string.h> | |
31 #include <sys/time.h> | |
32 #include <unistd.h> | |
33 | |
34 #include "dsputil.h" | |
35 | |
633 | 36 #include "simple_idct.h" |
1557 | 37 #include "faandct.h" |
33 | 38 |
980 | 39 #ifndef MAX |
40 #define MAX(a, b) (((a) > (b)) ? (a) : (b)) | |
41 #endif | |
42 | |
2872 | 43 #undef printf |
44 | |
45 void *fast_memcpy(void *a, const void *b, size_t c){return memcpy(a,b,c);}; | |
46 | |
33 | 47 /* reference fdct/idct */ |
0 | 48 extern void fdct(DCTELEM *block); |
33 | 49 extern void idct(DCTELEM *block); |
2872 | 50 extern void ff_idct_xvid_mmx(DCTELEM *block); |
51 extern void ff_idct_xvid_mmx2(DCTELEM *block); | |
0 | 52 extern void init_fdct(); |
53 | |
33 | 54 extern void ff_mmx_idct(DCTELEM *data); |
55 extern void ff_mmxext_idct(DCTELEM *data); | |
56 | |
633 | 57 extern void odivx_idct_c (short *block); |
58 | |
4755
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
59 // BFIN |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
60 extern void ff_bfin_idct (DCTELEM *block) ; |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
61 extern void ff_bfin_fdct (DCTELEM *block) ; |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
62 |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
63 // ALTIVEC |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
64 extern void fdct_altivec (DCTELEM *block); |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
65 //extern void idct_altivec (DCTELEM *block);?? no routine |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
66 |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
67 |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
68 struct algo { |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
69 char *name; |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
70 enum { FDCT, IDCT } is_idct; |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
71 void (* func) (DCTELEM *block); |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
72 void (* ref) (DCTELEM *block); |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
73 enum formattag { NO_PERM,MMX_PERM, MMX_SIMPLE_PERM, SCALE_PERM } format; |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
74 }; |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
75 |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
76 #ifndef FAAN_POSTSCALE |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
77 #define FAAN_SCALE SCALE_PERM |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
78 #else |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
79 #define FAAN_SCALE NO_PERM |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
80 #endif |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
81 |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
82 #define DCT_ERROR(name,is_idct,func,ref,form) {name,is_idct,func,ref,form} |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
83 |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
84 |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
85 struct algo algos[] = { |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
86 DCT_ERROR( "REF-DBL", 0, fdct, fdct, NO_PERM), |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
87 DCT_ERROR("IJG-AAN-INT", 0, fdct_ifast, fdct, SCALE_PERM), |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
88 DCT_ERROR("IJG-LLM-INT", 0, ff_jpeg_fdct_islow, fdct, NO_PERM), |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
89 DCT_ERROR("REF-DBL", 1, idct, idct, NO_PERM), |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
90 DCT_ERROR("INT", 1, j_rev_dct, idct, MMX_PERM), |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
91 DCT_ERROR("SIMPLE-C", 1, simple_idct, idct, NO_PERM), |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
92 |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
93 #ifdef ARCH_X86 |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
94 DCT_ERROR("MMX", 0, ff_fdct_mmx, fdct, NO_PERM), |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
95 DCT_ERROR("MMX2", 0, ff_fdct_mmx2, fdct, NO_PERM), |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
96 DCT_ERROR("FAAN", 0, ff_faandct, fdct, FAAN_SCALE), |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
97 |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
98 DCT_ERROR("LIBMPEG2-MMX", 1, ff_mmx_idct, idct, MMX_PERM), |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
99 DCT_ERROR("LIBMPEG2-MMXEXT", 1, ff_mmxext_idct, idct, MMX_PERM), |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
100 DCT_ERROR("SIMPLE-MMX", 1, ff_simple_idct_mmx, idct, MMX_SIMPLE_PERM), |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
101 DCT_ERROR("XVID-MMX", 1, ff_idct_xvid_mmx, idct, NO_PERM), |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
102 DCT_ERROR("XVID-MMX2", 1, ff_idct_xvid_mmx2, idct, NO_PERM), |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
103 #endif |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
104 |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
105 #ifdef HAVE_ALTIVEC |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
106 DCT_ERROR("altivecfdct", 0, fdct_altivec, fdct, NO_PERM), |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
107 #endif |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
108 |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
109 #ifdef ARCH_BFIN |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
110 DCT_ERROR("BFINfdct", 0, ff_bfin_fdct, fdct, NO_PERM), |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
111 DCT_ERROR("BFINidct", 1, ff_bfin_idct, idct, NO_PERM), |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
112 #endif |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
113 |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
114 { 0 } |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
115 }; |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
116 |
0 | 117 #define AANSCALE_BITS 12 |
118 static const unsigned short aanscales[64] = { | |
119 /* precomputed values scaled up by 14 bits */ | |
120 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, | |
121 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270, | |
122 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906, | |
123 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315, | |
124 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, | |
125 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552, | |
126 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446, | |
127 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247 | |
128 }; | |
129 | |
4197 | 130 uint8_t cropTbl[256 + 2 * MAX_NEG_CROP]; |
633 | 131 |
1064 | 132 int64_t gettime(void) |
0 | 133 { |
134 struct timeval tv; | |
135 gettimeofday(&tv,NULL); | |
1064 | 136 return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec; |
0 | 137 } |
138 | |
139 #define NB_ITS 20000 | |
140 #define NB_ITS_SPEED 50000 | |
141 | |
33 | 142 static short idct_mmx_perm[64]; |
143 | |
633 | 144 static short idct_simple_mmx_perm[64]={ |
2979 | 145 0x00, 0x08, 0x04, 0x09, 0x01, 0x0C, 0x05, 0x0D, |
146 0x10, 0x18, 0x14, 0x19, 0x11, 0x1C, 0x15, 0x1D, | |
147 0x20, 0x28, 0x24, 0x29, 0x21, 0x2C, 0x25, 0x2D, | |
148 0x12, 0x1A, 0x16, 0x1B, 0x13, 0x1E, 0x17, 0x1F, | |
149 0x02, 0x0A, 0x06, 0x0B, 0x03, 0x0E, 0x07, 0x0F, | |
150 0x30, 0x38, 0x34, 0x39, 0x31, 0x3C, 0x35, 0x3D, | |
151 0x22, 0x2A, 0x26, 0x2B, 0x23, 0x2E, 0x27, 0x2F, | |
152 0x32, 0x3A, 0x36, 0x3B, 0x33, 0x3E, 0x37, 0x3F, | |
633 | 153 }; |
154 | |
33 | 155 void idct_mmx_init(void) |
156 { | |
157 int i; | |
158 | |
159 /* the mmx/mmxext idct uses a reordered input, so we patch scan tables */ | |
160 for (i = 0; i < 64; i++) { | |
2979 | 161 idct_mmx_perm[i] = (i & 0x38) | ((i & 6) >> 1) | ((i & 1) << 2); |
162 // idct_simple_mmx_perm[i] = simple_block_permute_op(i); | |
33 | 163 } |
164 } | |
165 | |
166 static DCTELEM block[64] __attribute__ ((aligned (8))); | |
167 static DCTELEM block1[64] __attribute__ ((aligned (8))); | |
633 | 168 static DCTELEM block_org[64] __attribute__ ((aligned (8))); |
33 | 169 |
170 void dct_error(const char *name, int is_idct, | |
171 void (*fdct_func)(DCTELEM *block), | |
4755
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
172 void (*fdct_ref)(DCTELEM *block), int form, int test) |
0 | 173 { |
174 int it, i, scale; | |
175 int err_inf, v; | |
1064 | 176 int64_t err2, ti, ti1, it1; |
177 int64_t sysErr[64], sysErrMax=0; | |
633 | 178 int maxout=0; |
179 int blockSumErrMax=0, blockSumErr; | |
0 | 180 |
181 srandom(0); | |
182 | |
183 err_inf = 0; | |
184 err2 = 0; | |
633 | 185 for(i=0; i<64; i++) sysErr[i]=0; |
0 | 186 for(it=0;it<NB_ITS;it++) { |
633 | 187 for(i=0;i<64;i++) |
188 block1[i] = 0; | |
189 switch(test){ | |
2967 | 190 case 0: |
633 | 191 for(i=0;i<64;i++) |
192 block1[i] = (random() % 512) -256; | |
635 | 193 if (is_idct){ |
633 | 194 fdct(block1); |
635 | 195 |
196 for(i=0;i<64;i++) | |
197 block1[i]>>=3; | |
198 } | |
633 | 199 break; |
200 case 1:{ | |
201 int num= (random()%10)+1; | |
202 for(i=0;i<num;i++) | |
203 block1[random()%64] = (random() % 512) -256; | |
204 }break; | |
205 case 2: | |
206 block1[0]= (random()%4096)-2048; | |
207 block1[63]= (block1[0]&1)^1; | |
208 break; | |
209 } | |
33 | 210 |
633 | 211 #if 0 // simulate mismatch control |
212 { int sum=0; | |
213 for(i=0;i<64;i++) | |
214 sum+=block1[i]; | |
215 | |
2967 | 216 if((sum&1)==0) block1[63]^=1; |
633 | 217 } |
218 #endif | |
219 | |
220 for(i=0; i<64; i++) | |
221 block_org[i]= block1[i]; | |
33 | 222 |
4755
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
223 if (form == MMX_PERM) { |
633 | 224 for(i=0;i<64;i++) |
33 | 225 block[idct_mmx_perm[i]] = block1[i]; |
4755
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
226 } else if (form == MMX_SIMPLE_PERM) { |
633 | 227 for(i=0;i<64;i++) |
228 block[idct_simple_mmx_perm[i]] = block1[i]; | |
229 | |
2979 | 230 } else { |
633 | 231 for(i=0; i<64; i++) |
232 block[i]= block1[i]; | |
33 | 233 } |
633 | 234 #if 0 // simulate mismatch control for tested IDCT but not the ref |
235 { int sum=0; | |
236 for(i=0;i<64;i++) | |
237 sum+=block[i]; | |
238 | |
2967 | 239 if((sum&1)==0) block[63]^=1; |
633 | 240 } |
241 #endif | |
33 | 242 |
0 | 243 fdct_func(block); |
4752
d49f8b3e8c4a
Replace emms() with emms_c(), patch by Marc Hoffman, mmh pleasantst com.
diego
parents:
4197
diff
changeset
|
244 emms_c(); /* for ff_mmx_idct */ |
33 | 245 |
4755
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
246 if (form == SCALE_PERM) { |
0 | 247 for(i=0; i<64; i++) { |
635 | 248 scale = 8*(1 << (AANSCALE_BITS + 11)) / aanscales[i]; |
633 | 249 block[i] = (block[i] * scale /*+ (1<<(AANSCALE_BITS-1))*/) >> AANSCALE_BITS; |
250 } | |
251 } | |
252 | |
33 | 253 fdct_ref(block1); |
0 | 254 |
633 | 255 blockSumErr=0; |
0 | 256 for(i=0;i<64;i++) { |
257 v = abs(block[i] - block1[i]); | |
258 if (v > err_inf) | |
259 err_inf = v; | |
260 err2 += v * v; | |
2979 | 261 sysErr[i] += block[i] - block1[i]; |
262 blockSumErr += v; | |
263 if( abs(block[i])>maxout) maxout=abs(block[i]); | |
0 | 264 } |
633 | 265 if(blockSumErrMax < blockSumErr) blockSumErrMax= blockSumErr; |
266 #if 0 // print different matrix pairs | |
267 if(blockSumErr){ | |
268 printf("\n"); | |
269 for(i=0; i<64; i++){ | |
270 if((i&7)==0) printf("\n"); | |
271 printf("%4d ", block_org[i]); | |
272 } | |
273 for(i=0; i<64; i++){ | |
274 if((i&7)==0) printf("\n"); | |
275 printf("%4d ", block[i] - block1[i]); | |
276 } | |
277 } | |
278 #endif | |
0 | 279 } |
4001 | 280 for(i=0; i<64; i++) sysErrMax= MAX(sysErrMax, FFABS(sysErr[i])); |
2967 | 281 |
633 | 282 #if 1 // dump systematic errors |
283 for(i=0; i<64; i++){ | |
2979 | 284 if(i%8==0) printf("\n"); |
633 | 285 printf("%5d ", (int)sysErr[i]); |
286 } | |
287 printf("\n"); | |
288 #endif | |
2967 | 289 |
633 | 290 printf("%s %s: err_inf=%d err2=%0.8f syserr=%0.8f maxout=%d blockSumErr=%d\n", |
33 | 291 is_idct ? "IDCT" : "DCT", |
633 | 292 name, err_inf, (double)err2 / NB_ITS / 64.0, (double)sysErrMax / NB_ITS, maxout, blockSumErrMax); |
293 #if 1 //Speed test | |
0 | 294 /* speed test */ |
633 | 295 for(i=0;i<64;i++) |
296 block1[i] = 0; | |
297 switch(test){ | |
2967 | 298 case 0: |
633 | 299 for(i=0;i<64;i++) |
300 block1[i] = (random() % 512) -256; | |
635 | 301 if (is_idct){ |
633 | 302 fdct(block1); |
635 | 303 |
304 for(i=0;i<64;i++) | |
305 block1[i]>>=3; | |
306 } | |
633 | 307 break; |
308 case 1:{ | |
309 case 2: | |
310 block1[0] = (random() % 512) -256; | |
311 block1[1] = (random() % 512) -256; | |
312 block1[2] = (random() % 512) -256; | |
313 block1[3] = (random() % 512) -256; | |
314 }break; | |
315 } | |
0 | 316 |
4755
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
317 if (form == MMX_PERM) { |
633 | 318 for(i=0;i<64;i++) |
33 | 319 block[idct_mmx_perm[i]] = block1[i]; |
4755
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
320 } else if(form == MMX_SIMPLE_PERM) { |
633 | 321 for(i=0;i<64;i++) |
322 block[idct_simple_mmx_perm[i]] = block1[i]; | |
323 } else { | |
324 for(i=0; i<64; i++) | |
325 block[i]= block1[i]; | |
33 | 326 } |
327 | |
0 | 328 ti = gettime(); |
329 it1 = 0; | |
330 do { | |
331 for(it=0;it<NB_ITS_SPEED;it++) { | |
633 | 332 for(i=0; i<64; i++) |
333 block[i]= block1[i]; | |
334 // memcpy(block, block1, sizeof(DCTELEM) * 64); | |
335 // dont memcpy especially not fastmemcpy because it does movntq !!! | |
0 | 336 fdct_func(block); |
337 } | |
338 it1 += NB_ITS_SPEED; | |
339 ti1 = gettime() - ti; | |
340 } while (ti1 < 1000000); | |
4752
d49f8b3e8c4a
Replace emms() with emms_c(), patch by Marc Hoffman, mmh pleasantst com.
diego
parents:
4197
diff
changeset
|
341 emms_c(); |
0 | 342 |
633 | 343 printf("%s %s: %0.1f kdct/s\n", |
33 | 344 is_idct ? "IDCT" : "DCT", |
0 | 345 name, (double)it1 * 1000.0 / (double)ti1); |
633 | 346 #endif |
0 | 347 } |
348 | |
1064 | 349 static uint8_t img_dest[64] __attribute__ ((aligned (8))); |
350 static uint8_t img_dest1[64] __attribute__ ((aligned (8))); | |
720 | 351 |
1064 | 352 void idct248_ref(uint8_t *dest, int linesize, int16_t *block) |
720 | 353 { |
354 static int init; | |
355 static double c8[8][8]; | |
356 static double c4[4][4]; | |
357 double block1[64], block2[64], block3[64]; | |
358 double s, sum, v; | |
359 int i, j, k; | |
360 | |
361 if (!init) { | |
362 init = 1; | |
363 | |
364 for(i=0;i<8;i++) { | |
365 sum = 0; | |
366 for(j=0;j<8;j++) { | |
367 s = (i==0) ? sqrt(1.0/8.0) : sqrt(1.0/4.0); | |
368 c8[i][j] = s * cos(M_PI * i * (j + 0.5) / 8.0); | |
369 sum += c8[i][j] * c8[i][j]; | |
370 } | |
371 } | |
2967 | 372 |
720 | 373 for(i=0;i<4;i++) { |
374 sum = 0; | |
375 for(j=0;j<4;j++) { | |
376 s = (i==0) ? sqrt(1.0/4.0) : sqrt(1.0/2.0); | |
377 c4[i][j] = s * cos(M_PI * i * (j + 0.5) / 4.0); | |
378 sum += c4[i][j] * c4[i][j]; | |
379 } | |
380 } | |
381 } | |
382 | |
383 /* butterfly */ | |
722
ff90043f4a2d
in fact IDCT248 needs to be normalized as I suspected
bellard
parents:
720
diff
changeset
|
384 s = 0.5 * sqrt(2.0); |
720 | 385 for(i=0;i<4;i++) { |
386 for(j=0;j<8;j++) { | |
722
ff90043f4a2d
in fact IDCT248 needs to be normalized as I suspected
bellard
parents:
720
diff
changeset
|
387 block1[8*(2*i)+j] = (block[8*(2*i)+j] + block[8*(2*i+1)+j]) * s; |
ff90043f4a2d
in fact IDCT248 needs to be normalized as I suspected
bellard
parents:
720
diff
changeset
|
388 block1[8*(2*i+1)+j] = (block[8*(2*i)+j] - block[8*(2*i+1)+j]) * s; |
720 | 389 } |
390 } | |
391 | |
392 /* idct8 on lines */ | |
393 for(i=0;i<8;i++) { | |
394 for(j=0;j<8;j++) { | |
395 sum = 0; | |
396 for(k=0;k<8;k++) | |
397 sum += c8[k][j] * block1[8*i+k]; | |
398 block2[8*i+j] = sum; | |
399 } | |
400 } | |
401 | |
402 /* idct4 */ | |
403 for(i=0;i<8;i++) { | |
404 for(j=0;j<4;j++) { | |
405 /* top */ | |
406 sum = 0; | |
407 for(k=0;k<4;k++) | |
408 sum += c4[k][j] * block2[8*(2*k)+i]; | |
409 block3[8*(2*j)+i] = sum; | |
410 | |
411 /* bottom */ | |
412 sum = 0; | |
413 for(k=0;k<4;k++) | |
414 sum += c4[k][j] * block2[8*(2*k+1)+i]; | |
415 block3[8*(2*j+1)+i] = sum; | |
416 } | |
417 } | |
418 | |
419 /* clamp and store the result */ | |
420 for(i=0;i<8;i++) { | |
421 for(j=0;j<8;j++) { | |
722
ff90043f4a2d
in fact IDCT248 needs to be normalized as I suspected
bellard
parents:
720
diff
changeset
|
422 v = block3[8*i+j]; |
720 | 423 if (v < 0) |
424 v = 0; | |
425 else if (v > 255) | |
426 v = 255; | |
427 dest[i * linesize + j] = (int)rint(v); | |
428 } | |
429 } | |
430 } | |
431 | |
2967 | 432 void idct248_error(const char *name, |
1064 | 433 void (*idct248_put)(uint8_t *dest, int line_size, int16_t *block)) |
720 | 434 { |
435 int it, i, it1, ti, ti1, err_max, v; | |
436 | |
437 srandom(0); | |
2967 | 438 |
720 | 439 /* just one test to see if code is correct (precision is less |
440 important here) */ | |
441 err_max = 0; | |
442 for(it=0;it<NB_ITS;it++) { | |
2967 | 443 |
722
ff90043f4a2d
in fact IDCT248 needs to be normalized as I suspected
bellard
parents:
720
diff
changeset
|
444 /* XXX: use forward transform to generate values */ |
720 | 445 for(i=0;i<64;i++) |
722
ff90043f4a2d
in fact IDCT248 needs to be normalized as I suspected
bellard
parents:
720
diff
changeset
|
446 block1[i] = (random() % 256) - 128; |
ff90043f4a2d
in fact IDCT248 needs to be normalized as I suspected
bellard
parents:
720
diff
changeset
|
447 block1[0] += 1024; |
ff90043f4a2d
in fact IDCT248 needs to be normalized as I suspected
bellard
parents:
720
diff
changeset
|
448 |
720 | 449 for(i=0; i<64; i++) |
450 block[i]= block1[i]; | |
451 idct248_ref(img_dest1, 8, block); | |
2967 | 452 |
722
ff90043f4a2d
in fact IDCT248 needs to be normalized as I suspected
bellard
parents:
720
diff
changeset
|
453 for(i=0; i<64; i++) |
ff90043f4a2d
in fact IDCT248 needs to be normalized as I suspected
bellard
parents:
720
diff
changeset
|
454 block[i]= block1[i]; |
ff90043f4a2d
in fact IDCT248 needs to be normalized as I suspected
bellard
parents:
720
diff
changeset
|
455 idct248_put(img_dest, 8, block); |
2967 | 456 |
722
ff90043f4a2d
in fact IDCT248 needs to be normalized as I suspected
bellard
parents:
720
diff
changeset
|
457 for(i=0;i<64;i++) { |
ff90043f4a2d
in fact IDCT248 needs to be normalized as I suspected
bellard
parents:
720
diff
changeset
|
458 v = abs((int)img_dest[i] - (int)img_dest1[i]); |
ff90043f4a2d
in fact IDCT248 needs to be normalized as I suspected
bellard
parents:
720
diff
changeset
|
459 if (v == 255) |
ff90043f4a2d
in fact IDCT248 needs to be normalized as I suspected
bellard
parents:
720
diff
changeset
|
460 printf("%d %d\n", img_dest[i], img_dest1[i]); |
ff90043f4a2d
in fact IDCT248 needs to be normalized as I suspected
bellard
parents:
720
diff
changeset
|
461 if (v > err_max) |
ff90043f4a2d
in fact IDCT248 needs to be normalized as I suspected
bellard
parents:
720
diff
changeset
|
462 err_max = v; |
ff90043f4a2d
in fact IDCT248 needs to be normalized as I suspected
bellard
parents:
720
diff
changeset
|
463 } |
720 | 464 #if 0 |
465 printf("ref=\n"); | |
466 for(i=0;i<8;i++) { | |
467 int j; | |
468 for(j=0;j<8;j++) { | |
469 printf(" %3d", img_dest1[i*8+j]); | |
470 } | |
471 printf("\n"); | |
472 } | |
2967 | 473 |
720 | 474 printf("out=\n"); |
475 for(i=0;i<8;i++) { | |
476 int j; | |
477 for(j=0;j<8;j++) { | |
478 printf(" %3d", img_dest[i*8+j]); | |
479 } | |
480 printf("\n"); | |
481 } | |
482 #endif | |
483 } | |
484 printf("%s %s: err_inf=%d\n", | |
485 1 ? "IDCT248" : "DCT248", | |
486 name, err_max); | |
487 | |
488 ti = gettime(); | |
489 it1 = 0; | |
490 do { | |
491 for(it=0;it<NB_ITS_SPEED;it++) { | |
492 for(i=0; i<64; i++) | |
493 block[i]= block1[i]; | |
494 // memcpy(block, block1, sizeof(DCTELEM) * 64); | |
495 // dont memcpy especially not fastmemcpy because it does movntq !!! | |
496 idct248_put(img_dest, 8, block); | |
497 } | |
498 it1 += NB_ITS_SPEED; | |
499 ti1 = gettime() - ti; | |
500 } while (ti1 < 1000000); | |
4752
d49f8b3e8c4a
Replace emms() with emms_c(), patch by Marc Hoffman, mmh pleasantst com.
diego
parents:
4197
diff
changeset
|
501 emms_c(); |
720 | 502 |
503 printf("%s %s: %0.1f kdct/s\n", | |
504 1 ? "IDCT248" : "DCT248", | |
505 name, (double)it1 * 1000.0 / (double)ti1); | |
506 } | |
507 | |
33 | 508 void help(void) |
509 { | |
633 | 510 printf("dct-test [-i] [<test-number>]\n" |
511 "test-number 0 -> test with random matrixes\n" | |
512 " 1 -> test with random sparse matrixes\n" | |
513 " 2 -> do 3. test from mpeg4 std\n" | |
720 | 514 "-i test IDCT implementations\n" |
515 "-4 test IDCT248 implementations\n"); | |
33 | 516 } |
517 | |
0 | 518 int main(int argc, char **argv) |
519 { | |
720 | 520 int test_idct = 0, test_248_dct = 0; |
633 | 521 int c,i; |
522 int test=1; | |
33 | 523 |
0 | 524 init_fdct(); |
33 | 525 idct_mmx_init(); |
0 | 526 |
4197 | 527 for(i=0;i<256;i++) cropTbl[i + MAX_NEG_CROP] = i; |
633 | 528 for(i=0;i<MAX_NEG_CROP;i++) { |
4197 | 529 cropTbl[i] = 0; |
530 cropTbl[i + MAX_NEG_CROP + 256] = 255; | |
633 | 531 } |
2967 | 532 |
33 | 533 for(;;) { |
720 | 534 c = getopt(argc, argv, "ih4"); |
33 | 535 if (c == -1) |
536 break; | |
537 switch(c) { | |
538 case 'i': | |
539 test_idct = 1; | |
540 break; | |
720 | 541 case '4': |
542 test_248_dct = 1; | |
543 break; | |
633 | 544 default : |
33 | 545 case 'h': |
546 help(); | |
4754 | 547 return 0; |
33 | 548 } |
549 } | |
2967 | 550 |
633 | 551 if(optind <argc) test= atoi(argv[optind]); |
2967 | 552 |
33 | 553 printf("ffmpeg DCT/IDCT test\n"); |
554 | |
720 | 555 if (test_248_dct) { |
556 idct248_error("SIMPLE-C", simple_idct248_put); | |
33 | 557 } else { |
4755
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
558 for (i=0;algos[i].name;i++) |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
559 if (algos[i].is_idct == test_idct) { |
b7c27288e509
platform-independent restructuring and code simplification
diego
parents:
4754
diff
changeset
|
560 dct_error (algos[i].name, algos[i].is_idct, algos[i].func, algos[i].ref, algos[i].format, test); |
720 | 561 } |
33 | 562 } |
0 | 563 return 0; |
564 } |