aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--internal.h9
-rw-r--r--string.c4
3 files changed, 19 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index b52dd0456b..e45dc8a303 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Sun May 1 07:30:44 2016 NARUSE, Yui <naruse@ruby-lang.org>
+
+ * string.c (search_nonascii): use nlz on big endian environments.
+
+ * internal.h (nlz_intpr): defined.
+
Sun May 1 00:03:30 2016 NARUSE, Yui <naruse@ruby-lang.org>
* configure.in (__builtin_ctz): check.
diff --git a/internal.h b/internal.h
index a8f4240059..0bac79e012 100644
--- a/internal.h
+++ b/internal.h
@@ -261,6 +261,15 @@ nlz_int128(uint128_t x)
#endif
static inline int
+nlz_intptr(uintptr_t x) {
+#if SIZEOF_VOIDP == 8
+ return nlz_long_long(x);
+#elif SIZEOF_VOIDP == 4
+ return nlz_int(x);
+#endif
+}
+
+static inline int
rb_popcount32(uint32_t x) {
x = (x & 0x55555555) + (x >> 1 & 0x55555555);
x = (x & 0x33333333) + (x >> 2 & 0x33333333);
diff --git a/string.c b/string.c
index 04fc5d063d..3bcaa6cd64 100644
--- a/string.c
+++ b/string.c
@@ -449,7 +449,11 @@ search_nonascii(const char *p, const char *e)
const uintptr_t *t = (const uintptr_t *)(e - (SIZEOF_VOIDP-1));
for (;s < t; s++) {
if (*s & NONASCII_MASK) {
+#if BYTE_ORDER == LITTLE_ENDIAN
return (const char *)s + (ntz_intptr(*s&NONASCII_MASK)>>3);
+#else
+ return (const char *)s + (nlz_intptr(*s&NONASCII_MASK)>>3);
+#endif
}
}
p = (const char *)s;