AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
cpu.hpp
1/*
2 ANCH Framework: ANother C++ Hack is a C++ framework based on C++23 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 <https://www.gnu.org/licenses/>.
19*/
20#pragma once
21
22#include "anch-device-export.hpp"
23
24#include "singleton.hpp"
25
26#if defined(__x86_64__) || defined(__i386__)
27#include <cpuid.h>
28#endif
29
30
31namespace anch::device {
32
43 class ANCH_DEVICE_EXPORT CPU: public anch::Singleton<CPU> {
44
45 friend class anch::Singleton<CPU>;
46
47 // Attributes +
48 private:
50 bool _aes;
51
53 bool _mmx;
54
56 bool _sse;
57
59 bool _sse2;
60
62 bool _sse3;
63
65 bool _ssse3;
66
68 bool _sse4;
69
71 bool _sse4_1;
72
74 bool _sse4_2;
75 // Attributes -
76
77
78 // Constructors +
79 private:
83 CPU():
84 _aes(false),
85 _mmx(false),
86 _sse(false),
87 _sse2(false),
88 _sse3(false),
89 _ssse3(false),
90 _sse4(false),
91 _sse4_1(false),
92 _sse4_2(false) {
93#if defined(__x86_64__) || defined(__i386__)
94 unsigned int eax, ebx, ecx, edx;
95 // __get_cpuid returns 0 when leaf 1 is not available
96 if(__get_cpuid(1, &eax, &ebx, &ecx, &edx) != 0) {
97 _aes = (ecx & bit_AES) != 0;
98 _mmx = (edx & bit_MMX) != 0;
99 _sse = (edx & bit_SSE) != 0;
100 _sse2 = (edx & bit_SSE2) != 0;
101 _sse3 = (ecx & bit_SSE3) != 0;
102 _ssse3 = (ecx & bit_SSSE3) != 0;
103 _sse4_1 = (ecx & bit_SSE4_1) != 0;
104 _sse4_2 = (ecx & bit_SSE4_2) != 0;
105 _sse4 = _sse4_1 || _sse4_2;
106 }
107#endif
108 }
109 // Constructors -
110
111
112 // Accessors +
113 public:
119 bool isAES() const;
120
126 bool isMMX() const;
127
133 bool isSSE() const;
134
140 bool isSSE2() const;
141
147 bool isSSE3() const;
148
154 bool isSSSE3() const;
155
161 bool isSSE4() const;
162
168 bool isSSE4_1() const;
169
175 bool isSSE4_2() const;
176 // Accessors -
177
178 };
179
180}
181
182#include "device/impl/cpu.hpp"
Meyers' singleton implementation.
Definition singleton.hpp:50
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:31