Skip to content

Commit

Permalink
Merge pull request #30 from mcastelino/topic/vmx
Browse files Browse the repository at this point in the history
Add VMX detection
  • Loading branch information
klauspost authored Jul 13, 2019
2 parents 05a8198 + 6357cd9 commit cf2ded4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Package home: https://github.com/klauspost/cpuid
* **RDTSCP** (RDTSCP Instruction)
* **CX16** (CMPXCHG16B Instruction)
* **SGX** (Software Guard Extensions, with activation details)
* **VMX** (Virtual Machine Extensions)

## Performance
* **RDTSCP()** Returns current cycle count. Can be used for benchmarking.
Expand Down
10 changes: 10 additions & 0 deletions cpuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ const (
SGX // Software Guard Extensions
IBPB // Indirect Branch Restricted Speculation (IBRS) and Indirect Branch Predictor Barrier (IBPB)
STIBP // Single Thread Indirect Branch Predictors
VMX // Virtual Machine Extensions

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

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

// VMX indicates support of VMX
func (c CPUInfo) VMX() bool {
return c.Features&VMX != 0
}

// MMX indicates support of MMX instructions
func (c CPUInfo) MMX() bool {
return c.Features&MMX != 0
Expand Down Expand Up @@ -820,6 +827,9 @@ func support() Flags {
if (c & 1) != 0 {
rval |= SSE3
}
if (c & (1 << 5)) != 0 {
rval |= VMX
}
if (c & 0x00000200) != 0 {
rval |= SSSE3
}
Expand Down
10 changes: 10 additions & 0 deletions cpuid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@ func TestAmd3dnowExt(t *testing.T) {
t.Log("AMD3DNOWEXT Support:", got)
}

// TestVMX tests VMX() function
func TestVMX(t *testing.T) {
got := CPU.VMX()
expected := CPU.Features&VMX == VMX
if got != expected {
t.Fatalf("VMX: expected %v, got %v", expected, got)
}
t.Log("VMX Support:", got)
}

// TestMMX tests MMX() function
func TestMMX(t *testing.T) {
got := CPU.MMX()
Expand Down

0 comments on commit cf2ded4

Please sign in to comment.