From 4f8c44c17425470202759cafc49ae4496745598d Mon Sep 17 00:00:00 2001 From: Jason Garrett-Glaser Date: Fri, 9 Apr 2010 01:49:55 -0700 Subject: [PATCH] Add miscompilation check for x264_clz Running a Phenom-optimized build of x264 (e.g. -march=amdfam10) on a non-Phenom CPU didn't SIGILL; instead it would silently produce incorrect output. Now, instead, it will error out loudly. --- encoder/encoder.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/encoder/encoder.c b/encoder/encoder.c index 289f4588..eb8d89a3 100644 --- a/encoder/encoder.c +++ b/encoder/encoder.c @@ -1001,12 +1001,26 @@ x264_t *x264_encoder_open( x264_param_t *param ) goto fail; if( x264_analyse_init_costs( h, X264_LOOKAHEAD_QP ) ) goto fail; + + /* Checks for known miscompilation issues. */ if( h->cost_mv[1][2013] != 24 ) { x264_log( h, X264_LOG_ERROR, "MV cost test failed: x264 has been miscompiled!\n" ); goto fail; } + /* Must be volatile or else GCC will optimize it out. */ + volatile int temp = 392; + if( x264_clz( temp ) != 23 ) + { + x264_log( h, X264_LOG_ERROR, "CLZ test failed: x264 has been miscompiled!\n" ); +#if defined(ARCH_X86) || defined(ARCH_X86_64) + x264_log( h, X264_LOG_ERROR, "Are you attempting to run an SSE4a-targeted build on a CPU that\n" ); + x264_log( h, X264_LOG_ERROR, "doesn't support it?\n" ); +#endif + goto fail; + } + h->out.i_nal = 0; h->out.i_bitstream = X264_MAX( 1000000, h->param.i_width * h->param.i_height * 4 * ( h->param.rc.i_rc_method == X264_RC_ABR ? pow( 0.95, h->param.rc.i_qp_min ) -- 2.47.3