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