/* $ NetBSD: bcopy. c, V 1.6 20:24:12 Christos exp $ */<br/>... <br/>/* <br/> * Copy a block of memory, handling overlap. <br/> * This is the routine that actually implements <br/> * (the portable versions of) bcopy, memcpy, and memmove. <br/> */<br/> # ifdef memcopy <br/> void * <br/> memcpy (dst0, src0, length) <br/> # else <br/> # ifdef memmove <br/> void * <br/> memmove (dst0, src0, length) <br/> # else <br/> void <br/> bcopy (src0, dst0, length) <br/> # endif <br/> void * dst0; <br/> const void * src0; <br/> Register size_t length; <br/>{< br/> Register char * DST = dst0; <br/> Register const char * src = src0; <br/> Register size_t T; <br/> If (length = 0 | DST = SRC)/* nothing to do */<br/> goto done; <br/>/* <br/> * macros: loop-T-times; and loop-T-times, t> 0 <br/> */<br/> # define tloop (s) if (t) tloop1 (s) <br/> # define tloop1 (s) do {s;} while (-- t) <br/> If (unsigned long) DST <(unsigned long) SRC) {<br/>/* <br/> * Copy forward. <br/> */<br/> T = (long) SRC;/* only need low bits */<br/> If (T | (long) DST) & wmask) {<br/>/* <br/> * try to align operands. this cannot be done <br/> * unless the low bits match. <br/> */<br/> If (t ^ (long) DST) & wmask | length <wsize) <br/> T = length; <br/> else <br/> T = wsize-(T & wmask); <br/> length-= T; <br/> tloop1 (* DST ++ = * SRC ++); <br/>}< br/>/* <br/> * Copy whole words, then mop up any trailing bytes. <br/> */<br/> T = length/wsize; <br/> tloop (* (word *) DST = * (word *) SRC; SRC + = wsize; DST + = wsize); <br/> T = Length & wmask; <br/> tloop (* DST ++ = * SRC ++ ); <br/>} else {<br/>/* <br/> * Copy backwards. otherwise essentially the same. <br/> * alignment works as before, doesn t that it takes <br/> * (T & wmask) bytes to align, not wsize-(T & wmask ). <br/> */<br/> SRC + = length; <br/> DST + = length; <br/> T = (long) SRC; <br/> If (T | (long) DST) & wmask) {<br/> If (t ^ (long) DST) & wmask | length <= wsize) <br/> T = length; <br/> else <br/> T & = wmask; <br/> length-= T; <br/> tloop1 (* -- DST = * -- SRC); <br/>}< br/> T = length/wsize; <br/> tloop (SRC-= wsize; DST-= wsize; * (word *) DST = * (word *) SRC ); <br/> T = Length & wmask; <br/> tloop (* -- DST = * -- SRC); <br/>}< br/> done: <br/> # If defined (memcopy) | defined (memmove) <br/> return (dst0); <br/> # else <br/> return; <br/> # endif <br/>