Skip to content

Commit

Permalink
Add cpu.features flag (#68)
Browse files Browse the repository at this point in the history
* Add cpu.features flag

Will display features and exit.
  • Loading branch information
klauspost authored Dec 18, 2020
1 parent e6213a4 commit d1038c4
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cpuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ package cpuid

import (
"flag"
"fmt"
"math"
"os"
"strings"
)

Expand Down Expand Up @@ -238,6 +240,11 @@ func Detect() {
safe = !*detectArmFlag
}
addInfo(&CPU, safe)
if displayFeats != nil && *displayFeats {
fmt.Println("cpu features:", strings.Join(CPU.FeatureSet(), ","))
// Exit with non-zero so tests will print value.
os.Exit(1)
}
if disableFlag != nil {
s := strings.Split(*disableFlag, ",")
for _, feat := range s {
Expand All @@ -259,6 +266,7 @@ func DetectARM() {
}

var detectArmFlag *bool
var displayFeats *bool
var disableFlag *string

// Flags will enable flags.
Expand All @@ -268,6 +276,7 @@ var disableFlag *string
// will not contain these flags.
func Flags() {
disableFlag = flag.String("cpu.disable", "", "disable cpu features; comma separated list")
displayFeats = flag.Bool("cpu.features", false, "lists cpu features and exits")
detectArmFlag = flag.Bool("cpu.arm", false, "allow ARM features to be detected; can potentially crash")
}

Expand Down

0 comments on commit d1038c4

Please sign in to comment.