75a74ab62c1e3a73ca1f9040e5ae737951098958
[x264/x264-sandbox.git] / common / x86 / predict-c.c
1 /*****************************************************************************
2  * predict-c.c: intra prediction
3  *****************************************************************************
4  * Copyright (C) 2003-2013 x264 project
5  *
6  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
7  *          Loren Merritt <lorenm@u.washington.edu>
8  *          Fiona Glaser <fiona@x264.com>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111, USA.
23  *
24  * This program is also available under a commercial proprietary license.
25  * For more information, contact us at licensing@x264.com.
26  *****************************************************************************/
27
28 #include "common/common.h"
29 #include "predict.h"
30 #include "pixel.h"
31
32 #define PREDICT_16x16_DC(name)\
33 void x264_predict_16x16_dc_##name( pixel *src )\
34 {\
35     uint32_t dc = 16;\
36     for( int i = 0; i < 16; i += 2 )\
37     {\
38         dc += src[-1 + i * FDEC_STRIDE];\
39         dc += src[-1 + (i+1) * FDEC_STRIDE];\
40     }\
41     x264_predict_16x16_dc_core_##name( src, dc );\
42 }
43
44 PREDICT_16x16_DC( mmx2 )
45 PREDICT_16x16_DC( sse2 )
46
47 #define PREDICT_16x16_DC_LEFT(name)\
48 static void x264_predict_16x16_dc_left_##name( pixel *src )\
49 {\
50     uint32_t dc = 8;\
51     for( int i = 0; i < 16; i += 2 )\
52     {\
53         dc += src[-1 + i * FDEC_STRIDE];\
54         dc += src[-1 + (i+1) * FDEC_STRIDE];\
55     }\
56     x264_predict_16x16_dc_left_core_##name( src, dc>>4 );\
57 }
58
59 PREDICT_16x16_DC_LEFT( mmx2 )
60 PREDICT_16x16_DC_LEFT( sse2 )
61
62 #define PREDICT_P_SUM(j,i)\
63     H += i * ( src[j+i - FDEC_STRIDE ]  - src[j-i - FDEC_STRIDE ] );\
64     V += i * ( src[(j+i)*FDEC_STRIDE -1] - src[(j-i)*FDEC_STRIDE -1] );\
65
66 ALIGNED_16( static const int16_t pw_12345678[8] ) = {1,2,3,4,5,6,7,8};
67 ALIGNED_16( static const int16_t pw_m87654321[8] ) = {-8,-7,-6,-5,-4,-3,-2,-1};
68 ALIGNED_16( static const int16_t pw_m32101234[8] ) = {-3,-2,-1,0,1,2,3,4};
69 ALIGNED_8( static const int8_t pb_12345678[8] ) = {1,2,3,4,5,6,7,8};
70 ALIGNED_8( static const int8_t pb_m87654321[8] ) = {-8,-7,-6,-5,-4,-3,-2,-1};
71 ALIGNED_8( static const int8_t pb_m32101234[8] ) = {-3,-2,-1,0,1,2,3,4};
72
73 #if !HIGH_BIT_DEPTH
74 #define PREDICT_16x16_P(name)\
75 static void x264_predict_16x16_p_##name( pixel *src )\
76 {\
77     int a, b, c;\
78     int H = 0;\
79     int V = 0;\
80     int i00;\
81     PREDICT_P_SUM(7,1) \
82     PREDICT_P_SUM(7,2) \
83     PREDICT_P_SUM(7,3) \
84     PREDICT_P_SUM(7,4) \
85     PREDICT_P_SUM(7,5) \
86     PREDICT_P_SUM(7,6) \
87     PREDICT_P_SUM(7,7) \
88     PREDICT_P_SUM(7,8) \
89     a = 16 * ( src[15*FDEC_STRIDE -1] + src[15 - FDEC_STRIDE] );\
90     b = ( 5 * H + 32 ) >> 6;\
91     c = ( 5 * V + 32 ) >> 6;\
92     i00 = a - b * 7 - c * 7 + 16;\
93     x264_predict_16x16_p_core_##name( src, i00, b, c );\
94 }
95 #ifndef ARCH_X86_64
96 PREDICT_16x16_P( mmx2 )
97 #endif
98 PREDICT_16x16_P( sse2   )
99 PREDICT_16x16_P( avx    )
100 #endif //!HIGH_BIT_DEPTH
101
102 #define PREDICT_8x16C_P_CORE \
103     int H = 0, V = 0;\
104     for( int i = 0; i < 4; i++ )\
105         H += ( i + 1 ) * ( src[4 + i - FDEC_STRIDE] - src[2 - i - FDEC_STRIDE] );\
106     for( int i = 0; i < 8; i++ )\
107         V += ( i + 1 ) * ( src[-1 + (i+8)*FDEC_STRIDE] - src[-1 + (6-i)*FDEC_STRIDE] );\
108     int a = 16 * ( src[-1 + 15*FDEC_STRIDE] + src[7 - FDEC_STRIDE] );\
109     int b = ( 17 * H + 16 ) >> 5;\
110     int c = ( 5 * V + 32 ) >> 6;
111
112 #if HIGH_BIT_DEPTH
113 #define PREDICT_8x16_P(name)\
114 static void x264_predict_8x16c_p_##name( uint16_t *src )\
115 {\
116     PREDICT_8x16C_P_CORE \
117     x264_predict_8x16c_p_core_##name( src, a, b, c );\
118 }
119
120 PREDICT_8x16_P(sse2)
121 PREDICT_8x16_P(avx)
122 #else
123 #define PREDICT_8x16_P(name)\
124 static void x264_predict_8x16c_p_##name( uint8_t *src )\
125 {\
126     PREDICT_8x16C_P_CORE \
127     int i00 = a -3*b -7*c + 16;\
128     x264_predict_8x16c_p_core_##name( src, i00, b, c );\
129 }
130 #ifndef ARCH_X86_64
131 PREDICT_8x16_P(mmx2)
132 #endif
133 PREDICT_8x16_P(sse2)
134 PREDICT_8x16_P(avx)
135 #endif
136
137 #if HAVE_X86_INLINE_ASM
138 #if HIGH_BIT_DEPTH
139 static void x264_predict_16x16_p_sse2( uint16_t *src )
140 #else
141 static void x264_predict_16x16_p_ssse3( uint8_t *src )
142 #endif
143 {
144     int a, b, c, i00;
145     int H, V;
146 #if HIGH_BIT_DEPTH
147     asm (
148         "movdqu           %1, %%xmm1 \n"
149         "movdqa           %2, %%xmm0 \n"
150         "pmaddwd          %3, %%xmm0 \n"
151         "pmaddwd          %4, %%xmm1 \n"
152         "paddd        %%xmm1, %%xmm0 \n"
153         "movhlps      %%xmm0, %%xmm1 \n"
154         "paddd        %%xmm1, %%xmm0 \n"
155         "pshuflw $14, %%xmm0, %%xmm1 \n"
156         "paddd        %%xmm1, %%xmm0 \n"
157         "movd         %%xmm0, %0     \n"
158         :"=r"(H)
159         :"m"(src[-FDEC_STRIDE-1]), "m"(src[-FDEC_STRIDE+8]),
160          "m"(*pw_12345678), "m"(*pw_m87654321)
161     );
162 #else
163     asm (
164         "movq           %1, %%mm1 \n"
165         "movq           %2, %%mm0 \n"
166         "palignr $7,    %3, %%mm1 \n"
167         "pmaddubsw      %4, %%mm0 \n"
168         "pmaddubsw      %5, %%mm1 \n"
169         "paddw       %%mm1, %%mm0 \n"
170         "pshufw $14, %%mm0, %%mm1 \n"
171         "paddw       %%mm1, %%mm0 \n"
172         "pshufw  $1, %%mm0, %%mm1 \n"
173         "paddw       %%mm1, %%mm0 \n"
174         "movd        %%mm0, %0    \n"
175         "movswl        %w0, %0    \n"
176         :"=r"(H)
177         :"m"(src[-FDEC_STRIDE]), "m"(src[-FDEC_STRIDE+8]),
178          "m"(src[-FDEC_STRIDE-8]), "m"(*pb_12345678), "m"(*pb_m87654321)
179     );
180 #endif
181     V = 8 * ( src[15*FDEC_STRIDE-1] - src[-1*FDEC_STRIDE-1] )
182       + 7 * ( src[14*FDEC_STRIDE-1] - src[ 0*FDEC_STRIDE-1] )
183       + 6 * ( src[13*FDEC_STRIDE-1] - src[ 1*FDEC_STRIDE-1] )
184       + 5 * ( src[12*FDEC_STRIDE-1] - src[ 2*FDEC_STRIDE-1] )
185       + 4 * ( src[11*FDEC_STRIDE-1] - src[ 3*FDEC_STRIDE-1] )
186       + 3 * ( src[10*FDEC_STRIDE-1] - src[ 4*FDEC_STRIDE-1] )
187       + 2 * ( src[ 9*FDEC_STRIDE-1] - src[ 5*FDEC_STRIDE-1] )
188       + 1 * ( src[ 8*FDEC_STRIDE-1] - src[ 6*FDEC_STRIDE-1] );
189     a = 16 * ( src[15*FDEC_STRIDE -1] + src[15 - FDEC_STRIDE] );
190     b = ( 5 * H + 32 ) >> 6;
191     c = ( 5 * V + 32 ) >> 6;
192     i00 = a - b * 7 - c * 7 + 16;
193     /* b*15 + c*15 can overflow: it's easier to just branch away in this rare case
194      * than to try to consider it in the asm. */
195     if( BIT_DEPTH > 8 && (i00 > 0x7fff || abs(b) > 1092 || abs(c) > 1092) )
196         x264_predict_16x16_p_c( src );
197     else
198         x264_predict_16x16_p_core_sse2( src, i00, b, c );
199 }
200 #endif
201
202 #if !HIGH_BIT_DEPTH
203
204 #define PREDICT_8x8_P(name)\
205 static void x264_predict_8x8c_p_##name( uint8_t *src )\
206 {\
207     int a, b, c;\
208     int H = 0;\
209     int V = 0;\
210     int i00;\
211     PREDICT_P_SUM(3,1)\
212     PREDICT_P_SUM(3,2)\
213     PREDICT_P_SUM(3,3)\
214     PREDICT_P_SUM(3,4)\
215     a = 16 * ( src[7*FDEC_STRIDE -1] + src[7 - FDEC_STRIDE] );\
216     b = ( 17 * H + 16 ) >> 5;\
217     c = ( 17 * V + 16 ) >> 5;\
218     i00 = a -3*b -3*c + 16;\
219     x264_predict_8x8c_p_core_##name( src, i00, b, c );\
220 }
221 #ifndef ARCH_X86_64
222 PREDICT_8x8_P( mmx2 )
223 #endif
224 PREDICT_8x8_P( sse2   )
225
226 #endif //!HIGH_BIT_DEPTH
227
228 #if HAVE_X86_INLINE_ASM
229
230 #define PREDICT_8x8C_P_CORE\
231     V = 1 * ( src[4*FDEC_STRIDE -1] - src[ 2*FDEC_STRIDE -1] )\
232       + 2 * ( src[5*FDEC_STRIDE -1] - src[ 1*FDEC_STRIDE -1] )\
233       + 3 * ( src[6*FDEC_STRIDE -1] - src[ 0*FDEC_STRIDE -1] )\
234       + 4 * ( src[7*FDEC_STRIDE -1] - src[-1*FDEC_STRIDE -1] );\
235     H += -4 * src[-1*FDEC_STRIDE -1];\
236     int a = 16 * ( src[7*FDEC_STRIDE -1] + src[7 - FDEC_STRIDE] );\
237     int b = ( 17 * H + 16 ) >> 5;\
238     int c = ( 17 * V + 16 ) >> 5;
239
240 #if HIGH_BIT_DEPTH
241 #define PREDICT_8x8_P2(cpu1, cpu2)\
242 static void x264_predict_8x8c_p_ ## cpu1( pixel *src )\
243 {\
244     int H, V;\
245     asm (\
246         "movdqa           %1, %%xmm0 \n"\
247         "pmaddwd          %2, %%xmm0 \n"\
248         "movhlps      %%xmm0, %%xmm1 \n"\
249         "paddd        %%xmm1, %%xmm0 \n"\
250         "pshuflw $14, %%xmm0, %%xmm1 \n"\
251         "paddd        %%xmm1, %%xmm0 \n"\
252         "movd         %%xmm0, %0     \n"\
253         :"=r"(H)\
254         :"m"(src[-FDEC_STRIDE]), "m"(*pw_m32101234)\
255     );\
256     PREDICT_8x8C_P_CORE\
257     x264_predict_8x8c_p_core_ ## cpu2( src, a, b, c );\
258 }
259
260 PREDICT_8x8_P2(sse2, sse2)
261 PREDICT_8x8_P2( avx,  avx)
262
263 #else  //!HIGH_BIT_DEPTH
264 #define PREDICT_8x8_P2(cpu1, cpu2)\
265 static void x264_predict_8x8c_p_ ## cpu1( pixel *src )\
266 {\
267     int H, V;\
268     asm (\
269         "movq           %1, %%mm0 \n"\
270         "pmaddubsw      %2, %%mm0 \n"\
271         "pshufw $14, %%mm0, %%mm1 \n"\
272         "paddw       %%mm1, %%mm0 \n"\
273         "pshufw  $1, %%mm0, %%mm1 \n"\
274         "paddw       %%mm1, %%mm0 \n"\
275         "movd        %%mm0, %0    \n"\
276         "movswl        %w0, %0    \n"\
277         :"=r"(H)\
278         :"m"(src[-FDEC_STRIDE]), "m"(*pb_m32101234)\
279     );\
280     PREDICT_8x8C_P_CORE\
281     int i00 = a -3*b -3*c + 16;\
282     x264_predict_8x8c_p_core_ ## cpu2( src, i00, b, c );\
283 }
284
285 PREDICT_8x8_P2(ssse3, sse2)
286 PREDICT_8x8_P2(  avx,  avx)
287 #endif
288 #endif
289
290 #if ARCH_X86_64 && !HIGH_BIT_DEPTH
291 static void x264_predict_8x8c_dc_left( uint8_t *src )
292 {
293     int y;
294     uint32_t s0 = 0, s1 = 0;
295     uint64_t dc0, dc1;
296
297     for( y = 0; y < 4; y++ )
298     {
299         s0 += src[y * FDEC_STRIDE     - 1];
300         s1 += src[(y+4) * FDEC_STRIDE - 1];
301     }
302     dc0 = (( s0 + 2 ) >> 2) * 0x0101010101010101ULL;
303     dc1 = (( s1 + 2 ) >> 2) * 0x0101010101010101ULL;
304
305     for( y = 0; y < 4; y++ )
306     {
307         M64( src ) = dc0;
308         src += FDEC_STRIDE;
309     }
310     for( y = 0; y < 4; y++ )
311     {
312         M64( src ) = dc1;
313         src += FDEC_STRIDE;
314     }
315
316 }
317 #endif // ARCH_X86_64 && !HIGH_BIT_DEPTH
318
319 /****************************************************************************
320  * Exported functions:
321  ****************************************************************************/
322 void x264_predict_16x16_init_mmx( int cpu, x264_predict_t pf[7] )
323 {
324     if( !(cpu&X264_CPU_MMX2) )
325         return;
326     pf[I_PRED_16x16_DC]      = x264_predict_16x16_dc_mmx2;
327     pf[I_PRED_16x16_DC_TOP]  = x264_predict_16x16_dc_top_mmx2;
328     pf[I_PRED_16x16_DC_LEFT] = x264_predict_16x16_dc_left_mmx2;
329     pf[I_PRED_16x16_V]       = x264_predict_16x16_v_mmx2;
330     pf[I_PRED_16x16_H]       = x264_predict_16x16_h_mmx2;
331 #if HIGH_BIT_DEPTH
332     if( !(cpu&X264_CPU_SSE) )
333         return;
334     pf[I_PRED_16x16_V]       = x264_predict_16x16_v_sse;
335     if( !(cpu&X264_CPU_SSE2) )
336         return;
337     pf[I_PRED_16x16_DC]      = x264_predict_16x16_dc_sse2;
338     pf[I_PRED_16x16_DC_TOP]  = x264_predict_16x16_dc_top_sse2;
339     pf[I_PRED_16x16_DC_LEFT] = x264_predict_16x16_dc_left_sse2;
340     pf[I_PRED_16x16_H]       = x264_predict_16x16_h_sse2;
341 #if HAVE_X86_INLINE_ASM
342     pf[I_PRED_16x16_P]       = x264_predict_16x16_p_sse2;
343 #endif
344     if( !(cpu&X264_CPU_AVX) )
345         return;
346     pf[I_PRED_16x16_V]       = x264_predict_16x16_v_avx;
347     if( !(cpu&X264_CPU_AVX2) )
348         return;
349     pf[I_PRED_16x16_H]       = x264_predict_16x16_h_avx2;
350 #else
351 #if !ARCH_X86_64
352     pf[I_PRED_16x16_P]       = x264_predict_16x16_p_mmx2;
353 #endif
354     if( !(cpu&X264_CPU_SSE) )
355         return;
356     pf[I_PRED_16x16_V]       = x264_predict_16x16_v_sse;
357     if( !(cpu&X264_CPU_SSE2) )
358         return;
359     pf[I_PRED_16x16_DC]      = x264_predict_16x16_dc_sse2;
360     if( cpu&X264_CPU_SSE2_IS_SLOW )
361         return;
362     pf[I_PRED_16x16_DC_TOP]  = x264_predict_16x16_dc_top_sse2;
363     pf[I_PRED_16x16_DC_LEFT] = x264_predict_16x16_dc_left_sse2;
364     pf[I_PRED_16x16_P]       = x264_predict_16x16_p_sse2;
365     if( !(cpu&X264_CPU_SSSE3) )
366         return;
367     if( !(cpu&X264_CPU_SLOW_PSHUFB) )
368         pf[I_PRED_16x16_H]       = x264_predict_16x16_h_ssse3;
369 #if HAVE_X86_INLINE_ASM
370     pf[I_PRED_16x16_P]       = x264_predict_16x16_p_ssse3;
371 #endif
372     if( !(cpu&X264_CPU_AVX) )
373         return;
374     pf[I_PRED_16x16_P]       = x264_predict_16x16_p_avx;
375 #endif // HIGH_BIT_DEPTH
376 }
377
378 void x264_predict_8x8c_init_mmx( int cpu, x264_predict_t pf[7] )
379 {
380     if( !(cpu&X264_CPU_MMX) )
381         return;
382 #if HIGH_BIT_DEPTH
383     pf[I_PRED_CHROMA_V]       = x264_predict_8x8c_v_mmx;
384     if( !(cpu&X264_CPU_MMX2) )
385         return;
386     pf[I_PRED_CHROMA_DC]      = x264_predict_8x8c_dc_mmx2;
387     pf[I_PRED_CHROMA_H]       = x264_predict_8x8c_h_mmx2;
388     if( !(cpu&X264_CPU_SSE) )
389         return;
390     pf[I_PRED_CHROMA_V]       = x264_predict_8x8c_v_sse;
391     if( !(cpu&X264_CPU_SSE2) )
392         return;
393     pf[I_PRED_CHROMA_DC]      = x264_predict_8x8c_dc_sse2;
394     pf[I_PRED_CHROMA_DC_TOP]  = x264_predict_8x8c_dc_top_sse2;
395     pf[I_PRED_CHROMA_H]       = x264_predict_8x8c_h_sse2;
396 #if HAVE_X86_INLINE_ASM
397     pf[I_PRED_CHROMA_P]       = x264_predict_8x8c_p_sse2;
398     if( !(cpu&X264_CPU_AVX) )
399         return;
400     pf[I_PRED_CHROMA_P]       = x264_predict_8x8c_p_avx;
401     if( !(cpu&X264_CPU_AVX2) )
402         return;
403     pf[I_PRED_CHROMA_H]   = x264_predict_8x8c_h_avx2;
404 #endif
405 #else
406 #if ARCH_X86_64
407     pf[I_PRED_CHROMA_DC_LEFT] = x264_predict_8x8c_dc_left;
408 #endif
409     pf[I_PRED_CHROMA_V]       = x264_predict_8x8c_v_mmx;
410     if( !(cpu&X264_CPU_MMX2) )
411         return;
412     pf[I_PRED_CHROMA_DC_TOP]  = x264_predict_8x8c_dc_top_mmx2;
413     pf[I_PRED_CHROMA_H]       = x264_predict_8x8c_h_mmx2;
414 #if !ARCH_X86_64
415     pf[I_PRED_CHROMA_P]       = x264_predict_8x8c_p_mmx2;
416 #endif
417     pf[I_PRED_CHROMA_DC]      = x264_predict_8x8c_dc_mmx2;
418     if( !(cpu&X264_CPU_SSE2) )
419         return;
420     pf[I_PRED_CHROMA_P]       = x264_predict_8x8c_p_sse2;
421     if( !(cpu&X264_CPU_SSSE3) )
422         return;
423     pf[I_PRED_CHROMA_H]       = x264_predict_8x8c_h_ssse3;
424 #if HAVE_X86_INLINE_ASM
425     pf[I_PRED_CHROMA_P]       = x264_predict_8x8c_p_ssse3;
426     if( !(cpu&X264_CPU_AVX) )
427         return;
428     pf[I_PRED_CHROMA_P]       = x264_predict_8x8c_p_avx;
429 #endif
430 #endif // HIGH_BIT_DEPTH
431 }
432
433 void x264_predict_8x16c_init_mmx( int cpu, x264_predict_t pf[7] )
434 {
435     if( !(cpu&X264_CPU_MMX) )
436         return;
437 #if HIGH_BIT_DEPTH
438     if( !(cpu&X264_CPU_MMX2) )
439         return;
440     pf[I_PRED_CHROMA_DC]      = x264_predict_8x16c_dc_mmx2;
441     pf[I_PRED_CHROMA_H]       = x264_predict_8x16c_h_mmx2;
442     if( !(cpu&X264_CPU_SSE) )
443         return;
444     pf[I_PRED_CHROMA_V]       = x264_predict_8x16c_v_sse;
445     if( !(cpu&X264_CPU_SSE2) )
446         return;
447     pf[I_PRED_CHROMA_DC_TOP]  = x264_predict_8x16c_dc_top_sse2;
448     pf[I_PRED_CHROMA_DC]      = x264_predict_8x16c_dc_sse2;
449     pf[I_PRED_CHROMA_H]       = x264_predict_8x16c_h_sse2;
450     pf[I_PRED_CHROMA_P]       = x264_predict_8x16c_p_sse2;
451     if( !(cpu&X264_CPU_AVX) )
452         return;
453     pf[I_PRED_CHROMA_P]       = x264_predict_8x16c_p_avx;
454     if( !(cpu&X264_CPU_AVX2) )
455         return;
456     pf[I_PRED_CHROMA_H]   = x264_predict_8x16c_h_avx2;
457 #else
458     pf[I_PRED_CHROMA_V]       = x264_predict_8x16c_v_mmx;
459     if( !(cpu&X264_CPU_MMX2) )
460         return;
461     pf[I_PRED_CHROMA_DC_TOP]  = x264_predict_8x16c_dc_top_mmx2;
462     pf[I_PRED_CHROMA_DC]      = x264_predict_8x16c_dc_mmx2;
463     pf[I_PRED_CHROMA_H]       = x264_predict_8x16c_h_mmx2;
464 #ifndef ARCH_X86_64
465     pf[I_PRED_CHROMA_P]       = x264_predict_8x16c_p_mmx2;
466 #endif
467     if( !(cpu&X264_CPU_SSE2) )
468         return;
469     pf[I_PRED_CHROMA_P]       = x264_predict_8x16c_p_sse2;
470     if( !(cpu&X264_CPU_SSSE3) )
471         return;
472     pf[I_PRED_CHROMA_H]       = x264_predict_8x16c_h_ssse3;
473     if( !(cpu&X264_CPU_AVX) )
474         return;
475     pf[I_PRED_CHROMA_P]       = x264_predict_8x16c_p_avx;
476 #endif // HIGH_BIT_DEPTH
477 }
478
479 void x264_predict_8x8_init_mmx( int cpu, x264_predict8x8_t pf[12], x264_predict_8x8_filter_t *predict_8x8_filter )
480 {
481     if( !(cpu&X264_CPU_MMX2) )
482         return;
483 #if HIGH_BIT_DEPTH
484     if( !(cpu&X264_CPU_SSE) )
485         return;
486     pf[I_PRED_8x8_V]      = x264_predict_8x8_v_sse;
487     if( !(cpu&X264_CPU_SSE2) )
488         return;
489     pf[I_PRED_8x8_H]      = x264_predict_8x8_h_sse2;
490     pf[I_PRED_8x8_DC]     = x264_predict_8x8_dc_sse2;
491     pf[I_PRED_8x8_DC_TOP] = x264_predict_8x8_dc_top_sse2;
492     pf[I_PRED_8x8_DC_LEFT]= x264_predict_8x8_dc_left_sse2;
493     pf[I_PRED_8x8_DDL]    = x264_predict_8x8_ddl_sse2;
494     pf[I_PRED_8x8_DDR]    = x264_predict_8x8_ddr_sse2;
495     pf[I_PRED_8x8_VL]     = x264_predict_8x8_vl_sse2;
496     pf[I_PRED_8x8_VR]     = x264_predict_8x8_vr_sse2;
497     pf[I_PRED_8x8_HD]     = x264_predict_8x8_hd_sse2;
498     pf[I_PRED_8x8_HU]     = x264_predict_8x8_hu_sse2;
499     *predict_8x8_filter   = x264_predict_8x8_filter_sse2;
500     if( !(cpu&X264_CPU_SSSE3) )
501         return;
502     pf[I_PRED_8x8_DDL]    = x264_predict_8x8_ddl_ssse3;
503     pf[I_PRED_8x8_DDR]    = x264_predict_8x8_ddr_ssse3;
504     pf[I_PRED_8x8_HD]     = x264_predict_8x8_hd_ssse3;
505     pf[I_PRED_8x8_HU]     = x264_predict_8x8_hu_ssse3;
506     pf[I_PRED_8x8_VL]     = x264_predict_8x8_vl_ssse3;
507     pf[I_PRED_8x8_VR]     = x264_predict_8x8_vr_ssse3;
508     *predict_8x8_filter   = x264_predict_8x8_filter_ssse3;
509     if( cpu&X264_CPU_CACHELINE_64 )
510     {
511         pf[I_PRED_8x8_DDL]= x264_predict_8x8_ddl_ssse3_cache64;
512         pf[I_PRED_8x8_DDR]= x264_predict_8x8_ddr_ssse3_cache64;
513     }
514     if( !(cpu&X264_CPU_AVX) )
515         return;
516     pf[I_PRED_8x8_HD]     = x264_predict_8x8_hd_avx;
517     pf[I_PRED_8x8_HU]     = x264_predict_8x8_hu_avx;
518     pf[I_PRED_8x8_VL]     = x264_predict_8x8_vl_avx;
519     pf[I_PRED_8x8_VR]     = x264_predict_8x8_vr_avx;
520     *predict_8x8_filter   = x264_predict_8x8_filter_avx;
521 #else
522     pf[I_PRED_8x8_V]      = x264_predict_8x8_v_mmx2;
523     pf[I_PRED_8x8_H]      = x264_predict_8x8_h_mmx2;
524     pf[I_PRED_8x8_DC]     = x264_predict_8x8_dc_mmx2;
525     pf[I_PRED_8x8_DC_TOP] = x264_predict_8x8_dc_top_mmx2;
526     pf[I_PRED_8x8_DC_LEFT]= x264_predict_8x8_dc_left_mmx2;
527     pf[I_PRED_8x8_HD]     = x264_predict_8x8_hd_mmx2;
528     pf[I_PRED_8x8_VL]     = x264_predict_8x8_vl_mmx2;
529     *predict_8x8_filter   = x264_predict_8x8_filter_mmx2;
530 #if ARCH_X86
531     pf[I_PRED_8x8_DDL]  = x264_predict_8x8_ddl_mmx2;
532     pf[I_PRED_8x8_DDR]  = x264_predict_8x8_ddr_mmx2;
533     pf[I_PRED_8x8_VR]   = x264_predict_8x8_vr_mmx2;
534     pf[I_PRED_8x8_HU]   = x264_predict_8x8_hu_mmx2;
535 #endif
536     if( !(cpu&X264_CPU_SSE2) )
537         return;
538     pf[I_PRED_8x8_DDL]  = x264_predict_8x8_ddl_sse2;
539     pf[I_PRED_8x8_VL]   = x264_predict_8x8_vl_sse2;
540     pf[I_PRED_8x8_VR]   = x264_predict_8x8_vr_sse2;
541     pf[I_PRED_8x8_DDR]  = x264_predict_8x8_ddr_sse2;
542     pf[I_PRED_8x8_HD]   = x264_predict_8x8_hd_sse2;
543     pf[I_PRED_8x8_HU]   = x264_predict_8x8_hu_sse2;
544     if( !(cpu&X264_CPU_SSSE3) )
545         return;
546     if( !(cpu&X264_CPU_SLOW_PALIGNR) )
547     {
548         pf[I_PRED_8x8_DDL]  = x264_predict_8x8_ddl_ssse3;
549         pf[I_PRED_8x8_VR]   = x264_predict_8x8_vr_ssse3;
550     }
551     pf[I_PRED_8x8_HU]   = x264_predict_8x8_hu_ssse3;
552     *predict_8x8_filter = x264_predict_8x8_filter_ssse3;
553     if( !(cpu&X264_CPU_AVX) )
554         return;
555     pf[I_PRED_8x8_DDL]  = x264_predict_8x8_ddl_avx;
556     pf[I_PRED_8x8_DDR]  = x264_predict_8x8_ddr_avx;
557     pf[I_PRED_8x8_VL]   = x264_predict_8x8_vl_avx;
558     pf[I_PRED_8x8_VR]   = x264_predict_8x8_vr_avx;
559     pf[I_PRED_8x8_HD]   = x264_predict_8x8_hd_avx;
560 #endif // HIGH_BIT_DEPTH
561 }
562
563 void x264_predict_4x4_init_mmx( int cpu, x264_predict_t pf[12] )
564 {
565     if( !(cpu&X264_CPU_MMX2) )
566         return;
567     pf[I_PRED_4x4_DC]  = x264_predict_4x4_dc_mmx2;
568     pf[I_PRED_4x4_DDL] = x264_predict_4x4_ddl_mmx2;
569     pf[I_PRED_4x4_DDR] = x264_predict_4x4_ddr_mmx2;
570     pf[I_PRED_4x4_VL]  = x264_predict_4x4_vl_mmx2;
571     pf[I_PRED_4x4_HD]  = x264_predict_4x4_hd_mmx2;
572     pf[I_PRED_4x4_HU]  = x264_predict_4x4_hu_mmx2;
573 #if HIGH_BIT_DEPTH
574     if( !(cpu&X264_CPU_SSE2) )
575         return;
576     pf[I_PRED_4x4_DDL] = x264_predict_4x4_ddl_sse2;
577     pf[I_PRED_4x4_DDR] = x264_predict_4x4_ddr_sse2;
578     pf[I_PRED_4x4_HD]  = x264_predict_4x4_hd_sse2;
579     pf[I_PRED_4x4_VL]  = x264_predict_4x4_vl_sse2;
580     pf[I_PRED_4x4_VR]  = x264_predict_4x4_vr_sse2;
581     if( !(cpu&X264_CPU_SSSE3) )
582         return;
583     pf[I_PRED_4x4_DDR] = x264_predict_4x4_ddr_ssse3;
584     pf[I_PRED_4x4_VR]  = x264_predict_4x4_vr_ssse3;
585     pf[I_PRED_4x4_HD]  = x264_predict_4x4_hd_ssse3;
586     if( !(cpu&X264_CPU_AVX) )
587         return;
588     pf[I_PRED_4x4_DDL] = x264_predict_4x4_ddl_avx;
589     pf[I_PRED_4x4_DDR] = x264_predict_4x4_ddr_avx;
590     pf[I_PRED_4x4_HD]  = x264_predict_4x4_hd_avx;
591     pf[I_PRED_4x4_VL]  = x264_predict_4x4_vl_avx;
592     pf[I_PRED_4x4_VR]  = x264_predict_4x4_vr_avx;
593     if( !(cpu&X264_CPU_AVX2) )
594         return;
595     pf[I_PRED_4x4_H]  = x264_predict_4x4_h_avx2;
596 #else
597     pf[I_PRED_4x4_VR]  = x264_predict_4x4_vr_mmx2;
598     if( !(cpu&X264_CPU_SSSE3) )
599         return;
600     pf[I_PRED_4x4_DDR] = x264_predict_4x4_ddr_ssse3;
601     pf[I_PRED_4x4_VR]  = x264_predict_4x4_vr_ssse3;
602     pf[I_PRED_4x4_HD]  = x264_predict_4x4_hd_ssse3;
603     if( cpu&X264_CPU_CACHELINE_64 )
604         pf[I_PRED_4x4_VR] = x264_predict_4x4_vr_ssse3_cache64;
605 #endif // HIGH_BIT_DEPTH
606 }