Clean up MUtils::CPUFetaures code.
[MUtilities.git] / include / MUtils / CPUFeatures.h
blobd9028f0d6200de2b12bfc0731975bdfeba9a7174
1 ///////////////////////////////////////////////////////////////////////////////
2 // MuldeR's Utilities for Qt
3 // Copyright (C) 2004-2016 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 uint8_t VENDOR_INTEL = 0x01U; ///< \brief CPU vendor flag \details Indicates that the CPU's vendor is *Intel*
48 static const uint8_t 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_SSE4 = 0x030U; ///< \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
61 /**
62 * \brief Struct to hold information about the CPU
64 typedef struct
66 quint32 family; ///< CPU *family* indicator, which specifies the processor "generation" to which the CPU belongs
67 quint32 model; ///< CPU *model* indicator, which is used to distinguish processor "variants" within a generation
68 quint32 stepping; ///< CPU *stepping* indicator, which is used to distinguish "revisions" of a certain processor model
69 quint32 count; ///< The number of available (logical) processors
70 quint32 features; ///< CPU *feature* flags, indicating suppoprt for extended instruction sets; all flags are OR-combined
71 bool x64; ///< Indicates that the processor and the operating system support 64-Bit (AMD64/EM64T)
72 uint8_t vendor; ///< CPU *vendor* flag; might be zero, if vendor is unknown
73 char idstr[13]; ///< CPU *identifier* string, exactly 12 characters (e.g. "GenuineIntel" or "AuthenticAMD")
74 char brand[48]; ///< CPU *brand* string, up to 48 characters (e.g. "Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz")
76 cpu_info_t;
78 /**
79 * \brief Detect processor information
81 * 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.
83 * \return The function returns a `cpu_info_t` struct containing the detected information about the CPU.
85 MUTILS_API cpu_info_t detect(void);