mirror of
https://github.com/dingusdev/dingusppc.git
synced 2025-01-11 20:29:46 +00:00
ppcopcodes: fix cntlzw with __builtin_clz.
The result of __builtin_clz is undefined when the source operand is zero. Add a check for this case and handle it accordingly.
This commit is contained in:
parent
5cba9c1dae
commit
99641b1b5e
@ -516,15 +516,15 @@ void dppc_interpreter::ppc_neg() {
|
|||||||
void dppc_interpreter::ppc_cntlzw() {
|
void dppc_interpreter::ppc_cntlzw() {
|
||||||
ppc_grab_regssa();
|
ppc_grab_regssa();
|
||||||
|
|
||||||
uint32_t lead = 0;
|
uint32_t lead;
|
||||||
uint32_t bit_check = ppc_result_d;
|
uint32_t bit_check = ppc_result_d;
|
||||||
|
|
||||||
#ifdef USE_GCC_BUILTINS
|
#ifdef USE_GCC_BUILTINS
|
||||||
lead = __builtin_clz(bit_check);
|
lead = !bit_check ? 32 : __builtin_clz(bit_check);
|
||||||
#elif defined USE_VS_BUILTINS
|
#elif defined USE_VS_BUILTINS
|
||||||
lead = __lzcnt(bit_check);
|
lead = __lzcnt(bit_check);
|
||||||
#else
|
#else
|
||||||
for (uint32_t mask = 0x80000000UL; mask; lead++, mask >>= 1) {
|
for (uint32_t mask = 0x80000000UL, lead = 0; mask; lead++, mask >>= 1) {
|
||||||
if (bit_check & mask)
|
if (bit_check & mask)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user