swscale_ppc_template.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /*
  2. * AltiVec-enhanced yuv2yuvX
  3. *
  4. * Copyright (C) 2004 Romain Dolbeau <romain@dolbeau.org>
  5. * based on the equivalent C code in swscale.c
  6. *
  7. * This file is part of FFmpeg.
  8. *
  9. * FFmpeg is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 2.1 of the License, or (at your option) any later version.
  13. *
  14. * FFmpeg is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with FFmpeg; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. */
  23. static void FUNC(yuv2planeX_8_16)(const int16_t *filter, int filterSize,
  24. const int16_t **src, uint8_t *dest,
  25. const uint8_t *dither, int offset, int x)
  26. {
  27. register int i, j;
  28. LOCAL_ALIGNED(16, int, val, [16]);
  29. vector signed int vo1, vo2, vo3, vo4;
  30. vector unsigned short vs1, vs2;
  31. vector unsigned char vf;
  32. vector unsigned int altivec_vectorShiftInt19 =
  33. vec_add(vec_splat_u32(10), vec_splat_u32(9));
  34. for (i = 0; i < 16; i++)
  35. val[i] = dither[(x + i + offset) & 7] << 12;
  36. vo1 = vec_ld(0, val);
  37. vo2 = vec_ld(16, val);
  38. vo3 = vec_ld(32, val);
  39. vo4 = vec_ld(48, val);
  40. for (j = 0; j < filterSize; j++) {
  41. unsigned int joffset=j<<1;
  42. unsigned int xoffset=x<<1;
  43. vector unsigned char av_unused perm;
  44. vector signed short l1,vLumFilter;
  45. LOAD_FILTER(vLumFilter,filter);
  46. vLumFilter = vec_splat(vLumFilter, 0);
  47. LOAD_L1(l1,src[j],perm);
  48. yuv2planeX_8(vo1, vo2, l1, src[j], x, perm, vLumFilter);
  49. yuv2planeX_8(vo3, vo4, l1, src[j], x + 8, perm, vLumFilter);
  50. }
  51. vo1 = vec_sra(vo1, altivec_vectorShiftInt19);
  52. vo2 = vec_sra(vo2, altivec_vectorShiftInt19);
  53. vo3 = vec_sra(vo3, altivec_vectorShiftInt19);
  54. vo4 = vec_sra(vo4, altivec_vectorShiftInt19);
  55. vs1 = vec_packsu(vo1, vo2);
  56. vs2 = vec_packsu(vo3, vo4);
  57. vf = vec_packsu(vs1, vs2);
  58. VEC_ST(vf, 0, dest);
  59. }
  60. static inline void yuv2planeX_u(const int16_t *filter, int filterSize,
  61. const int16_t **src, uint8_t *dest, int dstW,
  62. const uint8_t *dither, int offset, int x)
  63. {
  64. int i, j;
  65. for (i = x; i < dstW; i++) {
  66. int t = dither[(i + offset) & 7] << 12;
  67. for (j = 0; j < filterSize; j++)
  68. t += src[j][i] * filter[j];
  69. dest[i] = av_clip_uint8(t >> 19);
  70. }
  71. }
  72. static void FUNC(yuv2planeX)(const int16_t *filter, int filterSize,
  73. const int16_t **src, uint8_t *dest, int dstW,
  74. const uint8_t *dither, int offset)
  75. {
  76. int dst_u = -(uintptr_t)dest & 15;
  77. int i;
  78. yuv2planeX_u(filter, filterSize, src, dest, dst_u, dither, offset, 0);
  79. for (i = dst_u; i < dstW - 15; i += 16)
  80. FUNC(yuv2planeX_8_16)(filter, filterSize, src, dest + i, dither,
  81. offset, i);
  82. yuv2planeX_u(filter, filterSize, src, dest, dstW, dither, offset, i);
  83. }
  84. static void FUNC(hScale_real)(SwsContext *c, int16_t *dst, int dstW,
  85. const uint8_t *src, const int16_t *filter,
  86. const int32_t *filterPos, int filterSize)
  87. {
  88. register int i;
  89. LOCAL_ALIGNED(16, int, tempo, [4]);
  90. if (filterSize % 4) {
  91. for (i = 0; i < dstW; i++) {
  92. register int j;
  93. register int srcPos = filterPos[i];
  94. register int val = 0;
  95. for (j = 0; j < filterSize; j++)
  96. val += ((int)src[srcPos + j]) * filter[filterSize * i + j];
  97. dst[i] = FFMIN(val >> 7, (1 << 15) - 1);
  98. }
  99. } else
  100. switch (filterSize) {
  101. case 4:
  102. for (i = 0; i < dstW; i++) {
  103. register int srcPos = filterPos[i];
  104. vector unsigned char src_vF = unaligned_load(srcPos, src);
  105. vector signed short src_v, filter_v;
  106. vector signed int val_vEven, val_s;
  107. src_v = // vec_unpackh sign-extends...
  108. (vector signed short)(VEC_MERGEH((vector unsigned char)vzero, src_vF));
  109. // now put our elements in the even slots
  110. src_v = vec_mergeh(src_v, (vector signed short)vzero);
  111. GET_VF4(i, filter_v, filter);
  112. val_vEven = vec_mule(src_v, filter_v);
  113. val_s = vec_sums(val_vEven, vzero);
  114. vec_st(val_s, 0, tempo);
  115. dst[i] = FFMIN(tempo[3] >> 7, (1 << 15) - 1);
  116. }
  117. break;
  118. case 8:
  119. for (i = 0; i < dstW; i++) {
  120. register int srcPos = filterPos[i];
  121. vector unsigned char src_vF, av_unused src_v0, av_unused src_v1;
  122. vector unsigned char av_unused permS;
  123. vector signed short src_v, filter_v;
  124. vector signed int val_v, val_s;
  125. FIRST_LOAD(src_v0, srcPos, src, permS);
  126. LOAD_SRCV8(srcPos, 0, src, permS, src_v0, src_v1, src_vF);
  127. src_v = // vec_unpackh sign-extends...
  128. (vector signed short)(VEC_MERGEH((vector unsigned char)vzero, src_vF));
  129. filter_v = vec_ld(i << 4, filter);
  130. val_v = vec_msums(src_v, filter_v, (vector signed int)vzero);
  131. val_s = vec_sums(val_v, vzero);
  132. vec_st(val_s, 0, tempo);
  133. dst[i] = FFMIN(tempo[3] >> 7, (1 << 15) - 1);
  134. }
  135. break;
  136. case 16:
  137. for (i = 0; i < dstW; i++) {
  138. register int srcPos = filterPos[i];
  139. vector unsigned char src_vF = unaligned_load(srcPos, src);
  140. vector signed short src_vA = // vec_unpackh sign-extends...
  141. (vector signed short)(VEC_MERGEH((vector unsigned char)vzero, src_vF));
  142. vector signed short src_vB = // vec_unpackh sign-extends...
  143. (vector signed short)(VEC_MERGEL((vector unsigned char)vzero, src_vF));
  144. vector signed short filter_v0 = vec_ld(i << 5, filter);
  145. vector signed short filter_v1 = vec_ld((i << 5) + 16, filter);
  146. vector signed int val_acc = vec_msums(src_vA, filter_v0, (vector signed int)vzero);
  147. vector signed int val_v = vec_msums(src_vB, filter_v1, val_acc);
  148. vector signed int val_s = vec_sums(val_v, vzero);
  149. VEC_ST(val_s, 0, tempo);
  150. dst[i] = FFMIN(tempo[3] >> 7, (1 << 15) - 1);
  151. }
  152. break;
  153. default:
  154. for (i = 0; i < dstW; i++) {
  155. register int j, av_unused offset = i * 2 * filterSize;
  156. register int srcPos = filterPos[i];
  157. vector signed int val_s, val_v = (vector signed int)vzero;
  158. vector signed short av_unused filter_v0R;
  159. vector unsigned char av_unused permF, av_unused src_v0, av_unused permS;
  160. FIRST_LOAD(filter_v0R, offset, filter, permF);
  161. FIRST_LOAD(src_v0, srcPos, src, permS);
  162. for (j = 0; j < filterSize - 15; j += 16) {
  163. vector unsigned char av_unused src_v1, src_vF;
  164. vector signed short av_unused filter_v1R, av_unused filter_v2R,
  165. filter_v0, filter_v1, src_vA, src_vB;
  166. vector signed int val_acc;
  167. LOAD_SRCV(srcPos, j, src, permS, src_v0, src_v1, src_vF);
  168. src_vA = // vec_unpackh sign-extends...
  169. (vector signed short)(VEC_MERGEH((vector unsigned char)vzero, src_vF));
  170. src_vB = // vec_unpackh sign-extends...
  171. (vector signed short)(VEC_MERGEL((vector unsigned char)vzero, src_vF));
  172. GET_VFD(i, j, filter, filter_v0R, filter_v1R, permF, filter_v0, 0);
  173. GET_VFD(i, j, filter, filter_v1R, filter_v2R, permF, filter_v1, 16);
  174. val_acc = vec_msums(src_vA, filter_v0, val_v);
  175. val_v = vec_msums(src_vB, filter_v1, val_acc);
  176. UPDATE_PTR(filter_v2R, filter_v0R, src_v1, src_v0);
  177. }
  178. if (j < filterSize - 7) {
  179. // loading src_v0 is useless, it's already done above
  180. vector unsigned char av_unused src_v1, src_vF;
  181. vector signed short src_v, av_unused filter_v1R, filter_v;
  182. LOAD_SRCV8(srcPos, j, src, permS, src_v0, src_v1, src_vF);
  183. src_v = // vec_unpackh sign-extends...
  184. (vector signed short)(VEC_MERGEH((vector unsigned char)vzero, src_vF));
  185. GET_VFD(i, j, filter, filter_v0R, filter_v1R, permF, filter_v, 0);
  186. val_v = vec_msums(src_v, filter_v, val_v);
  187. }
  188. val_s = vec_sums(val_v, vzero);
  189. VEC_ST(val_s, 0, tempo);
  190. dst[i] = FFMIN(tempo[3] >> 7, (1 << 15) - 1);
  191. }
  192. }
  193. }