[PATCH 2/2] riscv: Add big-endian support to string-fzi.h.
Jovan Dmitrovic
jovan.dmitrovic@htecgroup.com
Wed Nov 4 12:40:56 GMT 2026
Functions index_first and index_last should depend on endianness,
considering we are looking at raw bytes.
Signed-off-by: Jovan Dmitrović <jovan.dmitrovic@htecgroup.com>
Signed-off-by: Đorđe Todorović <djordje.todorovic@htecgroup.com>
ChangeLog:
* sysdeps/riscv/string-fzi.h (index_first): Add big-endian
implementation.
(index_last): Likewise.
---
sysdeps/riscv/string-fzi.h | 68 ++++++++++++++++++++++++++++++++++++++
1 file changed, 68 insertions(+)
diff --git a/sysdeps/riscv/string-fzi.h b/sysdeps/riscv/string-fzi.h
index 1e398681fd..75b5be3858 100644
--- a/sysdeps/riscv/string-fzi.h
+++ b/sysdeps/riscv/string-fzi.h
@@ -26,6 +26,73 @@
instead of calling compiler auxiliary functions. */
# include <string-optype.h>
+# if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+static __always_inline unsigned int
+index_first (find_t c)
+{
+ if (sizeof (op_t) == 8)
+ {
+ if (c & 0xff00000000000000UL)
+ return 0;
+ if (c & 0xff000000000000UL)
+ return 1;
+ if (c & 0xff0000000000UL)
+ return 2;
+ if (c & 0xff00000000UL)
+ return 3;
+ if (c & 0xff000000UL)
+ return 4;
+ if (c & 0xff0000UL)
+ return 5;
+ if (c & 0xff00UL)
+ return 6;
+ return 7;
+ }
+ else
+ {
+ if (c & 0xff000000U)
+ return 0;
+ if (c & 0xff0000U)
+ return 1;
+ if (c & 0xff00U)
+ return 2;
+ return 3;
+ }
+}
+
+static __always_inline unsigned int
+index_last (find_t c)
+{
+ if (sizeof (op_t) == 8)
+ {
+ if (c & 0xffUL)
+ return 7;
+ if (c & 0xff00UL)
+ return 6;
+ if (c & 0xff0000UL)
+ return 5;
+ if (c & 0xff000000UL)
+ return 4;
+ if (c & 0xff00000000UL)
+ return 3;
+ if (c & 0xff0000000000UL)
+ return 2;
+ if (c & 0xff000000000000UL)
+ return 1;
+ return 0;
+ }
+ else
+ {
+ if (c & 0xffU)
+ return 3;
+ if (c & 0xff00U)
+ return 2;
+ if (c & 0xff0000U)
+ return 1;
+ return 0;
+ }
+}
+# else
static __always_inline unsigned int
index_first (find_t c)
{
@@ -72,6 +139,7 @@ index_last (find_t c)
return 1;
return 0;
}
+# endif /* __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ */
#endif
#endif /* STRING_FZI_H */
--
2.34.1
More information about the Libc-alpha
mailing list