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.

166 lines
4.0KB

  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
  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 "config.h"
  30. #include "dsputil.h"
  31. #include "libavutil/lfg.h"
  32. #undef printf
  33. #define WIDTH 64
  34. #define HEIGHT 64
  35. static uint8_t img1[WIDTH * HEIGHT];
  36. static uint8_t img2[WIDTH * HEIGHT];
  37. static void fill_random(uint8_t *tab, int size)
  38. {
  39. int i;
  40. AVLFG prng;
  41. av_lfg_init(&prng, 1);
  42. for(i=0;i<size;i++) {
  43. #if 1
  44. tab[i] = av_lfg_get(&prng) % 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. }
  55. static int64_t gettime(void)
  56. {
  57. struct timeval tv;
  58. gettimeofday(&tv,NULL);
  59. return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
  60. }
  61. #define NB_ITS 500
  62. int dummy;
  63. static void test_motion(const char *name,
  64. me_cmp_func test_func, me_cmp_func ref_func)
  65. {
  66. int x, y, d1, d2, it;
  67. uint8_t *ptr;
  68. int64_t ti;
  69. printf("testing '%s'\n", name);
  70. /* test correctness */
  71. for(it=0;it<20;it++) {
  72. fill_random(img1, WIDTH * HEIGHT);
  73. fill_random(img2, WIDTH * HEIGHT);
  74. for(y=0;y<HEIGHT-17;y++) {
  75. for(x=0;x<WIDTH-17;x++) {
  76. ptr = img2 + y * WIDTH + x;
  77. d1 = test_func(NULL, img1, ptr, WIDTH, 1);
  78. d2 = ref_func(NULL, img1, ptr, WIDTH, 1);
  79. if (d1 != d2) {
  80. printf("error: mmx=%d c=%d\n", d1, d2);
  81. }
  82. }
  83. }
  84. }
  85. emms_c();
  86. /* speed test */
  87. ti = gettime();
  88. d1 = 0;
  89. for(it=0;it<NB_ITS;it++) {
  90. for(y=0;y<HEIGHT-17;y++) {
  91. for(x=0;x<WIDTH-17;x++) {
  92. ptr = img2 + y * WIDTH + x;
  93. d1 += test_func(NULL, img1, ptr, WIDTH, 1);
  94. }
  95. }
  96. }
  97. emms_c();
  98. dummy = d1; /* avoid optimization */
  99. ti = gettime() - ti;
  100. printf(" %0.0f kop/s\n",
  101. (double)NB_ITS * (WIDTH - 16) * (HEIGHT - 16) /
  102. (double)(ti / 1000.0));
  103. }
  104. int main(int argc, char **argv)
  105. {
  106. AVCodecContext *ctx;
  107. int c;
  108. DSPContext cctx, mmxctx;
  109. int flags[2] = { AV_CPU_FLAG_MMX, AV_CPU_FLAG_MMX2 };
  110. int flags_size = HAVE_MMX2 ? 2 : 1;
  111. for(;;) {
  112. c = getopt(argc, argv, "h");
  113. if (c == -1)
  114. break;
  115. switch(c) {
  116. case 'h':
  117. help();
  118. return 1;
  119. }
  120. }
  121. printf("ffmpeg motion test\n");
  122. ctx = avcodec_alloc_context3(NULL);
  123. ctx->dsp_mask = AV_CPU_FLAG_FORCE;
  124. ff_dsputil_init(&cctx, ctx);
  125. for (c = 0; c < flags_size; c++) {
  126. int x;
  127. ctx->dsp_mask = AV_CPU_FLAG_FORCE | flags[c];
  128. ff_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. }