Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAL3m8eAkutia2mxJqzi+RiW4BfQcYCTzi5jwkSSS99xkfOxZjg@mail.gmail.com>
Date: Sun, 5 May 2013 09:11:12 -0500
From: Strake <strake888@...il.com>
To: musl@...ts.openwall.com
Subject: Re: [patch] add ether_(aton, ntoa)

On 28/04/2013, Rich Felker <dalias@...ifal.cx> wrote:
> On Sun, Apr 14, 2013 at 11:10:55PM -0500, Strake wrote:
>> > Could you compare and see if it generates smaller code if we use a
>> > single snprintf/sscanf to implement these functions rather than a
>> > loop? I'm not sure which is better, but since they're not widely used,
>> > my main interest is keeping them small.
>>
>> ntoa: same size
>> aton: mine is smaller
>
> This doesn't seem to match my results. I compared against the
> following version of aton and it was half the size of yours:
>
> struct ether_addr *ether_aton_r (const char *x, struct ether_addr *p_a)
> {
> 	unsigned char *y = p_a->ether_addr_octet;
> 	char c;
> 	if (sscanf(x, "%2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx%c",
> y,y+1,y+2,y+3,y+4,y+5,y+6,&c)!=6)
> 		return 0;
> 	return p_a;
> }
>
> Rich

My method:

$ cat test.c
#include <netinet/ether.h>

int main (int argc, char *argu[]) {
	struct ether_addr *p_a;
	p_a = ether_aton (argu[1]);
	return (*p_a).ether_addr_octet[0];
}

$ cc -I $MUSL/include -L $MUSL/lib -o test test.c && strip test && wc -c <test

Mine: 6200
Yours: 15504

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.