You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

160 lines
3.8KB

  1. /*
  2. * MMX optimized DSP utils
  3. * Copyright (c) 2000, 2001, 2002 Fabrice Bellard.
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #define TESTCPU_MAIN
  20. #include "dsputil.h"
  21. //#include "../libavcodec/dsputil.c"
  22. #include "../libavcodec/i386/cputest.c"
  23. #include "../libavcodec/i386/dsputil_mmx.c"
  24. #undef TESTCPU_MAIN
  25. #define PAD 0x10000
  26. /*
  27. * for testing speed of various routine - should be probably extended
  28. * for a general purpose regression test later
  29. *
  30. * currently only for i386 - FIXME
  31. */
  32. #define PIX_FUNC_C(a) \
  33. { #a "_c", a ## _c, 0 }, \
  34. { #a "_mmx", a ## _mmx, MM_MMX }, \
  35. { #a "_mmx2", a ## _mmx2, MM_MMXEXT | PAD }
  36. #define PIX_FUNC(a) \
  37. { #a "_mmx", a ## _mmx, MM_MMX }, \
  38. { #a "_3dnow", a ## _3dnow, MM_3DNOW }, \
  39. { #a "_mmx2", a ## _mmx2, MM_MMXEXT | PAD }
  40. #define PIX_FUNC_MMX(a) \
  41. { #a "_mmx", a ## _mmx, MM_MMX | PAD }
  42. /*
  43. PIX_FUNC_C(pix_abs16x16),
  44. PIX_FUNC_C(pix_abs16x16_x2),
  45. PIX_FUNC_C(pix_abs16x16_y2),
  46. PIX_FUNC_C(pix_abs16x16_xy2),
  47. PIX_FUNC_C(pix_abs8x8),
  48. PIX_FUNC_C(pix_abs8x8_x2),
  49. PIX_FUNC_C(pix_abs8x8_y2),
  50. PIX_FUNC_C(pix_abs8x8_xy2),
  51. */
  52. static const struct pix_func {
  53. char* name;
  54. op_pixels_func func;
  55. int mm_flags;
  56. } pix_func[] = {
  57. PIX_FUNC_MMX(put_pixels),
  58. #if 1
  59. PIX_FUNC(put_pixels_x2),
  60. PIX_FUNC(put_pixels_y2),
  61. PIX_FUNC_MMX(put_pixels_xy2),
  62. PIX_FUNC(put_no_rnd_pixels_x2),
  63. PIX_FUNC(put_no_rnd_pixels_y2),
  64. PIX_FUNC_MMX(put_no_rnd_pixels_xy2),
  65. PIX_FUNC(avg_pixels),
  66. PIX_FUNC(avg_pixels_x2),
  67. PIX_FUNC(avg_pixels_y2),
  68. PIX_FUNC(avg_pixels_xy2),
  69. #endif
  70. { 0, 0 }
  71. };
  72. static inline long long rdtsc()
  73. {
  74. long long l;
  75. asm volatile( "rdtsc\n\t"
  76. : "=A" (l)
  77. );
  78. return l;
  79. }
  80. static test_speed(int step)
  81. {
  82. const struct pix_func* pix = pix_func;
  83. const int linesize = 720;
  84. char empty[32768];
  85. char* bu =(char*)(((long)empty + 32) & ~0xf);
  86. int sum = 0;
  87. while (pix->name)
  88. {
  89. int i;
  90. uint64_t te, ts;
  91. op_pixels_func func = pix->func;
  92. char* im = bu;
  93. if (!(pix->mm_flags & mm_flags))
  94. continue;
  95. printf("%30s... ", pix->name);
  96. fflush(stdout);
  97. ts = rdtsc();
  98. for(i=0; i<100000; i++){
  99. func(im, im + 1000, linesize, 16);
  100. im += step;
  101. if (im > bu + 20000)
  102. im = bu;
  103. }
  104. te = rdtsc();
  105. emms();
  106. printf("% 9d\n", (int)(te - ts));
  107. sum += (te - ts) / 100000;
  108. if (pix->mm_flags & PAD)
  109. puts("");
  110. pix++;
  111. }
  112. printf("Total sum: %d\n", sum);
  113. }
  114. int main(int argc, char* argv[])
  115. {
  116. int step = 16;
  117. if (argc > 1)
  118. {
  119. // something simple for now
  120. if (argc > 2 && (strcmp("-s", argv[1]) == 0
  121. || strcmp("-step", argv[1]) == 0))
  122. step = atoi(argv[2]);
  123. }
  124. mm_flags = mm_support();
  125. printf("%s: detected CPU flags:", argv[0]);
  126. if (mm_flags & MM_MMX)
  127. printf(" mmx");
  128. if (mm_flags & MM_MMXEXT)
  129. printf(" mmxext");
  130. if (mm_flags & MM_3DNOW)
  131. printf(" 3dnow");
  132. if (mm_flags & MM_SSE)
  133. printf(" sse");
  134. if (mm_flags & MM_SSE2)
  135. printf(" sse2");
  136. printf("\n");
  137. printf("Using step: %d\n", step);
  138. test_speed(step);
  139. }