1 Android NDK CPU Features detection library: 2 ------------------------------------------- 3 4 This NDK provides a small library named "cpufeatures" that can be used at 5 runtime to detect the target device's CPU family and the optional features 6 it supports. 7 8 Usage: 9 ------ 10 11 The library is available from sources/cpufeatures. It provides an Android.mk 12 build script that can be used to build it as a static library. 13 14 To use it, you must: 15 16 * include '$(NDK_ROOT)/sources/cpufeatures/Android.mk' at the start or end of your 17 Android.mk file. 18 19 * add '$(NDK_ROOT)/sources/cpufeatures' to your LOCAL_C_INCLUDES definition. 20 21 * add 'cpufeatures' to your LOCAL_STATIC_LIBRARIES definition when building 22 your final shared library. 23 24 your source code can then #include <cpu-features.h> to compile against it. 25 26 Here is a simple example: 27 28 <project-path>/jni/Android.mk: 29 LOCAL_PATH := $(call my-dir) 30 31 include $(CLEAR_VARS) 32 LOCAL_MODULE := <your-module-name> 33 LOCAL_C_INCLUDES += $(NDK_ROOT)/sources/cpufeatures 34 LOCAL_SRC_FILES := <your-source-files> 35 LOCAL_STATIC_LIBRARIES += cpufeatures 36 include $(BUILD_SHARED_LIBRARY) 37 38 include $(NDK_ROOT)/sources/cpufeature/Android.mk 39 40 41 Features: 42 --------- 43 44 Two functions are provided for now: 45 46 AndroidCpuFamily android_getCpuFamily(); 47 48 Returns the target device's CPU Family as an enum. For now, the only 49 supported family is ANDROID_CPU_FAMILY_ARM. 50 51 52 uint64_t android_getCpuFeatures(); 53 54 Returns the set of optional features supported by the device's CPU. 55 The result is a set of bit-flags, each corresponding to one CPU 56 Family-specific optional feature. 57 58 Currently, only the following flags are defined, for the ARM CPU Family: 59 60 ANDROID_CPU_ARM_FEATURE_ARMv7 61 Indicates that the device's CPU supports the ARMv7-A instruction 62 set as supported by the "armeabi-v7a" abi (see CPU-ARCH-ABIS.TXT). 63 This corresponds to Thumb-2 and VFPv3-D16 instructions. 64 65 ANDROID_CPU_ARM_FEATURE_VFPv3 66 Indicates that the device's CPU supports the VFPv3 hardware FPU 67 instruction set extension. Due to the definition of 'armeabi-v7a', 68 this will always be the case if ANDROID_CPU_ARM_FEATURE_ARMv7 is 69 returned. 70 71 Note that this corresponds to the minimum profile VFPv3-D16 that 72 _only_ provides 16 hardware FP registers. 73 74 ANDROID_CPU_ARM_FEATURE_NEON 75 Indicates that the device's CPU supports the ARM Advanced SIMD 76 (a.k.a. NEON) vector instruction set extension. Note that ARM 77 mandates that such CPUs also implement VFPv3-D32, which provides 78 32 hardware FP registers (shared with the NEON unit). 79 80 81 Important Note: 82 --------------- 83 84 The cpufeatures library will be updated to support more CPU families and 85 optional features in the future. It is designed to work as-is on all 86 official Android platform versions. 87