N64 Decompilation Patterns

From Decompedia
Revision as of 20:18, 5 April 2023 by Mkst (talk | contribs) (Created page with "==Intro== The act of compiling source code loses a lot of the context and information present in the original source - and the higher the level of optimisation, the more information is lost; decompiling code compiled with <code>-O0</code> is significantly more straightforward than <code>-O2</code>. Some of the codegen differences can be fixed by adding random snippets such as <code>if(1){};</code> or wrapping statements in <code>do { ...} while(0)</code> statements. =...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Intro

The act of compiling source code loses a lot of the context and information present in the original source - and the higher the level of optimisation, the more information is lost; decompiling code compiled with -O0 is significantly more straightforward than -O2.

Some of the codegen differences can be fixed by adding random snippets such as if(1){}; or wrapping statements in do { ...} while(0) statements.

Common Patterns

Division by power-of-two

// when you see this:
if (x > 0) {
    y = x >> 0x10;
} else {
    y = (x + 0xFFFF) >> 0x10;
}

// it's likely:
y = x / 0x10000;

IDO Patterns

IDO is full of quirks.

  • Whitespace can affect codegen


GCC Patterns

GCC is less quirky than IDO.