Bcopy, bzero and bcmp on a not-Berkeley machine

Michael Meissner meissner at tiktok.dg.com
Tue Sep 26 10:48:59 AEST 1989


In article <1155 at radig.UUCP> peter at radig.UUCP (Peter Radig) writes:
| Is is possible to replace calls to `bcopy', `bzero' and `bcmp' by
| the following macros:
| 
| 	#ifdef USG
| 	#define bcmp(s1,s2,cnt)  memcpy(s1,s2,cnt)
| 	#define bcopy(fr,to,cnt) memcpy(to,fr,cnt)
| 	#define bzero(addr,cnt)  memset(addr,'\0',cnt)
| 	#endif USG
| 
| or are there restrictions?

Some programs that use bcopy depend on it 'doing the right thing' when
given pointers to overlapping regions.  The memcpy routine has no such
guarantee.  If your system vendor has added the new ANSI C routine
`memmove', you can replace bcopy with a call to memmove.  I would
suspect memmove is not yet in most libraries.

You could just hope and pray, you never have overlapping strings (or
inspect the code, or write your own).

Our database people found an interesting quirk -- they were doing
*lots* of block moves of overlapping regions, and found that the
hardware character move (which could move in either direction) was
*noticably* faster moving left to right rather than right to left.  It
was so much of a difference, that it was faster to move the bytes into
an automatic array, and then move them again than.  I've seen some
implementations of bcopy, et. al, that do the same thing (ie, optimize
the common case, and revert to single byte load/stores for the
overlapping case).
--
Michael Meissner, Data General.
Uucp:		...!mcnc!rti!xyzzy!meissner		If compiles were much
Internet:	meissner at dg-rtp.DG.COM			faster, when would we
Old Internet:	meissner%dg-rtp.DG.COM at relay.cs.net	have time for netnews?



More information about the Comp.unix.wizards mailing list