1 Android NDK CPU Features detection library:
2 -------------------------------------------
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
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.
16 * add 'cpufeatures' to your APP_MODULES list in your Application.mk
18 * include 'sources/cpufeatures/Android.mk' at the start or end of your
21 * add 'sources/cpufeatures' to your LOCAL_C_INCLUDES definition.
23 * add 'cpufeatures' to your LOCAL_STATIC_LIBRARIES definition when building
24 your final shared library.
26 your source code can then #include <cpu-features.h> to compile against it.
28 Here is a simple example:
30 <NDK>/apps/<appname>/Application.mk:
31 APP_PROJECT_PATH := <project-path>
32 APP_MODULES := <your-modules> cpufeatures
34 <project-path>/jni/Android.mk:
35 LOCAL_PATH := $(call my-dir)
38 LOCAL_MODULE := <your-module-name>
39 LOCAL_C_INCLUDES += sources/cpufeatures
40 LOCAL_SRC_FILES := <your-source-files>
41 LOCAL_STATIC_LIBRARIES += cpufeatures
42 include $(BUILD_SHARED_LIBRARY)
44 include sources/cpufeature/Android.mk
50 Two functions are provided for now:
52 AndroidCpuFamily android_getCpuFamily();
54 Returns the target device's CPU Family as an enum. For now, the only
55 supported family is ANDROID_CPU_FAMILY_ARM.
58 uint64_t android_getCpuFeatures();
60 Returns the set of optional features supported by the device's CPU.
61 The result is a set of bit-flags, each corresponding to one CPU
62 Family-specific optional feature.
64 Currently, only the following flags are defined, for the ARM CPU Family:
66 ANDROID_CPU_ARM_FEATURE_ARMv7
67 Indicates that the device's CPU supports the ARMv7-A instruction
68 set as supported by the "armeabi-v7a" abi (see CPU-ARCH-ABIS.TXT).
69 This corresponds to Thumb-2 and VFPv3-D16 instructions.
71 ANDROID_CPU_ARM_FEATURE_VFPv3
72 Indicates that the device's CPU supports the VFPv3 hardware FPU
73 instruction set extension. Due to the definition of 'armeabi-v7a',
74 this will always be the case if ANDROID_CPU_ARM_FEATURE_ARMv7 is
77 Note that this corresponds to the minimum profile VFPv3-D16 that
78 only provides 16 hardware FP registers.
80 ANDROID_CPU_ARM_FEATURE_NEON
81 Indicates that the device's CPU supports the ARM Advanced SIMD
82 (a.k.a. NEON) vector instruction set extension. Note that ARM
83 mandates that such CPUs also implement VFPv3-D32, which provides
84 32 hardware FP registers (shared with the NEON unit).
90 The cpufeatures library will be updated to support more CPU families and
91 optional features in the future. It is designed to work as-is on all
92 official Android platform versions.