matt-kempster / m2c

A MIPS and PowerPC decompiler.
GNU General Public License v3.0
396 stars 48 forks source link

Implement PPC carry/extended ops, floating intriniscs, clz #207

Closed zbanks closed 2 years ago

zbanks commented 2 years ago

This rounds out the most popular instructions. There's a histogram of remaining instructions in the projects I know about in this gist.

Added instructions:

The carry/extended behavior of the -c/-e instructions is not implemented. Usually these instructions are used to implement 64-bit integer arithmetic, but the codebase isn't currently equipped to easily handle this. (The instructions may be interleaved, and the value may be in an arbitrary pair of registers.)

Added a pattern to fold_divmod to rewrite CLZ(x) >> 5 into x == 0. This accounts for ~80% of cntlzw usage (and is why its implemented as a UnaryOp instead of a fn_op). This is tested by the comparison e2e test.

Also expanded the pattern for modulo-by-power-of-2 to match the MWCC version, which emits (x - (x >> N) * M) instead of (x - (x / N) * N).

The other comparison patterns aren't detected yet (see the comparison e2e test).