| 1 |
#include <stdio.h> |
| 2 |
#include <math.h> |
| 3 |
#include <asm/msr.h> |
| 4 |
#include "resample.h" |
| 5 |
|
| 6 |
#define CLK 300.e6 |
| 7 |
#define LOOPS 20000 |
| 8 |
|
| 9 |
|
| 10 |
typedef double ( *ddf ) ( double ); |
| 11 |
|
| 12 |
|
| 13 |
float a1 [256]; |
| 14 |
float a2 [256]; |
| 15 |
|
| 16 |
void init ( void ) |
| 17 |
{ |
| 18 |
int i; |
| 19 |
|
| 20 |
for ( i = 0; i < sizeof(a1)/sizeof(*a1); i++ ) { |
| 21 |
a1 [i] = sin(i)+0.2*sin(1.8*i)+log(2+i); |
| 22 |
a2 [i] = cos(0.1*i); |
| 23 |
} |
| 24 |
} |
| 25 |
|
| 26 |
void test ( unsigned int no, scalar_t f ) |
| 27 |
{ |
| 28 |
unsigned long long t1; |
| 29 |
unsigned long long t2; |
| 30 |
unsigned long long t3; |
| 31 |
unsigned long long t4; |
| 32 |
int l; |
| 33 |
double last = 0; |
| 34 |
double curr = 0; |
| 35 |
|
| 36 |
printf ( "[%3u] %22.14f\t\t", no, (double)f (a1,a2) ); |
| 37 |
fflush ( stdout ); |
| 38 |
|
| 39 |
do { |
| 40 |
rdtscll (t1); |
| 41 |
l = LOOPS; |
| 42 |
do |
| 43 |
; |
| 44 |
while (--l); |
| 45 |
rdtscll (t2); |
| 46 |
rdtscll (t3); |
| 47 |
l = LOOPS; |
| 48 |
do |
| 49 |
f(a1,a2), f(a1,a2), f(a1,a2), f(a1,a2); |
| 50 |
while (--l); |
| 51 |
rdtscll (t4); |
| 52 |
last = curr; |
| 53 |
curr = (t4-t3-t2+t1) / CLK / LOOPS / 4 * 1.e9; |
| 54 |
} while ( fabs(curr-last) > 1.e-4 * (curr+last) ); |
| 55 |
printf ("%8.2f ns\n", (curr+last) / 2 ); |
| 56 |
} |
| 57 |
|
| 58 |
void testn ( scalarn_t f ) |
| 59 |
{ |
| 60 |
unsigned long long t1; |
| 61 |
unsigned long long t2; |
| 62 |
unsigned long long t3; |
| 63 |
unsigned long long t4; |
| 64 |
int l; |
| 65 |
int i; |
| 66 |
double last = 0; |
| 67 |
double curr = 0; |
| 68 |
|
| 69 |
for ( i = 1; i <= 64; i += i<6 ? 1 : i<8 ? 2 : i ) { |
| 70 |
printf ( "[%3u] %22.14f\t\t", 4u*i, (double)f (a1,a2,i) ); |
| 71 |
fflush ( stdout ); |
| 72 |
|
| 73 |
do { |
| 74 |
rdtscll (t1); |
| 75 |
l = LOOPS; |
| 76 |
do |
| 77 |
; |
| 78 |
while (--l); |
| 79 |
rdtscll (t2); |
| 80 |
rdtscll (t3); |
| 81 |
l = LOOPS; |
| 82 |
do |
| 83 |
f(a1,a2,i), f(a1,a2,i), f(a1,a2,i), f(a1,a2,i); |
| 84 |
while (--l); |
| 85 |
rdtscll (t4); |
| 86 |
last = curr; |
| 87 |
curr = (t4-t3-t2+t1) / CLK / LOOPS / 4 * 1.e9; |
| 88 |
} while ( fabs(curr-last) > 1.e-4 * (curr+last) ); |
| 89 |
printf ("%8.2f ns\n", (curr+last) / 2 ); |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
void test2 ( const char* name, ddf f ) |
| 94 |
{ |
| 95 |
int i; |
| 96 |
double x; |
| 97 |
|
| 98 |
printf ( "\n%%%% %s\n\n", name ); |
| 99 |
|
| 100 |
for ( i = -1000; i <= 1000; i++ ) { |
| 101 |
x = 1.e-3 * i; |
| 102 |
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 ); |
| 103 |
} |
| 104 |
printf ( "%%%%\n" ); |
| 105 |
fflush ( stdout ); |
| 106 |
} |
| 107 |
|
| 108 |
|
| 109 |
int main ( int argc, char** argv ) |
| 110 |
{ |
| 111 |
|
| 112 |
#if 0 |
| 113 |
|
| 114 |
test2 ( "Hann", hanning ); |
| 115 |
test2 ( "Hamm", hamming ); |
| 116 |
test2 ( "BM", blackman ); |
| 117 |
test2 ( "BM1",blackman1 ); |
| 118 |
test2 ( "BM2",blackman2 ); |
| 119 |
test2 ( "BMH N",blackmanharris_nuttall ); |
| 120 |
test2 ( "MNH Min",blackmanharris_min4 ); |
| 121 |
|
| 122 |
#else |
| 123 |
|
| 124 |
init (); |
| 125 |
|
| 126 |
test ( 4, scalar04_float32 ); |
| 127 |
test ( 4, scalar04_float32_i387 ); |
| 128 |
test ( 4, scalar04_float32_3DNow ); |
| 129 |
test ( 4, scalar04_float32_SIMD ); |
| 130 |
|
| 131 |
test ( 8, scalar08_float32 ); |
| 132 |
test ( 8, scalar08_float32_i387 ); |
| 133 |
test ( 8, scalar08_float32_3DNow ); |
| 134 |
test ( 8, scalar08_float32_SIMD ); |
| 135 |
|
| 136 |
test ( 12, scalar12_float32 ); |
| 137 |
test ( 12, scalar12_float32_i387 ); |
| 138 |
test ( 12, scalar12_float32_3DNow ); |
| 139 |
test ( 12, scalar12_float32_SIMD ); |
| 140 |
|
| 141 |
test ( 16, scalar16_float32 ); |
| 142 |
test ( 16, scalar16_float32_i387 ); |
| 143 |
test ( 16, scalar16_float32_3DNow ); |
| 144 |
test ( 16, scalar16_float32_SIMD ); |
| 145 |
|
| 146 |
test ( 20, scalar20_float32 ); |
| 147 |
test ( 20, scalar20_float32_i387 ); |
| 148 |
test ( 20, scalar20_float32_3DNow ); |
| 149 |
test ( 20, scalar20_float32_SIMD ); |
| 150 |
|
| 151 |
test ( 24, scalar24_float32 ); |
| 152 |
test ( 24, scalar24_float32_i387 ); |
| 153 |
test ( 24, scalar24_float32_3DNow ); |
| 154 |
test ( 24, scalar24_float32_SIMD ); |
| 155 |
|
| 156 |
testn( scalar4n_float32 ); |
| 157 |
testn( scalar4n_float32_i387 ); |
| 158 |
testn( scalar4n_float32_3DNow ); |
| 159 |
testn( scalar4n_float32_SIMD ); |
| 160 |
|
| 161 |
#endif |
| 162 |
|
| 163 |
return 0; |
| 164 |
} |
| 165 |
|
| 166 |
/* end of scalartest.c */ |