fixed_dsp.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. #include "libavutil/mem_internal.h"
  26. #define BUF_SIZE 256
  27. #define randomize_buffers() \
  28. do { \
  29. int i; \
  30. for (i = 0; i < BUF_SIZE; i++) { \
  31. src0[i] = sign_extend(rnd(), 24); \
  32. src1[i] = sign_extend(rnd(), 24); \
  33. src2[i] = sign_extend(rnd(), 24); \
  34. } \
  35. } while (0)
  36. static void check_vector_fmul(const int *src0, const int *src1)
  37. {
  38. LOCAL_ALIGNED_32(int, ref, [BUF_SIZE]);
  39. LOCAL_ALIGNED_32(int, new, [BUF_SIZE]);
  40. declare_func(void, int *dst, const int *src0, const int *src1, int len);
  41. call_ref(ref, src0, src1, BUF_SIZE);
  42. call_new(new, src0, src1, BUF_SIZE);
  43. if (memcmp(ref, new, BUF_SIZE * sizeof(int)))
  44. fail();
  45. bench_new(new, src0, src1, BUF_SIZE);
  46. }
  47. static void check_vector_fmul_add(const int *src0, const int *src1, const int *src2)
  48. {
  49. LOCAL_ALIGNED_32(int, ref, [BUF_SIZE]);
  50. LOCAL_ALIGNED_32(int, new, [BUF_SIZE]);
  51. declare_func(void, int *dst, const int *src0, const int *src1, const int *src2, int len);
  52. call_ref(ref, src0, src1, src2, BUF_SIZE);
  53. call_new(new, src0, src1, src2, BUF_SIZE);
  54. if (memcmp(ref, new, BUF_SIZE * sizeof(int)))
  55. fail();
  56. bench_new(new, src0, src1, src2, BUF_SIZE);
  57. }
  58. static void check_vector_fmul_window(const int32_t *src0, const int32_t *src1, const int32_t *win)
  59. {
  60. LOCAL_ALIGNED_32(int32_t, ref, [BUF_SIZE]);
  61. LOCAL_ALIGNED_32(int32_t, new, [BUF_SIZE]);
  62. declare_func(void, int32_t *dst, const int32_t *src0, const int32_t *src1, const int32_t *win, int len);
  63. call_ref(ref, src0, src1, win, BUF_SIZE / 2);
  64. call_new(new, src0, src1, win, BUF_SIZE / 2);
  65. if (memcmp(ref, new, BUF_SIZE * sizeof(int32_t)))
  66. fail();
  67. bench_new(new, src0, src1, win, BUF_SIZE / 2);
  68. }
  69. static void check_vector_fmul_window_scaled(const int32_t *src0, const int32_t *src1, const int32_t *win)
  70. {
  71. LOCAL_ALIGNED_16(int16_t, ref, [BUF_SIZE]);
  72. LOCAL_ALIGNED_16(int16_t, new, [BUF_SIZE]);
  73. declare_func(void, int16_t *dst, const int32_t *src0, const int32_t *src1, const int32_t *win, int len, uint8_t bits);
  74. call_ref(ref, src0, src1, win, BUF_SIZE / 2, 2);
  75. call_new(new, src0, src1, win, BUF_SIZE / 2, 2);
  76. if (memcmp(ref, new, BUF_SIZE * sizeof(int16_t)))
  77. fail();
  78. bench_new(new, src0, src1, win, BUF_SIZE / 2, 2);
  79. }
  80. static void check_butterflies(const int *src0, const int *src1)
  81. {
  82. LOCAL_ALIGNED_16(int, ref0, [BUF_SIZE]);
  83. LOCAL_ALIGNED_16(int, ref1, [BUF_SIZE]);
  84. LOCAL_ALIGNED_16(int, new0, [BUF_SIZE]);
  85. LOCAL_ALIGNED_16(int, new1, [BUF_SIZE]);
  86. declare_func(void, int *restrict src0, int *restrict src1, int len);
  87. memcpy(ref0, src0, BUF_SIZE * sizeof(*src0));
  88. memcpy(ref1, src1, BUF_SIZE * sizeof(*src1));
  89. memcpy(new0, src0, BUF_SIZE * sizeof(*src0));
  90. memcpy(new1, src1, BUF_SIZE * sizeof(*src1));
  91. call_ref(ref0, ref1, BUF_SIZE);
  92. call_new(new0, new1, BUF_SIZE);
  93. if (memcmp(ref0, new0, BUF_SIZE * sizeof(*ref0)) ||
  94. memcmp(ref1, new1, BUF_SIZE * sizeof(*ref1)))
  95. fail();
  96. memcpy(new0, src0, BUF_SIZE * sizeof(*src0));
  97. memcpy(new1, src1, BUF_SIZE * sizeof(*src1));
  98. bench_new(new0, new1, BUF_SIZE);
  99. }
  100. static void check_scalarproduct_fixed(const int *src0, const int *src1)
  101. {
  102. int ref, new;
  103. declare_func(int, const int *src0, const int *src1, int len);
  104. ref = call_ref(src0, src1, BUF_SIZE);
  105. new = call_new(src0, src1, BUF_SIZE);
  106. if (ref != new)
  107. fail();
  108. bench_new(src0, src1, BUF_SIZE);
  109. }
  110. void checkasm_check_fixed_dsp(void)
  111. {
  112. LOCAL_ALIGNED_32(int32_t, src0, [BUF_SIZE]);
  113. LOCAL_ALIGNED_32(int32_t, src1, [BUF_SIZE]);
  114. LOCAL_ALIGNED_32(int32_t, src2, [BUF_SIZE]);
  115. AVFixedDSPContext *fdsp = avpriv_alloc_fixed_dsp(1);
  116. randomize_buffers();
  117. if (check_func(fdsp->vector_fmul, "vector_fmul_fixed"))
  118. check_vector_fmul(src0, src1);
  119. if (check_func(fdsp->vector_fmul_add, "vector_fmul_add_fixed"))
  120. check_vector_fmul_add(src0, src1, src2);
  121. if (check_func(fdsp->vector_fmul_reverse, "vector_fmul_reverse_fixed"))
  122. check_vector_fmul(src0, src1);
  123. if (check_func(fdsp->vector_fmul_window, "vector_fmul_window_fixed"))
  124. check_vector_fmul_window(src0, src1, src2);
  125. if (check_func(fdsp->vector_fmul_window_scaled, "vector_fmul_window_scaled_fixed"))
  126. check_vector_fmul_window_scaled(src0, src1, src2);
  127. report("vector_fmul");
  128. if (check_func(fdsp->butterflies_fixed, "butterflies_fixed"))
  129. check_butterflies(src0, src1);
  130. report("butterflies_fixed");
  131. if (check_func(fdsp->scalarproduct_fixed, "scalarproduct_fixed"))
  132. check_scalarproduct_fixed(src0, src1);
  133. report("scalarproduct_fixed");
  134. av_freep(&fdsp);
  135. }