I need some help reverse engineering a function in MIPS assembly. It was compiled for the PlayStation 2's EmotionEngine CPU. My goal is to produce a matching decomp of the function; it is the proof-of-concept for a project of mine that I am hoping will get the ball rolling for PS2 decompilation.
The function is very simple; it takes two floats, g
and absLimit
, and limits the absolute value of g
to absLimit
. Here is the C++ source code I have written so far (not matching):
// Limits the absolute value of g to absLimit
float GLimitAbs(float g, float absLimit)
{
float result = g;
if (g > absLimit)
result = absLimit;
else if (g < -absLimit)
result = -absLimit;
return result;
}
Here you can see the target assembly on the left, and the current compiled source on the right. The compiler is ee-gcc 2.96
with standard optimization (-O2
).
As you can see, the target assembly has this confounding pattern of c.lt.s
instructions followed by nop
s, whereas my code produces c.olt.s
instructions sans nop
s.
My research has not turned up much as there are very few resources for PS2 reversing. One thing I've learned is that the OLT compare "does not signal an exception for unordered values" while the LT compare does. However, I don't fully understand what that means or what kind of code pattern would result in one over the other.
Is there some change to the source that I'm missing that would produce a matching decomp of the function? Or could perhaps the only explanation be that I'm using the wrong compiler/assembler/etc? Any help would be appreciated.