Skip to content

Commit

Permalink
Merge pull request #32 from mythi/vnni
Browse files Browse the repository at this point in the history
Add AVX512-VNNI detection
  • Loading branch information
klauspost authored Nov 6, 2019
2 parents cf2ded4 + c9295f4 commit 5a626f7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
10 changes: 10 additions & 0 deletions cpuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const (
AVX512BW // AVX-512 Byte and Word Instructions
AVX512VL // AVX-512 Vector Length Extensions
AVX512VBMI // AVX-512 Vector Bit Manipulation Instructions
AVX512VNNI // AVX-512 Vector Neural Network Instructions
MPX // Intel MPX (Memory Protection Extensions)
ERMS // Enhanced REP MOVSB/STOSB
RDTSCP // RDTSCP Instruction
Expand Down Expand Up @@ -131,6 +132,7 @@ var flagNames = map[Flags]string{
AVX512BW: "AVX512BW", // AVX-512 Byte and Word Instructions
AVX512VL: "AVX512VL", // AVX-512 Vector Length Extensions
AVX512VBMI: "AVX512VBMI", // AVX-512 Vector Bit Manipulation Instructions
AVX512VNNI: "AVX512VNNI", // AVX-512 Vector Neural Network Instructions
MPX: "MPX", // Intel MPX (Memory Protection Extensions)
ERMS: "ERMS", // Enhanced REP MOVSB/STOSB
RDTSCP: "RDTSCP", // RDTSCP Instruction
Expand Down Expand Up @@ -440,6 +442,11 @@ func (c CPUInfo) AVX512VBMI() bool {
return c.Features&AVX512VBMI != 0
}

// AVX512VNNI indicates support of AVX-512 Vector Neural Network Instructions
func (c CPUInfo) AVX512VNNI() bool {
return c.Features&AVX512VNNI != 0
}

// MPX indicates support of Intel MPX (Memory Protection Extensions)
func (c CPUInfo) MPX() bool {
return c.Features&MPX != 0
Expand Down Expand Up @@ -955,6 +962,9 @@ func support() Flags {
if ecx&(1<<1) != 0 {
rval |= AVX512VBMI
}
if ecx&(1<<11) != 0 {
rval |= AVX512VNNI
}
}
}
}
Expand Down
12 changes: 11 additions & 1 deletion cpuid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ func TestAVX512VL(t *testing.T) {
t.Log("AVX512VL Support:", got)
}

// TestAVX512VL tests AVX512VBMI() function (AVX-512 Vector Bit Manipulation Instructions)
// TestAVX512VBMI tests AVX512VBMI() function (AVX-512 Vector Bit Manipulation Instructions)
func TestAVX512VBMI(t *testing.T) {
got := CPU.AVX512VBMI()
expected := CPU.Features&AVX512VBMI == AVX512VBMI
Expand All @@ -564,6 +564,16 @@ func TestAVX512VBMI(t *testing.T) {
t.Log("AVX512VBMI Support:", got)
}

// TestAVX512VNNI tests AVX512VNNI() function (AVX-512 Vector Neural Network Instructions)
func TestAVX512VNNI(t *testing.T) {
got := CPU.AVX512VNNI()
expected := CPU.Features&AVX512VNNI == AVX512VNNI
if got != expected {
t.Fatalf("AVX512VNNI: expected %v, got %v", expected, got)
}
t.Log("AVX512VNNI Support:", got)
}

// TestMPX tests MPX() function (Intel MPX (Memory Protection Extensions))
func TestMPX(t *testing.T) {
got := CPU.MPX()
Expand Down

0 comments on commit 5a626f7

Please sign in to comment.