Commit 5792500c authored by Damien George's avatar Damien George
Browse files

Merge branch 'memcpy' of github.com:iabdalkader/micropython into iabdalkader-memcpy

parents bb295468 d60580eb
...@@ -27,14 +27,50 @@ ...@@ -27,14 +27,50 @@
#include <stdint.h> #include <stdint.h>
#include "std.h" #include "std.h"
void *memcpy(void *dest, const void *src, size_t n) { #define likely(x) __builtin_expect((x), 1)
// TODO align and copy 32 bits at a time
uint8_t *d = dest; void *memcpy(void *dst, const void *src, size_t n) {
const uint8_t *s = src; if (likely(!((long)dst&3) && !((long)src&3))) {
for (; n > 0; n--) { //copy words from aligned pointers first
*d++ = *s++; long *d = dst;
const long *s = src;
for (int i=(n>>2); i; i--) {
*d++ = *s++;
}
//copy remaining bytes
if (n&3) {
char *d8 = (char*)d;
const char *s8 =(char*) s;
switch (n&3) {
case 1:
*d8=*s8;
break;
case 2:
*d8++=*s8++;
*d8=*s8;
break;
case 3:
*d8++=*s8++;
*d8++=*s8++;
*d8=*s8;
break;
}
}
} 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) { 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