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.

133 lines
3.1KB

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