Go Down

Topic: divmod10() : a fast replacement for /10 and %10 (unsigned) (Read 23 times) previous topic - next topic

Paul Stoffregen


'all' we need to do is document up and make available in a form every one can use easily.
thats that hard part,


How about the Print.cpp and Print.h Tom posted on reply #51 or I posted on #49 and #54 ?

All you have to do to use these is drop them into your Arduino's hardware/arduino/cores/arduino folder (or hardware/teensy/cores/teensy), replacing the Print.cpp and Print.h that are already there.

On a Mac, you'll need to control-click on Arduino and choose "show package contents", then navigate or search until you find the folder with Print.cpp and Print.h.  I believe it's Contents/Resources/Java/hardware/arduino/cores/arduino, but I don't have a Mac handy at the moment to check.

Admittedly, the copy I posted on #54 had test code enabled.  Here's a "final" version with all the test stuff commented, as ready-to-use as it gets.  These are tested with Teensy but probably will work with official Arduino boards.

aarondc

When Arduino release a new IDE, etc, those libraries you have upgraded are potentially going to get blown away, and require work to reinstall / overwrite.

One potential solution would be if you could set up pathing so modified libraries were linked if they existed in rather than default libraries.
Windows serial port monitor: Tellurium | Arduino serial port debugging library: DBG | Cusom LCD char generator | Technical questions will only be answered in forum threads

Paul Stoffregen

I restarted my exhaustive test, using the asm macro version.  In a few days I should be able to confirm if it matches the C library version for all 2^32 possible inputs....

robtillaart

Code: [Select]
Unless there's more algorithm magic, I believe it's safe to say this 83 cycle version is the fastest possible implementation.
That's why I asked several posts back if one of the earlier C version - shorter in terms of C - could be faster is asm as it might be less statements.

Code: [Select]
In a few days I should be able to confirm if it matches the C library version for all 2^32 possible inputs....
how do you do this test? Generate strings and compare them?
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Paul Stoffregen


how do you do this test? Generate strings and compare them?


Compute the quotient and modulus using both and check if either is different.  Basically, like this:

Code: [Select]

                q1 = n / 10;
                m1 = n - q1 * 10;
                q2 = n;
                divmod10_asm(q2, tmp, m2);
                if (q1 != q2 || m1 != m2) {
                        errorcount++;
                }


Here is the complete code.   It should run on any AVR-based Arduino compatible board.

Go Up