diff options
author | iabdalkader <i.abdalkader@gmail.com> | 2014-09-11 19:01:48 +0200 |
---|---|---|
committer | iabdalkader <i.abdalkader@gmail.com> | 2014-09-11 19:01:48 +0200 |
commit | d60580eb5e701853878bcfee34d163ec5746f2a1 (patch) | |
tree | 0b071857c67e05c2cb63f98eb242bbbd4146d1a3 /stmhal/string0.c | |
parent | 81b2ddf5d175ee810b93925da49754ca18a3e607 (diff) | |
download | micropython-d60580eb5e701853878bcfee34d163ec5746f2a1.tar.gz micropython-d60580eb5e701853878bcfee34d163ec5746f2a1.zip |
Optimize memcpy more
Diffstat (limited to 'stmhal/string0.c')
-rw-r--r-- | stmhal/string0.c | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/stmhal/string0.c b/stmhal/string0.c index 2f28de097c..aceca8b68d 100644 --- a/stmhal/string0.c +++ b/stmhal/string0.c @@ -30,14 +30,36 @@ #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 + if (likely(!((long)dst&3) && !((long)src&3))) { + //copy words from aligned pointers first long *d = dst; const long *s = src; - for (n=(n>>2); n; n--) { + 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; |