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.

104 lines
3.2KB

  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 <stdint.h>
  20. #if HAVE_ALTIVEC_H
  21. #include <altivec.h>
  22. #endif
  23. #include "libavutil/attributes.h"
  24. #include "libavutil/cpu.h"
  25. #include "libavutil/ppc/cpu.h"
  26. #include "libavutil/ppc/types_altivec.h"
  27. #include "libavutil/ppc/util_altivec.h"
  28. #include "libavcodec/mpegvideoencdsp.h"
  29. #if HAVE_ALTIVEC
  30. static int pix_norm1_altivec(uint8_t *pix, int line_size)
  31. {
  32. int i, s = 0;
  33. const vector unsigned int zero =
  34. (const vector unsigned int) vec_splat_u32(0);
  35. vector unsigned char perm = vec_lvsl(0, pix);
  36. vector unsigned int sv = (vector unsigned int) vec_splat_u32(0);
  37. vector signed int sum;
  38. for (i = 0; i < 16; i++) {
  39. /* Read the potentially unaligned pixels. */
  40. vector unsigned char pixl = vec_ld(0, pix);
  41. vector unsigned char pixr = vec_ld(15, pix);
  42. vector unsigned char pixv = vec_perm(pixl, pixr, perm);
  43. /* Square the values, and add them to our sum. */
  44. sv = vec_msum(pixv, pixv, sv);
  45. pix += line_size;
  46. }
  47. /* Sum up the four partial sums, and put the result into s. */
  48. sum = vec_sums((vector signed int) sv, (vector signed int) zero);
  49. sum = vec_splat(sum, 3);
  50. vec_ste(sum, 0, &s);
  51. return s;
  52. }
  53. static int pix_sum_altivec(uint8_t *pix, int line_size)
  54. {
  55. int i, s;
  56. const vector unsigned int zero =
  57. (const vector unsigned int) vec_splat_u32(0);
  58. vector unsigned char perm = vec_lvsl(0, pix);
  59. vector unsigned int sad = (vector unsigned int) vec_splat_u32(0);
  60. vector signed int sumdiffs;
  61. for (i = 0; i < 16; i++) {
  62. /* Read the potentially unaligned 16 pixels into t1. */
  63. vector unsigned char pixl = vec_ld(0, pix);
  64. vector unsigned char pixr = vec_ld(15, pix);
  65. vector unsigned char t1 = vec_perm(pixl, pixr, perm);
  66. /* Add each 4 pixel group together and put 4 results into sad. */
  67. sad = vec_sum4s(t1, sad);
  68. pix += line_size;
  69. }
  70. /* Sum up the four partial sums, and put the result into s. */
  71. sumdiffs = vec_sums((vector signed int) sad, (vector signed int) zero);
  72. sumdiffs = vec_splat(sumdiffs, 3);
  73. vec_ste(sumdiffs, 0, &s);
  74. return s;
  75. }
  76. #endif /* HAVE_ALTIVEC */
  77. av_cold void ff_mpegvideoencdsp_init_ppc(MpegvideoEncDSPContext *c,
  78. AVCodecContext *avctx)
  79. {
  80. #if HAVE_ALTIVEC
  81. if (!PPC_ALTIVEC(av_get_cpu_flags()))
  82. return;
  83. c->pix_norm1 = pix_norm1_altivec;
  84. c->pix_sum = pix_sum_altivec;
  85. #endif /* HAVE_ALTIVEC */
  86. }