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.

83 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. #include "config.h"
  21. #if HAVE_ALTIVEC_H
  22. #include <altivec.h>
  23. #endif
  24. #include "libavutil/attributes.h"
  25. #include "libavutil/cpu.h"
  26. #include "libavutil/ppc/cpu.h"
  27. #include "libavutil/ppc/types_altivec.h"
  28. #include "libavcodec/apedsp.h"
  29. #if HAVE_ALTIVEC && HAVE_BIGENDIAN
  30. static int32_t scalarproduct_and_madd_int16_altivec(int16_t *v1,
  31. const int16_t *v2,
  32. const int16_t *v3,
  33. int order, int mul)
  34. {
  35. LOAD_ZERO;
  36. vec_s16 *pv1 = (vec_s16 *) v1;
  37. register vec_s16 muls = { mul, mul, mul, mul, mul, mul, mul, mul };
  38. register vec_s16 t0, t1, i0, i1, i4;
  39. register vec_s16 i2 = vec_ld(0, v2), i3 = vec_ld(0, v3);
  40. register vec_s32 res = zero_s32v;
  41. register vec_u8 align = vec_lvsl(0, v2);
  42. int32_t ires;
  43. order >>= 4;
  44. do {
  45. i1 = vec_ld(16, v2);
  46. t0 = vec_perm(i2, i1, align);
  47. i2 = vec_ld(32, v2);
  48. t1 = vec_perm(i1, i2, align);
  49. i0 = pv1[0];
  50. i1 = pv1[1];
  51. res = vec_msum(t0, i0, res);
  52. res = vec_msum(t1, i1, res);
  53. i4 = vec_ld(16, v3);
  54. t0 = vec_perm(i3, i4, align);
  55. i3 = vec_ld(32, v3);
  56. t1 = vec_perm(i4, i3, align);
  57. pv1[0] = vec_mladd(t0, muls, i0);
  58. pv1[1] = vec_mladd(t1, muls, i1);
  59. pv1 += 2;
  60. v2 += 16;
  61. v3 += 16;
  62. } while (--order);
  63. res = vec_splat(vec_sums(res, zero_s32v), 3);
  64. vec_ste(res, 0, &ires);
  65. return ires;
  66. }
  67. #endif /* HAVE_ALTIVEC */
  68. av_cold void ff_apedsp_init_ppc(APEDSPContext *c)
  69. {
  70. #if HAVE_ALTIVEC && HAVE_BIGENDIAN
  71. if (!PPC_ALTIVEC(av_get_cpu_flags()))
  72. return;
  73. c->scalarproduct_and_madd_int16 = scalarproduct_and_madd_int16_altivec;
  74. #endif /* HAVE_ALTIVEC */
  75. }