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.

136 lines
3.6KB

  1. /*
  2. * This file is part of Libav.
  3. *
  4. * Libav is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * Libav 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 GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with Libav; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include "config.h"
  19. #include "attributes.h"
  20. #include "float_dsp.h"
  21. static void vector_fmul_c(float *dst, const float *src0, const float *src1,
  22. int len)
  23. {
  24. int i;
  25. for (i = 0; i < len; i++)
  26. dst[i] = src0[i] * src1[i];
  27. }
  28. static void vector_fmac_scalar_c(float *dst, const float *src, float mul,
  29. int len)
  30. {
  31. int i;
  32. for (i = 0; i < len; i++)
  33. dst[i] += src[i] * mul;
  34. }
  35. static void vector_fmul_scalar_c(float *dst, const float *src, float mul,
  36. int len)
  37. {
  38. int i;
  39. for (i = 0; i < len; i++)
  40. dst[i] = src[i] * mul;
  41. }
  42. static void vector_dmul_scalar_c(double *dst, const double *src, double mul,
  43. int len)
  44. {
  45. int i;
  46. for (i = 0; i < len; i++)
  47. dst[i] = src[i] * mul;
  48. }
  49. static void vector_fmul_window_c(float *dst, const float *src0,
  50. const float *src1, const float *win, int len)
  51. {
  52. int i, j;
  53. dst += len;
  54. win += len;
  55. src0 += len;
  56. for (i = -len, j = len - 1; i < 0; i++, j--) {
  57. float s0 = src0[i];
  58. float s1 = src1[j];
  59. float wi = win[i];
  60. float wj = win[j];
  61. dst[i] = s0 * wj - s1 * wi;
  62. dst[j] = s0 * wi + s1 * wj;
  63. }
  64. }
  65. static void vector_fmul_add_c(float *dst, const float *src0, const float *src1,
  66. const float *src2, int len){
  67. int i;
  68. for (i = 0; i < len; i++)
  69. dst[i] = src0[i] * src1[i] + src2[i];
  70. }
  71. static void vector_fmul_reverse_c(float *dst, const float *src0,
  72. const float *src1, int len)
  73. {
  74. int i;
  75. src1 += len-1;
  76. for (i = 0; i < len; i++)
  77. dst[i] = src0[i] * src1[-i];
  78. }
  79. static void butterflies_float_c(float *restrict v1, float *restrict v2,
  80. int len)
  81. {
  82. int i;
  83. for (i = 0; i < len; i++) {
  84. float t = v1[i] - v2[i];
  85. v1[i] += v2[i];
  86. v2[i] = t;
  87. }
  88. }
  89. float avpriv_scalarproduct_float_c(const float *v1, const float *v2, int len)
  90. {
  91. float p = 0.0;
  92. int i;
  93. for (i = 0; i < len; i++)
  94. p += v1[i] * v2[i];
  95. return p;
  96. }
  97. av_cold void avpriv_float_dsp_init(AVFloatDSPContext *fdsp, int bit_exact)
  98. {
  99. fdsp->vector_fmul = vector_fmul_c;
  100. fdsp->vector_fmac_scalar = vector_fmac_scalar_c;
  101. fdsp->vector_fmul_scalar = vector_fmul_scalar_c;
  102. fdsp->vector_dmul_scalar = vector_dmul_scalar_c;
  103. fdsp->vector_fmul_window = vector_fmul_window_c;
  104. fdsp->vector_fmul_add = vector_fmul_add_c;
  105. fdsp->vector_fmul_reverse = vector_fmul_reverse_c;
  106. fdsp->butterflies_float = butterflies_float_c;
  107. fdsp->scalarproduct_float = avpriv_scalarproduct_float_c;
  108. if (ARCH_AARCH64)
  109. ff_float_dsp_init_aarch64(fdsp);
  110. if (ARCH_ARM)
  111. ff_float_dsp_init_arm(fdsp);
  112. if (ARCH_PPC)
  113. ff_float_dsp_init_ppc(fdsp, bit_exact);
  114. if (ARCH_X86)
  115. ff_float_dsp_init_x86(fdsp);
  116. }