问题
How to determine whether NEON engine exists on given ARM processor? Any status/flag register can be queried for such purpose?
回答1:
I believe unixsmurf's answer is about as good as you'll get if using an OS with privileged kernel. For general purpose feature detection, it seems ARM has made it a requirement to get this from the OS, and so you must use an OS API to get it.
- On Android NDK use
#include <cpu-features.h>
with(android_getCpuFamily() == ANDROID_CPU_FAMILY_ARM) && (android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON)
. Note this is for 32 bit ARM. ARM 64 bit has different flags but the idea is the same. See the sources/docs. - On Linux, if available use
#include <sys/auxv.h>
and#include <asm/hwcap.h>
withgetauxval(AT_HWCAP) & HWCAP_NEON
. - On iOS, I'm not sure there is a dynamic call, the methodology seems to be that you build your app targeting NEON, then make sure your app is flagged to require NEON so it will only install on devices which support it. Of course you should use the pre-defined preprocessor flag
__ARM_NEON__
to make sure everything is in order at compile time. - On whatever Microsoft does or if you are using some other RTOS... I don't know...
Actually you'll see a lot of Android implementations which just parse /proc/cpuinfo in order to implement android_getCpuFeatures().... Heh. But still it seems to be getting improved and newest versions use the getauxval method.
回答2:
One reliable way is to check the architectural feature trap register. For example, on ARM Cortex A35, you can check the value of HCPTR register to see whether NEON is implemented (0x000033FF), or not (0x0000BFFF). The register name and indication value are platform dependent, making sure to check the technical reference manual.
来源:https://stackoverflow.com/questions/26701262/how-to-check-the-existence-of-neon-on-arm