Fast strcmp() wanted.

Michael Meissner meissner at osf.org
Fri Oct 5 00:57:17 AEST 1990


In article <6757 at uwm.edu> markh at csd4.csd.uwm.edu (Mark William
Hopkins) writes:

| Path: paperboy!snorkelwacker!bionet!uwm.edu!csd4.csd.uwm.edu!markh
| From: markh at csd4.csd.uwm.edu (Mark William Hopkins)
| Newsgroups: alt.sources
| Date: 4 Oct 90 06:01:08 GMT
| References: <12145 at crdgw1.crd.ge.com>
| Sender: news at uwm.edu
| Reply-To: markh at csd4.csd.uwm.edu (Mark William Hopkins)
| Organization: University of Wisconsin-Milwaukee
| Lines: 13
| 
| In article <12145 at crdgw1.crd.ge.com> larocque at jupiter.crd.ge.com (David M. LaRocque) writes:
| >After I profiled my C program I discovered that the function
| >strcmp() takes one third of my program's CPU time.  I was hoping
| >someone may have written their own version of strcmp() that
| >outperforms the library's function.
| 
| Look at some references on the architecture of the machine your system is
| running on.  It will most likely have hardware-implemented string instructions
| that you can use.
| 
| On our machine, the strcmp library routine is really nothing more than a single
| assembly-language instruction with a couple register-initializations.  It will
| almost certainly run far faster than any equivalent high-level source.

While it is not probably true in this case, some machine instructions
which do strcmp are actually slower than exceedingly tight asm code
that a real programmer can produce.  It depends on many factors,
including how much of the chip area supports the string instructions
or whether they are microcoded.  For example, the original microvax
did not have some of the string instructions in the hardware, and
trapped to the OS for emulation.  Another example is on one other
specific machine within an architecture family was found to do string
moves slower than the naive load byte/store byte sequence!

--
Michael Meissner	email: meissner at osf.org		phone: 617-621-8861
Open Software Foundation, 11 Cambridge Center, Cambridge, MA, 02142

Do apple growers tell their kids money doesn't grow on bushes?



More information about the Alt.sources mailing list