aacpsdsp.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * FFmpeg is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. */
  18. #include "libavcodec/aacpsdsp.h"
  19. #include "checkasm.h"
  20. #define N 32
  21. #define STRIDE 128
  22. #define BUF_SIZE (N * STRIDE)
  23. #define randomize(buf, len) do { \
  24. int i; \
  25. for (i = 0; i < len; i++) { \
  26. const INTFLOAT f = (INTFLOAT)rnd() / UINT_MAX; \
  27. (buf)[i] = f; \
  28. } \
  29. } while (0)
  30. #define EPS 0.005
  31. static void test_add_squares(void)
  32. {
  33. LOCAL_ALIGNED_16(INTFLOAT, dst0, [BUF_SIZE]);
  34. LOCAL_ALIGNED_16(INTFLOAT, dst1, [BUF_SIZE]);
  35. LOCAL_ALIGNED_16(INTFLOAT, src, [BUF_SIZE], [2]);
  36. declare_func(void, INTFLOAT *dst,
  37. const INTFLOAT (*src)[2], int n);
  38. randomize((INTFLOAT *)src, BUF_SIZE * 2);
  39. randomize(dst0, BUF_SIZE);
  40. memcpy(dst1, dst0, BUF_SIZE * sizeof(INTFLOAT));
  41. call_ref(dst0, src, BUF_SIZE);
  42. call_new(dst1, src, BUF_SIZE);
  43. if (!float_near_abs_eps_array(dst0, dst1, EPS, BUF_SIZE))
  44. fail();
  45. bench_new(dst1, src, BUF_SIZE);
  46. }
  47. static void test_mul_pair_single(void)
  48. {
  49. LOCAL_ALIGNED_16(INTFLOAT, dst0, [BUF_SIZE], [2]);
  50. LOCAL_ALIGNED_16(INTFLOAT, dst1, [BUF_SIZE], [2]);
  51. LOCAL_ALIGNED_16(INTFLOAT, src0, [BUF_SIZE], [2]);
  52. LOCAL_ALIGNED_16(INTFLOAT, src1, [BUF_SIZE]);
  53. declare_func(void, INTFLOAT (*dst)[2],
  54. INTFLOAT (*src0)[2], INTFLOAT *src1, int n);
  55. randomize((INTFLOAT *)src0, BUF_SIZE * 2);
  56. randomize(src1, BUF_SIZE);
  57. call_ref(dst0, src0, src1, BUF_SIZE);
  58. call_new(dst1, src0, src1, BUF_SIZE);
  59. if (!float_near_abs_eps_array((float *)dst0, (float *)dst1, EPS, BUF_SIZE * 2))
  60. fail();
  61. bench_new(dst1, src0, src1, BUF_SIZE);
  62. }
  63. static void test_hybrid_analysis(void)
  64. {
  65. LOCAL_ALIGNED_16(INTFLOAT, dst0, [BUF_SIZE], [2]);
  66. LOCAL_ALIGNED_16(INTFLOAT, dst1, [BUF_SIZE], [2]);
  67. LOCAL_ALIGNED_16(INTFLOAT, in, [13], [2]);
  68. LOCAL_ALIGNED_16(INTFLOAT, filter, [N], [8][2]);
  69. declare_func(void, INTFLOAT (*out)[2], INTFLOAT (*in)[2],
  70. const INTFLOAT (*filter)[8][2],
  71. ptrdiff_t stride, int n);
  72. randomize((INTFLOAT *)in, 13 * 2);
  73. randomize((INTFLOAT *)filter, N * 8 * 2);
  74. randomize((INTFLOAT *)dst0, BUF_SIZE * 2);
  75. memcpy(dst1, dst0, BUF_SIZE * 2 * sizeof(INTFLOAT));
  76. call_ref(dst0, in, filter, STRIDE, N);
  77. call_new(dst1, in, filter, STRIDE, N);
  78. if (!float_near_abs_eps_array((float *)dst0, (float *)dst1, EPS, BUF_SIZE * 2))
  79. fail();
  80. bench_new(dst1, in, filter, STRIDE, N);
  81. }
  82. static void test_hybrid_analysis_ileave(void)
  83. {
  84. LOCAL_ALIGNED_16(INTFLOAT, in, [2], [38][64]);
  85. LOCAL_ALIGNED_16(INTFLOAT, out0, [91], [32][2]);
  86. LOCAL_ALIGNED_16(INTFLOAT, out1, [91], [32][2]);
  87. declare_func(void, INTFLOAT (*out)[32][2], INTFLOAT L[2][38][64],
  88. int i, int len);
  89. randomize((INTFLOAT *)out0, 91 * 32 * 2);
  90. randomize((INTFLOAT *)in, 2 * 38 * 64);
  91. memcpy(out1, out0, 91 * 32 * 2 * sizeof(INTFLOAT));
  92. /* len is hardcoded to 32 as that's the only value used in
  93. libavcodec. asm functions are likely to be optimized
  94. hardcoding this value in their loops and could fail with
  95. anything else.
  96. i is hardcoded to the two values currently used by the
  97. aac decoder because the arm neon implementation is
  98. micro-optimized for them and will fail for almost every
  99. other value. */
  100. call_ref(out0, in, 3, 32);
  101. call_new(out1, in, 3, 32);
  102. /* the function just moves data around, so memcmp is enough */
  103. if (memcmp(out0, out1, 91 * 32 * 2 * sizeof(INTFLOAT)))
  104. fail();
  105. call_ref(out0, in, 5, 32);
  106. call_new(out1, in, 5, 32);
  107. if (memcmp(out0, out1, 91 * 32 * 2 * sizeof(INTFLOAT)))
  108. fail();
  109. bench_new(out1, in, 3, 32);
  110. }
  111. static void test_hybrid_synthesis_deint(void)
  112. {
  113. LOCAL_ALIGNED_16(INTFLOAT, out0, [2], [38][64]);
  114. LOCAL_ALIGNED_16(INTFLOAT, out1, [2], [38][64]);
  115. LOCAL_ALIGNED_16(INTFLOAT, in, [91], [32][2]);
  116. declare_func(void, INTFLOAT out[2][38][64], INTFLOAT (*in)[32][2],
  117. int i, int len);
  118. randomize((INTFLOAT *)in, 91 * 32 * 2);
  119. randomize((INTFLOAT *)out0, 2 * 38 * 64);
  120. memcpy(out1, out0, 2 * 38 * 64 * sizeof(INTFLOAT));
  121. /* len is hardcoded to 32 as that's the only value used in
  122. libavcodec. asm functions are likely to be optimized
  123. hardcoding this value in their loops and could fail with
  124. anything else.
  125. i is hardcoded to the two values currently used by the
  126. aac decoder because the arm neon implementation is
  127. micro-optimized for them and will fail for almost every
  128. other value. */
  129. call_ref(out0, in, 3, 32);
  130. call_new(out1, in, 3, 32);
  131. /* the function just moves data around, so memcmp is enough */
  132. if (memcmp(out0, out1, 2 * 38 * 64 * sizeof(INTFLOAT)))
  133. fail();
  134. call_ref(out0, in, 5, 32);
  135. call_new(out1, in, 5, 32);
  136. if (memcmp(out0, out1, 2 * 38 * 64 * sizeof(INTFLOAT)))
  137. fail();
  138. bench_new(out1, in, 3, 32);
  139. }
  140. static void test_stereo_interpolate(PSDSPContext *psdsp)
  141. {
  142. int i;
  143. LOCAL_ALIGNED_16(INTFLOAT, l, [BUF_SIZE], [2]);
  144. LOCAL_ALIGNED_16(INTFLOAT, r, [BUF_SIZE], [2]);
  145. LOCAL_ALIGNED_16(INTFLOAT, l0, [BUF_SIZE], [2]);
  146. LOCAL_ALIGNED_16(INTFLOAT, r0, [BUF_SIZE], [2]);
  147. LOCAL_ALIGNED_16(INTFLOAT, l1, [BUF_SIZE], [2]);
  148. LOCAL_ALIGNED_16(INTFLOAT, r1, [BUF_SIZE], [2]);
  149. LOCAL_ALIGNED_16(INTFLOAT, h, [2], [4]);
  150. LOCAL_ALIGNED_16(INTFLOAT, h_step, [2], [4]);
  151. declare_func(void, INTFLOAT (*l)[2], INTFLOAT (*r)[2],
  152. INTFLOAT h[2][4], INTFLOAT h_step[2][4], int len);
  153. randomize((INTFLOAT *)l, BUF_SIZE * 2);
  154. randomize((INTFLOAT *)r, BUF_SIZE * 2);
  155. for (i = 0; i < 2; i++) {
  156. if (check_func(psdsp->stereo_interpolate[i], "ps_stereo_interpolate%s", i ? "_ipdopd" : "")) {
  157. memcpy(l0, l, BUF_SIZE * 2 * sizeof(INTFLOAT));
  158. memcpy(l1, l, BUF_SIZE * 2 * sizeof(INTFLOAT));
  159. memcpy(r0, r, BUF_SIZE * 2 * sizeof(INTFLOAT));
  160. memcpy(r1, r, BUF_SIZE * 2 * sizeof(INTFLOAT));
  161. randomize((INTFLOAT *)h, 2 * 4);
  162. randomize((INTFLOAT *)h_step, 2 * 4);
  163. call_ref(l0, r0, h, h_step, BUF_SIZE);
  164. call_new(l1, r1, h, h_step, BUF_SIZE);
  165. if (!float_near_abs_eps_array((float *)l0, (float *)l1, EPS, BUF_SIZE * 2) ||
  166. !float_near_abs_eps_array((float *)r0, (float *)r1, EPS, BUF_SIZE * 2))
  167. fail();
  168. memcpy(l1, l, BUF_SIZE * 2 * sizeof(INTFLOAT));
  169. memcpy(r1, r, BUF_SIZE * 2 * sizeof(INTFLOAT));
  170. bench_new(l1, r1, h, h_step, BUF_SIZE);
  171. }
  172. }
  173. }
  174. void checkasm_check_aacpsdsp(void)
  175. {
  176. PSDSPContext psdsp;
  177. ff_psdsp_init(&psdsp);
  178. if (check_func(psdsp.add_squares, "ps_add_squares"))
  179. test_add_squares();
  180. report("add_squares");
  181. if (check_func(psdsp.mul_pair_single, "ps_mul_pair_single"))
  182. test_mul_pair_single();
  183. report("mul_pair_single");
  184. if (check_func(psdsp.hybrid_analysis, "ps_hybrid_analysis"))
  185. test_hybrid_analysis();
  186. report("hybrid_analysis");
  187. if (check_func(psdsp.hybrid_analysis_ileave, "ps_hybrid_analysis_ileave"))
  188. test_hybrid_analysis_ileave();
  189. report("hybrid_analysis_ileave");
  190. if (check_func(psdsp.hybrid_synthesis_deint, "ps_hybrid_synthesis_deint"))
  191. test_hybrid_synthesis_deint();
  192. report("hybrid_synthesis_deint");
  193. test_stereo_interpolate(&psdsp);
  194. report("stereo_interpolate");
  195. }