fixed_dsp.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * Copyright (c) 2015 James Almer
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (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
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. */
  20. #include "checkasm.h"
  21. #include "libavutil/common.h"
  22. #include "libavutil/fixed_dsp.h"
  23. #include "libavutil/internal.h"
  24. #include "libavutil/mem.h"
  25. #define BUF_SIZE 256
  26. #define randomize_buffers() \
  27. do { \
  28. int i; \
  29. for (i = 0; i < BUF_SIZE; i++) { \
  30. src0[i] = sign_extend(rnd(), 24); \
  31. src1[i] = sign_extend(rnd(), 24); \
  32. src2[i] = sign_extend(rnd(), 24); \
  33. } \
  34. } while (0)
  35. static void check_vector_fmul(const int *src0, const int *src1)
  36. {
  37. LOCAL_ALIGNED_32(int, ref, [BUF_SIZE]);
  38. LOCAL_ALIGNED_32(int, new, [BUF_SIZE]);
  39. declare_func(void, int *dst, const int *src0, const int *src1, int len);
  40. call_ref(ref, src0, src1, BUF_SIZE);
  41. call_new(new, src0, src1, BUF_SIZE);
  42. if (memcmp(ref, new, BUF_SIZE * sizeof(int)))
  43. fail();
  44. bench_new(new, src0, src1, BUF_SIZE);
  45. }
  46. static void check_vector_fmul_add(const int *src0, const int *src1, const int *src2)
  47. {
  48. LOCAL_ALIGNED_32(int, ref, [BUF_SIZE]);
  49. LOCAL_ALIGNED_32(int, new, [BUF_SIZE]);
  50. declare_func(void, int *dst, const int *src0, const int *src1, const int *src2, int len);
  51. call_ref(ref, src0, src1, src2, BUF_SIZE);
  52. call_new(new, src0, src1, src2, BUF_SIZE);
  53. if (memcmp(ref, new, BUF_SIZE * sizeof(int)))
  54. fail();
  55. bench_new(new, src0, src1, src2, BUF_SIZE);
  56. }
  57. static void check_vector_fmul_window(const int32_t *src0, const int32_t *src1, const int32_t *win)
  58. {
  59. LOCAL_ALIGNED_32(int32_t, ref, [BUF_SIZE]);
  60. LOCAL_ALIGNED_32(int32_t, new, [BUF_SIZE]);
  61. declare_func(void, int32_t *dst, const int32_t *src0, const int32_t *src1, const int32_t *win, int len);
  62. call_ref(ref, src0, src1, win, BUF_SIZE / 2);
  63. call_new(new, src0, src1, win, BUF_SIZE / 2);
  64. if (memcmp(ref, new, BUF_SIZE * sizeof(int32_t)))
  65. fail();
  66. bench_new(new, src0, src1, win, BUF_SIZE / 2);
  67. }
  68. static void check_vector_fmul_window_scaled(const int32_t *src0, const int32_t *src1, const int32_t *win)
  69. {
  70. LOCAL_ALIGNED_16(int16_t, ref, [BUF_SIZE]);
  71. LOCAL_ALIGNED_16(int16_t, new, [BUF_SIZE]);
  72. declare_func(void, int16_t *dst, const int32_t *src0, const int32_t *src1, const int32_t *win, int len, uint8_t bits);
  73. call_ref(ref, src0, src1, win, BUF_SIZE / 2, 2);
  74. call_new(new, src0, src1, win, BUF_SIZE / 2, 2);
  75. if (memcmp(ref, new, BUF_SIZE * sizeof(int16_t)))
  76. fail();
  77. bench_new(new, src0, src1, win, BUF_SIZE / 2, 2);
  78. }
  79. static void check_butterflies(const int *src0, const int *src1)
  80. {
  81. LOCAL_ALIGNED_16(int, ref0, [BUF_SIZE]);
  82. LOCAL_ALIGNED_16(int, ref1, [BUF_SIZE]);
  83. LOCAL_ALIGNED_16(int, new0, [BUF_SIZE]);
  84. LOCAL_ALIGNED_16(int, new1, [BUF_SIZE]);
  85. declare_func(void, int *av_restrict src0, int *av_restrict src1, int len);
  86. memcpy(ref0, src0, BUF_SIZE * sizeof(*src0));
  87. memcpy(ref1, src1, BUF_SIZE * sizeof(*src1));
  88. memcpy(new0, src0, BUF_SIZE * sizeof(*src0));
  89. memcpy(new1, src1, BUF_SIZE * sizeof(*src1));
  90. call_ref(ref0, ref1, BUF_SIZE);
  91. call_new(new0, new1, BUF_SIZE);
  92. if (memcmp(ref0, new0, BUF_SIZE * sizeof(*ref0)) ||
  93. memcmp(ref1, new1, BUF_SIZE * sizeof(*ref1)))
  94. fail();
  95. memcpy(new0, src0, BUF_SIZE * sizeof(*src0));
  96. memcpy(new1, src1, BUF_SIZE * sizeof(*src1));
  97. bench_new(new0, new1, BUF_SIZE);
  98. }
  99. static void check_scalarproduct_fixed(const int *src0, const int *src1)
  100. {
  101. int ref, new;
  102. declare_func(int, const int *src0, const int *src1, int len);
  103. ref = call_ref(src0, src1, BUF_SIZE);
  104. new = call_new(src0, src1, BUF_SIZE);
  105. if (ref != new)
  106. fail();
  107. bench_new(src0, src1, BUF_SIZE);
  108. }
  109. void checkasm_check_fixed_dsp(void)
  110. {
  111. LOCAL_ALIGNED_32(int32_t, src0, [BUF_SIZE]);
  112. LOCAL_ALIGNED_32(int32_t, src1, [BUF_SIZE]);
  113. LOCAL_ALIGNED_32(int32_t, src2, [BUF_SIZE]);
  114. AVFixedDSPContext *fdsp = avpriv_alloc_fixed_dsp(1);
  115. randomize_buffers();
  116. if (check_func(fdsp->vector_fmul, "vector_fmul_fixed"))
  117. check_vector_fmul(src0, src1);
  118. if (check_func(fdsp->vector_fmul_add, "vector_fmul_add_fixed"))
  119. check_vector_fmul_add(src0, src1, src2);
  120. if (check_func(fdsp->vector_fmul_reverse, "vector_fmul_reverse_fixed"))
  121. check_vector_fmul(src0, src1);
  122. if (check_func(fdsp->vector_fmul_window, "vector_fmul_window_fixed"))
  123. check_vector_fmul_window(src0, src1, src2);
  124. if (check_func(fdsp->vector_fmul_window_scaled, "vector_fmul_window_scaled_fixed"))
  125. check_vector_fmul_window_scaled(src0, src1, src2);
  126. report("vector_fmul");
  127. if (check_func(fdsp->butterflies_fixed, "butterflies_fixed"))
  128. check_butterflies(src0, src1);
  129. report("butterflies_fixed");
  130. if (check_func(fdsp->scalarproduct_fixed, "scalarproduct_fixed"))
  131. check_scalarproduct_fixed(src0, src1);
  132. report("scalarproduct_fixed");
  133. av_freep(&fdsp);
  134. }