From 8cf3a83dd735fd90f169d92428b1f047bb9eda7f Mon Sep 17 00:00:00 2001 From: Gregory Hainaut Date: Wed, 11 Jan 2017 21:25:09 +0100 Subject: [PATCH] gsdx: try to ask GCC to generate not dumb code Unfortunately it requires at least GCC6. If a nice guy can check the generated code on GCC6. I don't know clang status. Here the only example, I have found on the web https://developers.redhat.com/blog/2016/02/25/new-asm-flags-feature-for-x86-in-gcc-6/ Current generated code in GSTextureCache::SourceMap::Add 38b3: bsf eax,esi 38b6: add esp,0x10 38b9: test esi,esi 38bb: jne 387e BSF already set the Z flag when input (esi) is 0. So it would be better to not put a silly add before the jump and to skip the test operation. --- plugins/GSdx/stdafx.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/plugins/GSdx/stdafx.h b/plugins/GSdx/stdafx.h index be7096a88a..a1e0312e28 100644 --- a/plugins/GSdx/stdafx.h +++ b/plugins/GSdx/stdafx.h @@ -391,11 +391,17 @@ using namespace stdext; // http://svn.reactos.org/svn/reactos/trunk/reactos/include/crt/mingw32/intrin_x86.h?view=markup - __forceinline unsigned char _BitScanForward(unsigned long* const Index, const unsigned long Mask) + __forceinline int _BitScanForward(unsigned long* const Index, const unsigned long Mask) { - __asm__("bsfl %k[Mask], %k[Index]" : [Index] "=r" (*Index) : [Mask] "mr" (Mask)); - +#if defined(__GCC_ASM_FLAG_OUTPUTS__) && 0 + // Need GCC6 to test the code validity + int flag; + __asm__("bsfl %k[Mask], %k[Index]" : [Index] "=r" (*Index), "=@ccz" (flag) : [Mask] "mr" (Mask)); + return flag; +#else + __asm__("bsfl %k[Mask], %k[Index]" : [Index] "=r" (*Index) : [Mask] "mr" (Mask) : "cc"); return Mask ? 1 : 0; +#endif } #ifdef __GNUC__