1159b3361Sopenharmony_ci#include <stdio.h> 2159b3361Sopenharmony_ci#include <math.h> 3159b3361Sopenharmony_ci#include <asm/msr.h> 4159b3361Sopenharmony_ci#include "resample.h" 5159b3361Sopenharmony_ci 6159b3361Sopenharmony_ci#define CLK 300.e6 7159b3361Sopenharmony_ci#define LOOPS 20000 8159b3361Sopenharmony_ci 9159b3361Sopenharmony_ci 10159b3361Sopenharmony_citypedef double ( *ddf ) ( double ); 11159b3361Sopenharmony_ci 12159b3361Sopenharmony_ci 13159b3361Sopenharmony_cifloat a1 [256]; 14159b3361Sopenharmony_cifloat a2 [256]; 15159b3361Sopenharmony_ci 16159b3361Sopenharmony_civoid init ( void ) 17159b3361Sopenharmony_ci{ 18159b3361Sopenharmony_ci int i; 19159b3361Sopenharmony_ci 20159b3361Sopenharmony_ci for ( i = 0; i < sizeof(a1)/sizeof(*a1); i++ ) { 21159b3361Sopenharmony_ci a1 [i] = sin(i)+0.2*sin(1.8*i)+log(2+i); 22159b3361Sopenharmony_ci a2 [i] = cos(0.1*i); 23159b3361Sopenharmony_ci } 24159b3361Sopenharmony_ci} 25159b3361Sopenharmony_ci 26159b3361Sopenharmony_civoid test ( unsigned int no, scalar_t f ) 27159b3361Sopenharmony_ci{ 28159b3361Sopenharmony_ci unsigned long long t1; 29159b3361Sopenharmony_ci unsigned long long t2; 30159b3361Sopenharmony_ci unsigned long long t3; 31159b3361Sopenharmony_ci unsigned long long t4; 32159b3361Sopenharmony_ci int l; 33159b3361Sopenharmony_ci double last = 0; 34159b3361Sopenharmony_ci double curr = 0; 35159b3361Sopenharmony_ci 36159b3361Sopenharmony_ci printf ( "[%3u] %22.14f\t\t", no, (double)f (a1,a2) ); 37159b3361Sopenharmony_ci fflush ( stdout ); 38159b3361Sopenharmony_ci 39159b3361Sopenharmony_ci do { 40159b3361Sopenharmony_ci rdtscll (t1); 41159b3361Sopenharmony_ci l = LOOPS; 42159b3361Sopenharmony_ci do 43159b3361Sopenharmony_ci ; 44159b3361Sopenharmony_ci while (--l); 45159b3361Sopenharmony_ci rdtscll (t2); 46159b3361Sopenharmony_ci rdtscll (t3); 47159b3361Sopenharmony_ci l = LOOPS; 48159b3361Sopenharmony_ci do 49159b3361Sopenharmony_ci f(a1,a2), f(a1,a2), f(a1,a2), f(a1,a2); 50159b3361Sopenharmony_ci while (--l); 51159b3361Sopenharmony_ci rdtscll (t4); 52159b3361Sopenharmony_ci last = curr; 53159b3361Sopenharmony_ci curr = (t4-t3-t2+t1) / CLK / LOOPS / 4 * 1.e9; 54159b3361Sopenharmony_ci } while ( fabs(curr-last) > 1.e-4 * (curr+last) ); 55159b3361Sopenharmony_ci printf ("%8.2f ns\n", (curr+last) / 2 ); 56159b3361Sopenharmony_ci} 57159b3361Sopenharmony_ci 58159b3361Sopenharmony_civoid testn ( scalarn_t f ) 59159b3361Sopenharmony_ci{ 60159b3361Sopenharmony_ci unsigned long long t1; 61159b3361Sopenharmony_ci unsigned long long t2; 62159b3361Sopenharmony_ci unsigned long long t3; 63159b3361Sopenharmony_ci unsigned long long t4; 64159b3361Sopenharmony_ci int l; 65159b3361Sopenharmony_ci int i; 66159b3361Sopenharmony_ci double last = 0; 67159b3361Sopenharmony_ci double curr = 0; 68159b3361Sopenharmony_ci 69159b3361Sopenharmony_ci for ( i = 1; i <= 64; i += i<6 ? 1 : i<8 ? 2 : i ) { 70159b3361Sopenharmony_ci printf ( "[%3u] %22.14f\t\t", 4u*i, (double)f (a1,a2,i) ); 71159b3361Sopenharmony_ci fflush ( stdout ); 72159b3361Sopenharmony_ci 73159b3361Sopenharmony_ci do { 74159b3361Sopenharmony_ci rdtscll (t1); 75159b3361Sopenharmony_ci l = LOOPS; 76159b3361Sopenharmony_ci do 77159b3361Sopenharmony_ci ; 78159b3361Sopenharmony_ci while (--l); 79159b3361Sopenharmony_ci rdtscll (t2); 80159b3361Sopenharmony_ci rdtscll (t3); 81159b3361Sopenharmony_ci l = LOOPS; 82159b3361Sopenharmony_ci do 83159b3361Sopenharmony_ci f(a1,a2,i), f(a1,a2,i), f(a1,a2,i), f(a1,a2,i); 84159b3361Sopenharmony_ci while (--l); 85159b3361Sopenharmony_ci rdtscll (t4); 86159b3361Sopenharmony_ci last = curr; 87159b3361Sopenharmony_ci curr = (t4-t3-t2+t1) / CLK / LOOPS / 4 * 1.e9; 88159b3361Sopenharmony_ci } while ( fabs(curr-last) > 1.e-4 * (curr+last) ); 89159b3361Sopenharmony_ci printf ("%8.2f ns\n", (curr+last) / 2 ); 90159b3361Sopenharmony_ci } 91159b3361Sopenharmony_ci} 92159b3361Sopenharmony_ci 93159b3361Sopenharmony_civoid test2 ( const char* name, ddf f ) 94159b3361Sopenharmony_ci{ 95159b3361Sopenharmony_ci int i; 96159b3361Sopenharmony_ci double x; 97159b3361Sopenharmony_ci 98159b3361Sopenharmony_ci printf ( "\n%%%% %s\n\n", name ); 99159b3361Sopenharmony_ci 100159b3361Sopenharmony_ci for ( i = -1000; i <= 1000; i++ ) { 101159b3361Sopenharmony_ci x = 1.e-3 * i; 102159b3361Sopenharmony_ci printf ( "%5d\t%12.8f\t%12.8f\t%12.8f\n", i, f(x), (f(x+5.e-5) - f(x-5.e-5))*1.e+4, (f(x+1.e-4) + f(x-1.e-4) - 2*f(x))*5.e+7 ); 103159b3361Sopenharmony_ci } 104159b3361Sopenharmony_ci printf ( "%%%%\n" ); 105159b3361Sopenharmony_ci fflush ( stdout ); 106159b3361Sopenharmony_ci} 107159b3361Sopenharmony_ci 108159b3361Sopenharmony_ci 109159b3361Sopenharmony_ciint main ( int argc, char** argv ) 110159b3361Sopenharmony_ci{ 111159b3361Sopenharmony_ci 112159b3361Sopenharmony_ci#if 0 113159b3361Sopenharmony_ci 114159b3361Sopenharmony_ci test2 ( "Hann", hanning ); 115159b3361Sopenharmony_ci test2 ( "Hamm", hamming ); 116159b3361Sopenharmony_ci test2 ( "BM", blackman ); 117159b3361Sopenharmony_ci test2 ( "BM1",blackman1 ); 118159b3361Sopenharmony_ci test2 ( "BM2",blackman2 ); 119159b3361Sopenharmony_ci test2 ( "BMH N",blackmanharris_nuttall ); 120159b3361Sopenharmony_ci test2 ( "MNH Min",blackmanharris_min4 ); 121159b3361Sopenharmony_ci 122159b3361Sopenharmony_ci#else 123159b3361Sopenharmony_ci 124159b3361Sopenharmony_ci init (); 125159b3361Sopenharmony_ci 126159b3361Sopenharmony_ci test ( 4, scalar04_float32 ); 127159b3361Sopenharmony_ci test ( 4, scalar04_float32_i387 ); 128159b3361Sopenharmony_ci test ( 4, scalar04_float32_3DNow ); 129159b3361Sopenharmony_ci test ( 4, scalar04_float32_SIMD ); 130159b3361Sopenharmony_ci 131159b3361Sopenharmony_ci test ( 8, scalar08_float32 ); 132159b3361Sopenharmony_ci test ( 8, scalar08_float32_i387 ); 133159b3361Sopenharmony_ci test ( 8, scalar08_float32_3DNow ); 134159b3361Sopenharmony_ci test ( 8, scalar08_float32_SIMD ); 135159b3361Sopenharmony_ci 136159b3361Sopenharmony_ci test ( 12, scalar12_float32 ); 137159b3361Sopenharmony_ci test ( 12, scalar12_float32_i387 ); 138159b3361Sopenharmony_ci test ( 12, scalar12_float32_3DNow ); 139159b3361Sopenharmony_ci test ( 12, scalar12_float32_SIMD ); 140159b3361Sopenharmony_ci 141159b3361Sopenharmony_ci test ( 16, scalar16_float32 ); 142159b3361Sopenharmony_ci test ( 16, scalar16_float32_i387 ); 143159b3361Sopenharmony_ci test ( 16, scalar16_float32_3DNow ); 144159b3361Sopenharmony_ci test ( 16, scalar16_float32_SIMD ); 145159b3361Sopenharmony_ci 146159b3361Sopenharmony_ci test ( 20, scalar20_float32 ); 147159b3361Sopenharmony_ci test ( 20, scalar20_float32_i387 ); 148159b3361Sopenharmony_ci test ( 20, scalar20_float32_3DNow ); 149159b3361Sopenharmony_ci test ( 20, scalar20_float32_SIMD ); 150159b3361Sopenharmony_ci 151159b3361Sopenharmony_ci test ( 24, scalar24_float32 ); 152159b3361Sopenharmony_ci test ( 24, scalar24_float32_i387 ); 153159b3361Sopenharmony_ci test ( 24, scalar24_float32_3DNow ); 154159b3361Sopenharmony_ci test ( 24, scalar24_float32_SIMD ); 155159b3361Sopenharmony_ci 156159b3361Sopenharmony_ci testn( scalar4n_float32 ); 157159b3361Sopenharmony_ci testn( scalar4n_float32_i387 ); 158159b3361Sopenharmony_ci testn( scalar4n_float32_3DNow ); 159159b3361Sopenharmony_ci testn( scalar4n_float32_SIMD ); 160159b3361Sopenharmony_ci 161159b3361Sopenharmony_ci#endif 162159b3361Sopenharmony_ci 163159b3361Sopenharmony_ci return 0; 164159b3361Sopenharmony_ci} 165159b3361Sopenharmony_ci 166159b3361Sopenharmony_ci/* end of scalartest.c */ 167