bcopy.c
ubixos/types.h
strings.h
string.h
src/sys/lib/memcpy.c
ubixos/types.h
sys/_types.h
string.h
strings.h
src/sys/lib/bcopy.c
src/sys/lib/memcpy.c
src/sys/lib/bcopy.c
TLOOP
s
if (t) TLOOP1(s)
bcopy
TLOOP1
s
do { s; } while (--t)
bcopy
wmask
(wsize - 1)
bcopy
memset
wsize
sizeof(word)
bcopy
memset
uint32_t typedef uint32_t uintptr_t uintptr_t
int typedef int word word
void void bcopy (const void *src0, void *dst0, size_t length) bcopy const void * src0 void * dst0 size_t length done TLOOP TLOOP1 wmask wsize

    /*-
    *Copyright(c)1990,1993
    *TheRegentsoftheUniversityofCalifornia.Allrightsreserved.
    *
    *ThiscodeisderivedfromsoftwarecontributedtoBerkeleyby
    *ChrisTorek.
    *
    *Redistributionanduseinsourceandbinaryforms,withorwithout
    *modification,arepermittedprovidedthatthefollowingconditions
    *aremet:
    *1.Redistributionsofsourcecodemustretaintheabovecopyright
    *notice,thislistofconditionsandthefollowingdisclaimer.
    *2.Redistributionsinbinaryformmustreproducetheabovecopyright
    *notice,thislistofconditionsandthefollowingdisclaimerinthe
    *documentationand/orothermaterialsprovidedwiththedistribution.
    *3.Alladvertisingmaterialsmentioningfeaturesoruseofthissoftware
    *mustdisplaythefollowingacknowledgement:
    *ThisproductincludessoftwaredevelopedbytheUniversityof
    *California,Berkeleyanditscontributors.
    *4.NeitherthenameoftheUniversitynorthenamesofitscontributors
    *maybeusedtoendorseorpromoteproductsderivedfromthissoftware
    *withoutspecificpriorwrittenpermission.
    *
    *THISSOFTWAREISPROVIDEDBYTHEREGENTSANDCONTRIBUTORS``ASIS''AND
    *ANYEXPRESSORIMPLIEDWARRANTIES,INCLUDING,BUTNOTLIMITEDTO,THE
    *IMPLIEDWARRANTIESOFMERCHANTABILITYANDFITNESSFORAPARTICULARPURPOSE
    *AREDISCLAIMED.INNOEVENTSHALLTHEREGENTSORCONTRIBUTORSBELIABLE
    *FORANYDIRECT,INDIRECT,INCIDENTAL,SPECIAL,EXEMPLARY,ORCONSEQUENTIAL
    *DAMAGES(INCLUDING,BUTNOTLIMITEDTO,PROCUREMENTOFSUBSTITUTEGOODS
    *ORSERVICES;LOSSOFUSE,DATA,ORPROFITS;ORBUSINESSINTERRUPTION)
    *HOWEVERCAUSEDANDONANYTHEORYOFLIABILITY,WHETHERINCONTRACT,STRICT
    *LIABILITY,ORTORT(INCLUDINGNEGLIGENCEOROTHERWISE)ARISINGINANYWAY
    *OUTOFTHEUSEOFTHISSOFTWARE,EVENIFADVISEDOFTHEPOSSIBILITYOF
    *SUCHDAMAGE.
    *
    *$ID:$
    */

    #include<ubixos/types.h>

    /*
    *sizeof(word)MUSTBEAPOWEROFTWO
    *SOTHATwmaskBELOWISALLONES
    */
    typedefintword;/*"word"usedforoptimalcopyspeed*/
    typedefuint32_tuintptr_t;

    #definewsizesizeof(word)
    #definewmask(wsize-1)

    /*
    *Copyablockofmemory,handlingoverlap.
    *Thisistheroutinethatactuallyimplements
    *(theportableversionsof)bcopy,memcpy,andmemmove.
    */
    #ifdefined(MEMCOPY)||defined(MEMMOVE)
    #include<string.h>

    void*
    #ifdefMEMCOPY
    memcpy
    #else
    memmove
    #endif
    (void*dst0,constvoid*src0,size_tlength)
    #else
    #include<strings.h>

    void
    bcopy(constvoid*src0,void*dst0,size_tlength)
    #endif
    {
    char*dst=dst0;
    constchar*src=src0;
    size_tt;

    if(length==0||dst==src)/*nothingtodo*/
    gotodone;

    /*
    *Macros:loop-t-times;andloop-t-times,t>0
    */
    #defineTLOOP(s)if(t)TLOOP1(s)
    #defineTLOOP1(s)do{s;}while(--t)

    if((unsignedlong)dst<(unsignedlong)src){
    /*
    *Copyforward.
    */
    t=(uintptr_t)src;/*onlyneedlowbits*/
    if((t|(uintptr_t)dst)&wmask){
    /*
    *Trytoalignoperands.Thiscannotbedone
    *unlessthelowbitsmatch.
    */
    if((t^(uintptr_t)dst)&wmask||length<wsize)
    t=length;
    else
    t=wsize-(t&wmask);
    length-=t;
    TLOOP1(*dst++=*src++);
    }
    /*
    *Copywholewords,thenmopupanytrailingbytes.
    */
    t=length/wsize;
    TLOOP(*(word*)dst=*(word*)src;src+=wsize;dst+=wsize);
    t=length&wmask;
    TLOOP(*dst++=*src++);
    }else{
    /*
    *Copybackwards.Otherwiseessentiallythesame.
    *Alignmentworksasbefore,exceptthatittakes
    *(t&wmask)bytestoalign,notwsize-(t&wmask).
    */
    src+=length;
    dst+=length;
    t=(uintptr_t)src;
    if((t|(uintptr_t)dst)&wmask){
    if((t^(uintptr_t)dst)&wmask||length<=wsize)
    t=length;
    else
    t&=wmask;
    length-=t;
    TLOOP1(*--dst=*--src);
    }
    t=length/wsize;
    TLOOP(src-=wsize;dst-=wsize;*(word*)dst=*(word*)src);
    t=length&wmask;
    TLOOP(*--dst=*--src);
    }
    done:
    #ifdefined(MEMCOPY)||defined(MEMMOVE)
    return(dst0);
    #else
    return;
    #endif
    }