19 |
* along with this program; if not, write to the Free Software |
* along with this program; if not, write to the Free Software |
20 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
21 |
* |
* |
22 |
* $Id: xvid_bench.c,v 1.11 2004-03-22 22:36:23 edgomez Exp $ |
* $Id: xvid_bench.c,v 1.14 2004-04-12 15:49:56 edgomez Exp $ |
23 |
* |
* |
24 |
****************************************************************************/ |
****************************************************************************/ |
25 |
|
|
26 |
/***************************************************************************** |
/***************************************************************************** |
27 |
* |
* |
28 |
* 'Reference' output is at the end of file. |
* '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)... |
|
29 |
* |
* |
30 |
* compiles with something like: |
* compiles with something like: |
31 |
* gcc -o xvid_bench xvid_bench.c -I../src/ -lxvidcore -lm |
* gcc -o xvid_bench xvid_bench.c -I../src/ -lxvidcore -lm |
119 |
, { "3DNOW ", XVID_CPU_3DNOW } |
, { "3DNOW ", XVID_CPU_3DNOW } |
120 |
, { "3DNOWE", XVID_CPU_3DNOW | XVID_CPU_3DNOWEXT } |
, { "3DNOWE", XVID_CPU_3DNOW | XVID_CPU_3DNOWEXT } |
121 |
#endif |
#endif |
122 |
|
#ifdef ARCH_IS_PPC |
123 |
|
, { "ALTIVEC", XVID_CPU_ALTIVEC } |
124 |
|
#endif |
125 |
//, { "IA64 ", XVID_CPU_IA64 } |
//, { "IA64 ", XVID_CPU_IA64 } |
126 |
//, { "TSC ", XVID_CPU_TSC } |
//, { "TSC ", XVID_CPU_TSC } |
127 |
, { 0, 0 } }; |
, { 0, 0 } }; |
658 |
} \ |
} \ |
659 |
t = (gettime_usec()-t-overhead)/nb_tests/qm |
t = (gettime_usec()-t-overhead)/nb_tests/qm |
660 |
|
|
661 |
|
#define TEST_INTRA(REFFUNC, NEWFUNC, RANGE) \ |
662 |
|
{ int i,q,s;\ |
663 |
|
DECLARE_ALIGNED_MATRIX(Src, 8, 8, int16_t, 16); \ |
664 |
|
DECLARE_ALIGNED_MATRIX(Dst, 8, 8, int16_t, 16); \ |
665 |
|
DECLARE_ALIGNED_MATRIX(Dst2,8, 8, int16_t, 16); \ |
666 |
|
for(q=1;q<=max_Q;q++) \ |
667 |
|
for(s=-RANGE;s<RANGE;s++) { \ |
668 |
|
for(i=0;i<64;i++) Src[i]=s; \ |
669 |
|
(REFFUNC)((Dst),(Src),q,q,mpeg_quant_matrices); \ |
670 |
|
(NEWFUNC)((Dst2),(Src),q,q,mpeg_quant_matrices); \ |
671 |
|
for(i=0;i<64;i++) \ |
672 |
|
if(Dst[i]!=Dst2[i]) printf("ERROR : " #NEWFUNC " i%d quant:%d input:%d C_result:%d ASM_result:%d\n",i,q,s,Dst[i],Dst2[i]); \ |
673 |
|
} \ |
674 |
|
} |
675 |
|
|
676 |
|
#define TEST_INTER(REFFUNC, NEWFUNC, RANGE) \ |
677 |
|
{ int i,q,s; \ |
678 |
|
DECLARE_ALIGNED_MATRIX(Src, 8, 8, int16_t, 16); \ |
679 |
|
DECLARE_ALIGNED_MATRIX(Dst, 8, 8, int16_t, 16); \ |
680 |
|
DECLARE_ALIGNED_MATRIX(Dst2,8, 8, int16_t, 16); \ |
681 |
|
for(q=1;q<=max_Q;q++) \ |
682 |
|
for(s=-RANGE;s<RANGE;s++) { \ |
683 |
|
for(i=0;i<64;i++) Src[i]=s; \ |
684 |
|
(REFFUNC)((Dst),(Src),q,mpeg_quant_matrices); \ |
685 |
|
(NEWFUNC)((Dst2),(Src),q,mpeg_quant_matrices); \ |
686 |
|
emms(); \ |
687 |
|
for(i=0;i<64;i++) \ |
688 |
|
if(Dst[i]!=Dst2[i]) printf("ERROR : " #NEWFUNC " i%d quant:%d input:%d C_result:%d ASM_result:%d\n",i,q,s,Dst[i],Dst2[i]); \ |
689 |
|
} \ |
690 |
|
} |
691 |
|
|
692 |
void test_quant() |
void test_quant() |
693 |
{ |
{ |
694 |
const int nb_tests = 1*speed_ref; |
const int nb_tests = 1*speed_ref; |
699 |
CPU *cpu; |
CPU *cpu; |
700 |
DECLARE_ALIGNED_MATRIX(Src, 8, 8, int16_t, 16); |
DECLARE_ALIGNED_MATRIX(Src, 8, 8, int16_t, 16); |
701 |
DECLARE_ALIGNED_MATRIX(Dst, 8, 8, int16_t, 16); |
DECLARE_ALIGNED_MATRIX(Dst, 8, 8, int16_t, 16); |
702 |
|
DECLARE_ALIGNED_MATRIX(Dst2,8, 8, int16_t, 16); |
703 |
uint8_t Quant[8*8]; |
uint8_t Quant[8*8]; |
704 |
|
|
705 |
printf( "\n ===== test quant =====\n" ); |
printf( "\n ===== test quant =====\n" ); |
720 |
if (!init_cpu(cpu)) |
if (!init_cpu(cpu)) |
721 |
continue; |
continue; |
722 |
|
|
723 |
|
// exhaustive tests to compare against the (ref) C-version |
724 |
|
TEST_INTRA(quant_h263_intra_c, quant_h263_intra, 2048); |
725 |
|
TEST_INTRA(dequant_h263_intra_c, dequant_h263_intra , 512 ); |
726 |
|
TEST_INTER(quant_h263_inter_c, quant_h263_inter , 2048); |
727 |
|
TEST_INTER(dequant_h263_inter_c, dequant_h263_inter , 512 ); |
728 |
|
|
729 |
overhead = -gettime_usec(); |
overhead = -gettime_usec(); |
730 |
for(s=0,qm=1; qm<=255; ++qm) { |
for(s=0,qm=1; qm<=255; ++qm) { |
731 |
for(i=0; i<8*8; ++i) Quant[i] = qm; |
for(i=0; i<8*8; ++i) Quant[i] = qm; |
780 |
} |
} |
781 |
|
|
782 |
/********************************************************************* |
/********************************************************************* |
783 |
|
* test distortion operators |
784 |
|
*********************************************************************/ |
785 |
|
|
786 |
|
static void ieee_reseed(long s); |
787 |
|
static long ieee_rand(int Min, int Max); |
788 |
|
|
789 |
|
#define TEST_SSE(FUNCTION, SRC1, SRC2, STRIDE) \ |
790 |
|
do { \ |
791 |
|
t = gettime_usec(); \ |
792 |
|
tst = nb_tests; \ |
793 |
|
while((tst--)>0) sse = (FUNCTION)((SRC1), (SRC2), (STRIDE)); \ |
794 |
|
emms(); \ |
795 |
|
t = (gettime_usec() - t)/(double)nb_tests; \ |
796 |
|
} while(0) |
797 |
|
|
798 |
|
|
799 |
|
void test_sse() |
800 |
|
{ |
801 |
|
const int nb_tests = 100000*speed_ref; |
802 |
|
int i; |
803 |
|
CPU *cpu; |
804 |
|
DECLARE_ALIGNED_MATRIX(Src1, 8, 8, int16_t, 16); |
805 |
|
DECLARE_ALIGNED_MATRIX(Src2, 8, 8, int16_t, 16); |
806 |
|
DECLARE_ALIGNED_MATRIX(Src3, 8, 8, int16_t, 16); |
807 |
|
DECLARE_ALIGNED_MATRIX(Src4, 8, 8, int16_t, 16); |
808 |
|
|
809 |
|
printf( "\n ===== test sse =====\n" ); |
810 |
|
|
811 |
|
ieee_reseed(1); |
812 |
|
for(i=0; i<64; ++i) { |
813 |
|
Src1[i] = ieee_rand(-2048, 2047); |
814 |
|
Src2[i] = ieee_rand(-2048, 2047); |
815 |
|
Src3[i] = ieee_rand(-2048, 2047); |
816 |
|
Src4[i] = ieee_rand(-2048, 2047); |
817 |
|
} |
818 |
|
|
819 |
|
for(cpu = cpu_list; cpu->name!=0; ++cpu) |
820 |
|
{ |
821 |
|
double t; |
822 |
|
int tst, sse; |
823 |
|
|
824 |
|
if (!init_cpu(cpu)) |
825 |
|
continue; |
826 |
|
|
827 |
|
/* 16 bit element blocks */ |
828 |
|
TEST_SSE(sse8_16bit, Src1, Src2, 16); |
829 |
|
printf("%s - sse8_16bit#1 %.3f usec sse=%d %s\n", |
830 |
|
cpu->name, t, sse, (sse!=182013834)?"| ERROR": ""); |
831 |
|
TEST_SSE(sse8_16bit, Src1, Src3, 16); |
832 |
|
printf("%s - sse8_16bit#2 %.3f usec sse=%d %s\n", |
833 |
|
cpu->name, t, sse, (sse!=142545203)?"| ERROR": ""); |
834 |
|
TEST_SSE(sse8_16bit, Src1, Src4, 16); |
835 |
|
printf("%s - sse8_16bit#3 %.3f usec sse=%d %s\n", |
836 |
|
cpu->name, t, sse, (sse!=146340935)?"| ERROR": ""); |
837 |
|
TEST_SSE(sse8_16bit, Src2, Src3, 16); |
838 |
|
printf("%s - sse8_16bit#4 %.3f usec sse=%d %s\n", |
839 |
|
cpu->name, t, sse, (sse!=130136661)?"| ERROR": ""); |
840 |
|
TEST_SSE(sse8_16bit, Src2, Src4, 16); |
841 |
|
printf("%s - sse8_16bit#5 %.3f usec sse=%d %s\n", |
842 |
|
cpu->name, t, sse, (sse!=136870353)?"| ERROR": ""); |
843 |
|
TEST_SSE(sse8_16bit, Src3, Src4, 16); |
844 |
|
printf("%s - sse8_16bit#6 %.3f usec sse=%d %s\n", |
845 |
|
cpu->name, t, sse, (sse!=164107772)?"| ERROR": ""); |
846 |
|
|
847 |
|
/* 8 bit element blocks */ |
848 |
|
TEST_SSE(sse8_8bit, (int8_t*)Src1, (int8_t*)Src2, 8); |
849 |
|
printf("%s - sse8_8bit#1 %.3f usec sse=%d %s\n", |
850 |
|
cpu->name, t, sse, (sse!=1356423)?"| ERROR": ""); |
851 |
|
TEST_SSE(sse8_8bit, (int8_t*)Src1, (int8_t*)Src3, 8); |
852 |
|
printf("%s - sse8_8bit#2 %.3f usec sse=%d %s\n", |
853 |
|
cpu->name, t, sse, (sse!=1173074)?"| ERROR": ""); |
854 |
|
TEST_SSE(sse8_8bit, (int8_t*)Src1, (int8_t*)Src4, 8); |
855 |
|
printf("%s - sse8_8bit#3 %.3f usec sse=%d %s\n", |
856 |
|
cpu->name, t, sse, (sse!=1092357)?"| ERROR": ""); |
857 |
|
TEST_SSE(sse8_8bit, (int8_t*)Src2, (int8_t*)Src3, 8); |
858 |
|
printf("%s - sse8_8bit#4 %.3f usec sse=%d %s\n", |
859 |
|
cpu->name, t, sse, (sse!=1360239)?"| ERROR": ""); |
860 |
|
TEST_SSE(sse8_8bit, (int8_t*)Src2, (int8_t*)Src4, 8); |
861 |
|
printf("%s - sse8_8bit#5 %.3f usec sse=%d %s\n", |
862 |
|
cpu->name, t, sse, (sse!=1208414)?"| ERROR": ""); |
863 |
|
TEST_SSE(sse8_8bit, (int8_t*)Src3, (int8_t*)Src4, 8); |
864 |
|
printf("%s - sse8_8bit#6 %.3f usec sse=%d %s\n", |
865 |
|
cpu->name, t, sse, (sse!=1099285)?"| ERROR": ""); |
866 |
|
|
867 |
|
printf(" ---\n"); |
868 |
|
} |
869 |
|
} |
870 |
|
|
871 |
|
/********************************************************************* |
872 |
* test non-zero AC counting |
* test non-zero AC counting |
873 |
*********************************************************************/ |
*********************************************************************/ |
874 |
|
|
909 |
continue; |
continue; |
910 |
|
|
911 |
TEST_CBP(calc_cbp, Src1); |
TEST_CBP(calc_cbp, Src1); |
912 |
printf("%s - calc_cbp#1 %.3f usec cbp=0x%02x\n", |
printf("%s - calc_cbp#1 %.3f usec cbp=0x%02x %s\n", |
913 |
cpu->name, t, cbp, (cbp!=0x15)?"| ERROR": ""); |
cpu->name, t, cbp, (cbp!=0x15)?"| ERROR": ""); |
914 |
TEST_CBP(calc_cbp, Src2); |
TEST_CBP(calc_cbp, Src2); |
915 |
printf("%s - calc_cbp#2 %.3f usec cbp=0x%02x\n", |
printf("%s - calc_cbp#2 %.3f usec cbp=0x%02x %s\n", |
916 |
cpu->name, t, cbp, (cbp!=0x38)?"| ERROR": ""); |
cpu->name, t, cbp, (cbp!=0x38)?"| ERROR": ""); |
917 |
TEST_CBP(calc_cbp, Src3); |
TEST_CBP(calc_cbp, Src3); |
918 |
printf("%s - calc_cbp#3 %.3f usec cbp=0x%02x\n", |
printf("%s - calc_cbp#3 %.3f usec cbp=0x%02x %s\n", |
919 |
cpu->name, t, cbp, (cbp!=0x0f)?"| ERROR": "" ); |
cpu->name, t, cbp, (cbp!=0x0f)?"| ERROR": "" ); |
920 |
TEST_CBP(calc_cbp, Src4); |
TEST_CBP(calc_cbp, Src4); |
921 |
printf("%s - calc_cbp#4 %.3f usec cbp=0x%02x\n", |
printf("%s - calc_cbp#4 %.3f usec cbp=0x%02x %s\n", |
922 |
cpu->name, t, cbp, (cbp!=0x05)?"| ERROR": "" ); |
cpu->name, t, cbp, (cbp!=0x05)?"| ERROR": "" ); |
923 |
printf( " --- \n" ); |
printf( " --- \n" ); |
924 |
} |
} |
1588 |
if (what==0 || what==4) test_transfer(); |
if (what==0 || what==4) test_transfer(); |
1589 |
if (what==0 || what==5) test_quant(); |
if (what==0 || what==5) test_quant(); |
1590 |
if (what==0 || what==6) test_cbp(); |
if (what==0 || what==6) test_cbp(); |
1591 |
|
if (what==0 || what==10) test_sse(); |
1592 |
|
|
1593 |
if (what==7) { |
if (what==7) { |
1594 |
test_IEEE1180_compliance(-256, 255, 1); |
test_IEEE1180_compliance(-256, 255, 1); |
1618 |
if (what==-2) |
if (what==-2) |
1619 |
test_quant_bug(); |
test_quant_bug(); |
1620 |
|
|
1621 |
if (what >= 0 && what <= 6) { |
if ((what >= 0 && what <= 6) || what == 10) { |
1622 |
printf("\n\n" |
printf("\n\n" |
1623 |
"NB: If a function isn't optimised for a specific set of intructions,\n" |
"NB: If a function isn't optimised for a specific set of intructions,\n" |
1624 |
" a C function is used instead. So don't panic if some functions\n" |
" a C function is used instead. So don't panic if some functions\n" |