@@ -191,6 +191,47 @@ bytes_equal_nocarry (vector_int x, vector_int y)
}
#endif
+#ifndef CUSTOM_COMPARE_BYTES
+# if __BYTE_ORDER == __LITTLE_ENDIAN
+static __always_inline
+int
+compare_bytes (vector_int x, vector_int y, vector_int zero_mask)
+{
+ /* Removes bytes beyond terminating '\0'. When zero mask its 0 then it
+ evaluates to ~0 and doesn't mask anything. */
+ zero_mask = zero_mask ^ (zero_mask - 1);
+
+ /* Find first bit that differs. Make mask with bits upto that bit set
+ to 1. */
+ vector_int and_mask = (((x ^ y) ^ ((x ^ y) - 1))
+
+ /* With difference in highest bit we can't compare them by subtraction. */
+
+ if (and_mask == ~((vector_int) 0))
+ {
+ if (x > y)
+ return 1;
+ if (x < y)
+ return -1;
+ return 0;
+ }
+
+ /* Convert mask to bytewise one that has in given byte 255 or 0 if bitwise
+ mask had some bit selected or not. */
+
+ and_mask = (and_mask & ones) * 255;
+
+ and_mask = and_mask & zero_mask;
+
+ /* As check above ensures that difference fits signed vector_int we could
+ subtract them. */
+
+ vector_int diff = (x & and_mask) - (y_greater & and_mask);
+ return (int)(diff >> (8 * (LSIZE - sizeof (int))));
+}
+# endif
+#endif
+
/*
When you have hardware ctz/clz its probably best bet. However
for softare emulation you could get better than generic one as you