Merge pull request #193 from gsomlo/gls-memcpy-fix
software/libbase: memcpy: simple, arch-width agnostic implementation
This commit is contained in:
commit
cb2d4372e4
|
@ -293,71 +293,12 @@ void *memset(void *s, int c, size_t count)
|
||||||
*/
|
*/
|
||||||
void *memcpy(void *to, const void *from, size_t n)
|
void *memcpy(void *to, const void *from, size_t n)
|
||||||
{
|
{
|
||||||
void *xto = to;
|
char *tmp = to;
|
||||||
size_t temp;
|
const char *s = from;
|
||||||
|
|
||||||
if(!n)
|
while (n--)
|
||||||
return xto;
|
*tmp++ = *s++;
|
||||||
if((long)to & 1) {
|
return to;
|
||||||
char *cto = to;
|
|
||||||
const char *cfrom = from;
|
|
||||||
*cto++ = *cfrom++;
|
|
||||||
to = cto;
|
|
||||||
from = cfrom;
|
|
||||||
n--;
|
|
||||||
}
|
|
||||||
if((long)from & 1) {
|
|
||||||
char *cto = to;
|
|
||||||
const char *cfrom = from;
|
|
||||||
for (; n; n--)
|
|
||||||
*cto++ = *cfrom++;
|
|
||||||
return xto;
|
|
||||||
}
|
|
||||||
if(n > 2 && (long)to & 2) {
|
|
||||||
short *sto = to;
|
|
||||||
const short *sfrom = from;
|
|
||||||
*sto++ = *sfrom++;
|
|
||||||
to = sto;
|
|
||||||
from = sfrom;
|
|
||||||
n -= 2;
|
|
||||||
}
|
|
||||||
if((long)from & 2) {
|
|
||||||
short *sto = to;
|
|
||||||
const short *sfrom = from;
|
|
||||||
temp = n >> 1;
|
|
||||||
for (; temp; temp--)
|
|
||||||
*sto++ = *sfrom++;
|
|
||||||
to = sto;
|
|
||||||
from = sfrom;
|
|
||||||
if(n & 1) {
|
|
||||||
char *cto = to;
|
|
||||||
const char *cfrom = from;
|
|
||||||
*cto = *cfrom;
|
|
||||||
}
|
|
||||||
return xto;
|
|
||||||
}
|
|
||||||
temp = n >> 2;
|
|
||||||
if(temp) {
|
|
||||||
long *lto = to;
|
|
||||||
const long *lfrom = from;
|
|
||||||
for(; temp; temp--)
|
|
||||||
*lto++ = *lfrom++;
|
|
||||||
to = lto;
|
|
||||||
from = lfrom;
|
|
||||||
}
|
|
||||||
if(n & 2) {
|
|
||||||
short *sto = to;
|
|
||||||
const short *sfrom = from;
|
|
||||||
*sto++ = *sfrom++;
|
|
||||||
to = sto;
|
|
||||||
from = sfrom;
|
|
||||||
}
|
|
||||||
if(n & 1) {
|
|
||||||
char *cto = to;
|
|
||||||
const char *cfrom = from;
|
|
||||||
*cto = *cfrom;
|
|
||||||
}
|
|
||||||
return xto;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue