This patch register spills the mvc_max variable when x264_ultrahardened is defined. The work in this patch is released under whichever license the x264 project has now or on the future. Patch is: © (c) 2013 Francisco Blas Izquierdo Riera (klondike) klondike (a t ) gentoo.org --- common/x86/util.h 2013-09-12 22:45:04.000000000 +0200 +++ common/x86/util.h 2013-11-03 20:35:18.646888328 +0100 @@ -121,11 +121,18 @@ return amvd; } +/*Some hardened systems only have available 4 registers on x86 systems. If that's he case we have to register spill mvc_max*/ +#ifdef x264_ultrahardened +#define mvc_max_mode "=m" +#else +#define mvc_max_mode "+r" +#endif + #define x264_predictor_clip x264_predictor_clip_mmx2 static int ALWAYS_INLINE x264_predictor_clip_mmx2( int16_t (*dst)[2], int16_t (*mvc)[2], int i_mvc, int16_t mv_limit[2][2], uint32_t pmv ) { static const uint32_t pd_32 = 0x20; - intptr_t tmp = (intptr_t)mv_limit, mvc_max = i_mvc, i = 0; + intptr_t tmp = (intptr_t)mv_limit, mvc_max = ((uint32_t *)mvc)+i_mvc, i = 0; asm( "movq (%2), %%mm5 \n" @@ -137,7 +145,6 @@ "punpckldq %%mm3, %%mm3 \n" "punpckldq %%mm5, %%mm5 \n" "movd %7, %%mm4 \n" - "lea (%0,%3,4), %3 \n" "1: \n" "movq (%0), %%mm0 \n" "add $8, %0 \n" @@ -176,7 +183,7 @@ "and $1, %k2 \n" "sub %2, %4 \n" // output += !(mv == pmv || mv == 0) "3: \n" - :"+r"(mvc), "=m"(M64( dst )), "+r"(tmp), "+r"(mvc_max), "+r"(i) + :"+r"(mvc), "=m"(M64( dst )), "+r"(tmp), mvc_max_mode(mvc_max), "+r"(i) :"r"(dst), "g"(pmv), "m"(pd_32), "m"(M64( mvc )) ); return i; @@ -188,7 +195,7 @@ { static const uint64_t pw_2 = 0x0002000200020002ULL; static const uint32_t pd_32 = 0x20; - intptr_t tmp = (intptr_t)mv_limit, mvc_max = i_mvc, i = 0; + intptr_t tmp = (intptr_t)mv_limit, mvc_max = ((uint32_t *)mvc)+i_mvc, i = 0; asm( "movq (%2), %%mm5 \n" @@ -200,7 +207,6 @@ "punpckldq %%mm3, %%mm3 \n" "punpckldq %%mm5, %%mm5 \n" "movd %8, %%mm4 \n" - "lea (%0,%3,4), %3 \n" "1: \n" "movq (%0), %%mm0 \n" "add $8, %0 \n" @@ -243,7 +249,7 @@ "and $1, %k2 \n" "sub %2, %4 \n" "3: \n" - :"+r"(mvc), "=m"(M64( dst )), "+r"(tmp), "+r"(mvc_max), "+r"(i) + :"+r"(mvc), "=m"(M64( dst )), "+r"(tmp), mvc_max_mode(mvc_max), "+r"(i) :"r"(dst), "m"(pw_2), "g"(pmv), "m"(pd_32), "m"(M64( mvc )) ); return i;