]>
Commit | Line | Data |
---|---|---|
f22341db | 1 | /* This file is part of the Vc library. |
2 | ||
3 | Copyright (C) 2009-2012 Matthias Kretz <kretz@kde.org> | |
4 | ||
5 | Vc is free software: you can redistribute it and/or modify | |
6 | it under the terms of the GNU Lesser General Public License as | |
7 | published by the Free Software Foundation, either version 3 of | |
8 | the License, or (at your option) any later version. | |
9 | ||
10 | Vc is distributed in the hope that it will be useful, but | |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | GNU Lesser General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU Lesser General Public | |
16 | License along with Vc. If not, see <http://www.gnu.org/licenses/>. | |
17 | ||
18 | */ | |
19 | ||
20 | #ifndef CPUID_H | |
21 | #define CPUID_H | |
22 | ||
23 | #include <iostream> | |
24 | ||
25 | namespace Vc | |
26 | { | |
27 | class CpuId | |
28 | { | |
29 | typedef unsigned char uchar; | |
30 | typedef unsigned short ushort; | |
31 | typedef unsigned int uint; | |
32 | ||
33 | public: | |
34 | enum ProcessorType { | |
35 | OriginalOemProcessor = 0, | |
36 | IntelOverDriveProcessor = 1, | |
37 | DualProcessor = 2, | |
38 | IntelReserved = 3 | |
39 | }; | |
40 | ||
41 | static void init(); | |
42 | static inline ushort cacheLineSize() { return static_cast<ushort>(s_cacheLineSize) * 8u; } | |
43 | static inline ProcessorType processorType() { return s_processorType; } | |
44 | static inline uint processorFamily() { return s_processorFamily; } | |
45 | static inline uint processorModel() { return s_processorModel; } | |
46 | static inline uint logicalProcessors() { return s_logicalProcessors; } | |
47 | static inline bool isAmd () { return s_ecx0 == 0x444D4163; } | |
48 | static inline bool isIntel () { return s_ecx0 == 0x6C65746E; } | |
49 | static inline bool hasSse3 () { return s_processorFeaturesC & (1 << 0); } | |
50 | static inline bool hasVmx () { return (s_processorFeaturesC & (1 << 5)) != 0; } | |
51 | static inline bool hasSmx () { return (s_processorFeaturesC & (1 << 6)) != 0; } | |
52 | static inline bool hasEst () { return (s_processorFeaturesC & (1 << 7)) != 0; } | |
53 | static inline bool hasTm2 () { return (s_processorFeaturesC & (1 << 8)) != 0; } | |
54 | static inline bool hasSsse3() { return (s_processorFeaturesC & (1 << 9)) != 0; } | |
55 | static inline bool hasPdcm () { return (s_processorFeaturesC & (1 << 15)) != 0; } | |
56 | static inline bool hasSse41() { return (s_processorFeaturesC & (1 << 19)) != 0; } | |
57 | static inline bool hasSse42() { return (s_processorFeaturesC & (1 << 20)) != 0; } | |
58 | static inline bool hasAes () { return (s_processorFeaturesC & (1 << 25)) != 0; } | |
59 | static inline bool hasOsxsave() { return (s_processorFeaturesC & (1 << 27)) != 0; } | |
60 | static inline bool hasAvx () { return (s_processorFeaturesC & (1 << 28)) != 0; } | |
61 | static inline bool hasFpu () { return (s_processorFeaturesD & (1 << 0)) != 0; } | |
62 | static inline bool hasVme () { return (s_processorFeaturesD & (1 << 1)) != 0; } | |
63 | static inline bool hasDe () { return (s_processorFeaturesD & (1 << 2)) != 0; } | |
64 | static inline bool hasPse () { return (s_processorFeaturesD & (1 << 3)) != 0; } | |
65 | static inline bool hasTsc () { return (s_processorFeaturesD & (1 << 4)) != 0; } | |
66 | static inline bool hasMsr () { return (s_processorFeaturesD & (1 << 5)) != 0; } | |
67 | static inline bool hasPae () { return (s_processorFeaturesD & (1 << 6)) != 0; } | |
68 | static inline bool hasMtrr () { return (s_processorFeaturesD & (1 << 12)) != 0; } | |
69 | static inline bool hasCmov () { return (s_processorFeaturesD & (1 << 15)) != 0; } | |
70 | static inline bool hasClfsh() { return (s_processorFeaturesD & (1 << 19)) != 0; } | |
71 | static inline bool hasAcpi () { return (s_processorFeaturesD & (1 << 22)) != 0; } | |
72 | static inline bool hasMmx () { return (s_processorFeaturesD & (1 << 23)) != 0; } | |
73 | static inline bool hasSse () { return (s_processorFeaturesD & (1 << 25)) != 0; } | |
74 | static inline bool hasSse2 () { return (s_processorFeaturesD & (1 << 26)) != 0; } | |
75 | static inline bool hasHtt () { return (s_processorFeaturesD & (1 << 28)) != 0; } | |
76 | static inline bool hasSse4a() { return (s_processorFeatures8C & (1 << 6)) != 0; } | |
77 | static inline bool hasMisAlignSse() { return (s_processorFeatures8C & (1 << 7)) != 0; } | |
78 | static inline bool hasAmdPrefetch() { return (s_processorFeatures8C & (1 << 8)) != 0; } | |
79 | static inline bool hasXop () { return (s_processorFeatures8C & (1 << 11)) != 0; } | |
80 | static inline bool hasFma4 () { return (s_processorFeatures8C & (1 << 16)) != 0; } | |
81 | static inline bool hasRdtscp() { return (s_processorFeatures8D & (1 << 27)) != 0; } | |
82 | static inline bool has3DNow() { return (s_processorFeatures8D & (1u << 31)) != 0; } | |
83 | static inline bool has3DNowExt() { return (s_processorFeatures8D & (1 << 30)) != 0; } | |
84 | static inline uint L1Instruction() { return s_L1Instruction; } | |
85 | static inline uint L1Data() { return s_L1Data; } | |
86 | static inline uint L2Data() { return s_L2Data; } | |
87 | static inline uint L3Data() { return s_L3Data; } | |
88 | static inline ushort L1InstructionLineSize() { return s_L1InstructionLineSize; } | |
89 | static inline ushort L1DataLineSize() { return s_L1DataLineSize; } | |
90 | static inline ushort L2DataLineSize() { return s_L2DataLineSize; } | |
91 | static inline ushort L3DataLineSize() { return s_L3DataLineSize; } | |
92 | static inline uint L1Associativity() { return s_L1Associativity; } | |
93 | static inline uint L2Associativity() { return s_L2Associativity; } | |
94 | static inline uint L3Associativity() { return s_L3Associativity; } | |
95 | static inline ushort prefetch() { return s_prefetch; } | |
96 | ||
97 | private: | |
98 | static void interpret(uchar byte, bool *checkLeaf4); | |
99 | ||
100 | static uint s_ecx0; | |
101 | static uint s_logicalProcessors; | |
102 | static uint s_processorFeaturesC; | |
103 | static uint s_processorFeaturesD; | |
104 | static uint s_processorFeatures8C; | |
105 | static uint s_processorFeatures8D; | |
106 | static uint s_L1Instruction; | |
107 | static uint s_L1Data; | |
108 | static uint s_L2Data; | |
109 | static uint s_L3Data; | |
110 | static ushort s_L1InstructionLineSize; | |
111 | static ushort s_L1DataLineSize; | |
112 | static ushort s_L2DataLineSize; | |
113 | static ushort s_L3DataLineSize; | |
114 | static uint s_L1Associativity; | |
115 | static uint s_L2Associativity; | |
116 | static uint s_L3Associativity; | |
117 | static ushort s_prefetch; | |
118 | static uchar s_brandIndex; | |
119 | static uchar s_cacheLineSize; | |
120 | static uchar s_processorModel; | |
121 | static uchar s_processorFamily; | |
122 | static ProcessorType s_processorType; | |
123 | static bool s_noL2orL3; | |
124 | }; | |
125 | } // namespace Vc | |
126 | ||
127 | #endif // CPUID_H |