public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Kevin Atkinson <kevina@gnu.org>
To: Roger Sayle <roger@www.eyesopen.com>
Cc: gcc@gcc.gnu.org
Subject: Re: Slow memcmp for aligned strings on Pentium 3
Date: Fri, 04 Apr 2003 14:51:00 -0000	[thread overview]
Message-ID: <Pine.LNX.4.44.0304040812060.912-100000@kevin-pc.atkinson.dhs.org> (raw)
In-Reply-To: <Pine.LNX.4.44.0304032110020.7684-100000@www.eyesopen.com>

On Thu, 3 Apr 2003, Roger Sayle wrote:

> 
> Hi Kevin,
> > I did some tests and discovered that using cmps was rather slow,
> > compared to a simple loop and then a bswap and subtract at the end.
> 
> I'm sure that GCC's memcmp implementations could be improved, but
> from reading the code examples in your patch it looks like you
> are always assuming that either the length is a multiple of four,
> or that the bytes following the memory sections to be compared
> contain identical values (i.e. you're hoping they're all zero).
> 
> i.e., if p and q are suitably 4-byte aligned
> 
>   memset(p,"abcd",4);
>   memset(q,"abef",4);
>   memcmp(p,q,2)
> 
> should compare equal but don't using bswaps and subtractions.
> Similarly, when two words mismatch their return value <0 or
> >0 should depend upon the first byte that differs, not the
> values of the bytes that come after it.

Your right.  It can be fixed by a test if it is a multiple of 4 and if not 
do a byte wise comparison at the end.

> I suspect it should be possible to fix your code to handle these
> termination conditions correctly, and a comparison of your
> routine's performance with these fixes vs. __builtin_memcmp
> would be of interest.

I will see what I can do.

--- 
http://kevin.atkinson.dhs.org

  reply	other threads:[~2003-04-04 13:18 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-04-04 13:18 Roger Sayle
2003-04-04 14:51 ` Kevin Atkinson [this message]
2003-04-04 17:08 ` Kevin Atkinson
2003-04-04 18:58   ` Marcel Cox
2003-04-04 19:27     ` Kevin Atkinson
  -- strict thread matches above, loose matches on Subject: below --
2003-04-04 17:13 Jerry Quinn
2003-04-04 17:29 ` Kevin Atkinson
2003-04-06  5:54   ` Jerry Quinn
2003-04-06 22:17     ` Kevin Atkinson
2003-04-07 17:30       ` Jerry Quinn
2003-04-04 14:33 Bonzini
2003-04-04  6:22 Kevin Atkinson
2003-04-04  8:52 ` Zack Weinberg
2003-04-04 15:16   ` Kevin Atkinson

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=Pine.LNX.4.44.0304040812060.912-100000@kevin-pc.atkinson.dhs.org \
    --to=kevina@gnu.org \
    --cc=gcc@gcc.gnu.org \
    --cc=roger@www.eyesopen.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 read-only IMAP folder(s) and NNTP newsgroup(s).