From: Denis Zaitsev <zzz@anda.ru>
To: Andreas Schwab <schwab@suse.de>
Cc: Roland McGrath <roland@redhat.com>,
Zack Weinberg <zack@codesourcery.com>,
Andreas Jaeger <aj@suse.de>, Richard Henderson <rth@redhat.com>,
libc-alpha@sources.redhat.com, linux-gcc@vger.kernel.org
Subject: Re: strcmp is too heavy for its everyday usage...
Date: Fri, 9 Jan 2004 10:11:45 +0500 [thread overview]
Message-ID: <20040109101145.A8801@zzz.ward.six> (raw)
In-Reply-To: <jeoetehjoj.fsf@sykes.suse.de>; from schwab@suse.de on Thu, Jan 08, 2004 at 10:30:04AM +0100
On Thu, Jan 08, 2004 at 10:30:04AM +0100, Andreas Schwab wrote:
> Denis Zaitsev <zzz@anda.ru> writes:
>
> > On Wed, Jan 07, 2004 at 05:13:11PM -0800, Roland McGrath wrote:
> >
> >> The optimized string functions already do word comparisons when
> >> that is possible and advantageous. The comparisons to extract
> >> the ordering vs just equality/nonequality are only on the first
> >> nonmatching byte.
> >
> > But it's an overhead anyway.
>
> Rather neglectable, IMHO.
Nearly agreed.
> > Then, it's bad enough for the inlining.
>
> If it's inlined then the compiler should be smart enough to discard
> the unneded bits. If not, and the difference is measurable, then
> the compiler should be fixed.
GCC is smart enough. It doesn't do the job thru the best possible
way, but this should and (important!) can really be fixed. So,
generally I agree again. But suppose such an example:
extern inline
s(const unsigned char *a, const unsigned char *b)
{
int r;
(r= a[0] - b[0]) &&
(r= a[1] - b[1]) &&
(r= a[2] - b[2]) &&
(r= a[3] - b[3]);
return r;
}
It's a typical inline code for compare 4-byte of mem. When it is
used, say, in such a context
s(a,b) ? A() : B();
GCC discards the value of r perfectly, leaving the only code needed
for compare bytes for eq/neq. But GCC doesn't merge the 4 byte
comparing into single word comparing. And, as I understand, it will
never do that, as it's not asked to. Or this kind of optimization is
assumed ok for compiler, but just still unimplemented?
next prev parent reply other threads:[~2004-01-09 5:11 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-01-08 1:09 strcmp is too heavy for its everyday usage Denis Zaitsev
2004-01-08 1:13 ` Roland McGrath
2004-01-08 1:36 ` Denis Zaitsev
2004-01-08 9:30 ` Andreas Schwab
2004-01-09 5:11 ` Denis Zaitsev [this message]
2004-01-09 8:12 ` Richard Henderson
2004-01-09 8:49 ` Denis Zaitsev
2004-01-14 5:09 ` James Antill
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=20040109101145.A8801@zzz.ward.six \
--to=zzz@anda.ru \
--cc=aj@suse.de \
--cc=libc-alpha@sources.redhat.com \
--cc=linux-gcc@vger.kernel.org \
--cc=roland@redhat.com \
--cc=rth@redhat.com \
--cc=schwab@suse.de \
--cc=zack@codesourcery.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).