Skip to content

Commit cf2ded4

Browse files
authored
Merge pull request #30 from mcastelino/topic/vmx
Add VMX detection
2 parents 05a8198 + 6357cd9 commit cf2ded4

3 files changed

Lines changed: 21 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ Package home: https://github.com/klauspost/cpuid
6464
* **RDTSCP** (RDTSCP Instruction)
6565
* **CX16** (CMPXCHG16B Instruction)
6666
* **SGX** (Software Guard Extensions, with activation details)
67+
* **VMX** (Virtual Machine Extensions)
6768

6869
## Performance
6970
* **RDTSCP()** Returns current cycle count. Can be used for benchmarking.

cpuid.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ const (
8080
SGX // Software Guard Extensions
8181
IBPB // Indirect Branch Restricted Speculation (IBRS) and Indirect Branch Predictor Barrier (IBPB)
8282
STIBP // Single Thread Indirect Branch Predictors
83+
VMX // Virtual Machine Extensions
8384

8485
// Performance indicators
8586
SSE2SLOW // SSE2 is supported, but usually not faster
@@ -137,6 +138,7 @@ var flagNames = map[Flags]string{
137138
SGX: "SGX", // Software Guard Extensions
138139
IBPB: "IBPB", // Indirect Branch Restricted Speculation and Indirect Branch Predictor Barrier
139140
STIBP: "STIBP", // Single Thread Indirect Branch Predictors
141+
VMX: "VMX", // Virtual Machine Extensions
140142

141143
// Performance indicators
142144
SSE2SLOW: "SSE2SLOW", // SSE2 supported, but usually not faster
@@ -223,6 +225,11 @@ func (c CPUInfo) Amd3dnowExt() bool {
223225
return c.Features&AMD3DNOWEXT != 0
224226
}
225227

228+
// VMX indicates support of VMX
229+
func (c CPUInfo) VMX() bool {
230+
return c.Features&VMX != 0
231+
}
232+
226233
// MMX indicates support of MMX instructions
227234
func (c CPUInfo) MMX() bool {
228235
return c.Features&MMX != 0
@@ -820,6 +827,9 @@ func support() Flags {
820827
if (c & 1) != 0 {
821828
rval |= SSE3
822829
}
830+
if (c & (1 << 5)) != 0 {
831+
rval |= VMX
832+
}
823833
if (c & 0x00000200) != 0 {
824834
rval |= SSSE3
825835
}

cpuid_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,16 @@ func TestAmd3dnowExt(t *testing.T) {
114114
t.Log("AMD3DNOWEXT Support:", got)
115115
}
116116

117+
// TestVMX tests VMX() function
118+
func TestVMX(t *testing.T) {
119+
got := CPU.VMX()
120+
expected := CPU.Features&VMX == VMX
121+
if got != expected {
122+
t.Fatalf("VMX: expected %v, got %v", expected, got)
123+
}
124+
t.Log("VMX Support:", got)
125+
}
126+
117127
// TestMMX tests MMX() function
118128
func TestMMX(t *testing.T) {
119129
got := CPU.MMX()

0 commit comments

Comments
 (0)