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.

155 lines
3.9KB

  1. /*
  2. * (c) 2001 Fabrice Bellard
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with this library; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. /**
  19. * @file motion_test.c
  20. * motion test.
  21. */
  22. #include <stdlib.h>
  23. #include <stdio.h>
  24. #include <string.h>
  25. #include <sys/time.h>
  26. #include <unistd.h>
  27. #include "dsputil.h"
  28. #include "i386/mmx.h"
  29. int pix_abs16x16_mmx(uint8_t *blk1, uint8_t *blk2, int lx);
  30. int pix_abs16x16_mmx1(uint8_t *blk1, uint8_t *blk2, int lx);
  31. int pix_abs16x16_x2_mmx(uint8_t *blk1, uint8_t *blk2, int lx);
  32. int pix_abs16x16_x2_mmx1(uint8_t *blk1, uint8_t *blk2, int lx);
  33. int pix_abs16x16_x2_c(uint8_t *blk1, uint8_t *blk2, int lx);
  34. int pix_abs16x16_y2_mmx(uint8_t *blk1, uint8_t *blk2, int lx);
  35. int pix_abs16x16_y2_mmx1(uint8_t *blk1, uint8_t *blk2, int lx);
  36. int pix_abs16x16_y2_c(uint8_t *blk1, uint8_t *blk2, int lx);
  37. int pix_abs16x16_xy2_mmx(uint8_t *blk1, uint8_t *blk2, int lx);
  38. int pix_abs16x16_xy2_mmx1(uint8_t *blk1, uint8_t *blk2, int lx);
  39. int pix_abs16x16_xy2_c(uint8_t *blk1, uint8_t *blk2, int lx);
  40. typedef int motion_func(uint8_t *blk1, uint8_t *blk2, int lx);
  41. #define WIDTH 64
  42. #define HEIGHT 64
  43. uint8_t img1[WIDTH * HEIGHT];
  44. uint8_t img2[WIDTH * HEIGHT];
  45. void fill_random(uint8_t *tab, int size)
  46. {
  47. int i;
  48. for(i=0;i<size;i++) {
  49. #if 1
  50. tab[i] = random() % 256;
  51. #else
  52. tab[i] = i;
  53. #endif
  54. }
  55. }
  56. void help(void)
  57. {
  58. printf("motion-test [-h]\n"
  59. "test motion implementations\n");
  60. exit(1);
  61. }
  62. int64_t gettime(void)
  63. {
  64. struct timeval tv;
  65. gettimeofday(&tv,NULL);
  66. return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
  67. }
  68. #define NB_ITS 500
  69. int dummy;
  70. void test_motion(const char *name,
  71. motion_func *test_func, motion_func *ref_func)
  72. {
  73. int x, y, d1, d2, it;
  74. uint8_t *ptr;
  75. int64_t ti;
  76. printf("testing '%s'\n", name);
  77. /* test correctness */
  78. for(it=0;it<20;it++) {
  79. fill_random(img1, WIDTH * HEIGHT);
  80. fill_random(img2, WIDTH * HEIGHT);
  81. for(y=0;y<HEIGHT-17;y++) {
  82. for(x=0;x<WIDTH-17;x++) {
  83. ptr = img2 + y * WIDTH + x;
  84. d1 = test_func(img1, ptr, WIDTH);
  85. d2 = ref_func(img1, ptr, WIDTH);
  86. if (d1 != d2) {
  87. printf("error: mmx=%d c=%d\n", d1, d2);
  88. }
  89. }
  90. }
  91. }
  92. emms();
  93. /* speed test */
  94. ti = gettime();
  95. d1 = 0;
  96. for(it=0;it<NB_ITS;it++) {
  97. for(y=0;y<HEIGHT-17;y++) {
  98. for(x=0;x<WIDTH-17;x++) {
  99. ptr = img2 + y * WIDTH + x;
  100. d1 += test_func(img1, ptr, WIDTH);
  101. }
  102. }
  103. }
  104. emms();
  105. dummy = d1; /* avoid optimisation */
  106. ti = gettime() - ti;
  107. printf(" %0.0f kop/s\n",
  108. (double)NB_ITS * (WIDTH - 16) * (HEIGHT - 16) /
  109. (double)(ti / 1000.0));
  110. }
  111. int main(int argc, char **argv)
  112. {
  113. int c;
  114. for(;;) {
  115. c = getopt(argc, argv, "h");
  116. if (c == -1)
  117. break;
  118. switch(c) {
  119. case 'h':
  120. help();
  121. break;
  122. }
  123. }
  124. printf("ffmpeg motion test\n");
  125. test_motion("mmx", pix_abs16x16_mmx, pix_abs16x16_c);
  126. test_motion("mmx_x2", pix_abs16x16_x2_mmx, pix_abs16x16_x2_c);
  127. test_motion("mmx_y2", pix_abs16x16_y2_mmx, pix_abs16x16_y2_c);
  128. test_motion("mmx_xy2", pix_abs16x16_xy2_mmx, pix_abs16x16_xy2_c);
  129. return 0;
  130. }