aboutsummaryrefslogtreecommitdiffstats
path: root/string.c
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-05-03 13:14:30 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-05-03 13:14:30 +0000
commit313e45cd4ffd4b8d37f3b02bb67699f1c5bfdf06 (patch)
tree855a25048f055dd4070d6472ee2ea1ad3ae5afc4 /string.c
parentaafa14b4e8e0340b5bc1ab6bcbd76f5e5435e15f (diff)
downloadruby-313e45cd4ffd4b8d37f3b02bb67699f1c5bfdf06.tar.gz
* 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.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/string.c b/string.c
index 35e53f7306..9ccf0933e2 100644
--- a/string.c
+++ b/string.c
@@ -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