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).

enter image description here

As you can see, the target assembly has this confounding pattern of c.lt.s instructions followed by nops, whereas my code produces c.olt.s instructions sans nops.

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.

  • I suspect the difference is rooted in different compiler flags. The missing NOPs are an indicator the right side is better optimized. Also OLT is faster than LT. Try compiling with less optimization than O2, and play around with math modes like -ffast-math or its negation. Jul 1, 2022 at 17:07


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.