35 |
|
|
36 |
#include <stdio.h> |
#include <stdio.h> |
37 |
#include <stdlib.h> |
#include <stdlib.h> |
38 |
#ifdef WIN32 |
#include <sys/time.h> // for gettimeofday |
39 |
#include <time.h> /* for clock */ |
#include <string.h> // for memset |
|
#else |
|
|
#include <sys/time.h> /* for gettimeofday */ |
|
|
#endif |
|
|
#include <string.h> /* for memset */ |
|
40 |
#include <assert.h> |
#include <assert.h> |
41 |
|
|
42 |
#include "xvid.h" |
#include "xvid.h" |
43 |
|
|
44 |
/* inner guts */ |
// inner guts |
45 |
#include "dct/idct.h" |
#include "dct/idct.h" |
46 |
#include "dct/fdct.h" |
#include "dct/fdct.h" |
47 |
#include "image/colorspace.h" |
#include "image/colorspace.h" |
56 |
#include "bitstream/cbp.h" |
#include "bitstream/cbp.h" |
57 |
|
|
58 |
#include <math.h> |
#include <math.h> |
59 |
#ifndef M_PI |
const int speed_ref = 100; // on slow machines, decrease this value |
|
# define M_PI 3.14159265359 |
|
|
# define M_PI_2 1.5707963268 |
|
|
#endif |
|
|
const int speed_ref = 100; /* on slow machines, decrease this value */ |
|
60 |
|
|
61 |
/********************************************************************* |
/********************************************************************* |
62 |
* misc |
* misc |
65 |
/* returns time in micro-s*/ |
/* returns time in micro-s*/ |
66 |
double gettime_usec() |
double gettime_usec() |
67 |
{ |
{ |
|
#ifdef WIN32 |
|
|
return clock()*1000; |
|
|
#else |
|
68 |
struct timeval tv; |
struct timeval tv; |
69 |
gettimeofday(&tv, 0); |
gettimeofday(&tv, 0); |
70 |
return tv.tv_sec*1.0e6 + tv.tv_usec; |
return tv.tv_sec*1.0e6 + tv.tv_usec; |
|
#endif |
|
71 |
} |
} |
72 |
|
|
73 |
/* 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 */ |
103 |
, { "3DNOW ", XVID_CPU_3DNOW } |
, { "3DNOW ", XVID_CPU_3DNOW } |
104 |
, { "3DNOWE", XVID_CPU_3DNOWEXT } |
, { "3DNOWE", XVID_CPU_3DNOWEXT } |
105 |
, { "IA64 ", XVID_CPU_IA64 } |
, { "IA64 ", XVID_CPU_IA64 } |
106 |
/*, { "TSC ", XVID_CPU_TSC } */ |
//, { "TSC ", XVID_CPU_TSC } |
107 |
, { 0, 0 } } |
, { 0, 0 } } |
108 |
|
|
109 |
, cpu_short_list[] = |
, cpu_short_list[] = |
110 |
{ { "PLAINC", 0 } |
{ { "PLAINC", 0 } |
111 |
, { "MMX ", XVID_CPU_MMX } |
, { "MMX ", XVID_CPU_MMX } |
112 |
/*, { "MMXEXT", XVID_CPU_MMXEXT | XVID_CPU_MMX } */ |
//, { "MMXEXT", XVID_CPU_MMXEXT | XVID_CPU_MMX } |
113 |
, { "IA64 ", XVID_CPU_IA64 } |
, { "IA64 ", XVID_CPU_IA64 } |
114 |
, { 0, 0 } } |
, { 0, 0 } } |
115 |
|
|
127 |
|
|
128 |
cpu_type = check_cpu_features() & cpu->cpu; |
cpu_type = check_cpu_features() & cpu->cpu; |
129 |
xinit.cpu_flags = cpu_type | XVID_CPU_FORCE; |
xinit.cpu_flags = cpu_type | XVID_CPU_FORCE; |
130 |
/* xinit.cpu_flags = XVID_CPU_MMX | XVID_CPU_FORCE; */ |
// xinit.cpu_flags = XVID_CPU_MMX | XVID_CPU_FORCE; |
131 |
xerr = xvid_init(NULL, 0, &xinit, NULL); |
xerr = xvid_init(NULL, 0, &xinit, NULL); |
132 |
if (cpu->cpu>0 && (cpu_type==0 || xerr!=XVID_ERR_OK)) { |
if (cpu->cpu>0 && (cpu_type==0 || xerr!=XVID_ERR_OK)) { |
133 |
printf( "%s - skipped...\n", cpu->name ); |
printf( "%s - skipped...\n", cpu->name ); |
285 |
const int nb_tests = 2000*speed_ref; |
const int nb_tests = 2000*speed_ref; |
286 |
CPU *cpu; |
CPU *cpu; |
287 |
const uint8_t Src0[16*9] = { |
const uint8_t Src0[16*9] = { |
288 |
/* try to have every possible combinaison of rounding... */ |
// try to have every possible combinaison of rounding... |
289 |
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 |
290 |
, 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 |
291 |
, 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 |
335 |
if (iCrc!=8103) printf( "*** CRC ERROR! ***\n" ); |
if (iCrc!=8103) printf( "*** CRC ERROR! ***\n" ); |
336 |
|
|
337 |
|
|
338 |
/* this is a new function, as of 06.06.2002 */ |
// this is a new function, as of 06.06.2002 |
339 |
#if 0 |
#if 0 |
340 |
TEST_MB2(interpolate8x8_avrg); |
TEST_MB2(interpolate8x8_avrg); |
341 |
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 ); |
457 |
TEST_TRANSFER3(transfer_8to16sub2, Dst16, Src8, Ref1, Ref2); |
TEST_TRANSFER3(transfer_8to16sub2, Dst16, Src8, Ref1, Ref2); |
458 |
printf( "%s - 8to16sub2 %.3f usec crc=%d\n", cpu->name, t, s ); |
printf( "%s - 8to16sub2 %.3f usec crc=%d\n", cpu->name, t, s ); |
459 |
if (s!=20384) printf( "*** CRC ERROR! ***\n" ); |
if (s!=20384) printf( "*** CRC ERROR! ***\n" ); |
460 |
/* for(i=0; i<64; ++i) printf( "[%d]", Dst16[i]); */ |
// for(i=0; i<64; ++i) printf( "[%d]", Dst16[i]); |
461 |
/* printf("\n"); */ |
// printf("\n"); |
462 |
#endif |
#endif |
463 |
printf( " --- \n" ); |
printf( " --- \n" ); |
464 |
} |
} |
511 |
|
|
512 |
printf( "\n ===== test quant =====\n" ); |
printf( "\n ===== test quant =====\n" ); |
513 |
|
|
514 |
/* we deliberately enfringe the norm's specified range [-127,127], */ |
// we deliberately enfringe the norm's specified range [-127,127], |
515 |
/* to test the robustness of the iquant module */ |
// to test the robustness of the iquant module |
516 |
for(i=0; i<64; ++i) { |
for(i=0; i<64; ++i) { |
517 |
Src[i] = 1 + (i-32) * (i&6); |
Src[i] = 1 + (i-32) * (i&6); |
518 |
Dst[i] = 0; |
Dst[i] = 0; |
599 |
printf( "\n ===== test cbp =====\n" ); |
printf( "\n ===== test cbp =====\n" ); |
600 |
|
|
601 |
for(i=0; i<6*64; ++i) { |
for(i=0; i<6*64; ++i) { |
602 |
Src1[i] = (i*i*3/8192)&(i/64)&1; /* 'random' */ |
Src1[i] = (i*i*3/8192)&(i/64)&1; // 'random' |
603 |
Src2[i] = (i<3*64); /* half-full */ |
Src2[i] = (i<3*64); // half-full |
604 |
Src3[i] = ((i+32)>3*64); |
Src3[i] = ((i+32)>3*64); |
605 |
Src4[i] = (i==(3*64+2) || i==(5*64+9)); |
Src4[i] = (i==(3*64+2) || i==(5*64+9)); |
606 |
} |
} |
755 |
} |
} |
756 |
} |
} |
757 |
|
|
758 |
/*//////////////////////////////////////////////////////// */ |
////////////////////////////////////////////////////////// |
759 |
/* Pseudo-random generator specified by IEEE 1180 */ |
/* Pseudo-random generator specified by IEEE 1180 */ |
760 |
|
|
761 |
static long ieee_seed = 1; |
static long ieee_seed = 1; |
842 |
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 }; |
843 |
int Loops = 10000; |
int Loops = 10000; |
844 |
int i, m, n; |
int i, m, n; |
845 |
short Blk0[64]; /* reference */ |
short Blk0[64]; // reference |
846 |
short Blk[64], iBlk[64]; |
short Blk[64], iBlk[64]; |
847 |
short Ref_FDCT[64]; |
short Ref_FDCT[64]; |
848 |
short Ref_IDCT[64]; |
short Ref_IDCT[64]; |
849 |
|
|
850 |
STATS_8x8 FStats; /* forward dct stats */ |
STATS_8x8 FStats; // forward dct stats |
851 |
STATS_8x8 IStats; /* inverse dct stats */ |
STATS_8x8 IStats; // inverse dct stats |
852 |
|
|
853 |
CPU *cpu; |
CPU *cpu; |
854 |
|
|
871 |
for(i=0; i<64; ++i) |
for(i=0; i<64; ++i) |
872 |
Blk0[i] = (short)ieee_rand(Min,Max) * Sign; |
Blk0[i] = (short)ieee_rand(Min,Max) * Sign; |
873 |
|
|
874 |
/* hmm, I'm not quite sure this is exactly */ |
// hmm, I'm not quite sure this is exactly |
875 |
/* the tests described in the norm. check... */ |
// the tests described in the norm. check... |
876 |
|
|
877 |
memcpy(Ref_FDCT, Blk0, 64*sizeof(short)); |
memcpy(Ref_FDCT, Blk0, 64*sizeof(short)); |
878 |
ref_fdct(Ref_FDCT); |
ref_fdct(Ref_FDCT); |
898 |
|
|
899 |
|
|
900 |
printf( "\n -- FDCT report --\n" ); |
printf( "\n -- FDCT report --\n" ); |
901 |
/* print_stats(&FStats); */ |
// print_stats(&FStats); |
902 |
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 |
903 |
|
|
904 |
for(i=0; i<64; i++) Blk[i] = 0; |
for(i=0; i<64; i++) Blk[i] = 0; |
905 |
emms(); fdct(Blk); emms(); |
emms(); fdct(Blk); emms(); |
907 |
printf( "FDCT(0) == 0 ? %s\n", (m!=0) ? "NOPE!" : "yup." ); |
printf( "FDCT(0) == 0 ? %s\n", (m!=0) ? "NOPE!" : "yup." ); |
908 |
|
|
909 |
printf( "\n -- IDCT report --\n" ); |
printf( "\n -- IDCT report --\n" ); |
910 |
/* print_stats(&IStats); */ |
// print_stats(&IStats); |
911 |
report_stats(&IStats, ILimits); |
report_stats(&IStats, ILimits); |
912 |
|
|
913 |
|
|
921 |
|
|
922 |
void test_dct_saturation(int Min, int Max) |
void test_dct_saturation(int Min, int Max) |
923 |
{ |
{ |
924 |
/* test behaviour on input range fringe */ |
// test behaviour on input range fringe |
925 |
|
|
926 |
int i, n, p; |
int i, n, p; |
927 |
CPU *cpu; |
CPU *cpu; |
928 |
/* const short IDCT_MAX = 2047; // 12bits input */ |
// const short IDCT_MAX = 2047; // 12bits input |
929 |
/* const short IDCT_MIN = -2048; */ |
// const short IDCT_MIN = -2048; |
930 |
/* const short IDCT_OUT = 256; // 9bits ouput */ |
// const short IDCT_OUT = 256; // 9bits ouput |
931 |
const int Partitions = 4; |
const int Partitions = 4; |
932 |
const int Loops = 10000 / Partitions; |
const int Loops = 10000 / Partitions; |
933 |
|
|
944 |
printf( "\n===== IEEE test for %s Min=%d Max=%d =====\n", |
printf( "\n===== IEEE test for %s Min=%d Max=%d =====\n", |
945 |
cpu->name, Min, Max ); |
cpu->name, Min, Max ); |
946 |
|
|
947 |
/* FDCT tests // */ |
// FDCT tests // |
948 |
|
|
949 |
init_stats(&Stats); |
init_stats(&Stats); |
950 |
|
|
951 |
/* test each computation channels separately */ |
// test each computation channels separately |
952 |
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; |
953 |
ref_fdct(Blk0); |
ref_fdct(Blk0); |
954 |
emms(); fdct(Blk); emms(); |
emms(); fdct(Blk); emms(); |
959 |
emms(); fdct(Blk); emms(); |
emms(); fdct(Blk); emms(); |
960 |
store_stats(&Stats, Blk, Blk0); |
store_stats(&Stats, Blk, Blk0); |
961 |
|
|
962 |
/* randomly saturated inputs */ |
// randomly saturated inputs |
963 |
for(p=0; p<Partitions; ++p) |
for(p=0; p<Partitions; ++p) |
964 |
{ |
{ |
965 |
for(n=0; n<Loops; ++n) |
for(n=0; n<Loops; ++n) |
975 |
report_stats(&Stats, 0); |
report_stats(&Stats, 0); |
976 |
|
|
977 |
|
|
978 |
/* IDCT tests */ |
// IDCT tests // |
979 |
#if 0 |
#if 0 |
980 |
/* no finished yet */ |
// no finished yet |
981 |
|
|
982 |
init_stats(&Stats); |
init_stats(&Stats); |
983 |
|
|
984 |
/* test each computation channel separately */ |
// test each computation channel separately |
985 |
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; |
986 |
ref_idct(Blk0); |
ref_idct(Blk0); |
987 |
emms(); idct(Blk); emms(); |
emms(); idct(Blk); emms(); |
994 |
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); } |
995 |
store_stats(&Stats, Blk, Blk0); |
store_stats(&Stats, Blk, Blk0); |
996 |
|
|
997 |
/* randomly saturated inputs */ |
// randomly saturated inputs |
998 |
for(p=0; p<Partitions; ++p) |
for(p=0; p<Partitions; ++p) |
999 |
{ |
{ |
1000 |
for(n=0; n<Loops; ++n) |
for(n=0; n<Loops; ++n) |
1063 |
} |
} |
1064 |
else printf( "Input size: %d\n", buf_size); |
else printf( "Input size: %d\n", buf_size); |
1065 |
|
|
1066 |
buf = malloc(buf_size); /* should be enuf' */ |
buf = malloc(buf_size); // should be enuf' |
1067 |
rgb_out = calloc(4, width*height); /* <-room for _RGB24 */ |
rgb_out = calloc(4, width*height); // <-room for _RGB24 |
1068 |
if (buf==0 || rgb_out==0) { |
if (buf==0 || rgb_out==0) { |
1069 |
printf( "malloc failed!\n" ); |
printf( "malloc failed!\n" ); |
1070 |
goto End; |
goto End; |