source: trunk/minix/commands/elle/sbbcpy.c@ 10

Last change on this file since 10 was 9, checked in by Mattia Monga, 13 years ago

Minix 3.1.2a

File size: 1.6 KB
Line 
1
2#include "sb.h"
3
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.
10 */
11bcopy(from, to, cnt) /* Copy count bytes from -> to */
12register SBMA from;
13register SBMA to;
14register unsigned cnt;
15{
16 if(!cnt)
17 return;
18 while(rndrem((int)from)) /* Get source aligned */
19 { *to++ = *from++;
20 if(--cnt == 0) return;
21 }
22 if(rndrem((int)to) == 0) /* Do word move if dest now aligned */
23 { register unsigned tmp;
24 tmp = cnt;
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 */
30 from += tmp;
31 to += tmp;
32 }
33 else cnt = tmp; /* Not worth call overhead */
34 }
35 do { *to++ = *from++; } /* Finish up with byte loop */
36 while(--cnt);
37}
38
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 *)).
46 */
47sbm_wcpy(from, to, cnt)
48register int *from, *to;
49register unsigned cnt;
50{
51 if(cnt)
52 do { *to++ = *from++; }
53 while(--cnt);
54}
Note: See TracBrowser for help on using the repository browser.