summaryrefslogtreecommitdiffstats
path: root/cpukit/include/libfdt.h
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2018-11-19 16:36:15 +1100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2020-03-02 07:52:19 +0100
commitbef6dfc5889ba5f2123c558228072d99ae1d8418 (patch)
tree9d3b2680b18b787061aa1cae4adf1fcbd2792642 /cpukit/include/libfdt.h
parentlibfdt: return correct value if #size-cells property is not present (diff)
downloadrtems-bef6dfc5889ba5f2123c558228072d99ae1d8418.tar.bz2
libfdt: Don't use memcpy to handle unaligned reads on ARM
6dcb8ba4 "libfdt: Add helpers for accessing unaligned words" introduced the fdt32_ld() and fdt64_ld() helpers for loading values from the FDT blob which might not be naturally aligned. This matters for ARM, where attempting a plain unaligned load will often cause an exception. However, it seems the memcpy() we used here was surprisingly expensive, making libfdt nearly 6x slower on at least some ARM platforms. This patch takes an alternative approach, using a bunch of 1-byte loads and shifts to implement the helpers. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'cpukit/include/libfdt.h')
-rw-r--r--cpukit/include/libfdt.h22
1 files changed, 15 insertions, 7 deletions
diff --git a/cpukit/include/libfdt.h b/cpukit/include/libfdt.h
index face02c102..fdaa3e6f39 100644
--- a/cpukit/include/libfdt.h
+++ b/cpukit/include/libfdt.h
@@ -163,18 +163,26 @@ uint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset);
static inline uint32_t fdt32_ld(const fdt32_t *p)
{
- fdt32_t v;
+ const uint8_t *bp = (const uint8_t *)p;
- memcpy(&v, p, sizeof(v));
- return fdt32_to_cpu(v);
+ return ((uint32_t)bp[0] << 24)
+ | ((uint32_t)bp[1] << 16)
+ | ((uint32_t)bp[2] << 8)
+ | bp[3];
}
static inline uint64_t fdt64_ld(const fdt64_t *p)
{
- fdt64_t v;
-
- memcpy(&v, p, sizeof(v));
- return fdt64_to_cpu(v);
+ const uint8_t *bp = (const uint8_t *)p;
+
+ return ((uint64_t)bp[0] << 56)
+ | ((uint64_t)bp[1] << 48)
+ | ((uint64_t)bp[2] << 40)
+ | ((uint64_t)bp[3] << 32)
+ | ((uint64_t)bp[4] << 24)
+ | ((uint64_t)bp[5] << 16)
+ | ((uint64_t)bp[6] << 8)
+ | bp[7];
}
/**********************************************************************/