[PATCH] unify itoa

Rob Landley rob at landley.net
Tue Jul 11 19:41:17 UTC 2006


On Tuesday 11 July 2006 12:14 pm, Denis Vlasenko wrote:
> On Tuesday 11 July 2006 16:44, Denis Vlasenko wrote:
> > It's even a bit smaller. gcc is smart enough to know div instruction
> > produces the remainder also, and we get n %= i for free.
> >
> > I still dislike the speed, i/=10 eats too much CPU...
>
> This patch converts division into mul + shift.
> It's smaller and faster.
>
> i = (i*429496730ULL)>>32 /* divide by 10, fast */

A) That's too ugly for words.

B) On what platform are you having a speed problem, and on what platform is 
this an improvement?  On 32 bit platforms (which are what most of busybox is 
deployed on these days, and where most of it will _continue_ to be deployed 
on for years to come if not the foreseeable future) gcc produces absolutely 
_horrible_ code for long long multiplies, and it triggers the gcc_s shared 
library problem with some toolchains.

C) On a lot of 64 bit platforms (I don't know if it's all), long long is a 128 
bit number, so this is a big pessimization.

> Speed is ok, correctness check ok:
>
> sprintf='12345678' count=27599
> utoa_to_buf='12345678' count=62667
> utoa='12345678' count=59227
> utoa_to_buf_test='12345678' count=41303

What are you using to produce these numbers?  What hardware, what test 
program, and what _other_ platforms have you tried it on to see what the 
impact is there?

Rob
-- 
Never bet against the cheap plastic solution.



More information about the busybox mailing list