Skip to content

Compiler Patterns and Gotchas

mattbruv edited this page Oct 23, 2020 · 4 revisions

Modulo instruction generation

This pattern denotes a modulo operation: r3 % r4:

divwu r0, r3, r4
mullw r0, r0, r4
subf  r0, r0, r3

Narrowing to a u8

This pattern: clrlwi r3, r5, 0x18 is the result of casting a boolean value to an integer. In this example, there is a function that returns an unsigned int in r3, and the r5 register either has 0 or 1.

In many places throughout the code, Heavy Iron uses 4 byte integers as return values for functions which return a boolean type, whereas in C++, the bool keyword is equivalent to a single byte.

Clone this wiki locally