Happy new year 2017!
[MUtilities.git] / include / MUtils / CPUFeatures.h
blob830e81f3d22867eee510ac26d214b62d4d02fd22
1 ///////////////////////////////////////////////////////////////////////////////
2 // MuldeR's Utilities for Qt
3 // Copyright (C) 2004-2017 LoRd_MuldeR <MuldeR2@GMX.de>
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 // http://www.gnu.org/licenses/lgpl-2.1.txt
20 //////////////////////////////////////////////////////////////////////////////////
22 /**
23 * @file
24 * @brief This file contains function for detecting information about the CPU
26 * Call the MUtils::CPUFetaures::detect() to detect information about the processor, which will be returned in a `MUtils::CPUFetaures::cpu_info_t` struct.
29 #pragma once
31 //MUtils
32 #include <MUtils/Global.h>
34 //Qt
35 #include <QStringList>
37 namespace MUtils
39 /**
40 * \brief This namespace contains functions and constants for detecting CPU information
42 * Call the detect() to detect information about the processor, which will be returned in a `cpu_info_t` struct.
44 namespace CPUFetaures
46 // CPU vendor flag
47 static const quint8 VENDOR_INTEL = 0x01U; ///< \brief CPU vendor flag \details Indicates that the CPU's vendor is *Intel*
48 static const quint8 VENDOR_AMD = 0x02U; ///< \brief CPU vendor flag \details Indicates that the CPU's vendor is *AMD*
50 // CPU feature flag
51 static const quint32 FLAG_CMOV = 0x001U; ///< \brief CPU feature flag \details Indicates that the CPU supports the *CMOV* instruction
52 static const quint32 FLAG_MMX = 0x002U; ///< \brief CPU feature flag \details Indicates that the CPU supports the *MMX* instruction set extension
53 static const quint32 FLAG_SSE = 0x004U; ///< \brief CPU feature flag \details Indicates that the CPU supports the *SSE* instruction set extension
54 static const quint32 FLAG_SSE2 = 0x008U; ///< \brief CPU feature flag \details Indicates that the CPU supports the *SSE2* instruction set extension
55 static const quint32 FLAG_SSE3 = 0x010U; ///< \brief CPU feature flag \details Indicates that the CPU supports the *SSE3* instruction set extension
56 static const quint32 FLAG_SSSE3 = 0x020U; ///< \brief CPU feature flag \details Indicates that the CPU supports the *SSSE3* instruction set extension
57 static const quint32 FLAG_SSE41 = 0x040U; ///< \brief CPU feature flag \details Indicates that the CPU supports the *SSE4.1* instruction set extension
58 static const quint32 FLAG_SSE42 = 0x080U; ///< \brief CPU feature flag \details Indicates that the CPU supports the *SSE4.2* instruction set extension
59 static const quint32 FLAG_AVX = 0x100U; ///< \brief CPU feature flag \details Indicates that the CPU supports the *AVX* instruction set extension
60 static const quint32 FLAG_AVX2 = 0x200U; ///< \brief CPU feature flag \details Indicates that the CPU supports the *AVX2* instruction set extension
61 static const quint32 FLAG_FMA3 = 0x400U; ///< \brief CPU feature flag \details Indicates that the CPU supports the *FMA3* instruction
62 static const quint32 FLAG_LZCNT = 0x800U; ///< \brief CPU feature flag \details Indicates that the CPU supports the *LZCNT* instruction
64 /**
65 * \brief Struct to hold information about the CPU. See `_cpu_info_t` for details!
67 typedef struct _cpu_info_t
69 quint32 family; ///< CPU *family* indicator, which specifies the processor "generation" to which the CPU belongs
70 quint32 model; ///< CPU *model* indicator, which is used to distinguish processor "variants" within a generation
71 quint32 stepping; ///< CPU *stepping* indicator, which is used to distinguish "revisions" of a certain processor model
72 quint32 count; ///< The number of available (logical) processors
73 quint32 features; ///< CPU *feature* flags, indicating suppoprt for extended instruction sets; all flags are OR-combined
74 bool x64; ///< Indicates that the processor and the operating system support 64-Bit (AMD64/EM64T)
75 quint8 vendor; ///< CPU *vendor* flag; might be zero, if vendor is unknown
76 char idstr[13]; ///< CPU *identifier* string, exactly 12 characters (e.g. "GenuineIntel" or "AuthenticAMD")
77 char brand[48]; ///< CPU *brand* string, up to 48 characters (e.g. "Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz")
79 cpu_info_t;
81 /**
82 * \brief Detect processor information
84 * Detects information about the CPU on which the application is running, including CPU vendor, identifier string, feature flags (MMX, SSE, AVX, etc) as well as the CPU core count.
86 * \return The function returns a `cpu_info_t` struct containing the detected information about the CPU.
88 MUTILS_API cpu_info_t detect(void);