24 |
* Don't take the checksums and crc too seriouly, they aren't |
* Don't take the checksums and crc too seriouly, they aren't |
25 |
* bullet-proof (should plug some .md5 here)... |
* bullet-proof (should plug some .md5 here)... |
26 |
* |
* |
27 |
* compiles with something like: |
* compiles best at xvidcore/src-dir with something like |
28 |
* gcc -o xvid_bench xvid_bench.c -I../src/ -lxvidcore -lm |
* |
29 |
|
* gcc -DARCH_IS_IA32 -DARCH_IS_32BIT -o xvid_bench xvid_bench.c \ |
30 |
|
* ../build/generic/libxvidcore.a -lm |
31 |
* |
* |
32 |
* History: |
* History: |
33 |
* |
* |
34 |
* 06.06.2002 initial coding -Skal- |
* 06.06.2002 initial coding -Skal- |
35 |
|
* 27.02.2003 minor changes (compile, sad16v) <gruel@web.de> |
36 |
* |
* |
37 |
*************************************************************************/ |
*************************************************************************/ |
38 |
|
|
39 |
#include <stdio.h> |
#include <stdio.h> |
40 |
#include <stdlib.h> |
#include <stdlib.h> |
41 |
#ifdef WIN32 |
#include <string.h> // for memset |
42 |
#include <time.h> /* for clock */ |
#include <assert.h> |
43 |
|
|
44 |
|
#ifndef WIN32 |
45 |
|
#include <sys/time.h> // for gettimeofday |
46 |
#else |
#else |
47 |
#include <sys/time.h> /* for gettimeofday */ |
#include <time.h> |
48 |
#endif |
#endif |
49 |
#include <string.h> /* for memset */ |
|
|
#include <assert.h> |
|
50 |
|
|
51 |
#include "xvid.h" |
#include "xvid.h" |
52 |
|
|
53 |
/* inner guts */ |
// inner guts |
54 |
#include "dct/idct.h" |
#include "dct/idct.h" |
55 |
#include "dct/fdct.h" |
#include "dct/fdct.h" |
56 |
#include "image/colorspace.h" |
#include "image/colorspace.h" |
65 |
#include "bitstream/cbp.h" |
#include "bitstream/cbp.h" |
66 |
|
|
67 |
#include <math.h> |
#include <math.h> |
68 |
|
|
69 |
#ifndef M_PI |
#ifndef M_PI |
70 |
# define M_PI 3.14159265359 |
#define M_PI 3.14159265358979323846 |
|
# define M_PI_2 1.5707963268 |
|
71 |
#endif |
#endif |
72 |
const int speed_ref = 100; /* on slow machines, decrease this value */ |
|
73 |
|
const int speed_ref = 100; // on slow machines, decrease this value |
74 |
|
|
75 |
/********************************************************************* |
/********************************************************************* |
76 |
* misc |
* misc |
79 |
/* returns time in micro-s*/ |
/* returns time in micro-s*/ |
80 |
double gettime_usec() |
double gettime_usec() |
81 |
{ |
{ |
82 |
#ifdef WIN32 |
#ifndef WIN32 |
|
return clock()*1000; |
|
|
#else |
|
83 |
struct timeval tv; |
struct timeval tv; |
84 |
gettimeofday(&tv, 0); |
gettimeofday(&tv, 0); |
85 |
return tv.tv_sec*1.0e6 + tv.tv_usec; |
return tv.tv_sec*1.0e6 + tv.tv_usec; |
86 |
|
#else |
87 |
|
clock_t clk; |
88 |
|
clk = clock(); |
89 |
|
return clk * 1000000 / CLOCKS_PER_SEC; |
90 |
#endif |
#endif |
91 |
} |
} |
92 |
|
|
123 |
, { "3DNOW ", XVID_CPU_3DNOW } |
, { "3DNOW ", XVID_CPU_3DNOW } |
124 |
, { "3DNOWE", XVID_CPU_3DNOWEXT } |
, { "3DNOWE", XVID_CPU_3DNOWEXT } |
125 |
, { "IA64 ", XVID_CPU_IA64 } |
, { "IA64 ", XVID_CPU_IA64 } |
126 |
/*, { "TSC ", XVID_CPU_TSC } */ |
//, { "TSC ", XVID_CPU_TSC } |
127 |
, { 0, 0 } } |
, { 0, 0 } } |
128 |
|
|
129 |
, cpu_short_list[] = |
, cpu_short_list[] = |
130 |
{ { "PLAINC", 0 } |
{ { "PLAINC", 0 } |
131 |
, { "MMX ", XVID_CPU_MMX } |
, { "MMX ", XVID_CPU_MMX } |
132 |
/*, { "MMXEXT", XVID_CPU_MMXEXT | XVID_CPU_MMX } */ |
//, { "MMXEXT", XVID_CPU_MMXEXT | XVID_CPU_MMX } |
133 |
, { "IA64 ", XVID_CPU_IA64 } |
, { "IA64 ", XVID_CPU_IA64 } |
134 |
, { 0, 0 } } |
, { 0, 0 } } |
135 |
|
|
147 |
|
|
148 |
cpu_type = check_cpu_features() & cpu->cpu; |
cpu_type = check_cpu_features() & cpu->cpu; |
149 |
xinit.cpu_flags = cpu_type | XVID_CPU_FORCE; |
xinit.cpu_flags = cpu_type | XVID_CPU_FORCE; |
150 |
/* xinit.cpu_flags = XVID_CPU_MMX | XVID_CPU_FORCE; */ |
// xinit.cpu_flags = XVID_CPU_MMX | XVID_CPU_FORCE; |
151 |
xerr = xvid_init(NULL, 0, &xinit, NULL); |
xerr = xvid_init(NULL, 0, &xinit, NULL); |
152 |
if (cpu->cpu>0 && (cpu_type==0 || xerr!=XVID_ERR_OK)) { |
if (cpu->cpu>0 && (cpu_type==0 || xerr!=XVID_ERR_OK)) { |
153 |
printf( "%s - skipped...\n", cpu->name ); |
printf( "%s - skipped...\n", cpu->name ); |
219 |
void test_sad() |
void test_sad() |
220 |
{ |
{ |
221 |
const int nb_tests = 2000*speed_ref; |
const int nb_tests = 2000*speed_ref; |
222 |
int tst; |
int tst,dummy[4]; |
223 |
CPU *cpu; |
CPU *cpu; |
224 |
int i; |
int i; |
225 |
uint8_t Cur[16*16], Ref1[16*16], Ref2[16*16]; |
uint8_t Cur[16*16], Ref1[16*16], Ref2[16*16]; |
248 |
|
|
249 |
t = gettime_usec(); |
t = gettime_usec(); |
250 |
emms(); |
emms(); |
251 |
for(tst=0; tst<nb_tests; ++tst) s = sad16(Cur, Ref1, 16, -1); |
for(tst=0; tst<nb_tests; ++tst) s = sad16(Cur, Ref1, 16, 65535); |
252 |
emms(); |
emms(); |
253 |
t = (gettime_usec() - t) / nb_tests; |
t = (gettime_usec() - t) / nb_tests; |
254 |
printf( "%s - sad16 %.3f usec sad=%d\n", cpu->name, t, s ); |
printf( "%s - sad16 %.3f usec sad=%d\n", cpu->name, t, s ); |
256 |
|
|
257 |
t = gettime_usec(); |
t = gettime_usec(); |
258 |
emms(); |
emms(); |
259 |
|
for(tst=0; tst<nb_tests; ++tst) s = sad16v(Cur, Ref1, 16, dummy); |
260 |
|
emms(); |
261 |
|
t = (gettime_usec() - t) / nb_tests; |
262 |
|
printf( "%s - sad16v %.3f usec sad=%d\n", cpu->name, t, s ); |
263 |
|
if (s!=27214) printf( "*** CRC ERROR! ***\n" ); |
264 |
|
|
265 |
|
t = gettime_usec(); |
266 |
|
emms(); |
267 |
for(tst=0; tst<nb_tests; ++tst) s = sad16bi(Cur, Ref1, Ref2, 16); |
for(tst=0; tst<nb_tests; ++tst) s = sad16bi(Cur, Ref1, Ref2, 16); |
268 |
emms(); |
emms(); |
269 |
t = (gettime_usec() - t) / nb_tests; |
t = (gettime_usec() - t) / nb_tests; |
313 |
const int nb_tests = 2000*speed_ref; |
const int nb_tests = 2000*speed_ref; |
314 |
CPU *cpu; |
CPU *cpu; |
315 |
const uint8_t Src0[16*9] = { |
const uint8_t Src0[16*9] = { |
316 |
/* try to have every possible combinaison of rounding... */ |
// try to have every possible combinaison of rounding... |
317 |
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 |
318 |
, 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 |
319 |
, 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 |
363 |
if (iCrc!=8103) printf( "*** CRC ERROR! ***\n" ); |
if (iCrc!=8103) printf( "*** CRC ERROR! ***\n" ); |
364 |
|
|
365 |
|
|
366 |
/* this is a new function, as of 06.06.2002 */ |
// this is a new function, as of 06.06.2002 |
367 |
#if 0 |
#if 0 |
368 |
TEST_MB2(interpolate8x8_avrg); |
TEST_MB2(interpolate8x8_avrg); |
369 |
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 ); |
485 |
TEST_TRANSFER3(transfer_8to16sub2, Dst16, Src8, Ref1, Ref2); |
TEST_TRANSFER3(transfer_8to16sub2, Dst16, Src8, Ref1, Ref2); |
486 |
printf( "%s - 8to16sub2 %.3f usec crc=%d\n", cpu->name, t, s ); |
printf( "%s - 8to16sub2 %.3f usec crc=%d\n", cpu->name, t, s ); |
487 |
if (s!=20384) printf( "*** CRC ERROR! ***\n" ); |
if (s!=20384) printf( "*** CRC ERROR! ***\n" ); |
488 |
/* for(i=0; i<64; ++i) printf( "[%d]", Dst16[i]); */ |
// for(i=0; i<64; ++i) printf( "[%d]", Dst16[i]); |
489 |
/* printf("\n"); */ |
// printf("\n"); |
490 |
#endif |
#endif |
491 |
printf( " --- \n" ); |
printf( " --- \n" ); |
492 |
} |
} |
539 |
|
|
540 |
printf( "\n ===== test quant =====\n" ); |
printf( "\n ===== test quant =====\n" ); |
541 |
|
|
542 |
/* we deliberately enfringe the norm's specified range [-127,127], */ |
// we deliberately enfringe the norm's specified range [-127,127], |
543 |
/* to test the robustness of the iquant module */ |
// to test the robustness of the iquant module |
544 |
for(i=0; i<64; ++i) { |
for(i=0; i<64; ++i) { |
545 |
Src[i] = 1 + (i-32) * (i&6); |
Src[i] = 1 + (i-32) * (i&6); |
546 |
Dst[i] = 0; |
Dst[i] = 0; |
627 |
printf( "\n ===== test cbp =====\n" ); |
printf( "\n ===== test cbp =====\n" ); |
628 |
|
|
629 |
for(i=0; i<6*64; ++i) { |
for(i=0; i<6*64; ++i) { |
630 |
Src1[i] = (i*i*3/8192)&(i/64)&1; /* 'random' */ |
Src1[i] = (i*i*3/8192)&(i/64)&1; // 'random' |
631 |
Src2[i] = (i<3*64); /* half-full */ |
Src2[i] = (i<3*64); // half-full |
632 |
Src3[i] = ((i+32)>3*64); |
Src3[i] = ((i+32)>3*64); |
633 |
Src4[i] = (i==(3*64+2) || i==(5*64+9)); |
Src4[i] = (i==(3*64+2) || i==(5*64+9)); |
634 |
} |
} |
783 |
} |
} |
784 |
} |
} |
785 |
|
|
786 |
/*//////////////////////////////////////////////////////// */ |
////////////////////////////////////////////////////////// |
787 |
/* Pseudo-random generator specified by IEEE 1180 */ |
/* Pseudo-random generator specified by IEEE 1180 */ |
788 |
|
|
789 |
static long ieee_seed = 1; |
static long ieee_seed = 1; |
870 |
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 }; |
871 |
int Loops = 10000; |
int Loops = 10000; |
872 |
int i, m, n; |
int i, m, n; |
873 |
short Blk0[64]; /* reference */ |
short Blk0[64]; // reference |
874 |
short Blk[64], iBlk[64]; |
short Blk[64], iBlk[64]; |
875 |
short Ref_FDCT[64]; |
short Ref_FDCT[64]; |
876 |
short Ref_IDCT[64]; |
short Ref_IDCT[64]; |
877 |
|
|
878 |
STATS_8x8 FStats; /* forward dct stats */ |
STATS_8x8 FStats; // forward dct stats |
879 |
STATS_8x8 IStats; /* inverse dct stats */ |
STATS_8x8 IStats; // inverse dct stats |
880 |
|
|
881 |
CPU *cpu; |
CPU *cpu; |
882 |
|
|
899 |
for(i=0; i<64; ++i) |
for(i=0; i<64; ++i) |
900 |
Blk0[i] = (short)ieee_rand(Min,Max) * Sign; |
Blk0[i] = (short)ieee_rand(Min,Max) * Sign; |
901 |
|
|
902 |
/* hmm, I'm not quite sure this is exactly */ |
// hmm, I'm not quite sure this is exactly |
903 |
/* the tests described in the norm. check... */ |
// the tests described in the norm. check... |
904 |
|
|
905 |
memcpy(Ref_FDCT, Blk0, 64*sizeof(short)); |
memcpy(Ref_FDCT, Blk0, 64*sizeof(short)); |
906 |
ref_fdct(Ref_FDCT); |
ref_fdct(Ref_FDCT); |
926 |
|
|
927 |
|
|
928 |
printf( "\n -- FDCT report --\n" ); |
printf( "\n -- FDCT report --\n" ); |
929 |
/* print_stats(&FStats); */ |
// print_stats(&FStats); |
930 |
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 |
931 |
|
|
932 |
for(i=0; i<64; i++) Blk[i] = 0; |
for(i=0; i<64; i++) Blk[i] = 0; |
933 |
emms(); fdct(Blk); emms(); |
emms(); fdct(Blk); emms(); |
935 |
printf( "FDCT(0) == 0 ? %s\n", (m!=0) ? "NOPE!" : "yup." ); |
printf( "FDCT(0) == 0 ? %s\n", (m!=0) ? "NOPE!" : "yup." ); |
936 |
|
|
937 |
printf( "\n -- IDCT report --\n" ); |
printf( "\n -- IDCT report --\n" ); |
938 |
/* print_stats(&IStats); */ |
// print_stats(&IStats); |
939 |
report_stats(&IStats, ILimits); |
report_stats(&IStats, ILimits); |
940 |
|
|
941 |
|
|
949 |
|
|
950 |
void test_dct_saturation(int Min, int Max) |
void test_dct_saturation(int Min, int Max) |
951 |
{ |
{ |
952 |
/* test behaviour on input range fringe */ |
// test behaviour on input range fringe |
953 |
|
|
954 |
int i, n, p; |
int i, n, p; |
955 |
CPU *cpu; |
CPU *cpu; |
956 |
/* const short IDCT_MAX = 2047; // 12bits input */ |
// const short IDCT_MAX = 2047; // 12bits input |
957 |
/* const short IDCT_MIN = -2048; */ |
// const short IDCT_MIN = -2048; |
958 |
/* const short IDCT_OUT = 256; // 9bits ouput */ |
// const short IDCT_OUT = 256; // 9bits ouput |
959 |
const int Partitions = 4; |
const int Partitions = 4; |
960 |
const int Loops = 10000 / Partitions; |
const int Loops = 10000 / Partitions; |
961 |
|
|
972 |
printf( "\n===== IEEE test for %s Min=%d Max=%d =====\n", |
printf( "\n===== IEEE test for %s Min=%d Max=%d =====\n", |
973 |
cpu->name, Min, Max ); |
cpu->name, Min, Max ); |
974 |
|
|
975 |
/* FDCT tests // */ |
// FDCT tests // |
976 |
|
|
977 |
init_stats(&Stats); |
init_stats(&Stats); |
978 |
|
|
979 |
/* test each computation channels separately */ |
// test each computation channels separately |
980 |
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; |
981 |
ref_fdct(Blk0); |
ref_fdct(Blk0); |
982 |
emms(); fdct(Blk); emms(); |
emms(); fdct(Blk); emms(); |
987 |
emms(); fdct(Blk); emms(); |
emms(); fdct(Blk); emms(); |
988 |
store_stats(&Stats, Blk, Blk0); |
store_stats(&Stats, Blk, Blk0); |
989 |
|
|
990 |
/* randomly saturated inputs */ |
// randomly saturated inputs |
991 |
for(p=0; p<Partitions; ++p) |
for(p=0; p<Partitions; ++p) |
992 |
{ |
{ |
993 |
for(n=0; n<Loops; ++n) |
for(n=0; n<Loops; ++n) |
1003 |
report_stats(&Stats, 0); |
report_stats(&Stats, 0); |
1004 |
|
|
1005 |
|
|
1006 |
/* IDCT tests */ |
// IDCT tests // |
1007 |
#if 0 |
#if 0 |
1008 |
/* no finished yet */ |
// no finished yet |
1009 |
|
|
1010 |
init_stats(&Stats); |
init_stats(&Stats); |
1011 |
|
|
1012 |
/* test each computation channel separately */ |
// test each computation channel separately |
1013 |
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; |
1014 |
ref_idct(Blk0); |
ref_idct(Blk0); |
1015 |
emms(); idct(Blk); emms(); |
emms(); idct(Blk); emms(); |
1022 |
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); } |
1023 |
store_stats(&Stats, Blk, Blk0); |
store_stats(&Stats, Blk, Blk0); |
1024 |
|
|
1025 |
/* randomly saturated inputs */ |
// randomly saturated inputs |
1026 |
for(p=0; p<Partitions; ++p) |
for(p=0; p<Partitions; ++p) |
1027 |
{ |
{ |
1028 |
for(n=0; n<Loops; ++n) |
for(n=0; n<Loops; ++n) |
1091 |
} |
} |
1092 |
else printf( "Input size: %d\n", buf_size); |
else printf( "Input size: %d\n", buf_size); |
1093 |
|
|
1094 |
buf = malloc(buf_size); /* should be enuf' */ |
buf = malloc(buf_size); // should be enuf' |
1095 |
rgb_out = calloc(4, width*height); /* <-room for _RGB24 */ |
rgb_out = calloc(4, width*height); // <-room for _RGB24 |
1096 |
if (buf==0 || rgb_out==0) { |
if (buf==0 || rgb_out==0) { |
1097 |
printf( "malloc failed!\n" ); |
printf( "malloc failed!\n" ); |
1098 |
goto End; |
goto End; |