X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=common%2Fquant.c;h=312f7cd9101d95047ec17c9cdd00951ce6d6ead6;hb=refs%2Fheads%2Fspeedcontrol;hp=a97d6c38e11e728475faa747ef72e3300524d2aa;hpb=189c30d390d08b2b3d3007acd0a106a4e0cd17b2;p=x264 diff --git a/common/quant.c b/common/quant.c index a97d6c38..312f7cd9 100644 --- a/common/quant.c +++ b/common/quant.c @@ -1,11 +1,12 @@ /***************************************************************************** * quant.c: quantization and level-run ***************************************************************************** - * Copyright (C) 2005-2011 x264 project + * Copyright (C) 2005-2016 x264 project * * Authors: Loren Merritt * Fiona Glaser * Christian Heine + * Henrik Gramner * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -36,6 +37,12 @@ #if ARCH_ARM # include "arm/quant.h" #endif +#if ARCH_AARCH64 +# include "aarch64/quant.h" +#endif +#if ARCH_MIPS +# include "mips/quant.h" +#endif #define QUANT_ONE( coef, mf, f ) \ { \ @@ -62,6 +69,19 @@ static int quant_4x4( dctcoef dct[16], udctcoef mf[16], udctcoef bias[16] ) return !!nz; } +static int quant_4x4x4( dctcoef dct[4][16], udctcoef mf[16], udctcoef bias[16] ) +{ + int nza = 0; + for( int j = 0; j < 4; j++ ) + { + int nz = 0; + for( int i = 0; i < 16; i++ ) + QUANT_ONE( dct[j][i], mf[i], bias[i] ); + nza |= (!!nz)<> 6; + dct4x4[1][0] = ((b2 + b3) * dmf + 32) >> 6; + dct4x4[2][0] = ((b0 - b1) * dmf + 32) >> 6; + dct4x4[3][0] = ((b2 - b3) * dmf + 32) >> 6; + dct4x4[4][0] = ((b4 - b5) * dmf + 32) >> 6; + dct4x4[5][0] = ((b6 - b7) * dmf + 32) >> 6; + dct4x4[6][0] = ((b4 + b5) * dmf + 32) >> 6; + dct4x4[7][0] = ((b6 + b7) * dmf + 32) >> 6; +} + +static void idct_dequant_2x4_dconly( dctcoef dct[8], int dequant_mf[6][16], int i_qp ) +{ + IDCT_DEQUANT_2X4_START + int dmf = dequant_mf[i_qp%6][0] << i_qp/6; + dct[0] = ((b0 + b1) * dmf + 32) >> 6; + dct[1] = ((b2 + b3) * dmf + 32) >> 6; + dct[2] = ((b0 - b1) * dmf + 32) >> 6; + dct[3] = ((b2 - b3) * dmf + 32) >> 6; + dct[4] = ((b4 - b5) * dmf + 32) >> 6; + dct[5] = ((b6 - b7) * dmf + 32) >> 6; + dct[6] = ((b4 + b5) * dmf + 32) >> 6; + dct[7] = ((b6 + b7) * dmf + 32) >> 6; +} + +static ALWAYS_INLINE void optimize_chroma_idct_dequant_2x4( dctcoef out[8], dctcoef dct[8], int dmf ) +{ + IDCT_DEQUANT_2X4_START + out[0] = ((b0 + b1) * dmf + 2080) >> 6; /* 2080 = 32 + (32<<6) */ + out[1] = ((b2 + b3) * dmf + 2080) >> 6; + out[2] = ((b0 - b1) * dmf + 2080) >> 6; + out[3] = ((b2 - b3) * dmf + 2080) >> 6; + out[4] = ((b4 - b5) * dmf + 2080) >> 6; + out[5] = ((b6 - b7) * dmf + 2080) >> 6; + out[6] = ((b4 + b5) * dmf + 2080) >> 6; + out[7] = ((b6 + b7) * dmf + 2080) >> 6; +} +#undef IDCT_DEQUANT_2X4_START + +static ALWAYS_INLINE void optimize_chroma_idct_dequant_2x2( dctcoef out[4], dctcoef dct[4], int dmf ) { int d0 = dct[0] + dct[1]; int d1 = dct[2] + dct[3]; int d2 = dct[0] - dct[1]; int d3 = dct[2] - dct[3]; - out[0] = (d0 + d1) * dequant_mf >> 5; - out[1] = (d0 - d1) * dequant_mf >> 5; - out[2] = (d2 + d3) * dequant_mf >> 5; - out[3] = (d2 - d3) * dequant_mf >> 5; + out[0] = ((d0 + d1) * dmf >> 5) + 32; + out[1] = ((d0 - d1) * dmf >> 5) + 32; + out[2] = ((d2 + d3) * dmf >> 5) + 32; + out[3] = ((d2 - d3) * dmf >> 5) + 32; } -static ALWAYS_INLINE int idct_dequant_round_2x2_dc( dctcoef ref[4], dctcoef dct[4], int dequant_mf ) +static ALWAYS_INLINE int optimize_chroma_round( dctcoef *ref, dctcoef *dct, int dequant_mf, int chroma422 ) { - dctcoef out[4]; - idct_dequant_2x2_dconly( out, dct, dequant_mf ); - return ((ref[0] ^ (out[0]+32)) - | (ref[1] ^ (out[1]+32)) - | (ref[2] ^ (out[2]+32)) - | (ref[3] ^ (out[3]+32))) >> 6; + dctcoef out[8]; + + if( chroma422 ) + optimize_chroma_idct_dequant_2x4( out, dct, dequant_mf ); + else + optimize_chroma_idct_dequant_2x2( out, dct, dequant_mf ); + + int sum = 0; + for( int i = 0; i < (chroma422?8:4); i++ ) + sum |= ref[i] ^ out[i]; + return sum >> 6; } -static int optimize_chroma_dc( dctcoef dct[4], int dequant_mf ) +static ALWAYS_INLINE int optimize_chroma_dc_internal( dctcoef *dct, int dequant_mf, int chroma422 ) { /* dequant_mf = h->dequant4_mf[CQM_4IC + b_inter][i_qp%6][0] << i_qp/6, max 32*64 */ - dctcoef dct_orig[4]; + dctcoef dct_orig[8]; int coeff, nz; - idct_dequant_2x2_dconly( dct_orig, dct, dequant_mf ); - dct_orig[0] += 32; - dct_orig[1] += 32; - dct_orig[2] += 32; - dct_orig[3] += 32; + if( chroma422 ) + optimize_chroma_idct_dequant_2x4( dct_orig, dct, dequant_mf ); + else + optimize_chroma_idct_dequant_2x2( dct_orig, dct, dequant_mf ); /* If the DC coefficients already round to zero, terminate early. */ - if( !((dct_orig[0]|dct_orig[1]|dct_orig[2]|dct_orig[3])>>6) ) + int sum = 0; + for( int i = 0; i < (chroma422?8:4); i++ ) + sum |= dct_orig[i]; + if( !(sum >> 6) ) return 0; /* Start with the highest frequency coefficient... is this the best option? */ - for( nz = 0, coeff = 3; coeff >= 0; coeff-- ) + for( nz = 0, coeff = (chroma422?7:3); coeff >= 0; coeff-- ) { int level = dct[coeff]; - int sign = level>>31 | 1; /* dct2x2[coeff] < 0 ? -1 : 1 */ + int sign = level>>31 | 1; /* dct[coeff] < 0 ? -1 : 1 */ while( level ) { dct[coeff] = level - sign; - if( idct_dequant_round_2x2_dc( dct_orig, dct, dequant_mf ) ) + if( optimize_chroma_round( dct_orig, dct, dequant_mf, chroma422 ) ) { nz = 1; dct[coeff] = level; @@ -201,6 +288,16 @@ static int optimize_chroma_dc( dctcoef dct[4], int dequant_mf ) return nz; } +static int optimize_chroma_2x2_dc( dctcoef dct[4], int dequant_mf ) +{ + return optimize_chroma_dc_internal( dct, dequant_mf, 0 ); +} + +static int optimize_chroma_2x4_dc( dctcoef dct[8], int dequant_mf ) +{ + return optimize_chroma_dc_internal( dct, dequant_mf, 1 ); +} + static void x264_denoise_dct( dctcoef *dct, uint32_t *sum, udctcoef *offset, int size ) { for( int i = 0; i < size; i++ ) @@ -275,56 +372,59 @@ static int x264_decimate_score64( dctcoef *dct ) return x264_decimate_score_internal( dct, 64 ); } -static int ALWAYS_INLINE x264_coeff_last_internal( dctcoef *l, int i_count ) -{ - int i_last = i_count-1; - while( i_last >= 0 && l[i_last] == 0 ) - i_last--; - return i_last; +#define last(num)\ +static int x264_coeff_last##num( dctcoef *l )\ +{\ + int i_last = num-1;\ + while( i_last >= 0 && l[i_last] == 0 )\ + i_last--;\ + return i_last;\ } -static int x264_coeff_last4( dctcoef *l ) -{ - return x264_coeff_last_internal( l, 4 ); -} -static int x264_coeff_last15( dctcoef *l ) -{ - return x264_coeff_last_internal( l, 15 ); -} -static int x264_coeff_last16( dctcoef *l ) -{ - return x264_coeff_last_internal( l, 16 ); -} -static int x264_coeff_last64( dctcoef *l ) -{ - return x264_coeff_last_internal( l, 64 ); -} +last(4) +last(8) +last(15) +last(16) +last(64) #define level_run(num)\ static int x264_coeff_level_run##num( dctcoef *dct, x264_run_level_t *runlevel )\ {\ int i_last = runlevel->last = x264_coeff_last##num(dct);\ int i_total = 0;\ + int mask = 0;\ do\ {\ - int r = 0;\ - runlevel->level[i_total] = dct[i_last];\ - while( --i_last >= 0 && dct[i_last] == 0 )\ - r++;\ - runlevel->run[i_total++] = r;\ + runlevel->level[i_total++] = dct[i_last];\ + mask |= 1 << (i_last);\ + while( --i_last >= 0 && dct[i_last] == 0 );\ } while( i_last >= 0 );\ + runlevel->mask = mask;\ return i_total;\ } level_run(4) +level_run(8) level_run(15) level_run(16) +#if ARCH_X86_64 +#define INIT_TRELLIS(cpu)\ + pf->trellis_cabac_4x4 = x264_trellis_cabac_4x4_##cpu;\ + pf->trellis_cabac_8x8 = x264_trellis_cabac_8x8_##cpu;\ + pf->trellis_cabac_4x4_psy = x264_trellis_cabac_4x4_psy_##cpu;\ + pf->trellis_cabac_8x8_psy = x264_trellis_cabac_8x8_psy_##cpu;\ + pf->trellis_cabac_dc = x264_trellis_cabac_dc_##cpu;\ + pf->trellis_cabac_chroma_422_dc = x264_trellis_cabac_chroma_422_dc_##cpu; +#else +#define INIT_TRELLIS(...) +#endif void x264_quant_init( x264_t *h, int cpu, x264_quant_function_t *pf ) { pf->quant_8x8 = quant_8x8; pf->quant_4x4 = quant_4x4; + pf->quant_4x4x4 = quant_4x4x4; pf->quant_4x4_dc = quant_4x4_dc; pf->quant_2x2_dc = quant_2x2_dc; @@ -332,75 +432,81 @@ void x264_quant_init( x264_t *h, int cpu, x264_quant_function_t *pf ) pf->dequant_4x4_dc = dequant_4x4_dc; pf->dequant_8x8 = dequant_8x8; - pf->optimize_chroma_dc = optimize_chroma_dc; + pf->idct_dequant_2x4_dc = idct_dequant_2x4_dc; + pf->idct_dequant_2x4_dconly = idct_dequant_2x4_dconly; + + pf->optimize_chroma_2x2_dc = optimize_chroma_2x2_dc; + pf->optimize_chroma_2x4_dc = optimize_chroma_2x4_dc; pf->denoise_dct = x264_denoise_dct; pf->decimate_score15 = x264_decimate_score15; pf->decimate_score16 = x264_decimate_score16; pf->decimate_score64 = x264_decimate_score64; - pf->coeff_last[DCT_CHROMA_DC] = x264_coeff_last4; + pf->coeff_last4 = x264_coeff_last4; + pf->coeff_last8 = x264_coeff_last8; pf->coeff_last[ DCT_LUMA_AC] = x264_coeff_last15; pf->coeff_last[ DCT_LUMA_4x4] = x264_coeff_last16; pf->coeff_last[ DCT_LUMA_8x8] = x264_coeff_last64; - pf->coeff_level_run[DCT_CHROMA_DC] = x264_coeff_level_run4; + pf->coeff_level_run4 = x264_coeff_level_run4; + pf->coeff_level_run8 = x264_coeff_level_run8; pf->coeff_level_run[ DCT_LUMA_AC] = x264_coeff_level_run15; pf->coeff_level_run[ DCT_LUMA_4x4] = x264_coeff_level_run16; #if HIGH_BIT_DEPTH #if HAVE_MMX + INIT_TRELLIS( sse2 ); if( cpu&X264_CPU_MMX2 ) { #if ARCH_X86 pf->denoise_dct = x264_denoise_dct_mmx; pf->decimate_score15 = x264_decimate_score15_mmx2; pf->decimate_score16 = x264_decimate_score16_mmx2; - if( cpu&X264_CPU_SLOW_CTZ ) - { - pf->decimate_score15 = x264_decimate_score15_mmx2_slowctz; - pf->decimate_score16 = x264_decimate_score16_mmx2_slowctz; - } pf->decimate_score64 = x264_decimate_score64_mmx2; - pf->coeff_last[DCT_CHROMA_DC] = x264_coeff_last4_mmx2; + pf->coeff_last8 = x264_coeff_last8_mmx2; pf->coeff_last[ DCT_LUMA_AC] = x264_coeff_last15_mmx2; pf->coeff_last[ DCT_LUMA_4x4] = x264_coeff_last16_mmx2; pf->coeff_last[ DCT_LUMA_8x8] = x264_coeff_last64_mmx2; + pf->coeff_level_run8 = x264_coeff_level_run8_mmx2; pf->coeff_level_run[ DCT_LUMA_AC] = x264_coeff_level_run15_mmx2; pf->coeff_level_run[ DCT_LUMA_4x4] = x264_coeff_level_run16_mmx2; #endif - pf->coeff_level_run[DCT_CHROMA_DC] = x264_coeff_level_run4_mmx2; + pf->coeff_last4 = x264_coeff_last4_mmx2; + pf->coeff_level_run4 = x264_coeff_level_run4_mmx2; if( cpu&X264_CPU_LZCNT ) - pf->coeff_level_run[DCT_CHROMA_DC] = x264_coeff_level_run4_mmx2_lzcnt; + pf->coeff_level_run4 = x264_coeff_level_run4_mmx2_lzcnt; } if( cpu&X264_CPU_SSE2 ) { pf->quant_4x4 = x264_quant_4x4_sse2; + pf->quant_4x4x4 = x264_quant_4x4x4_sse2; pf->quant_8x8 = x264_quant_8x8_sse2; pf->quant_2x2_dc = x264_quant_2x2_dc_sse2; pf->quant_4x4_dc = x264_quant_4x4_dc_sse2; pf->dequant_4x4 = x264_dequant_4x4_sse2; pf->dequant_8x8 = x264_dequant_8x8_sse2; pf->dequant_4x4_dc = x264_dequant_4x4dc_sse2; + pf->idct_dequant_2x4_dc = x264_idct_dequant_2x4_dc_sse2; + pf->idct_dequant_2x4_dconly = x264_idct_dequant_2x4_dconly_sse2; pf->denoise_dct = x264_denoise_dct_sse2; pf->decimate_score15 = x264_decimate_score15_sse2; pf->decimate_score16 = x264_decimate_score16_sse2; pf->decimate_score64 = x264_decimate_score64_sse2; - if( cpu&X264_CPU_SLOW_CTZ ) - { - pf->decimate_score15 = x264_decimate_score15_sse2_slowctz; - pf->decimate_score16 = x264_decimate_score16_sse2_slowctz; - } + pf->coeff_last8 = x264_coeff_last8_sse2; pf->coeff_last[ DCT_LUMA_AC] = x264_coeff_last15_sse2; pf->coeff_last[DCT_LUMA_4x4] = x264_coeff_last16_sse2; pf->coeff_last[DCT_LUMA_8x8] = x264_coeff_last64_sse2; + pf->coeff_level_run8 = x264_coeff_level_run8_sse2; pf->coeff_level_run[ DCT_LUMA_AC] = x264_coeff_level_run15_sse2; pf->coeff_level_run[DCT_LUMA_4x4] = x264_coeff_level_run16_sse2; if( cpu&X264_CPU_LZCNT ) { - pf->coeff_last[DCT_CHROMA_DC] = x264_coeff_last4_mmx2_lzcnt; + pf->coeff_last4 = x264_coeff_last4_mmx2_lzcnt; + pf->coeff_last8 = x264_coeff_last8_sse2_lzcnt; pf->coeff_last[ DCT_LUMA_AC] = x264_coeff_last15_sse2_lzcnt; pf->coeff_last[DCT_LUMA_4x4] = x264_coeff_last16_sse2_lzcnt; pf->coeff_last[DCT_LUMA_8x8] = x264_coeff_last64_sse2_lzcnt; + pf->coeff_level_run8 = x264_coeff_level_run8_sse2_lzcnt; pf->coeff_level_run[ DCT_LUMA_AC] = x264_coeff_level_run15_sse2_lzcnt; pf->coeff_level_run[DCT_LUMA_4x4] = x264_coeff_level_run16_sse2_lzcnt; } @@ -408,34 +514,59 @@ void x264_quant_init( x264_t *h, int cpu, x264_quant_function_t *pf ) if( cpu&X264_CPU_SSSE3 ) { pf->quant_4x4 = x264_quant_4x4_ssse3; + pf->quant_4x4x4 = x264_quant_4x4x4_ssse3; pf->quant_8x8 = x264_quant_8x8_ssse3; pf->quant_2x2_dc = x264_quant_2x2_dc_ssse3; pf->quant_4x4_dc = x264_quant_4x4_dc_ssse3; pf->denoise_dct = x264_denoise_dct_ssse3; pf->decimate_score15 = x264_decimate_score15_ssse3; pf->decimate_score16 = x264_decimate_score16_ssse3; - if( cpu&X264_CPU_SLOW_CTZ ) - { - pf->decimate_score15 = x264_decimate_score15_ssse3_slowctz; - pf->decimate_score16 = x264_decimate_score16_ssse3_slowctz; - } pf->decimate_score64 = x264_decimate_score64_ssse3; + INIT_TRELLIS( ssse3 ); } if( cpu&X264_CPU_SSE4 ) { pf->quant_2x2_dc = x264_quant_2x2_dc_sse4; pf->quant_4x4_dc = x264_quant_4x4_dc_sse4; pf->quant_4x4 = x264_quant_4x4_sse4; + pf->quant_4x4x4 = x264_quant_4x4x4_sse4; pf->quant_8x8 = x264_quant_8x8_sse4; } + if( cpu&X264_CPU_AVX ) + { + pf->idct_dequant_2x4_dc = x264_idct_dequant_2x4_dc_avx; + pf->idct_dequant_2x4_dconly = x264_idct_dequant_2x4_dconly_avx; + pf->denoise_dct = x264_denoise_dct_avx; + } + if( cpu&X264_CPU_XOP ) + { + pf->dequant_4x4_dc = x264_dequant_4x4dc_xop; + if( h->param.i_cqm_preset != X264_CQM_FLAT ) + { + pf->dequant_4x4 = x264_dequant_4x4_xop; + pf->dequant_8x8 = x264_dequant_8x8_xop; + } + } + if( cpu&X264_CPU_AVX2 ) + { + pf->quant_4x4 = x264_quant_4x4_avx2; + pf->quant_4x4_dc = x264_quant_4x4_dc_avx2; + pf->quant_8x8 = x264_quant_8x8_avx2; + pf->quant_4x4x4 = x264_quant_4x4x4_avx2; + pf->dequant_4x4 = x264_dequant_4x4_avx2; + pf->dequant_8x8 = x264_dequant_8x8_avx2; + pf->dequant_4x4_dc = x264_dequant_4x4dc_avx2; + pf->denoise_dct = x264_denoise_dct_avx2; + if( cpu&X264_CPU_LZCNT ) + pf->coeff_last[DCT_LUMA_8x8] = x264_coeff_last64_avx2_lzcnt; + } #endif // HAVE_MMX #else // !HIGH_BIT_DEPTH #if HAVE_MMX + INIT_TRELLIS( sse2 ); if( cpu&X264_CPU_MMX ) { #if ARCH_X86 - pf->quant_4x4 = x264_quant_4x4_mmx; - pf->quant_8x8 = x264_quant_8x8_mmx; pf->dequant_4x4 = x264_dequant_4x4_mmx; pf->dequant_4x4_dc = x264_dequant_4x4dc_mmx2; pf->dequant_8x8 = x264_dequant_8x8_mmx; @@ -452,14 +583,11 @@ void x264_quant_init( x264_t *h, int cpu, x264_quant_function_t *pf ) { pf->quant_2x2_dc = x264_quant_2x2_dc_mmx2; #if ARCH_X86 + pf->quant_4x4 = x264_quant_4x4_mmx2; + pf->quant_8x8 = x264_quant_8x8_mmx2; pf->quant_4x4_dc = x264_quant_4x4_dc_mmx2; pf->decimate_score15 = x264_decimate_score15_mmx2; pf->decimate_score16 = x264_decimate_score16_mmx2; - if( cpu&X264_CPU_SLOW_CTZ ) - { - pf->decimate_score15 = x264_decimate_score15_mmx2_slowctz; - pf->decimate_score16 = x264_decimate_score16_mmx2_slowctz; - } pf->decimate_score64 = x264_decimate_score64_mmx2; pf->coeff_last[ DCT_LUMA_AC] = x264_coeff_last15_mmx2; pf->coeff_last[ DCT_LUMA_4x4] = x264_coeff_last16_mmx2; @@ -467,12 +595,16 @@ void x264_quant_init( x264_t *h, int cpu, x264_quant_function_t *pf ) pf->coeff_level_run[ DCT_LUMA_AC] = x264_coeff_level_run15_mmx2; pf->coeff_level_run[ DCT_LUMA_4x4] = x264_coeff_level_run16_mmx2; #endif - pf->coeff_last[DCT_CHROMA_DC] = x264_coeff_last4_mmx2; - pf->coeff_level_run[DCT_CHROMA_DC] = x264_coeff_level_run4_mmx2; + pf->coeff_last4 = x264_coeff_last4_mmx2; + pf->coeff_last8 = x264_coeff_last8_mmx2; + pf->coeff_level_run4 = x264_coeff_level_run4_mmx2; + pf->coeff_level_run8 = x264_coeff_level_run8_mmx2; if( cpu&X264_CPU_LZCNT ) { - pf->coeff_last[DCT_CHROMA_DC] = x264_coeff_last4_mmx2_lzcnt; - pf->coeff_level_run[DCT_CHROMA_DC] = x264_coeff_level_run4_mmx2_lzcnt; + pf->coeff_last4 = x264_coeff_last4_mmx2_lzcnt; + pf->coeff_last8 = x264_coeff_last8_mmx2_lzcnt; + pf->coeff_level_run4 = x264_coeff_level_run4_mmx2_lzcnt; + pf->coeff_level_run8 = x264_coeff_level_run8_mmx2_lzcnt; } } @@ -480,6 +612,7 @@ void x264_quant_init( x264_t *h, int cpu, x264_quant_function_t *pf ) { pf->quant_4x4_dc = x264_quant_4x4_dc_sse2; pf->quant_4x4 = x264_quant_4x4_sse2; + pf->quant_4x4x4 = x264_quant_4x4x4_sse2; pf->quant_8x8 = x264_quant_8x8_sse2; pf->dequant_4x4 = x264_dequant_4x4_sse2; pf->dequant_4x4_dc = x264_dequant_4x4dc_sse2; @@ -489,16 +622,13 @@ void x264_quant_init( x264_t *h, int cpu, x264_quant_function_t *pf ) pf->dequant_4x4 = x264_dequant_4x4_flat16_sse2; pf->dequant_8x8 = x264_dequant_8x8_flat16_sse2; } - pf->optimize_chroma_dc = x264_optimize_chroma_dc_sse2; + pf->idct_dequant_2x4_dc = x264_idct_dequant_2x4_dc_sse2; + pf->idct_dequant_2x4_dconly = x264_idct_dequant_2x4_dconly_sse2; + pf->optimize_chroma_2x2_dc = x264_optimize_chroma_2x2_dc_sse2; pf->denoise_dct = x264_denoise_dct_sse2; pf->decimate_score15 = x264_decimate_score15_sse2; pf->decimate_score16 = x264_decimate_score16_sse2; pf->decimate_score64 = x264_decimate_score64_sse2; - if( cpu&X264_CPU_SLOW_CTZ ) - { - pf->decimate_score15 = x264_decimate_score15_sse2_slowctz; - pf->decimate_score16 = x264_decimate_score16_sse2_slowctz; - } pf->coeff_last[ DCT_LUMA_AC] = x264_coeff_last15_sse2; pf->coeff_last[DCT_LUMA_4x4] = x264_coeff_last16_sse2; pf->coeff_last[DCT_LUMA_8x8] = x264_coeff_last64_sse2; @@ -519,17 +649,25 @@ void x264_quant_init( x264_t *h, int cpu, x264_quant_function_t *pf ) pf->quant_2x2_dc = x264_quant_2x2_dc_ssse3; pf->quant_4x4_dc = x264_quant_4x4_dc_ssse3; pf->quant_4x4 = x264_quant_4x4_ssse3; + pf->quant_4x4x4 = x264_quant_4x4x4_ssse3; pf->quant_8x8 = x264_quant_8x8_ssse3; - pf->optimize_chroma_dc = x264_optimize_chroma_dc_ssse3; + pf->optimize_chroma_2x2_dc = x264_optimize_chroma_2x2_dc_ssse3; pf->denoise_dct = x264_denoise_dct_ssse3; pf->decimate_score15 = x264_decimate_score15_ssse3; pf->decimate_score16 = x264_decimate_score16_ssse3; - if( cpu&X264_CPU_SLOW_CTZ ) + pf->decimate_score64 = x264_decimate_score64_ssse3; + INIT_TRELLIS( ssse3 ); + pf->coeff_level_run4 = x264_coeff_level_run4_ssse3; + pf->coeff_level_run8 = x264_coeff_level_run8_ssse3; + pf->coeff_level_run[ DCT_LUMA_AC] = x264_coeff_level_run15_ssse3; + pf->coeff_level_run[DCT_LUMA_4x4] = x264_coeff_level_run16_ssse3; + if( cpu&X264_CPU_LZCNT ) { - pf->decimate_score15 = x264_decimate_score15_ssse3_slowctz; - pf->decimate_score16 = x264_decimate_score16_ssse3_slowctz; + pf->coeff_level_run4 = x264_coeff_level_run4_ssse3; + pf->coeff_level_run8 = x264_coeff_level_run8_ssse3; + pf->coeff_level_run[ DCT_LUMA_AC] = x264_coeff_level_run15_ssse3_lzcnt; + pf->coeff_level_run[DCT_LUMA_4x4] = x264_coeff_level_run16_ssse3_lzcnt; } - pf->decimate_score64 = x264_decimate_score64_ssse3; } if( cpu&X264_CPU_SSE4 ) @@ -537,21 +675,60 @@ void x264_quant_init( x264_t *h, int cpu, x264_quant_function_t *pf ) pf->quant_4x4_dc = x264_quant_4x4_dc_sse4; pf->quant_4x4 = x264_quant_4x4_sse4; pf->quant_8x8 = x264_quant_8x8_sse4; - pf->optimize_chroma_dc = x264_optimize_chroma_dc_sse4; + pf->optimize_chroma_2x2_dc = x264_optimize_chroma_2x2_dc_sse4; } if( cpu&X264_CPU_AVX ) { - pf->dequant_4x4 = x264_dequant_4x4_avx; - pf->dequant_8x8 = x264_dequant_8x8_avx; pf->dequant_4x4_dc = x264_dequant_4x4dc_avx; - pf->optimize_chroma_dc = x264_optimize_chroma_dc_avx; + if( h->param.i_cqm_preset != X264_CQM_FLAT ) + { + pf->dequant_4x4 = x264_dequant_4x4_avx; + pf->dequant_8x8 = x264_dequant_8x8_avx; + } + pf->idct_dequant_2x4_dc = x264_idct_dequant_2x4_dc_avx; + pf->idct_dequant_2x4_dconly = x264_idct_dequant_2x4_dconly_avx; + pf->optimize_chroma_2x2_dc = x264_optimize_chroma_2x2_dc_avx; pf->denoise_dct = x264_denoise_dct_avx; } + + if( cpu&X264_CPU_XOP ) + { + if( h->param.i_cqm_preset != X264_CQM_FLAT ) + { + pf->dequant_4x4 = x264_dequant_4x4_xop; + pf->dequant_8x8 = x264_dequant_8x8_xop; + } + } + + if( cpu&X264_CPU_AVX2 ) + { + pf->quant_4x4 = x264_quant_4x4_avx2; + pf->quant_4x4_dc = x264_quant_4x4_dc_avx2; + pf->quant_8x8 = x264_quant_8x8_avx2; + pf->quant_4x4x4 = x264_quant_4x4x4_avx2; + pf->dequant_4x4 = x264_dequant_4x4_avx2; + pf->dequant_8x8 = x264_dequant_8x8_avx2; + pf->dequant_4x4_dc = x264_dequant_4x4dc_avx2; + if( h->param.i_cqm_preset == X264_CQM_FLAT ) + { + pf->dequant_4x4 = x264_dequant_4x4_flat16_avx2; + pf->dequant_8x8 = x264_dequant_8x8_flat16_avx2; + } + pf->decimate_score64 = x264_decimate_score64_avx2; + pf->denoise_dct = x264_denoise_dct_avx2; + if( cpu&X264_CPU_LZCNT ) + { + pf->coeff_last[DCT_LUMA_8x8] = x264_coeff_last64_avx2_lzcnt; + pf->coeff_level_run[ DCT_LUMA_AC] = x264_coeff_level_run15_avx2_lzcnt; + pf->coeff_level_run[DCT_LUMA_4x4] = x264_coeff_level_run16_avx2_lzcnt; + } + } #endif // HAVE_MMX #if HAVE_ALTIVEC - if( cpu&X264_CPU_ALTIVEC ) { + if( cpu&X264_CPU_ALTIVEC ) + { pf->quant_2x2_dc = x264_quant_2x2_dc_altivec; pf->quant_4x4_dc = x264_quant_4x4_dc_altivec; pf->quant_4x4 = x264_quant_4x4_altivec; @@ -564,13 +741,18 @@ void x264_quant_init( x264_t *h, int cpu, x264_quant_function_t *pf ) #if HAVE_ARMV6 if( cpu&X264_CPU_ARMV6 ) - pf->coeff_last[DCT_CHROMA_DC] = x264_coeff_last4_arm; - + { + pf->coeff_last4 = x264_coeff_last4_arm; + pf->coeff_last8 = x264_coeff_last8_arm; + } +#endif +#if HAVE_ARMV6 || ARCH_AARCH64 if( cpu&X264_CPU_NEON ) { pf->quant_2x2_dc = x264_quant_2x2_dc_neon; pf->quant_4x4 = x264_quant_4x4_neon; pf->quant_4x4_dc = x264_quant_4x4_dc_neon; + pf->quant_4x4x4 = x264_quant_4x4x4_neon; pf->quant_8x8 = x264_quant_8x8_neon; pf->dequant_4x4 = x264_dequant_4x4_neon; pf->dequant_4x4_dc = x264_dequant_4x4_dc_neon; @@ -578,6 +760,39 @@ void x264_quant_init( x264_t *h, int cpu, x264_quant_function_t *pf ) pf->coeff_last[ DCT_LUMA_AC] = x264_coeff_last15_neon; pf->coeff_last[DCT_LUMA_4x4] = x264_coeff_last16_neon; pf->coeff_last[DCT_LUMA_8x8] = x264_coeff_last64_neon; + pf->denoise_dct = x264_denoise_dct_neon; + pf->decimate_score15 = x264_decimate_score15_neon; + pf->decimate_score16 = x264_decimate_score16_neon; + pf->decimate_score64 = x264_decimate_score64_neon; + } +#endif +#if ARCH_AARCH64 + if( cpu&X264_CPU_ARMV8 ) + { + pf->coeff_last4 = x264_coeff_last4_aarch64; + pf->coeff_last8 = x264_coeff_last8_aarch64; + pf->coeff_level_run4 = x264_coeff_level_run4_aarch64; + } + if( cpu&X264_CPU_NEON ) + { + pf->coeff_level_run8 = x264_coeff_level_run8_neon; + pf->coeff_level_run[ DCT_LUMA_AC] = x264_coeff_level_run15_neon; + pf->coeff_level_run[ DCT_LUMA_4x4] = x264_coeff_level_run16_neon; + } +#endif + +#if HAVE_MSA + if( cpu&X264_CPU_MSA ) + { + pf->quant_4x4 = x264_quant_4x4_msa; + pf->quant_4x4_dc = x264_quant_4x4_dc_msa; + pf->quant_4x4x4 = x264_quant_4x4x4_msa; + pf->quant_8x8 = x264_quant_8x8_msa; + pf->dequant_4x4 = x264_dequant_4x4_msa; + pf->dequant_4x4_dc = x264_dequant_4x4_dc_msa; + pf->dequant_8x8 = x264_dequant_8x8_msa; + pf->coeff_last[DCT_LUMA_4x4] = x264_coeff_last16_msa; + pf->coeff_last[DCT_LUMA_8x8] = x264_coeff_last64_msa; } #endif #endif // HIGH_BIT_DEPTH