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.

162 lines
5.5KB

  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, [12], [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, 12 * 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_stereo_interpolate(PSDSPContext *psdsp)
  83. {
  84. int i;
  85. LOCAL_ALIGNED_16(INTFLOAT, l, [BUF_SIZE], [2]);
  86. LOCAL_ALIGNED_16(INTFLOAT, r, [BUF_SIZE], [2]);
  87. LOCAL_ALIGNED_16(INTFLOAT, l0, [BUF_SIZE], [2]);
  88. LOCAL_ALIGNED_16(INTFLOAT, r0, [BUF_SIZE], [2]);
  89. LOCAL_ALIGNED_16(INTFLOAT, l1, [BUF_SIZE], [2]);
  90. LOCAL_ALIGNED_16(INTFLOAT, r1, [BUF_SIZE], [2]);
  91. LOCAL_ALIGNED_16(INTFLOAT, h, [2], [4]);
  92. LOCAL_ALIGNED_16(INTFLOAT, h_step, [2], [4]);
  93. declare_func(void, INTFLOAT (*l)[2], INTFLOAT (*r)[2],
  94. INTFLOAT h[2][4], INTFLOAT h_step[2][4], int len);
  95. randomize((INTFLOAT *)l, BUF_SIZE * 2);
  96. randomize((INTFLOAT *)r, BUF_SIZE * 2);
  97. for (i = 0; i < 2; i++) {
  98. if (check_func(psdsp->stereo_interpolate[i], "ps_stereo_interpolate%s", i ? "_ipdopd" : "")) {
  99. memcpy(l0, l, BUF_SIZE * 2 * sizeof(INTFLOAT));
  100. memcpy(l1, l, BUF_SIZE * 2 * sizeof(INTFLOAT));
  101. memcpy(r0, r, BUF_SIZE * 2 * sizeof(INTFLOAT));
  102. memcpy(r1, r, BUF_SIZE * 2 * sizeof(INTFLOAT));
  103. randomize((INTFLOAT *)h, 2 * 4);
  104. randomize((INTFLOAT *)h_step, 2 * 4);
  105. call_ref(l0, r0, h, h_step, BUF_SIZE);
  106. call_new(l1, r1, h, h_step, BUF_SIZE);
  107. if (!float_near_abs_eps_array((float *)l0, (float *)l1, EPS, BUF_SIZE * 2) ||
  108. !float_near_abs_eps_array((float *)r0, (float *)r1, EPS, BUF_SIZE * 2))
  109. fail();
  110. memcpy(l1, l, BUF_SIZE * 2 * sizeof(INTFLOAT));
  111. memcpy(r1, r, BUF_SIZE * 2 * sizeof(INTFLOAT));
  112. bench_new(l1, r1, h, h_step, BUF_SIZE);
  113. }
  114. }
  115. }
  116. void checkasm_check_aacpsdsp(void)
  117. {
  118. PSDSPContext psdsp;
  119. ff_psdsp_init(&psdsp);
  120. if (check_func(psdsp.add_squares, "ps_add_squares"))
  121. test_add_squares();
  122. report("add_squares");
  123. if (check_func(psdsp.mul_pair_single, "ps_mul_pair_single"))
  124. test_mul_pair_single();
  125. report("mul_pair_single");
  126. if (check_func(psdsp.hybrid_analysis, "ps_hybrid_analysis"))
  127. test_hybrid_analysis();
  128. report("hybrid_analysis");
  129. test_stereo_interpolate(&psdsp);
  130. report("stereo_interpolate");
  131. }