1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <memory.h> 4 #include <time.h> 5 #include "config.h" 6 #ifdef HAVE_GETOPT_H 7 #include <getopt.h> 8 #endif 9 #include "fec.h" 10 11 #if HAVE_GETOPT_LONG 12 struct option Options[] = { 13 {"frame-length",1,NULL,'l'}, 14 {"frame-count",1,NULL,'n'}, 15 {"verbose",0,NULL,'v'}, 16 {"force-altivec",0,NULL,'a'}, 17 {"force-port",0,NULL,'p'}, 18 {"force-mmx",0,NULL,'m'}, 19 {"force-sse",0,NULL,'s'}, 20 {"force-sse2",0,NULL,'t'}, 21 {NULL}, 22 }; 23 #endif 24 25 int Verbose = 0; 26 27 int main(int argc,char *argv[]){ 28 signed short *buf; 29 int i,d,trial,trials=10000; 30 int bufsize = 2048; 31 long long port_sum,simd_sum; 32 time_t t; 33 int timetrials=0; 34 35 find_cpu_mode(); 36 time(&t); 37 srandom(t); 38 39 #if HAVE_GETOPT_LONG 40 while((d = getopt_long(argc,argv,"vapmstl:n:T",Options,NULL)) != EOF){ 41 #else 42 while((d = getopt(argc,argv,"vapmstl:n:T")) != EOF){ 43 #endif 44 switch(d){ 45 case 'a': 46 Cpu_mode = ALTIVEC; 47 break; 48 case 'p': 49 Cpu_mode = PORT; 50 break; 51 case 'm': 52 Cpu_mode = MMX; 53 break; 54 case 's': 55 Cpu_mode = SSE; 56 break; 57 case 't': 58 Cpu_mode = SSE2; 59 break; 60 case 'l': 61 bufsize = atoi(optarg); 62 break; 63 case 'n': 64 trials = atoi(optarg); 65 break; 66 case 'v': 67 Verbose++; 68 break; 69 case 'T': 70 timetrials++; 71 break; 72 } 73 } 74 75 buf = (signed short *)calloc(bufsize,sizeof(signed short)); 76 if(timetrials){ 77 for(trial=0;trial<trials;trial++){ 78 (void)sumsq(buf,bufsize); 79 } 80 } else { 81 for(trial=0;trial<trials;trial++){ 82 int length,offset; 83 84 offset = random() & 7; 85 length = (random() % bufsize) - offset; 86 if(length <= 0) 87 continue; 88 for(i=0;i<bufsize;i++) 89 buf[i] = random(); 90 91 port_sum = sumsq_port(buf+offset,length); 92 simd_sum = sumsq(buf+offset,length); 93 if(port_sum != simd_sum){ 94 printf("offset %d len %d port_sum = %lld simd_sum = %lld ",offset,length,port_sum,simd_sum); 95 96 printf("ERROR! diff = %lld\n",simd_sum-port_sum); 97 } 98 } 99 } 100 exit(0); 101 } 102