[PATCH] unify itoa

Denis Vlasenko vda.linux at googlemail.com
Tue Jul 11 16:14:09 UTC 2006


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 */

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
utoa_to_buf_test(0)='0'
utoa_to_buf_test(123)='123'
utoa_to_buf_test(100223)='100223'
utoa_to_buf_test(100223,3)='23'
utoa_to_buf_test(100223,2)='3'
utoa_to_buf_test(100223,1)=''

Please apply.
--
vda
-------------- next part --------------
A non-text attachment was scrubbed...
Name: itoa.diff
Type: text/x-diff
Size: 930 bytes
Desc: not available
Url : http://lists.busybox.net/pipermail/busybox/attachments/20060711/863e5e7d/attachment.bin 


More information about the busybox mailing list