takdsp.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * Copyright (c) 2023 Institue of Software Chinese Academy of Sciences (ISCAS).
  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/mem.h"
  22. #include "libavutil/mem_internal.h"
  23. #include "libavcodec/takdsp.h"
  24. #include "libavcodec/mathops.h"
  25. #include "checkasm.h"
  26. #define randomize(buf, len) \
  27. do { \
  28. for (int i = 0; i < len; i++) \
  29. buf[i] = rnd(); \
  30. } while (0)
  31. #define BUF_SIZE 1024
  32. static void test_decorrelate_ls(TAKDSPContext *s) {
  33. declare_func(void, const int32_t *, int32_t *, int);
  34. if (check_func(s->decorrelate_ls, "decorrelate_ls")) {
  35. LOCAL_ALIGNED_32(int32_t, p1, [BUF_SIZE]);
  36. LOCAL_ALIGNED_32(int32_t, p2, [BUF_SIZE]);
  37. LOCAL_ALIGNED_32(int32_t, p2_2, [BUF_SIZE]);
  38. randomize(p1, BUF_SIZE);
  39. randomize(p2, BUF_SIZE);
  40. memcpy(p2_2, p2, BUF_SIZE * sizeof(*p2));
  41. call_ref(p1, p2, BUF_SIZE);
  42. call_new(p1, p2_2, BUF_SIZE);
  43. if (memcmp(p2, p2_2, BUF_SIZE * sizeof(*p2)) != 0) {
  44. fail();
  45. }
  46. bench_new(p1, p2, BUF_SIZE);
  47. }
  48. report("decorrelate_ls");
  49. }
  50. static void test_decorrelate_sr(TAKDSPContext *s) {
  51. declare_func(void, int32_t *, const int32_t *, int);
  52. if (check_func(s->decorrelate_sr, "decorrelate_sr")) {
  53. LOCAL_ALIGNED_32(int32_t, p1, [BUF_SIZE]);
  54. LOCAL_ALIGNED_32(int32_t, p1_2, [BUF_SIZE]);
  55. LOCAL_ALIGNED_32(int32_t, p2, [BUF_SIZE]);
  56. randomize(p1, BUF_SIZE);
  57. memcpy(p1_2, p1, BUF_SIZE * sizeof(*p1));
  58. randomize(p2, BUF_SIZE);
  59. call_ref(p1, p2, BUF_SIZE);
  60. call_new(p1_2, p2, BUF_SIZE);
  61. if (memcmp(p1, p1_2, BUF_SIZE * sizeof(*p1)) != 0) {
  62. fail();
  63. }
  64. bench_new(p1, p2, BUF_SIZE);
  65. }
  66. report("decorrelate_sr");
  67. }
  68. static void test_decorrelate_sm(TAKDSPContext *s) {
  69. declare_func(void, int32_t *, int32_t *, int);
  70. if (check_func(s->decorrelate_sm, "decorrelate_sm")) {
  71. LOCAL_ALIGNED_32(int32_t, p1, [BUF_SIZE]);
  72. LOCAL_ALIGNED_32(int32_t, p1_2, [BUF_SIZE]);
  73. LOCAL_ALIGNED_32(int32_t, p2, [BUF_SIZE]);
  74. LOCAL_ALIGNED_32(int32_t, p2_2, [BUF_SIZE]);
  75. randomize(p1, BUF_SIZE);
  76. memcpy(p1_2, p1, BUF_SIZE * sizeof(*p1));
  77. randomize(p2, BUF_SIZE);
  78. memcpy(p2_2, p2, BUF_SIZE * sizeof(*p2));
  79. call_ref(p1, p2, BUF_SIZE);
  80. call_new(p1_2, p2_2, BUF_SIZE);
  81. if (memcmp(p1, p1_2, BUF_SIZE * sizeof(*p1)) != 0 ||
  82. memcmp(p2, p2_2, BUF_SIZE * sizeof(*p2)) != 0) {
  83. fail();
  84. }
  85. bench_new(p1, p2, BUF_SIZE);
  86. }
  87. report("decorrelate_sm");
  88. }
  89. static void test_decorrelate_sf(TAKDSPContext *s) {
  90. declare_func(void, int32_t *, const int32_t *, int, int, int);
  91. if (check_func(s->decorrelate_sf, "decorrelate_sf")) {
  92. LOCAL_ALIGNED_32(int32_t, p1, [BUF_SIZE]);
  93. LOCAL_ALIGNED_32(int32_t, p1_2, [BUF_SIZE]);
  94. LOCAL_ALIGNED_32(int32_t, p2, [BUF_SIZE]);
  95. int dshift, dfactor;
  96. randomize(p1, BUF_SIZE);
  97. memcpy(p1_2, p1, BUF_SIZE * sizeof(*p1));
  98. randomize(p2, BUF_SIZE);
  99. dshift = (rnd() & 0xF) + 1;
  100. dfactor = sign_extend(rnd(), 10);
  101. call_ref(p1, p2, BUF_SIZE, dshift, dfactor);
  102. call_new(p1_2, p2, BUF_SIZE, dshift, dfactor);
  103. if (memcmp(p1, p1_2, BUF_SIZE * sizeof(*p1)) != 0) {
  104. fail();
  105. }
  106. bench_new(p1, p2, BUF_SIZE, dshift, dfactor);
  107. }
  108. report("decorrelate_sf");
  109. }
  110. void checkasm_check_takdsp(void)
  111. {
  112. TAKDSPContext s = { 0 };
  113. ff_takdsp_init(&s);
  114. test_decorrelate_ls(&s);
  115. test_decorrelate_sr(&s);
  116. test_decorrelate_sm(&s);
  117. test_decorrelate_sf(&s);
  118. }