2001-02-02 17:54:47 +00:00
|
|
|
#include "byte.h"
|
|
|
|
|
|
|
|
/* byte_copy copies in[0] to out[0], in[1] to out[1], ... and in[len-1]
|
|
|
|
* to out[len-1]. */
|
2006-11-07 17:56:05 +00:00
|
|
|
void byte_copy(void* out, size_t len, const void* in) {
|
2008-08-25 22:15:29 +00:00
|
|
|
char* s=out;
|
|
|
|
const char* t=in;
|
|
|
|
#if 1
|
|
|
|
/* gcc 4.3.1 generates wrong code for this, so I'm switching to
|
|
|
|
* simpler code */
|
|
|
|
size_t i;
|
|
|
|
for (i=0; i<len; ++i)
|
|
|
|
s[i]=t[i];
|
|
|
|
#else
|
|
|
|
const char* u=t+len;
|
2001-09-10 10:37:00 +00:00
|
|
|
if (len>127) {
|
2002-08-14 16:00:02 +00:00
|
|
|
while ((unsigned long)s&(sizeof(unsigned long)-1)) {
|
2008-08-25 22:15:29 +00:00
|
|
|
*s=*t; ++s; ++t;
|
2002-08-14 16:00:02 +00:00
|
|
|
}
|
2002-08-14 15:54:49 +00:00
|
|
|
/* s (destination) is now unsigned long aligned */
|
|
|
|
#ifndef __i386__
|
2002-08-14 15:57:33 +00:00
|
|
|
if (!((unsigned long)t&(sizeof(unsigned long)-1)))
|
2002-08-14 15:54:49 +00:00
|
|
|
#endif
|
2002-08-14 15:57:33 +00:00
|
|
|
while (t+sizeof(unsigned long)<=u) {
|
|
|
|
*(unsigned long*)s=*(unsigned long*)t;
|
|
|
|
s+=sizeof(unsigned long); t+=sizeof(unsigned long);
|
|
|
|
}
|
|
|
|
}
|
2001-02-02 17:54:47 +00:00
|
|
|
for (;;) {
|
|
|
|
if (t==u) break; *s=*t; ++s; ++t;
|
|
|
|
if (t==u) break; *s=*t; ++s; ++t;
|
|
|
|
if (t==u) break; *s=*t; ++s; ++t;
|
|
|
|
if (t==u) break; *s=*t; ++s; ++t;
|
|
|
|
}
|
2008-08-25 22:15:29 +00:00
|
|
|
#endif
|
2001-02-02 17:54:47 +00:00
|
|
|
}
|