1 /*****************************************************************************
2 * quant.c: quantization and level-run
3 *****************************************************************************
4 * Copyright (C) 2005-2016 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 <henrik@gramner.com>
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 # include "aarch64/quant.h"
44 # include "mips/quant.h"
47 #define QUANT_ONE( coef, mf, f ) \
50 (coef) = (f + (coef)) * (mf) >> 16; \
52 (coef) = - ((f - (coef)) * (mf) >> 16); \
56 static int quant_8x8( dctcoef dct[64], udctcoef mf[64], udctcoef bias[64] )
59 for( int i = 0; i < 64; i++ )
60 QUANT_ONE( dct[i], mf[i], bias[i] );
64 static int quant_4x4( dctcoef dct[16], udctcoef mf[16], udctcoef bias[16] )
67 for( int i = 0; i < 16; i++ )
68 QUANT_ONE( dct[i], mf[i], bias[i] );
72 static int quant_4x4x4( dctcoef dct[4][16], udctcoef mf[16], udctcoef bias[16] )
75 for( int j = 0; j < 4; j++ )
78 for( int i = 0; i < 16; i++ )
79 QUANT_ONE( dct[j][i], mf[i], bias[i] );
85 static int quant_4x4_dc( dctcoef dct[16], int mf, int bias )
88 for( int i = 0; i < 16; i++ )
89 QUANT_ONE( dct[i], mf, bias );
93 static int quant_2x2_dc( dctcoef dct[4], int mf, int bias )
96 QUANT_ONE( dct[0], mf, bias );
97 QUANT_ONE( dct[1], mf, bias );
98 QUANT_ONE( dct[2], mf, bias );
99 QUANT_ONE( dct[3], mf, bias );
103 #define DEQUANT_SHL( x ) \
104 dct[x] = ( dct[x] * dequant_mf[i_mf][x] ) << i_qbits
106 #define DEQUANT_SHR( x ) \
107 dct[x] = ( dct[x] * dequant_mf[i_mf][x] + f ) >> (-i_qbits)
109 static void dequant_4x4( dctcoef dct[16], int dequant_mf[6][16], int i_qp )
111 const int i_mf = i_qp%6;
112 const int i_qbits = i_qp/6 - 4;
116 for( int i = 0; i < 16; i++ )
121 const int f = 1 << (-i_qbits-1);
122 for( int i = 0; i < 16; i++ )
127 static void dequant_8x8( dctcoef dct[64], int dequant_mf[6][64], int i_qp )
129 const int i_mf = i_qp%6;
130 const int i_qbits = i_qp/6 - 6;
134 for( int i = 0; i < 64; i++ )
139 const int f = 1 << (-i_qbits-1);
140 for( int i = 0; i < 64; i++ )
145 static void dequant_4x4_dc( dctcoef dct[16], int dequant_mf[6][16], int i_qp )
147 const int i_qbits = i_qp/6 - 6;
151 const int i_dmf = dequant_mf[i_qp%6][0] << i_qbits;
152 for( int i = 0; i < 16; i++ )
157 const int i_dmf = dequant_mf[i_qp%6][0];
158 const int f = 1 << (-i_qbits-1);
159 for( int i = 0; i < 16; i++ )
160 dct[i] = ( dct[i] * i_dmf + f ) >> (-i_qbits);
164 #define IDCT_DEQUANT_2X4_START \
165 int a0 = dct[0] + dct[1]; \
166 int a1 = dct[2] + dct[3]; \
167 int a2 = dct[4] + dct[5]; \
168 int a3 = dct[6] + dct[7]; \
169 int a4 = dct[0] - dct[1]; \
170 int a5 = dct[2] - dct[3]; \
171 int a6 = dct[4] - dct[5]; \
172 int a7 = dct[6] - dct[7]; \
182 static void idct_dequant_2x4_dc( dctcoef dct[8], dctcoef dct4x4[8][16], int dequant_mf[6][16], int i_qp )
184 IDCT_DEQUANT_2X4_START
185 int dmf = dequant_mf[i_qp%6][0] << i_qp/6;
186 dct4x4[0][0] = ((b0 + b1) * dmf + 32) >> 6;
187 dct4x4[1][0] = ((b2 + b3) * dmf + 32) >> 6;
188 dct4x4[2][0] = ((b0 - b1) * dmf + 32) >> 6;
189 dct4x4[3][0] = ((b2 - b3) * dmf + 32) >> 6;
190 dct4x4[4][0] = ((b4 - b5) * dmf + 32) >> 6;
191 dct4x4[5][0] = ((b6 - b7) * dmf + 32) >> 6;
192 dct4x4[6][0] = ((b4 + b5) * dmf + 32) >> 6;
193 dct4x4[7][0] = ((b6 + b7) * dmf + 32) >> 6;
196 static void idct_dequant_2x4_dconly( dctcoef dct[8], int dequant_mf[6][16], int i_qp )
198 IDCT_DEQUANT_2X4_START
199 int dmf = dequant_mf[i_qp%6][0] << i_qp/6;
200 dct[0] = ((b0 + b1) * dmf + 32) >> 6;
201 dct[1] = ((b2 + b3) * dmf + 32) >> 6;
202 dct[2] = ((b0 - b1) * dmf + 32) >> 6;
203 dct[3] = ((b2 - b3) * dmf + 32) >> 6;
204 dct[4] = ((b4 - b5) * dmf + 32) >> 6;
205 dct[5] = ((b6 - b7) * dmf + 32) >> 6;
206 dct[6] = ((b4 + b5) * dmf + 32) >> 6;
207 dct[7] = ((b6 + b7) * dmf + 32) >> 6;
210 static ALWAYS_INLINE void optimize_chroma_idct_dequant_2x4( dctcoef out[8], dctcoef dct[8], int dmf )
212 IDCT_DEQUANT_2X4_START
213 out[0] = ((b0 + b1) * dmf + 2080) >> 6; /* 2080 = 32 + (32<<6) */
214 out[1] = ((b2 + b3) * dmf + 2080) >> 6;
215 out[2] = ((b0 - b1) * dmf + 2080) >> 6;
216 out[3] = ((b2 - b3) * dmf + 2080) >> 6;
217 out[4] = ((b4 - b5) * dmf + 2080) >> 6;
218 out[5] = ((b6 - b7) * dmf + 2080) >> 6;
219 out[6] = ((b4 + b5) * dmf + 2080) >> 6;
220 out[7] = ((b6 + b7) * dmf + 2080) >> 6;
222 #undef IDCT_DEQUANT_2X4_START
224 static ALWAYS_INLINE void optimize_chroma_idct_dequant_2x2( dctcoef out[4], dctcoef dct[4], int dmf )
226 int d0 = dct[0] + dct[1];
227 int d1 = dct[2] + dct[3];
228 int d2 = dct[0] - dct[1];
229 int d3 = dct[2] - dct[3];
230 out[0] = ((d0 + d1) * dmf >> 5) + 32;
231 out[1] = ((d0 - d1) * dmf >> 5) + 32;
232 out[2] = ((d2 + d3) * dmf >> 5) + 32;
233 out[3] = ((d2 - d3) * dmf >> 5) + 32;
236 static ALWAYS_INLINE int optimize_chroma_round( dctcoef *ref, dctcoef *dct, int dequant_mf, int chroma422 )
241 optimize_chroma_idct_dequant_2x4( out, dct, dequant_mf );
243 optimize_chroma_idct_dequant_2x2( out, dct, dequant_mf );
246 for( int i = 0; i < (chroma422?8:4); i++ )
247 sum |= ref[i] ^ out[i];
251 static ALWAYS_INLINE int optimize_chroma_dc_internal( dctcoef *dct, int dequant_mf, int chroma422 )
253 /* dequant_mf = h->dequant4_mf[CQM_4IC + b_inter][i_qp%6][0] << i_qp/6, max 32*64 */
258 optimize_chroma_idct_dequant_2x4( dct_orig, dct, dequant_mf );
260 optimize_chroma_idct_dequant_2x2( dct_orig, dct, dequant_mf );
262 /* If the DC coefficients already round to zero, terminate early. */
264 for( int i = 0; i < (chroma422?8:4); i++ )
269 /* Start with the highest frequency coefficient... is this the best option? */
270 for( nz = 0, coeff = (chroma422?7:3); coeff >= 0; coeff-- )
272 int level = dct[coeff];
273 int sign = level>>31 | 1; /* dct[coeff] < 0 ? -1 : 1 */
277 dct[coeff] = level - sign;
278 if( optimize_chroma_round( dct_orig, dct, dequant_mf, chroma422 ) )
291 static int optimize_chroma_2x2_dc( dctcoef dct[4], int dequant_mf )
293 return optimize_chroma_dc_internal( dct, dequant_mf, 0 );
296 static int optimize_chroma_2x4_dc( dctcoef dct[8], int dequant_mf )
298 return optimize_chroma_dc_internal( dct, dequant_mf, 1 );
301 static void x264_denoise_dct( dctcoef *dct, uint32_t *sum, udctcoef *offset, int size )
303 for( int i = 0; i < size; i++ )
306 int sign = level>>31;
307 level = (level+sign)^sign;
310 dct[i] = level<0 ? 0 : (level^sign)-sign;
315 * x264_mb_decimate_score: given dct coeffs it returns a score to see if we could empty this dct coeffs
316 * to 0 (low score means set it to null)
317 * Used in inter macroblock (luma and chroma)
318 * luma: for a 8x8 block: if score < 4 -> null
319 * for the complete mb: if score < 6 -> null
320 * chroma: for the complete mb: if score < 7 -> null
323 const uint8_t x264_decimate_table4[16] =
325 3,2,2,1,1,1,0,0,0,0,0,0,0,0,0,0
327 const uint8_t x264_decimate_table8[64] =
329 3,3,3,3,2,2,2,2,2,2,2,2,1,1,1,1,
330 1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,
331 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
332 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
335 static int ALWAYS_INLINE x264_decimate_score_internal( dctcoef *dct, int i_max )
337 const uint8_t *ds_table = (i_max == 64) ? x264_decimate_table8 : x264_decimate_table4;
341 while( idx >= 0 && dct[idx] == 0 )
347 if( (unsigned)(dct[idx--] + 1) > 2 )
351 while( idx >= 0 && dct[idx] == 0 )
356 i_score += ds_table[i_run];
362 static int x264_decimate_score15( dctcoef *dct )
364 return x264_decimate_score_internal( dct+1, 15 );
366 static int x264_decimate_score16( dctcoef *dct )
368 return x264_decimate_score_internal( dct, 16 );
370 static int x264_decimate_score64( dctcoef *dct )
372 return x264_decimate_score_internal( dct, 64 );
376 static int x264_coeff_last##num( dctcoef *l )\
379 while( i_last >= 0 && l[i_last] == 0 )\
390 #define level_run(num)\
391 static int x264_coeff_level_run##num( dctcoef *dct, x264_run_level_t *runlevel )\
393 int i_last = runlevel->last = x264_coeff_last##num(dct);\
398 runlevel->level[i_total++] = dct[i_last];\
399 mask |= 1 << (i_last);\
400 while( --i_last >= 0 && dct[i_last] == 0 );\
401 } while( i_last >= 0 );\
402 runlevel->mask = mask;\
412 #define INIT_TRELLIS(cpu)\
413 pf->trellis_cabac_4x4 = x264_trellis_cabac_4x4_##cpu;\
414 pf->trellis_cabac_8x8 = x264_trellis_cabac_8x8_##cpu;\
415 pf->trellis_cabac_4x4_psy = x264_trellis_cabac_4x4_psy_##cpu;\
416 pf->trellis_cabac_8x8_psy = x264_trellis_cabac_8x8_psy_##cpu;\
417 pf->trellis_cabac_dc = x264_trellis_cabac_dc_##cpu;\
418 pf->trellis_cabac_chroma_422_dc = x264_trellis_cabac_chroma_422_dc_##cpu;
420 #define INIT_TRELLIS(...)
423 void x264_quant_init( x264_t *h, int cpu, x264_quant_function_t *pf )
425 pf->quant_8x8 = quant_8x8;
426 pf->quant_4x4 = quant_4x4;
427 pf->quant_4x4x4 = quant_4x4x4;
428 pf->quant_4x4_dc = quant_4x4_dc;
429 pf->quant_2x2_dc = quant_2x2_dc;
431 pf->dequant_4x4 = dequant_4x4;
432 pf->dequant_4x4_dc = dequant_4x4_dc;
433 pf->dequant_8x8 = dequant_8x8;
435 pf->idct_dequant_2x4_dc = idct_dequant_2x4_dc;
436 pf->idct_dequant_2x4_dconly = idct_dequant_2x4_dconly;
438 pf->optimize_chroma_2x2_dc = optimize_chroma_2x2_dc;
439 pf->optimize_chroma_2x4_dc = optimize_chroma_2x4_dc;
441 pf->denoise_dct = x264_denoise_dct;
442 pf->decimate_score15 = x264_decimate_score15;
443 pf->decimate_score16 = x264_decimate_score16;
444 pf->decimate_score64 = x264_decimate_score64;
446 pf->coeff_last4 = x264_coeff_last4;
447 pf->coeff_last8 = x264_coeff_last8;
448 pf->coeff_last[ DCT_LUMA_AC] = x264_coeff_last15;
449 pf->coeff_last[ DCT_LUMA_4x4] = x264_coeff_last16;
450 pf->coeff_last[ DCT_LUMA_8x8] = x264_coeff_last64;
451 pf->coeff_level_run4 = x264_coeff_level_run4;
452 pf->coeff_level_run8 = x264_coeff_level_run8;
453 pf->coeff_level_run[ DCT_LUMA_AC] = x264_coeff_level_run15;
454 pf->coeff_level_run[ DCT_LUMA_4x4] = x264_coeff_level_run16;
458 INIT_TRELLIS( sse2 );
459 if( cpu&X264_CPU_MMX2 )
462 pf->denoise_dct = x264_denoise_dct_mmx;
463 pf->decimate_score15 = x264_decimate_score15_mmx2;
464 pf->decimate_score16 = x264_decimate_score16_mmx2;
465 pf->decimate_score64 = x264_decimate_score64_mmx2;
466 pf->coeff_last8 = x264_coeff_last8_mmx2;
467 pf->coeff_last[ DCT_LUMA_AC] = x264_coeff_last15_mmx2;
468 pf->coeff_last[ DCT_LUMA_4x4] = x264_coeff_last16_mmx2;
469 pf->coeff_last[ DCT_LUMA_8x8] = x264_coeff_last64_mmx2;
470 pf->coeff_level_run8 = x264_coeff_level_run8_mmx2;
471 pf->coeff_level_run[ DCT_LUMA_AC] = x264_coeff_level_run15_mmx2;
472 pf->coeff_level_run[ DCT_LUMA_4x4] = x264_coeff_level_run16_mmx2;
474 pf->coeff_last4 = x264_coeff_last4_mmx2;
475 pf->coeff_level_run4 = x264_coeff_level_run4_mmx2;
476 if( cpu&X264_CPU_LZCNT )
477 pf->coeff_level_run4 = x264_coeff_level_run4_mmx2_lzcnt;
479 if( cpu&X264_CPU_SSE2 )
481 pf->quant_4x4 = x264_quant_4x4_sse2;
482 pf->quant_4x4x4 = x264_quant_4x4x4_sse2;
483 pf->quant_8x8 = x264_quant_8x8_sse2;
484 pf->quant_2x2_dc = x264_quant_2x2_dc_sse2;
485 pf->quant_4x4_dc = x264_quant_4x4_dc_sse2;
486 pf->dequant_4x4 = x264_dequant_4x4_sse2;
487 pf->dequant_8x8 = x264_dequant_8x8_sse2;
488 pf->dequant_4x4_dc = x264_dequant_4x4dc_sse2;
489 pf->idct_dequant_2x4_dc = x264_idct_dequant_2x4_dc_sse2;
490 pf->idct_dequant_2x4_dconly = x264_idct_dequant_2x4_dconly_sse2;
491 pf->denoise_dct = x264_denoise_dct_sse2;
492 pf->decimate_score15 = x264_decimate_score15_sse2;
493 pf->decimate_score16 = x264_decimate_score16_sse2;
494 pf->decimate_score64 = x264_decimate_score64_sse2;
495 pf->coeff_last8 = x264_coeff_last8_sse2;
496 pf->coeff_last[ DCT_LUMA_AC] = x264_coeff_last15_sse2;
497 pf->coeff_last[DCT_LUMA_4x4] = x264_coeff_last16_sse2;
498 pf->coeff_last[DCT_LUMA_8x8] = x264_coeff_last64_sse2;
499 pf->coeff_level_run8 = x264_coeff_level_run8_sse2;
500 pf->coeff_level_run[ DCT_LUMA_AC] = x264_coeff_level_run15_sse2;
501 pf->coeff_level_run[DCT_LUMA_4x4] = x264_coeff_level_run16_sse2;
502 if( cpu&X264_CPU_LZCNT )
504 pf->coeff_last4 = x264_coeff_last4_mmx2_lzcnt;
505 pf->coeff_last8 = x264_coeff_last8_sse2_lzcnt;
506 pf->coeff_last[ DCT_LUMA_AC] = x264_coeff_last15_sse2_lzcnt;
507 pf->coeff_last[DCT_LUMA_4x4] = x264_coeff_last16_sse2_lzcnt;
508 pf->coeff_last[DCT_LUMA_8x8] = x264_coeff_last64_sse2_lzcnt;
509 pf->coeff_level_run8 = x264_coeff_level_run8_sse2_lzcnt;
510 pf->coeff_level_run[ DCT_LUMA_AC] = x264_coeff_level_run15_sse2_lzcnt;
511 pf->coeff_level_run[DCT_LUMA_4x4] = x264_coeff_level_run16_sse2_lzcnt;
514 if( cpu&X264_CPU_SSSE3 )
516 pf->quant_4x4 = x264_quant_4x4_ssse3;
517 pf->quant_4x4x4 = x264_quant_4x4x4_ssse3;
518 pf->quant_8x8 = x264_quant_8x8_ssse3;
519 pf->quant_2x2_dc = x264_quant_2x2_dc_ssse3;
520 pf->quant_4x4_dc = x264_quant_4x4_dc_ssse3;
521 pf->denoise_dct = x264_denoise_dct_ssse3;
522 pf->decimate_score15 = x264_decimate_score15_ssse3;
523 pf->decimate_score16 = x264_decimate_score16_ssse3;
524 pf->decimate_score64 = x264_decimate_score64_ssse3;
525 INIT_TRELLIS( ssse3 );
527 if( cpu&X264_CPU_SSE4 )
529 pf->quant_2x2_dc = x264_quant_2x2_dc_sse4;
530 pf->quant_4x4_dc = x264_quant_4x4_dc_sse4;
531 pf->quant_4x4 = x264_quant_4x4_sse4;
532 pf->quant_4x4x4 = x264_quant_4x4x4_sse4;
533 pf->quant_8x8 = x264_quant_8x8_sse4;
535 if( cpu&X264_CPU_AVX )
537 pf->idct_dequant_2x4_dc = x264_idct_dequant_2x4_dc_avx;
538 pf->idct_dequant_2x4_dconly = x264_idct_dequant_2x4_dconly_avx;
539 pf->denoise_dct = x264_denoise_dct_avx;
541 if( cpu&X264_CPU_XOP )
543 pf->dequant_4x4_dc = x264_dequant_4x4dc_xop;
544 if( h->param.i_cqm_preset != X264_CQM_FLAT )
546 pf->dequant_4x4 = x264_dequant_4x4_xop;
547 pf->dequant_8x8 = x264_dequant_8x8_xop;
550 if( cpu&X264_CPU_AVX2 )
552 pf->quant_4x4 = x264_quant_4x4_avx2;
553 pf->quant_4x4_dc = x264_quant_4x4_dc_avx2;
554 pf->quant_8x8 = x264_quant_8x8_avx2;
555 pf->quant_4x4x4 = x264_quant_4x4x4_avx2;
556 pf->dequant_4x4 = x264_dequant_4x4_avx2;
557 pf->dequant_8x8 = x264_dequant_8x8_avx2;
558 pf->dequant_4x4_dc = x264_dequant_4x4dc_avx2;
559 pf->denoise_dct = x264_denoise_dct_avx2;
560 if( cpu&X264_CPU_LZCNT )
561 pf->coeff_last[DCT_LUMA_8x8] = x264_coeff_last64_avx2_lzcnt;
564 #else // !HIGH_BIT_DEPTH
566 INIT_TRELLIS( sse2 );
567 if( cpu&X264_CPU_MMX )
570 pf->dequant_4x4 = x264_dequant_4x4_mmx;
571 pf->dequant_4x4_dc = x264_dequant_4x4dc_mmx2;
572 pf->dequant_8x8 = x264_dequant_8x8_mmx;
573 if( h->param.i_cqm_preset == X264_CQM_FLAT )
575 pf->dequant_4x4 = x264_dequant_4x4_flat16_mmx;
576 pf->dequant_8x8 = x264_dequant_8x8_flat16_mmx;
578 pf->denoise_dct = x264_denoise_dct_mmx;
582 if( cpu&X264_CPU_MMX2 )
584 pf->quant_2x2_dc = x264_quant_2x2_dc_mmx2;
586 pf->quant_4x4 = x264_quant_4x4_mmx2;
587 pf->quant_8x8 = x264_quant_8x8_mmx2;
588 pf->quant_4x4_dc = x264_quant_4x4_dc_mmx2;
589 pf->decimate_score15 = x264_decimate_score15_mmx2;
590 pf->decimate_score16 = x264_decimate_score16_mmx2;
591 pf->decimate_score64 = x264_decimate_score64_mmx2;
592 pf->coeff_last[ DCT_LUMA_AC] = x264_coeff_last15_mmx2;
593 pf->coeff_last[ DCT_LUMA_4x4] = x264_coeff_last16_mmx2;
594 pf->coeff_last[ DCT_LUMA_8x8] = x264_coeff_last64_mmx2;
595 pf->coeff_level_run[ DCT_LUMA_AC] = x264_coeff_level_run15_mmx2;
596 pf->coeff_level_run[ DCT_LUMA_4x4] = x264_coeff_level_run16_mmx2;
598 pf->coeff_last4 = x264_coeff_last4_mmx2;
599 pf->coeff_last8 = x264_coeff_last8_mmx2;
600 pf->coeff_level_run4 = x264_coeff_level_run4_mmx2;
601 pf->coeff_level_run8 = x264_coeff_level_run8_mmx2;
602 if( cpu&X264_CPU_LZCNT )
604 pf->coeff_last4 = x264_coeff_last4_mmx2_lzcnt;
605 pf->coeff_last8 = x264_coeff_last8_mmx2_lzcnt;
606 pf->coeff_level_run4 = x264_coeff_level_run4_mmx2_lzcnt;
607 pf->coeff_level_run8 = x264_coeff_level_run8_mmx2_lzcnt;
611 if( cpu&X264_CPU_SSE2 )
613 pf->quant_4x4_dc = x264_quant_4x4_dc_sse2;
614 pf->quant_4x4 = x264_quant_4x4_sse2;
615 pf->quant_4x4x4 = x264_quant_4x4x4_sse2;
616 pf->quant_8x8 = x264_quant_8x8_sse2;
617 pf->dequant_4x4 = x264_dequant_4x4_sse2;
618 pf->dequant_4x4_dc = x264_dequant_4x4dc_sse2;
619 pf->dequant_8x8 = x264_dequant_8x8_sse2;
620 if( h->param.i_cqm_preset == X264_CQM_FLAT )
622 pf->dequant_4x4 = x264_dequant_4x4_flat16_sse2;
623 pf->dequant_8x8 = x264_dequant_8x8_flat16_sse2;
625 pf->idct_dequant_2x4_dc = x264_idct_dequant_2x4_dc_sse2;
626 pf->idct_dequant_2x4_dconly = x264_idct_dequant_2x4_dconly_sse2;
627 pf->optimize_chroma_2x2_dc = x264_optimize_chroma_2x2_dc_sse2;
628 pf->denoise_dct = x264_denoise_dct_sse2;
629 pf->decimate_score15 = x264_decimate_score15_sse2;
630 pf->decimate_score16 = x264_decimate_score16_sse2;
631 pf->decimate_score64 = x264_decimate_score64_sse2;
632 pf->coeff_last[ DCT_LUMA_AC] = x264_coeff_last15_sse2;
633 pf->coeff_last[DCT_LUMA_4x4] = x264_coeff_last16_sse2;
634 pf->coeff_last[DCT_LUMA_8x8] = x264_coeff_last64_sse2;
635 pf->coeff_level_run[ DCT_LUMA_AC] = x264_coeff_level_run15_sse2;
636 pf->coeff_level_run[DCT_LUMA_4x4] = x264_coeff_level_run16_sse2;
637 if( cpu&X264_CPU_LZCNT )
639 pf->coeff_last[ DCT_LUMA_AC] = x264_coeff_last15_sse2_lzcnt;
640 pf->coeff_last[DCT_LUMA_4x4] = x264_coeff_last16_sse2_lzcnt;
641 pf->coeff_last[DCT_LUMA_8x8] = x264_coeff_last64_sse2_lzcnt;
642 pf->coeff_level_run[ DCT_LUMA_AC] = x264_coeff_level_run15_sse2_lzcnt;
643 pf->coeff_level_run[DCT_LUMA_4x4] = x264_coeff_level_run16_sse2_lzcnt;
647 if( cpu&X264_CPU_SSSE3 )
649 pf->quant_2x2_dc = x264_quant_2x2_dc_ssse3;
650 pf->quant_4x4_dc = x264_quant_4x4_dc_ssse3;
651 pf->quant_4x4 = x264_quant_4x4_ssse3;
652 pf->quant_4x4x4 = x264_quant_4x4x4_ssse3;
653 pf->quant_8x8 = x264_quant_8x8_ssse3;
654 pf->optimize_chroma_2x2_dc = x264_optimize_chroma_2x2_dc_ssse3;
655 pf->denoise_dct = x264_denoise_dct_ssse3;
656 pf->decimate_score15 = x264_decimate_score15_ssse3;
657 pf->decimate_score16 = x264_decimate_score16_ssse3;
658 pf->decimate_score64 = x264_decimate_score64_ssse3;
659 INIT_TRELLIS( ssse3 );
660 pf->coeff_level_run4 = x264_coeff_level_run4_ssse3;
661 pf->coeff_level_run8 = x264_coeff_level_run8_ssse3;
662 pf->coeff_level_run[ DCT_LUMA_AC] = x264_coeff_level_run15_ssse3;
663 pf->coeff_level_run[DCT_LUMA_4x4] = x264_coeff_level_run16_ssse3;
664 if( cpu&X264_CPU_LZCNT )
666 pf->coeff_level_run4 = x264_coeff_level_run4_ssse3;
667 pf->coeff_level_run8 = x264_coeff_level_run8_ssse3;
668 pf->coeff_level_run[ DCT_LUMA_AC] = x264_coeff_level_run15_ssse3_lzcnt;
669 pf->coeff_level_run[DCT_LUMA_4x4] = x264_coeff_level_run16_ssse3_lzcnt;
673 if( cpu&X264_CPU_SSE4 )
675 pf->quant_4x4_dc = x264_quant_4x4_dc_sse4;
676 pf->quant_4x4 = x264_quant_4x4_sse4;
677 pf->quant_8x8 = x264_quant_8x8_sse4;
678 pf->optimize_chroma_2x2_dc = x264_optimize_chroma_2x2_dc_sse4;
681 if( cpu&X264_CPU_AVX )
683 pf->dequant_4x4_dc = x264_dequant_4x4dc_avx;
684 if( h->param.i_cqm_preset != X264_CQM_FLAT )
686 pf->dequant_4x4 = x264_dequant_4x4_avx;
687 pf->dequant_8x8 = x264_dequant_8x8_avx;
689 pf->idct_dequant_2x4_dc = x264_idct_dequant_2x4_dc_avx;
690 pf->idct_dequant_2x4_dconly = x264_idct_dequant_2x4_dconly_avx;
691 pf->optimize_chroma_2x2_dc = x264_optimize_chroma_2x2_dc_avx;
692 pf->denoise_dct = x264_denoise_dct_avx;
695 if( cpu&X264_CPU_XOP )
697 if( h->param.i_cqm_preset != X264_CQM_FLAT )
699 pf->dequant_4x4 = x264_dequant_4x4_xop;
700 pf->dequant_8x8 = x264_dequant_8x8_xop;
704 if( cpu&X264_CPU_AVX2 )
706 pf->quant_4x4 = x264_quant_4x4_avx2;
707 pf->quant_4x4_dc = x264_quant_4x4_dc_avx2;
708 pf->quant_8x8 = x264_quant_8x8_avx2;
709 pf->quant_4x4x4 = x264_quant_4x4x4_avx2;
710 pf->dequant_4x4 = x264_dequant_4x4_avx2;
711 pf->dequant_8x8 = x264_dequant_8x8_avx2;
712 pf->dequant_4x4_dc = x264_dequant_4x4dc_avx2;
713 if( h->param.i_cqm_preset == X264_CQM_FLAT )
715 pf->dequant_4x4 = x264_dequant_4x4_flat16_avx2;
716 pf->dequant_8x8 = x264_dequant_8x8_flat16_avx2;
718 pf->decimate_score64 = x264_decimate_score64_avx2;
719 pf->denoise_dct = x264_denoise_dct_avx2;
720 if( cpu&X264_CPU_LZCNT )
722 pf->coeff_last[DCT_LUMA_8x8] = x264_coeff_last64_avx2_lzcnt;
723 pf->coeff_level_run[ DCT_LUMA_AC] = x264_coeff_level_run15_avx2_lzcnt;
724 pf->coeff_level_run[DCT_LUMA_4x4] = x264_coeff_level_run16_avx2_lzcnt;
730 if( cpu&X264_CPU_ALTIVEC )
732 pf->quant_2x2_dc = x264_quant_2x2_dc_altivec;
733 pf->quant_4x4_dc = x264_quant_4x4_dc_altivec;
734 pf->quant_4x4 = x264_quant_4x4_altivec;
735 pf->quant_8x8 = x264_quant_8x8_altivec;
737 pf->dequant_4x4 = x264_dequant_4x4_altivec;
738 pf->dequant_8x8 = x264_dequant_8x8_altivec;
743 if( cpu&X264_CPU_ARMV6 )
745 pf->coeff_last4 = x264_coeff_last4_arm;
746 pf->coeff_last8 = x264_coeff_last8_arm;
749 #if HAVE_ARMV6 || ARCH_AARCH64
750 if( cpu&X264_CPU_NEON )
752 pf->quant_2x2_dc = x264_quant_2x2_dc_neon;
753 pf->quant_4x4 = x264_quant_4x4_neon;
754 pf->quant_4x4_dc = x264_quant_4x4_dc_neon;
755 pf->quant_4x4x4 = x264_quant_4x4x4_neon;
756 pf->quant_8x8 = x264_quant_8x8_neon;
757 pf->dequant_4x4 = x264_dequant_4x4_neon;
758 pf->dequant_4x4_dc = x264_dequant_4x4_dc_neon;
759 pf->dequant_8x8 = x264_dequant_8x8_neon;
760 pf->coeff_last[ DCT_LUMA_AC] = x264_coeff_last15_neon;
761 pf->coeff_last[DCT_LUMA_4x4] = x264_coeff_last16_neon;
762 pf->coeff_last[DCT_LUMA_8x8] = x264_coeff_last64_neon;
763 pf->denoise_dct = x264_denoise_dct_neon;
764 pf->decimate_score15 = x264_decimate_score15_neon;
765 pf->decimate_score16 = x264_decimate_score16_neon;
766 pf->decimate_score64 = x264_decimate_score64_neon;
770 if( cpu&X264_CPU_ARMV8 )
772 pf->coeff_last4 = x264_coeff_last4_aarch64;
773 pf->coeff_last8 = x264_coeff_last8_aarch64;
774 pf->coeff_level_run4 = x264_coeff_level_run4_aarch64;
776 if( cpu&X264_CPU_NEON )
778 pf->coeff_level_run8 = x264_coeff_level_run8_neon;
779 pf->coeff_level_run[ DCT_LUMA_AC] = x264_coeff_level_run15_neon;
780 pf->coeff_level_run[ DCT_LUMA_4x4] = x264_coeff_level_run16_neon;
785 if( cpu&X264_CPU_MSA )
787 pf->quant_4x4 = x264_quant_4x4_msa;
788 pf->quant_4x4_dc = x264_quant_4x4_dc_msa;
789 pf->quant_4x4x4 = x264_quant_4x4x4_msa;
790 pf->quant_8x8 = x264_quant_8x8_msa;
791 pf->dequant_4x4 = x264_dequant_4x4_msa;
792 pf->dequant_4x4_dc = x264_dequant_4x4_dc_msa;
793 pf->dequant_8x8 = x264_dequant_8x8_msa;
794 pf->coeff_last[DCT_LUMA_4x4] = x264_coeff_last16_msa;
795 pf->coeff_last[DCT_LUMA_8x8] = x264_coeff_last64_msa;
798 #endif // HIGH_BIT_DEPTH
799 pf->coeff_last[DCT_LUMA_DC] = pf->coeff_last[DCT_CHROMAU_DC] = pf->coeff_last[DCT_CHROMAV_DC] =
800 pf->coeff_last[DCT_CHROMAU_4x4] = pf->coeff_last[DCT_CHROMAV_4x4] = pf->coeff_last[DCT_LUMA_4x4];
801 pf->coeff_last[DCT_CHROMA_AC] = pf->coeff_last[DCT_CHROMAU_AC] =
802 pf->coeff_last[DCT_CHROMAV_AC] = pf->coeff_last[DCT_LUMA_AC];
803 pf->coeff_last[DCT_CHROMAU_8x8] = pf->coeff_last[DCT_CHROMAV_8x8] = pf->coeff_last[DCT_LUMA_8x8];
805 pf->coeff_level_run[DCT_LUMA_DC] = pf->coeff_level_run[DCT_CHROMAU_DC] = pf->coeff_level_run[DCT_CHROMAV_DC] =
806 pf->coeff_level_run[DCT_CHROMAU_4x4] = pf->coeff_level_run[DCT_CHROMAV_4x4] = pf->coeff_level_run[DCT_LUMA_4x4];
807 pf->coeff_level_run[DCT_CHROMA_AC] = pf->coeff_level_run[DCT_CHROMAU_AC] =
808 pf->coeff_level_run[DCT_CHROMAV_AC] = pf->coeff_level_run[DCT_LUMA_AC];