-
Notifications
You must be signed in to change notification settings - Fork 130
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
cpufeatures: ARM support #378
Comments
Unfortunately, it's not possible to do properly without RFC 2725. AFAIK ARM does not have a dedicated CPUID-like (BTW RISC-V is similar in this regard, while it has a CPUID-like instruction, it requires privileged mode), on come CPUs it's possible to detect capabilities by reading system registers, but I am not sure about portability of such solution. Currently, the best solution is to rely on a platform-dependent feature detection as we do in |
Curious about this |
See the top answer here. |
These seem potentially relevant:
|
Can you check if it works in user space on your M1 Mac? Later I can check your snippet on a RPi4 board. |
Sure, I can give it a try |
It seems those registers are not accessible from userspace at all 😢 However, now I realize that we can pretty safely assume that Not sure what to do on Linux. Seems we may need to use something like |
It looks like if we were to use the libc crate (or potentially emit our own system call instruction), we could use https://www.kernel.org/doc/html/latest/arm64/elf_hwcaps.html Namely:
|
Yes, it's what I meant by "platform-dependent feature detection" and it's exactly that we currently do in |
Aha! Neat! What do you think about moving that functionality into this crate, and having an abstraction that works across both Linux and macOS? |
I think On ARM and non-supported OSes/enviroments we probably should simply fall back to the compile-time target feature detection. |
Here's a guide: They suggest using It looks like the feature detection flags reside in the
Somewhat curiously AES, SHA-1, and SHA-256 aren't listed on my Mac Mini M1. Edit: here is the Golang-related discussion about this particular issue. This comment in particular suggests it is and will always be safe to assume There's also a followup comment by David Benjamin from the BoringSSL team saying they do the same thing and offers this rationale:
|
FWIW I just registered the |
In this case I think Rust should enable the relevant target features itself for these targets, similarly to how SSE2 is enabled by default for |
It should, and in that case ideally the feature detection macro will optimize away. However, ideally I think we shouldn't need to gate CPU feature detection on OS, and the OS specifics should be handled in this crate. That means on MacOS there will need to be a set of "armcaps" that are always available, and others that need to be queried via |
Yes and it's exactly the purpose of RFC 2725.
No, ideally it should be handled either by |
Well sure, this crate is a stopgap. But it doesn't seem like there has been a whole lot of progress on RFC 2725? In the meantime it seems like we should be working on something with a similar API shape at least. |
All Apple ARM64 hardware has the same baseline set of statically known capabilities which can be assumed on all iOS (and macOS) platforms. This commit adds support for those statically known capabilities on iOS. Unfortunately it does not appear to be possible to access the `sysctl(3)` namespace on iOS in order to determine the availability of other CPU features which aren't part of this baseline set the same way we can on macOS, so a static capability set is the best we can do. See this issue for more information: #378
All Apple ARM64 hardware has the same baseline set of statically known capabilities which can be assumed on all iOS (and macOS) platforms. This commit adds support for those statically known capabilities on iOS. Unfortunately it does not appear to be possible to access the `sysctl(3)` namespace on iOS in order to determine the availability of other CPU features which aren't part of this baseline set the same way we can on macOS, so a static capability set is the best we can do. See this issue for more information: #378
It would be nice to be able to do ARM feature detection.
A notable use case would be detecting the ARMv8 Cryptography Extensions.
The text was updated successfully, but these errors were encountered: