1 /*****************************************************************************
2 * quant.c: quantization and level-run
3 *****************************************************************************
4 * Copyright (C) 2005-2013 x264 project
6 * Authors: Loren Merritt <lorenm@u.washington.edu>
7 * Fiona Glaser <fiona@x264.com>
8 * Christian Heine <sennindemokrit@gmx.net>
9 * Henrik Gramner <hengar-6@student.ltu.se>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
25 * This program is also available under a commercial proprietary license.
26 * For more information, contact us at licensing@x264.com.
27 *****************************************************************************/
32 #include "x86/quant.h"
35 # include "ppc/quant.h"
38 # include "arm/quant.h"
41 #define QUANT_ONE( coef, mf, f ) \
44 (coef) = (f + (coef)) * (mf) >> 16; \
46 (coef) = - ((f - (coef)) * (mf) >> 16); \
50 static int quant_8x8( dctcoef dct[64], udctcoef mf[64], udctcoef bias[64] )
53 for( int i = 0; i < 64; i++ )
54 QUANT_ONE( dct[i], mf[i], bias[i] );
58 static int quant_4x4( dctcoef dct[16], udctcoef mf[16], udctcoef bias[16] )
61 for( int i = 0; i < 16; i++ )
62 QUANT_ONE( dct[i], mf[i], bias[i] );
66 static int quant_4x4x4( dctcoef dct[4][16], udctcoef mf[16], udctcoef bias[16] )
69 for( int j = 0; j < 4; j++ )
72 for( int i = 0; i < 16; i++ )
73 QUANT_ONE( dct[j][i], mf[i], bias[i] );
79 static int quant_4x4_dc( dctcoef dct[16], int mf, int bias )
82 for( int i = 0; i < 16; i++ )
83 QUANT_ONE( dct[i], mf, bias );
87 static int quant_2x2_dc( dctcoef dct[4], int mf, int bias )
90 QUANT_ONE( dct[0], mf, bias );
91 QUANT_ONE( dct[1], mf, bias );
92 QUANT_ONE( dct[2], mf, bias );
93 QUANT_ONE( dct[3], mf, bias );
97 #define DEQUANT_SHL( x ) \
98 dct[x] = ( dct[x] * dequant_mf[i_mf][x] ) << i_qbits
100 #define DEQUANT_SHR( x ) \
101 dct[x] = ( dct[x] * dequant_mf[i_mf][x] + f ) >> (-i_qbits)
103 static void dequant_4x4( dctcoef dct[16], int dequant_mf[6][16], int i_qp )
105 const int i_mf = i_qp%6;
106 const int i_qbits = i_qp/6 - 4;
110 for( int i = 0; i < 16; i++ )
115 const int f = 1 << (-i_qbits-1);
116 for( int i = 0; i < 16; i++ )
121 static void dequant_8x8( dctcoef dct[64], int dequant_mf[6][64], int i_qp )
123 const int i_mf = i_qp%6;
124 const int i_qbits = i_qp/6 - 6;
128 for( int i = 0; i < 64; i++ )
133 const int f = 1 << (-i_qbits-1);
134 for( int i = 0; i < 64; i++ )
139 static void dequant_4x4_dc( dctcoef dct[16], int dequant_mf[6][16], int i_qp )
141 const int i_qbits = i_qp/6 - 6;
145 const int i_dmf = dequant_mf[i_qp%6][0] << i_qbits;
146 for( int i = 0; i < 16; i++ )
151 const int i_dmf = dequant_mf[i_qp%6][0];
152 const int f = 1 << (-i_qbits-1);
153 for( int i = 0; i < 16; i++ )
154 dct[i] = ( dct[i] * i_dmf + f ) >> (-i_qbits);
158 #define IDCT_DEQUANT_2X4_START \
159 int a0 = dct[0] + dct[1]; \
160 int a1 = dct[2] + dct[3]; \
161 int a2 = dct[4] + dct[5]; \
162 int a3 = dct[6] + dct[7]; \
163 int a4 = dct[0] - dct[1]; \
164 int a5 = dct[2] - dct[3]; \
165 int a6 = dct[4] - dct[5]; \
166 int a7 = dct[6] - dct[7]; \
176 static void idct_dequant_2x4_dc( dctcoef dct[8], dctcoef dct4x4[8][16], int dequant_mf[6][16], int i_qp )
178 IDCT_DEQUANT_2X4_START
179 int dmf = dequant_mf[i_qp%6][0] << i_qp/6;
180 dct4x4[0][0] = ((b0 + b1) * dmf + 32) >> 6;
181 dct4x4[1][0] = ((b2 + b3) * dmf + 32) >> 6;
182 dct4x4[2][0] = ((b0 - b1) * dmf + 32) >> 6;
183 dct4x4[3][0] = ((b2 - b3) * dmf + 32) >> 6;
184 dct4x4[4][0] = ((b4 - b5) * dmf + 32) >> 6;
185 dct4x4[5][0] = ((b6 - b7) * dmf + 32) >> 6;
186 dct4x4[6][0] = ((b4 + b5) * dmf + 32) >> 6;
187 dct4x4[7][0] = ((b6 + b7) * dmf + 32) >> 6;
190 static void idct_dequant_2x4_dconly( dctcoef dct[8], int dequant_mf[6][16], int i_qp )
192 IDCT_DEQUANT_2X4_START
193 int dmf = dequant_mf[i_qp%6][0] << i_qp/6;
194 dct[0] = ((b0 + b1) * dmf + 32) >> 6;
195 dct[1] = ((b2 + b3) * dmf + 32) >> 6;
196 dct[2] = ((b0 - b1) * dmf + 32) >> 6;
197 dct[3] = ((b2 - b3) * dmf + 32) >> 6;
198 dct[4] = ((b4 - b5) * dmf + 32) >> 6;
199 dct[5] = ((b6 - b7) * dmf + 32) >> 6;
200 dct[6] = ((b4 + b5) * dmf + 32) >> 6;
201 dct[7] = ((b6 + b7) * dmf + 32) >> 6;
204 static ALWAYS_INLINE void optimize_chroma_idct_dequant_2x4( dctcoef out[8], dctcoef dct[8], int dmf )
206 IDCT_DEQUANT_2X4_START
207 out[0] = ((b0 + b1) * dmf + 2080) >> 6; /* 2080 = 32 + (32<<6) */
208 out[1] = ((b2 + b3) * dmf + 2080) >> 6;
209 out[2] = ((b0 - b1) * dmf + 2080) >> 6;
210 out[3] = ((b2 - b3) * dmf + 2080) >> 6;
211 out[4] = ((b4 - b5) * dmf + 2080) >> 6;
212 out[5] = ((b6 - b7) * dmf + 2080) >> 6;
213 out[6] = ((b4 + b5) * dmf + 2080) >> 6;
214 out[7] = ((b6 + b7) * dmf + 2080) >> 6;
216 #undef IDCT_DEQUANT_2X4_START
218 static ALWAYS_INLINE void optimize_chroma_idct_dequant_2x2( dctcoef out[4], dctcoef dct[4], int dmf )
220 int d0 = dct[0] + dct[1];
221 int d1 = dct[2] + dct[3];
222 int d2 = dct[0] - dct[1];
223 int d3 = dct[2] - dct[3];
224 out[0] = ((d0 + d1) * dmf >> 5) + 32;
225 out[1] = ((d0 - d1) * dmf >> 5) + 32;
226 out[2] = ((d2 + d3) * dmf >> 5) + 32;
227 out[3] = ((d2 - d3) * dmf >> 5) + 32;
230 static ALWAYS_INLINE int optimize_chroma_round( dctcoef *ref, dctcoef *dct, int dequant_mf, int chroma422 )
235 optimize_chroma_idct_dequant_2x4( out, dct, dequant_mf );
237 optimize_chroma_idct_dequant_2x2( out, dct, dequant_mf );
240 for( int i = 0; i < (chroma422?8:4); i++ )
241 sum |= ref[i] ^ out[i];
245 static ALWAYS_INLINE int optimize_chroma_dc_internal( dctcoef *dct, int dequant_mf, int chroma422 )
247 /* dequant_mf = h->dequant4_mf[CQM_4IC + b_inter][i_qp%6][0] << i_qp/6, max 32*64 */
252 optimize_chroma_idct_dequant_2x4( dct_orig, dct, dequant_mf );
254 optimize_chroma_idct_dequant_2x2( dct_orig, dct, dequant_mf );
256 /* If the DC coefficients already round to zero, terminate early. */
258 for( int i = 0; i < (chroma422?8:4); i++ )
263 /* Start with the highest frequency coefficient... is this the best option? */
264 for( nz = 0, coeff = (chroma422?7:3); coeff >= 0; coeff-- )
266 int level = dct[coeff];
267 int sign = level>>31 | 1; /* dct[coeff] < 0 ? -1 : 1 */
271 dct[coeff] = level - sign;
272 if( optimize_chroma_round( dct_orig, dct, dequant_mf, chroma422 ) )
285 static int optimize_chroma_2x2_dc( dctcoef dct[4], int dequant_mf )
287 return optimize_chroma_dc_internal( dct, dequant_mf, 0 );
290 static int optimize_chroma_2x4_dc( dctcoef dct[8], int dequant_mf )
292 return optimize_chroma_dc_internal( dct, dequant_mf, 1 );
295 static void x264_denoise_dct( dctcoef *dct, uint32_t *sum, udctcoef *offset, int size )
297 for( int i = 0; i < size; i++ )
300 int sign = level>>31;
301 level = (level+sign)^sign;
304 dct[i] = level<0 ? 0 : (level^sign)-sign;
309 * x264_mb_decimate_score: given dct coeffs it returns a score to see if we could empty this dct coeffs
310 * to 0 (low score means set it to null)
311 * Used in inter macroblock (luma and chroma)
312 * luma: for a 8x8 block: if score < 4 -> null
313 * for the complete mb: if score < 6 -> null
314 * chroma: for the complete mb: if score < 7 -> null
317 const uint8_t x264_decimate_table4[16] =
319 3,2,2,1,1,1,0,0,0,0,0,0,0,0,0,0
321 const uint8_t x264_decimate_table8[64] =
323 3,3,3,3,2,2,2,2,2,2,2,2,1,1,1,1,
324 1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,
325 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
326 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
329 static int ALWAYS_INLINE x264_decimate_score_internal( dctcoef *dct, int i_max )
331 const uint8_t *ds_table = (i_max == 64) ? x264_decimate_table8 : x264_decimate_table4;
335 while( idx >= 0 && dct[idx] == 0 )
341 if( (unsigned)(dct[idx--] + 1) > 2 )
345 while( idx >= 0 && dct[idx] == 0 )
350 i_score += ds_table[i_run];
356 static int x264_decimate_score15( dctcoef *dct )
358 return x264_decimate_score_internal( dct+1, 15 );
360 static int x264_decimate_score16( dctcoef *dct )
362 return x264_decimate_score_internal( dct, 16 );
364 static int x264_decimate_score64( dctcoef *dct )
366 return x264_decimate_score_internal( dct, 64 );
370 static int x264_coeff_last##num( dctcoef *l )\
373 while( i_last >= 0 && l[i_last] == 0 )\
384 #define level_run(num)\
385 static int x264_coeff_level_run##num( dctcoef *dct, x264_run_level_t *runlevel )\
387 int i_last = runlevel->last = x264_coeff_last##num(dct);\
392 runlevel->level[i_total++] = dct[i_last];\
393 mask |= 1 << (i_last);\
394 while( --i_last >= 0 && dct[i_last] == 0 );\
395 } while( i_last >= 0 );\
396 runlevel->mask = mask;\
406 #define INIT_TRELLIS(cpu)\
407 pf->trellis_cabac_4x4 = x264_trellis_cabac_4x4_##cpu;\
408 pf->trellis_cabac_8x8 = x264_trellis_cabac_8x8_##cpu;\
409 pf->trellis_cabac_4x4_psy = x264_trellis_cabac_4x4_psy_##cpu;\
410 pf->trellis_cabac_8x8_psy = x264_trellis_cabac_8x8_psy_##cpu;\
411 pf->trellis_cabac_dc = x264_trellis_cabac_dc_##cpu;\
412 pf->trellis_cabac_chroma_422_dc = x264_trellis_cabac_chroma_422_dc_##cpu;
414 #define INIT_TRELLIS(...)
417 void x264_quant_init( x264_t *h, int cpu, x264_quant_function_t *pf )
419 pf->quant_8x8 = quant_8x8;
420 pf->quant_4x4 = quant_4x4;
421 pf->quant_4x4x4 = quant_4x4x4;
422 pf->quant_4x4_dc = quant_4x4_dc;
423 pf->quant_2x2_dc = quant_2x2_dc;
425 pf->dequant_4x4 = dequant_4x4;
426 pf->dequant_4x4_dc = dequant_4x4_dc;
427 pf->dequant_8x8 = dequant_8x8;
429 pf->idct_dequant_2x4_dc = idct_dequant_2x4_dc;
430 pf->idct_dequant_2x4_dconly = idct_dequant_2x4_dconly;
432 pf->optimize_chroma_2x2_dc = optimize_chroma_2x2_dc;
433 pf->optimize_chroma_2x4_dc = optimize_chroma_2x4_dc;
435 pf->denoise_dct = x264_denoise_dct;
436 pf->decimate_score15 = x264_decimate_score15;
437 pf->decimate_score16 = x264_decimate_score16;
438 pf->decimate_score64 = x264_decimate_score64;
440 pf->coeff_last4 = x264_coeff_last4;
441 pf->coeff_last8 = x264_coeff_last8;
442 pf->coeff_last[ DCT_LUMA_AC] = x264_coeff_last15;
443 pf->coeff_last[ DCT_LUMA_4x4] = x264_coeff_last16;
444 pf->coeff_last[ DCT_LUMA_8x8] = x264_coeff_last64;
445 pf->coeff_level_run4 = x264_coeff_level_run4;
446 pf->coeff_level_run8 = x264_coeff_level_run8;
447 pf->coeff_level_run[ DCT_LUMA_AC] = x264_coeff_level_run15;
448 pf->coeff_level_run[ DCT_LUMA_4x4] = x264_coeff_level_run16;
452 INIT_TRELLIS( sse2 );
453 if( cpu&X264_CPU_MMX2 )
456 pf->denoise_dct = x264_denoise_dct_mmx;
457 pf->decimate_score15 = x264_decimate_score15_mmx2;
458 pf->decimate_score16 = x264_decimate_score16_mmx2;
459 pf->decimate_score64 = x264_decimate_score64_mmx2;
460 pf->coeff_last8 = x264_coeff_last8_mmx2;
461 pf->coeff_last[ DCT_LUMA_AC] = x264_coeff_last15_mmx2;
462 pf->coeff_last[ DCT_LUMA_4x4] = x264_coeff_last16_mmx2;
463 pf->coeff_last[ DCT_LUMA_8x8] = x264_coeff_last64_mmx2;
464 pf->coeff_level_run8 = x264_coeff_level_run8_mmx2;
465 pf->coeff_level_run[ DCT_LUMA_AC] = x264_coeff_level_run15_mmx2;
466 pf->coeff_level_run[ DCT_LUMA_4x4] = x264_coeff_level_run16_mmx2;
468 pf->coeff_last4 = x264_coeff_last4_mmx2;
469 pf->coeff_level_run4 = x264_coeff_level_run4_mmx2;
470 if( cpu&X264_CPU_LZCNT )
471 pf->coeff_level_run4 = x264_coeff_level_run4_mmx2_lzcnt;
473 if( cpu&X264_CPU_SSE2 )
475 pf->quant_4x4 = x264_quant_4x4_sse2;
476 pf->quant_4x4x4 = x264_quant_4x4x4_sse2;
477 pf->quant_8x8 = x264_quant_8x8_sse2;
478 pf->quant_2x2_dc = x264_quant_2x2_dc_sse2;
479 pf->quant_4x4_dc = x264_quant_4x4_dc_sse2;
480 pf->dequant_4x4 = x264_dequant_4x4_sse2;
481 pf->dequant_8x8 = x264_dequant_8x8_sse2;
482 pf->dequant_4x4_dc = x264_dequant_4x4dc_sse2;
483 pf->denoise_dct = x264_denoise_dct_sse2;
484 pf->decimate_score15 = x264_decimate_score15_sse2;
485 pf->decimate_score16 = x264_decimate_score16_sse2;
486 pf->decimate_score64 = x264_decimate_score64_sse2;
487 pf->coeff_last8 = x264_coeff_last8_sse2;
488 pf->coeff_last[ DCT_LUMA_AC] = x264_coeff_last15_sse2;
489 pf->coeff_last[DCT_LUMA_4x4] = x264_coeff_last16_sse2;
490 pf->coeff_last[DCT_LUMA_8x8] = x264_coeff_last64_sse2;
491 pf->coeff_level_run8 = x264_coeff_level_run8_sse2;
492 pf->coeff_level_run[ DCT_LUMA_AC] = x264_coeff_level_run15_sse2;
493 pf->coeff_level_run[DCT_LUMA_4x4] = x264_coeff_level_run16_sse2;
494 if( cpu&X264_CPU_LZCNT )
496 pf->coeff_last4 = x264_coeff_last4_mmx2_lzcnt;
497 pf->coeff_last8 = x264_coeff_last8_sse2_lzcnt;
498 pf->coeff_last[ DCT_LUMA_AC] = x264_coeff_last15_sse2_lzcnt;
499 pf->coeff_last[DCT_LUMA_4x4] = x264_coeff_last16_sse2_lzcnt;
500 pf->coeff_last[DCT_LUMA_8x8] = x264_coeff_last64_sse2_lzcnt;
501 pf->coeff_level_run8 = x264_coeff_level_run8_sse2_lzcnt;
502 pf->coeff_level_run[ DCT_LUMA_AC] = x264_coeff_level_run15_sse2_lzcnt;
503 pf->coeff_level_run[DCT_LUMA_4x4] = x264_coeff_level_run16_sse2_lzcnt;
506 if( cpu&X264_CPU_SSSE3 )
508 pf->quant_4x4 = x264_quant_4x4_ssse3;
509 pf->quant_4x4x4 = x264_quant_4x4x4_ssse3;
510 pf->quant_8x8 = x264_quant_8x8_ssse3;
511 pf->quant_2x2_dc = x264_quant_2x2_dc_ssse3;
512 pf->quant_4x4_dc = x264_quant_4x4_dc_ssse3;
513 pf->denoise_dct = x264_denoise_dct_ssse3;
514 pf->decimate_score15 = x264_decimate_score15_ssse3;
515 pf->decimate_score16 = x264_decimate_score16_ssse3;
516 pf->decimate_score64 = x264_decimate_score64_ssse3;
517 INIT_TRELLIS( ssse3 );
519 if( cpu&X264_CPU_SSE4 )
521 pf->quant_2x2_dc = x264_quant_2x2_dc_sse4;
522 pf->quant_4x4_dc = x264_quant_4x4_dc_sse4;
523 pf->quant_4x4 = x264_quant_4x4_sse4;
524 pf->quant_4x4x4 = x264_quant_4x4x4_sse4;
525 pf->quant_8x8 = x264_quant_8x8_sse4;
527 if( cpu&X264_CPU_AVX )
529 pf->denoise_dct = x264_denoise_dct_avx;
531 if( cpu&X264_CPU_XOP )
533 pf->dequant_4x4_dc = x264_dequant_4x4dc_xop;
534 if( h->param.i_cqm_preset != X264_CQM_FLAT )
536 pf->dequant_4x4 = x264_dequant_4x4_xop;
537 pf->dequant_8x8 = x264_dequant_8x8_xop;
541 #else // !HIGH_BIT_DEPTH
543 INIT_TRELLIS( sse2 );
544 if( cpu&X264_CPU_MMX )
547 pf->quant_4x4 = x264_quant_4x4_mmx;
548 pf->quant_4x4x4 = x264_quant_4x4x4_mmx;
549 pf->quant_8x8 = x264_quant_8x8_mmx;
550 pf->dequant_4x4 = x264_dequant_4x4_mmx;
551 pf->dequant_4x4_dc = x264_dequant_4x4dc_mmx2;
552 pf->dequant_8x8 = x264_dequant_8x8_mmx;
553 if( h->param.i_cqm_preset == X264_CQM_FLAT )
555 pf->dequant_4x4 = x264_dequant_4x4_flat16_mmx;
556 pf->dequant_8x8 = x264_dequant_8x8_flat16_mmx;
558 pf->denoise_dct = x264_denoise_dct_mmx;
562 if( cpu&X264_CPU_MMX2 )
564 pf->quant_2x2_dc = x264_quant_2x2_dc_mmx2;
566 pf->quant_4x4_dc = x264_quant_4x4_dc_mmx2;
567 pf->decimate_score15 = x264_decimate_score15_mmx2;
568 pf->decimate_score16 = x264_decimate_score16_mmx2;
569 pf->decimate_score64 = x264_decimate_score64_mmx2;
570 pf->coeff_last[ DCT_LUMA_AC] = x264_coeff_last15_mmx2;
571 pf->coeff_last[ DCT_LUMA_4x4] = x264_coeff_last16_mmx2;
572 pf->coeff_last[ DCT_LUMA_8x8] = x264_coeff_last64_mmx2;
573 pf->coeff_level_run[ DCT_LUMA_AC] = x264_coeff_level_run15_mmx2;
574 pf->coeff_level_run[ DCT_LUMA_4x4] = x264_coeff_level_run16_mmx2;
576 pf->coeff_last4 = x264_coeff_last4_mmx2;
577 pf->coeff_last8 = x264_coeff_last8_mmx2;
578 pf->coeff_level_run4 = x264_coeff_level_run4_mmx2;
579 pf->coeff_level_run8 = x264_coeff_level_run8_mmx2;
580 if( cpu&X264_CPU_LZCNT )
582 pf->coeff_last4 = x264_coeff_last4_mmx2_lzcnt;
583 pf->coeff_last8 = x264_coeff_last8_mmx2_lzcnt;
584 pf->coeff_level_run4 = x264_coeff_level_run4_mmx2_lzcnt;
585 pf->coeff_level_run8 = x264_coeff_level_run8_mmx2_lzcnt;
589 if( cpu&X264_CPU_SSE2 )
591 pf->quant_4x4_dc = x264_quant_4x4_dc_sse2;
592 pf->quant_4x4 = x264_quant_4x4_sse2;
593 pf->quant_4x4x4 = x264_quant_4x4x4_sse2;
594 pf->quant_8x8 = x264_quant_8x8_sse2;
595 pf->dequant_4x4 = x264_dequant_4x4_sse2;
596 pf->dequant_4x4_dc = x264_dequant_4x4dc_sse2;
597 pf->dequant_8x8 = x264_dequant_8x8_sse2;
598 if( h->param.i_cqm_preset == X264_CQM_FLAT )
600 pf->dequant_4x4 = x264_dequant_4x4_flat16_sse2;
601 pf->dequant_8x8 = x264_dequant_8x8_flat16_sse2;
603 pf->optimize_chroma_2x2_dc = x264_optimize_chroma_2x2_dc_sse2;
604 pf->denoise_dct = x264_denoise_dct_sse2;
605 pf->decimate_score15 = x264_decimate_score15_sse2;
606 pf->decimate_score16 = x264_decimate_score16_sse2;
607 pf->decimate_score64 = x264_decimate_score64_sse2;
608 pf->coeff_last[ DCT_LUMA_AC] = x264_coeff_last15_sse2;
609 pf->coeff_last[DCT_LUMA_4x4] = x264_coeff_last16_sse2;
610 pf->coeff_last[DCT_LUMA_8x8] = x264_coeff_last64_sse2;
611 pf->coeff_level_run[ DCT_LUMA_AC] = x264_coeff_level_run15_sse2;
612 pf->coeff_level_run[DCT_LUMA_4x4] = x264_coeff_level_run16_sse2;
613 if( cpu&X264_CPU_LZCNT )
615 pf->coeff_last[ DCT_LUMA_AC] = x264_coeff_last15_sse2_lzcnt;
616 pf->coeff_last[DCT_LUMA_4x4] = x264_coeff_last16_sse2_lzcnt;
617 pf->coeff_last[DCT_LUMA_8x8] = x264_coeff_last64_sse2_lzcnt;
618 pf->coeff_level_run[ DCT_LUMA_AC] = x264_coeff_level_run15_sse2_lzcnt;
619 pf->coeff_level_run[DCT_LUMA_4x4] = x264_coeff_level_run16_sse2_lzcnt;
623 if( cpu&X264_CPU_SSSE3 )
625 pf->quant_2x2_dc = x264_quant_2x2_dc_ssse3;
626 pf->quant_4x4_dc = x264_quant_4x4_dc_ssse3;
627 pf->quant_4x4 = x264_quant_4x4_ssse3;
628 pf->quant_4x4x4 = x264_quant_4x4x4_ssse3;
629 pf->quant_8x8 = x264_quant_8x8_ssse3;
630 pf->optimize_chroma_2x2_dc = x264_optimize_chroma_2x2_dc_ssse3;
631 pf->denoise_dct = x264_denoise_dct_ssse3;
632 pf->decimate_score15 = x264_decimate_score15_ssse3;
633 pf->decimate_score16 = x264_decimate_score16_ssse3;
634 pf->decimate_score64 = x264_decimate_score64_ssse3;
635 INIT_TRELLIS( ssse3 );
636 pf->coeff_level_run4 = x264_coeff_level_run4_ssse3;
637 pf->coeff_level_run8 = x264_coeff_level_run8_ssse3;
638 pf->coeff_level_run[ DCT_LUMA_AC] = x264_coeff_level_run15_ssse3;
639 pf->coeff_level_run[DCT_LUMA_4x4] = x264_coeff_level_run16_ssse3;
640 if( cpu&X264_CPU_LZCNT )
642 pf->coeff_level_run4 = x264_coeff_level_run4_ssse3;
643 pf->coeff_level_run8 = x264_coeff_level_run8_ssse3;
644 pf->coeff_level_run[ DCT_LUMA_AC] = x264_coeff_level_run15_ssse3_lzcnt;
645 pf->coeff_level_run[DCT_LUMA_4x4] = x264_coeff_level_run16_ssse3_lzcnt;
649 if( cpu&X264_CPU_SSE4 )
651 pf->quant_4x4_dc = x264_quant_4x4_dc_sse4;
652 pf->quant_4x4 = x264_quant_4x4_sse4;
653 pf->quant_8x8 = x264_quant_8x8_sse4;
654 pf->optimize_chroma_2x2_dc = x264_optimize_chroma_2x2_dc_sse4;
657 if( cpu&X264_CPU_AVX )
659 pf->dequant_4x4_dc = x264_dequant_4x4dc_avx;
660 if( h->param.i_cqm_preset != X264_CQM_FLAT )
662 pf->dequant_4x4 = x264_dequant_4x4_avx;
663 pf->dequant_8x8 = x264_dequant_8x8_avx;
665 pf->optimize_chroma_2x2_dc = x264_optimize_chroma_2x2_dc_avx;
666 pf->denoise_dct = x264_denoise_dct_avx;
669 if( cpu&X264_CPU_XOP )
671 if( h->param.i_cqm_preset != X264_CQM_FLAT )
673 pf->dequant_4x4 = x264_dequant_4x4_xop;
674 pf->dequant_8x8 = x264_dequant_8x8_xop;
678 if( cpu&X264_CPU_AVX2 )
680 pf->quant_4x4 = x264_quant_4x4_avx2;
681 pf->quant_4x4_dc = x264_quant_4x4_dc_avx2;
682 pf->quant_8x8 = x264_quant_8x8_avx2;
683 pf->quant_4x4x4 = x264_quant_4x4x4_avx2;
684 if( cpu&X264_CPU_LZCNT )
685 pf->coeff_last[DCT_LUMA_8x8] = x264_coeff_last64_avx2_lzcnt;
686 pf->dequant_4x4 = x264_dequant_4x4_avx2;
687 pf->dequant_8x8 = x264_dequant_8x8_avx2;
688 if( h->param.i_cqm_preset == X264_CQM_FLAT )
690 pf->dequant_4x4 = x264_dequant_4x4_flat16_avx2;
691 pf->dequant_8x8 = x264_dequant_8x8_flat16_avx2;
693 pf->decimate_score64 = x264_decimate_score64_avx2;
694 pf->denoise_dct = x264_denoise_dct_avx2;
695 if( cpu&X264_CPU_LZCNT )
697 pf->coeff_level_run[ DCT_LUMA_AC] = x264_coeff_level_run15_avx2_lzcnt;
698 pf->coeff_level_run[DCT_LUMA_4x4] = x264_coeff_level_run16_avx2_lzcnt;
704 if( cpu&X264_CPU_ALTIVEC ) {
705 pf->quant_2x2_dc = x264_quant_2x2_dc_altivec;
706 pf->quant_4x4_dc = x264_quant_4x4_dc_altivec;
707 pf->quant_4x4 = x264_quant_4x4_altivec;
708 pf->quant_8x8 = x264_quant_8x8_altivec;
710 pf->dequant_4x4 = x264_dequant_4x4_altivec;
711 pf->dequant_8x8 = x264_dequant_8x8_altivec;
716 if( cpu&X264_CPU_ARMV6 )
717 pf->coeff_last4 = x264_coeff_last4_arm;
719 if( cpu&X264_CPU_NEON )
721 pf->quant_2x2_dc = x264_quant_2x2_dc_neon;
722 pf->quant_4x4 = x264_quant_4x4_neon;
723 pf->quant_4x4_dc = x264_quant_4x4_dc_neon;
724 pf->quant_4x4x4 = x264_quant_4x4x4_neon;
725 pf->quant_8x8 = x264_quant_8x8_neon;
726 pf->dequant_4x4 = x264_dequant_4x4_neon;
727 pf->dequant_4x4_dc = x264_dequant_4x4_dc_neon;
728 pf->dequant_8x8 = x264_dequant_8x8_neon;
729 pf->coeff_last[ DCT_LUMA_AC] = x264_coeff_last15_neon;
730 pf->coeff_last[DCT_LUMA_4x4] = x264_coeff_last16_neon;
731 pf->coeff_last[DCT_LUMA_8x8] = x264_coeff_last64_neon;
734 #endif // HIGH_BIT_DEPTH
735 pf->coeff_last[DCT_LUMA_DC] = pf->coeff_last[DCT_CHROMAU_DC] = pf->coeff_last[DCT_CHROMAV_DC] =
736 pf->coeff_last[DCT_CHROMAU_4x4] = pf->coeff_last[DCT_CHROMAV_4x4] = pf->coeff_last[DCT_LUMA_4x4];
737 pf->coeff_last[DCT_CHROMA_AC] = pf->coeff_last[DCT_CHROMAU_AC] =
738 pf->coeff_last[DCT_CHROMAV_AC] = pf->coeff_last[DCT_LUMA_AC];
739 pf->coeff_last[DCT_CHROMAU_8x8] = pf->coeff_last[DCT_CHROMAV_8x8] = pf->coeff_last[DCT_LUMA_8x8];
741 pf->coeff_level_run[DCT_LUMA_DC] = pf->coeff_level_run[DCT_CHROMAU_DC] = pf->coeff_level_run[DCT_CHROMAV_DC] =
742 pf->coeff_level_run[DCT_CHROMAU_4x4] = pf->coeff_level_run[DCT_CHROMAV_4x4] = pf->coeff_level_run[DCT_LUMA_4x4];
743 pf->coeff_level_run[DCT_CHROMA_AC] = pf->coeff_level_run[DCT_CHROMAU_AC] =
744 pf->coeff_level_run[DCT_CHROMAV_AC] = pf->coeff_level_run[DCT_LUMA_AC];