diff options
author | Jakub Zawadzki <darkjames@darkjames.pl> | 2014-05-31 11:22:56 +0200 |
---|---|---|
committer | Michael Mann <mmann78@netscape.net> | 2014-05-31 13:01:08 +0000 |
commit | 531541660b31e87922021158454b2441e67935fa (patch) | |
tree | 6594ab833afa6c6887627c8058e990ba931ebedc /wsutil/ws_cpuid.h | |
parent | 799972425dc2178b28067e729abc99d31e0ccc67 (diff) |
Move cpuid to seperate header file.
It'll be later used also for detecting sse4.2
Change-Id: I1930abb29026b455d453a79b5f301cdf37585160
Reviewed-on: https://code.wireshark.org/review/1803
Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'wsutil/ws_cpuid.h')
-rw-r--r-- | wsutil/ws_cpuid.h | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/wsutil/ws_cpuid.h b/wsutil/ws_cpuid.h new file mode 100644 index 0000000000..75500f2c4d --- /dev/null +++ b/wsutil/ws_cpuid.h @@ -0,0 +1,66 @@ +/* ws_cpuid.h + * Get the CPU info + * + * 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. + */ + +/* + * 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. + */ + +#if defined(_MSC_VER) /* MSVC */ +static void +ws_cpuid(guint32 *CPUInfo, guint32 selector) +{ + __cpuid((int *) CPUInfo, selector); +} + +#elif defined(__GNUC__) /* GCC/clang */ + +#if defined(__x86_64__) +static inline void +ws_cpuid(guint32 *CPUInfo, int selector) +{ + __asm__ __volatile__("cpuid" + : "=a" (CPUInfo[0]), + "=b" (CPUInfo[1]), + "=c" (CPUInfo[2]), + "=d" (CPUInfo[3]) + : "a"(selector)); +} +#else /* (__i386__) */ + +static void +ws_cpuid(guint32 *CPUInfo, int selector _U_) +{ + /* TODO: need a test if older proccesors have the cpuid instruction */ + CPUInfo[0] = 0; +} +#endif + +#else /* Other compilers */ + +static void +ws_cpuid(guint32 *CPUInfo, int selector _U_) +{ + CPUInfo[0] = 0; +} +#endif |