From: Victor Julien Date: Thu, 14 Nov 2013 11:51:06 +0000 (+0100) Subject: memcmp: don't use SSE intrinsics if less that 16 bytes are available in SSE_4_2 version. X-Git-Tag: suricata-2.0beta2~155 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=49a54713daafde0edbecdd5e7e8e81dfb342ad37;p=thirdparty%2Fsuricata.git memcmp: don't use SSE intrinsics if less that 16 bytes are available in SSE_4_2 version. --- diff --git a/src/util-memcmp.h b/src/util-memcmp.h index f6fc3a0c59..8443526318 100644 --- a/src/util-memcmp.h +++ b/src/util-memcmp.h @@ -66,6 +66,12 @@ static inline int SCMemcmp(void *s1, void *s2, size_t n) size_t m = 0; do { + /* apparently we can't just read 16 bytes even though + * it almost always works fine :) */ + if (likely(n - m < 16)) { + return memcmp(s1, s2, n - m) ? 1 : 0; + } + /* load the buffers into the 128bit vars */ b1 = _mm_loadu_si128((const __m128i *) s1); b2 = _mm_loadu_si128((const __m128i *) s2); @@ -102,6 +108,12 @@ static inline int SCMemcmpLowercase(void *s1, void *s2, size_t n) __m128i uplow = _mm_set1_epi8(0x20); do { + /* apparently we can't just read 16 bytes even though + * it almost always works fine :) */ + if (likely(n - m < 16)) { + return MemcmpLowercase(s1, s2, n - m); + } + b1 = _mm_loadu_si128((const __m128i *) s1); b2 = _mm_loadu_si128((const __m128i *) s2); size_t len = n - m;