So, there is a part of the game I'm working on that needs to multiply a number by another one that doesn't change while a level is played (only between levels). It's a simple 8x8=8 multiplication and with an unrolled loop it was quite fast. But I need to do this so many times during a frame that I figured I had to make the process as fast as I could.
Since I have no space for a look-up table that large, I made a routine that generates the optimal code to multiply any number by the number in question. Since the number I'm multiplying for is constant, the generated uses the accumulator as much as it can before using a RAM variable, and it knows when to add the doubling value to the accumulator without having to check any bits.
The results are very good, the generated code works flawlessly and it's much faster than the old routine, even if you consider the JMPs necessary to call it and return (it's used only in one place, so there is no need for JSR and RTS). I'm just not sure this solution is worth the 30 something bytes the dynamic code occupies, or even if it's worth the complexity it adds to the program. I can't think of any technical reason not to do this (if the RAM gets corrupted somehow, it would be just as catastrophic as, say, if a pointer got screwed up). Do you guys have any considerations on this subject? Reasons for using or not using dynamic code?
Since I have no space for a look-up table that large, I made a routine that generates the optimal code to multiply any number by the number in question. Since the number I'm multiplying for is constant, the generated uses the accumulator as much as it can before using a RAM variable, and it knows when to add the doubling value to the accumulator without having to check any bits.
The results are very good, the generated code works flawlessly and it's much faster than the old routine, even if you consider the JMPs necessary to call it and return (it's used only in one place, so there is no need for JSR and RTS). I'm just not sure this solution is worth the 30 something bytes the dynamic code occupies, or even if it's worth the complexity it adds to the program. I can't think of any technical reason not to do this (if the RAM gets corrupted somehow, it would be just as catastrophic as, say, if a pointer got screwed up). Do you guys have any considerations on this subject? Reasons for using or not using dynamic code?