Implementation of memcpy on NetBSD

Source: Internet
Author: User

/* $ 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/>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.