scalartest.c 3.7 KB

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