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