aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWojtek Kosior <kwojtus@protonmail.com>2019-12-31 21:56:20 +0100
committerWojtek Kosior <kwojtus@protonmail.com>2019-12-31 21:56:20 +0100
commit263a2ddec4f7f17c5bcd3a36ded396f6fe4e836a (patch)
tree9fa18bfd39cd1f9e8af6ab4419f9001d44740b65
parent3fb88e3c0237379e32bd6d1d27465d5324726684 (diff)
downloadrpi-MMU-example-263a2ddec4f7f17c5bcd3a36ded396f6fe4e836a.tar.gz
rpi-MMU-example-263a2ddec4f7f17c5bcd3a36ded396f6fe4e836a.zip
copy by one byte in memcpy to avoid alignment faults
-rw-r--r--strings.c10
1 files changed, 3 insertions, 7 deletions
diff --git a/strings.c b/strings.c
index c741938..368d7dc 100644
--- a/strings.c
+++ b/strings.c
@@ -82,13 +82,9 @@ void memcpy(void *dst, void *src, size_t nbytes)
{
size_t iter;
- // copying by word is faster than by byte
- // copy by word as much as possible
- for (iter = 0; iter < nbytes / 4; iter++)
- ((volatile uint32_t*) dst)[iter] = ((uint32_t*) src)[iter];
-
- // copy the remaining 1, 2 or 3 bytes by byte
- for (iter *= 4; iter < nbytes; iter++)
+ // copying by word is faster than by byte,
+ // but can easily cause alignment faults, so we resign from it...
+ for (iter = 0; iter < nbytes ; iter++)
((volatile uint8_t*) dst)[iter] = ((uint8_t*) src)[iter];
}