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