From a32bce31ecf816bbf0dc3530c6e7dee1e5653ac9 Mon Sep 17 00:00:00 2001 From: Jann Horn Date: Tue, 18 Jun 2013 19:41:28 +0200 Subject: [PATCH] add sse2 stuff for doing stuff with certain chars in strings --- string.c | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) 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