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.

303 lines
9.1KB

  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 "libavutil/mem_internal.h"
  19. #include "libavcodec/sbrdsp.h"
  20. #include <float.h>
  21. #include "checkasm.h"
  22. #define randomize(buf, len) do { \
  23. int i; \
  24. for (i = 0; i < len; i++) { \
  25. const INTFLOAT f = (INTFLOAT)rnd() / UINT_MAX; \
  26. (buf)[i] = f; \
  27. } \
  28. } while (0)
  29. #define EPS 0.0001
  30. static void test_sum64x5(void)
  31. {
  32. LOCAL_ALIGNED_16(INTFLOAT, dst0, [64 + 256]);
  33. LOCAL_ALIGNED_16(INTFLOAT, dst1, [64 + 256]);
  34. declare_func(void, INTFLOAT *z);
  35. randomize((INTFLOAT *)dst0, 64 + 256);
  36. memcpy(dst1, dst0, (64 + 256) * sizeof(INTFLOAT));
  37. call_ref(dst0);
  38. call_new(dst1);
  39. if (!float_near_abs_eps_array(dst0, dst1, EPS, 64 + 256))
  40. fail();
  41. bench_new(dst1);
  42. }
  43. static void test_sum_square(void)
  44. {
  45. INTFLOAT res0;
  46. INTFLOAT res1;
  47. LOCAL_ALIGNED_16(INTFLOAT, src, [256], [2]);
  48. double t = 4 * 256;
  49. declare_func_float(INTFLOAT, INTFLOAT (*x)[2], int n);
  50. randomize((INTFLOAT *)src, 256 * 2);
  51. res0 = call_ref(src, 256);
  52. res1 = call_new(src, 256);
  53. if (!float_near_abs_eps(res0, res1, t * 2 * FLT_EPSILON))
  54. fail();
  55. bench_new(src, 256);
  56. }
  57. static void test_neg_odd_64(void)
  58. {
  59. LOCAL_ALIGNED_16(INTFLOAT, dst0, [64]);
  60. LOCAL_ALIGNED_16(INTFLOAT, dst1, [64]);
  61. declare_func(void, INTFLOAT *x);
  62. randomize((INTFLOAT *)dst0, 64);
  63. memcpy(dst1, dst0, (64) * sizeof(INTFLOAT));
  64. call_ref(dst0);
  65. call_new(dst1);
  66. if (!float_near_abs_eps_array(dst0, dst1, EPS, 64))
  67. fail();
  68. bench_new(dst1);
  69. }
  70. static void test_qmf_pre_shuffle(void)
  71. {
  72. LOCAL_ALIGNED_16(INTFLOAT, dst0, [128]);
  73. LOCAL_ALIGNED_16(INTFLOAT, dst1, [128]);
  74. declare_func(void, INTFLOAT *z);
  75. randomize((INTFLOAT *)dst0, 128);
  76. memcpy(dst1, dst0, (128) * sizeof(INTFLOAT));
  77. call_ref(dst0);
  78. call_new(dst1);
  79. if (!float_near_abs_eps_array(dst0, dst1, EPS, 128))
  80. fail();
  81. bench_new(dst1);
  82. }
  83. static void test_qmf_post_shuffle(void)
  84. {
  85. LOCAL_ALIGNED_16(INTFLOAT, src, [64]);
  86. LOCAL_ALIGNED_16(INTFLOAT, dst0, [32], [2]);
  87. LOCAL_ALIGNED_16(INTFLOAT, dst1, [32], [2]);
  88. declare_func(void, INTFLOAT W[32][2], const INTFLOAT *z);
  89. randomize((INTFLOAT *)src, 64);
  90. call_ref(dst0, src);
  91. call_new(dst1, src);
  92. if (!float_near_abs_eps_array((INTFLOAT *)dst0, (INTFLOAT *)dst1, EPS, 64))
  93. fail();
  94. bench_new(dst1, src);
  95. }
  96. static void test_qmf_deint_neg(void)
  97. {
  98. LOCAL_ALIGNED_16(INTFLOAT, src, [64]);
  99. LOCAL_ALIGNED_16(INTFLOAT, dst0, [64]);
  100. LOCAL_ALIGNED_16(INTFLOAT, dst1, [64]);
  101. declare_func(void, INTFLOAT *v, const INTFLOAT *src);
  102. randomize((INTFLOAT *)src, 64);
  103. call_ref(dst0, src);
  104. call_new(dst1, src);
  105. if (!float_near_abs_eps_array(dst0, dst1, EPS, 64))
  106. fail();
  107. bench_new(dst1, src);
  108. }
  109. static void test_qmf_deint_bfly(void)
  110. {
  111. LOCAL_ALIGNED_16(INTFLOAT, src0, [64]);
  112. LOCAL_ALIGNED_16(INTFLOAT, src1, [64]);
  113. LOCAL_ALIGNED_16(INTFLOAT, dst0, [128]);
  114. LOCAL_ALIGNED_16(INTFLOAT, dst1, [128]);
  115. declare_func(void, INTFLOAT *v, const INTFLOAT *src0, const INTFLOAT *src1);
  116. memset(dst0, 0, 128 * sizeof(INTFLOAT));
  117. memset(dst1, 0, 128 * sizeof(INTFLOAT));
  118. randomize((INTFLOAT *)src0, 64);
  119. randomize((INTFLOAT *)src1, 64);
  120. call_ref(dst0, src0, src1);
  121. call_new(dst1, src0, src1);
  122. if (!float_near_abs_eps_array(dst0, dst1, EPS, 128))
  123. fail();
  124. bench_new(dst1, src0, src1);
  125. }
  126. static void test_autocorrelate(void)
  127. {
  128. LOCAL_ALIGNED_16(INTFLOAT, src, [40], [2]);
  129. LOCAL_ALIGNED_16(INTFLOAT, dst0, [3], [2][2]);
  130. LOCAL_ALIGNED_16(INTFLOAT, dst1, [3], [2][2]);
  131. declare_func(void, const INTFLOAT x[40][2], INTFLOAT phi[3][2][2]);
  132. memset(dst0, 0, 3 * 2 * 2 * sizeof(INTFLOAT));
  133. memset(dst1, 0, 3 * 2 * 2 * sizeof(INTFLOAT));
  134. randomize((INTFLOAT *)src, 80);
  135. call_ref(src, dst0);
  136. call_new(src, dst1);
  137. if (!float_near_abs_eps_array((INTFLOAT *)dst0, (INTFLOAT *)dst1, EPS, 3 * 2 * 2))
  138. fail();
  139. bench_new(src, dst1);
  140. }
  141. static void test_hf_gen(void)
  142. {
  143. LOCAL_ALIGNED_16(INTFLOAT, low, [128], [2]);
  144. LOCAL_ALIGNED_16(INTFLOAT, alpha0, [2]);
  145. LOCAL_ALIGNED_16(INTFLOAT, alpha1, [2]);
  146. LOCAL_ALIGNED_16(INTFLOAT, dst0, [128], [2]);
  147. LOCAL_ALIGNED_16(INTFLOAT, dst1, [128], [2]);
  148. INTFLOAT bw = (INTFLOAT)rnd() / UINT_MAX;
  149. int i;
  150. declare_func(void, INTFLOAT (*X_high)[2], const INTFLOAT (*X_low)[2],
  151. const INTFLOAT alpha0[2], const INTFLOAT alpha1[2],
  152. INTFLOAT bw, int start, int end);
  153. randomize((INTFLOAT *)low, 128 * 2);
  154. randomize((INTFLOAT *)alpha0, 2);
  155. randomize((INTFLOAT *)alpha1, 2);
  156. for (i = 2; i < 64; i += 2) {
  157. memset(dst0, 0, 128 * 2 * sizeof(INTFLOAT));
  158. memset(dst1, 0, 128 * 2 * sizeof(INTFLOAT));
  159. call_ref(dst0, low, alpha0, alpha1, 0.0, i, 128);
  160. call_new(dst1, low, alpha0, alpha1, 0.0, i, 128);
  161. if (!float_near_abs_eps_array((INTFLOAT *)dst0, (INTFLOAT *)dst1, EPS, 128 * 2))
  162. fail();
  163. bench_new(dst1, low, alpha0, alpha1, bw, i, 128);
  164. }
  165. }
  166. static void test_hf_g_filt(void)
  167. {
  168. LOCAL_ALIGNED_16(INTFLOAT, high, [128], [40][2]);
  169. LOCAL_ALIGNED_16(INTFLOAT, g_filt, [128]);
  170. LOCAL_ALIGNED_16(INTFLOAT, dst0, [128], [2]);
  171. LOCAL_ALIGNED_16(INTFLOAT, dst1, [128], [2]);
  172. declare_func(void, INTFLOAT (*Y)[2], const INTFLOAT (*X_high)[40][2],
  173. const INTFLOAT *g_filt, int m_max, intptr_t ixh);
  174. randomize((INTFLOAT *)high, 128 * 40 * 2);
  175. randomize((INTFLOAT *)g_filt, 128);
  176. call_ref(dst0, high, g_filt, 128, 20);
  177. call_new(dst1, high, g_filt, 128, 20);
  178. if (!float_near_abs_eps_array((INTFLOAT *)dst0, (INTFLOAT *)dst1, EPS, 128 * 2))
  179. fail();
  180. bench_new(dst1, high, g_filt, 128, 20);
  181. }
  182. static void test_hf_apply_noise(const SBRDSPContext *sbrdsp)
  183. {
  184. LOCAL_ALIGNED_16(AAC_FLOAT, s_m, [128]);
  185. LOCAL_ALIGNED_16(AAC_FLOAT, q_filt, [128]);
  186. LOCAL_ALIGNED_16(INTFLOAT, ref, [128], [2]);
  187. LOCAL_ALIGNED_16(INTFLOAT, dst0, [128], [2]);
  188. LOCAL_ALIGNED_16(INTFLOAT, dst1, [128], [2]);
  189. int noise = 0x2a;
  190. int i, j;
  191. declare_func(void, INTFLOAT (*Y)[2], const AAC_FLOAT *s_m,
  192. const AAC_FLOAT *q_filt, int noise,
  193. int kx, int m_max);
  194. randomize((INTFLOAT *)ref, 128 * 2);
  195. randomize((INTFLOAT *)s_m, 128);
  196. randomize((INTFLOAT *)q_filt, 128);
  197. for (i = 0; i < 4; i++) {
  198. if (check_func(sbrdsp->hf_apply_noise[i], "hf_apply_noise_%d", i)) {
  199. for (j = 0; j < 2; j++) {
  200. memcpy(dst0, ref, 128 * 2 * sizeof(INTFLOAT));
  201. memcpy(dst1, ref, 128 * 2 * sizeof(INTFLOAT));
  202. call_ref(dst0, s_m, q_filt, noise, j, 128);
  203. call_new(dst1, s_m, q_filt, noise, j, 128);
  204. if (!float_near_abs_eps_array((INTFLOAT *)dst0, (INTFLOAT *)dst1, EPS, 128 * 2))
  205. fail();
  206. bench_new(dst1, s_m, q_filt, noise, j, 128);
  207. }
  208. }
  209. }
  210. }
  211. void checkasm_check_sbrdsp(void)
  212. {
  213. SBRDSPContext sbrdsp;
  214. ff_sbrdsp_init(&sbrdsp);
  215. if (check_func(sbrdsp.sum64x5, "sum64x5"))
  216. test_sum64x5();
  217. report("sum64x5");
  218. if (check_func(sbrdsp.sum_square, "sum_square"))
  219. test_sum_square();
  220. report("sum_square");
  221. if (check_func(sbrdsp.neg_odd_64, "neg_odd_64"))
  222. test_neg_odd_64();
  223. report("neg_odd_64");
  224. if (check_func(sbrdsp.qmf_pre_shuffle, "qmf_pre_shuffle"))
  225. test_qmf_pre_shuffle();
  226. report("qmf_pre_shuffle");
  227. if (check_func(sbrdsp.qmf_post_shuffle, "qmf_post_shuffle"))
  228. test_qmf_post_shuffle();
  229. report("qmf_post_shuffle");
  230. if (check_func(sbrdsp.qmf_deint_neg, "qmf_deint_neg"))
  231. test_qmf_deint_neg();
  232. report("qmf_deint_neg");
  233. if (check_func(sbrdsp.qmf_deint_bfly, "qmf_deint_bfly"))
  234. test_qmf_deint_bfly();
  235. report("qmf_deint_bfly");
  236. if (check_func(sbrdsp.autocorrelate, "autocorrelate"))
  237. test_autocorrelate();
  238. report("autocorrelate");
  239. if (check_func(sbrdsp.hf_gen, "hf_gen"))
  240. test_hf_gen();
  241. report("hf_gen");
  242. if (check_func(sbrdsp.hf_g_filt, "hf_g_filt"))
  243. test_hf_g_filt();
  244. report("hf_g_filt");
  245. test_hf_apply_noise(&sbrdsp);
  246. report("hf_apply_noise");
  247. }