You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
PowerPC comparisons returned or stored in variables decompile poorly, as they use countLeadingZeros(v) >> 5 as a way to check if v is 0 (as if so, v has 32 bits set to 0, and 32 >> 5 == 1).
To Reproduce
Decompile the attached binaries, using PowerPC:BE:32:default:default as the language. For instance, equals3_32 in cntlz_O1.o looks like this:
The 64-bit version looks sillier, producing this (note that I had to manually set the data type and set custom storage to r3 and r4 for this; by default ghidra detects it as 2 uint parameters and with just longlong it tries to place it on the stack):
Expected behavior
The decompiled code should look closer to the original code, ideally generating param_1 == 3 in all cases (but something like param_1 ^ 3 == 0 would still be a major improvement).
Attachments cntlz.zip — contains .o files at -O0 through -O3 with and without -g (though -O1, -O2, and -O3 are all the same without -g) compiled using powerpc-eabi-gcc provided via devkitPPC. (I release this code under CC0.)
Environment (please complete the following information):
OS: Windows 10, insider build 19042
Java Version: 11.0.3
Ghidra Version: 9.2.2
Ghidra Origin: official ghidra-sre.org distro
Additional context
I have also seen variable - 3 instead of variable ^ 3, but this doesn't seem to happen with GCC.
This relates to #2121 (though I don't think adding a PcodeOp for countLeadingZeros would fix it on its own, nor am I sure that a fix would actually require adding a PcodeOp).
The text was updated successfully, but these errors were encountered:
Describe the bug
PowerPC comparisons returned or stored in variables decompile poorly, as they use
countLeadingZeros(v) >> 5
as a way to check ifv
is 0 (as if so,v
has 32 bits set to 0, and32 >> 5 == 1
).To Reproduce
Decompile the attached binaries, using
PowerPC:BE:32:default:default
as the language. For instance,equals3_32
incntlz_O1.o
looks like this:The 64-bit version looks sillier, producing this (note that I had to manually set the data type and set custom storage to r3 and r4 for this; by default ghidra detects it as 2
uint
parameters and with justlonglong
it tries to place it on the stack):The unoptimized versions have various sign-extensions and masks that don't show up when optimisations are turned on:
Expected behavior
The decompiled code should look closer to the original code, ideally generating
param_1 == 3
in all cases (but something likeparam_1 ^ 3 == 0
would still be a major improvement).Attachments
cntlz.zip — contains
.o
files at-O0
through-O3
with and without-g
(though-O1
,-O2
, and-O3
are all the same without-g
) compiled usingpowerpc-eabi-gcc
provided via devkitPPC. (I release this code under CC0.)Environment (please complete the following information):
Additional context
I have also seen
variable - 3
instead ofvariable ^ 3
, but this doesn't seem to happen with GCC.This relates to #2121 (though I don't think adding a PcodeOp for
countLeadingZeros
would fix it on its own, nor am I sure that a fix would actually require adding a PcodeOp).The text was updated successfully, but these errors were encountered: