From dbbaf13a7879e76b6ba36ad2a76695ffd27512dd Mon Sep 17 00:00:00 2001 From: Maxim Poliakovski Date: Fri, 18 Dec 2020 18:31:05 +0100 Subject: [PATCH] ppcopcodes: fix cntlzw to compile properly with Clang. Enable USE_GCC_BUILTINS by default. --- cpu/ppc/ppcemu.h | 2 +- cpu/ppc/ppcopcodes.cpp | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/cpu/ppc/ppcemu.h b/cpu/ppc/ppcemu.h index 481be6c..b9c8694 100644 --- a/cpu/ppc/ppcemu.h +++ b/cpu/ppc/ppcemu.h @@ -35,7 +35,7 @@ along with this program. If not, see . //#define ILLEGAL_OP_SAFE 1 // Uncomment this to use GCC built-in functions. -//#define USE_GCC_BUILTINS 1 +#define USE_GCC_BUILTINS 1 // Uncomment this to use Visual Studio built-in functions. //#define USE_VS_BUILTINS 1 diff --git a/cpu/ppc/ppcopcodes.cpp b/cpu/ppc/ppcopcodes.cpp index 21c3e21..70e81d3 100644 --- a/cpu/ppc/ppcopcodes.cpp +++ b/cpu/ppc/ppcopcodes.cpp @@ -516,15 +516,16 @@ void dppc_interpreter::ppc_neg() { void dppc_interpreter::ppc_cntlzw() { ppc_grab_regssa(); - uint32_t lead; uint32_t bit_check = ppc_result_d; #ifdef USE_GCC_BUILTINS - lead = !bit_check ? 32 : __builtin_clz(bit_check); + uint32_t lead = !bit_check ? 32 : __builtin_clz(bit_check); #elif defined USE_VS_BUILTINS - lead = __lzcnt(bit_check); + uint32_t lead = __lzcnt(bit_check); #else - for (uint32_t mask = 0x80000000UL, lead = 0; mask; lead++, mask >>= 1) { + uint32_t lead, mask; + + for (mask = 0x80000000UL, lead = 0; mask != 0; lead++, mask >>= 1) { if (bit_check & mask) break; }