📄 xvid_bench.c
字号:
/************************************************************************** * * XVID MPEG-4 VIDEO CODEC - Unit tests and benches * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * *************************************************************************//************************************************************************ * * '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 * * History: * * 06.06.2002 initial coding -Skal- * *************************************************************************/#include <stdio.h>#include <stdlib.h>#ifdef WIN32#include <time.h> /* for clock */#else#include <sys/time.h> /* for gettimeofday */#endif#include <string.h> /* for memset */#include <assert.h>#include "xvid.h"/* inner guts */#include "dct/idct.h"#include "dct/fdct.h"#include "image/colorspace.h"#include "image/interpolate8x8.h"#include "utils/mem_transfer.h"#include "quant/quant_h263.h"#include "quant/quant_mpeg4.h"#include "motion/sad.h"#include "utils/emms.h"#include "utils/timer.h"#include "quant/quant_matrix.c"#include "bitstream/cbp.h"#include <math.h>#ifndef M_PI# define M_PI 3.14159265359# define M_PI_2 1.5707963268#endifconst int speed_ref = 100; /* on slow machines, decrease this value *//********************************************************************* * misc *********************************************************************/ /* returns time in micro-s*/double gettime_usec(){ #ifdef WIN32 return clock()*1000;#else struct timeval tv; gettimeofday(&tv, 0); return tv.tv_sec*1.0e6 + tv.tv_usec;#endif} /* returns squared deviates (mean(v*v)-mean(v)^2) of a 8x8 block */double sqr_dev(uint8_t v[8*8]){ double sum=0.; double sum2=0.; int n; for (n=0;n<8*8;n++) { sum += v[n]; sum2 += v[n]*v[n]; } sum2 /= n; sum /= n; return sum2-sum*sum;}/********************************************************************* * cpu init *********************************************************************/typedef struct { const char *name; unsigned int cpu;} CPU;CPU cpu_list[] = { { "PLAINC", 0 }, { "MMX ", XVID_CPU_MMX }, { "MMXEXT", XVID_CPU_MMXEXT | XVID_CPU_MMX }, { "SSE2 ", XVID_CPU_SSE2 | XVID_CPU_MMX }, { "3DNOW ", XVID_CPU_3DNOW }, { "3DNOWE", XVID_CPU_3DNOWEXT }, { "IA64 ", XVID_CPU_IA64 } /*, { "TSC ", XVID_CPU_TSC } */, { 0, 0 } }, cpu_short_list[] ={ { "PLAINC", 0 }, { "MMX ", XVID_CPU_MMX }/*, { "MMXEXT", XVID_CPU_MMXEXT | XVID_CPU_MMX } */, { "IA64 ", XVID_CPU_IA64 }, { 0, 0 } }, cpu_short_list2[] = { { "PLAINC", 0 }, { "MMX ", XVID_CPU_MMX }, { "SSE2 ", XVID_CPU_SSE2 | XVID_CPU_MMX }, { 0, 0 } };int init_cpu(CPU *cpu){ int xerr, cpu_type; XVID_INIT_PARAM xinit; cpu_type = check_cpu_features() & cpu->cpu; xinit.cpu_flags = cpu_type | XVID_CPU_FORCE; /* xinit.cpu_flags = XVID_CPU_MMX | XVID_CPU_FORCE; */ xerr = xvid_init(NULL, 0, &xinit, NULL); if (cpu->cpu>0 && (cpu_type==0 || xerr!=XVID_ERR_OK)) { printf( "%s - skipped...\n", cpu->name ); return 0; } return 1;}/********************************************************************* * test DCT *********************************************************************/#define ABS(X) ((X)<0 ? -(X) : (X))void test_dct(){ const int nb_tests = 300*speed_ref; int tst; CPU *cpu; int i; short iDst0[8*8], iDst[8*8], fDst[8*8]; double overhead; printf( "\n ===== test fdct/idct =====\n" ); for(i=0; i<8*8; ++i) iDst0[i] = (i*7-i*i) & 0x7f; overhead = gettime_usec(); for(tst=0; tst<nb_tests; ++tst) { for(i=0; i<8*8; ++i) fDst[i] = iDst0[i]; for(i=0; i<8*8; ++i) iDst[i] = fDst[i]; } overhead = gettime_usec() - overhead; for(cpu = cpu_list; cpu->name!=0; ++cpu) { double t, PSNR, MSE; if (!init_cpu(cpu)) continue; t = gettime_usec(); emms(); for(tst=0; tst<nb_tests; ++tst) { for(i=0; i<8*8; ++i) fDst[i] = iDst0[i]; fdct(fDst); for(i=0; i<8*8; ++i) iDst[i] = fDst[i]; idct(iDst); } emms(); t = (gettime_usec() - t - overhead) / nb_tests; MSE = 0.; for(i=0; i<8*8; ++i) { double delta = 1.0*(iDst[i] - iDst0[i]); MSE += delta*delta; } PSNR = (MSE==0.) ? 1.e6 : -4.3429448*log( MSE/64. ); printf( "%s - %.3f usec PSNR=%.3f MSE=%.3f\n", cpu->name, t, PSNR, MSE ); if (ABS(MSE)>=64) printf( "*** CRC ERROR! ***\n" ); }}/********************************************************************* * test SAD *********************************************************************/void test_sad(){ const int nb_tests = 2000*speed_ref; int tst; CPU *cpu; int i; uint8_t Cur[16*16], Ref1[16*16], Ref2[16*16]; printf( "\n ====== test SAD ======\n" ); for(i=0; i<16*16;++i) { Cur[i] = (i/5) ^ 0x05; Ref1[i] = (i + 0x0b) & 0xff; Ref2[i] = i ^ 0x76; } for(cpu = cpu_list; cpu->name!=0; ++cpu) { double t; uint32_t s; if (!init_cpu(cpu)) continue; t = gettime_usec(); emms(); for(tst=0; tst<nb_tests; ++tst) s = sad8(Cur, Ref1, 16); emms(); t = (gettime_usec() - t) / nb_tests; printf( "%s - sad8 %.3f usec sad=%d\n", cpu->name, t, s ); if (s!=3776) printf( "*** CRC ERROR! ***\n" ); t = gettime_usec(); emms(); for(tst=0; tst<nb_tests; ++tst) s = sad16(Cur, Ref1, 16, -1); emms(); t = (gettime_usec() - t) / nb_tests; printf( "%s - sad16 %.3f usec sad=%d\n", cpu->name, t, s ); if (s!=27214) printf( "*** CRC ERROR! ***\n" ); t = gettime_usec(); emms(); for(tst=0; tst<nb_tests; ++tst) s = sad16bi(Cur, Ref1, Ref2, 16); emms(); t = (gettime_usec() - t) / nb_tests; printf( "%s - sad16bi %.3f usec sad=%d\n", cpu->name, t, s ); if (s!=26274) printf( "*** CRC ERROR! ***\n" ); t = gettime_usec(); emms(); for(tst=0; tst<nb_tests; ++tst) s = dev16(Cur, 16); emms(); t = (gettime_usec() - t) / nb_tests; printf( "%s - dev16 %.3f usec sad=%d\n", cpu->name, t, s ); if (s!=3344) printf( "*** CRC ERROR! ***\n" ); printf( " --- \n" ); }}/********************************************************************* * test interpolation *********************************************************************/#define ENTER \ for(i=0; i<16*8; ++i) Dst[i] = 0; \ t = gettime_usec(); \ emms();#define LEAVE \ emms(); \ t = (gettime_usec() - t) / nb_tests; \ iCrc = 0; \ for(i=0; i<16*8; ++i) { iCrc += Dst[i]^i; }#define TEST_MB(FUNC, R) \ ENTER \ for(tst=0; tst<nb_tests; ++tst) (FUNC)(Dst, Src0, 16, (R)); \ LEAVE#define TEST_MB2(FUNC) \ ENTER \ for(tst=0; tst<nb_tests; ++tst) (FUNC)(Dst, Src0, 16); \ LEAVEvoid test_mb(){ const int nb_tests = 2000*speed_ref; CPU *cpu; const uint8_t Src0[16*9] = { /* try to have every possible combinaison of rounding... */ 0, 0, 1, 0, 2, 0, 3, 0, 4 ,0,0,0, 0,0,0,0 , 0, 1, 1, 1, 2, 1, 3, 1, 3 ,0,0,0, 0,0,0,0 , 0, 2, 1, 2, 2, 2, 3, 2, 2 ,0,0,0, 0,0,0,0 , 0, 3, 1, 3, 2, 3, 3, 3, 1 ,0,0,0, 0,0,0,0 , 1, 3, 0, 2, 1, 0, 2, 3, 4 ,0,0,0, 0,0,0,0 , 2, 2, 1, 2, 0, 1, 3, 5, 3 ,0,0,0, 0,0,0,0 , 3, 1, 2, 3, 1, 2, 2, 6, 2 ,0,0,0, 0,0,0,0 , 1, 0, 1, 3, 0, 3, 1, 6, 1 ,0,0,0, 0,0,0,0 , 4, 3, 2, 1, 2, 3, 4, 0, 3 ,0,0,0, 0,0,0,0 }; uint8_t Dst[16*8] = {0}; printf( "\n === test block motion ===\n" ); for(cpu = cpu_list; cpu->name!=0; ++cpu) { double t; int tst, i, iCrc; if (!init_cpu(cpu)) continue; TEST_MB(interpolate8x8_halfpel_h, 0); printf( "%s - interp- h-round0 %.3f usec iCrc=%d\n", cpu->name, t, iCrc ); if (iCrc!=8107) printf( "*** CRC ERROR! ***\n" ); TEST_MB(interpolate8x8_halfpel_h, 1); printf( "%s - round1 %.3f usec iCrc=%d\n", cpu->name, t, iCrc ); if (iCrc!=8100) printf( "*** CRC ERROR! ***\n" ); TEST_MB(interpolate8x8_halfpel_v, 0); printf( "%s - interp- v-round0 %.3f usec iCrc=%d\n", cpu->name, t, iCrc ); if (iCrc!=8108) printf( "*** CRC ERROR! ***\n" ); TEST_MB(interpolate8x8_halfpel_v, 1); printf( "%s - round1 %.3f usec iCrc=%d\n", cpu->name, t, iCrc ); if (iCrc!=8105) printf( "*** CRC ERROR! ***\n" ); TEST_MB(interpolate8x8_halfpel_hv, 0); printf( "%s - interp-hv-round0 %.3f usec iCrc=%d\n", cpu->name, t, iCrc ); if (iCrc!=8112) printf( "*** CRC ERROR! ***\n" ); TEST_MB(interpolate8x8_halfpel_hv, 1); printf( "%s - round1 %.3f usec iCrc=%d\n", cpu->name, t, iCrc ); if (iCrc!=8103) printf( "*** CRC ERROR! ***\n" ); /* this is a new function, as of 06.06.2002 */#if 0 TEST_MB2(interpolate8x8_avrg); printf( "%s - interpolate8x8_c %.3f usec iCrc=%d\n", cpu->name, t, iCrc ); if (iCrc!=8107) printf( "*** CRC ERROR! ***\n" );#endif printf( " --- \n" ); }}/********************************************************************* * test transfer *********************************************************************/#define INIT_TRANSFER \ for(i=0; i<8*32; ++i) { \ Src8[i] = i; Src16[i] = i; \ Dst8[i] = 0; Dst16[i] = 0; \ Ref1[i] = i^0x27; \ Ref2[i] = i^0x51; \ }#define TEST_TRANSFER_BEGIN(DST) \ INIT_TRANSFER \ overhead = -gettime_usec(); \ for(tst=0; tst<nb_tests; ++tst) { \ for(i=0; i<8*32; ++i) (DST)[i] = i^0x6a;\ } \ overhead += gettime_usec(); \ t = gettime_usec(); \ emms(); \ for(tst=0; tst<nb_tests; ++tst) { \ for(i=0; i<8*32; ++i) (DST)[i] = i^0x6a;#define TEST_TRANSFER_END(DST) \ } \ emms(); \ t = (gettime_usec()-t -overhead) / nb_tests;\ s = 0; for(i=0; i<8*32; ++i) { s += (DST)[i]^i; }#define TEST_TRANSFER(FUNC, DST, SRC) \ TEST_TRANSFER_BEGIN(DST); \ (FUNC)((DST), (SRC), 32); \ TEST_TRANSFER_END(DST)#define TEST_TRANSFER2_BEGIN(DST, SRC) \ INIT_TRANSFER \ overhead = -gettime_usec(); \ for(tst=0; tst<nb_tests; ++tst) { \ for(i=0; i<8*32; ++i) (DST)[i] = i^0x6a;\ for(i=0; i<8*32; ++i) (SRC)[i] = i^0x3e;\ } \ overhead += gettime_usec(); \ t = gettime_usec(); \ emms(); \ for(tst=0; tst<nb_tests; ++tst) { \ for(i=0; i<8*32; ++i) (DST)[i] = i^0x6a;\ for(i=0; i<8*32; ++i) (SRC)[i] = i^0x3e;#define TEST_TRANSFER2_END(DST) \ } \ emms(); \ t = (gettime_usec()-t -overhead) / nb_tests;\ s = 0; for(i=0; i<8*32; ++i) { s += (DST)[i]; }#define TEST_TRANSFER2(FUNC, DST, SRC, R1) \ TEST_TRANSFER2_BEGIN(DST,SRC); \ (FUNC)((DST), (SRC), (R1), 32); \ TEST_TRANSFER2_END(DST)#define TEST_TRANSFER3(FUNC, DST, SRC, R1, R2)\ TEST_TRANSFER_BEGIN(DST); \ (FUNC)((DST), (SRC), (R1), (R2), 32); \ TEST_TRANSFER_END(DST)void test_transfer(){ const int nb_tests = 4000*speed_ref; int i; CPU *cpu; uint8_t Src8[8*32], Dst8[8*32], Ref1[8*32], Ref2[8*32]; int16_t Src16[8*32], Dst16[8*32]; printf( "\n === test transfer ===\n" ); for(cpu = cpu_short_list; cpu->name!=0; ++cpu) { double t, overhead; int tst, s; if (!init_cpu(cpu)) continue; TEST_TRANSFER(transfer_8to16copy, Dst16, Src8); printf( "%s - 8to16 %.3f usec crc=%d\n", cpu->name, t, s ); if (s!=28288) printf( "*** CRC ERROR! ***\n" ); TEST_TRANSFER(transfer_16to8copy, Dst8, Src16); printf( "%s - 16to8 %.3f usec crc=%d\n", cpu->name, t, s ); if (s!=28288) printf( "*** CRC ERROR! ***\n" ); TEST_TRANSFER(transfer8x8_copy, Dst8, Src8); printf( "%s - 8to8 %.3f usec crc=%d\n", cpu->name, t, s ); if (s!=20352) printf( "*** CRC ERROR! ***\n" ); TEST_TRANSFER(transfer_16to8add, Dst8, Src16); printf( "%s - 16to8add %.3f usec crc=%d\n", cpu->name, t, s ); if (s!=25536) printf( "*** CRC ERROR! ***\n" ); TEST_TRANSFER2(transfer_8to16sub, Dst16, Src8, Ref1); printf( "%s - 8to16sub %.3f usec crc1=%d ", cpu->name, t, s ); if (s!=28064) printf( "*** CRC ERROR! ***\n" ); s = 0; for(i=0; i<8*32; ++i) { s += (Src8[i]-Ref1[i])&i; } printf( "crc2=%d\n", s); if (s!=16256) printf( "*** CRC ERROR! ***\n" );#if 1 TEST_TRANSFER3(transfer_8to16sub2, Dst16, Src8, Ref1, Ref2); printf( "%s - 8to16sub2 %.3f usec crc=%d\n", cpu->name, t, s ); if (s!=20384) printf( "*** CRC ERROR! ***\n" );/* for(i=0; i<64; ++i) printf( "[%d]", Dst16[i]); *//* printf("\n"); */#endif printf( " --- \n" ); }}/********************************************************************* * test quantization *********************************************************************/#define TEST_QUANT(FUNC, DST, SRC) \ t = gettime_usec(); \ for(s=0,qm=1; qm<=255; ++qm) { \ for(i=0; i<8*8; ++i) Quant[i] = qm; \ set_inter_matrix( Quant ); \
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -