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.

96 lines
3.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 "config.h"
  19. #include <float.h>
  20. #include <stdint.h>
  21. #include "libavfilter/af_afir.h"
  22. #include "libavutil/internal.h"
  23. #include "checkasm.h"
  24. #define LEN 256
  25. #define randomize_buffer(buf) \
  26. do { \
  27. int i; \
  28. double bmg[2], stddev = 10.0, mean = 0.0; \
  29. \
  30. for (i = 0; i < LEN*2+8; i += 2) { \
  31. av_bmg_get(&checkasm_lfg, bmg); \
  32. buf[i] = bmg[0] * stddev + mean; \
  33. buf[i + 1] = bmg[1] * stddev + mean; \
  34. } \
  35. } while(0);
  36. static void test_fcmul_add(const float *src0, const float *src1, const float *src2)
  37. {
  38. LOCAL_ALIGNED_32(float, cdst, [LEN*2+8]);
  39. LOCAL_ALIGNED_32(float, odst, [LEN*2+8]);
  40. int i;
  41. declare_func(void, float *sum, const float *t, const float *c,
  42. ptrdiff_t len);
  43. memcpy(cdst, src0, (LEN*2+8) * sizeof(float));
  44. memcpy(odst, src0, (LEN*2+8) * sizeof(float));
  45. call_ref(cdst, src1, src2, LEN);
  46. call_new(odst, src1, src2, LEN);
  47. for (i = 0; i <= LEN*2; i++) {
  48. int idx = i & ~1;
  49. float cre = src2[idx];
  50. float cim = src2[idx + 1];
  51. float tre = src1[idx];
  52. float tim = src1[idx + 1];
  53. double t = fabs(src0[i]) +
  54. fabs(tre) + fabs(tim) + fabs(cre) + fabs(cim) +
  55. fabs(tre * cre) + fabs(tim * cim) +
  56. fabs(tre * cim) + fabs(tim * cre) +
  57. fabs(tre * cre - tim * cim) +
  58. fabs(tre * cim + tim * cre) +
  59. fabs(cdst[i]) + 1.0;
  60. if (!float_near_abs_eps(cdst[i], odst[i], t * 2 * FLT_EPSILON)) {
  61. fprintf(stderr, "%d: %- .12f - %- .12f = % .12g\n",
  62. i, cdst[i], odst[i], cdst[i] - odst[i]);
  63. fail();
  64. break;
  65. }
  66. }
  67. memcpy(odst, src0, (LEN*2+8) * sizeof(float));
  68. bench_new(odst, src1, src2, LEN);
  69. }
  70. void checkasm_check_afir(void)
  71. {
  72. LOCAL_ALIGNED_32(float, src0, [LEN*2+8]);
  73. LOCAL_ALIGNED_32(float, src1, [LEN*2+8]);
  74. LOCAL_ALIGNED_32(float, src2, [LEN*2+8]);
  75. AudioFIRDSPContext fir = { 0 };
  76. ff_afir_init(&fir);
  77. randomize_buffer(src0);
  78. randomize_buffer(src1);
  79. randomize_buffer(src2);
  80. if (check_func(fir.fcmul_add, "fcmul_add"))
  81. test_fcmul_add(src0, src1, src2);
  82. report("fcmul_add");
  83. }