Home | History | Annotate | Download | only in docs
      1 <html><body><pre>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 as an import module. To use it, you must:
     12 
     13 To use it, you must:
     14 
     15   * List 'cpufeatures' in your list of static library dependencies, as in:
     16 
     17         LOCAL_STATIC_LIBRARIES := cpufeatures
     18 
     19   * At the end of your Android.mk, import the 'android/cpufeatures' module,
     20     as in:
     21 
     22         $(call import-module,android/cpufeatures)
     23 
     24   * In your source code, include the header named &lt;cpu-features.h&gt;
     25 
     26 
     27 Here is a simple example:
     28 
     29 &lt;project-path&gt;/jni/Android.mk:
     30     LOCAL_PATH := $(call my-dir)
     31 
     32     include $(CLEAR_VARS)
     33     LOCAL_MODULE := &lt;your-module-name&gt;
     34     LOCAL_SRC_FILES := &lt;your-source-files&gt;
     35     LOCAL_STATIC_LIBRARIES := cpufeatures
     36     include $(BUILD_SHARED_LIBRARY)
     37 
     38     $(call import-module,android/cpufeatures)
     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_VFPv2
     61       Indicates that the device's CPU supports VFPv2 instruction set.
     62       Most ARMv6 CPUs support these.
     63 
     64    ANDROID_CPU_ARM_FEATURE_ARMv7
     65       Indicates that the device's CPU supports the ARMv7-A instruction
     66       set as supported by the "armeabi-v7a" abi (see CPU-ARCH-ABIS.html).
     67       This corresponds to Thumb-2 and VFPv3-D16 instructions.
     68 
     69    ANDROID_CPU_ARM_FEATURE_VFPv3
     70       Indicates that the device's CPU supports the VFPv3 hardware FPU
     71       instruction set extension. Due to the definition of 'armeabi-v7a',
     72       this will always be the case if ANDROID_CPU_ARM_FEATURE_ARMv7 is
     73       returned.
     74 
     75       Note that this corresponds to the minimum profile VFPv3-D16 that
     76       _only_ provides 16 hardware double-precision FP registers.
     77 
     78    ANDROID_CPU_ARM_FEATURE_VFP_D32
     79       Indicates that the device's CPU supports 32 hardware double-precision
     80       FP registers instead of 16.  Note that there are still only 32 single-
     81       precision registers mapped to the same register banks.
     82 
     83    ANDROID_CPU_ARM_FEATURE_NEON
     84       Indicates that the device's CPU supports the ARM Advanced SIMD
     85       (a.k.a. NEON) vector instruction set extension. Note that ARM
     86       mandates that such CPUs also implement VFPv3-D32, which provides
     87       32 hardware FP registers (shared with the NEON unit).
     88 
     89    ANDROID_CPU_ARM_FEATURE_VFP_FP16
     90       Indicates that the device's CPU supports instructions to perform
     91       floating-point operations on 16-bit registers. This is part of the
     92       VFPv4 specification.
     93 
     94    ANDROID_CPU_ARM_FEATURE_VFP_FMA
     95       Indicates that the device's CPU supports fused multiply-accumulate
     96       VFP instructions extension. Also part of the VFPv4 specification.
     97 
     98    ANDROID_CPU_ARM_FEATURE_NEON_FMA
     99       Indicates that the device's CPU supports fused multiply-accumulate
    100       NEON instructions extension.  Also part of the VFPv4 specification.
    101 
    102    ANDROID_CPU_ARM_FEATURE_IDIV_ARM
    103       Indicates that the device's CPU supports Integer division in ARM mode.
    104       Only available on recent CPUs (e.g. Cortex-A15).
    105 
    106    ANDROID_CPU_ARM_FEATURE_IDIV_THUMB2
    107       Indicates that the device's CPU supports Integer division in Thumb-2
    108       mode.  Only available on recent CPUs (e.g. Cortex-A15).
    109 
    110    ANDROID_CPU_ARM_FEATURE_iWMMXt
    111       Indicates that the device's CPU supports extension that adds MMX
    112       registers and instructions.  This is only available on a few XScale-
    113       based CPU.
    114 
    115    ANDROID_CPU_ARM_FEATURE_LDREX_STREX
    116       Indicates that the device's CPU supports LDREX and STREX instructions
    117       available since ARMv6.  Together they provide atomic update on memory
    118       with the help of exclusive monitor.
    119 
    120 And the following flags for the x86 CPU Family:
    121 
    122     ANDROID_CPU_X86_FEATURE_SSSE3
    123       Indicates that the device's CPU supports the SSSE3 instruction
    124       extension set. Note that this is unlike SSE3 which is required
    125       by the x86 NDK ABI.
    126 
    127     ANDROID_CPU_X86_FEATURE_POPCNT
    128       Indicates that the device's CPU supports the POPCNT instruction.
    129 
    130     ANDROID_CPU_X86_FEATURE_MOVBE
    131       Indicates that the device's CPU supports the MOVBE instruction.
    132       This one is specific to some Intel IA-32 CPUs, like the Atom.
    133 
    134 
    135 The following function is also defined to return the max number of
    136 CPU cores on the target device:
    137 
    138     int  android_getCpuCount(void);
    139 
    140 
    141 Important Note:
    142 ---------------
    143 
    144 The cpufeatures library will be updated to support more CPU families and
    145 optional features in the future. It is designed to work as-is on all
    146 official Android platform versions.
    147 
    148 
    149 Change History:
    150 ---------------
    151 
    152 Please see the comments in $NDK/sources/android/cpufeatures/cpu-features.c
    153 for the complete change history for this library.
    154 </pre></body></html>