From 08cd281200a16d9482b8c59860aca6e89f01247d Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Thu, 25 Jan 2024 23:35:37 +0900 Subject: [PATCH] string.c (search_nonascii): skip alignment adjustment for some CPUs Some CPUs (e.g. x86) allow unaligned access to the memory. --- src/string.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/string.c b/src/string.c index cdd11c274..bbb6c2e15 100644 --- a/src/string.c +++ b/src/string.c @@ -327,10 +327,20 @@ search_nonascii(const char *p, const char *e) # define NONASCII_MASK 0x80808080UL #endif +#if defined(__i386) || defined(__i386__) || defined(_M_IX86) || \ + defined(__x86_64) || defined(__x86_64__) || defined(_M_AMD64) || \ + defined(__powerpc64__) || defined(__POWERPC__) || defined(__aarch64__) || \ + defined(__mc68020__) +# define ALIGNED_WORD_ACCESS 0 +#else +# define ALIGNED_WORD_ACCESS 1 +#endif + static const char* search_nonascii(const char *p, const char *e) { if (e - p >= sizeof(void*)) { +#if ALIGNED_WORD_ACCESS if ((uintptr_t)p % sizeof(void*)) { int l = sizeof(void*) - (uintptr_t)p % sizeof(void*); p += l; @@ -347,6 +357,7 @@ search_nonascii(const char *p, const char *e) case 0: break; } } +#endif const uintptr_t *s = (uintptr_t*)p; const uintptr_t *t = (uintptr_t*)(e - (sizeof(void*)-1));