May 21, 2008 -- Argh! I commented out the optimization code for some testing and forgot to return it. It's back now!
Sept 25, 2008 -- Failed if both a whole and fractional part existed (eg, 3.1416). Fixed.
This program generates JAL code required for single
fixed multiply. It was inspired by the Constant
Division/Multiplication Code Generator by Nikolai
Golovchenko that can be found here:
Value is any value greater than 0. To divide, simply multiply by the inverse (eg, divide by 10 = multiply by 0.1).
Error is the maximum error between the value requested and the real value used expressed as a %.
Round: set to round the value up if the bit past the last bit used in the computation is 1.
Eventually I plan to incorporate this into the JALv2 compiler.
Note that while the code generated is fine, the result after compilation will not be as fast as the result listed above, but it generally will be smaller. Long ago I opted for size reduction over speed.
Select 'detail' to see the gory details used internally to generate the code. Internally the value is converted to a fixed point value with a 32.32 bit format. The shift distances on the left side of the binary point are one greater than the real shift distance to account for a valid, 0 shift.
Source for this program can be found at http://www.casadeyork.com/jalv2/cmul.c
A good write-up about how this works can be found here: