09-22-2019, 11:39 PM
Maybe your code could benefit from some simplification. I find that a code is a lot easier to debug when it’s optimized.
Recommendation 1: instead of having multiple branches, take the absolute value of your number you want to check and then just check if it’s greater/less than some bound, in one branch. Here’s the relevant function (parameter r3, return r6) from the PPC CWG:
srawi R4,R3,31
xor R5,R4,R3
subf R6,R4,R5
Recommendation 2: I noticed you have a lot of repeated code for the checks with different registers. There are two ways to fix this: either make your repeated code into a function or implement self-modifying ASM, in which you use the BL trick to get the address of the ASM address you want, then use rlwimi to change the register bits of the opcode. The catch with this is that you have to flush the instruction cache in order to fully “reset” your ASM; since it’s a little overkill so I would probably just use a function.
Recommendation 1: instead of having multiple branches, take the absolute value of your number you want to check and then just check if it’s greater/less than some bound, in one branch. Here’s the relevant function (parameter r3, return r6) from the PPC CWG:
srawi R4,R3,31
xor R5,R4,R3
subf R6,R4,R5
Recommendation 2: I noticed you have a lot of repeated code for the checks with different registers. There are two ways to fix this: either make your repeated code into a function or implement self-modifying ASM, in which you use the BL trick to get the address of the ASM address you want, then use rlwimi to change the register bits of the opcode. The catch with this is that you have to flush the instruction cache in order to fully “reset” your ASM; since it’s a little overkill so I would probably just use a function.