From: Daniel Jacobowitz <dan@debian.org>
To: Rusty Russell <rusty@rustcorp.com.au>
Cc: junkio@cox.net, linux-kernel@vger.kernel.org,
Keith Owens <kaos@ocs.com.au>
Subject: Re: [TRIVIAL] strlen("literal string") -> (sizeof("literal string")-1)
Date: Wed, 28 Aug 2002 23:26:42 -0400 [thread overview]
Message-ID: <20020829032642.GA9201@nevyn.them.org> (raw)
In-Reply-To: <20020828221716.2C1D12C0E8@lists.samba.org>
On Thu, Aug 29, 2002 at 01:09:05PM +1000, Rusty Russell wrote:
> In message <200208282131.g7SLVVGx024191@siamese.dyndns.org> you write:
> > Here is a patch that does the same as what Keith Owens did in
> > his patch recently.
> >
> > Message-ID: <fa.iks3ohv.1flge08@ifi.uio.no>
> > From: Keith Owens <kaos@ocs.com.au>
> > Subject: [patch] 2.4.19 Generate better code for nfs_sillyrename
> > Date: Wed, 28 Aug 2002 07:08:17 GMT
> >
> > Using strlen() generates an unnecessary inline function expansion plus
> > dynamic stack adjustment. For constant strings, strlen() == sizeof()-1
> > and the object code is better.
>
> Disagree. If you really care make strlen use __builtin_constant_p().
> Then authors don't have to sacrifice readability.
>
> #define strlen(x) (__builtin_constant_p(x) ? sizeof(x)-1 : __strlen(x))
Also disagree; besides, the evidence implies that Keith is wrong. GCC
2.95.3:
drow@nevyn:~% cat strlen.c
int foo() { return strlen ("baz"); }
int bar() { return sizeof ("baz") - 1; }
drow@nevyn:~% cat strlen.s
.file "strlen.c"
.version "01.01"
gcc2_compiled.:
.text
.align 4
.globl foo
.type foo,@function
foo:
pushl %ebp
movl %esp,%ebp
movl $3,%eax
leave
ret
.Lfe1:
.size foo,.Lfe1-foo
.align 4
.globl bar
.type bar,@function
bar:
pushl %ebp
movl %esp,%ebp
movl $3,%eax
leave
ret
.Lfe2:
.size bar,.Lfe2-bar
.ident "GCC: (GNU) 2.95.4 20011002 (Debian prerelease)"
3.2 does the same thing. With -fomit-frame-pointer the results are as
expected, just a move and a return.
If you include headers that define strlen, that's another problem.
--
Daniel Jacobowitz
MontaVista Software Debian GNU/Linux Developer
next prev parent reply other threads:[~2002-08-29 3:21 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <fa.iks3ohv.1flge08@ifi.uio.no>
2002-08-28 21:31 ` [TRIVIAL] strlen("literal string") -> (sizeof("literal string")-1) junkio
2002-08-28 21:55 ` Jim Treadway
2002-08-29 3:09 ` Rusty Russell
2002-08-29 3:26 ` Daniel Jacobowitz [this message]
2002-08-29 6:29 ` Rusty Russell
2002-08-29 7:10 ` Jakub Jelinek
2002-08-29 16:56 ` Linus Torvalds
2002-08-29 20:38 ` Denis Zaitsev
2002-09-06 12:53 ` Pavel Machek
[not found] <fa.lrmcokv.1q28k2s@ifi.uio.no>
[not found] ` <fa.pm2g4iv.k0s9jg@ifi.uio.no>
2002-08-29 0:49 ` junio
2002-08-29 3:15 ` Rusty Russell
2002-08-29 15:39 ` Thunder from the hill
2002-08-29 15:48 ` Dave Jones
2002-08-30 3:50 ` Rusty Russell
[not found] <20020829031008.T7920@devserv.devel.redhat.com.suse.lists.linux.kernel>
[not found] ` <Pine.LNX.4.44.0208290955280.2070-100000@home.transmeta.com.suse.lists.linux.kernel>
2002-08-29 17:23 ` Andi Kleen
2002-08-29 17:51 ` Alexander Viro
2002-08-29 17:53 ` Andi Kleen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20020829032642.GA9201@nevyn.them.org \
--to=dan@debian.org \
--cc=junkio@cox.net \
--cc=kaos@ocs.com.au \
--cc=linux-kernel@vger.kernel.org \
--cc=rusty@rustcorp.com.au \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.