Commit 81b2ddf5 authored by iabdalkader's avatar iabdalkader
Browse files

Memcpy: copy words

parent 95307431
......@@ -27,14 +27,28 @@
#include <stdint.h>
#include "std.h"
void *memcpy(void *dest, const void *src, size_t n) {
// TODO align and copy 32 bits at a time
uint8_t *d = dest;
const uint8_t *s = src;
for (; n > 0; n--) {
*d++ = *s++;
#define likely(x) __builtin_expect((x), 1)
void *memcpy(void *dst, const void *src, size_t n) {
if (likely(!(n&3) && !((long)dst&3) && !((long)src&3))) {
//aligned access, copy words
long *d = dst;
const long *s = src;
for (n=(n>>2); n; n--) {
*d++ = *s++;
}
} else {
//unaligned access, copy bytes
char *d = dst;
const char *s = src;
for (; n; n--) {
*d++ = *s++;
}
}
return dest;
return dst;
}
void *memmove(void *dest, const void *src, size_t n) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment