x86cpuinfo.h 6.07 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
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
// [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
//! \{

// ============================================================================
// [asmjit::kX86CpuFeature]
// ============================================================================

//! X86 CPU features.
ASMJIT_ENUM(kX86CpuFeature) {
  //! Cpu has multithreading.
  kX86CpuFeatureMultithreading = 1,
  //! Cpu has execute disable bit.
  kX86CpuFeatureExecuteDisableBit,
  //! Cpu has RDTSC.
  kX86CpuFeatureRdtsc,
  //! Cpu has RDTSCP.
  kX86CpuFeatureRdtscp,
  //! Cpu has CMOV.
  kX86CpuFeatureCmov,
  //! Cpu has CMPXCHG8B.
  kX86CpuFeatureCmpXchg8B,
  //! Cpu has CMPXCHG16B (x64).
  kX86CpuFeatureCmpXchg16B,
  //! Cpu has CLFUSH.
  kX86CpuFeatureClflush,
  //! Cpu has PREFETCH.
  kX86CpuFeaturePrefetch,
  //! Cpu has LAHF/SAHF.
  kX86CpuFeatureLahfSahf,
  //! Cpu has FXSAVE/FXRSTOR.
  kX86CpuFeatureFxsr,
  //! Cpu has FXSAVE/FXRSTOR optimizations.
  kX86CpuFeatureFfxsr,
  //! Cpu has MMX.
  kX86CpuFeatureMmx,
  //! Cpu has extended MMX.
  kX86CpuFeatureMmxExt,
  //! Cpu has 3dNow!
  kX86CpuFeature3dNow,
  //! Cpu has enchanced 3dNow!
  kX86CpuFeature3dNowExt,
  //! Cpu has SSE.
  kX86CpuFeatureSse,
  //! Cpu has SSE2.
  kX86CpuFeatureSse2,
  //! Cpu has SSE3.
  kX86CpuFeatureSse3,
  //! Cpu has Supplemental SSE3 (SSSE3).
  kX86CpuFeatureSsse3,
  //! Cpu has SSE4.A.
  kX86CpuFeatureSse4A,
  //! Cpu has SSE4.1.
  kX86CpuFeatureSse41,
  //! Cpu has SSE4.2.
  kX86CpuFeatureSse42,
  //! Cpu has Misaligned SSE (MSSE).
  kX86CpuFeatureMsse,
  //! Cpu has MONITOR and MWAIT.
  kX86CpuFeatureMonitorMWait,
  //! Cpu has MOVBE.
  kX86CpuFeatureMovbe,
  //! Cpu has POPCNT.
  kX86CpuFeaturePopcnt,
  //! Cpu has LZCNT.
  kX86CpuFeatureLzcnt,
  //! Cpu has AESNI.
  kX86CpuFeatureAesni,
  //! Cpu has PCLMULQDQ.
  kX86CpuFeaturePclmulqdq,
  //! Cpu has RDRAND.
  kX86CpuFeatureRdrand,
  //! Cpu has AVX.
  kX86CpuFeatureAvx,
  //! Cpu has AVX2.
  kX86CpuFeatureAvx2,
  //! Cpu has F16C.
  kX86CpuFeatureF16C,
  //! Cpu has FMA3.
  kX86CpuFeatureFma3,
  //! Cpu has FMA4.
  kX86CpuFeatureFma4,
  //! Cpu has XOP.
  kX86CpuFeatureXop,
  //! Cpu has BMI.
  kX86CpuFeatureBmi,
  //! Cpu has BMI2.
  kX86CpuFeatureBmi2,
  //! Cpu has HLE.
  kX86CpuFeatureHle,
  //! Cpu has RTM.
  kX86CpuFeatureRtm,
  //! Cpu has FSGSBASE.
  kX86CpuFeatureFsGsBase,
  //! Cpu has enhanced REP MOVSB/STOSB.
  kX86CpuFeatureRepMovsbStosbExt,

  //! 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]
// ============================================================================

#if defined(ASMJIT_HOST_X86) || defined(ASMJIT_HOST_X64)
//! CPU utilities available only if the host processor is X86/X64.
struct X86CpuUtil {
  //! Get the result of calling CPUID instruction to `out`.
  ASMJIT_API static void callCpuId(uint32_t inEax, uint32_t inEcx, X86CpuId* out);

  //! Detect the Host CPU.
  ASMJIT_API static void detect(X86CpuInfo* cpuInfo);
};
#endif // ASMJIT_HOST_X86 || ASMJIT_HOST_X64

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

struct X86CpuInfo : public CpuInfo {
  ASMJIT_NO_COPY(X86CpuInfo)

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

  ASMJIT_INLINE X86CpuInfo(uint32_t size = sizeof(X86CpuInfo)) :
    CpuInfo(size) {}

  // --------------------------------------------------------------------------
  // [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]
  // --------------------------------------------------------------------------

#if defined(ASMJIT_HOST_X86) || defined(ASMJIT_HOST_X64)
  //! Get global instance of `X86CpuInfo`.
  static ASMJIT_INLINE const X86CpuInfo* getHost() {
    return static_cast<const X86CpuInfo*>(CpuInfo::getHost());
  }
#endif // ASMJIT_HOST_X86 || ASMJIT_HOST_X64

  // --------------------------------------------------------------------------
  // [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;
};

//! \}

} // asmjit namespace

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

// [Guard]
#endif // _ASMJIT_X86_X86CPUINFO_H