From -7403499999666511977
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,fea2c3a38bda88aa
X-Google-Attributes: gidf78e5,public
From: "Paul D. DeRocco" <pderocco@ix.netcom.com>
Subject: Re: memcmp source
Date: 1997/12/17
Message-ID: <34986660.F999A5E8@ix.netcom.com>#1/1
X-Deja-AN: 299188827
References: <01bd073a$216f93e0$245b9b26@GMorris.dallasmfg.com> <34921798.9351A27@ix.netcom.com> <m3wwh6b8vz.fsf@gabi-soft.fr>
X-Original-Date: Wed, 17 Dec 1997 18:55:12 -0500
Originator: austern@isolde.mti.sgi.com
Organization: The Booboisie
X-NETCOM-Date: Wed Dec 17  3:57:00 PM PST 1997
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBVAwUBNJhwUUy4NqrwXLNJAQHivQH8CLjZp6P2fMrZ8qNphTS7+jCs/aXTFUTL zCACEb5uoS1C2amEcq1HFrmmCJmznAT9nO7O3vWP16wOrhk08k84sA== =t5EQ
Newsgroups: comp.std.c++


J. Kanze wrote:
> 
> If given constants, or values about which the compiler has some
> information, the compiler can generate optimal inline code without the
> tests.  On an Intel architecture, for example, it would be a very poor
> compiler that would still use movsb when the length were an even
> constant, for example.  From actual measurements, done a long time ago
> on an 8086, over actual code, using different implementations of memcpy
> (as a function, thus, always with run-time tests), shifting the count
> right and copying words was a definite win, even with relatively short
> strings, despite the overhead of the extra tests.  On the other hand,
> trying to align wasn't: statistically, enough of the
> sources/destinations were already aligned so that the rare improvement
> didn't offset the tests of the other calls.

What you're saying is undoubtedly correct for memcpy, but the original question
was about memcmp. While it is certainly common to do big memcpy's (e.g., disk
buffers), I think memcmp's are typically much shorter, so it may not be worth
even the small optimization you suggest. For instance, the Borland compiler's
library functions (which are used when intrinsics are disabled) perform this
optimization for memcpy but not memcmp.

I did a version of memcpy once that did a simple test at the beginning: if the
count was greater than a certain value (I think I used 16), I did the
full-blown optimization, including alignment. Otherwise, it just moved bytes.

-- 

Ciao,
Paul
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu 
]



