--- trunk/xvidcore/examples/xvid_bench.c 2004/04/02 21:29:21 1398 +++ trunk/xvidcore/examples/xvid_bench.c 2005/05/17 21:03:32 1616 @@ -19,15 +19,13 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: xvid_bench.c,v 1.12 2004-04-02 21:29:21 edgomez Exp $ + * $Id: xvid_bench.c,v 1.18 2005-05-17 21:03:32 Skal Exp $ * ****************************************************************************/ /***************************************************************************** * * 'Reference' output is at the end of file. - * Don't take the checksums and crc too seriouly, they aren't - * bullet-proof (should plug some .md5 here)... * * compiles with something like: * gcc -o xvid_bench xvid_bench.c -I../src/ -lxvidcore -lm @@ -67,7 +65,9 @@ #define M_PI 3.14159265358979323846 #endif -const int speed_ref = 100; /* on slow machines, decrease this value */ +int speed_ref = 100; /* on slow machines, decrease this value */ +int verbose = 0; +unsigned int cpu_mask; /********************************************************************* * misc @@ -83,7 +83,7 @@ #else clock_t clk; clk = clock(); - return clk * 1000000 / CLOCKS_PER_SEC; + return clk * 1000. / CLOCKS_PER_SEC; /* clock() returns time in Milliseconds */ #endif } @@ -121,6 +121,12 @@ , { "3DNOW ", XVID_CPU_3DNOW } , { "3DNOWE", XVID_CPU_3DNOW | XVID_CPU_3DNOWEXT } #endif +#ifdef ARCH_IS_PPC + , { "ALTIVEC", XVID_CPU_ALTIVEC } +#endif +#ifdef ARCH_IS_X86_64 + , { "X86_64", XVID_CPU_ASM} +#endif //, { "IA64 ", XVID_CPU_IA64 } //, { "TSC ", XVID_CPU_TSC } , { 0, 0 } }; @@ -253,13 +259,8 @@ }; uint32_t -calc_crc(uint8_t *mem, int len, uint32_t initial) +calc_crc(uint8_t *mem, int len, uint32_t crc) { - - register unsigned int crc; - - crc = initial; - while( len >= 8) { DO8(mem, crc); len -= 8; @@ -270,8 +271,7 @@ len--; } - return(crc); - + return crc; } /********************************************************************* @@ -779,6 +779,95 @@ } /********************************************************************* + * test distortion operators + *********************************************************************/ + +static void ieee_reseed(long s); +static long ieee_rand(int Min, int Max); + +#define TEST_SSE(FUNCTION, SRC1, SRC2, STRIDE) \ + do { \ + t = gettime_usec(); \ + tst = nb_tests; \ + while((tst--)>0) sse = (FUNCTION)((SRC1), (SRC2), (STRIDE)); \ + emms(); \ + t = (gettime_usec() - t)/(double)nb_tests; \ + } while(0) + + +void test_sse() +{ + const int nb_tests = 100000*speed_ref; + int i; + CPU *cpu; + DECLARE_ALIGNED_MATRIX(Src1, 8, 8, int16_t, 16); + DECLARE_ALIGNED_MATRIX(Src2, 8, 8, int16_t, 16); + DECLARE_ALIGNED_MATRIX(Src3, 8, 8, int16_t, 16); + DECLARE_ALIGNED_MATRIX(Src4, 8, 8, int16_t, 16); + + printf( "\n ===== test sse =====\n" ); + + ieee_reseed(1); + for(i=0; i<64; ++i) { + Src1[i] = ieee_rand(-2048, 2047); + Src2[i] = ieee_rand(-2048, 2047); + Src3[i] = ieee_rand(-2048, 2047); + Src4[i] = ieee_rand(-2048, 2047); + } + + for(cpu = cpu_list; cpu->name!=0; ++cpu) + { + double t; + int tst, sse; + + if (!init_cpu(cpu)) + continue; + + /* 16 bit element blocks */ + TEST_SSE(sse8_16bit, Src1, Src2, 16); + printf("%s - sse8_16bit#1 %.3f usec sse=%d %s\n", + cpu->name, t, sse, (sse!=182013834)?"| ERROR": ""); + TEST_SSE(sse8_16bit, Src1, Src3, 16); + printf("%s - sse8_16bit#2 %.3f usec sse=%d %s\n", + cpu->name, t, sse, (sse!=142545203)?"| ERROR": ""); + TEST_SSE(sse8_16bit, Src1, Src4, 16); + printf("%s - sse8_16bit#3 %.3f usec sse=%d %s\n", + cpu->name, t, sse, (sse!=146340935)?"| ERROR": ""); + TEST_SSE(sse8_16bit, Src2, Src3, 16); + printf("%s - sse8_16bit#4 %.3f usec sse=%d %s\n", + cpu->name, t, sse, (sse!=130136661)?"| ERROR": ""); + TEST_SSE(sse8_16bit, Src2, Src4, 16); + printf("%s - sse8_16bit#5 %.3f usec sse=%d %s\n", + cpu->name, t, sse, (sse!=136870353)?"| ERROR": ""); + TEST_SSE(sse8_16bit, Src3, Src4, 16); + printf("%s - sse8_16bit#6 %.3f usec sse=%d %s\n", + cpu->name, t, sse, (sse!=164107772)?"| ERROR": ""); + + /* 8 bit element blocks */ + TEST_SSE(sse8_8bit, (int8_t*)Src1, (int8_t*)Src2, 8); + printf("%s - sse8_8bit#1 %.3f usec sse=%d %s\n", + cpu->name, t, sse, (sse!=1356423)?"| ERROR": ""); + TEST_SSE(sse8_8bit, (int8_t*)Src1, (int8_t*)Src3, 8); + printf("%s - sse8_8bit#2 %.3f usec sse=%d %s\n", + cpu->name, t, sse, (sse!=1173074)?"| ERROR": ""); + TEST_SSE(sse8_8bit, (int8_t*)Src1, (int8_t*)Src4, 8); + printf("%s - sse8_8bit#3 %.3f usec sse=%d %s\n", + cpu->name, t, sse, (sse!=1092357)?"| ERROR": ""); + TEST_SSE(sse8_8bit, (int8_t*)Src2, (int8_t*)Src3, 8); + printf("%s - sse8_8bit#4 %.3f usec sse=%d %s\n", + cpu->name, t, sse, (sse!=1360239)?"| ERROR": ""); + TEST_SSE(sse8_8bit, (int8_t*)Src2, (int8_t*)Src4, 8); + printf("%s - sse8_8bit#5 %.3f usec sse=%d %s\n", + cpu->name, t, sse, (sse!=1208414)?"| ERROR": ""); + TEST_SSE(sse8_8bit, (int8_t*)Src3, (int8_t*)Src4, 8); + printf("%s - sse8_8bit#6 %.3f usec sse=%d %s\n", + cpu->name, t, sse, (sse!=1099285)?"| ERROR": ""); + + printf(" ---\n"); + } +} + +/********************************************************************* * test non-zero AC counting *********************************************************************/ @@ -819,16 +908,16 @@ continue; TEST_CBP(calc_cbp, Src1); - printf("%s - calc_cbp#1 %.3f usec cbp=0x%02x\n", + printf("%s - calc_cbp#1 %.3f usec cbp=0x%02x %s\n", cpu->name, t, cbp, (cbp!=0x15)?"| ERROR": ""); TEST_CBP(calc_cbp, Src2); - printf("%s - calc_cbp#2 %.3f usec cbp=0x%02x\n", + printf("%s - calc_cbp#2 %.3f usec cbp=0x%02x %s\n", cpu->name, t, cbp, (cbp!=0x38)?"| ERROR": ""); TEST_CBP(calc_cbp, Src3); - printf("%s - calc_cbp#3 %.3f usec cbp=0x%02x\n", + printf("%s - calc_cbp#3 %.3f usec cbp=0x%02x %s\n", cpu->name, t, cbp, (cbp!=0x0f)?"| ERROR": "" ); TEST_CBP(calc_cbp, Src4); - printf("%s - calc_cbp#4 %.3f usec cbp=0x%02x\n", + printf("%s - calc_cbp#4 %.3f usec cbp=0x%02x %s\n", cpu->name, t, cbp, (cbp!=0x05)?"| ERROR": "" ); printf( " --- \n" ); } @@ -1225,7 +1314,7 @@ * measure raw decoding speed *********************************************************************/ -void test_dec(const char *name, int width, int height, int with_chksum) +void test_dec(const char *name, int width, int height, int ref_chksum) { FILE *f = 0; void *dechandle = 0; @@ -1236,22 +1325,23 @@ double t = 0.; int nb = 0; uint8_t *buf = 0; - uint8_t *rgb_out = 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 = XVID_CPU_MMX | XVID_CPU_FORCE; + xinit.cpu_flags = cpu_mask; xinit.version = XVID_VERSION; xvid_global(NULL, 0, &xinit, NULL); memset(&xparam, 0, sizeof(xparam)); - xparam.width = width; + 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("can't init decoder (err=%d)\n", xerr); + printf("ERROR: can't init decoder (err=%d)\n", xerr); return; } dechandle = xparam.handle; @@ -1259,27 +1349,26 @@ f = fopen(name, "rb"); if (f==0) { - printf( "can't open file '%s'\n", name); + 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 while stating file\n"); + printf("ERROR: 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" ); + 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( "file-read failed\n" ); + printf( "ERROR: file-read failed\n" ); goto End; } @@ -1287,41 +1376,57 @@ pos = 0; t = -gettime_usec(); while(1) { + int y; + memset(&xframe, 0, sizeof(xframe)); xframe.version = XVID_VERSION; xframe.bitstream = buf + pos; xframe.length = buf_size - pos; - xframe.output.plane[0] = rgb_out; - xframe.output.stride[0] = width; - xframe.output.csp = XVID_CSP_BGR; + xframe.output.plane[0] = (uint8_t*)(((size_t)yuv_out + 15) & ~15); + xframe.output.plane[1] = xframe.output.plane[0] + bps*height; + xframe.output.plane[2] = xframe.output.plane[1] + bps/2; + xframe.output.stride[0] = bps; + xframe.output.stride[1] = bps; + xframe.output.stride[2] = bps; + xframe.output.csp = XVID_CSP_I420; xerr = xvid_decore(dechandle, XVID_DEC_DECODE, &xframe, 0); + if (xerr<0) { + printf("ERROR: decoding failed for frame #%d (err=%d)!\n", nb, xerr); + break; + } + else if (xerr==0) + break; + else if (verbose>0) printf("#%d %d\n", nb, xerr ); + + pos += xerr; nb++; - pos += xframe.length; - if (with_chksum) { - int k = width*height; - uint32_t *ptr = (uint32_t *)rgb_out; - while(k-->0) chksum += *ptr++; + + for(y=0; y0.) - 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); + if (ref_chksum==0) { + if (t>0.) + printf( "%d frames decoded in %.3f s -> %.1f FPS Checksum:0x%.8x\n", nb, t*1.e-6f, (float)(nb*1.e6f/t), chksum ); + } + else { + printf("FPS:%.1f Checksum: 0x%.8x Expected:0x%.8x | %s\n", + t>0. ? (float)(nb*1.e6f/t) : 0.f, chksum, ref_chksum, (chksum==ref_chksum) ? "OK" : "ERROR"); + } End: - if (rgb_out!=0) free(rgb_out); + if (yuv_out!=0) free(yuv_out); if (buf!=0) free(buf); if (dechandle!=0) { xerr= xvid_decore(dechandle, XVID_DEC_DESTROY, NULL, NULL); if (xerr==XVID_ERR_FAIL) - printf("destroy-decoder failed (err=%d)!\n", xerr); + printf("ERROR: destroy-decoder failed (err=%d)!\n", xerr); } if (f!=0) fclose(f); } @@ -1483,21 +1588,128 @@ } #endif } +/*********************************************************************/ + +static uint32_t __inline log2bin_v1(uint32_t value) +{ + int n = 0; + while (value) { + value >>= 1; + n++; + } + return n; +} + +static const uint8_t log2_tab_16[256] = { 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4 }; + +static uint32_t __inline log2bin_v2(uint32_t value) +{ + int n = 0; + if (value & 0xffff0000) { + value >>= 16; + n += 16; + } + if (value & 0xff00) { + value >>= 8; + n += 8; + } + if (value & 0xf0) { + value >>= 4; + n += 4; + } + return n + log2_tab_16[value]; +} + +void test_log2bin() +{ + const int nb_tests = 3000*speed_ref; + int n, crc1=0, crc2=0; + uint32_t s, s0; + double t1, t2; + + t1 = gettime_usec(); + s0 = (int)(t1*31.241); + for(s=s0, n=0; n1) what = atoi(argv[1]); + int c, what = 0; + int width, height; + uint32_t chksum = 0; + const char * test_bitstream = 0; + + cpu_mask = 0; // default => will use autodectect + for(c=1; cargc) { + printf("usage: %s %d bitstream width height (checksum)\n", argv[0], what); + exit(-1); + } + test_bitstream = argv[++c]; + width = atoi(argv[++c]); + height = atoi(argv[++c]); + if (c+15)); - } - + if (test_bitstream) + test_dec(test_bitstream, width, height, chksum); if (what==-1) { test_dct_precision_diffs(); test_bugs1(); @@ -1527,7 +1730,7 @@ if (what==-2) test_quant_bug(); - if (what >= 0 && what <= 6) { + if ((what >= 0 && what <= 6) || what == 10) { printf("\n\n" "NB: If a function isn't optimised for a specific set of intructions,\n" " a C function is used instead. So don't panic if some functions\n"