AnCH Framework 0.1
Another C++ Hack Framework
 
Loading...
Searching...
No Matches
cpu.hpp
1/*
2 ANCH Framework: ANother C++ Hack is a C++ framework based on C++11 standard
3 Copyright (C) 2012 Vincent Lachenal
4
5 This file is part of ANCH Framework.
6
7 ANCH Framework is free software: you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 ANCH Framework is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with ANCH Framework. If not, see <http://www.gnu.org/licenses/>.
19*/
20#pragma once
21
22#include "singleton.hpp"
23
24#ifdef ANCH_WINDOWS
25
26// Windows
27#define anch_cpuid(info, x) __cpuidex(info, x, 0)
28
29#elif defined ANCH_POSIX
30
31// GCC Intrinsics
32#include <cpuid.h>
33void anch_cpuid(int info[4], int InfoType){
34 __cpuid_count(InfoType, 0, info[0], info[1], info[2], info[3]);
35}
36
37#endif
38
39
40namespace anch::device {
41
51 class CPU: public anch::Singleton<CPU> {
52
53 friend class anch::Singleton<CPU>;
54
55 // Attributes +
56 private:
58 bool _aes;
59
61 bool _mmx;
62
64 bool _sse;
65
67 bool _sse2;
68
70 bool _sse3;
71
73 bool _ssse3;
74
76 bool _sse4;
77
79 bool _sse4_1;
80
82 bool _sse4_2;
83 // Attributes -
84
85
86 // Constructors +
87 private:
91 CPU() {
92 int info[4];
93 anch_cpuid(info, 0);
94 int nIds = info[0];
95 if(nIds >= 0x00000001) {
96 anch_cpuid(info,0x00000001);
97 _aes = (info[2] & ((int)1 << 25)) != 0;
98 _mmx = (info[3] & ((int)1 << 23)) != 0;
99 _sse = (info[3] & ((int)1 << 25)) != 0;
100 _sse2 = (info[3] & ((int)1 << 26)) != 0;
101 _sse3 = (info[2] & ((int)1 << 0)) != 0;
102 _ssse3 = (info[2] & ((int)1 << 9)) != 0;
103 _sse4_1 = (info[2] & ((int)1 << 19)) != 0;
104 _sse4_2 = (info[2] & ((int)1 << 20)) != 0;
105 _sse4 = _sse4_1 || _sse4_2;
106 }
107 }
108 // Constructors -
109
110
111 // Accessors +
112 public:
118 bool isAES() const;
119
125 bool isMMX() const;
126
132 bool isSSE() const;
133
139 bool isSSE2() const;
140
146 bool isSSE3() const;
147
153 bool isSSSE3() const;
154
160 bool isSSE4() const;
161
167 bool isSSE4_1() const;
168
174 bool isSSE4_2() const;
175 // Accessors -
176
177 };
178
179}
180
181#include "device/impl/cpu.hpp"
Meyers' singleton implementation.
Definition singleton.hpp:34
bool isSSE2() const
bool isSSE4_1() const
bool isAES() const
bool isSSE4_2() const
bool isSSSE3() const
bool isSSE4() const
bool isSSE3() const
bool isMMX() const
bool isSSE() const
Device management namespace.
Definition cpu.hpp:40