1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
|
// AsmJit - Complete JIT Assembler for C++ Language.
// Copyright (c) 2008-2010, Petr Kobalicek <kobalicek.petr@gmail.com>
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
// [Guard]
#ifndef _ASMJIT_CPUINFO_H
#define _ASMJIT_CPUINFO_H
// [Dependencies]
#include "Build.h"
// [Api-Begin]
#include "ApiBegin.h"
namespace AsmJit {
//! @addtogroup AsmJit_CpuInfo
//! @{
// ============================================================================
// [AsmJit::CpuId]
// ============================================================================
#if defined(ASMJIT_X86) || defined(ASMJIT_X64)
//! @brief Structure (union) used by cpuid() function.
union CpuId
{
//! @brief cpuid results array(eax, ebx, ecx and edx registers).
uint32_t i[4];
struct
{
//! @brief cpuid result in eax register.
uint32_t eax;
//! @brief cpuid result in ebx register.
uint32_t ebx;
//! @brief cpuid result in ecx register.
uint32_t ecx;
//! @brief cpuid result in edx register.
uint32_t edx;
};
};
//! @brief Calls CPUID instruction with eax == @a in and returns result to @a out.
//!
//! @c cpuid() function has one input parameter that is passed to cpuid through
//! eax register and results in four output values representing result of cpuid
//! instruction (eax, ebx, ecx and edx registers).
ASMJIT_API void cpuid(uint32_t in, CpuId* out) ASMJIT_NOTHROW;
#endif // ASMJIT_X86 || ASMJIT_X64
// ============================================================================
// [AsmJit::CPU_VENDOR]
// ============================================================================
//! @brief Cpu vendor IDs.
//!
//! Cpu vendor IDs are specific for AsmJit library. Vendor ID is not directly
//! read from cpuid result, instead it's based on CPU vendor string.
enum CPU_VENDOR
{
//! @brief Unknown CPU vendor.
CPU_VENDOR_UNKNOWN = 0,
//! @brief Intel CPU vendor.
CPU_VENDOR_INTEL = 1,
//! @brief AMD CPU vendor.
CPU_VENDOR_AMD = 2,
//! @brief National Semiconductor CPU vendor (applies also to Cyrix processors).
CPU_VENDOR_NSM = 3,
//! @brief Transmeta CPU vendor.
CPU_VENDOR_TRANSMETA = 4,
//! @brief VIA CPU vendor.
CPU_VENDOR_VIA = 5
};
// ============================================================================
// [AsmJit::CPU_FEATURE]
// ============================================================================
//! @brief X86/X64 CPU features.
enum CPU_FEATURE
{
//! @brief Cpu has RDTSC instruction.
CPU_FEATURE_RDTSC = 1U << 0,
//! @brief Cpu has RDTSCP instruction.
CPU_FEATURE_RDTSCP = 1U << 1,
//! @brief Cpu has CMOV instruction (conditional move)
CPU_FEATURE_CMOV = 1U << 2,
//! @brief Cpu has CMPXCHG8B instruction
CPU_FEATURE_CMPXCHG8B = 1U << 3,
//! @brief Cpu has CMPXCHG16B instruction (64-bit processors)
CPU_FEATURE_CMPXCHG16B = 1U << 4,
//! @brief Cpu has CLFUSH instruction
CPU_FEATURE_CLFLUSH = 1U << 5,
//! @brief Cpu has PREFETCH instruction
CPU_FEATURE_PREFETCH = 1U << 6,
//! @brief Cpu supports LAHF and SAHF instrictions.
CPU_FEATURE_LAHF_SAHF = 1U << 7,
//! @brief Cpu supports FXSAVE and FXRSTOR instructions.
CPU_FEATURE_FXSR = 1U << 8,
//! @brief Cpu supports FXSAVE and FXRSTOR instruction optimizations (FFXSR).
CPU_FEATURE_FFXSR = 1U << 9,
//! @brief Cpu has MMX.
CPU_FEATURE_MMX = 1U << 10,
//! @brief Cpu has extended MMX.
CPU_FEATURE_MMX_EXT = 1U << 11,
//! @brief Cpu has 3dNow!
CPU_FEATURE_3DNOW = 1U << 12,
//! @brief Cpu has enchanced 3dNow!
CPU_FEATURE_3DNOW_EXT = 1U << 13,
//! @brief Cpu has SSE.
CPU_FEATURE_SSE = 1U << 14,
//! @brief Cpu has SSE2.
CPU_FEATURE_SSE2 = 1U << 15,
//! @brief Cpu has SSE3.
CPU_FEATURE_SSE3 = 1U << 16,
//! @brief Cpu has Supplemental SSE3 (SSSE3).
CPU_FEATURE_SSSE3 = 1U << 17,
//! @brief Cpu has SSE4.A.
CPU_FEATURE_SSE4_A = 1U << 18,
//! @brief Cpu has SSE4.1.
CPU_FEATURE_SSE4_1 = 1U << 19,
//! @brief Cpu has SSE4.2.
CPU_FEATURE_SSE4_2 = 1U << 20,
//! @brief Cpu has AVX.
CPU_FEATURE_AVX = 1U << 22,
//! @brief Cpu has Misaligned SSE (MSSE).
CPU_FEATURE_MSSE = 1U << 23,
//! @brief Cpu supports MONITOR and MWAIT instructions.
CPU_FEATURE_MONITOR_MWAIT = 1U << 24,
//! @brief Cpu supports MOVBE instruction.
CPU_FEATURE_MOVBE = 1U << 25,
//! @brief Cpu supports POPCNT instruction.
CPU_FEATURE_POPCNT = 1U << 26,
//! @brief Cpu supports LZCNT instruction.
CPU_FEATURE_LZCNT = 1U << 27,
//! @brief Cpu supports PCLMULDQ set of instructions.
CPU_FEATURE_PCLMULDQ = 1U << 28,
//! @brief Cpu supports multithreading.
CPU_FEATURE_MULTI_THREADING = 1U << 29,
//! @brief Cpu supports execute disable bit (execute protection).
CPU_FEATURE_EXECUTE_DISABLE_BIT = 1U << 30,
//! @brief 64-bit CPU.
CPU_FEATURE_64_BIT = 1U << 31
};
// ============================================================================
// [AsmJit::CPU_BUG]
// ============================================================================
//! @brief X86/X64 CPU bugs.
enum CPU_BUG
{
//! @brief Whether the processor contains bug seen in some
//! AMD-Opteron processors.
CPU_BUG_AMD_LOCK_MB = 1U << 0
};
// ============================================================================
// [AsmJit::CpuInfo]
// ============================================================================
//! @brief Informations about host cpu.
struct ASMJIT_HIDDEN CpuInfo
{
//! @brief Cpu short vendor string.
char vendor[16];
//! @brief Cpu long vendor string (brand).
char brand[64];
//! @brief Cpu vendor id (see @c AsmJit::CpuInfo::VendorId enum).
uint32_t vendorId;
//! @brief Cpu family ID.
uint32_t family;
//! @brief Cpu model ID.
uint32_t model;
//! @brief Cpu stepping.
uint32_t stepping;
//! @brief Number of processors or cores.
uint32_t numberOfProcessors;
//! @brief Cpu features bitfield, see @c AsmJit::CpuInfo::Feature enum).
uint32_t features;
//! @brief Cpu bugs bitfield, see @c AsmJit::CpuInfo::Bug enum).
uint32_t bugs;
#if defined(ASMJIT_X86) || defined(ASMJIT_X64)
//! @brief Extended information for x86/x64 compatible processors.
struct X86ExtendedInfo
{
//! @brief Processor type.
uint32_t processorType;
//! @brief Brand index.
uint32_t brandIndex;
//! @brief Flush cache line size in bytes.
uint32_t flushCacheLineSize;
//! @brief Maximum number of addressable IDs for logical processors.
uint32_t maxLogicalProcessors;
//! @brief Initial APIC ID.
uint32_t apicPhysicalId;
};
//! @brief Extended information for x86/x64 compatible processors.
X86ExtendedInfo x86ExtendedInfo;
#endif // ASMJIT_X86 || ASMJIT_X64
};
//! @brief Detect CPU features to CpuInfo structure @a i.
//!
//! @sa @c CpuInfo.
ASMJIT_API void detectCpuInfo(CpuInfo* i) ASMJIT_NOTHROW;
//! @brief Return CpuInfo (detection is done only once).
//!
//! @sa @c CpuInfo.
ASMJIT_API CpuInfo* getCpuInfo() ASMJIT_NOTHROW;
//! @}
} // AsmJit namespace
// [Api-End]
#include "ApiEnd.h"
// [Guard]
#endif // _ASMJIT_CPUINFO_H
|