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.

134 lines
3.2KB

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