📄 xvid_bench.c
字号:
for(p=0; p<Partitions; ++p) { for(n=0; n<Loops; ++n) { for(i=0; i<64; ++i) Blk0[i] = Blk[i] = (ieee_rand(0,Partitions)>=p)? Max : Min; ref_fdct(Blk0); emms(); fdct(Blk); emms(); store_stats(&Stats, Blk, Blk0); } } printf( "\n -- FDCT saturation report --\n" ); report_stats(&Stats, 0); /* IDCT tests */#if 0 /* no finished yet */ init_stats(&Stats); /* test each computation channel separately */ for(i=0; i<64; i++) Blk[i] = Blk0[i] = ((i/8)==(i%8)) ? IDCT_MAX : 0; ref_idct(Blk0); emms(); idct(Blk); emms(); for(i=0; i<64; i++) { CLAMP(Blk0[i], IDCT_OUT); CLAMP(Blk[i], IDCT_OUT); } store_stats(&Stats, Blk, Blk0); for(i=0; i<64; i++) Blk[i] = Blk0[i] = ((i/8)==(i%8)) ? IDCT_MIN : 0; ref_idct(Blk0); emms(); idct(Blk); emms(); for(i=0; i<64; i++) { CLAMP(Blk0[i], IDCT_OUT); CLAMP(Blk[i], IDCT_OUT); } store_stats(&Stats, Blk, Blk0); /* randomly saturated inputs */ for(p=0; p<Partitions; ++p) { for(n=0; n<Loops; ++n) { for(i=0; i<64; ++i) Blk0[i] = Blk[i] = (ieee_rand(0,Partitions)>=p)? IDCT_MAX : IDCT_MIN; ref_idct(Blk0); emms(); idct(Blk); emms(); for(i=0; i<64; i++) { CLAMP(Blk0[i],IDCT_OUT); CLAMP(Blk[i],IDCT_OUT); } store_stats(&Stats, Blk, Blk0); } } printf( "\n -- IDCT saturation report --\n" ); print_stats(&Stats); report_stats(&Stats, 0);#endif }}/********************************************************************* * measure raw decoding speed *********************************************************************/void test_dec(const char *name, int width, int height, int with_chksum){ FILE *f = 0; void *dechandle = 0; int xerr; XVID_INIT_PARAM xinit; XVID_DEC_PARAM xparam; XVID_DEC_FRAME xframe; double t = 0.; int nb = 0; uint8_t *buf = 0; uint8_t *rgb_out = 0; int buf_size, pos; uint32_t chksum = 0; xinit.cpu_flags = XVID_CPU_MMX | XVID_CPU_FORCE; xvid_init(NULL, 0, &xinit, NULL); printf( "API version: %d, core build:%d\n", xinit.api_version, xinit.core_build); xparam.width = width; xparam.height = height; xerr = xvid_decore(NULL, XVID_DEC_CREATE, &xparam, NULL); if (xerr!=XVID_ERR_OK) { printf("can't init decoder (err=%d)\n", xerr); return; } dechandle = xparam.handle; f = fopen(name, "rb"); if (f==0) { printf( "can't open file '%s'\n", name); return; } fseek(f, 0, SEEK_END); buf_size = ftell(f); fseek(f, 0, SEEK_SET); if (buf_size<=0) { printf("error while stating file\n"); goto End; } else printf( "Input size: %d\n", buf_size); buf = malloc(buf_size); /* should be enuf' */ rgb_out = calloc(4, width*height); /* <-room for _RGB24 */ if (buf==0 || rgb_out==0) { printf( "malloc failed!\n" ); goto End; } if (fread(buf, buf_size, 1, f)!=1) { printf( "file-read failed\n" ); goto End; } nb = 0; pos = 0; t = -gettime_usec(); while(1) { xframe.bitstream = buf + pos; xframe.length = buf_size - pos; xframe.image = rgb_out; xframe.stride = width; xframe.colorspace = XVID_CSP_RGB24; xerr = xvid_decore(dechandle, XVID_DEC_DECODE, &xframe, 0); nb++; pos += xframe.length; if (with_chksum) { int k = width*height; uint32_t *ptr = (uint32_t *)rgb_out; while(k-->0) chksum += *ptr++; } if (pos==buf_size) break; if (xerr!=XVID_ERR_OK) { printf("decoding failed for frame #%d (err=%d)!\n", nb, xerr); break; } } t += gettime_usec(); if (t>0.) printf( "%d frames decoded in %.3f s -> %.1f FPS\n", nb, t*1.e-6f, (float)(nb*1.e6f/t) ); if (with_chksum) printf("checksum: 0x%.8x\n", chksum);End: if (rgb_out!=0) free(rgb_out); if (buf!=0) free(buf); if (dechandle!=0) { xerr= xvid_decore(dechandle, XVID_DEC_DESTROY, NULL, NULL); if (xerr!=XVID_ERR_OK) printf("destroy-decoder failed (err=%d)!\n", xerr); } if (f!=0) fclose(f);}/********************************************************************* * non-regression tests *********************************************************************/void test_bugs1(){ CPU *cpu; printf( "\n ===== (de)quant4_intra saturation bug? =====\n" ); for(cpu = cpu_short_list; cpu->name!=0; ++cpu) { int i; int16_t Src[8*8], Dst[8*8]; if (!init_cpu(cpu)) continue; for(i=0; i<64; ++i) Src[i] = i-32; set_intra_matrix( get_default_intra_matrix() ); dequant4_intra(Dst, Src, 31, 5); printf( "dequant4_intra with CPU=%s: ", cpu->name); printf( " Out[]= " ); for(i=0; i<64; ++i) printf( "[%d]", Dst[i]); printf( "\n" ); } printf( "\n ===== (de)quant4_inter saturation bug? =====\n" ); for(cpu = cpu_short_list; cpu->name!=0; ++cpu) { int i; int16_t Src[8*8], Dst[8*8]; if (!init_cpu(cpu)) continue; for(i=0; i<64; ++i) Src[i] = i-32; set_inter_matrix( get_default_inter_matrix() ); dequant4_inter(Dst, Src, 31); printf( "dequant4_inter with CPU=%s: ", cpu->name); printf( " Out[]= " ); for(i=0; i<64; ++i) printf( "[%d]", Dst[i]); printf( "\n" ); }}void test_dct_precision_diffs(){ CPU *cpu; short Blk[8*8], Blk0[8*8]; printf( "\n ===== fdct/idct precision diffs =====\n" ); for(cpu = cpu_short_list; cpu->name!=0; ++cpu) { int i; if (!init_cpu(cpu)) continue; for(i=0; i<8*8; ++i) { Blk0[i] = (i*7-i*i) & 0x7f; Blk[i] = Blk0[i]; } fdct(Blk); idct(Blk); printf( " fdct+idct diffs with CPU=%s: \n", cpu->name ); for(i=0; i<8; ++i) { int j; for(j=0; j<8; ++j) printf( " %d ", Blk[i*8+j]-Blk0[i*8+j]); printf("\n"); } printf("\n"); }}void test_quant_bug(){ const int max_Q = 31; int i, n, qm, q; CPU *cpu; int16_t Src[8*8], Dst[8*8]; uint8_t Quant[8*8]; CPU cpu_bug_list[] = { { "PLAINC", 0 }, { "MMX ", XVID_CPU_MMX }, {0,0} }; uint16_t Crcs_Inter[2][32]; uint16_t Crcs_Intra[2][32]; printf( "\n ===== test MPEG4-quantize bug =====\n" ); for(i=0; i<64; ++i) Src[i] = 2048*(i-32)/32;#if 1 for(qm=1; qm<=255; ++qm) { for(i=0; i<8*8; ++i) Quant[i] = qm; set_inter_matrix( Quant ); for(n=0, cpu = cpu_bug_list; cpu->name!=0; ++cpu, ++n) { uint16_t s; if (!init_cpu(cpu)) continue; for(q=1; q<=max_Q; ++q) { emms(); quant4_inter( Dst, Src, q ); emms(); for(s=0, i=0; i<64; ++i) s+=((uint16_t)Dst[i])^i; Crcs_Inter[n][q] = s; } } for(q=1; q<=max_Q; ++q) for(i=0; i<n-1; ++i) if (Crcs_Inter[i][q]!=Crcs_Inter[i+1][q]) printf( "Discrepancy Inter: qm=%d, q=%d -> %d/%d !\n", qm, q, Crcs_Inter[i][q], Crcs_Inter[i+1][q]); }#endif#if 1 for(qm=1; qm<=255; ++qm) { for(i=0; i<8*8; ++i) Quant[i] = qm; set_intra_matrix( Quant ); for(n=0, cpu = cpu_bug_list; cpu->name!=0; ++cpu, ++n) { uint16_t s; if (!init_cpu(cpu)) continue; for(q=1; q<=max_Q; ++q) { emms(); quant4_intra( Dst, Src, q, q); emms(); for(s=0, i=0; i<64; ++i) s+=((uint16_t)Dst[i])^i; Crcs_Intra[n][q] = s; } } for(q=1; q<=max_Q; ++q) for(i=0; i<n-1; ++i) if (Crcs_Intra[i][q]!=Crcs_Intra[i+1][q]) printf( "Discrepancy Intra: qm=%d, q=%d -> %d/%d!\n", qm, q, Crcs_Inter[i][q], Crcs_Inter[i+1][q]); }#endif}/********************************************************************* * main *********************************************************************/int main(int argc, char *argv[]){ int what = 0; if (argc>1) what = atoi(argv[1]); if (what==0 || what==1) test_dct(); if (what==0 || what==2) test_mb(); if (what==0 || what==3) test_sad(); if (what==0 || what==4) test_transfer(); if (what==0 || what==5) test_quant(); if (what==0 || what==6) test_cbp(); if (what==7) { test_IEEE1180_compliance(-256, 255, 1);#if 0 test_IEEE1180_compliance(-256, 255,-1); test_IEEE1180_compliance( -5, 5, 1); test_IEEE1180_compliance( -5, 5,-1); test_IEEE1180_compliance(-300, 300, 1); test_IEEE1180_compliance(-300, 300,-1);#endif } if (what==8) test_dct_saturation(-256, 255); if (what==9) { int width, height; if (argc<5) { printf("usage: %s %d [bitstream] [width] [height]\n", argv[0], what); return 1; } width = atoi(argv[3]); height = atoi(argv[4]); test_dec(argv[2], width, height, (argc>5)); } if (what==-1) { test_dct_precision_diffs(); test_bugs1(); } if (what==-2) test_quant_bug(); return 0;}/********************************************************************* * 'Reference' output (except for timing) on a PIII 1.13Ghz/linux *********************************************************************/ /* as of 07/01/2002, there's a problem with mpeg4-quantization *//* ===== test fdct/idct =====PLAINC - 3.312 usec PSNR=13.291 MSE=3.000MMX - 0.591 usec PSNR=13.291 MSE=3.000MMXEXT - 0.577 usec PSNR=13.291 MSE=3.000SSE2 - 0.588 usec PSNR=13.291 MSE=3.0003DNOW - skipped...3DNOWE - skipped... === test block motion ===PLAINC - interp- h-round0 0.911 usec iCrc=8107PLAINC - round1 0.863 usec iCrc=8100PLAINC - interp- v-round0 0.860 usec iCrc=8108PLAINC - round1 0.857 usec iCrc=8105PLAINC - interp-hv-round0 2.103 usec iCrc=8112PLAINC - round1 2.050 usec iCrc=8103 --- MMX - interp- h-round0 0.105 usec iCrc=8107MMX - round1 0.106 usec iCrc=8100MMX - interp- v-round0 0.106 usec iCrc=8108MMX - round1 0.106 usec iCrc=8105MMX - interp-hv-round0 0.145 usec iCrc=8112MMX - round1 0.145 usec iCrc=8103 --- MMXEXT - interp- h-round0 0.028 usec iCrc=8107MMXEXT - round1 0.041 usec iCrc=8100MMXEXT - interp- v-round0 0.027 usec iCrc=8108MMXEXT - round1 0.041 usec iCrc=8105MMXEXT - interp-hv-round0 0.066 usec iCrc=8112MMXEXT - round1 0.065 usec iCrc=8103 --- SSE2 - interp- h-round0 0.109 usec iCrc=8107SSE2 - round1 0.105 usec iCrc=8100SSE2 - interp- v-round0 0.106 usec iCrc=8108SSE2 - round1 0.109 usec iCrc=8105SSE2 - interp-hv-round0 0.145 usec iCrc=8112SSE2 - round1 0.145 usec iCrc=8103 --- 3DNOW - skipped...3DNOWE - skipped... ====== test SAD ======PLAINC - sad8 0.251 usec sad=3776PLAINC - sad16 1.601 usec sad=27214PLAINC - sad16bi 2.371 usec sad=26274PLAINC - dev16 1.564 usec sad=3344 --- MMX - sad8 0.057 usec sad=3776MMX - sad16 0.182 usec sad=27214MMX - sad16bi 2.462 usec sad=26274MMX - dev16 0.311 usec sad=3344 --- MMXEXT - sad8 0.036 usec sad=3776MMXEXT - sad16 0.109 usec sad=27214MMXEXT - sad16bi 0.143 usec sad=26274MMXEXT - dev16 0.192 usec sad=3344 --- SSE2 - sad8 0.057 usec sad=3776SSE2 - sad16 0.179 usec sad=27214SSE2 - sad16bi 2.456 usec sad=26274SSE2 - dev16 0.321 usec sad=3344 --- 3DNOW - skipped...3DNOWE - skipped... === test transfer ===PLAINC - 8to16 0.151 usec crc=28288PLAINC - 16to8 1.113 usec crc=28288PLAINC - 8to8 0.043 usec crc=20352PLAINC - 16to8add 1.069 usec crc=25536PLAINC - 8to16sub 0.631 usec crc1=28064 crc2=16256PLAINC - 8to16sub2 0.597 usec crc=20384 --- MMX - 8to16 0.032 usec crc=28288MMX - 16to8 0.024 usec crc=28288MMX - 8to8 0.020 usec crc=20352MMX - 16to8add 0.043 usec crc=25536MMX - 8to16sub 0.066 usec crc1=28064 crc2=16256MMX - 8to16sub2 0.111 usec crc=20384 --- ===== test quant =====PLAINC - quant4_intra 74.248 usec crc=29809PLAINC - quant4_inter 70.850 usec crc=12574PLAINC - dequant4_intra 40.628 usec crc=24052PLAINC - dequant4_inter 45.691 usec crc=63847PLAINC - quant_intra 43.357 usec crc=25662PLAINC - quant_inter 33.410 usec crc=23972PLAINC - dequant_intra 36.384 usec crc=49900PLAINC - dequant_inter 48.930 usec crc=48899 --- MMX - quant4_intra 7.445 usec crc=3459*** CRC ERROR! ***MMX - quant4_inter 5.384 usec crc=51072*** CRC ERROR! ***MMX - dequant4_intra 5.515 usec crc=24052MMX - dequant4_inter 7.745 usec crc=63847MMX - quant_intra 4.661 usec crc=25662MMX - quant_inter 4.406 usec crc=23972MMX - dequant_intra 4.928 usec crc=49900MMX - dequant_inter 4.532 usec crc=48899 --- ===== test cbp =====PLAINC - calc_cbp#1 0.371 usec cbp=0x15PLAINC - calc_cbp#2 0.432 usec cbp=0x38PLAINC - calc_cbp#3 0.339 usec cbp=0xfPLAINC - calc_cbp#4 0.506 usec cbp=0x5 --- MMX - calc_cbp#1 0.136 usec cbp=0x15MMX - calc_cbp#2 0.134 usec cbp=0x38MMX - calc_cbp#3 0.138 usec cbp=0xfMMX - calc_cbp#4 0.135 usec cbp=0x5 --- SSE2 - calc_cbp#1 0.136 usec cbp=0x15SSE2 - calc_cbp#2 0.133 usec cbp=0x38SSE2 - calc_cbp#3 0.133 usec cbp=0xfSSE2 - calc_cbp#4 0.141 usec cbp=0x5 --- */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -