Android NDK文档之 Android NDK CPU 功能侦测库

来源:互联网 发布:戒色吧为什么不封 知乎 编辑:程序博客网 时间:2024/06/10 22:56
详细来自:http://blog.sina.com.cn/s/blog_4c451e0e0100sy90.html

Android NDK CPU Features detection library:
Android NDK CPU 功能侦测库:
-------------------------------------------

This NDK provides a small library named "cpufeatures" that canbe used at
runtime to detect the target device's CPU family and theoptional features
it supports.
NDK 提供一个小的名为 cpufeatures 的库,可以用来在运行时侦测目标设备的 CPU语系和它支持的可选功能。

Usage:
用法:
------

The library is available as an importmodule. 
该库是可作为导入模块使用的。

To use it, you must:
要使用它,你必须:

  * List 'cpufeatures' in your list of staticlibrary 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 headernamed <cpu-features.h> , as in:
  * 在你的源代码中,包含名为 cpu-features.h的头文件,如此:

       #include<cpu-features.h>


Here is a simple example:
这里是一个简单示例:

<project-path>/jni/Android.mk:
    LOCAL_PATH := $(callmy-dir)

    include$(CLEAR_VARS)
    LOCAL_MODULE :=<your-module-name>
    LOCAL_SRC_FILES :=<your-source-files>
    LOCAL_STATIC_LIBRARIES:= cpufeatures
    include$(BUILD_SHARED_LIBRARY)

    $(callimport-module,android/cpufeatures)


Features:
功能:
---------

Two functions are provided for now:
现在提供了两个函数:

   AndroidCpuFamily  android_getCpuFamily();

Returns the target device's CPU Family as anenum. 
以枚举型式返回目标设备的 CPU 语系。

For now, the only supported family isANDROID_CPU_FAMILY_ARM.
现在,仅支持的语系是 ANDROID_CPU_FAMILY_ARM 。

   uint64_t  android_getCpuFeatures();

Returns the set of optional features supported by the device'sCPU.
返回设备 CPU 支持的可选功能集。

The result is a set of bit-flags, 
each corresponding to one CPU Family-specific optionalfeature.
结果是一组位标志,每一个对应一个 CPU 指定语系的可选功能。

Currently, only the following flags are defined, for the ARMCPU Family:
目前,只为 ARM CPU 语系定义了如下标志:

ANDROID_CPU_ARM_FEATURE_ARMv7

Indicates that the device's CPU supports the ARMv7-Ainstruction set 
as supported by the "armeabi-v7a" ABI (seeCPU-ARCH-ABIS.html).
指出设备的 CPU 支持 ARMv7-A 指令集与由 armeabi-v7a ABI 支持的等同(参见CPU-ARCH-ABIS.html)。

This corresponds to Thumb-2 and VFPv3-D16 instructions.
这相当于 Thumb-2 和 VFPv3-D16 指令。

ANDROID_CPU_ARM_FEATURE_VFPv3

Indicates that the device's CPU supports the VFPv3 hardwareFPU instruction set extension. 
指出设备的 CPU 支持 VFPv3 硬件浮点单元指令集扩展。

Due to the definition of 'armeabi-v7a',
this will always be the case if ANDROID_CPU_ARM_FEATURE_ARMv7is returned.
由于 armeabi-v7a 的定义,如果已返回 ANDROID_CPU_ARM_FEATURE_ARMv7这个将无例外地一起返回。

Note that this corresponds to the minimum profile VFPv3-D16that
_only_ provides 16 hardware FP registers.
注意相应的最小型 VFPv3-D16 仅支持 16 个硬件浮点寄存器。

详细来自:http://blog.sina.com.cn/s/blog_4c451e0e0100sy90.html
ANDROID_CPU_ARM_FEATURE_NEON

Indicates that the device's CPU supports the ARM AdvancedSIMD 
(a.k.a. NEON) vector instruction setextension. 
指出设备的 CPU 支持 ARM 高级的 SIMD (又叫做,NEON)矢量指令集扩展。
注:NEON 技术是用于多媒体处理的硬件加速。 

Note that ARM mandates that such CPUs also implementVFPv3-D32, 
which provides 32 hardware FP registers (shared with the NEONunit).
注意 ARM 要求这样的 CPU 同样实现 VFPv3-D32 提供 32 个硬件浮点寄存器(与 NEON单元共享)。

Important Note:
重要提示:
---------------

The cpufeatures library will be updatedto 
support more CPU families and optional features in thefuture. 
在将来 cpufeatures 库将更新支持更多 CPU 语系和可选功能。

It is designed to work as-is on all official Android platformversions.
按现状它是被设计工作在全部官方 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中的注释,了解这个库的完整修订记录。