Unsigned integer division by 10
|
|
Bjørn
|
|
Registered Member #27
Joined: Fri Feb 03 2006, 02:20AM
Location: Hyperborea
Posts: 2058
|
My main problem with that method is that if I multiply with anything larger than 1, numbers like 0xFFFFFFFF will overflow a 32 bit register. I might need 96 bits to make sure that method works with all numbers and that is going to be quite slow.
With a 64 bit multiply (n*429496730)>>32 works for all numbers up to 1 073 741 829 and (n*1717986919)>>34 works for all numbers up to 2 863 311 539.
Edit: ((n-(n>>30))*429496730)>>32 works on all 32 bit numbers and takes at most 7 cycles on an ARM7 with a 64 bit multiplier. That is more than twice as fast as I was looking for.
|
Back to top
|
|
Moderator(s): Chris Russell, Noelle, Alex, Tesladownunder, Dave Marshall, Dave Billington, Bjørn, Steve Conner, Wolfram, Kizmo, Mads Barnkob
|
|
Powered by e107 Forum System
|