[Olsr-dev] Fixed Point Math Patch - please apply
Sven-Ola Tücke
(spam-protected)
Thu Feb 14 08:16:24 CET 2008
Morning,
fixed point math seems to run. On a standard WRT (Mips, 200Mhz) it saves
around 50%. On my PC it saves nothing (that can be measured currently). I
have a web camera with ~ 25 Bogomips where I can see no saving at all. You
can find the patch here - please apply:
http://ff-firmware.cvs.sourceforge.net/*checkout*/ff-firmware/ff-devel/101-olsrd-fpm.patch
Technical Info:
Fixed point math replaces floating point calculations by integer counterparts.
The 20 higher bits of a typical 32 bit hold the digits before the deciaml
point > 1.0, the lower 12 bits hold the digits after the decimal point. An
old trick, e.g. use in gaming to speed up calculations, because long (+-*/)
long is always faster than float (+-*/). Of course, all calculations and
automatic number conversions have to be found and adpated.
To help in debugging, I added and #ifdef USE_FPM to toggle betwenn FPM and
normal maths. We can remove that at a later stage if we are sure it works
correct. For this, I added CPPFLAGS+=USE_FPM to the central Makefile.inc.
Also critical: When using 20+12 bits, one have to check for overflows and
underflows. This is done by a number of assert() statements active only if
you compile with "make DEBUG=1". The olsrd compiled in this way will of
course save no CPU cycles.
I only converted some critical parts to FPM - theres still floating point math
left inside (e.g. the config file parsing and the int-to-double-vtime stuff).
@Eric: In the BMF Plugin, there is something like maxETX=2*INFINITE_ETX and a
calculation like etx1+etx2 without a range check against the INFINITE_ETX
value. For this reason, I adapted BMF in a way that it still uses floats.
The patch is double licensed as required (both BSD and GPL2).
P.S. AFAIK, the patch programme does not like mixed licensed patches - so with
the above sentence the patch should not output the standard license error
codes <ggg> Also I really do not care about the BSD - FSF license combat. Yes
I know - some day a gun/car/bomb with an "powered by olsrd" sticker on it may
be spotted in the supermarket. C'est la vie...
// Sven-Ola
More information about the Olsr-dev
mailing list