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.

139 lines
3.2KB

  1. /* motion test. (c) 2001 Fabrice Bellard. */
  2. /**
  3. * @file motion_test.c
  4. * motion test.
  5. */
  6. #include <stdlib.h>
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include <sys/time.h>
  10. #include <unistd.h>
  11. #include "dsputil.h"
  12. #include "i386/mmx.h"
  13. int pix_abs16x16_mmx(uint8_t *blk1, uint8_t *blk2, int lx);
  14. int pix_abs16x16_mmx1(uint8_t *blk1, uint8_t *blk2, int lx);
  15. int pix_abs16x16_x2_mmx(uint8_t *blk1, uint8_t *blk2, int lx);
  16. int pix_abs16x16_x2_mmx1(uint8_t *blk1, uint8_t *blk2, int lx);
  17. int pix_abs16x16_x2_c(uint8_t *blk1, uint8_t *blk2, int lx);
  18. int pix_abs16x16_y2_mmx(uint8_t *blk1, uint8_t *blk2, int lx);
  19. int pix_abs16x16_y2_mmx1(uint8_t *blk1, uint8_t *blk2, int lx);
  20. int pix_abs16x16_y2_c(uint8_t *blk1, uint8_t *blk2, int lx);
  21. int pix_abs16x16_xy2_mmx(uint8_t *blk1, uint8_t *blk2, int lx);
  22. int pix_abs16x16_xy2_mmx1(uint8_t *blk1, uint8_t *blk2, int lx);
  23. int pix_abs16x16_xy2_c(uint8_t *blk1, uint8_t *blk2, int lx);
  24. typedef int motion_func(uint8_t *blk1, uint8_t *blk2, int lx);
  25. #define WIDTH 64
  26. #define HEIGHT 64
  27. uint8_t img1[WIDTH * HEIGHT];
  28. uint8_t img2[WIDTH * HEIGHT];
  29. void fill_random(uint8_t *tab, int size)
  30. {
  31. int i;
  32. for(i=0;i<size;i++) {
  33. #if 1
  34. tab[i] = random() % 256;
  35. #else
  36. tab[i] = i;
  37. #endif
  38. }
  39. }
  40. void help(void)
  41. {
  42. printf("motion-test [-h]\n"
  43. "test motion implementations\n");
  44. exit(1);
  45. }
  46. int64_t gettime(void)
  47. {
  48. struct timeval tv;
  49. gettimeofday(&tv,NULL);
  50. return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
  51. }
  52. #define NB_ITS 500
  53. int dummy;
  54. void test_motion(const char *name,
  55. motion_func *test_func, motion_func *ref_func)
  56. {
  57. int x, y, d1, d2, it;
  58. uint8_t *ptr;
  59. int64_t ti;
  60. printf("testing '%s'\n", name);
  61. /* test correctness */
  62. for(it=0;it<20;it++) {
  63. fill_random(img1, WIDTH * HEIGHT);
  64. fill_random(img2, WIDTH * HEIGHT);
  65. for(y=0;y<HEIGHT-17;y++) {
  66. for(x=0;x<WIDTH-17;x++) {
  67. ptr = img2 + y * WIDTH + x;
  68. d1 = test_func(img1, ptr, WIDTH);
  69. d2 = ref_func(img1, ptr, WIDTH);
  70. if (d1 != d2) {
  71. printf("error: mmx=%d c=%d\n", d1, d2);
  72. }
  73. }
  74. }
  75. }
  76. emms();
  77. /* speed test */
  78. ti = gettime();
  79. d1 = 0;
  80. for(it=0;it<NB_ITS;it++) {
  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. }
  86. }
  87. }
  88. emms();
  89. dummy = d1; /* avoid optimisation */
  90. ti = gettime() - ti;
  91. printf(" %0.0f kop/s\n",
  92. (double)NB_ITS * (WIDTH - 16) * (HEIGHT - 16) /
  93. (double)(ti / 1000.0));
  94. }
  95. int main(int argc, char **argv)
  96. {
  97. int c;
  98. for(;;) {
  99. c = getopt(argc, argv, "h");
  100. if (c == -1)
  101. break;
  102. switch(c) {
  103. case 'h':
  104. help();
  105. break;
  106. }
  107. }
  108. printf("ffmpeg motion test\n");
  109. test_motion("mmx", pix_abs16x16_mmx, pix_abs16x16_c);
  110. test_motion("mmx_x2", pix_abs16x16_x2_mmx, pix_abs16x16_x2_c);
  111. test_motion("mmx_y2", pix_abs16x16_y2_mmx, pix_abs16x16_y2_c);
  112. test_motion("mmx_xy2", pix_abs16x16_xy2_mmx, pix_abs16x16_xy2_c);
  113. return 0;
  114. }