AnCH Framework  0.1
Another C++ Hack Framework
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 #ifndef _ANCH_DEVICE_CPU_H_
21 #define _ANCH_DEVICE_CPU_H_
22 
23 #include "singleton.hpp"
24 
25 #ifdef ANCH_WINDOWS
26 
27 // Windows
28 #define anch_cpuid(info, x) __cpuidex(info, x, 0)
29 
30 #elif defined ANCH_POSIX
31 
32 // GCC Intrinsics
33 #include <cpuid.h>
34 void anch_cpuid(int info[4], int InfoType){
35  __cpuid_count(InfoType, 0, info[0], info[1], info[2], info[3]);
36 }
37 
38 #endif
39 
40 
41 namespace anch {
42  namespace device {
43 
53  class CPU: public anch::Singleton<CPU> {
54 
55  friend class anch::Singleton<CPU>;
56 
57  // Attributes +
58  private:
60  bool _aes;
61 
63  bool _mmx;
64 
66  bool _sse;
67 
69  bool _sse2;
70 
72  bool _sse3;
73 
75  bool _ssse3;
76 
78  bool _sse4;
79 
81  bool _sse4_1;
82 
84  bool _sse4_2;
85  // Attributes -
86 
87 
88  // Constructors +
89  private:
93  CPU() {
94  int info[4];
95  anch_cpuid(info, 0);
96  int nIds = info[0];
97  if(nIds >= 0x00000001) {
98  anch_cpuid(info,0x00000001);
99  _aes = (info[2] & ((int)1 << 25)) != 0;
100  _mmx = (info[3] & ((int)1 << 23)) != 0;
101  _sse = (info[3] & ((int)1 << 25)) != 0;
102  _sse2 = (info[3] & ((int)1 << 26)) != 0;
103  _sse3 = (info[2] & ((int)1 << 0)) != 0;
104  _ssse3 = (info[2] & ((int)1 << 9)) != 0;
105  _sse4_1 = (info[2] & ((int)1 << 19)) != 0;
106  _sse4_2 = (info[2] & ((int)1 << 20)) != 0;
107  _sse4 = _sse4_1 || _sse4_2;
108  }
109  }
110  // Constructors -
111 
112 
113  // Accessors +
114  public:
120  inline bool isAES() const {
121  return _aes;
122  }
123 
129  inline bool isMMX() const {
130  return _mmx;
131  }
132 
138  inline bool isSSE() const {
139  return _sse;
140  }
141 
147  inline bool isSSE2() const {
148  return _sse2;
149  }
150 
156  inline bool isSSE3() const {
157  return _sse3;
158  }
159 
165  inline bool isSSSE3() const {
166  return _ssse3;
167  }
168 
174  inline bool isSSE4() const {
175  return _sse4;
176  }
177 
183  inline bool isSSE4_1() const {
184  return _sse4_1;
185  }
186 
192  inline bool isSSE4_2() const {
193  return _sse4_2;
194  }
195  // Accessors -
196 
197  };
198 
199  }
200 }
201 
202 #endif // _ANCH_DEVICE_CPU_H_
bool isSSE() const
Definition: cpu.hpp:138
bool isSSE4_1() const
Definition: cpu.hpp:183
bool isMMX() const
Definition: cpu.hpp:129
AnCH framework base namespace.
Definition: base64.hpp:28
bool isSSE3() const
Definition: cpu.hpp:156
bool isSSSE3() const
Definition: cpu.hpp:165
CPU features detection.
Definition: cpu.hpp:53
bool isAES() const
Definition: cpu.hpp:120
bool isSSE4_2() const
Definition: cpu.hpp:192
bool isSSE4() const
Definition: cpu.hpp:174
bool isSSE2() const
Definition: cpu.hpp:147
Meyers&#39; singleton implemtation.
Definition: singleton.hpp:35