[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] [PATCH] Cleanup use of strlen() to check for empty string
Oops sorry I take that back, gcc3 just produces different output... Never mind then. Must get coffee. Jacob On 10/5/05, Jacob Gorm Hansen <jacobg@xxxxxxx> wrote: > On 10/5/05, Petersson, Mats <mats.petersson@xxxxxxx> wrote: > > > I created a function: > > > > int foo(char *s) > > { > > if (strlen(s)) return 1; else return 0; > > } > > > > Compiled with gcc 4.0.0 as: > > gcc -O3 -s x.c (or gcc -O2 ...) > > Gives the following code: > > > > foo: > > xorl %eax, %eax > > cmpb $(0), (%rdi) > > sete %al > > ret > > Cool, I am surprised gcc4 is able to fix this. gcc 3.3.4 which I am > using is not, even with -O3. How does gcc4 behave without -O3? > > foo: > push %ebp > mov %esp,%ebp > mov 0x8(%ebp),%edx > pop %ebp > cmpb $0x0,(%edx) > setne %dl > movzbl %dl,%eax > ret > > I guess I only reacted to this because I have seen worse examples > resulting from the "strlen is constant-time" assumption (people > iterating over a string in a while(strlen(s)) loop), and because I was > bored with trying to get block devices running with xenbus. :-) > > Jacob > -- Save time and bandwidth with EDelta: http://www.diku.dk/~jacobg/edelta/ _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |