]> git.sesse.net Git - x264/blob - common/x86/mc-c.c
More cosmetics
[x264] / common / x86 / mc-c.c
1 /*****************************************************************************
2  * mc-c.c: h264 encoder library (Motion Compensation)
3  *****************************************************************************
4  * Copyright (C) 2003-2008 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
25 #include <stdlib.h>
26 #include <stdio.h>
27 #include <string.h>
28
29 #include "common/common.h"
30 #include "mc.h"
31
32 #define DECL_SUF( func, args )\
33     void func##_mmxext args;\
34     void func##_sse2 args;\
35     void func##_ssse3 args;
36
37 DECL_SUF( x264_pixel_avg_16x16, ( uint8_t *, int, uint8_t *, int, uint8_t *, int, int ))
38 DECL_SUF( x264_pixel_avg_16x8,  ( uint8_t *, int, uint8_t *, int, uint8_t *, int, int ))
39 DECL_SUF( x264_pixel_avg_8x16,  ( uint8_t *, int, uint8_t *, int, uint8_t *, int, int ))
40 DECL_SUF( x264_pixel_avg_8x8,   ( uint8_t *, int, uint8_t *, int, uint8_t *, int, int ))
41 DECL_SUF( x264_pixel_avg_8x4,   ( uint8_t *, int, uint8_t *, int, uint8_t *, int, int ))
42 DECL_SUF( x264_pixel_avg_4x8,   ( uint8_t *, int, uint8_t *, int, uint8_t *, int, int ))
43 DECL_SUF( x264_pixel_avg_4x4,   ( uint8_t *, int, uint8_t *, int, uint8_t *, int, int ))
44 DECL_SUF( x264_pixel_avg_4x2,   ( uint8_t *, int, uint8_t *, int, uint8_t *, int, int ))
45
46 #define MC_WEIGHT(w,type) \
47     void x264_mc_weight_w##w##_##type( uint8_t *,int, uint8_t *,int, const x264_weight_t *,int );
48
49 #define MC_WEIGHT_OFFSET(w,type) \
50     void x264_mc_offsetadd_w##w##_##type( uint8_t *,int, uint8_t *,int, const x264_weight_t *,int ); \
51     void x264_mc_offsetsub_w##w##_##type( uint8_t *,int, uint8_t *,int, const x264_weight_t *,int ); \
52     MC_WEIGHT(w,type)
53
54 MC_WEIGHT_OFFSET( 4, mmxext )
55 MC_WEIGHT_OFFSET( 8, mmxext )
56 MC_WEIGHT_OFFSET( 12, mmxext )
57 MC_WEIGHT_OFFSET( 16, mmxext )
58 MC_WEIGHT_OFFSET( 20, mmxext )
59 MC_WEIGHT_OFFSET( 12, sse2 )
60 MC_WEIGHT_OFFSET( 16, sse2 )
61 MC_WEIGHT_OFFSET( 20, sse2 )
62 MC_WEIGHT( 8, sse2  )
63 MC_WEIGHT( 4, ssse3 )
64 MC_WEIGHT( 8, ssse3 )
65 MC_WEIGHT( 12, ssse3 )
66 MC_WEIGHT( 16, ssse3 )
67 MC_WEIGHT( 20, ssse3 )
68 #undef MC_OFFSET
69 #undef MC_WEIGHT
70
71 void x264_mc_copy_w4_mmx( uint8_t *, int, uint8_t *, int, int );
72 void x264_mc_copy_w8_mmx( uint8_t *, int, uint8_t *, int, int );
73 void x264_mc_copy_w16_mmx( uint8_t *, int, uint8_t *, int, int );
74 void x264_mc_copy_w16_sse2( uint8_t *, int, uint8_t *, int, int );
75 void x264_mc_copy_w16_sse3( uint8_t *, int, uint8_t *, int, int );
76 void x264_mc_copy_w16_aligned_sse2( uint8_t *, int, uint8_t *, int, int );
77 void x264_prefetch_fenc_mmxext( uint8_t *, int, uint8_t *, int, int );
78 void x264_prefetch_ref_mmxext( uint8_t *, int, int );
79 void x264_mc_chroma_mmxext( uint8_t *src, int i_src_stride,
80                             uint8_t *dst, int i_dst_stride,
81                             int dx, int dy, int i_width, int i_height );
82 void x264_mc_chroma_sse2( uint8_t *src, int i_src_stride,
83                           uint8_t *dst, int i_dst_stride,
84                           int dx, int dy, int i_width, int i_height );
85 void x264_mc_chroma_ssse3( uint8_t *src, int i_src_stride,
86                            uint8_t *dst, int i_dst_stride,
87                            int dx, int dy, int i_width, int i_height );
88 void x264_mc_chroma_ssse3_cache64( uint8_t *src, int i_src_stride,
89                                    uint8_t *dst, int i_dst_stride,
90                                    int dx, int dy, int i_width, int i_height );
91 void x264_plane_copy_core_mmxext( uint8_t *, int, uint8_t *, int, int w, int h);
92 void x264_plane_copy_c( uint8_t *, int, uint8_t *, int, int w, int h);
93 void *x264_memcpy_aligned_mmx( void * dst, const void * src, size_t n );
94 void *x264_memcpy_aligned_sse2( void * dst, const void * src, size_t n );
95 void x264_memzero_aligned_mmx( void * dst, int n );
96 void x264_memzero_aligned_sse2( void * dst, int n );
97 void x264_integral_init4h_sse4( uint16_t *sum, uint8_t *pix, int stride );
98 void x264_integral_init8h_sse4( uint16_t *sum, uint8_t *pix, int stride );
99 void x264_integral_init4v_mmx( uint16_t *sum8, uint16_t *sum4, int stride );
100 void x264_integral_init4v_sse2( uint16_t *sum8, uint16_t *sum4, int stride );
101 void x264_integral_init8v_mmx( uint16_t *sum8, int stride );
102 void x264_integral_init8v_sse2( uint16_t *sum8, int stride );
103 void x264_integral_init4v_ssse3( uint16_t *sum8, uint16_t *sum4, int stride );
104 void x264_mbtree_propagate_cost_sse2( int *dst, uint16_t *propagate_in, uint16_t *intra_costs,
105                                       uint16_t *inter_costs, uint16_t *inv_qscales, int len );
106 #define LOWRES(cpu)\
107 void x264_frame_init_lowres_core_##cpu( uint8_t *src0, uint8_t *dst0, uint8_t *dsth, uint8_t *dstv, uint8_t *dstc,\
108                                         int src_stride, int dst_stride, int width, int height );
109 LOWRES(mmxext)
110 LOWRES(cache32_mmxext)
111 LOWRES(sse2)
112 LOWRES(ssse3)
113
114 #define PIXEL_AVG_W(width,cpu)\
115 void x264_pixel_avg2_w##width##_##cpu( uint8_t *, int, uint8_t *, int, uint8_t *, int );
116 /* This declares some functions that don't exist, but that isn't a problem. */
117 #define PIXEL_AVG_WALL(cpu)\
118 PIXEL_AVG_W(4,cpu); PIXEL_AVG_W(8,cpu); PIXEL_AVG_W(12,cpu); PIXEL_AVG_W(16,cpu); PIXEL_AVG_W(20,cpu);
119
120 PIXEL_AVG_WALL(mmxext)
121 PIXEL_AVG_WALL(cache32_mmxext)
122 PIXEL_AVG_WALL(cache64_mmxext)
123 PIXEL_AVG_WALL(cache64_sse2)
124 PIXEL_AVG_WALL(sse2)
125 PIXEL_AVG_WALL(sse2_misalign)
126 PIXEL_AVG_WALL(cache64_ssse3)
127
128 #define PIXEL_AVG_WTAB(instr, name1, name2, name3, name4, name5)\
129 static void (* const x264_pixel_avg_wtab_##instr[6])( uint8_t *, int, uint8_t *, int, uint8_t *, int ) =\
130 {\
131     NULL,\
132     x264_pixel_avg2_w4_##name1,\
133     x264_pixel_avg2_w8_##name2,\
134     x264_pixel_avg2_w12_##name3,\
135     x264_pixel_avg2_w16_##name4,\
136     x264_pixel_avg2_w20_##name5,\
137 };
138
139 /* w16 sse2 is faster than w12 mmx as long as the cacheline issue is resolved */
140 #define x264_pixel_avg2_w12_cache64_sse2 x264_pixel_avg2_w16_cache64_sse2
141 #define x264_pixel_avg2_w12_sse3         x264_pixel_avg2_w16_sse3
142 #define x264_pixel_avg2_w12_sse2         x264_pixel_avg2_w16_sse2
143
144 PIXEL_AVG_WTAB(mmxext, mmxext, mmxext, mmxext, mmxext, mmxext)
145 #ifdef ARCH_X86
146 PIXEL_AVG_WTAB(cache32_mmxext, mmxext, cache32_mmxext, cache32_mmxext, cache32_mmxext, cache32_mmxext)
147 PIXEL_AVG_WTAB(cache64_mmxext, mmxext, cache64_mmxext, cache64_mmxext, cache64_mmxext, cache64_mmxext)
148 #endif
149 PIXEL_AVG_WTAB(sse2, mmxext, mmxext, sse2, sse2, sse2)
150 PIXEL_AVG_WTAB(sse2_misalign, mmxext, mmxext, sse2, sse2, sse2_misalign)
151 PIXEL_AVG_WTAB(cache64_sse2, mmxext, cache64_mmxext, cache64_sse2, cache64_sse2, cache64_sse2)
152 PIXEL_AVG_WTAB(cache64_ssse3, mmxext, cache64_mmxext, cache64_sse2, cache64_ssse3, cache64_sse2)
153
154 #define MC_COPY_WTAB(instr, name1, name2, name3)\
155 static void (* const x264_mc_copy_wtab_##instr[5])( uint8_t *, int, uint8_t *, int, int ) =\
156 {\
157     NULL,\
158     x264_mc_copy_w4_##name1,\
159     x264_mc_copy_w8_##name2,\
160     NULL,\
161     x264_mc_copy_w16_##name3,\
162 };
163
164 MC_COPY_WTAB(mmx,mmx,mmx,mmx)
165 MC_COPY_WTAB(sse2,mmx,mmx,sse2)
166
167 #define MC_WEIGHT_WTAB(function, instr, name1, name2, w12version)\
168     static void (* x264_mc_##function##_wtab_##instr[6])( uint8_t *, int, uint8_t *, int, const x264_weight_t *, int ) =\
169 {\
170     x264_mc_##function##_w4_##name1,\
171     x264_mc_##function##_w4_##name1,\
172     x264_mc_##function##_w8_##name2,\
173     x264_mc_##function##_w##w12version##_##instr,\
174     x264_mc_##function##_w16_##instr,\
175     x264_mc_##function##_w20_##instr,\
176 };
177
178 MC_WEIGHT_WTAB(weight,mmxext,mmxext,mmxext,12)
179 MC_WEIGHT_WTAB(offsetadd,mmxext,mmxext,mmxext,12)
180 MC_WEIGHT_WTAB(offsetsub,mmxext,mmxext,mmxext,12)
181 MC_WEIGHT_WTAB(weight,sse2,mmxext,sse2,16)
182 MC_WEIGHT_WTAB(offsetadd,sse2,mmxext,mmxext,16)
183 MC_WEIGHT_WTAB(offsetsub,sse2,mmxext,mmxext,16)
184 MC_WEIGHT_WTAB(weight,ssse3,ssse3,ssse3,16)
185
186 static void x264_weight_cache_mmxext( x264_t *h, x264_weight_t *w )
187 {
188     int i;
189     int16_t den1;
190
191     if( w->i_scale == 1<<w->i_denom )
192     {
193         if( w->i_offset < 0 )
194             w->weightfn = h->mc.offsetsub;
195         else
196             w->weightfn = h->mc.offsetadd;
197         memset( w->cachea, abs(w->i_offset), sizeof(w->cachea) );
198         return;
199     }
200     w->weightfn = h->mc.weight;
201     den1 = 1 << (w->i_denom - 1) | w->i_offset << w->i_denom;
202     for( i = 0; i < 8; i++ )
203     {
204         w->cachea[i] = w->i_scale;
205         w->cacheb[i] = den1;
206     }
207 }
208
209 static void x264_weight_cache_ssse3( x264_t *h, x264_weight_t *w )
210 {
211     int i, den1;
212     if( w->i_scale == 1<<w->i_denom )
213     {
214         if( w->i_offset < 0 )
215             w->weightfn = h->mc.offsetsub;
216         else
217             w->weightfn = h->mc.offsetadd;
218
219         memset( w->cachea, abs( w->i_offset ), sizeof(w->cachea) );
220         return;
221     }
222     w->weightfn = h->mc.weight;
223     den1 = w->i_scale << (8 - w->i_denom);
224     for(i = 0;i<8;i++)
225     {
226         w->cachea[i] = den1;
227         w->cacheb[i] = w->i_offset;
228     }
229 }
230
231 static const int hpel_ref0[16] = {0,1,1,1,0,1,1,1,2,3,3,3,0,1,1,1};
232 static const int hpel_ref1[16] = {0,0,0,0,2,2,3,2,2,2,3,2,2,2,3,2};
233
234 #define MC_LUMA(name,instr1,instr2)\
235 static void mc_luma_##name( uint8_t *dst,    int i_dst_stride,\
236                   uint8_t *src[4], int i_src_stride,\
237                   int mvx, int mvy,\
238                   int i_width, int i_height, const x264_weight_t *weight )\
239 {\
240     int qpel_idx = ((mvy&3)<<2) + (mvx&3);\
241     int offset = (mvy>>2)*i_src_stride + (mvx>>2);\
242     uint8_t *src1 = src[hpel_ref0[qpel_idx]] + offset + ((mvy&3) == 3) * i_src_stride;\
243     if( qpel_idx & 5 ) /* qpel interpolation needed */\
244     {\
245         uint8_t *src2 = src[hpel_ref1[qpel_idx]] + offset + ((mvx&3) == 3);\
246         x264_pixel_avg_wtab_##instr1[i_width>>2](\
247                 dst, i_dst_stride, src1, i_src_stride,\
248                 src2, i_height );\
249         if( weight->weightfn )\
250             weight->weightfn[i_width>>2]( dst, i_dst_stride, dst, i_dst_stride, weight, i_height );\
251     }\
252     else if( weight->weightfn )\
253         weight->weightfn[i_width>>2]( dst, i_dst_stride, src1, i_src_stride, weight, i_height );\
254     else\
255         x264_mc_copy_wtab_##instr2[i_width>>2](dst, i_dst_stride, src1, i_src_stride, i_height );\
256 }
257
258 MC_LUMA(mmxext,mmxext,mmx)
259 #ifdef ARCH_X86
260 MC_LUMA(cache32_mmxext,cache32_mmxext,mmx)
261 MC_LUMA(cache64_mmxext,cache64_mmxext,mmx)
262 #endif
263 MC_LUMA(sse2,sse2,sse2)
264 MC_LUMA(cache64_sse2,cache64_sse2,sse2)
265 MC_LUMA(cache64_ssse3,cache64_ssse3,sse2)
266
267 #define GET_REF(name)\
268 static uint8_t *get_ref_##name( uint8_t *dst,   int *i_dst_stride,\
269                          uint8_t *src[4], int i_src_stride,\
270                          int mvx, int mvy,\
271                          int i_width, int i_height, const x264_weight_t *weight )\
272 {\
273     int qpel_idx = ((mvy&3)<<2) + (mvx&3);\
274     int offset = (mvy>>2)*i_src_stride + (mvx>>2);\
275     uint8_t *src1 = src[hpel_ref0[qpel_idx]] + offset + ((mvy&3) == 3) * i_src_stride;\
276     if( qpel_idx & 5 ) /* qpel interpolation needed */\
277     {\
278         uint8_t *src2 = src[hpel_ref1[qpel_idx]] + offset + ((mvx&3) == 3);\
279         x264_pixel_avg_wtab_##name[i_width>>2](\
280                 dst, *i_dst_stride, src1, i_src_stride,\
281                 src2, i_height );\
282         if( weight->weightfn )\
283             weight->weightfn[i_width>>2]( dst, *i_dst_stride, dst, *i_dst_stride, weight, i_height );\
284         return dst;\
285     }\
286     else if( weight->weightfn )\
287     {\
288         weight->weightfn[i_width>>2]( dst, *i_dst_stride, src1, i_src_stride, weight, i_height );\
289         return dst;\
290     }\
291     else\
292     {\
293         *i_dst_stride = i_src_stride;\
294         return src1;\
295     }\
296 }
297
298 GET_REF(mmxext)
299 #ifdef ARCH_X86
300 GET_REF(cache32_mmxext)
301 GET_REF(cache64_mmxext)
302 #endif
303 GET_REF(sse2)
304 GET_REF(sse2_misalign)
305 GET_REF(cache64_sse2)
306 GET_REF(cache64_ssse3)
307
308 #define HPEL(align, cpu, cpuv, cpuc, cpuh)\
309 void x264_hpel_filter_v_##cpuv( uint8_t *dst, uint8_t *src, int16_t *buf, int stride, int width);\
310 void x264_hpel_filter_c_##cpuc( uint8_t *dst, int16_t *buf, int width );\
311 void x264_hpel_filter_h_##cpuh( uint8_t *dst, uint8_t *src, int width );\
312 static void x264_hpel_filter_##cpu( uint8_t *dsth, uint8_t *dstv, uint8_t *dstc, uint8_t *src,\
313                              int stride, int width, int height, int16_t *buf )\
314 {\
315     int realign = (intptr_t)src & (align-1);\
316     src -= realign;\
317     dstv -= realign;\
318     dstc -= realign;\
319     dsth -= realign;\
320     width += realign;\
321     while( height-- )\
322     {\
323         x264_hpel_filter_v_##cpuv( dstv, src, buf+8, stride, width );\
324         x264_hpel_filter_c_##cpuc( dstc, buf+8, width );\
325         x264_hpel_filter_h_##cpuh( dsth, src, width );\
326         dsth += stride;\
327         dstv += stride;\
328         dstc += stride;\
329         src  += stride;\
330     }\
331     x264_sfence();\
332 }
333
334 HPEL(8, mmxext, mmxext, mmxext, mmxext)
335 HPEL(16, sse2_amd, mmxext, mmxext, sse2)
336 #ifdef ARCH_X86_64
337 void x264_hpel_filter_sse2( uint8_t *dsth, uint8_t *dstv, uint8_t *dstc, uint8_t *src, int stride, int width, int height, int16_t *buf );
338 void x264_hpel_filter_ssse3( uint8_t *dsth, uint8_t *dstv, uint8_t *dstc, uint8_t *src, int stride, int width, int height, int16_t *buf );
339 #else
340 HPEL(16, sse2, sse2, sse2, sse2)
341 HPEL(16, ssse3, ssse3, ssse3, ssse3)
342 #endif
343 HPEL(16, sse2_misalign, sse2, sse2_misalign, sse2)
344
345 static void x264_plane_copy_mmxext( uint8_t *dst, int i_dst, uint8_t *src, int i_src, int w, int h)
346 {
347     if( w < 256 ) { // tiny resolutions don't want non-temporal hints. dunno the exact threshold.
348         x264_plane_copy_c( dst, i_dst, src, i_src, w, h );
349     } else if(i_src > 0) {
350         // have to use plain memcpy on the last line (in memory order) to avoid overreading src
351         x264_plane_copy_core_mmxext( dst, i_dst, src, i_src, (w+15)&~15, h-1 );
352         memcpy( dst+i_dst*(h-1), src+i_src*(h-1), w );
353     } else {
354         memcpy( dst, src, w );
355         x264_plane_copy_core_mmxext( dst+i_dst, i_dst, src+i_src, i_src, (w+15)&~15, h-1 );
356     }
357 }
358
359 void x264_mc_init_mmx( int cpu, x264_mc_functions_t *pf )
360 {
361     if( !(cpu&X264_CPU_MMX) )
362         return;
363
364     pf->copy_16x16_unaligned = x264_mc_copy_w16_mmx;
365     pf->copy[PIXEL_16x16] = x264_mc_copy_w16_mmx;
366     pf->copy[PIXEL_8x8]   = x264_mc_copy_w8_mmx;
367     pf->copy[PIXEL_4x4]   = x264_mc_copy_w4_mmx;
368     pf->memcpy_aligned = x264_memcpy_aligned_mmx;
369     pf->memzero_aligned = x264_memzero_aligned_mmx;
370     pf->integral_init4v = x264_integral_init4v_mmx;
371     pf->integral_init8v = x264_integral_init8v_mmx;
372
373     if( !(cpu&X264_CPU_MMXEXT) )
374         return;
375
376     pf->mc_luma = mc_luma_mmxext;
377     pf->get_ref = get_ref_mmxext;
378     pf->mc_chroma = x264_mc_chroma_mmxext;
379
380     pf->weight = x264_mc_weight_wtab_mmxext;
381     pf->offsetadd = x264_mc_offsetadd_wtab_mmxext;
382     pf->offsetsub = x264_mc_offsetsub_wtab_mmxext;
383     pf->weight_cache = x264_weight_cache_mmxext;
384
385     pf->avg[PIXEL_16x16] = x264_pixel_avg_16x16_mmxext;
386     pf->avg[PIXEL_16x8]  = x264_pixel_avg_16x8_mmxext;
387     pf->avg[PIXEL_8x16]  = x264_pixel_avg_8x16_mmxext;
388     pf->avg[PIXEL_8x8]   = x264_pixel_avg_8x8_mmxext;
389     pf->avg[PIXEL_8x4]   = x264_pixel_avg_8x4_mmxext;
390     pf->avg[PIXEL_4x8]   = x264_pixel_avg_4x8_mmxext;
391     pf->avg[PIXEL_4x4]   = x264_pixel_avg_4x4_mmxext;
392     pf->avg[PIXEL_4x2]   = x264_pixel_avg_4x2_mmxext;
393
394     pf->plane_copy = x264_plane_copy_mmxext;
395     pf->hpel_filter = x264_hpel_filter_mmxext;
396     pf->frame_init_lowres_core = x264_frame_init_lowres_core_mmxext;
397
398     pf->prefetch_fenc = x264_prefetch_fenc_mmxext;
399     pf->prefetch_ref  = x264_prefetch_ref_mmxext;
400
401 #ifdef ARCH_X86 // all x86_64 cpus with cacheline split issues use sse2 instead
402     if( cpu&X264_CPU_CACHELINE_32 )
403     {
404         pf->mc_luma = mc_luma_cache32_mmxext;
405         pf->get_ref = get_ref_cache32_mmxext;
406         pf->frame_init_lowres_core = x264_frame_init_lowres_core_cache32_mmxext;
407     }
408     else if( cpu&X264_CPU_CACHELINE_64 )
409     {
410         pf->mc_luma = mc_luma_cache64_mmxext;
411         pf->get_ref = get_ref_cache64_mmxext;
412         pf->frame_init_lowres_core = x264_frame_init_lowres_core_cache32_mmxext;
413     }
414 #endif
415
416     if( !(cpu&X264_CPU_SSE2) )
417         return;
418
419     pf->memcpy_aligned = x264_memcpy_aligned_sse2;
420     pf->memzero_aligned = x264_memzero_aligned_sse2;
421     pf->integral_init4v = x264_integral_init4v_sse2;
422     pf->integral_init8v = x264_integral_init8v_sse2;
423     pf->hpel_filter = x264_hpel_filter_sse2_amd;
424     pf->mbtree_propagate_cost = x264_mbtree_propagate_cost_sse2;
425
426     if( cpu&X264_CPU_SSE2_IS_SLOW )
427         return;
428
429     pf->weight = x264_mc_weight_wtab_sse2;
430     pf->offsetadd = x264_mc_offsetadd_wtab_sse2;
431     pf->offsetsub = x264_mc_offsetsub_wtab_sse2;
432
433     pf->copy[PIXEL_16x16] = x264_mc_copy_w16_aligned_sse2;
434     pf->avg[PIXEL_16x16] = x264_pixel_avg_16x16_sse2;
435     pf->avg[PIXEL_16x8]  = x264_pixel_avg_16x8_sse2;
436     pf->avg[PIXEL_8x16] = x264_pixel_avg_8x16_sse2;
437     pf->avg[PIXEL_8x8]  = x264_pixel_avg_8x8_sse2;
438     pf->avg[PIXEL_8x4]  = x264_pixel_avg_8x4_sse2;
439     pf->hpel_filter = x264_hpel_filter_sse2;
440     if( cpu&X264_CPU_SSE_MISALIGN )
441         pf->hpel_filter = x264_hpel_filter_sse2_misalign;
442     pf->frame_init_lowres_core = x264_frame_init_lowres_core_sse2;
443     pf->mc_chroma = x264_mc_chroma_sse2;
444
445     if( cpu&X264_CPU_SSE2_IS_FAST )
446     {
447         pf->mc_luma = mc_luma_sse2;
448         pf->get_ref = get_ref_sse2;
449         if( cpu&X264_CPU_CACHELINE_64 )
450         {
451             pf->mc_luma = mc_luma_cache64_sse2;
452             pf->get_ref = get_ref_cache64_sse2;
453         }
454         if( cpu&X264_CPU_SSE_MISALIGN )
455             pf->get_ref = get_ref_sse2_misalign;
456     }
457
458     if( !(cpu&X264_CPU_SSSE3) )
459         return;
460
461     pf->avg[PIXEL_16x16] = x264_pixel_avg_16x16_ssse3;
462     pf->avg[PIXEL_16x8]  = x264_pixel_avg_16x8_ssse3;
463     pf->avg[PIXEL_8x16]  = x264_pixel_avg_8x16_ssse3;
464     pf->avg[PIXEL_8x8]   = x264_pixel_avg_8x8_ssse3;
465     pf->avg[PIXEL_8x4]   = x264_pixel_avg_8x4_ssse3;
466     pf->avg[PIXEL_4x8]   = x264_pixel_avg_4x8_ssse3;
467     pf->avg[PIXEL_4x4]   = x264_pixel_avg_4x4_ssse3;
468     pf->avg[PIXEL_4x2]   = x264_pixel_avg_4x2_ssse3;
469
470     pf->hpel_filter = x264_hpel_filter_ssse3;
471     pf->frame_init_lowres_core = x264_frame_init_lowres_core_ssse3;
472     pf->mc_chroma = x264_mc_chroma_ssse3;
473     if( cpu&X264_CPU_CACHELINE_64 )
474     {
475         pf->mc_chroma = x264_mc_chroma_ssse3_cache64;
476         pf->mc_luma = mc_luma_cache64_ssse3;
477         pf->get_ref = get_ref_cache64_ssse3;
478
479         /* ssse3 weight is slower on Nehalem, so only assign here. */
480         pf->weight_cache = x264_weight_cache_ssse3;
481         pf->weight = x264_mc_weight_wtab_ssse3;
482     }
483
484     if( cpu&X264_CPU_SHUFFLE_IS_FAST )
485         pf->integral_init4v = x264_integral_init4v_ssse3;
486
487     if( !(cpu&X264_CPU_SSE4) )
488         return;
489
490     pf->integral_init4h = x264_integral_init4h_sse4;
491     pf->integral_init8h = x264_integral_init8h_sse4;
492 }