[PATCH] riscv: Add big-endian support to string-fzi.h.
Jovan Dmitrovic
jovan.dmitrovic@htecgroup.com
Wed Jun 3 13:52:11 GMT 2026
Functions index_first and index_last should depend on endianness,
considering we are looking at raw bytes.
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 613e5789e4..0eba3c8c6a 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 & 0x8000000000000000UL)
+ return 0;
+ if (c & 0x80000000000000UL)
+ return 1;
+ if (c & 0x800000000000UL)
+ return 2;
+ if (c & 0x8000000000UL)
+ return 3;
+ if (c & 0x80000000UL)
+ return 4;
+ if (c & 0x800000UL)
+ return 5;
+ if (c & 0x8000UL)
+ return 6;
+ return 7;
+ }
+ else
+ {
+ if (c & 0x80000000U)
+ return 0;
+ if (c & 0x800000U)
+ return 1;
+ if (c & 0x8000U)
+ return 2;
+ return 3;
+ }
+}
+
+static __always_inline unsigned int
+index_last (find_t c)
+{
+ if (sizeof (op_t) == 8)
+ {
+ if (c & 0x80UL)
+ return 7;
+ if (c & 0x8000UL)
+ return 6;
+ if (c & 0x800000UL)
+ return 5;
+ if (c & 0x80000000UL)
+ return 4;
+ if (c & 0x8000000000UL)
+ return 3;
+ if (c & 0x800000000000UL)
+ return 2;
+ if (c & 0x80000000000000UL)
+ return 1;
+ return 0;
+ }
+ else
+ {
+ if (c & 0x80U)
+ return 3;
+ if (c & 0x8000U)
+ return 2;
+ if (c & 0x800000U)
+ 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