[PUSHED] riscv: don't do misaligned access with !_HAVE_HW_MISALIGNED_ACCESS
Kito Cheng
kito.cheng@sifive.com
Fri May 22 13:03:13 GMT 2026
Respsect _HAVE_HW_MISALIGNED_ACCESS for riscv string functions
---
newlib/libc/machine/riscv/rv_string.h | 3 ++-
newlib/libc/machine/riscv/strcmp.S | 3 ++-
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/newlib/libc/machine/riscv/rv_string.h b/newlib/libc/machine/riscv/rv_string.h
index dc2a26daf..754e2b577 100644
--- a/newlib/libc/machine/riscv/rv_string.h
+++ b/newlib/libc/machine/riscv/rv_string.h
@@ -13,6 +13,7 @@
#define _RV_STRING_H
#include <stdbool.h>
+#include "newlib.h"
#include "xlenint.h"
#if __riscv_zbb
@@ -67,7 +68,7 @@ static __inline char *__libc_strcpy(char *dst, const char *src, bool ret_start)
char *dst0 = dst;
#if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__)
-#if !(__riscv_misaligned_slow || __riscv_misaligned_fast)
+#if !_HAVE_HW_MISALIGNED_ACCESS
int misaligned = ((uintxlen_t)dst | (uintxlen_t)src) & (sizeof (uintxlen_t) - 1);
if (__builtin_expect(!misaligned, 1))
#endif
diff --git a/newlib/libc/machine/riscv/strcmp.S b/newlib/libc/machine/riscv/strcmp.S
index 18ac9a981..49b999c0f 100644
--- a/newlib/libc/machine/riscv/strcmp.S
+++ b/newlib/libc/machine/riscv/strcmp.S
@@ -10,6 +10,7 @@
*/
#include <sys/asm.h>
+#include "newlib.h"
.text
.globl strcmp
@@ -36,7 +37,7 @@ strcmp:
#else
li t2, -1
-#if !(__riscv_misaligned_slow || __riscv_misaligned_fast)
+#if !_HAVE_HW_MISALIGNED_ACCESS
or a4, a0, a1
and a4, a4, SZREG-1
bnez a4, .Lmisaligned
--
2.54.0
More information about the Newlib
mailing list