N64 Decompilation Patterns: Difference between revisions
Jump to navigation
Jump to search
(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. =...") |
mNo edit summary |
||
Line 23: | Line 23: | ||
*Whitespace can affect codegen | *Whitespace can affect codegen | ||
*Comparing a float with 0 is different to comparing a float with 0.0f | |||
*Defined vs declared (i.e. use of extern) can affect codegen, including defining variables as static | |||
Latest revision as of 12:20, 15 October 2023
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
- Comparing a float with 0 is different to comparing a float with 0.0f
- Defined vs declared (i.e. use of extern) can affect codegen, including defining variables as static
GCC Patterns
GCC is less quirky than IDO.