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.

153 lines
4.6KB

  1. /*
  2. * Copyright (c) 2007 Luca Barbato <lu_zero@gentoo.org>
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg 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. * FFmpeg 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 FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. /**
  21. ** @file libavcodec/ppc/int_altivec.c
  22. ** integer misc ops.
  23. **/
  24. #include "config.h"
  25. #if HAVE_ALTIVEC_H
  26. #include <altivec.h>
  27. #endif
  28. #include "libavcodec/dsputil.h"
  29. #include "dsputil_altivec.h"
  30. #include "types_altivec.h"
  31. static int ssd_int8_vs_int16_altivec(const int8_t *pix1, const int16_t *pix2,
  32. int size) {
  33. int i, size16;
  34. vector signed char vpix1;
  35. vector signed short vpix2, vdiff, vpix1l,vpix1h;
  36. union { vector signed int vscore;
  37. int32_t score[4];
  38. } u;
  39. u.vscore = vec_splat_s32(0);
  40. //
  41. //XXX lazy way, fix it later
  42. #define vec_unaligned_load(b) \
  43. vec_perm(vec_ld(0,b),vec_ld(15,b),vec_lvsl(0, b));
  44. size16 = size >> 4;
  45. while(size16) {
  46. // score += (pix1[i]-pix2[i])*(pix1[i]-pix2[i]);
  47. //load pix1 and the first batch of pix2
  48. vpix1 = vec_unaligned_load(pix1);
  49. vpix2 = vec_unaligned_load(pix2);
  50. pix2 += 8;
  51. //unpack
  52. vpix1h = vec_unpackh(vpix1);
  53. vdiff = vec_sub(vpix1h, vpix2);
  54. vpix1l = vec_unpackl(vpix1);
  55. // load another batch from pix2
  56. vpix2 = vec_unaligned_load(pix2);
  57. u.vscore = vec_msum(vdiff, vdiff, u.vscore);
  58. vdiff = vec_sub(vpix1l, vpix2);
  59. u.vscore = vec_msum(vdiff, vdiff, u.vscore);
  60. pix1 += 16;
  61. pix2 += 8;
  62. size16--;
  63. }
  64. u.vscore = vec_sums(u.vscore, vec_splat_s32(0));
  65. size %= 16;
  66. for (i = 0; i < size; i++) {
  67. u.score[3] += (pix1[i]-pix2[i])*(pix1[i]-pix2[i]);
  68. }
  69. return u.score[3];
  70. }
  71. static int32_t scalarproduct_int16_altivec(int16_t * v1, int16_t * v2, int order, const int shift)
  72. {
  73. int i;
  74. LOAD_ZERO;
  75. register vec_s16 vec1, *pv;
  76. register vec_s32 res = vec_splat_s32(0), t;
  77. register vec_u32 shifts;
  78. int32_t ires;
  79. shifts = zero_u32v;
  80. if(shift & 0x10) shifts = vec_add(shifts, vec_sl(vec_splat_u32(0x08), vec_splat_u32(0x1)));
  81. if(shift & 0x08) shifts = vec_add(shifts, vec_splat_u32(0x08));
  82. if(shift & 0x04) shifts = vec_add(shifts, vec_splat_u32(0x04));
  83. if(shift & 0x02) shifts = vec_add(shifts, vec_splat_u32(0x02));
  84. if(shift & 0x01) shifts = vec_add(shifts, vec_splat_u32(0x01));
  85. for(i = 0; i < order; i += 8){
  86. pv = (vec_s16*)v1;
  87. vec1 = vec_perm(pv[0], pv[1], vec_lvsl(0, v1));
  88. t = vec_msum(vec1, vec_ld(0, v2), zero_s32v);
  89. t = vec_sr(t, shifts);
  90. res = vec_sums(t, res);
  91. v1 += 8;
  92. v2 += 8;
  93. }
  94. res = vec_splat(res, 3);
  95. vec_ste(res, 0, &ires);
  96. return ires;
  97. }
  98. static int32_t scalarproduct_and_madd_int16_altivec(int16_t *v1, int16_t *v2, int16_t *v3, int order, int mul)
  99. {
  100. LOAD_ZERO;
  101. vec_s16 *pv1 = (vec_s16*)v1;
  102. vec_s16 *pv2 = (vec_s16*)v2;
  103. vec_s16 *pv3 = (vec_s16*)v3;
  104. register vec_s16 muls = {mul,mul,mul,mul,mul,mul,mul,mul};
  105. register vec_s16 t0, t1, i0, i1;
  106. register vec_s16 i2 = pv2[0], i3 = pv3[0];
  107. register vec_s32 res = zero_s32v;
  108. register vec_u8 align = vec_lvsl(0, v2);
  109. int32_t ires;
  110. order >>= 4;
  111. do {
  112. t0 = vec_perm(i2, pv2[1], align);
  113. i2 = pv2[2];
  114. t1 = vec_perm(pv2[1], i2, align);
  115. i0 = pv1[0];
  116. i1 = pv1[1];
  117. res = vec_msum(t0, i0, res);
  118. res = vec_msum(t1, i1, res);
  119. t0 = vec_perm(i3, pv3[1], align);
  120. i3 = pv3[2];
  121. t1 = vec_perm(pv3[1], i3, align);
  122. pv1[0] = vec_mladd(t0, muls, i0);
  123. pv1[1] = vec_mladd(t1, muls, i1);
  124. pv1 += 2;
  125. pv2 += 2;
  126. pv3 += 2;
  127. } while(--order);
  128. res = vec_splat(vec_sums(res, zero_s32v), 3);
  129. vec_ste(res, 0, &ires);
  130. return ires;
  131. }
  132. void int_init_altivec(DSPContext* c, AVCodecContext *avctx)
  133. {
  134. c->ssd_int8_vs_int16 = ssd_int8_vs_int16_altivec;
  135. c->scalarproduct_int16 = scalarproduct_int16_altivec;
  136. c->scalarproduct_and_madd_int16 = scalarproduct_and_madd_int16_altivec;
  137. }