From 28a2d7af87ceb29b93e73c99406316c04b2c9f23 Mon Sep 17 00:00:00 2001 From: Loren Merritt Date: Sun, 20 Apr 2008 12:19:46 -0600 Subject: [PATCH] checkasm cabac --- common/cabac.c | 4 +--- common/cabac.h | 9 ++++++++- common/x86/cabac-a.asm | 2 +- encoder/rdo.c | 1 + tools/checkasm.c | 33 ++++++++++++++++++++++++++++++++- 5 files changed, 43 insertions(+), 6 deletions(-) diff --git a/common/cabac.c b/common/cabac.c index ad5d203f..162978e5 100644 --- a/common/cabac.c +++ b/common/cabac.c @@ -895,8 +895,7 @@ static inline void x264_cabac_encode_renorm( x264_cabac_t *cb ) x264_cabac_putbyte( cb ); } -#ifndef HAVE_MMX -void x264_cabac_encode_decision( x264_cabac_t *cb, int i_ctx, int b ) +void x264_cabac_encode_decision_c( x264_cabac_t *cb, int i_ctx, int b ) { int i_state = cb->state[i_ctx]; int i_range_lps = x264_cabac_range_lps[i_state][(cb->i_range>>6)&0x03]; @@ -909,7 +908,6 @@ void x264_cabac_encode_decision( x264_cabac_t *cb, int i_ctx, int b ) cb->state[i_ctx] = x264_cabac_transition[i_state][b]; x264_cabac_encode_renorm( cb ); } -#endif void x264_cabac_encode_bypass( x264_cabac_t *cb, int b ) { diff --git a/common/cabac.h b/common/cabac.h index 1c762b89..091992fd 100644 --- a/common/cabac.h +++ b/common/cabac.h @@ -53,12 +53,19 @@ void x264_cabac_context_init( x264_cabac_t *cb, int i_slice_type, int i_qp, int /* encoder only: */ void x264_cabac_encode_init ( x264_cabac_t *cb, uint8_t *p_data, uint8_t *p_end ); -void x264_cabac_encode_decision( x264_cabac_t *cb, int i_ctx, int b ); +void x264_cabac_encode_decision_c( x264_cabac_t *cb, int i_ctx, int b ); +void x264_cabac_encode_decision_asm( x264_cabac_t *cb, int i_ctx, int b ); void x264_cabac_encode_bypass( x264_cabac_t *cb, int b ); void x264_cabac_encode_ue_bypass( x264_cabac_t *cb, int exp_bits, int val ); void x264_cabac_encode_terminal( x264_cabac_t *cb ); void x264_cabac_encode_flush( x264_t *h, x264_cabac_t *cb ); +#ifdef HAVE_MMX +#define x264_cabac_encode_decision x264_cabac_encode_decision_asm +#else +#define x264_cabac_encode_decision x264_cabac_encode_decision_c +#endif + static inline int x264_cabac_pos( x264_cabac_t *cb ) { return (cb->p - cb->p_start + cb->i_bytes_outstanding) * 8 + cb->i_queue; diff --git a/common/x86/cabac-a.asm b/common/x86/cabac-a.asm index 26a20d08..e0c52359 100644 --- a/common/x86/cabac-a.asm +++ b/common/x86/cabac-a.asm @@ -81,7 +81,7 @@ endstruc %endif %endmacro -cglobal x264_cabac_encode_decision, 0,7 +cglobal x264_cabac_encode_decision_asm, 0,7 movifnidn t0d, r0m movifnidn t1d, r1m picgetgot t2 diff --git a/encoder/rdo.c b/encoder/rdo.c index bd481cf4..8607e075 100644 --- a/encoder/rdo.c +++ b/encoder/rdo.c @@ -41,6 +41,7 @@ static uint16_t cabac_prefix_size[15][128]; /* CABAC: not exactly the same. x264_cabac_size_decision() keeps track of * fractional bits, but only finite precision. */ +#undef x264_cabac_encode_decision #define x264_cabac_encode_decision(c,x,v) x264_cabac_size_decision(c,x,v) #define x264_cabac_encode_terminal(c) x264_cabac_size_decision(c,276,0) #define x264_cabac_encode_bypass(c,v) ((c)->f8_bits_encoded += 256) diff --git a/tools/checkasm.c b/tools/checkasm.c index 05c25bdb..73faf122 100644 --- a/tools/checkasm.c +++ b/tools/checkasm.c @@ -854,6 +854,36 @@ static int check_intra( int cpu_ref, int cpu_new ) return ret; } +#define DECL_CABAC(cpu) \ +static void run_cabac_##cpu( uint8_t *dst )\ +{\ + int i;\ + x264_cabac_t cb;\ + x264_cabac_context_init( &cb, SLICE_TYPE_P, 26, 0 );\ + x264_cabac_encode_init( &cb, dst, dst+0xff0 );\ + for( i=0; i<0x400; i++ )\ + x264_cabac_encode_decision_##cpu( &cb, buf1[i]>>1, buf1[i]&1 );\ +} +DECL_CABAC(c) +#ifdef HAVE_MMX +DECL_CABAC(asm) +#else +#define run_cabac_asm run_cabac_c +#endif + +static int check_cabac( int cpu_ref, int cpu_new ) +{ + int ret = 0, ok, used_asm = 1; + if( cpu_ref || run_cabac_c == run_cabac_asm) + return 0; + memcpy( buf4, buf3, 0x1000 ); + call_c( run_cabac_c, buf3 ); + call_a( run_cabac_asm, buf4 ); + ok = !memcmp( buf3, buf4, 0x1000 ); + report( "cabac :" ); + return ret; +} + int check_all( int cpu_ref, int cpu_new ) { return check_pixel( cpu_ref, cpu_new ) @@ -861,7 +891,8 @@ int check_all( int cpu_ref, int cpu_new ) + check_mc( cpu_ref, cpu_new ) + check_intra( cpu_ref, cpu_new ) + check_deblock( cpu_ref, cpu_new ) - + check_quant( cpu_ref, cpu_new ); + + check_quant( cpu_ref, cpu_new ) + + check_cabac( cpu_ref, cpu_new ); } int add_flags( int *cpu_ref, int *cpu_new, int flags, const char *name ) -- 2.39.2