Changes in udhcp
Denys Vlasenko
vda.linux at googlemail.com
Fri Nov 30 05:29:18 UTC 2007
On Thursday 29 November 2007 06:37, Ralf Friedl wrote:
> 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);
I'm afraid you need to add some code to handle mask==0.
Existing code compiles to 6 instructions (11 bytes):
xorl %edx, %edx # i
jmp .L55 #
.L56: incl %edx # i
sall %eax # mask
.L55: testl %eax, %eax # mask
jne .L56 #,
Seems good enough to me.
--
vda
More information about the busybox
mailing list