From fcb710baec3caa30c2cb7c444bddbe087fc86574 Mon Sep 17 00:00:00 2001 From: Jakub Zawadzki Date: Thu, 22 May 2014 23:04:40 +0200 Subject: Add sse4.2 optimized function ws_mempbrk_sse42() In text protocols, like SIP, lot of time is spend guint8_pbrk(), assume that text is not binary (no NULs), and use SSE4.2 pcmpistri instruction. Also move & rename guint8_pbrk() from tvbuff.c as _ws_mempbrk. HAVE_SSE42 must be defined to use _ws_mempbrk_sse42() only activaded for Windows currently. Change-Id: Ic853d84805bdb6492c4f45d2bcc79a973fd9804e Reviewed-on: https://code.wireshark.org/review/1730 Reviewed-by: Anders Broman --- epan/tvbuff.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) (limited to 'epan/tvbuff.c') diff --git a/epan/tvbuff.c b/epan/tvbuff.c index be7f1403e5..a286924053 100644 --- a/epan/tvbuff.c +++ b/epan/tvbuff.c @@ -739,26 +739,17 @@ fast_ensure_contiguous(tvbuff_t *tvb, const gint offset, const guint length) return NULL; } +extern const guint8 *ws_mempbrk(const guint8* haystack, size_t haystacklen, const guint8 *needles); + static inline const guint8* guint8_pbrk(const guint8* haystack, size_t haystacklen, const guint8 *needles, guchar *found_needle) { - gchar tmp[256] = { 0 }; - const guint8 *haystack_end; - - while (*needles) - tmp[*needles++] = 1; + const guint8 *result = ws_mempbrk(haystack, haystacklen, needles); - haystack_end = haystack + haystacklen; - while (haystack < haystack_end) { - if (tmp[*haystack]) { - if (found_needle) - *found_needle = *haystack; - return haystack; - } - haystack++; - } + if (result && found_needle) + *found_needle = *result; - return NULL; + return result; } @@ -2963,6 +2954,12 @@ tvb_get_nstringz0(tvbuff_t *tvb, const gint offset, const guint bufsize, guint8* gint tvb_find_line_end(tvbuff_t *tvb, const gint offset, int len, gint *next_offset, const gboolean desegment) { +#ifdef WIN32 + static const char __declspec(align(16)) crlf[] = "\r\n" ; +#else + static const char crlf[] __attribute__((aligned(16))) = "\r\n" ; +#endif + gint eob_offset; gint eol_offset; int linelen; @@ -2981,7 +2978,7 @@ tvb_find_line_end(tvbuff_t *tvb, const gint offset, int len, gint *next_offset, /* * Look either for a CR or an LF. */ - eol_offset = tvb_pbrk_guint8(tvb, offset, len, "\r\n", &found_needle); + eol_offset = tvb_pbrk_guint8(tvb, offset, len, crlf, &found_needle); if (eol_offset == -1) { /* * No CR or LF - line is presumably continued in next packet. -- cgit v1.2.1