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.

320 lines
13KB

  1. /*
  2. * Copyright (c) 2004 Romain Dolbeau <romain@dolbeau.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. #include "libavutil/attributes.h"
  22. #include "libavutil/cpu.h"
  23. #include "libavutil/intreadwrite.h"
  24. #include "libavutil/ppc/cpu.h"
  25. #include "libavutil/ppc/types_altivec.h"
  26. #include "libavutil/ppc/util_altivec.h"
  27. #include "libavcodec/h264qpel.h"
  28. #include "hpeldsp_altivec.h"
  29. #if HAVE_ALTIVEC && HAVE_BIGENDIAN
  30. #define PUT_OP_U8_ALTIVEC(d, s, dst) d = s
  31. #define AVG_OP_U8_ALTIVEC(d, s, dst) d = vec_avg(dst, s)
  32. #define OP_U8_ALTIVEC PUT_OP_U8_ALTIVEC
  33. #define PREFIX_h264_qpel16_h_lowpass_altivec put_h264_qpel16_h_lowpass_altivec
  34. #define PREFIX_h264_qpel16_h_lowpass_num altivec_put_h264_qpel16_h_lowpass_num
  35. #define PREFIX_h264_qpel16_v_lowpass_altivec put_h264_qpel16_v_lowpass_altivec
  36. #define PREFIX_h264_qpel16_v_lowpass_num altivec_put_h264_qpel16_v_lowpass_num
  37. #define PREFIX_h264_qpel16_hv_lowpass_altivec put_h264_qpel16_hv_lowpass_altivec
  38. #define PREFIX_h264_qpel16_hv_lowpass_num altivec_put_h264_qpel16_hv_lowpass_num
  39. #include "h264qpel_template.c"
  40. #undef OP_U8_ALTIVEC
  41. #undef PREFIX_h264_qpel16_h_lowpass_altivec
  42. #undef PREFIX_h264_qpel16_h_lowpass_num
  43. #undef PREFIX_h264_qpel16_v_lowpass_altivec
  44. #undef PREFIX_h264_qpel16_v_lowpass_num
  45. #undef PREFIX_h264_qpel16_hv_lowpass_altivec
  46. #undef PREFIX_h264_qpel16_hv_lowpass_num
  47. #define OP_U8_ALTIVEC AVG_OP_U8_ALTIVEC
  48. #define PREFIX_h264_qpel16_h_lowpass_altivec avg_h264_qpel16_h_lowpass_altivec
  49. #define PREFIX_h264_qpel16_h_lowpass_num altivec_avg_h264_qpel16_h_lowpass_num
  50. #define PREFIX_h264_qpel16_v_lowpass_altivec avg_h264_qpel16_v_lowpass_altivec
  51. #define PREFIX_h264_qpel16_v_lowpass_num altivec_avg_h264_qpel16_v_lowpass_num
  52. #define PREFIX_h264_qpel16_hv_lowpass_altivec avg_h264_qpel16_hv_lowpass_altivec
  53. #define PREFIX_h264_qpel16_hv_lowpass_num altivec_avg_h264_qpel16_hv_lowpass_num
  54. #include "h264qpel_template.c"
  55. #undef OP_U8_ALTIVEC
  56. #undef PREFIX_h264_qpel16_h_lowpass_altivec
  57. #undef PREFIX_h264_qpel16_h_lowpass_num
  58. #undef PREFIX_h264_qpel16_v_lowpass_altivec
  59. #undef PREFIX_h264_qpel16_v_lowpass_num
  60. #undef PREFIX_h264_qpel16_hv_lowpass_altivec
  61. #undef PREFIX_h264_qpel16_hv_lowpass_num
  62. #define H264_MC(OPNAME, SIZE, CODETYPE) \
  63. static void OPNAME ## h264_qpel ## SIZE ## _mc00_ ## CODETYPE (uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
  64. {\
  65. ff_ ## OPNAME ## pixels ## SIZE ## _ ## CODETYPE(dst, src, stride, SIZE);\
  66. }\
  67. \
  68. static void OPNAME ## h264_qpel ## SIZE ## _mc10_ ## CODETYPE(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
  69. { \
  70. DECLARE_ALIGNED(16, uint8_t, half)[SIZE*SIZE];\
  71. put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(half, src, SIZE, stride);\
  72. OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, src, half, stride, stride, SIZE);\
  73. }\
  74. \
  75. static void OPNAME ## h264_qpel ## SIZE ## _mc20_ ## CODETYPE(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
  76. {\
  77. OPNAME ## h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(dst, src, stride, stride);\
  78. }\
  79. \
  80. static void OPNAME ## h264_qpel ## SIZE ## _mc30_ ## CODETYPE(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
  81. {\
  82. DECLARE_ALIGNED(16, uint8_t, half)[SIZE*SIZE];\
  83. put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(half, src, SIZE, stride);\
  84. OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, src+1, half, stride, stride, SIZE);\
  85. }\
  86. \
  87. static void OPNAME ## h264_qpel ## SIZE ## _mc01_ ## CODETYPE(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
  88. {\
  89. DECLARE_ALIGNED(16, uint8_t, half)[SIZE*SIZE];\
  90. put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(half, src, SIZE, stride);\
  91. OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, src, half, stride, stride, SIZE);\
  92. }\
  93. \
  94. static void OPNAME ## h264_qpel ## SIZE ## _mc02_ ## CODETYPE(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
  95. {\
  96. OPNAME ## h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(dst, src, stride, stride);\
  97. }\
  98. \
  99. static void OPNAME ## h264_qpel ## SIZE ## _mc03_ ## CODETYPE(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
  100. {\
  101. DECLARE_ALIGNED(16, uint8_t, half)[SIZE*SIZE];\
  102. put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(half, src, SIZE, stride);\
  103. OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, src+stride, half, stride, stride, SIZE);\
  104. }\
  105. \
  106. static void OPNAME ## h264_qpel ## SIZE ## _mc11_ ## CODETYPE(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
  107. {\
  108. DECLARE_ALIGNED(16, uint8_t, halfH)[SIZE*SIZE];\
  109. DECLARE_ALIGNED(16, uint8_t, halfV)[SIZE*SIZE];\
  110. put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(halfH, src, SIZE, stride);\
  111. put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(halfV, src, SIZE, stride);\
  112. OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfH, halfV, stride, SIZE, SIZE);\
  113. }\
  114. \
  115. static void OPNAME ## h264_qpel ## SIZE ## _mc31_ ## CODETYPE(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
  116. {\
  117. DECLARE_ALIGNED(16, uint8_t, halfH)[SIZE*SIZE];\
  118. DECLARE_ALIGNED(16, uint8_t, halfV)[SIZE*SIZE];\
  119. put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(halfH, src, SIZE, stride);\
  120. put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(halfV, src+1, SIZE, stride);\
  121. OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfH, halfV, stride, SIZE, SIZE);\
  122. }\
  123. \
  124. static void OPNAME ## h264_qpel ## SIZE ## _mc13_ ## CODETYPE(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
  125. {\
  126. DECLARE_ALIGNED(16, uint8_t, halfH)[SIZE*SIZE];\
  127. DECLARE_ALIGNED(16, uint8_t, halfV)[SIZE*SIZE];\
  128. put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(halfH, src + stride, SIZE, stride);\
  129. put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(halfV, src, SIZE, stride);\
  130. OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfH, halfV, stride, SIZE, SIZE);\
  131. }\
  132. \
  133. static void OPNAME ## h264_qpel ## SIZE ## _mc33_ ## CODETYPE(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
  134. {\
  135. DECLARE_ALIGNED(16, uint8_t, halfH)[SIZE*SIZE];\
  136. DECLARE_ALIGNED(16, uint8_t, halfV)[SIZE*SIZE];\
  137. put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(halfH, src + stride, SIZE, stride);\
  138. put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(halfV, src+1, SIZE, stride);\
  139. OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfH, halfV, stride, SIZE, SIZE);\
  140. }\
  141. \
  142. static void OPNAME ## h264_qpel ## SIZE ## _mc22_ ## CODETYPE(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
  143. {\
  144. DECLARE_ALIGNED(16, int16_t, tmp)[SIZE*(SIZE+8)];\
  145. OPNAME ## h264_qpel ## SIZE ## _hv_lowpass_ ## CODETYPE(dst, tmp, src, stride, SIZE, stride);\
  146. }\
  147. \
  148. static void OPNAME ## h264_qpel ## SIZE ## _mc21_ ## CODETYPE(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
  149. {\
  150. DECLARE_ALIGNED(16, uint8_t, halfH)[SIZE*SIZE];\
  151. DECLARE_ALIGNED(16, uint8_t, halfHV)[SIZE*SIZE];\
  152. DECLARE_ALIGNED(16, int16_t, tmp)[SIZE*(SIZE+8)];\
  153. put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(halfH, src, SIZE, stride);\
  154. put_h264_qpel ## SIZE ## _hv_lowpass_ ## CODETYPE(halfHV, tmp, src, SIZE, SIZE, stride);\
  155. OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfH, halfHV, stride, SIZE, SIZE);\
  156. }\
  157. \
  158. static void OPNAME ## h264_qpel ## SIZE ## _mc23_ ## CODETYPE(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
  159. {\
  160. DECLARE_ALIGNED(16, uint8_t, halfH)[SIZE*SIZE];\
  161. DECLARE_ALIGNED(16, uint8_t, halfHV)[SIZE*SIZE];\
  162. DECLARE_ALIGNED(16, int16_t, tmp)[SIZE*(SIZE+8)];\
  163. put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(halfH, src + stride, SIZE, stride);\
  164. put_h264_qpel ## SIZE ## _hv_lowpass_ ## CODETYPE(halfHV, tmp, src, SIZE, SIZE, stride);\
  165. OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfH, halfHV, stride, SIZE, SIZE);\
  166. }\
  167. \
  168. static void OPNAME ## h264_qpel ## SIZE ## _mc12_ ## CODETYPE(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
  169. {\
  170. DECLARE_ALIGNED(16, uint8_t, halfV)[SIZE*SIZE];\
  171. DECLARE_ALIGNED(16, uint8_t, halfHV)[SIZE*SIZE];\
  172. DECLARE_ALIGNED(16, int16_t, tmp)[SIZE*(SIZE+8)];\
  173. put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(halfV, src, SIZE, stride);\
  174. put_h264_qpel ## SIZE ## _hv_lowpass_ ## CODETYPE(halfHV, tmp, src, SIZE, SIZE, stride);\
  175. OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfV, halfHV, stride, SIZE, SIZE);\
  176. }\
  177. \
  178. static void OPNAME ## h264_qpel ## SIZE ## _mc32_ ## CODETYPE(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
  179. {\
  180. DECLARE_ALIGNED(16, uint8_t, halfV)[SIZE*SIZE];\
  181. DECLARE_ALIGNED(16, uint8_t, halfHV)[SIZE*SIZE];\
  182. DECLARE_ALIGNED(16, int16_t, tmp)[SIZE*(SIZE+8)];\
  183. put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(halfV, src+1, SIZE, stride);\
  184. put_h264_qpel ## SIZE ## _hv_lowpass_ ## CODETYPE(halfHV, tmp, src, SIZE, SIZE, stride);\
  185. OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfV, halfHV, stride, SIZE, SIZE);\
  186. }\
  187. static inline void put_pixels16_l2_altivec( uint8_t * dst, const uint8_t * src1,
  188. const uint8_t * src2, int dst_stride,
  189. int src_stride1, int h)
  190. {
  191. int i;
  192. vec_u8 a, b, d, tmp1, tmp2, mask, mask_, edges, align;
  193. mask_ = vec_lvsl(0, src2);
  194. for (i = 0; i < h; i++) {
  195. tmp1 = vec_ld(i * src_stride1, src1);
  196. mask = vec_lvsl(i * src_stride1, src1);
  197. tmp2 = vec_ld(i * src_stride1 + 15, src1);
  198. a = vec_perm(tmp1, tmp2, mask);
  199. tmp1 = vec_ld(i * 16, src2);
  200. tmp2 = vec_ld(i * 16 + 15, src2);
  201. b = vec_perm(tmp1, tmp2, mask_);
  202. tmp1 = vec_ld(0, dst);
  203. mask = vec_lvsl(0, dst);
  204. tmp2 = vec_ld(15, dst);
  205. d = vec_avg(a, b);
  206. edges = vec_perm(tmp2, tmp1, mask);
  207. align = vec_lvsr(0, dst);
  208. tmp2 = vec_perm(d, edges, align);
  209. tmp1 = vec_perm(edges, d, align);
  210. vec_st(tmp2, 15, dst);
  211. vec_st(tmp1, 0 , dst);
  212. dst += dst_stride;
  213. }
  214. }
  215. static inline void avg_pixels16_l2_altivec( uint8_t * dst, const uint8_t * src1,
  216. const uint8_t * src2, int dst_stride,
  217. int src_stride1, int h)
  218. {
  219. int i;
  220. vec_u8 a, b, d, tmp1, tmp2, mask, mask_, edges, align;
  221. mask_ = vec_lvsl(0, src2);
  222. for (i = 0; i < h; i++) {
  223. tmp1 = vec_ld(i * src_stride1, src1);
  224. mask = vec_lvsl(i * src_stride1, src1);
  225. tmp2 = vec_ld(i * src_stride1 + 15, src1);
  226. a = vec_perm(tmp1, tmp2, mask);
  227. tmp1 = vec_ld(i * 16, src2);
  228. tmp2 = vec_ld(i * 16 + 15, src2);
  229. b = vec_perm(tmp1, tmp2, mask_);
  230. tmp1 = vec_ld(0, dst);
  231. mask = vec_lvsl(0, dst);
  232. tmp2 = vec_ld(15, dst);
  233. d = vec_avg(vec_perm(tmp1, tmp2, mask), vec_avg(a, b));
  234. edges = vec_perm(tmp2, tmp1, mask);
  235. align = vec_lvsr(0, dst);
  236. tmp2 = vec_perm(d, edges, align);
  237. tmp1 = vec_perm(edges, d, align);
  238. vec_st(tmp2, 15, dst);
  239. vec_st(tmp1, 0 , dst);
  240. dst += dst_stride;
  241. }
  242. }
  243. /* Implemented but could be faster
  244. #define put_pixels16_l2_altivec(d,s1,s2,ds,s1s,h) put_pixels16_l2(d,s1,s2,ds,s1s,16,h)
  245. #define avg_pixels16_l2_altivec(d,s1,s2,ds,s1s,h) avg_pixels16_l2(d,s1,s2,ds,s1s,16,h)
  246. */
  247. H264_MC(put_, 16, altivec)
  248. H264_MC(avg_, 16, altivec)
  249. #endif /* HAVE_ALTIVEC */
  250. av_cold void ff_h264qpel_init_ppc(H264QpelContext *c, int bit_depth)
  251. {
  252. #if HAVE_ALTIVEC && HAVE_BIGENDIAN
  253. const int high_bit_depth = bit_depth > 8;
  254. if (!PPC_ALTIVEC(av_get_cpu_flags()))
  255. return;
  256. if (!high_bit_depth) {
  257. #define dspfunc(PFX, IDX, NUM) \
  258. c->PFX ## _pixels_tab[IDX][ 0] = PFX ## NUM ## _mc00_altivec; \
  259. c->PFX ## _pixels_tab[IDX][ 1] = PFX ## NUM ## _mc10_altivec; \
  260. c->PFX ## _pixels_tab[IDX][ 2] = PFX ## NUM ## _mc20_altivec; \
  261. c->PFX ## _pixels_tab[IDX][ 3] = PFX ## NUM ## _mc30_altivec; \
  262. c->PFX ## _pixels_tab[IDX][ 4] = PFX ## NUM ## _mc01_altivec; \
  263. c->PFX ## _pixels_tab[IDX][ 5] = PFX ## NUM ## _mc11_altivec; \
  264. c->PFX ## _pixels_tab[IDX][ 6] = PFX ## NUM ## _mc21_altivec; \
  265. c->PFX ## _pixels_tab[IDX][ 7] = PFX ## NUM ## _mc31_altivec; \
  266. c->PFX ## _pixels_tab[IDX][ 8] = PFX ## NUM ## _mc02_altivec; \
  267. c->PFX ## _pixels_tab[IDX][ 9] = PFX ## NUM ## _mc12_altivec; \
  268. c->PFX ## _pixels_tab[IDX][10] = PFX ## NUM ## _mc22_altivec; \
  269. c->PFX ## _pixels_tab[IDX][11] = PFX ## NUM ## _mc32_altivec; \
  270. c->PFX ## _pixels_tab[IDX][12] = PFX ## NUM ## _mc03_altivec; \
  271. c->PFX ## _pixels_tab[IDX][13] = PFX ## NUM ## _mc13_altivec; \
  272. c->PFX ## _pixels_tab[IDX][14] = PFX ## NUM ## _mc23_altivec; \
  273. c->PFX ## _pixels_tab[IDX][15] = PFX ## NUM ## _mc33_altivec
  274. dspfunc(put_h264_qpel, 0, 16);
  275. dspfunc(avg_h264_qpel, 0, 16);
  276. #undef dspfunc
  277. }
  278. #endif /* HAVE_ALTIVEC */
  279. }