aboutsummaryrefslogtreecommitdiffstats
path: root/wsutil/ws_cpuid.h
diff options
context:
space:
mode:
authorJakub Zawadzki <darkjames@darkjames.pl>2014-06-09 23:18:24 +0200
committerAnders Broman <a.broman58@gmail.com>2014-06-10 08:12:43 +0000
commit4571283379857f1a1a783ea037ffaeb5a19562b8 (patch)
treef394f9f6c1be14f01c2e6feb19ff3033f1af7f7d /wsutil/ws_cpuid.h
parent8878d7778e6fb10bf9e6ce20af16f4e247e51e04 (diff)
CPUID improvements
- Make ws_cpuid() return boolean when CPUID is support or no, this way it's easier for caller to determinate if it works (and can use cpuinfo[X] or no). - Add function ws_cpuid_sse42(), use it in ws_mempbrk() [cached] & version information. Change-Id: I4e77699f9f3d11bb9b2e8ea599e48d3c5ad84ed7 Reviewed-on: https://code.wireshark.org/review/2088 Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'wsutil/ws_cpuid.h')
-rw-r--r--wsutil/ws_cpuid.h30
1 files changed, 23 insertions, 7 deletions
diff --git a/wsutil/ws_cpuid.h b/wsutil/ws_cpuid.h
index 75500f2c4d..16e6f8b283 100644
--- a/wsutil/ws_cpuid.h
+++ b/wsutil/ws_cpuid.h
@@ -23,20 +23,23 @@
/*
* Get CPU info on platforms where the cpuid instruction can be used skip 32 bit versions for GCC
* http://www.intel.com/content/dam/www/public/us/en/documents/application-notes/processor-identification-cpuid-instruction-note.pdf
- * the ws_cpuid() routine will return 0 in CPUInfo[0] if cpuinfo isn't available.
+ * the ws_cpuid() routine will return 0 if cpuinfo isn't available.
*/
#if defined(_MSC_VER) /* MSVC */
-static void
+static int
ws_cpuid(guint32 *CPUInfo, guint32 selector)
{
+ CPUInfo[0] = CPUInfo[1] = CPUInfo[2] = CPUInfo[3] = 0;
__cpuid((int *) CPUInfo, selector);
+ /* XXX, how to check if it's supported on MSVC? just in case clear all flags above */
+ return 1;
}
#elif defined(__GNUC__) /* GCC/clang */
#if defined(__x86_64__)
-static inline void
+static inline int
ws_cpuid(guint32 *CPUInfo, int selector)
{
__asm__ __volatile__("cpuid"
@@ -45,22 +48,35 @@ ws_cpuid(guint32 *CPUInfo, int selector)
"=c" (CPUInfo[2]),
"=d" (CPUInfo[3])
: "a"(selector));
+ return 1;
}
#else /* (__i386__) */
-static void
+static int
ws_cpuid(guint32 *CPUInfo, int selector _U_)
{
/* TODO: need a test if older proccesors have the cpuid instruction */
- CPUInfo[0] = 0;
+ return 0;
}
#endif
#else /* Other compilers */
-static void
+static int
ws_cpuid(guint32 *CPUInfo, int selector _U_)
{
- CPUInfo[0] = 0;
+ return 0;
}
#endif
+
+static int
+ws_cpuid_sse42(void)
+{
+ guint32 CPUInfo[4];
+
+ if (!ws_cpuid(CPUInfo, 1))
+ return 0;
+
+ /* in ECX bit 20 toggled on */
+ return (CPUInfo[2] & (1 << 20));
+}