Skip to content

Commit 30e4506

Browse files
authored
Add IBPB, STIBP detection (#20)
* Add IBPB, STIBP detection * Bump test versions
1 parent ae832f2 commit 30e4506

4 files changed

Lines changed: 23 additions & 5 deletions

File tree

.travis.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ os:
66
- linux
77
- osx
88
go:
9-
- 1.6.x
10-
- 1.7.x
119
- 1.8.x
1210
- 1.9.x
11+
- 1.10.x
1312
- master
1413

1514
script:
@@ -21,5 +20,4 @@ script:
2120
matrix:
2221
allow_failures:
2322
- go: 'master'
24-
- go: '1.6.x'
2523
fast_finish: true

cpuid.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ const (
7676
RDTSCP // RDTSCP Instruction
7777
CX16 // CMPXCHG16B Instruction
7878
SGX // Software Guard Extensions
79+
IBPB // Indirect Branch Restricted Speculation (IBRS) and Indirect Branch Predictor Barrier (IBPB)
80+
STIBP // Single Thread Indirect Branch Predictors
7981

8082
// Performance indicators
8183
SSE2SLOW // SSE2 is supported, but usually not faster
@@ -131,6 +133,8 @@ var flagNames = map[Flags]string{
131133
RDTSCP: "RDTSCP", // RDTSCP Instruction
132134
CX16: "CX16", // CMPXCHG16B Instruction
133135
SGX: "SGX", // Software Guard Extensions
136+
IBPB: "IBPB", // Indirect Branch Restricted Speculation and Indirect Branch Predictor Barrier
137+
STIBP: "STIBP", // Single Thread Indirect Branch Predictors
134138

135139
// Performance indicators
136140
SSE2SLOW: "SSE2SLOW", // SSE2 supported, but usually not faster
@@ -854,7 +858,7 @@ func support() Flags {
854858

855859
// Check AVX2, AVX2 requires OS support, but BMI1/2 don't.
856860
if mfi >= 7 {
857-
_, ebx, ecx, _ := cpuidex(7, 0)
861+
_, ebx, ecx, edx := cpuidex(7, 0)
858862
if (rval&AVX) != 0 && (ebx&0x00000020) != 0 {
859863
rval |= AVX2
860864
}
@@ -888,6 +892,12 @@ func support() Flags {
888892
if ebx&(1<<29) != 0 {
889893
rval |= SHA
890894
}
895+
if edx&(1<<26) != 0 {
896+
rval |= IBPB
897+
}
898+
if edx&(1<<27) != 0 {
899+
rval |= STIBP
900+
}
891901

892902
// Only detect AVX-512 features if XGETBV is supported
893903
if c&((1<<26)|(1<<27)) == (1<<26)|(1<<27) {

private/cpuid.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ const (
7070
rdtscp // RDTSCP Instruction
7171
cx16 // CMPXCHG16B Instruction
7272
sgx // Software Guard Extensions
73+
ibpb // Indirect Branch Restricted Speculation (IBRS) and Indirect Branch Predictor Barrier (IBPB)
74+
stibp // Single Thread Indirect Branch Predictors
7375

7476
// Performance indicators
7577
sse2slow // SSE2 is supported, but usually not faster
@@ -125,6 +127,8 @@ var flagNames = map[flags]string{
125127
rdtscp: "RDTSCP", // RDTSCP Instruction
126128
cx16: "CX16", // CMPXCHG16B Instruction
127129
sgx: "SGX", // Software Guard Extensions
130+
ibpb: "IBPB", // Indirect Branch Restricted Speculation and Indirect Branch Predictor Barrier
131+
stibp: "STIBP", // Single Thread Indirect Branch Predictors
128132

129133
// Performance indicators
130134
sse2slow: "SSE2SLOW", // SSE2 supported, but usually not faster
@@ -848,7 +852,7 @@ func support() flags {
848852

849853
// Check AVX2, AVX2 requires OS support, but BMI1/2 don't.
850854
if mfi >= 7 {
851-
_, ebx, ecx, _ := cpuidex(7, 0)
855+
_, ebx, ecx, edx := cpuidex(7, 0)
852856
if (rval&avx) != 0 && (ebx&0x00000020) != 0 {
853857
rval |= avx2
854858
}
@@ -882,6 +886,12 @@ func support() flags {
882886
if ebx&(1<<29) != 0 {
883887
rval |= sha
884888
}
889+
if edx&(1<<26) != 0 {
890+
rval |= ibpb
891+
}
892+
if edx&(1<<27) != 0 {
893+
rval |= stibp
894+
}
885895

886896
// Only detect AVX-512 features if XGETBV is supported
887897
if c&((1<<26)|(1<<27)) == (1<<26)|(1<<27) {

testdata/cpuid_data.zip

-124 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)