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 */
