-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Description
We have a lot of packages in the std that uses specialized instructions
that are not always present. Most of the times, the package will detect
the required features by themselves. This is fine but will lead to code
duplication. And as Bryan Chan mentioned on https://golang.org/cl/22201,
even if the processor provides way to detect certain optional features,
it's still better to use AT_HWCAP from Linux auxv because that also
takes kernel support into account.
Only the runtime can access auxv, so it makes sense for the runtime
to query the processor capabilities and provide that to the packages.
I propose that we add an internal package internal/cpu
that exposes
capability flags for the current processor so that each std packages
could query it directly instead of having a runtime detection routine
that duplicates the work.
Another benefit is that, some processors, like ARM, doesn't provide
a way to do runtime capability detection, so we have to rely on the
kernel to provide this information. Different kernels provide different
mechanisms for this (sysctl for BSD and auxv for linux), so providing
a package that abstracts those OS-dependent feature away is also
beneficial.
We might promote the package to runtime/cpu if deemed fit, but that's
out of the scope for this proposal.
The package could be modeled after the Linux's AT_HWCAP bits,
and it will be processor dependent.