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.

301 lines
9.0KB

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