35 |
|
|
36 |
#include <stdio.h> |
#include <stdio.h> |
37 |
#include <stdlib.h> |
#include <stdlib.h> |
38 |
#ifdef WIN32 |
#include <string.h> // for memset |
39 |
#include <time.h> /* for clock */ |
#include <assert.h> |
40 |
|
|
41 |
|
#ifndef WIN32 |
42 |
|
#include <sys/time.h> // for gettimeofday |
43 |
#else |
#else |
44 |
#include <sys/time.h> /* for gettimeofday */ |
#include <time.h> |
45 |
#endif |
#endif |
46 |
#include <string.h> /* for memset */ |
|
|
#include <assert.h> |
|
47 |
|
|
48 |
#include "xvid.h" |
#include "xvid.h" |
49 |
|
|
50 |
/* inner guts */ |
// inner guts |
51 |
#include "dct/idct.h" |
#include "dct/idct.h" |
52 |
#include "dct/fdct.h" |
#include "dct/fdct.h" |
53 |
#include "image/colorspace.h" |
#include "image/colorspace.h" |
62 |
#include "bitstream/cbp.h" |
#include "bitstream/cbp.h" |
63 |
|
|
64 |
#include <math.h> |
#include <math.h> |
65 |
|
|
66 |
#ifndef M_PI |
#ifndef M_PI |
67 |
# define M_PI 3.14159265359 |
#define M_PI 3.14159265358979323846 |
|
# define M_PI_2 1.5707963268 |
|
68 |
#endif |
#endif |
69 |
const int speed_ref = 100; /* on slow machines, decrease this value */ |
|
70 |
|
const int speed_ref = 100; // on slow machines, decrease this value |
71 |
|
|
72 |
/********************************************************************* |
/********************************************************************* |
73 |
* misc |
* misc |
76 |
/* returns time in micro-s*/ |
/* returns time in micro-s*/ |
77 |
double gettime_usec() |
double gettime_usec() |
78 |
{ |
{ |
79 |
#ifdef WIN32 |
#ifndef WIN32 |
|
return clock()*1000; |
|
|
#else |
|
80 |
struct timeval tv; |
struct timeval tv; |
81 |
gettimeofday(&tv, 0); |
gettimeofday(&tv, 0); |
82 |
return tv.tv_sec*1.0e6 + tv.tv_usec; |
return tv.tv_sec*1.0e6 + tv.tv_usec; |
83 |
|
#else |
84 |
|
clock_t clk; |
85 |
|
clk = clock(); |
86 |
|
return clk * 1000000 / CLOCKS_PER_SEC; |
87 |
#endif |
#endif |
88 |
} |
} |
89 |
|
|
120 |
, { "3DNOW ", XVID_CPU_3DNOW } |
, { "3DNOW ", XVID_CPU_3DNOW } |
121 |
, { "3DNOWE", XVID_CPU_3DNOWEXT } |
, { "3DNOWE", XVID_CPU_3DNOWEXT } |
122 |
, { "IA64 ", XVID_CPU_IA64 } |
, { "IA64 ", XVID_CPU_IA64 } |
123 |
/*, { "TSC ", XVID_CPU_TSC } */ |
//, { "TSC ", XVID_CPU_TSC } |
124 |
, { 0, 0 } } |
, { 0, 0 } } |
125 |
|
|
126 |
, cpu_short_list[] = |
, cpu_short_list[] = |
127 |
{ { "PLAINC", 0 } |
{ { "PLAINC", 0 } |
128 |
, { "MMX ", XVID_CPU_MMX } |
, { "MMX ", XVID_CPU_MMX } |
129 |
/*, { "MMXEXT", XVID_CPU_MMXEXT | XVID_CPU_MMX } */ |
//, { "MMXEXT", XVID_CPU_MMXEXT | XVID_CPU_MMX } |
130 |
, { "IA64 ", XVID_CPU_IA64 } |
, { "IA64 ", XVID_CPU_IA64 } |
131 |
, { 0, 0 } } |
, { 0, 0 } } |
132 |
|
|
144 |
|
|
145 |
cpu_type = check_cpu_features() & cpu->cpu; |
cpu_type = check_cpu_features() & cpu->cpu; |
146 |
xinit.cpu_flags = cpu_type | XVID_CPU_FORCE; |
xinit.cpu_flags = cpu_type | XVID_CPU_FORCE; |
147 |
/* xinit.cpu_flags = XVID_CPU_MMX | XVID_CPU_FORCE; */ |
// xinit.cpu_flags = XVID_CPU_MMX | XVID_CPU_FORCE; |
148 |
xerr = xvid_init(NULL, 0, &xinit, NULL); |
xerr = xvid_init(NULL, 0, &xinit, NULL); |
149 |
if (cpu->cpu>0 && (cpu_type==0 || xerr!=XVID_ERR_OK)) { |
if (cpu->cpu>0 && (cpu_type==0 || xerr!=XVID_ERR_OK)) { |
150 |
printf( "%s - skipped...\n", cpu->name ); |
printf( "%s - skipped...\n", cpu->name ); |
302 |
const int nb_tests = 2000*speed_ref; |
const int nb_tests = 2000*speed_ref; |
303 |
CPU *cpu; |
CPU *cpu; |
304 |
const uint8_t Src0[16*9] = { |
const uint8_t Src0[16*9] = { |
305 |
/* try to have every possible combinaison of rounding... */ |
// try to have every possible combinaison of rounding... |
306 |
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 |
307 |
, 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 |
308 |
, 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 |
352 |
if (iCrc!=8103) printf( "*** CRC ERROR! ***\n" ); |
if (iCrc!=8103) printf( "*** CRC ERROR! ***\n" ); |
353 |
|
|
354 |
|
|
355 |
/* this is a new function, as of 06.06.2002 */ |
// this is a new function, as of 06.06.2002 |
356 |
#if 0 |
#if 0 |
357 |
TEST_MB2(interpolate8x8_avrg); |
TEST_MB2(interpolate8x8_avrg); |
358 |
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 ); |
474 |
TEST_TRANSFER3(transfer_8to16sub2, Dst16, Src8, Ref1, Ref2); |
TEST_TRANSFER3(transfer_8to16sub2, Dst16, Src8, Ref1, Ref2); |
475 |
printf( "%s - 8to16sub2 %.3f usec crc=%d\n", cpu->name, t, s ); |
printf( "%s - 8to16sub2 %.3f usec crc=%d\n", cpu->name, t, s ); |
476 |
if (s!=20384) printf( "*** CRC ERROR! ***\n" ); |
if (s!=20384) printf( "*** CRC ERROR! ***\n" ); |
477 |
/* for(i=0; i<64; ++i) printf( "[%d]", Dst16[i]); */ |
// for(i=0; i<64; ++i) printf( "[%d]", Dst16[i]); |
478 |
/* printf("\n"); */ |
// printf("\n"); |
479 |
#endif |
#endif |
480 |
printf( " --- \n" ); |
printf( " --- \n" ); |
481 |
} |
} |
528 |
|
|
529 |
printf( "\n ===== test quant =====\n" ); |
printf( "\n ===== test quant =====\n" ); |
530 |
|
|
531 |
/* we deliberately enfringe the norm's specified range [-127,127], */ |
// we deliberately enfringe the norm's specified range [-127,127], |
532 |
/* to test the robustness of the iquant module */ |
// to test the robustness of the iquant module |
533 |
for(i=0; i<64; ++i) { |
for(i=0; i<64; ++i) { |
534 |
Src[i] = 1 + (i-32) * (i&6); |
Src[i] = 1 + (i-32) * (i&6); |
535 |
Dst[i] = 0; |
Dst[i] = 0; |
616 |
printf( "\n ===== test cbp =====\n" ); |
printf( "\n ===== test cbp =====\n" ); |
617 |
|
|
618 |
for(i=0; i<6*64; ++i) { |
for(i=0; i<6*64; ++i) { |
619 |
Src1[i] = (i*i*3/8192)&(i/64)&1; /* 'random' */ |
Src1[i] = (i*i*3/8192)&(i/64)&1; // 'random' |
620 |
Src2[i] = (i<3*64); /* half-full */ |
Src2[i] = (i<3*64); // half-full |
621 |
Src3[i] = ((i+32)>3*64); |
Src3[i] = ((i+32)>3*64); |
622 |
Src4[i] = (i==(3*64+2) || i==(5*64+9)); |
Src4[i] = (i==(3*64+2) || i==(5*64+9)); |
623 |
} |
} |
772 |
} |
} |
773 |
} |
} |
774 |
|
|
775 |
/*//////////////////////////////////////////////////////// */ |
////////////////////////////////////////////////////////// |
776 |
/* Pseudo-random generator specified by IEEE 1180 */ |
/* Pseudo-random generator specified by IEEE 1180 */ |
777 |
|
|
778 |
static long ieee_seed = 1; |
static long ieee_seed = 1; |
859 |
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 }; |
860 |
int Loops = 10000; |
int Loops = 10000; |
861 |
int i, m, n; |
int i, m, n; |
862 |
short Blk0[64]; /* reference */ |
short Blk0[64]; // reference |
863 |
short Blk[64], iBlk[64]; |
short Blk[64], iBlk[64]; |
864 |
short Ref_FDCT[64]; |
short Ref_FDCT[64]; |
865 |
short Ref_IDCT[64]; |
short Ref_IDCT[64]; |
866 |
|
|
867 |
STATS_8x8 FStats; /* forward dct stats */ |
STATS_8x8 FStats; // forward dct stats |
868 |
STATS_8x8 IStats; /* inverse dct stats */ |
STATS_8x8 IStats; // inverse dct stats |
869 |
|
|
870 |
CPU *cpu; |
CPU *cpu; |
871 |
|
|
888 |
for(i=0; i<64; ++i) |
for(i=0; i<64; ++i) |
889 |
Blk0[i] = (short)ieee_rand(Min,Max) * Sign; |
Blk0[i] = (short)ieee_rand(Min,Max) * Sign; |
890 |
|
|
891 |
/* hmm, I'm not quite sure this is exactly */ |
// hmm, I'm not quite sure this is exactly |
892 |
/* the tests described in the norm. check... */ |
// the tests described in the norm. check... |
893 |
|
|
894 |
memcpy(Ref_FDCT, Blk0, 64*sizeof(short)); |
memcpy(Ref_FDCT, Blk0, 64*sizeof(short)); |
895 |
ref_fdct(Ref_FDCT); |
ref_fdct(Ref_FDCT); |
915 |
|
|
916 |
|
|
917 |
printf( "\n -- FDCT report --\n" ); |
printf( "\n -- FDCT report --\n" ); |
918 |
/* print_stats(&FStats); */ |
// print_stats(&FStats); |
919 |
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 |
920 |
|
|
921 |
for(i=0; i<64; i++) Blk[i] = 0; |
for(i=0; i<64; i++) Blk[i] = 0; |
922 |
emms(); fdct(Blk); emms(); |
emms(); fdct(Blk); emms(); |
924 |
printf( "FDCT(0) == 0 ? %s\n", (m!=0) ? "NOPE!" : "yup." ); |
printf( "FDCT(0) == 0 ? %s\n", (m!=0) ? "NOPE!" : "yup." ); |
925 |
|
|
926 |
printf( "\n -- IDCT report --\n" ); |
printf( "\n -- IDCT report --\n" ); |
927 |
/* print_stats(&IStats); */ |
// print_stats(&IStats); |
928 |
report_stats(&IStats, ILimits); |
report_stats(&IStats, ILimits); |
929 |
|
|
930 |
|
|
938 |
|
|
939 |
void test_dct_saturation(int Min, int Max) |
void test_dct_saturation(int Min, int Max) |
940 |
{ |
{ |
941 |
/* test behaviour on input range fringe */ |
// test behaviour on input range fringe |
942 |
|
|
943 |
int i, n, p; |
int i, n, p; |
944 |
CPU *cpu; |
CPU *cpu; |
945 |
/* const short IDCT_MAX = 2047; // 12bits input */ |
// const short IDCT_MAX = 2047; // 12bits input |
946 |
/* const short IDCT_MIN = -2048; */ |
// const short IDCT_MIN = -2048; |
947 |
/* const short IDCT_OUT = 256; // 9bits ouput */ |
// const short IDCT_OUT = 256; // 9bits ouput |
948 |
const int Partitions = 4; |
const int Partitions = 4; |
949 |
const int Loops = 10000 / Partitions; |
const int Loops = 10000 / Partitions; |
950 |
|
|
961 |
printf( "\n===== IEEE test for %s Min=%d Max=%d =====\n", |
printf( "\n===== IEEE test for %s Min=%d Max=%d =====\n", |
962 |
cpu->name, Min, Max ); |
cpu->name, Min, Max ); |
963 |
|
|
964 |
/* FDCT tests // */ |
// FDCT tests // |
965 |
|
|
966 |
init_stats(&Stats); |
init_stats(&Stats); |
967 |
|
|
968 |
/* test each computation channels separately */ |
// test each computation channels separately |
969 |
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; |
970 |
ref_fdct(Blk0); |
ref_fdct(Blk0); |
971 |
emms(); fdct(Blk); emms(); |
emms(); fdct(Blk); emms(); |
976 |
emms(); fdct(Blk); emms(); |
emms(); fdct(Blk); emms(); |
977 |
store_stats(&Stats, Blk, Blk0); |
store_stats(&Stats, Blk, Blk0); |
978 |
|
|
979 |
/* randomly saturated inputs */ |
// randomly saturated inputs |
980 |
for(p=0; p<Partitions; ++p) |
for(p=0; p<Partitions; ++p) |
981 |
{ |
{ |
982 |
for(n=0; n<Loops; ++n) |
for(n=0; n<Loops; ++n) |
992 |
report_stats(&Stats, 0); |
report_stats(&Stats, 0); |
993 |
|
|
994 |
|
|
995 |
/* IDCT tests */ |
// IDCT tests // |
996 |
#if 0 |
#if 0 |
997 |
/* no finished yet */ |
// no finished yet |
998 |
|
|
999 |
init_stats(&Stats); |
init_stats(&Stats); |
1000 |
|
|
1001 |
/* test each computation channel separately */ |
// test each computation channel separately |
1002 |
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; |
1003 |
ref_idct(Blk0); |
ref_idct(Blk0); |
1004 |
emms(); idct(Blk); emms(); |
emms(); idct(Blk); emms(); |
1011 |
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); } |
1012 |
store_stats(&Stats, Blk, Blk0); |
store_stats(&Stats, Blk, Blk0); |
1013 |
|
|
1014 |
/* randomly saturated inputs */ |
// randomly saturated inputs |
1015 |
for(p=0; p<Partitions; ++p) |
for(p=0; p<Partitions; ++p) |
1016 |
{ |
{ |
1017 |
for(n=0; n<Loops; ++n) |
for(n=0; n<Loops; ++n) |
1080 |
} |
} |
1081 |
else printf( "Input size: %d\n", buf_size); |
else printf( "Input size: %d\n", buf_size); |
1082 |
|
|
1083 |
buf = malloc(buf_size); /* should be enuf' */ |
buf = malloc(buf_size); // should be enuf' |
1084 |
rgb_out = calloc(4, width*height); /* <-room for _RGB24 */ |
rgb_out = calloc(4, width*height); // <-room for _RGB24 |
1085 |
if (buf==0 || rgb_out==0) { |
if (buf==0 || rgb_out==0) { |
1086 |
printf( "malloc failed!\n" ); |
printf( "malloc failed!\n" ); |
1087 |
goto End; |
goto End; |