x86cpuinfo.h 7.29 KB
Newer Older
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
// [AsmJit]
// Complete x86/x64 JIT and Remote Assembler for C++.
//
// [License]
// Zlib - See LICENSE.md file in the package.

// [Guard]
#ifndef _ASMJIT_X86_X86CPUINFO_H
#define _ASMJIT_X86_X86CPUINFO_H

// [Dependencies - AsmJit]
#include "../base/cpuinfo.h"

// [Api-Begin]
#include "../apibegin.h"

namespace asmjit {

// ============================================================================
// [Forward Declarations]
// ============================================================================

struct X86CpuInfo;

//! \addtogroup asmjit_x86_general
//! \{

// ============================================================================
29
// [asmjit::X86CpuFeature]
30
31
32
// ============================================================================

//! X86 CPU features.
33
34
35
ASMJIT_ENUM(X86CpuFeature) {
  //! Cpu has Not-Execute-Bit.
  kX86CpuFeatureNX = 0,
36
  //! Cpu has multithreading.
37
  kX86CpuFeatureMT,
38
  //! Cpu has RDTSC.
39
  kX86CpuFeatureRDTSC,
40
  //! Cpu has RDTSCP.
41
  kX86CpuFeatureRDTSCP,
42
  //! Cpu has CMOV.
43
  kX86CpuFeatureCMOV,
44
  //! Cpu has CMPXCHG8B.
45
46
47
  kX86CpuFeatureCMPXCHG8B,
  //! Cpu has CMPXCHG16B (X64).
  kX86CpuFeatureCMPXCHG16B,
48
  //! Cpu has CLFUSH.
49
50
51
  kX86CpuFeatureCLFLUSH,
  //! Cpu has CLFUSH (Optimized).
  kX86CpuFeatureCLFLUSHOpt,
52
  //! Cpu has PREFETCH.
53
54
55
  kX86CpuFeaturePREFETCH,
  //! Cpu has PREFETCHWT1.
  kX86CpuFeaturePREFETCHWT1,
56
57
58
  //! Cpu has LAHF/SAHF.
  kX86CpuFeatureLahfSahf,
  //! Cpu has FXSAVE/FXRSTOR.
59
60
61
  kX86CpuFeatureFXSR,
  //! Cpu has FXSAVE/FXRSTOR (Optimized).
  kX86CpuFeatureFXSROpt,
62
  //! Cpu has MMX.
63
  kX86CpuFeatureMMX,
64
  //! Cpu has extended MMX.
65
  kX86CpuFeatureMMX2,
66
  //! Cpu has 3dNow!
67
  kX86CpuFeature3DNOW,
68
  //! Cpu has enchanced 3dNow!
69
  kX86CpuFeature3DNOW2,
70
  //! Cpu has SSE.
71
  kX86CpuFeatureSSE,
72
  //! Cpu has SSE2.
73
  kX86CpuFeatureSSE2,
74
  //! Cpu has SSE3.
75
76
77
  kX86CpuFeatureSSE3,
  //! Cpu has SSSE3.
  kX86CpuFeatureSSSE3,
78
  //! Cpu has SSE4.A.
79
  kX86CpuFeatureSSE4A,
80
  //! Cpu has SSE4.1.
81
  kX86CpuFeatureSSE4_1,
82
  //! Cpu has SSE4.2.
83
  kX86CpuFeatureSSE4_2,
84
  //! Cpu has Misaligned SSE (MSSE).
85
  kX86CpuFeatureMSSE,
86
  //! Cpu has MONITOR and MWAIT.
87
  kX86CpuFeatureMONITOR,
88
  //! Cpu has MOVBE.
89
  kX86CpuFeatureMOVBE,
90
  //! Cpu has POPCNT.
91
  kX86CpuFeaturePOPCNT,
92
  //! Cpu has LZCNT.
93
  kX86CpuFeatureLZCNT,
94
  //! Cpu has AESNI.
95
  kX86CpuFeatureAESNI,
96
  //! Cpu has PCLMULQDQ.
97
  kX86CpuFeaturePCLMULQDQ,
98
  //! Cpu has RDRAND.
99
100
101
102
103
104
105
106
107
  kX86CpuFeatureRDRAND,
  //! Cpu has RDSEED.
  kX86CpuFeatureRDSEED,
  //! Cpu has SHA-1 and SHA-256.
  kX86CpuFeatureSHA,
  //! Cpu has XSAVE support - XSAVE/XRSTOR, XSETBV/XGETBV, and XCR0.
  kX86CpuFeatureXSave,
  //! OS has enabled XSAVE, you can call XGETBV to get value of XCR0.
  kX86CpuFeatureXSaveOS,
108
  //! Cpu has AVX.
109
  kX86CpuFeatureAVX,
110
  //! Cpu has AVX2.
111
  kX86CpuFeatureAVX2,
112
113
114
  //! Cpu has F16C.
  kX86CpuFeatureF16C,
  //! Cpu has FMA3.
115
  kX86CpuFeatureFMA3,
116
  //! Cpu has FMA4.
117
  kX86CpuFeatureFMA4,
118
  //! Cpu has XOP.
119
  kX86CpuFeatureXOP,
120
  //! Cpu has BMI.
121
  kX86CpuFeatureBMI,
122
  //! Cpu has BMI2.
123
  kX86CpuFeatureBMI2,
124
  //! Cpu has HLE.
125
  kX86CpuFeatureHLE,
126
  //! Cpu has RTM.
127
128
129
130
131
  kX86CpuFeatureRTM,
  //! Cpu has ADX.
  kX86CpuFeatureADX,
  //! Cpu has MPX (Memory Protection Extensions).
  kX86CpuFeatureMPX,
132
  //! Cpu has FSGSBASE.
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
  kX86CpuFeatureFSGSBase,
  //! Cpu has optimized REP MOVSB/STOSB.
  kX86CpuFeatureMOVSBSTOSBOpt,

  //! Cpu has AVX-512F (Foundation).
  kX86CpuFeatureAVX512F,
  //! Cpu has AVX-512CD (Conflict Detection).
  kX86CpuFeatureAVX512CD,
  //! Cpu has AVX-512PF (Prefetch Instructions).
  kX86CpuFeatureAVX512PF,
  //! Cpu has AVX-512ER (Exponential and Reciprocal Instructions).
  kX86CpuFeatureAVX512ER,
  //! Cpu has AVX-512DQ (DWord/QWord).
  kX86CpuFeatureAVX512DQ,
  //! Cpu has AVX-512BW (Byte/Word).
  kX86CpuFeatureAVX512BW,
  //! Cpu has AVX VL (Vector Length Excensions).
  kX86CpuFeatureAVX512VL,
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

  //! Count of X86/X64 Cpu features.
  kX86CpuFeatureCount
};

// ============================================================================
// [asmjit::X86CpuId]
// ============================================================================

//! X86/X64 CPUID output.
union X86CpuId {
  //! EAX/EBX/ECX/EDX output.
  uint32_t i[4];

  struct {
    //! EAX output.
    uint32_t eax;
    //! EBX output.
    uint32_t ebx;
    //! ECX output.
    uint32_t ecx;
    //! EDX output.
    uint32_t edx;
  };
};

// ============================================================================
// [asmjit::X86CpuUtil]
// ============================================================================

181
#if defined(ASMJIT_ARCH_X86) || defined(ASMJIT_ARCH_X64)
182
183
//! CPU utilities available only if the host processor is X86/X64.
struct X86CpuUtil {
184
185
186
187
188
189
  //! \internal
  //!
  //! Designed to support VS2008 and less in 64-bit mode, even if this compiler
  //! doesn't have `__cpuidex` intrinsic.
  ASMJIT_API static void _docpuid(uint32_t inEcx, uint32_t inEax, X86CpuId* out);

190
  //! Get the result of calling CPUID instruction to `out`.
191
192
193
  static ASMJIT_INLINE void callCpuId(X86CpuId* out, uint32_t inEax, uint32_t inEcx = 0) {
    return _docpuid(inEcx, inEax, out);
  }
194
195
196
197

  //! Detect the Host CPU.
  ASMJIT_API static void detect(X86CpuInfo* cpuInfo);
};
198
#endif // ASMJIT_ARCH_X86 || ASMJIT_ARCH_X64
199
200
201
202
203
204
205
206
207
208
209
210

// ============================================================================
// [asmjit::X86CpuInfo]
// ============================================================================

struct X86CpuInfo : public CpuInfo {
  ASMJIT_NO_COPY(X86CpuInfo)

  // --------------------------------------------------------------------------
  // [Construction / Destruction]
  // --------------------------------------------------------------------------

211
  ASMJIT_INLINE X86CpuInfo();
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

  // --------------------------------------------------------------------------
  // [Accessors]
  // --------------------------------------------------------------------------

  //! Get processor type.
  ASMJIT_INLINE uint32_t getProcessorType() const {
    return _processorType;
  }

  //! Get brand index.
  ASMJIT_INLINE uint32_t getBrandIndex() const {
    return _brandIndex;
  }

  //! Get flush cache line size.
  ASMJIT_INLINE uint32_t getFlushCacheLineSize() const {
    return _flushCacheLineSize;
  }

  //! Get maximum logical processors count.
  ASMJIT_INLINE uint32_t getMaxLogicalProcessors() const {
    return _maxLogicalProcessors;
  }

  // --------------------------------------------------------------------------
  // [Statics]
  // --------------------------------------------------------------------------

241
#if defined(ASMJIT_ARCH_X86) || defined(ASMJIT_ARCH_X64)
242
243
244
245
  //! Get global instance of `X86CpuInfo`.
  static ASMJIT_INLINE const X86CpuInfo* getHost() {
    return static_cast<const X86CpuInfo*>(CpuInfo::getHost());
  }
246
#endif // ASMJIT_ARCH_X86 || ASMJIT_ARCH_X64
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261

  // --------------------------------------------------------------------------
  // [Members]
  // --------------------------------------------------------------------------

  //! Processor type.
  uint32_t _processorType;
  //! Brand index.
  uint32_t _brandIndex;
  //! Flush cache line size in bytes.
  uint32_t _flushCacheLineSize;
  //! Maximum number of addressable IDs for logical processors.
  uint32_t _maxLogicalProcessors;
};

262
263
264
ASMJIT_INLINE X86CpuInfo::X86CpuInfo() :
  CpuInfo(sizeof(X86CpuInfo)) {}

265
266
267
268
269
270
271
272
273
//! \}

} // asmjit namespace

// [Api-End]
#include "../apiend.h"

// [Guard]
#endif // _ASMJIT_X86_X86CPUINFO_H