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.

283 lines
16KB

  1. /*
  2. * Copyright (c) 2010 Jason Garrett-Glaser
  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 "libavutil/cpu.h"
  21. #include "libavcodec/h264pred.h"
  22. #define PRED4x4(TYPE, DEPTH, OPT) \
  23. void ff_pred4x4_ ## TYPE ## _ ## DEPTH ## _ ## OPT (uint8_t *src, const uint8_t *topright, int stride);
  24. PRED4x4(dc, 10, mmxext)
  25. PRED4x4(down_left, 10, sse2)
  26. PRED4x4(down_left, 10, avx)
  27. PRED4x4(down_right, 10, sse2)
  28. PRED4x4(down_right, 10, ssse3)
  29. PRED4x4(down_right, 10, avx)
  30. PRED4x4(vertical_left, 10, sse2)
  31. PRED4x4(vertical_left, 10, avx)
  32. PRED4x4(vertical_right, 10, sse2)
  33. PRED4x4(vertical_right, 10, ssse3)
  34. PRED4x4(vertical_right, 10, avx)
  35. PRED4x4(horizontal_up, 10, mmxext)
  36. PRED4x4(horizontal_down, 10, sse2)
  37. PRED4x4(horizontal_down, 10, ssse3)
  38. PRED4x4(horizontal_down, 10, avx)
  39. #define PRED8x8(TYPE, DEPTH, OPT) \
  40. void ff_pred8x8_ ## TYPE ## _ ## DEPTH ## _ ## OPT (uint8_t *src, int stride);
  41. PRED8x8(vertical, 10, sse2)
  42. PRED8x8(horizontal, 10, sse2)
  43. void ff_pred16x16_vertical_mmx (uint8_t *src, int stride);
  44. void ff_pred16x16_vertical_sse (uint8_t *src, int stride);
  45. void ff_pred16x16_horizontal_mmx (uint8_t *src, int stride);
  46. void ff_pred16x16_horizontal_mmxext(uint8_t *src, int stride);
  47. void ff_pred16x16_horizontal_ssse3 (uint8_t *src, int stride);
  48. void ff_pred16x16_dc_mmxext (uint8_t *src, int stride);
  49. void ff_pred16x16_dc_sse2 (uint8_t *src, int stride);
  50. void ff_pred16x16_dc_ssse3 (uint8_t *src, int stride);
  51. void ff_pred16x16_plane_h264_mmx (uint8_t *src, int stride);
  52. void ff_pred16x16_plane_h264_mmx2 (uint8_t *src, int stride);
  53. void ff_pred16x16_plane_h264_sse2 (uint8_t *src, int stride);
  54. void ff_pred16x16_plane_h264_ssse3 (uint8_t *src, int stride);
  55. void ff_pred16x16_plane_rv40_mmx (uint8_t *src, int stride);
  56. void ff_pred16x16_plane_rv40_mmx2 (uint8_t *src, int stride);
  57. void ff_pred16x16_plane_rv40_sse2 (uint8_t *src, int stride);
  58. void ff_pred16x16_plane_rv40_ssse3 (uint8_t *src, int stride);
  59. void ff_pred16x16_plane_svq3_mmx (uint8_t *src, int stride);
  60. void ff_pred16x16_plane_svq3_mmx2 (uint8_t *src, int stride);
  61. void ff_pred16x16_plane_svq3_sse2 (uint8_t *src, int stride);
  62. void ff_pred16x16_plane_svq3_ssse3 (uint8_t *src, int stride);
  63. void ff_pred16x16_tm_vp8_mmx (uint8_t *src, int stride);
  64. void ff_pred16x16_tm_vp8_mmxext (uint8_t *src, int stride);
  65. void ff_pred16x16_tm_vp8_sse2 (uint8_t *src, int stride);
  66. void ff_pred8x8_top_dc_mmxext (uint8_t *src, int stride);
  67. void ff_pred8x8_dc_rv40_mmxext (uint8_t *src, int stride);
  68. void ff_pred8x8_dc_mmxext (uint8_t *src, int stride);
  69. void ff_pred8x8_vertical_mmx (uint8_t *src, int stride);
  70. void ff_pred8x8_horizontal_mmx (uint8_t *src, int stride);
  71. void ff_pred8x8_horizontal_mmxext (uint8_t *src, int stride);
  72. void ff_pred8x8_horizontal_ssse3 (uint8_t *src, int stride);
  73. void ff_pred8x8_plane_mmx (uint8_t *src, int stride);
  74. void ff_pred8x8_plane_mmx2 (uint8_t *src, int stride);
  75. void ff_pred8x8_plane_sse2 (uint8_t *src, int stride);
  76. void ff_pred8x8_plane_ssse3 (uint8_t *src, int stride);
  77. void ff_pred8x8_tm_vp8_mmx (uint8_t *src, int stride);
  78. void ff_pred8x8_tm_vp8_mmxext (uint8_t *src, int stride);
  79. void ff_pred8x8_tm_vp8_sse2 (uint8_t *src, int stride);
  80. void ff_pred8x8_tm_vp8_ssse3 (uint8_t *src, int stride);
  81. void ff_pred8x8l_top_dc_mmxext (uint8_t *src, int has_topleft, int has_topright, int stride);
  82. void ff_pred8x8l_top_dc_ssse3 (uint8_t *src, int has_topleft, int has_topright, int stride);
  83. void ff_pred8x8l_dc_mmxext (uint8_t *src, int has_topleft, int has_topright, int stride);
  84. void ff_pred8x8l_dc_ssse3 (uint8_t *src, int has_topleft, int has_topright, int stride);
  85. void ff_pred8x8l_horizontal_mmxext (uint8_t *src, int has_topleft, int has_topright, int stride);
  86. void ff_pred8x8l_horizontal_ssse3 (uint8_t *src, int has_topleft, int has_topright, int stride);
  87. void ff_pred8x8l_vertical_mmxext (uint8_t *src, int has_topleft, int has_topright, int stride);
  88. void ff_pred8x8l_vertical_ssse3 (uint8_t *src, int has_topleft, int has_topright, int stride);
  89. void ff_pred8x8l_down_left_mmxext (uint8_t *src, int has_topleft, int has_topright, int stride);
  90. void ff_pred8x8l_down_left_sse2 (uint8_t *src, int has_topleft, int has_topright, int stride);
  91. void ff_pred8x8l_down_left_ssse3 (uint8_t *src, int has_topleft, int has_topright, int stride);
  92. void ff_pred8x8l_down_right_mmxext (uint8_t *src, int has_topleft, int has_topright, int stride);
  93. void ff_pred8x8l_down_right_sse2 (uint8_t *src, int has_topleft, int has_topright, int stride);
  94. void ff_pred8x8l_down_right_ssse3 (uint8_t *src, int has_topleft, int has_topright, int stride);
  95. void ff_pred8x8l_vertical_right_mmxext(uint8_t *src, int has_topleft, int has_topright, int stride);
  96. void ff_pred8x8l_vertical_right_sse2(uint8_t *src, int has_topleft, int has_topright, int stride);
  97. void ff_pred8x8l_vertical_right_ssse3(uint8_t *src, int has_topleft, int has_topright, int stride);
  98. void ff_pred8x8l_vertical_left_sse2(uint8_t *src, int has_topleft, int has_topright, int stride);
  99. void ff_pred8x8l_vertical_left_ssse3(uint8_t *src, int has_topleft, int has_topright, int stride);
  100. void ff_pred8x8l_horizontal_up_mmxext(uint8_t *src, int has_topleft, int has_topright, int stride);
  101. void ff_pred8x8l_horizontal_up_ssse3(uint8_t *src, int has_topleft, int has_topright, int stride);
  102. void ff_pred8x8l_horizontal_down_mmxext(uint8_t *src, int has_topleft, int has_topright, int stride);
  103. void ff_pred8x8l_horizontal_down_sse2(uint8_t *src, int has_topleft, int has_topright, int stride);
  104. void ff_pred8x8l_horizontal_down_ssse3(uint8_t *src, int has_topleft, int has_topright, int stride);
  105. void ff_pred4x4_dc_mmxext (uint8_t *src, const uint8_t *topright, int stride);
  106. void ff_pred4x4_down_left_mmxext (uint8_t *src, const uint8_t *topright, int stride);
  107. void ff_pred4x4_down_right_mmxext (uint8_t *src, const uint8_t *topright, int stride);
  108. void ff_pred4x4_vertical_left_mmxext(uint8_t *src, const uint8_t *topright, int stride);
  109. void ff_pred4x4_vertical_right_mmxext(uint8_t *src, const uint8_t *topright, int stride);
  110. void ff_pred4x4_horizontal_up_mmxext(uint8_t *src, const uint8_t *topright, int stride);
  111. void ff_pred4x4_horizontal_down_mmxext(uint8_t *src, const uint8_t *topright, int stride);
  112. void ff_pred4x4_tm_vp8_mmx (uint8_t *src, const uint8_t *topright, int stride);
  113. void ff_pred4x4_tm_vp8_mmxext (uint8_t *src, const uint8_t *topright, int stride);
  114. void ff_pred4x4_tm_vp8_ssse3 (uint8_t *src, const uint8_t *topright, int stride);
  115. void ff_pred4x4_vertical_vp8_mmxext(uint8_t *src, const uint8_t *topright, int stride);
  116. void ff_h264_pred_init_x86(H264PredContext *h, int codec_id, const int bit_depth)
  117. {
  118. int mm_flags = av_get_cpu_flags();
  119. #if HAVE_YASM
  120. if (bit_depth == 8) {
  121. if (mm_flags & AV_CPU_FLAG_MMX) {
  122. h->pred16x16[VERT_PRED8x8 ] = ff_pred16x16_vertical_mmx;
  123. h->pred16x16[HOR_PRED8x8 ] = ff_pred16x16_horizontal_mmx;
  124. h->pred8x8 [VERT_PRED8x8 ] = ff_pred8x8_vertical_mmx;
  125. h->pred8x8 [HOR_PRED8x8 ] = ff_pred8x8_horizontal_mmx;
  126. if (codec_id == CODEC_ID_VP8) {
  127. h->pred16x16[PLANE_PRED8x8 ] = ff_pred16x16_tm_vp8_mmx;
  128. h->pred8x8 [PLANE_PRED8x8 ] = ff_pred8x8_tm_vp8_mmx;
  129. h->pred4x4 [TM_VP8_PRED ] = ff_pred4x4_tm_vp8_mmx;
  130. } else {
  131. h->pred8x8 [PLANE_PRED8x8] = ff_pred8x8_plane_mmx;
  132. if (codec_id == CODEC_ID_SVQ3) {
  133. h->pred16x16[PLANE_PRED8x8] = ff_pred16x16_plane_svq3_mmx;
  134. } else if (codec_id == CODEC_ID_RV40) {
  135. h->pred16x16[PLANE_PRED8x8] = ff_pred16x16_plane_rv40_mmx;
  136. } else {
  137. h->pred16x16[PLANE_PRED8x8] = ff_pred16x16_plane_h264_mmx;
  138. }
  139. }
  140. }
  141. if (mm_flags & AV_CPU_FLAG_MMX2) {
  142. h->pred16x16[HOR_PRED8x8 ] = ff_pred16x16_horizontal_mmxext;
  143. h->pred16x16[DC_PRED8x8 ] = ff_pred16x16_dc_mmxext;
  144. h->pred8x8 [HOR_PRED8x8 ] = ff_pred8x8_horizontal_mmxext;
  145. h->pred8x8l [TOP_DC_PRED ] = ff_pred8x8l_top_dc_mmxext;
  146. h->pred8x8l [DC_PRED ] = ff_pred8x8l_dc_mmxext;
  147. h->pred8x8l [HOR_PRED ] = ff_pred8x8l_horizontal_mmxext;
  148. h->pred8x8l [VERT_PRED ] = ff_pred8x8l_vertical_mmxext;
  149. h->pred8x8l [DIAG_DOWN_RIGHT_PRED ] = ff_pred8x8l_down_right_mmxext;
  150. h->pred8x8l [VERT_RIGHT_PRED ] = ff_pred8x8l_vertical_right_mmxext;
  151. h->pred8x8l [HOR_UP_PRED ] = ff_pred8x8l_horizontal_up_mmxext;
  152. h->pred8x8l [DIAG_DOWN_LEFT_PRED ] = ff_pred8x8l_down_left_mmxext;
  153. h->pred8x8l [HOR_DOWN_PRED ] = ff_pred8x8l_horizontal_down_mmxext;
  154. h->pred4x4 [DIAG_DOWN_RIGHT_PRED ] = ff_pred4x4_down_right_mmxext;
  155. h->pred4x4 [VERT_RIGHT_PRED ] = ff_pred4x4_vertical_right_mmxext;
  156. h->pred4x4 [HOR_DOWN_PRED ] = ff_pred4x4_horizontal_down_mmxext;
  157. h->pred4x4 [DC_PRED ] = ff_pred4x4_dc_mmxext;
  158. if (codec_id == CODEC_ID_VP8 || codec_id == CODEC_ID_H264) {
  159. h->pred4x4 [DIAG_DOWN_LEFT_PRED] = ff_pred4x4_down_left_mmxext;
  160. }
  161. if (codec_id == CODEC_ID_SVQ3 || codec_id == CODEC_ID_H264) {
  162. h->pred4x4 [VERT_LEFT_PRED ] = ff_pred4x4_vertical_left_mmxext;
  163. }
  164. if (codec_id != CODEC_ID_RV40) {
  165. h->pred4x4 [HOR_UP_PRED ] = ff_pred4x4_horizontal_up_mmxext;
  166. }
  167. if (codec_id == CODEC_ID_SVQ3 || codec_id == CODEC_ID_H264) {
  168. h->pred8x8 [TOP_DC_PRED8x8 ] = ff_pred8x8_top_dc_mmxext;
  169. h->pred8x8 [DC_PRED8x8 ] = ff_pred8x8_dc_mmxext;
  170. }
  171. if (codec_id == CODEC_ID_VP8) {
  172. h->pred16x16[PLANE_PRED8x8 ] = ff_pred16x16_tm_vp8_mmxext;
  173. h->pred8x8 [DC_PRED8x8 ] = ff_pred8x8_dc_rv40_mmxext;
  174. h->pred8x8 [PLANE_PRED8x8 ] = ff_pred8x8_tm_vp8_mmxext;
  175. h->pred4x4 [TM_VP8_PRED ] = ff_pred4x4_tm_vp8_mmxext;
  176. h->pred4x4 [VERT_PRED ] = ff_pred4x4_vertical_vp8_mmxext;
  177. } else {
  178. h->pred8x8 [PLANE_PRED8x8] = ff_pred8x8_plane_mmx2;
  179. if (codec_id == CODEC_ID_SVQ3) {
  180. h->pred16x16[PLANE_PRED8x8 ] = ff_pred16x16_plane_svq3_mmx2;
  181. } else if (codec_id == CODEC_ID_RV40) {
  182. h->pred16x16[PLANE_PRED8x8 ] = ff_pred16x16_plane_rv40_mmx2;
  183. } else {
  184. h->pred16x16[PLANE_PRED8x8 ] = ff_pred16x16_plane_h264_mmx2;
  185. }
  186. }
  187. }
  188. if (mm_flags & AV_CPU_FLAG_SSE) {
  189. h->pred16x16[VERT_PRED8x8] = ff_pred16x16_vertical_sse;
  190. }
  191. if (mm_flags & AV_CPU_FLAG_SSE2) {
  192. h->pred16x16[DC_PRED8x8 ] = ff_pred16x16_dc_sse2;
  193. h->pred8x8l [DIAG_DOWN_LEFT_PRED ] = ff_pred8x8l_down_left_sse2;
  194. h->pred8x8l [DIAG_DOWN_RIGHT_PRED ] = ff_pred8x8l_down_right_sse2;
  195. h->pred8x8l [VERT_RIGHT_PRED ] = ff_pred8x8l_vertical_right_sse2;
  196. h->pred8x8l [VERT_LEFT_PRED ] = ff_pred8x8l_vertical_left_sse2;
  197. h->pred8x8l [HOR_DOWN_PRED ] = ff_pred8x8l_horizontal_down_sse2;
  198. if (codec_id == CODEC_ID_VP8) {
  199. h->pred16x16[PLANE_PRED8x8 ] = ff_pred16x16_tm_vp8_sse2;
  200. h->pred8x8 [PLANE_PRED8x8 ] = ff_pred8x8_tm_vp8_sse2;
  201. } else {
  202. h->pred8x8 [PLANE_PRED8x8 ] = ff_pred8x8_plane_sse2;
  203. if (codec_id == CODEC_ID_SVQ3) {
  204. h->pred16x16[PLANE_PRED8x8] = ff_pred16x16_plane_svq3_sse2;
  205. } else if (codec_id == CODEC_ID_RV40) {
  206. h->pred16x16[PLANE_PRED8x8] = ff_pred16x16_plane_rv40_sse2;
  207. } else {
  208. h->pred16x16[PLANE_PRED8x8] = ff_pred16x16_plane_h264_sse2;
  209. }
  210. }
  211. }
  212. if (mm_flags & AV_CPU_FLAG_SSSE3) {
  213. h->pred16x16[HOR_PRED8x8 ] = ff_pred16x16_horizontal_ssse3;
  214. h->pred16x16[DC_PRED8x8 ] = ff_pred16x16_dc_ssse3;
  215. h->pred8x8 [HOR_PRED8x8 ] = ff_pred8x8_horizontal_ssse3;
  216. h->pred8x8l [TOP_DC_PRED ] = ff_pred8x8l_top_dc_ssse3;
  217. h->pred8x8l [DC_PRED ] = ff_pred8x8l_dc_ssse3;
  218. h->pred8x8l [HOR_PRED ] = ff_pred8x8l_horizontal_ssse3;
  219. h->pred8x8l [VERT_PRED ] = ff_pred8x8l_vertical_ssse3;
  220. h->pred8x8l [DIAG_DOWN_LEFT_PRED ] = ff_pred8x8l_down_left_ssse3;
  221. h->pred8x8l [DIAG_DOWN_RIGHT_PRED ] = ff_pred8x8l_down_right_ssse3;
  222. h->pred8x8l [VERT_RIGHT_PRED ] = ff_pred8x8l_vertical_right_ssse3;
  223. h->pred8x8l [VERT_LEFT_PRED ] = ff_pred8x8l_vertical_left_ssse3;
  224. h->pred8x8l [HOR_UP_PRED ] = ff_pred8x8l_horizontal_up_ssse3;
  225. h->pred8x8l [HOR_DOWN_PRED ] = ff_pred8x8l_horizontal_down_ssse3;
  226. if (codec_id == CODEC_ID_VP8) {
  227. h->pred8x8 [PLANE_PRED8x8 ] = ff_pred8x8_tm_vp8_ssse3;
  228. h->pred4x4 [TM_VP8_PRED ] = ff_pred4x4_tm_vp8_ssse3;
  229. } else {
  230. h->pred8x8 [PLANE_PRED8x8] = ff_pred8x8_plane_ssse3;
  231. if (codec_id == CODEC_ID_SVQ3) {
  232. h->pred16x16[PLANE_PRED8x8] = ff_pred16x16_plane_svq3_ssse3;
  233. } else if (codec_id == CODEC_ID_RV40) {
  234. h->pred16x16[PLANE_PRED8x8] = ff_pred16x16_plane_rv40_ssse3;
  235. } else {
  236. h->pred16x16[PLANE_PRED8x8] = ff_pred16x16_plane_h264_ssse3;
  237. }
  238. }
  239. }
  240. } else if (bit_depth == 10) {
  241. if (mm_flags & AV_CPU_FLAG_MMX2) {
  242. h->pred4x4[DC_PRED ] = ff_pred4x4_dc_10_mmxext;
  243. h->pred4x4[HOR_UP_PRED ] = ff_pred4x4_horizontal_up_10_mmxext;
  244. }
  245. if (mm_flags & AV_CPU_FLAG_SSE2) {
  246. h->pred4x4[DIAG_DOWN_LEFT_PRED ] = ff_pred4x4_down_left_10_sse2;
  247. h->pred4x4[DIAG_DOWN_RIGHT_PRED] = ff_pred4x4_down_right_10_sse2;
  248. h->pred4x4[VERT_LEFT_PRED ] = ff_pred4x4_vertical_left_10_sse2;
  249. h->pred4x4[VERT_RIGHT_PRED ] = ff_pred4x4_vertical_right_10_sse2;
  250. h->pred4x4[HOR_DOWN_PRED ] = ff_pred4x4_horizontal_down_10_sse2;
  251. h->pred8x8[VERT_PRED8x8 ] = ff_pred8x8_vertical_10_sse2;
  252. h->pred8x8[HOR_PRED8x8 ] = ff_pred8x8_horizontal_10_sse2;
  253. }
  254. if (mm_flags & AV_CPU_FLAG_SSSE3) {
  255. h->pred4x4[DIAG_DOWN_RIGHT_PRED] = ff_pred4x4_down_right_10_ssse3;
  256. h->pred4x4[VERT_RIGHT_PRED ] = ff_pred4x4_vertical_right_10_ssse3;
  257. h->pred4x4[HOR_DOWN_PRED ] = ff_pred4x4_horizontal_down_10_ssse3;
  258. }
  259. #if HAVE_AVX
  260. if (mm_flags & AV_CPU_FLAG_AVX) {
  261. h->pred4x4[DIAG_DOWN_LEFT_PRED ] = ff_pred4x4_down_left_10_avx;
  262. h->pred4x4[DIAG_DOWN_RIGHT_PRED] = ff_pred4x4_down_right_10_avx;
  263. h->pred4x4[VERT_RIGHT_PRED ] = ff_pred4x4_vertical_right_10_avx;
  264. h->pred4x4[HOR_DOWN_PRED ] = ff_pred4x4_horizontal_down_10_avx;
  265. }
  266. #endif /* HAVE_AVX */
  267. }
  268. #endif /* HAVE_YASM */
  269. }