mirror of /home/gitosis/repositories/libowfat.git
parent
d453330622
commit
9e3ba6e772
26 changed files with 173 additions and 109 deletions
@ -1,36 +1,12 @@ |
||||
#include <stdint.h> |
||||
#include "byte.h" |
||||
|
||||
/* byte_copy copies in[0] to out[0], in[1] to out[1], ... and in[len-1]
|
||||
* to out[len-1]. */ |
||||
void byte_copy(void* out, size_t len, const void* in) { |
||||
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 */ |
||||
char* d=out; |
||||
const char* s=in; |
||||
size_t i; |
||||
for (i=0; i<len; ++i) |
||||
s[i]=t[i]; |
||||
#else |
||||
const char* u=t+len; |
||||
if (len>127) { |
||||
while ((unsigned long)s&(sizeof(unsigned long)-1)) { |
||||
*s=*t; ++s; ++t; |
||||
} |
||||
/* s (destination) is now unsigned long aligned */ |
||||
#ifndef __i386__ |
||||
if (!((unsigned long)t&(sizeof(unsigned long)-1))) |
||||
#endif |
||||
while (t+sizeof(unsigned long)<=u) { |
||||
*(unsigned long*)s=*(unsigned long*)t; |
||||
s+=sizeof(unsigned long); t+=sizeof(unsigned long); |
||||
} |
||||
} |
||||
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; |
||||
} |
||||
#endif |
||||
d[i]=s[i]; |
||||
} |
||||
|
@ -1,22 +1,15 @@ |
||||
#include "byte.h" |
||||
#include <string.h> |
||||
|
||||
/* byte_zero sets the bytes out[0], out[1], ..., out[len-1] to 0 */ |
||||
void byte_zero(void* out, size_t len) { |
||||
#if 1 |
||||
/* gcc 4.3.1 generates wrong code for this, so I'm switching to
|
||||
* simpler code */ |
||||
/* instead of doing this ourselves, defer to the hopefully amazingly
|
||||
* optimized memset from libc */ |
||||
memset(out,0,len); |
||||
#if 0 |
||||
register char* s=out; |
||||
size_t i; |
||||
for (i=0; i<len; ++i) |
||||
s[i]=0; |
||||
#else |
||||
register char* s=out; |
||||
register const char* t=s+len; |
||||
for (;;) { |
||||
if (s==t) break; *s=0; ++s; |
||||
if (s==t) break; *s=0; ++s; |
||||
if (s==t) break; *s=0; ++s; |
||||
if (s==t) break; *s=0; ++s; |
||||
} |
||||
#endif |
||||
} |
||||
|
Loading…
Reference in new issue