Open RamonUnch opened 2 years ago
For modulo by constants, masking the upper bits accomplishes that for powers of two: 2, 4, 8.... 256, etc. It may be worth it to build a separate lookup table for other values. Multiplication and division on these old, 1970s microprocessors was so slow that some CISCs didn't even bother with the microcode for them, let alone dedicated hardware.
for modulo by a power of two WC already makes the optimization IIRC.
FastDoom could benefit from the optimisation of the modulo
%
operation. Internally WC generates an idiv operation. The optimization is similar to the divisions by a constant because it is almost the same thing: ie:There are very few places where the
x % constant
is used and it would almost not affect much performances.Also there are some missing optimizations: signed and unsigned divisions should be separated and when you are dividing a value you know to be positive (ie: monster damage), then an unsigned variant of the division should be used: example for unsigned Div10:
unsigned versions save a few instructions and mul is faster than imul (presumably?) I simply use GCC with -O2 -march=i386 and -mtune=generic Those should not be hard to inline with OpenWatcom. EDIT: I did not check properly all instances of DivXX() clls, maybe you never need unsigned versions...