------
英文文档见android-ndk-r5b的documentation.html
属于Android Native Development Kit (NDK)的一部分
见http://developer.android.com/sdk/ndk/(需要代理)
翻译仅个人见解
-----------------
Android NDK CPU Features detection library:
Android NDK CPU特性检测库:
-------------------------------------------
This NDK provides a small library named "cpufeatures" that can be used at runtime to detect the target device's CPU family and the optional features it supports.
NDK提供一个名为cpufeatures的小型库,它可以用于在运行期检测目标设备的CPU家族和它支持的可选特性。
Usage:
用法:
------
The library is available as an import module. To use it, you must:
这个库作为导入模块可用。要使用它,你必须:
To use it, you must:
要使用它,你必须:
* List 'cpufeatures' in your list of static library dependencies, as in:
* 在你的静态库依赖列表中列出cpufeatures,正如这样:
LOCAL_STATIC_LIBRARIES := cpufeatures
* At the end of your Android.mk, import the 'android/cpufeatures' module, as in:
* 在你的Android.mk结束处,导入android/cpufeatures模块,正如这样:
$(call import-module,android/cpufeatures)
* In your source code, include the header named <cpu-features.h>
* 在你的源代码中,包含名为<cpu-features.h>的头文件
Here is a simple example:
这里是一个简单示例:
<project-path>/jni/Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := <your-module-name>
LOCAL_SRC_FILES := <your-source-files>
LOCAL_STATIC_LIBRARIES := cpufeatures
include $(BUILD_SHARED_LIBRARY)
$(call import-module,android/cpufeatures)
Features:
特性:
---------
Two functions are provided for now:
现在提供两个函数:
AndroidCpuFamily android_getCpuFamily();
Returns the target device's CPU Family as an enum. For now, the only supported family is ANDROID_CPU_FAMILY_ARM.
用一个枚举值返回目标设备的CPU家族。现在,唯一支持的家族是ANDROID_CPU_FAMILY_ARM。
uint64_t android_getCpuFeatures();
Returns the set of optional features supported by the device's CPU. The result is a set of bit-flags, each corresponding to one CPU Family-specific optional feature.
返回设备CPU支持的可选特性。结构是一个位标志集合,每个位标志对应一项CPU家族特定的可选特性。
Currently, only the following flags are defined, for the ARM CPU Family:
目前,只为ARM CPU家族定义了如下标志:
ANDROID_CPU_ARM_FEATURE_ARMv7
Indicates that the device's CPU supports the ARMv7-A instruction set as supported by the "armeabi-v7a" abi (see CPU-ARCH-ABIS.html). This corresponds to Thumb-2 and VFPv3-D16 instructions.
ANDROID_CPU_ARM_FEATURE_ARMv7
指出设备的CPU支持ARMv7-A指令集,它由armeabi-v7a的ABI(注:应用程序二进制接口,操作系统暴露的接口,使二进制程序不需要重新编译即可在兼容ABI的操作系统上运行)支持(参考CPU-ARCH-ABIS.html)。它对应Thumb-2和VFPv3-D16指令。
ANDROID_CPU_ARM_FEATURE_VFPv3
Indicates that the device's CPU supports the VFPv3 hardware FPU instruction set extension. Due to the definition of 'armeabi-v7a', this will always be the case if ANDROID_CPU_ARM_FEATURE_ARMv7 is returned.
ANDROID_CPU_ARM_FEATURE_VFPv3
指出设备CPU支持VFPv3硬件FPU(注:FPU是浮点运算单元的缩写)指令集扩展。由于armeabi-v7a的定义,它将总是返回ANDROID_CPU_ARM_FEATURE_ARMv7(注:这里的意思可能是,它总是和ANDROID_CPU_ARM_FEATURE_ARMv7一起返回)。
Note that this corresponds to the minimum profile VFPv3-D16 that _only_ provides 16 hardware FP registers.
注意它对应最小型号是VFPv3-D16,它只提供16个硬件浮点寄存器。
ANDROID_CPU_ARM_FEATURE_NEON
Indicates that the device's CPU supports the ARM Advanced SIMD (a.k.a. NEON) vector instruction set extension. Note that ARM mandates that such CPUs also implement VFPv3-D32, which provides 32 hardware FP registers (shared with the NEON unit).
ANDROID_CPU_ARM_FEATURE_NEON
指出设备CPU支持ARM高级SIMD(即NEON)(注:NEON技术是ARM SIMD扩展指令,用于多媒体处理的硬件加速)向量指令集扩展。注意ARM授权这种CPU还实现了VFPv3-D32,提供32个硬件浮点寄存器(与NEON单元共享)。
Important Note:
重要注意事项:
---------------
The cpufeatures library will be updated to support more CPU families and optional features in the future. It is designed to work as-is on all official Android platform versions.
cpufeatures库将被更新以支持未来更多CPU家族和可选特性。它被设计为在所有官方Android平台版本上保持原样地工作。
Change History:
修改历史:
---------------
Please see the comments in $NDK/sources/android/cpufeatures/cpu-features.c for the complete change history for this library.
请参考$NDK/sources/android/cpufeatures/cpu-features.c中的注释以获得这个库的完整修改历史。(注:估计写文档的人太懒...)