motion-test.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. #undef exit
  31. #undef printf
  32. #undef random
  33. #define WIDTH 64
  34. #define HEIGHT 64
  35. uint8_t img1[WIDTH * HEIGHT];
  36. uint8_t img2[WIDTH * HEIGHT];
  37. void fill_random(uint8_t *tab, int size)
  38. {
  39. int i;
  40. for(i=0;i<size;i++) {
  41. #if 1
  42. tab[i] = random() % 256;
  43. #else
  44. tab[i] = i;
  45. #endif
  46. }
  47. }
  48. void help(void)
  49. {
  50. printf("motion-test [-h]\n"
  51. "test motion implementations\n");
  52. exit(1);
  53. }
  54. int64_t gettime(void)
  55. {
  56. struct timeval tv;
  57. gettimeofday(&tv,NULL);
  58. return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
  59. }
  60. #define NB_ITS 500
  61. int dummy;
  62. void test_motion(const char *name,
  63. me_cmp_func test_func, me_cmp_func ref_func)
  64. {
  65. int x, y, d1, d2, it;
  66. uint8_t *ptr;
  67. int64_t ti;
  68. printf("testing '%s'\n", name);
  69. /* test correctness */
  70. for(it=0;it<20;it++) {
  71. fill_random(img1, WIDTH * HEIGHT);
  72. fill_random(img2, WIDTH * HEIGHT);
  73. for(y=0;y<HEIGHT-17;y++) {
  74. for(x=0;x<WIDTH-17;x++) {
  75. ptr = img2 + y * WIDTH + x;
  76. d1 = test_func(NULL, img1, ptr, WIDTH, 1);
  77. d2 = ref_func(NULL, img1, ptr, WIDTH, 1);
  78. if (d1 != d2) {
  79. printf("error: mmx=%d c=%d\n", d1, d2);
  80. }
  81. }
  82. }
  83. }
  84. emms_c();
  85. /* speed test */
  86. ti = gettime();
  87. d1 = 0;
  88. for(it=0;it<NB_ITS;it++) {
  89. for(y=0;y<HEIGHT-17;y++) {
  90. for(x=0;x<WIDTH-17;x++) {
  91. ptr = img2 + y * WIDTH + x;
  92. d1 += test_func(NULL, img1, ptr, WIDTH, 1);
  93. }
  94. }
  95. }
  96. emms_c();
  97. dummy = d1; /* avoid optimization */
  98. ti = gettime() - ti;
  99. printf(" %0.0f kop/s\n",
  100. (double)NB_ITS * (WIDTH - 16) * (HEIGHT - 16) /
  101. (double)(ti / 1000.0));
  102. }
  103. int main(int argc, char **argv)
  104. {
  105. AVCodecContext *ctx;
  106. int c;
  107. DSPContext cctx, mmxctx;
  108. int flags[2] = { FF_MM_MMX, FF_MM_MMXEXT };
  109. for(;;) {
  110. c = getopt(argc, argv, "h");
  111. if (c == -1)
  112. break;
  113. switch(c) {
  114. case 'h':
  115. help();
  116. break;
  117. }
  118. }
  119. printf("ffmpeg motion test\n");
  120. ctx = avcodec_alloc_context();
  121. ctx->dsp_mask = FF_MM_FORCE;
  122. dsputil_init(&cctx, ctx);
  123. for (c = 0; c < 2; c++) {
  124. int x;
  125. ctx->dsp_mask = FF_MM_FORCE | flags[c];
  126. dsputil_init(&mmxctx, ctx);
  127. for (x = 0; x < 2; x++) {
  128. printf("%s for %dx%d pixels\n", c ? "mmx2" : "mmx",
  129. x ? 8 : 16, x ? 8 : 16);
  130. test_motion("mmx", mmxctx.pix_abs[x][0], cctx.pix_abs[x][0]);
  131. test_motion("mmx_x2", mmxctx.pix_abs[x][1], cctx.pix_abs[x][1]);
  132. test_motion("mmx_y2", mmxctx.pix_abs[x][2], cctx.pix_abs[x][2]);
  133. test_motion("mmx_xy2", mmxctx.pix_abs[x][3], cctx.pix_abs[x][3]);
  134. }
  135. }
  136. av_free(ctx);
  137. return 0;
  138. }