aboutsummaryrefslogtreecommitdiffstats
path: root/wsutil/ws_mempbrk.c
diff options
context:
space:
mode:
authorJakub Zawadzki <darkjames@darkjames.pl>2014-05-22 23:04:40 +0200
committerAnders Broman <a.broman58@gmail.com>2014-06-09 12:02:27 +0000
commitfcb710baec3caa30c2cb7c444bddbe087fc86574 (patch)
tree1ff3f1c4d9b5dca0794162a1000bede1b3a128e6 /wsutil/ws_mempbrk.c
parent66695661992beb054eff219dd73a23559220c867 (diff)
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 <a.broman58@gmail.com>
Diffstat (limited to 'wsutil/ws_mempbrk.c')
-rw-r--r--wsutil/ws_mempbrk.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/wsutil/ws_mempbrk.c b/wsutil/ws_mempbrk.c
new file mode 100644
index 0000000000..bde8452f8b
--- /dev/null
+++ b/wsutil/ws_mempbrk.c
@@ -0,0 +1,74 @@
+/* ws_mempbrk.c
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include "ws_symbol_export.h"
+#include "ws_cpuid.h"
+
+#ifdef HAVE_SSE42
+extern const char *_ws_mempbrk_sse42(const char* haystack, size_t haystacklen, const char *needles);
+#endif
+
+const guint8 *_ws_mempbrk(const guint8* haystack, size_t haystacklen, const guint8 *needles);
+
+const guint8 *
+_ws_mempbrk(const guint8* haystack, size_t haystacklen, const guint8 *needles)
+{
+ gchar tmp[256] = { 0 };
+ const guint8 *haystack_end;
+
+ while (*needles)
+ tmp[*needles++] = 1;
+
+ haystack_end = haystack + haystacklen;
+ while (haystack < haystack_end) {
+ if (tmp[*haystack])
+ return haystack;
+ haystack++;
+ }
+
+ return NULL;
+}
+
+WS_DLL_PUBLIC const guint8 *
+ws_mempbrk(const guint8* haystack, size_t haystacklen, const guint8 *needles)
+{
+#ifdef HAVE_SSE42
+ guint32 CPUInfo[4];
+ guint32 bSSE42Extensions;
+ /*const int has_sse42 = 1;*/ /* XXX, use CPUID */
+#endif
+ if (*needles == 0)
+ return NULL;
+
+#ifdef HAVE_SSE42
+ ws_cpuid(CPUInfo, 1);
+
+ bSSE42Extensions = (CPUInfo[2] & 0x100000);
+
+ if (haystacklen >= 16 && bSSE42Extensions)
+ return _ws_mempbrk_sse42(haystack, haystacklen, needles);
+#endif
+
+ return _ws_mempbrk(haystack, haystacklen, needles);
+}