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.

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