Skip to content

Commit

Permalink
* string.c (search_nonascii): use nlz on big endian environments.
Browse files Browse the repository at this point in the history
* internal.h (nlz_intpr): defined.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54859 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nurse committed Apr 30, 2016
1 parent aa2395b commit 0f0121f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
9 changes: 9 additions & 0 deletions internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,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);
Expand Down
4 changes: 4 additions & 0 deletions string.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 0f0121f

Please sign in to comment.