[x264-devel] commit: Add miscompilation check for x264_clz (Jason Garrett-Glaser )

git at videolan.org git at videolan.org
Sun Apr 11 06:50:31 CEST 2010


x264 | branch: master | Jason Garrett-Glaser <darkshikari at gmail.com> | Fri Apr  9 01:49:55 2010 -0700| [4f8c44c17425470202759cafc49ae4496745598d] | committer: Jason Garrett-Glaser 

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.

> http://git.videolan.org/gitweb.cgi/x264.git/?a=commit;h=4f8c44c17425470202759cafc49ae4496745598d
---

 encoder/encoder.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/encoder/encoder.c b/encoder/encoder.c
index 289f458..eb8d89a 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 )



More information about the x264-devel mailing list