]> git.sesse.net Git - x264/blob - common/quant.c
Cosmetics: s/mmxext/mmx2/
[x264] / common / quant.c
1 /*****************************************************************************
2  * quant.c: quantization and level-run
3  *****************************************************************************
4  * Copyright (C) 2005-2011 x264 project
5  *
6  * Authors: Loren Merritt <lorenm@u.washington.edu>
7  *          Fiona Glaser <fiona@x264.com>
8  *          Christian Heine <sennindemokrit@gmx.net>
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.h"
29
30 #if HAVE_MMX
31 #include "x86/quant.h"
32 #endif
33 #if ARCH_PPC
34 #   include "ppc/quant.h"
35 #endif
36 #if ARCH_ARM
37 #   include "arm/quant.h"
38 #endif
39
40 #define QUANT_ONE( coef, mf, f ) \
41 { \
42     if( (coef) > 0 ) \
43         (coef) = (f + (coef)) * (mf) >> 16; \
44     else \
45         (coef) = - ((f - (coef)) * (mf) >> 16); \
46     nz |= (coef); \
47 }
48
49 static int quant_8x8( dctcoef dct[64], udctcoef mf[64], udctcoef bias[64] )
50 {
51     int nz = 0;
52     for( int i = 0; i < 64; i++ )
53         QUANT_ONE( dct[i], mf[i], bias[i] );
54     return !!nz;
55 }
56
57 static int quant_4x4( dctcoef dct[16], udctcoef mf[16], udctcoef bias[16] )
58 {
59     int nz = 0;
60     for( int i = 0; i < 16; i++ )
61         QUANT_ONE( dct[i], mf[i], bias[i] );
62     return !!nz;
63 }
64
65 static int quant_4x4_dc( dctcoef dct[16], int mf, int bias )
66 {
67     int nz = 0;
68     for( int i = 0; i < 16; i++ )
69         QUANT_ONE( dct[i], mf, bias );
70     return !!nz;
71 }
72
73 static int quant_2x2_dc( dctcoef dct[4], int mf, int bias )
74 {
75     int nz = 0;
76     QUANT_ONE( dct[0], mf, bias );
77     QUANT_ONE( dct[1], mf, bias );
78     QUANT_ONE( dct[2], mf, bias );
79     QUANT_ONE( dct[3], mf, bias );
80     return !!nz;
81 }
82
83 #define DEQUANT_SHL( x ) \
84     dct[x] = ( dct[x] * dequant_mf[i_mf][x] ) << i_qbits
85
86 #define DEQUANT_SHR( x ) \
87     dct[x] = ( dct[x] * dequant_mf[i_mf][x] + f ) >> (-i_qbits)
88
89 static void dequant_4x4( dctcoef dct[16], int dequant_mf[6][16], int i_qp )
90 {
91     const int i_mf = i_qp%6;
92     const int i_qbits = i_qp/6 - 4;
93
94     if( i_qbits >= 0 )
95     {
96         for( int i = 0; i < 16; i++ )
97             DEQUANT_SHL( i );
98     }
99     else
100     {
101         const int f = 1 << (-i_qbits-1);
102         for( int i = 0; i < 16; i++ )
103             DEQUANT_SHR( i );
104     }
105 }
106
107 static void dequant_8x8( dctcoef dct[64], int dequant_mf[6][64], int i_qp )
108 {
109     const int i_mf = i_qp%6;
110     const int i_qbits = i_qp/6 - 6;
111
112     if( i_qbits >= 0 )
113     {
114         for( int i = 0; i < 64; i++ )
115             DEQUANT_SHL( i );
116     }
117     else
118     {
119         const int f = 1 << (-i_qbits-1);
120         for( int i = 0; i < 64; i++ )
121             DEQUANT_SHR( i );
122     }
123 }
124
125 static void dequant_4x4_dc( dctcoef dct[16], int dequant_mf[6][16], int i_qp )
126 {
127     const int i_qbits = i_qp/6 - 6;
128
129     if( i_qbits >= 0 )
130     {
131         const int i_dmf = dequant_mf[i_qp%6][0] << i_qbits;
132         for( int i = 0; i < 16; i++ )
133             dct[i] *= i_dmf;
134     }
135     else
136     {
137         const int i_dmf = dequant_mf[i_qp%6][0];
138         const int f = 1 << (-i_qbits-1);
139         for( int i = 0; i < 16; i++ )
140             dct[i] = ( dct[i] * i_dmf + f ) >> (-i_qbits);
141     }
142 }
143
144 static ALWAYS_INLINE void idct_dequant_2x2_dconly( dctcoef out[4], dctcoef dct[4], int dequant_mf )
145 {
146     int d0 = dct[0] + dct[1];
147     int d1 = dct[2] + dct[3];
148     int d2 = dct[0] - dct[1];
149     int d3 = dct[2] - dct[3];
150     out[0] = (d0 + d1) * dequant_mf >> 5;
151     out[1] = (d0 - d1) * dequant_mf >> 5;
152     out[2] = (d2 + d3) * dequant_mf >> 5;
153     out[3] = (d2 - d3) * dequant_mf >> 5;
154 }
155
156 static ALWAYS_INLINE int idct_dequant_round_2x2_dc( dctcoef ref[4], dctcoef dct[4], int dequant_mf )
157 {
158     dctcoef out[4];
159     idct_dequant_2x2_dconly( out, dct, dequant_mf );
160     return ((ref[0] ^ (out[0]+32))
161           | (ref[1] ^ (out[1]+32))
162           | (ref[2] ^ (out[2]+32))
163           | (ref[3] ^ (out[3]+32))) >> 6;
164 }
165
166 static int optimize_chroma_dc( dctcoef dct[4], int dequant_mf )
167 {
168     /* dequant_mf = h->dequant4_mf[CQM_4IC + b_inter][i_qp%6][0] << i_qp/6, max 32*64 */
169     dctcoef dct_orig[4];
170     int coeff, nz;
171
172     idct_dequant_2x2_dconly( dct_orig, dct, dequant_mf );
173     dct_orig[0] += 32;
174     dct_orig[1] += 32;
175     dct_orig[2] += 32;
176     dct_orig[3] += 32;
177
178     /* If the DC coefficients already round to zero, terminate early. */
179     if( !((dct_orig[0]|dct_orig[1]|dct_orig[2]|dct_orig[3])>>6) )
180         return 0;
181
182     /* Start with the highest frequency coefficient... is this the best option? */
183     for( nz = 0, coeff = 3; coeff >= 0; coeff-- )
184     {
185         int level = dct[coeff];
186         int sign = level>>31 | 1; /* dct2x2[coeff] < 0 ? -1 : 1 */
187
188         while( level )
189         {
190             dct[coeff] = level - sign;
191             if( idct_dequant_round_2x2_dc( dct_orig, dct, dequant_mf ) )
192             {
193                 nz = 1;
194                 dct[coeff] = level;
195                 break;
196             }
197             level -= sign;
198         }
199     }
200
201     return nz;
202 }
203
204 static void x264_denoise_dct( dctcoef *dct, uint32_t *sum, udctcoef *offset, int size )
205 {
206     for( int i = 0; i < size; i++ )
207     {
208         int level = dct[i];
209         int sign = level>>31;
210         level = (level+sign)^sign;
211         sum[i] += level;
212         level -= offset[i];
213         dct[i] = level<0 ? 0 : (level^sign)-sign;
214     }
215 }
216
217 /* (ref: JVT-B118)
218  * x264_mb_decimate_score: given dct coeffs it returns a score to see if we could empty this dct coeffs
219  * to 0 (low score means set it to null)
220  * Used in inter macroblock (luma and chroma)
221  *  luma: for a 8x8 block: if score < 4 -> null
222  *        for the complete mb: if score < 6 -> null
223  *  chroma: for the complete mb: if score < 7 -> null
224  */
225
226 const uint8_t x264_decimate_table4[16] =
227 {
228     3,2,2,1,1,1,0,0,0,0,0,0,0,0,0,0
229 };
230 const uint8_t x264_decimate_table8[64] =
231 {
232     3,3,3,3,2,2,2,2,2,2,2,2,1,1,1,1,
233     1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,
234     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
235     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
236 };
237
238 static int ALWAYS_INLINE x264_decimate_score_internal( dctcoef *dct, int i_max )
239 {
240     const uint8_t *ds_table = (i_max == 64) ? x264_decimate_table8 : x264_decimate_table4;
241     int i_score = 0;
242     int idx = i_max - 1;
243
244     while( idx >= 0 && dct[idx] == 0 )
245         idx--;
246     while( idx >= 0 )
247     {
248         int i_run;
249
250         if( (unsigned)(dct[idx--] + 1) > 2 )
251             return 9;
252
253         i_run = 0;
254         while( idx >= 0 && dct[idx] == 0 )
255         {
256             idx--;
257             i_run++;
258         }
259         i_score += ds_table[i_run];
260     }
261
262     return i_score;
263 }
264
265 static int x264_decimate_score15( dctcoef *dct )
266 {
267     return x264_decimate_score_internal( dct+1, 15 );
268 }
269 static int x264_decimate_score16( dctcoef *dct )
270 {
271     return x264_decimate_score_internal( dct, 16 );
272 }
273 static int x264_decimate_score64( dctcoef *dct )
274 {
275     return x264_decimate_score_internal( dct, 64 );
276 }
277
278 static int ALWAYS_INLINE x264_coeff_last_internal( dctcoef *l, int i_count )
279 {
280     int i_last = i_count-1;
281     while( i_last >= 0 && l[i_last] == 0 )
282         i_last--;
283     return i_last;
284 }
285
286 static int x264_coeff_last4( dctcoef *l )
287 {
288     return x264_coeff_last_internal( l, 4 );
289 }
290 static int x264_coeff_last15( dctcoef *l )
291 {
292     return x264_coeff_last_internal( l, 15 );
293 }
294 static int x264_coeff_last16( dctcoef *l )
295 {
296     return x264_coeff_last_internal( l, 16 );
297 }
298 static int x264_coeff_last64( dctcoef *l )
299 {
300     return x264_coeff_last_internal( l, 64 );
301 }
302
303 #define level_run(num)\
304 static int x264_coeff_level_run##num( dctcoef *dct, x264_run_level_t *runlevel )\
305 {\
306     int i_last = runlevel->last = x264_coeff_last##num(dct);\
307     int i_total = 0;\
308     do\
309     {\
310         int r = 0;\
311         runlevel->level[i_total] = dct[i_last];\
312         while( --i_last >= 0 && dct[i_last] == 0 )\
313             r++;\
314         runlevel->run[i_total++] = r;\
315     } while( i_last >= 0 );\
316     return i_total;\
317 }
318
319 level_run(4)
320 level_run(15)
321 level_run(16)
322
323
324 void x264_quant_init( x264_t *h, int cpu, x264_quant_function_t *pf )
325 {
326     pf->quant_8x8 = quant_8x8;
327     pf->quant_4x4 = quant_4x4;
328     pf->quant_4x4_dc = quant_4x4_dc;
329     pf->quant_2x2_dc = quant_2x2_dc;
330
331     pf->dequant_4x4 = dequant_4x4;
332     pf->dequant_4x4_dc = dequant_4x4_dc;
333     pf->dequant_8x8 = dequant_8x8;
334
335     pf->optimize_chroma_dc = optimize_chroma_dc;
336
337     pf->denoise_dct = x264_denoise_dct;
338     pf->decimate_score15 = x264_decimate_score15;
339     pf->decimate_score16 = x264_decimate_score16;
340     pf->decimate_score64 = x264_decimate_score64;
341
342     pf->coeff_last[DCT_CHROMA_DC] = x264_coeff_last4;
343     pf->coeff_last[  DCT_LUMA_AC] = x264_coeff_last15;
344     pf->coeff_last[ DCT_LUMA_4x4] = x264_coeff_last16;
345     pf->coeff_last[ DCT_LUMA_8x8] = x264_coeff_last64;
346     pf->coeff_level_run[DCT_CHROMA_DC] = x264_coeff_level_run4;
347     pf->coeff_level_run[  DCT_LUMA_AC] = x264_coeff_level_run15;
348     pf->coeff_level_run[ DCT_LUMA_4x4] = x264_coeff_level_run16;
349
350 #if HIGH_BIT_DEPTH
351 #if HAVE_MMX
352     if( cpu&X264_CPU_MMX2 )
353     {
354 #if ARCH_X86
355         pf->denoise_dct = x264_denoise_dct_mmx;
356         pf->decimate_score15 = x264_decimate_score15_mmx2;
357         pf->decimate_score16 = x264_decimate_score16_mmx2;
358         if( cpu&X264_CPU_SLOW_CTZ )
359         {
360             pf->decimate_score15 = x264_decimate_score15_mmx2_slowctz;
361             pf->decimate_score16 = x264_decimate_score16_mmx2_slowctz;
362         }
363         pf->decimate_score64 = x264_decimate_score64_mmx2;
364         pf->coeff_last[DCT_CHROMA_DC] = x264_coeff_last4_mmx2;
365         pf->coeff_last[  DCT_LUMA_AC] = x264_coeff_last15_mmx2;
366         pf->coeff_last[ DCT_LUMA_4x4] = x264_coeff_last16_mmx2;
367         pf->coeff_last[ DCT_LUMA_8x8] = x264_coeff_last64_mmx2;
368         pf->coeff_level_run[  DCT_LUMA_AC] = x264_coeff_level_run15_mmx2;
369         pf->coeff_level_run[ DCT_LUMA_4x4] = x264_coeff_level_run16_mmx2;
370 #endif
371         pf->coeff_level_run[DCT_CHROMA_DC] = x264_coeff_level_run4_mmx2;
372         if( cpu&X264_CPU_LZCNT )
373             pf->coeff_level_run[DCT_CHROMA_DC] = x264_coeff_level_run4_mmx2_lzcnt;
374     }
375     if( cpu&X264_CPU_SSE2 )
376     {
377         pf->quant_4x4 = x264_quant_4x4_sse2;
378         pf->quant_8x8 = x264_quant_8x8_sse2;
379         pf->quant_2x2_dc = x264_quant_2x2_dc_sse2;
380         pf->quant_4x4_dc = x264_quant_4x4_dc_sse2;
381         pf->dequant_4x4 = x264_dequant_4x4_sse2;
382         pf->dequant_8x8 = x264_dequant_8x8_sse2;
383         pf->dequant_4x4_dc = x264_dequant_4x4dc_sse2;
384         pf->denoise_dct = x264_denoise_dct_sse2;
385         pf->decimate_score15 = x264_decimate_score15_sse2;
386         pf->decimate_score16 = x264_decimate_score16_sse2;
387         pf->decimate_score64 = x264_decimate_score64_sse2;
388         if( cpu&X264_CPU_SLOW_CTZ )
389         {
390             pf->decimate_score15 = x264_decimate_score15_sse2_slowctz;
391             pf->decimate_score16 = x264_decimate_score16_sse2_slowctz;
392         }
393         pf->coeff_last[ DCT_LUMA_AC] = x264_coeff_last15_sse2;
394         pf->coeff_last[DCT_LUMA_4x4] = x264_coeff_last16_sse2;
395         pf->coeff_last[DCT_LUMA_8x8] = x264_coeff_last64_sse2;
396         pf->coeff_level_run[ DCT_LUMA_AC] = x264_coeff_level_run15_sse2;
397         pf->coeff_level_run[DCT_LUMA_4x4] = x264_coeff_level_run16_sse2;
398         if( cpu&X264_CPU_LZCNT )
399         {
400             pf->coeff_last[DCT_CHROMA_DC] = x264_coeff_last4_mmx2_lzcnt;
401             pf->coeff_last[ DCT_LUMA_AC] = x264_coeff_last15_sse2_lzcnt;
402             pf->coeff_last[DCT_LUMA_4x4] = x264_coeff_last16_sse2_lzcnt;
403             pf->coeff_last[DCT_LUMA_8x8] = x264_coeff_last64_sse2_lzcnt;
404             pf->coeff_level_run[ DCT_LUMA_AC] = x264_coeff_level_run15_sse2_lzcnt;
405             pf->coeff_level_run[DCT_LUMA_4x4] = x264_coeff_level_run16_sse2_lzcnt;
406         }
407     }
408     if( cpu&X264_CPU_SSSE3 )
409     {
410         pf->quant_4x4 = x264_quant_4x4_ssse3;
411         pf->quant_8x8 = x264_quant_8x8_ssse3;
412         pf->quant_2x2_dc = x264_quant_2x2_dc_ssse3;
413         pf->quant_4x4_dc = x264_quant_4x4_dc_ssse3;
414         pf->denoise_dct = x264_denoise_dct_ssse3;
415         pf->decimate_score15 = x264_decimate_score15_ssse3;
416         pf->decimate_score16 = x264_decimate_score16_ssse3;
417         if( cpu&X264_CPU_SLOW_CTZ )
418         {
419             pf->decimate_score15 = x264_decimate_score15_ssse3_slowctz;
420             pf->decimate_score16 = x264_decimate_score16_ssse3_slowctz;
421         }
422         pf->decimate_score64 = x264_decimate_score64_ssse3;
423     }
424     if( cpu&X264_CPU_SSE4 )
425     {
426         pf->quant_2x2_dc = x264_quant_2x2_dc_sse4;
427         pf->quant_4x4_dc = x264_quant_4x4_dc_sse4;
428         pf->quant_4x4 = x264_quant_4x4_sse4;
429         pf->quant_8x8 = x264_quant_8x8_sse4;
430     }
431 #endif // HAVE_MMX
432 #else // !HIGH_BIT_DEPTH
433 #if HAVE_MMX
434     if( cpu&X264_CPU_MMX )
435     {
436 #if ARCH_X86
437         pf->quant_4x4 = x264_quant_4x4_mmx;
438         pf->quant_8x8 = x264_quant_8x8_mmx;
439         pf->dequant_4x4 = x264_dequant_4x4_mmx;
440         pf->dequant_4x4_dc = x264_dequant_4x4dc_mmx2;
441         pf->dequant_8x8 = x264_dequant_8x8_mmx;
442         if( h->param.i_cqm_preset == X264_CQM_FLAT )
443         {
444             pf->dequant_4x4 = x264_dequant_4x4_flat16_mmx;
445             pf->dequant_8x8 = x264_dequant_8x8_flat16_mmx;
446         }
447         pf->denoise_dct = x264_denoise_dct_mmx;
448 #endif
449     }
450
451     if( cpu&X264_CPU_MMX2 )
452     {
453         pf->quant_2x2_dc = x264_quant_2x2_dc_mmx2;
454 #if ARCH_X86
455         pf->quant_4x4_dc = x264_quant_4x4_dc_mmx2;
456         pf->decimate_score15 = x264_decimate_score15_mmx2;
457         pf->decimate_score16 = x264_decimate_score16_mmx2;
458         if( cpu&X264_CPU_SLOW_CTZ )
459         {
460             pf->decimate_score15 = x264_decimate_score15_mmx2_slowctz;
461             pf->decimate_score16 = x264_decimate_score16_mmx2_slowctz;
462         }
463         pf->decimate_score64 = x264_decimate_score64_mmx2;
464         pf->coeff_last[  DCT_LUMA_AC] = x264_coeff_last15_mmx2;
465         pf->coeff_last[ DCT_LUMA_4x4] = x264_coeff_last16_mmx2;
466         pf->coeff_last[ DCT_LUMA_8x8] = x264_coeff_last64_mmx2;
467         pf->coeff_level_run[  DCT_LUMA_AC] = x264_coeff_level_run15_mmx2;
468         pf->coeff_level_run[ DCT_LUMA_4x4] = x264_coeff_level_run16_mmx2;
469 #endif
470         pf->coeff_last[DCT_CHROMA_DC] = x264_coeff_last4_mmx2;
471         pf->coeff_level_run[DCT_CHROMA_DC] = x264_coeff_level_run4_mmx2;
472         if( cpu&X264_CPU_LZCNT )
473         {
474             pf->coeff_last[DCT_CHROMA_DC] = x264_coeff_last4_mmx2_lzcnt;
475             pf->coeff_level_run[DCT_CHROMA_DC] = x264_coeff_level_run4_mmx2_lzcnt;
476         }
477     }
478
479     if( cpu&X264_CPU_SSE2 )
480     {
481         pf->quant_4x4_dc = x264_quant_4x4_dc_sse2;
482         pf->quant_4x4 = x264_quant_4x4_sse2;
483         pf->quant_8x8 = x264_quant_8x8_sse2;
484         pf->dequant_4x4 = x264_dequant_4x4_sse2;
485         pf->dequant_4x4_dc = x264_dequant_4x4dc_sse2;
486         pf->dequant_8x8 = x264_dequant_8x8_sse2;
487         if( h->param.i_cqm_preset == X264_CQM_FLAT )
488         {
489             pf->dequant_4x4 = x264_dequant_4x4_flat16_sse2;
490             pf->dequant_8x8 = x264_dequant_8x8_flat16_sse2;
491         }
492         pf->optimize_chroma_dc = x264_optimize_chroma_dc_sse2;
493         pf->denoise_dct = x264_denoise_dct_sse2;
494         pf->decimate_score15 = x264_decimate_score15_sse2;
495         pf->decimate_score16 = x264_decimate_score16_sse2;
496         pf->decimate_score64 = x264_decimate_score64_sse2;
497         if( cpu&X264_CPU_SLOW_CTZ )
498         {
499             pf->decimate_score15 = x264_decimate_score15_sse2_slowctz;
500             pf->decimate_score16 = x264_decimate_score16_sse2_slowctz;
501         }
502         pf->coeff_last[ DCT_LUMA_AC] = x264_coeff_last15_sse2;
503         pf->coeff_last[DCT_LUMA_4x4] = x264_coeff_last16_sse2;
504         pf->coeff_last[DCT_LUMA_8x8] = x264_coeff_last64_sse2;
505         pf->coeff_level_run[ DCT_LUMA_AC] = x264_coeff_level_run15_sse2;
506         pf->coeff_level_run[DCT_LUMA_4x4] = x264_coeff_level_run16_sse2;
507         if( cpu&X264_CPU_LZCNT )
508         {
509             pf->coeff_last[ DCT_LUMA_AC] = x264_coeff_last15_sse2_lzcnt;
510             pf->coeff_last[DCT_LUMA_4x4] = x264_coeff_last16_sse2_lzcnt;
511             pf->coeff_last[DCT_LUMA_8x8] = x264_coeff_last64_sse2_lzcnt;
512             pf->coeff_level_run[ DCT_LUMA_AC] = x264_coeff_level_run15_sse2_lzcnt;
513             pf->coeff_level_run[DCT_LUMA_4x4] = x264_coeff_level_run16_sse2_lzcnt;
514         }
515     }
516
517     if( cpu&X264_CPU_SSSE3 )
518     {
519         pf->quant_2x2_dc = x264_quant_2x2_dc_ssse3;
520         pf->quant_4x4_dc = x264_quant_4x4_dc_ssse3;
521         pf->quant_4x4 = x264_quant_4x4_ssse3;
522         pf->quant_8x8 = x264_quant_8x8_ssse3;
523         pf->optimize_chroma_dc = x264_optimize_chroma_dc_ssse3;
524         pf->denoise_dct = x264_denoise_dct_ssse3;
525         pf->decimate_score15 = x264_decimate_score15_ssse3;
526         pf->decimate_score16 = x264_decimate_score16_ssse3;
527         if( cpu&X264_CPU_SLOW_CTZ )
528         {
529             pf->decimate_score15 = x264_decimate_score15_ssse3_slowctz;
530             pf->decimate_score16 = x264_decimate_score16_ssse3_slowctz;
531         }
532         pf->decimate_score64 = x264_decimate_score64_ssse3;
533     }
534
535     if( cpu&X264_CPU_SSE4 )
536     {
537         pf->quant_4x4_dc = x264_quant_4x4_dc_sse4;
538         pf->quant_4x4 = x264_quant_4x4_sse4;
539         pf->quant_8x8 = x264_quant_8x8_sse4;
540         pf->optimize_chroma_dc = x264_optimize_chroma_dc_sse4;
541     }
542
543     if( cpu&X264_CPU_AVX )
544     {
545         pf->dequant_4x4 = x264_dequant_4x4_avx;
546         pf->dequant_8x8 = x264_dequant_8x8_avx;
547         pf->dequant_4x4_dc = x264_dequant_4x4dc_avx;
548         pf->optimize_chroma_dc = x264_optimize_chroma_dc_avx;
549         pf->denoise_dct = x264_denoise_dct_avx;
550     }
551 #endif // HAVE_MMX
552
553 #if HAVE_ALTIVEC
554     if( cpu&X264_CPU_ALTIVEC ) {
555         pf->quant_2x2_dc = x264_quant_2x2_dc_altivec;
556         pf->quant_4x4_dc = x264_quant_4x4_dc_altivec;
557         pf->quant_4x4 = x264_quant_4x4_altivec;
558         pf->quant_8x8 = x264_quant_8x8_altivec;
559
560         pf->dequant_4x4 = x264_dequant_4x4_altivec;
561         pf->dequant_8x8 = x264_dequant_8x8_altivec;
562     }
563 #endif
564
565 #if HAVE_ARMV6
566     if( cpu&X264_CPU_ARMV6 )
567         pf->coeff_last[DCT_CHROMA_DC] = x264_coeff_last4_arm;
568
569     if( cpu&X264_CPU_NEON )
570     {
571         pf->quant_2x2_dc   = x264_quant_2x2_dc_neon;
572         pf->quant_4x4      = x264_quant_4x4_neon;
573         pf->quant_4x4_dc   = x264_quant_4x4_dc_neon;
574         pf->quant_8x8      = x264_quant_8x8_neon;
575         pf->dequant_4x4    = x264_dequant_4x4_neon;
576         pf->dequant_4x4_dc = x264_dequant_4x4_dc_neon;
577         pf->dequant_8x8    = x264_dequant_8x8_neon;
578         pf->coeff_last[ DCT_LUMA_AC] = x264_coeff_last15_neon;
579         pf->coeff_last[DCT_LUMA_4x4] = x264_coeff_last16_neon;
580         pf->coeff_last[DCT_LUMA_8x8] = x264_coeff_last64_neon;
581     }
582 #endif
583 #endif // HIGH_BIT_DEPTH
584     pf->coeff_last[DCT_LUMA_DC]     = pf->coeff_last[DCT_CHROMAU_DC]  = pf->coeff_last[DCT_CHROMAV_DC] =
585     pf->coeff_last[DCT_CHROMAU_4x4] = pf->coeff_last[DCT_CHROMAV_4x4] = pf->coeff_last[DCT_LUMA_4x4];
586     pf->coeff_last[DCT_CHROMA_AC]   = pf->coeff_last[DCT_CHROMAU_AC]  =
587     pf->coeff_last[DCT_CHROMAV_AC]  = pf->coeff_last[DCT_LUMA_AC];
588     pf->coeff_last[DCT_CHROMAU_8x8] = pf->coeff_last[DCT_CHROMAV_8x8] = pf->coeff_last[DCT_LUMA_8x8];
589
590     pf->coeff_level_run[DCT_LUMA_DC]     = pf->coeff_level_run[DCT_CHROMAU_DC]  = pf->coeff_level_run[DCT_CHROMAV_DC] =
591     pf->coeff_level_run[DCT_CHROMAU_4x4] = pf->coeff_level_run[DCT_CHROMAV_4x4] = pf->coeff_level_run[DCT_LUMA_4x4];
592     pf->coeff_level_run[DCT_CHROMA_AC]   = pf->coeff_level_run[DCT_CHROMAU_AC]  =
593     pf->coeff_level_run[DCT_CHROMAV_AC]  = pf->coeff_level_run[DCT_LUMA_AC];
594 }