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.

152 lines
3.7KB

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