1 |
/************************************************************************** |
/***************************************************************************** |
2 |
* |
* |
3 |
* XVID MPEG-4 VIDEO CODEC - Unit tests and benches |
* XVID MPEG-4 VIDEO CODEC |
4 |
|
* - Unit tests and benches - |
5 |
|
* |
6 |
|
* Copyright(C) 2002 Pascal Massimino <skal@planet-d.net> |
7 |
* |
* |
8 |
* This program is free software; you can redistribute it and/or modify |
* This program is free software; you can redistribute it and/or modify |
9 |
* it under the terms of the GNU General Public License as published by |
* it under the terms of the GNU General Public License as published by |
17 |
* |
* |
18 |
* You should have received a copy of the GNU General Public License |
* You should have received a copy of the GNU General Public License |
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., 675 Mass Ave, Cambridge, MA 02139, USA. |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
21 |
|
* |
22 |
|
* $Id$ |
23 |
* |
* |
24 |
*************************************************************************/ |
****************************************************************************/ |
25 |
|
|
26 |
/************************************************************************ |
/***************************************************************************** |
27 |
* |
* |
28 |
* 'Reference' output is at the end of file. |
* 'Reference' output is at the end of file. |
29 |
* Don't take the checksums and crc too seriouly, they aren't |
* Don't take the checksums and crc too seriouly, they aren't |
32 |
* compiles with something like: |
* compiles with something like: |
33 |
* gcc -o xvid_bench xvid_bench.c -I../src/ -lxvidcore -lm |
* gcc -o xvid_bench xvid_bench.c -I../src/ -lxvidcore -lm |
34 |
* |
* |
35 |
* History: |
****************************************************************************/ |
|
* |
|
|
* 06.06.2002 initial coding -Skal- |
|
|
* |
|
|
*************************************************************************/ |
|
36 |
|
|
37 |
#include <stdio.h> |
#include <stdio.h> |
38 |
#include <stdlib.h> |
#include <stdlib.h> |
39 |
#include <sys/time.h> // for gettimeofday |
#include <string.h> /* for memset */ |
|
#include <string.h> // for memset |
|
40 |
#include <assert.h> |
#include <assert.h> |
41 |
|
|
42 |
|
#ifndef WIN32 |
43 |
|
#include <sys/time.h> /* for gettimeofday */ |
44 |
|
#else |
45 |
|
#include <time.h> |
46 |
|
#endif |
47 |
|
|
48 |
|
|
49 |
#include "xvid.h" |
#include "xvid.h" |
50 |
|
|
51 |
// inner guts |
// inner guts |
63 |
#include "bitstream/cbp.h" |
#include "bitstream/cbp.h" |
64 |
|
|
65 |
#include <math.h> |
#include <math.h> |
66 |
const int speed_ref = 100; // on slow machines, decrease this value |
|
67 |
|
#ifndef M_PI |
68 |
|
#define M_PI 3.14159265358979323846 |
69 |
|
#endif |
70 |
|
|
71 |
|
const int speed_ref = 100; /* on slow machines, decrease this value */ |
72 |
|
|
73 |
/********************************************************************* |
/********************************************************************* |
74 |
* misc |
* misc |
77 |
/* returns time in micro-s*/ |
/* returns time in micro-s*/ |
78 |
double gettime_usec() |
double gettime_usec() |
79 |
{ |
{ |
80 |
|
#ifndef WIN32 |
81 |
struct timeval tv; |
struct timeval tv; |
82 |
gettimeofday(&tv, 0); |
gettimeofday(&tv, 0); |
83 |
return tv.tv_sec*1.0e6f + tv.tv_usec; |
return tv.tv_sec*1.0e6 + tv.tv_usec; |
84 |
|
#else |
85 |
|
clock_t clk; |
86 |
|
clk = clock(); |
87 |
|
return clk * 1000000 / CLOCKS_PER_SEC; |
88 |
|
#endif |
89 |
} |
} |
90 |
|
|
91 |
/* returns squared deviates (mean(v*v)-mean(v)^2) of a 8x8 block */ |
/* returns squared deviates (mean(v*v)-mean(v)^2) of a 8x8 block */ |
120 |
, { "SSE2 ", XVID_CPU_SSE2 | XVID_CPU_MMX } |
, { "SSE2 ", XVID_CPU_SSE2 | XVID_CPU_MMX } |
121 |
, { "3DNOW ", XVID_CPU_3DNOW } |
, { "3DNOW ", XVID_CPU_3DNOW } |
122 |
, { "3DNOWE", XVID_CPU_3DNOWEXT } |
, { "3DNOWE", XVID_CPU_3DNOWEXT } |
123 |
|
, { "IA64 ", XVID_CPU_IA64 } |
124 |
//, { "TSC ", XVID_CPU_TSC } |
//, { "TSC ", XVID_CPU_TSC } |
125 |
, { 0, 0 } } |
, { 0, 0 } } |
126 |
|
|
128 |
{ { "PLAINC", 0 } |
{ { "PLAINC", 0 } |
129 |
, { "MMX ", XVID_CPU_MMX } |
, { "MMX ", XVID_CPU_MMX } |
130 |
//, { "MMXEXT", XVID_CPU_MMXEXT | XVID_CPU_MMX } |
//, { "MMXEXT", XVID_CPU_MMXEXT | XVID_CPU_MMX } |
131 |
|
, { "IA64 ", XVID_CPU_IA64 } |
132 |
, { 0, 0 } } |
, { 0, 0 } } |
133 |
|
|
134 |
, cpu_short_list2[] = |
, cpu_short_list2[] = |
145 |
|
|
146 |
cpu_type = check_cpu_features() & cpu->cpu; |
cpu_type = check_cpu_features() & cpu->cpu; |
147 |
xinit.cpu_flags = cpu_type | XVID_CPU_FORCE; |
xinit.cpu_flags = cpu_type | XVID_CPU_FORCE; |
148 |
// xinit.cpu_flags = XVID_CPU_MMX | XVID_CPU_FORCE; |
/* xinit.cpu_flags = XVID_CPU_MMX | XVID_CPU_FORCE; */ |
149 |
xerr = xvid_init(NULL, 0, &xinit, NULL); |
xerr = xvid_init(NULL, 0, &xinit, NULL); |
150 |
if (cpu->cpu>0 && (cpu_type==0 || xerr!=XVID_ERR_OK)) { |
if (cpu->cpu>0 && (cpu_type==0 || xerr!=XVID_ERR_OK)) { |
151 |
printf( "%s - skipped...\n", cpu->name ); |
printf( "%s - skipped...\n", cpu->name ); |
303 |
const int nb_tests = 2000*speed_ref; |
const int nb_tests = 2000*speed_ref; |
304 |
CPU *cpu; |
CPU *cpu; |
305 |
const uint8_t Src0[16*9] = { |
const uint8_t Src0[16*9] = { |
306 |
// try to have every possible combinaison of rounding... |
/* try to have every possible combinaison of rounding... */ |
307 |
0, 0, 1, 0, 2, 0, 3, 0, 4 ,0,0,0, 0,0,0,0 |
0, 0, 1, 0, 2, 0, 3, 0, 4 ,0,0,0, 0,0,0,0 |
308 |
, 0, 1, 1, 1, 2, 1, 3, 1, 3 ,0,0,0, 0,0,0,0 |
, 0, 1, 1, 1, 2, 1, 3, 1, 3 ,0,0,0, 0,0,0,0 |
309 |
, 0, 2, 1, 2, 2, 2, 3, 2, 2 ,0,0,0, 0,0,0,0 |
, 0, 2, 1, 2, 2, 2, 3, 2, 2 ,0,0,0, 0,0,0,0 |
353 |
if (iCrc!=8103) printf( "*** CRC ERROR! ***\n" ); |
if (iCrc!=8103) printf( "*** CRC ERROR! ***\n" ); |
354 |
|
|
355 |
|
|
356 |
// this is a new function, as of 06.06.2002 |
/* this is a new function, as of 06.06.2002 */ |
357 |
#if 0 |
#if 0 |
358 |
TEST_MB2(interpolate8x8_avrg); |
TEST_MB2(interpolate8x8_avrg); |
359 |
printf( "%s - interpolate8x8_c %.3f usec iCrc=%d\n", cpu->name, t, iCrc ); |
printf( "%s - interpolate8x8_c %.3f usec iCrc=%d\n", cpu->name, t, iCrc ); |
529 |
|
|
530 |
printf( "\n ===== test quant =====\n" ); |
printf( "\n ===== test quant =====\n" ); |
531 |
|
|
532 |
// we deliberately enfringe the norm's specified range [-127,127], |
/* we deliberately enfringe the norm's specified range [-127,127], */ |
533 |
// to test the robustness of the iquant module |
/* to test the robustness of the iquant module */ |
534 |
for(i=0; i<64; ++i) { |
for(i=0; i<64; ++i) { |
535 |
Src[i] = 1 + (i-32) * (i&6); |
Src[i] = 1 + (i-32) * (i&6); |
536 |
Dst[i] = 0; |
Dst[i] = 0; |
617 |
printf( "\n ===== test cbp =====\n" ); |
printf( "\n ===== test cbp =====\n" ); |
618 |
|
|
619 |
for(i=0; i<6*64; ++i) { |
for(i=0; i<6*64; ++i) { |
620 |
Src1[i] = (i*i*3/8192)&(i/64)&1; // 'random' |
Src1[i] = (i*i*3/8192)&(i/64)&1; /* 'random' */ |
621 |
Src2[i] = (i<3*64); // half-full |
Src2[i] = (i<3*64); /* half-full */ |
622 |
Src3[i] = ((i+32)>3*64); |
Src3[i] = ((i+32)>3*64); |
623 |
Src4[i] = (i==(3*64+2) || i==(5*64+9)); |
Src4[i] = (i==(3*64+2) || i==(5*64+9)); |
624 |
} |
} |
773 |
} |
} |
774 |
} |
} |
775 |
|
|
776 |
////////////////////////////////////////////////////////// |
///* ////////////////////////////////////////////////////// */ |
777 |
/* Pseudo-random generator specified by IEEE 1180 */ |
/* Pseudo-random generator specified by IEEE 1180 */ |
778 |
|
|
779 |
static long ieee_seed = 1; |
static long ieee_seed = 1; |
860 |
static const double ILimits[5] = { 1., 0.06, 0.02, 0.015, 0.0015 }; |
static const double ILimits[5] = { 1., 0.06, 0.02, 0.015, 0.0015 }; |
861 |
int Loops = 10000; |
int Loops = 10000; |
862 |
int i, m, n; |
int i, m, n; |
863 |
short Blk0[64]; // reference |
short Blk0[64]; /* reference */ |
864 |
short Blk[64], iBlk[64]; |
short Blk[64], iBlk[64]; |
865 |
short Ref_FDCT[64]; |
short Ref_FDCT[64]; |
866 |
short Ref_IDCT[64]; |
short Ref_IDCT[64]; |
867 |
|
|
868 |
STATS_8x8 FStats; // forward dct stats |
STATS_8x8 FStats; /* forward dct stats */ |
869 |
STATS_8x8 IStats; // inverse dct stats |
STATS_8x8 IStats; /* inverse dct stats */ |
870 |
|
|
871 |
CPU *cpu; |
CPU *cpu; |
872 |
|
|
889 |
for(i=0; i<64; ++i) |
for(i=0; i<64; ++i) |
890 |
Blk0[i] = (short)ieee_rand(Min,Max) * Sign; |
Blk0[i] = (short)ieee_rand(Min,Max) * Sign; |
891 |
|
|
892 |
// hmm, I'm not quite sure this is exactly |
/* hmm, I'm not quite sure this is exactly */ |
893 |
// the tests described in the norm. check... |
/* the tests described in the norm. check... */ |
894 |
|
|
895 |
memcpy(Ref_FDCT, Blk0, 64*sizeof(short)); |
memcpy(Ref_FDCT, Blk0, 64*sizeof(short)); |
896 |
ref_fdct(Ref_FDCT); |
ref_fdct(Ref_FDCT); |
917 |
|
|
918 |
printf( "\n -- FDCT report --\n" ); |
printf( "\n -- FDCT report --\n" ); |
919 |
// print_stats(&FStats); |
// print_stats(&FStats); |
920 |
report_stats(&FStats, 0); // so far I know, IEEE1180 says nothing for fdct |
report_stats(&FStats, 0); /* so far I know, IEEE1180 says nothing for fdct */ |
921 |
|
|
922 |
for(i=0; i<64; i++) Blk[i] = 0; |
for(i=0; i<64; i++) Blk[i] = 0; |
923 |
emms(); fdct(Blk); emms(); |
emms(); fdct(Blk); emms(); |
939 |
|
|
940 |
void test_dct_saturation(int Min, int Max) |
void test_dct_saturation(int Min, int Max) |
941 |
{ |
{ |
942 |
// test behaviour on input range fringe |
/* test behaviour on input range fringe */ |
943 |
|
|
944 |
int i, n, p; |
int i, n, p; |
945 |
CPU *cpu; |
CPU *cpu; |
946 |
// const short IDCT_MAX = 2047; // 12bits input |
// const short IDCT_MAX = 2047; /* 12bits input */ |
947 |
// const short IDCT_MIN = -2048; |
// const short IDCT_MIN = -2048; |
948 |
// const short IDCT_OUT = 256; // 9bits ouput |
// const short IDCT_OUT = 256; /* 9bits ouput */ |
949 |
const int Partitions = 4; |
const int Partitions = 4; |
950 |
const int Loops = 10000 / Partitions; |
const int Loops = 10000 / Partitions; |
951 |
|
|
962 |
printf( "\n===== IEEE test for %s Min=%d Max=%d =====\n", |
printf( "\n===== IEEE test for %s Min=%d Max=%d =====\n", |
963 |
cpu->name, Min, Max ); |
cpu->name, Min, Max ); |
964 |
|
|
965 |
// FDCT tests // |
/* FDCT tests // */ |
966 |
|
|
967 |
init_stats(&Stats); |
init_stats(&Stats); |
968 |
|
|
969 |
// test each computation channels separately |
/* test each computation channels separately */ |
970 |
for(i=0; i<64; i++) Blk[i] = Blk0[i] = ((i/8)==(i%8)) ? Max : 0; |
for(i=0; i<64; i++) Blk[i] = Blk0[i] = ((i/8)==(i%8)) ? Max : 0; |
971 |
ref_fdct(Blk0); |
ref_fdct(Blk0); |
972 |
emms(); fdct(Blk); emms(); |
emms(); fdct(Blk); emms(); |
977 |
emms(); fdct(Blk); emms(); |
emms(); fdct(Blk); emms(); |
978 |
store_stats(&Stats, Blk, Blk0); |
store_stats(&Stats, Blk, Blk0); |
979 |
|
|
980 |
// randomly saturated inputs |
/* randomly saturated inputs */ |
981 |
for(p=0; p<Partitions; ++p) |
for(p=0; p<Partitions; ++p) |
982 |
{ |
{ |
983 |
for(n=0; n<Loops; ++n) |
for(n=0; n<Loops; ++n) |
993 |
report_stats(&Stats, 0); |
report_stats(&Stats, 0); |
994 |
|
|
995 |
|
|
996 |
// IDCT tests // |
/* IDCT tests // */ |
997 |
#if 0 |
#if 0 |
998 |
// no finished yet |
/* no finished yet */ |
999 |
|
|
1000 |
init_stats(&Stats); |
init_stats(&Stats); |
1001 |
|
|
1002 |
// test each computation channel separately |
/* test each computation channel separately */ |
1003 |
for(i=0; i<64; i++) Blk[i] = Blk0[i] = ((i/8)==(i%8)) ? IDCT_MAX : 0; |
for(i=0; i<64; i++) Blk[i] = Blk0[i] = ((i/8)==(i%8)) ? IDCT_MAX : 0; |
1004 |
ref_idct(Blk0); |
ref_idct(Blk0); |
1005 |
emms(); idct(Blk); emms(); |
emms(); idct(Blk); emms(); |
1012 |
for(i=0; i<64; i++) { CLAMP(Blk0[i], IDCT_OUT); CLAMP(Blk[i], IDCT_OUT); } |
for(i=0; i<64; i++) { CLAMP(Blk0[i], IDCT_OUT); CLAMP(Blk[i], IDCT_OUT); } |
1013 |
store_stats(&Stats, Blk, Blk0); |
store_stats(&Stats, Blk, Blk0); |
1014 |
|
|
1015 |
// randomly saturated inputs |
/* randomly saturated inputs */ |
1016 |
for(p=0; p<Partitions; ++p) |
for(p=0; p<Partitions; ++p) |
1017 |
{ |
{ |
1018 |
for(n=0; n<Loops; ++n) |
for(n=0; n<Loops; ++n) |
1081 |
} |
} |
1082 |
else printf( "Input size: %d\n", buf_size); |
else printf( "Input size: %d\n", buf_size); |
1083 |
|
|
1084 |
buf = malloc(buf_size); // should be enuf' |
buf = malloc(buf_size); /* should be enuf' */ |
1085 |
rgb_out = calloc(4, width*height); // <-room for _RGB24 |
rgb_out = calloc(4, width*height); /* <-room for _RGB24 */ |
1086 |
if (buf==0 || rgb_out==0) { |
if (buf==0 || rgb_out==0) { |
1087 |
printf( "malloc failed!\n" ); |
printf( "malloc failed!\n" ); |
1088 |
goto End; |
goto End; |