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.

105 lines
2.6KB

  1. /*
  2. * Copyright (c) 2007 Luca Barbato <lu_zero@gentoo.org>
  3. *
  4. * This file is part of Libav.
  5. *
  6. * Libav is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * Libav 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 GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with Libav; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. /**
  21. * @file
  22. * miscellaneous audio operations
  23. */
  24. #include "config.h"
  25. #if HAVE_ALTIVEC_H
  26. #include <altivec.h>
  27. #endif
  28. #include "libavutil/attributes.h"
  29. #include "libavutil/cpu.h"
  30. #include "libavutil/ppc/cpu.h"
  31. #include "libavutil/ppc/types_altivec.h"
  32. #include "libavutil/ppc/util_altivec.h"
  33. #include "libavcodec/audiodsp.h"
  34. #if HAVE_ALTIVEC && HAVE_BIGENDIAN
  35. static int32_t scalarproduct_int16_altivec(const int16_t *v1, const int16_t *v2,
  36. int order)
  37. {
  38. int i;
  39. LOAD_ZERO;
  40. register vec_s16 vec1;
  41. register vec_s32 res = vec_splat_s32(0), t;
  42. int32_t ires;
  43. for (i = 0; i < order; i += 8) {
  44. vec1 = vec_unaligned_load(v1);
  45. t = vec_msum(vec1, vec_ld(0, v2), zero_s32v);
  46. res = vec_sums(t, res);
  47. v1 += 8;
  48. v2 += 8;
  49. }
  50. res = vec_splat(res, 3);
  51. vec_ste(res, 0, &ires);
  52. return ires;
  53. }
  54. #endif /* HAVE_ALTIVEC && HAVE_BIGENDIAN */
  55. #if HAVE_VSX
  56. static int32_t scalarproduct_int16_vsx(const int16_t *v1, const int16_t *v2, int order)
  57. {
  58. int i;
  59. LOAD_ZERO;
  60. register vec_s16 vec1;
  61. register vec_s32 res = vec_splat_s32(0), t;
  62. int32_t ires;
  63. for (i = 0; i < order; i += 8) {
  64. vec1 = vec_vsx_ld(0, v1);
  65. t = vec_msum(vec1, vec_ld(0, v2), zero_s32v);
  66. res = vec_sums(t, res);
  67. v1 += 8;
  68. v2 += 8;
  69. }
  70. res = vec_splat(res, 3);
  71. vec_ste(res, 0, &ires);
  72. return ires;
  73. }
  74. #endif /* HAVE_VSX */
  75. av_cold void ff_audiodsp_init_ppc(AudioDSPContext *c)
  76. {
  77. #if HAVE_ALTIVEC && HAVE_BIGENDIAN
  78. if (!PPC_ALTIVEC(av_get_cpu_flags()))
  79. return;
  80. c->scalarproduct_int16 = scalarproduct_int16_altivec;
  81. #endif /* HAVE_ALTIVEC */
  82. #if HAVE_VSX
  83. if (!PPC_VSX(av_get_cpu_flags()))
  84. return;
  85. c->scalarproduct_int16 = scalarproduct_int16_vsx;
  86. #endif /* HAVE_VSX */
  87. }