[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


  • To: "Petersson, Mats" <mats.petersson@xxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxx
  • From: Jacob Gorm Hansen <jacobg@xxxxxxx>
  • Date: Wed, 5 Oct 2005 13:16:48 +0200
  • Delivery-date: Wed, 05 Oct 2005 11:14:22 +0000
  • Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:sender:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=RHJIp++OhEZ5zy9/KgnSbTxwjaIk+MWrsGuHHHF1IhPFygn+vSHqaM7UpkgQzs7fdNQJV/1l/fEn3qrBpHRr8wX/RIY/BR4bhsmGAIVpFGHaPb1gsVcM0r8WL5b1bAC9tCZUOU92ubZPjdnYLNrYNJxCman2XxLV2rly4yHNLQE=
  • List-id: Xen developer discussion <xen-devel.lists.xensource.com>

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


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.