⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xvid_bench.c

📁 mpeg4 video codec mpeg4 video codec
💻 C
📖 第 1 页 / 共 4 页
字号:
			   cpu->name, t, cbp, (cbp!=0x15)?"| ERROR": "");		TEST_CBP(calc_cbp, Src2, nb_tests);		printf("%s -   calc_cbp#2 %.3f usec       cbp=0x%02x %s\n",			   cpu->name, t, cbp, (cbp!=0x38)?"| ERROR": "");		TEST_CBP(calc_cbp, Src3, nb_tests);		printf("%s -   calc_cbp#3 %.3f usec       cbp=0x%02x %s\n",			   cpu->name, t, cbp, (cbp!=0x0f)?"| ERROR": "" );		TEST_CBP(calc_cbp, Src4, nb_tests);		printf("%s -   calc_cbp#4 %.3f usec       cbp=0x%02x %s\n",			   cpu->name, t, cbp, (cbp!=0x05)?"| ERROR": "" );		TEST_CBP(calc_cbp, Src5, nb_tests);		printf("%s -   calc_cbp#4 %.3f usec       cbp=0x%02x %s\n",			   cpu->name, t, cbp, (cbp!=0x3f)?"| ERROR": "" );		printf( " --- \n" );	}	for(cpu = cpu_list; cpu->name!=0; ++cpu)  /* bench suggested by Carlo (carlo dot bramix at libero dot it) */	{		double t;		int tst, cbp, err;		if (!init_cpu(cpu))			continue;    err = 0;    for(n=0; n<6; ++n)    {      for(m=0; m<64; ++m)      {        for(i=0; i<6*64; ++i)          Src1[i] = (i== (m + n*64));        TEST_CBP(calc_cbp, Src1, 1);        if (cbp!= (((m!=0)<<(5-n))))        {          printf( "%s -   calc_cbp#5: ERROR at pos %d / %d!\n", cpu->name, n, m);          err = 1;          break;        }      }    }    if (!err)      printf( " %s -    calc_cbp#5 : OK\n", cpu->name );	}}/********************************************************************* * fdct/idct IEEE1180 compliance *********************************************************************/typedef struct {	long Errors[64];	long Sqr_Errors[64];	long Max_Errors[64];	long Nb;} STATS_8x8;void init_stats(STATS_8x8 *S){	int i;	for(i=0; i<64; ++i) {		S->Errors[i]     = 0;		S->Sqr_Errors[i] = 0;		S->Max_Errors[i] = 0;	}	S->Nb = 0;}void store_stats(STATS_8x8 *S, short Blk[64], short Ref[64]){	int i;	for(i=0; i<64; ++i)	{		short Err = Blk[i] - Ref[i];		S->Errors[i] += Err;		S->Sqr_Errors[i] += Err * Err;		if (Err<0) Err = -Err;		if (S->Max_Errors[i]<Err)			S->Max_Errors[i] = Err;	}	S->Nb++;}void print_stats(STATS_8x8 *S){	int i;	double Norm;	assert(S->Nb>0);	Norm = 1. / (double)S->Nb;	printf("\n== Max absolute values of errors ==\n");	for(i=0; i<64; i++) {		printf("  %4ld", S->Max_Errors[i]);		if ((i&7)==7) printf("\n");	}	printf("\n== Mean square errors ==\n");	for(i=0; i<64; i++)	{		double Err = Norm * (double)S->Sqr_Errors[i];		printf(" %.3f", Err);		if ((i&7)==7) printf("\n");	}	printf("\n== Mean errors ==\n");	for(i=0; i<64; i++)	{		double Err = Norm * (double)S->Errors[i];		printf(" %.3f", Err);		if ((i&7)==7) printf("\n");	}	printf("\n");}static const char *CHECK(double v, double l) {	if (fabs(v)<=l) return "ok";	else return "FAIL!";}void report_stats(STATS_8x8 *S, const double *Limits){	int i;	double Norm, PE, PMSE, OMSE, PME, OME;	assert(S->Nb>0);	Norm = 1. / (double)S->Nb;	PE = 0.;	for(i=0; i<64; i++) {		if (PE<S->Max_Errors[i])			PE = S->Max_Errors[i];	}	PMSE = 0.;	OMSE = 0.;	for(i=0; i<64; i++)	{		double Err = Norm * (double)S->Sqr_Errors[i];		OMSE += Err;		if (PMSE < Err) PMSE = Err;	}	OMSE /= 64.;	PME = 0.;	OME = 0.;	for(i=0; i<64; i++)	{		double Err = Norm * (double)S->Errors[i];		OME += Err;		Err = fabs(Err);		if (PME < Err) PME = Err;	}	OME /= 64.;	printf( "Peak error:   %4.4f\n", PE );	printf( "Peak MSE:     %4.4f\n", PMSE );	printf( "Overall MSE:  %4.4f\n", OMSE );	printf( "Peak ME:      %4.4f\n", PME );	printf( "Overall ME:   %4.4f\n", OME );	if (Limits!=0)	{		printf( "[PE<=%.4f %s]  ", Limits[0], CHECK(PE,   Limits[0]) );		printf( "\n" );		printf( "[PMSE<=%.4f %s]", Limits[1], CHECK(PMSE, Limits[1]) );		printf( "[OMSE<=%.4f %s]", Limits[2], CHECK(OMSE, Limits[2]) );		printf( "\n" );		printf( "[PME<=%.4f %s] ", Limits[3], CHECK(PME , Limits[3]) );		printf( "[OME<=%.4f %s] ", Limits[4], CHECK(OME , Limits[4]) );		printf( "\n" );	}}///* ////////////////////////////////////////////////////// *//* Pseudo-random generator specified by IEEE 1180 */static long ieee_seed = 1;static void ieee_reseed(long s) {	ieee_seed = s;}static long ieee_rand(int Min, int Max){	static double z = (double) 0x7fffffff;	long i,j;	double x;	ieee_seed = (ieee_seed * 1103515245) + 12345;	i = ieee_seed & 0x7ffffffe;	x = ((double) i) / z;	x *= (Max-Min+1);	j = (long)x;	j = j + Min;	assert(j>=Min && j<=Max);	return (short)j;}#define CLAMP(x, M)   (x) = ((x)<-(M)) ? (-(M)) : ((x)>=(M) ? ((M)-1) : (x))static double Cos[8][8];static void init_ref_dct(){	int i, j;	for(i=0; i<8; i++)	{		double scale = (i == 0) ? sqrt(0.125) : 0.5;		for (j=0; j<8; j++)			Cos[i][j] = scale*cos( (M_PI/8.0)*i*(j + 0.5) );	}}void ref_idct(short *M){	int i, j, k;	double Tmp[8][8];	for(i=0; i<8; i++) {		for(j=0; j<8; j++)		{			double Sum = 0.0;			for (k=0; k<8; k++) Sum += Cos[k][j]*M[8*i+k];			Tmp[i][j] = Sum;		}	}	for(i=0; i<8; i++) {		for(j=0; j<8; j++) {			double Sum = 0.0;			for (k=0; k<8; k++) Sum += Cos[k][i]*Tmp[k][j];			M[8*i+j] = (short)floor(Sum + .5);		}	}}void ref_fdct(short *M){	int i, j, k;	double Tmp[8][8];	for(i=0; i<8; i++) {		for(j=0; j<8; j++)		{			double Sum = 0.0;			for (k=0; k<8; k++) Sum += Cos[j][k]*M[8*i+k];			Tmp[i][j] = Sum;		}	}	for(i=0; i<8; i++) {		for(j=0; j<8; j++) {			double Sum = 0.0;			for (k=0; k<8; k++) Sum += Cos[i][k]*Tmp[k][j];			M[8*i+j] = (short)floor(Sum + 0.5);		}	}}void test_IEEE1180_compliance(int Min, int Max, int Sign){	static const double ILimits[5] = { 1., 0.06, 0.02, 0.015, 0.0015 };	int Loops = 10000;	int i, m, n;	DECLARE_ALIGNED_MATRIX(Blk0, 8, 8, short, 16); /* reference */	DECLARE_ALIGNED_MATRIX(Blk,  8, 8, short, 16);	DECLARE_ALIGNED_MATRIX(iBlk, 8, 8, short, 16);	DECLARE_ALIGNED_MATRIX(Ref_FDCT, 8, 8, short, 16);	DECLARE_ALIGNED_MATRIX(Ref_IDCT, 8, 8, short, 16);	STATS_8x8 FStats; /* forward dct stats */	STATS_8x8 IStats; /* inverse dct stats */	CPU *cpu;	init_ref_dct();	for(cpu = cpu_list; cpu->name!=0; ++cpu)	{		if (!init_cpu(cpu))			continue;		printf( "\n===== IEEE test for %s ==== (Min=%d Max=%d Sign=%d Loops=%d)\n",				cpu->name, Min, Max, Sign, Loops);		init_stats(&IStats);		init_stats(&FStats);		ieee_reseed(1);		for(n=0; n<Loops; ++n)		{			for(i=0; i<64; ++i)				Blk0[i] = (short)ieee_rand(Min,Max) * Sign;			/* hmm, I'm not quite sure this is exactly */			/* the tests described in the norm. check... */			memcpy(Ref_FDCT, Blk0, 64*sizeof(short));			ref_fdct(Ref_FDCT);			for(i=0; i<64; i++) CLAMP( Ref_FDCT[i], 2048 );			memcpy(Blk, Blk0, 64*sizeof(short));			emms(); fdct(Blk); emms();			for(i=0; i<64; i++) CLAMP( Blk[i], 2048 );			store_stats(&FStats, Blk, Ref_FDCT);			memcpy(Ref_IDCT, Ref_FDCT, 64*sizeof(short));			ref_idct(Ref_IDCT);			for (i=0; i<64; i++) CLAMP( Ref_IDCT[i], 256 );			memcpy(iBlk, Ref_FDCT, 64*sizeof(short));			emms(); idct(iBlk); emms();			for(i=0; i<64; i++) CLAMP( iBlk[i], 256 );			store_stats(&IStats, iBlk, Ref_IDCT);		}		printf( "\n  -- FDCT report --\n" );//    print_stats(&FStats);		report_stats(&FStats, 0); /* so far I know, IEEE1180 says nothing for fdct */		for(i=0; i<64; i++) Blk[i] = 0;		emms(); fdct(Blk); emms();		for(m=i=0; i<64; i++) if (Blk[i]!=0) m++;		printf( "FDCT(0) == 0 ?  %s\n", (m!=0) ? "NOPE!" : "yup." );		printf( "\n  -- IDCT report --\n" );//    print_stats(&IStats);		report_stats(&IStats, ILimits);		for(i=0; i<64; i++) Blk[i] = 0;		emms(); idct(Blk); emms();		for(m=i=0; i<64; i++) if (Blk[i]!=0) m++;		printf( "IDCT(0) == 0 ?  %s\n", (m!=0) ? "NOPE!" : "yup." );	}}void test_dct_saturation(int Min, int Max){/* test behaviour on input range fringe */	int i, n, p;	CPU *cpu;//  const short IDCT_MAX =  2047;  /* 12bits input *///  const short IDCT_MIN = -2048;//  const short IDCT_OUT =   256;  /* 9bits ouput */	const int Partitions = 4;	const int Loops = 10000 / Partitions;	init_ref_dct();	for(cpu = cpu_list; cpu->name!=0; ++cpu)	{		short Blk0[64], Blk[64];		STATS_8x8 Stats;		if (!init_cpu(cpu))			continue;		printf( "\n===== IEEE test for %s Min=%d Max=%d =====\n",				cpu->name, Min, Max );		/* FDCT tests // */		init_stats(&Stats);		/* test each computation channels separately */		for(i=0; i<64; i++) Blk[i] = Blk0[i] = ((i/8)==(i%8)) ? Max : 0;		ref_fdct(Blk0);		emms(); fdct(Blk); emms();		store_stats(&Stats, Blk, Blk0);		for(i=0; i<64; i++) Blk[i] = Blk0[i] = ((i/8)==(i%8)) ? Min : 0;		ref_fdct(Blk0);		emms(); fdct(Blk); emms();		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)? 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 ref_chksum){	FILE *f = 0;	void *dechandle = 0;	int xerr;	xvid_gbl_init_t xinit;	xvid_dec_create_t xparam;	xvid_dec_frame_t xframe;	double t = 0.;	int nb = 0;	uint8_t *buf = 0;	uint8_t *yuv_out = 0;	int buf_size, pos;	uint32_t chksum = 0;	int bps = (width+31) & ~31;	memset(&xinit, 0, sizeof(xinit));	xinit.cpu_flags = cpu_mask;	xinit.version = XVID_VERSION;	xvid_global(NULL, 0, &xinit, NULL);	memset(&xparam, 0, sizeof(xparam));	xparam.width  = width;	xparam.height = height;	xparam.version = XVID_VERSION;	xerr = xvid_decore(NULL, XVID_DEC_CREATE, &xparam, NULL);	if (xerr==XVID_ERR_FAIL) {		printf("ERROR: can't init decoder (err=%d)\n", xerr);		return;	}	dechandle = xparam.handle;	f = fopen(name, "rb");	if (f==0) {		printf( "ERROR: 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: error while stating file\n");		goto End;	}	buf = malloc(buf_size);	yuv_out = calloc(1, bps*height*3/2 + 15);	if (buf==0 || yuv_out==0) {		printf( "ERROR: malloc failed!\n" );		goto End;	}	if (fread(buf, buf_size, 1, f)!=1) {		printf( "ERROR: file-read failed\n" );		goto End;	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -