motion_test.c 4.0 KB

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