1From 8defbc643a5f57c2289d16138924cd776ed784bf Mon Sep 17 00:00:00 2001 2From: Jeffy Chen <jeffy.chen@rock-chips.com> 3Date: Fri, 27 Mar 2020 17:48:20 +0800 4Subject: [PATCH 04/17] cld3: Avoid unaligned accesses 5 6Although the unaligned memory accesses are enabled, somehow i still hit 7the SIGBUS: 8[23496.643138] Unhandled fault: alignment fault (0x92000021) at 0x00000000b182e636 9Received signal 7 BUS_ADRALN 0000b182e636 10 11Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com> 12--- 13 third_party/cld_3/src/src/script_span/port.h | 12 ++++++++++++ 14 1 file changed, 12 insertions(+) 15 16diff --git a/third_party/cld_3/src/src/script_span/port.h b/third_party/cld_3/src/src/script_span/port.h 17index 2b3bc515a..1d437babf 100644 18--- a/third_party/cld_3/src/src/script_span/port.h 19+++ b/third_party/cld_3/src/src/script_span/port.h 20@@ -78,11 +78,23 @@ namespace CLD2 { 21 // 22 // This is a mess, but there's not much we can do about it. 23 24+#if 0 25 #define UNALIGNED_LOAD16(_p) (*reinterpret_cast<const uint16 *>(_p)) 26 #define UNALIGNED_LOAD32(_p) (*reinterpret_cast<const uint32 *>(_p)) 27 28 #define UNALIGNED_STORE16(_p, _val) (*reinterpret_cast<uint16 *>(_p) = (_val)) 29 #define UNALIGNED_STORE32(_p, _val) (*reinterpret_cast<uint32 *>(_p) = (_val)) 30+#else 31+inline uint32 UNALIGNED_LOAD32(const void *p) { 32+ uint32 t; 33+ memcpy(&t, p, sizeof t); 34+ return t; 35+} 36+ 37+inline void UNALIGNED_STORE32(void *p, uint32 v) { 38+ memcpy(p, &v, sizeof v); 39+} 40+#endif 41 42 // TODO(sesse): NEON supports unaligned 64-bit loads and stores. 43 // See if that would be more efficient on platforms supporting it, 44-- 452.20.1 46 47