4 /* BCOPY(from,to,cnt) - Copy string of bytes.
5 * Normally this routine is an assembly-language library routine,
6 * but not all systems have it. Hence this C-language version
7 * which tries to be fairly machine-independent.
8 * Attempts to be clever about using word moves instead of byte moves.
9 * Does not hack overlapping backward moves.
11 bcopy(from
, to
, cnt
) /* Copy count bytes from -> to */
14 register unsigned cnt
;
18 while(rndrem((int)from
)) /* Get source aligned */
20 if(--cnt
== 0) return;
22 if(rndrem((int)to
) == 0) /* Do word move if dest now aligned */
23 { register unsigned tmp
;
25 if((cnt
= rnddiv(cnt
)) > 4)
26 { sbm_wcpy((int *)from
, (int *)to
, cnt
);
27 if((cnt
= rndrem(tmp
)) == 0)
28 return; /* No leftover bytes, all done */
29 tmp
-= cnt
; /* Ugh, must update pointers */
33 else cnt
= tmp
; /* Not worth call overhead */
35 do { *to
++ = *from
++; } /* Finish up with byte loop */
39 /* SBM_WCPY - word-move auxiliary routine.
40 * This is a separate routine so that machines with only a few
41 * registers have a chance to use them for the word copy loop.
42 * This cannot be made part of BCOPY without doing some
43 * unnecessary pointer conversions and using extra variables
44 * (since most compilers will not accept type casts on lvalues,
45 * which are needed to treat (char *) as (int *)).
47 sbm_wcpy(from
, to
, cnt
)
48 register int *from
, *to
;
49 register unsigned cnt
;
52 do { *to
++ = *from
++; }