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
14KB

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