Changes in udhcp
Ralf Friedl
Ralf.Friedl at online.de
Thu Nov 29 14:37:05 UTC 2007
Hi
I have two remarks to the recent changes to udhcp.
networking/udhcp/script.c contains "static int mton()" to count the bits
of a network mask. This could use the ffs() function:
The ffs() function returns the position of the first (least
significant) bit set in the word i. The least significant bit is
position 1 and the most significant position is 32.
So mton could be written as
return 32 - (ffs (ntohl(mask)) - 1);
Newer version of gcc also contain __builtin_clz which counts leading
(high) zero bits. As we want to count leading one bits, we must first
invert mask.
return __builtin_clz (~ntohl(mask));
Both examples are not tested, so some modifications might be necessary.
__builtin_clz and probably also ffs use special CPU instructions where
available, so they would be both faster and smaller in that case.
Otherwise they probably call into libgcc, which is present anyway.
In networking/udhcp/leases.c I found the comment "= { 0 } helps gcc to
put it in rodata, not bss".
Why is it desirable to have it in rodata instead of bss? rodata consumes
space in the file while bss doesn't.
Regards
Ralf Friedl
More information about the busybox
mailing list