From: Jann Horn Date: Tue, 18 Jun 2013 17:41:28 +0000 (+0200) Subject: add sse2 stuff for doing stuff with certain chars in strings X-Git-Url: http://git.thejh.net/?p=libjh.git;a=commitdiff_plain;h=a32bce31ecf816bbf0dc3530c6e7dee1e5653ac9;hp=483ad7514b32f4557c8866bbde2091aed69e98b4 add sse2 stuff for doing stuff with certain chars in strings --- diff --git a/string.c b/string.c index c91e6d2..5ef61b9 100644 --- a/string.c +++ b/string.c @@ -2,6 +2,8 @@ // This code is licensed under the AGPLv3. #include +#include +HEADER #include HEADER #define streq(a,b) (!strcmp((a),(b))) @@ -14,6 +16,112 @@ PUBLIC_FN int count_char_occurences(char *s, char c) { return n; } +// For big buffers. +PUBLIC_FN size_t count_char_occurences_in_buf(char *b, size_t bl, char c) { + char *be = b+bl; + size_t res = 0; + + #ifdef __SSE2__ + #include + + // do it the simple way until we get to the next 16-byte-aligned address + while ((((uint64_t)b)&0xf) && b + + // do it the simple way until we get to the next 16-byte-aligned address + while ((((uint64_t)b)&0xf) && b