motion-test.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. * (c) 2001 Fabrice Bellard
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. /**
  21. * @file libavcodec/motion-test.c
  22. * motion test.
  23. */
  24. #include <stdlib.h>
  25. #include <stdio.h>
  26. #include <string.h>
  27. #include <sys/time.h>
  28. #include <unistd.h>
  29. #include "dsputil.h"
  30. #include "libavutil/lfg.h"
  31. #undef exit
  32. #undef printf
  33. #define WIDTH 64
  34. #define HEIGHT 64
  35. uint8_t img1[WIDTH * HEIGHT];
  36. uint8_t img2[WIDTH * HEIGHT];
  37. static void fill_random(uint8_t *tab, int size)
  38. {
  39. int i;
  40. AVLFG prn;
  41. av_lfg_init(&prn, 1);
  42. for(i=0;i<size;i++) {
  43. #if 1
  44. tab[i] = av_lfg_get(&prn) % 256;
  45. #else
  46. tab[i] = i;
  47. #endif
  48. }
  49. }
  50. static void help(void)
  51. {
  52. printf("motion-test [-h]\n"
  53. "test motion implementations\n");
  54. exit(1);
  55. }
  56. static int64_t gettime(void)
  57. {
  58. struct timeval tv;
  59. gettimeofday(&tv,NULL);
  60. return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
  61. }
  62. #define NB_ITS 500
  63. int dummy;
  64. static void test_motion(const char *name,
  65. me_cmp_func test_func, me_cmp_func ref_func)
  66. {
  67. int x, y, d1, d2, it;
  68. uint8_t *ptr;
  69. int64_t ti;
  70. printf("testing '%s'\n", name);
  71. /* test correctness */
  72. for(it=0;it<20;it++) {
  73. fill_random(img1, WIDTH * HEIGHT);
  74. fill_random(img2, WIDTH * HEIGHT);
  75. for(y=0;y<HEIGHT-17;y++) {
  76. for(x=0;x<WIDTH-17;x++) {
  77. ptr = img2 + y * WIDTH + x;
  78. d1 = test_func(NULL, img1, ptr, WIDTH, 1);
  79. d2 = ref_func(NULL, img1, ptr, WIDTH, 1);
  80. if (d1 != d2) {
  81. printf("error: mmx=%d c=%d\n", d1, d2);
  82. }
  83. }
  84. }
  85. }
  86. emms_c();
  87. /* speed test */
  88. ti = gettime();
  89. d1 = 0;
  90. for(it=0;it<NB_ITS;it++) {
  91. for(y=0;y<HEIGHT-17;y++) {
  92. for(x=0;x<WIDTH-17;x++) {
  93. ptr = img2 + y * WIDTH + x;
  94. d1 += test_func(NULL, img1, ptr, WIDTH, 1);
  95. }
  96. }
  97. }
  98. emms_c();
  99. dummy = d1; /* avoid optimization */
  100. ti = gettime() - ti;
  101. printf(" %0.0f kop/s\n",
  102. (double)NB_ITS * (WIDTH - 16) * (HEIGHT - 16) /
  103. (double)(ti / 1000.0));
  104. }
  105. int main(int argc, char **argv)
  106. {
  107. AVCodecContext *ctx;
  108. int c;
  109. DSPContext cctx, mmxctx;
  110. int flags[2] = { FF_MM_MMX, FF_MM_MMXEXT };
  111. for(;;) {
  112. c = getopt(argc, argv, "h");
  113. if (c == -1)
  114. break;
  115. switch(c) {
  116. case 'h':
  117. help();
  118. break;
  119. }
  120. }
  121. printf("ffmpeg motion test\n");
  122. ctx = avcodec_alloc_context();
  123. ctx->dsp_mask = FF_MM_FORCE;
  124. dsputil_init(&cctx, ctx);
  125. for (c = 0; c < 1; c++) {
  126. int x;
  127. ctx->dsp_mask = FF_MM_FORCE | flags[c];
  128. dsputil_init(&mmxctx, ctx);
  129. for (x = 0; x < 2; x++) {
  130. printf("%s for %dx%d pixels\n", c ? "mmx2" : "mmx",
  131. x ? 8 : 16, x ? 8 : 16);
  132. test_motion("mmx", mmxctx.pix_abs[x][0], cctx.pix_abs[x][0]);
  133. test_motion("mmx_x2", mmxctx.pix_abs[x][1], cctx.pix_abs[x][1]);
  134. test_motion("mmx_y2", mmxctx.pix_abs[x][2], cctx.pix_abs[x][2]);
  135. test_motion("mmx_xy2", mmxctx.pix_abs[x][3], cctx.pix_abs[x][3]);
  136. }
  137. }
  138. av_free(ctx);
  139. return 0;
  140. }