avr-libc-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-libc-dev] optimizing strtol()/strtoul()


From: E. Weddington
Subject: Re: [avr-libc-dev] optimizing strtol()/strtoul()
Date: Tue, 16 Sep 2003 15:12:01 GMT

> I'm using avr-libc-0.99.90.20030908 as enclosed with 
latest WinAVR.
> 
> a) I noted a couple of variables, in strtol() and strtoul
(), not well 
> optimized for the target, specifically:
> ----
>       register int neg = 0, any;
> ----
> that don't need to be 16-bit wide, infact "neg" is used 
as a boolean 
> variable, and "any" serves as a three states flag.
> 
> Using a "char" (or signed char, wanting to keep the same 
usage for "any", 
> that spans -1, 0, 1) would save space in program space 
(and possibly on 
> stack), plus in execution time.
> 
> b) Another small improvement with coding is in the 
conversion loop:
> ----
>               else if (isalpha(c))
>                       c -= isupper(c) ? 'A' - 
10 : 'a' - 10;
>               else
> ----
> calling isupper(), after knowing it to be isalpha() makes 
code bigger; a 
> "clean" optimization could be
>       c = toupper(c) - 'A' - 10;
> Yes, avoiding the ternary ?: makes code smaller, though 
not faster, since 
> toupper() does an implicit isalpha().
> The "dirty", smaller, hack is bit masking (assuming we're 
all using ASCII 
> coding?)
>       c = (c & ~0x20) - 'A' - 10;
> It's obvious that this optimization puts in 
strtol.c/strtoul.c a control 
> that's to be elsewhere (ctype.h), so it is totally 
questionable.
> 
> I'm sure there can be other possible improvements, these 
ones just popped up 
> to my mind, peeking at the source code.
> 
> 

Would you be willing to work up a patch and submit it?

Thanks
Eric






reply via email to

[Prev in Thread] Current Thread [Next in Thread]