llauddsp.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * Copyright (c) 2016 Alexandra Hájková
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. */
  20. #include <string.h>
  21. #include "libavutil/common.h"
  22. #include "libavutil/intreadwrite.h"
  23. #include "libavutil/mem.h"
  24. #include "libavutil/mem_internal.h"
  25. #include "libavcodec/lossless_audiodsp.h"
  26. #include "checkasm.h"
  27. #define randomize_buf(buf, len) \
  28. do { \
  29. for (int i = 0; i < len; i++) \
  30. buf[i] = rnd(); \
  31. } while (0)
  32. static void check_scalarproduct_and_madd_int16(LLAudDSPContext *c)
  33. {
  34. #define BUF_SIZE 1088 // multiple of 16
  35. LOCAL_ALIGNED_16(int16_t, v1, [BUF_SIZE]);
  36. LOCAL_ALIGNED_16(int16_t, v2, [BUF_SIZE]);
  37. LOCAL_ALIGNED_16(int16_t, v3, [BUF_SIZE]);
  38. int mul;
  39. declare_func(int32_t, int16_t *, const int16_t *, const int16_t *,
  40. int, int);
  41. randomize_buf(v1, BUF_SIZE);
  42. randomize_buf(v2, BUF_SIZE);
  43. randomize_buf(v3, BUF_SIZE);
  44. mul = (int16_t)rnd();
  45. if (check_func(c->scalarproduct_and_madd_int16,
  46. "scalarproduct_and_madd_int16")) {
  47. LOCAL_ALIGNED_16(int16_t, dst0, [BUF_SIZE]);
  48. LOCAL_ALIGNED_16(int16_t, dst1, [BUF_SIZE]);
  49. int ref, val;
  50. memcpy(dst0, v1, sizeof (*dst0) * BUF_SIZE);
  51. memcpy(dst1, v1, sizeof (*dst1) * BUF_SIZE);
  52. ref = call_ref(dst0, v2, v3, BUF_SIZE, mul);
  53. val = call_new(dst1, v2, v3, BUF_SIZE, mul);
  54. if (memcmp(dst0, dst1, sizeof (*dst0) * BUF_SIZE) != 0 || ref != val)
  55. fail();
  56. bench_new(v1, v2, v3, BUF_SIZE, mul);
  57. }
  58. report("scalarproduct_and_madd_int16");
  59. }
  60. static void check_scalarproduct_and_madd_int32(LLAudDSPContext *c)
  61. {
  62. #define BUF_SIZE 1088 // multiple of 16
  63. LOCAL_ALIGNED_16(int16_t, v1, [BUF_SIZE]);
  64. LOCAL_ALIGNED_16(int32_t, v2, [BUF_SIZE]);
  65. LOCAL_ALIGNED_16(int16_t, v3, [BUF_SIZE]);
  66. int mul;
  67. declare_func(int32_t, int16_t *, const int32_t *, const int16_t *,
  68. int, int);
  69. randomize_buf(v1, BUF_SIZE);
  70. randomize_buf(v2, BUF_SIZE);
  71. randomize_buf(v3, BUF_SIZE);
  72. mul = (int16_t)rnd();
  73. if (check_func(c->scalarproduct_and_madd_int32,
  74. "scalarproduct_and_madd_int32")) {
  75. LOCAL_ALIGNED_16(int16_t, dst0, [BUF_SIZE]);
  76. LOCAL_ALIGNED_16(int16_t, dst1, [BUF_SIZE]);
  77. int ref, val;
  78. memcpy(dst0, v1, sizeof (*dst0) * BUF_SIZE);
  79. memcpy(dst1, v1, sizeof (*dst1) * BUF_SIZE);
  80. ref = call_ref(dst0, v2, v3, BUF_SIZE, mul);
  81. val = call_new(dst1, v2, v3, BUF_SIZE, mul);
  82. if (memcmp(dst0, dst1, sizeof (*dst0) * BUF_SIZE) != 0 || ref != val)
  83. fail();
  84. bench_new(v1, v2, v3, BUF_SIZE, mul);
  85. }
  86. report("scalarproduct_and_madd_int32");
  87. }
  88. void checkasm_check_llauddsp(void)
  89. {
  90. LLAudDSPContext c;
  91. ff_llauddsp_init(&c);
  92. check_scalarproduct_and_madd_int16(&c);
  93. check_scalarproduct_and_madd_int32(&c);
  94. }