-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proposal: x/sys/cpu: expose runtime AMD64 microarchitecture level #58015
Comments
Worth noting that this information is already available as a build tag, like Also, would this be a constant or a variable? I imagine a constant would be better, given that it's known at build time. |
@mvdan If I understand correctly the value is not known at build time. At build time we know the minimum supported microarchitecture level, from the |
Ah, this api would actually fetch the level of the machine running the program, which might well be higher than the one the binary was built for. I see the distinction now. |
I think generally its better to directly spell out the specific features that should gate an optimized code path at runtime instead of using microachitectural level. That way optimized code might be triggered more often as it is not conditional on the support of some instructions it doesnt use. e.g. LZCNT, BMI can be available without AVX2 support. example code used with internal/cpu: go/src/crypto/sha1/sha1block_amd64.go Line 15 in 0cd309e
|
A use case for this is selecting one among multiple binaries compiled for different GOAMD64 values. I currently use klauspost/cpuid for this exact purpose in https://github.com/CAFxX/mgo. |
In package
golang.org/x/sys/cpu
add anint
symbol [0-4] (0 if not AMD64) that exposes the AMD64 microarchitecture level of the machine running the program.References:
github.com/klauspost/cpuid/v2 CPUInfo.X64Level
The text was updated successfully, but these errors were encountered: