diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-05-03 13:14:30 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-05-03 13:14:30 +0000 |
commit | cdef0bc8337377bd11f7987ed82c5780dc6e869f (patch) | |
tree | 855a25048f055dd4070d6472ee2ea1ad3ae5afc4 /string.c | |
parent | e0611820df64b7cc70cbe15535b82e245913ee97 (diff) |
* string.c (count_utf8_lead_bytes_with_word): Use __builtin_popcount
only if it can use SSE 4.2 POPCNT whose latency is 3 cycle.
* internal.h (rb_popcount64): use __builtin_popcountll because now
it is in fast path.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54894 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r-- | string.c | 12 |
1 files changed, 8 insertions, 4 deletions
@@ -1476,17 +1476,21 @@ count_utf8_lead_bytes_with_word(const uintptr_t *s) uintptr_t d = *s; /* Transform so that bit0 indicates whether we have a UTF-8 leading byte or not. */ - d |= ~(d>>1); - d >>= 6; + d = (d>>6) | (~d>>7); d &= NONASCII_MASK >> 7; /* Gather all bytes. */ +#if defined(HAVE_BUILTIN___BUILTIN_POPCOUNT) && defined(__POPCNT__) + /* use only if it can use POPCNT */ + return rb_popcount_intptr(d); +#else d += (d>>8); d += (d>>16); -#if SIZEOF_VOIDP == 8 +# if SIZEOF_VOIDP == 8 d += (d>>32); -#endif +# endif return (d&0xF); +#endif } #endif |