]> git.videolan.org Git - x264.git/commitdiff
Add miscompilation check for x264_clz
authorJason Garrett-Glaser <darkshikari@gmail.com>
Fri, 9 Apr 2010 08:49:55 +0000 (01:49 -0700)
committerJason Garrett-Glaser <darkshikari@gmail.com>
Sun, 11 Apr 2010 03:44:54 +0000 (20:44 -0700)
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

index 289f45880f72ed5e6846934033686179e95e055b..eb8d89a35bb99d7f769c48ec1f056468e874e42f 100644 (file)
@@ -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 )