android ndk NEON Support
来源:互联网 发布:神优化游戏 编辑:程序博客网 时间:2024/06/04 17:43
NEON Support
On this page
- Using
LOCAL_ARM_NEON
- Using the
.neon
Suffix - Build Requirements
- Runtime Detection
- Sample Code
The NDK supports the ARM Advanced先进,高级 SIMD单指令多数据玲构(Single Instruction Multiple Data), an optional instruction-set extension of the ARMv7 spec. NEON provides a set of scalar无向量 /vector instructions and registers (shared with the FPU浮点运算单元(Float Point Unit)) comparable to MMX多媒体增强指令集(Multi Media Extension)/SSE扩展(Streaming Simd Extensions)/3DNow! in the x86 world. To function, it requires VFP(可变因素编程Variable Factor Programming)v3-D32 (32 hardware FPU 64-bit registers, instead of the minimum of 16).
The NDK supports the compilation of modules or even specific source files with support for NEON. As a result, a specific compiler flag enables the use of GCC ARM NEON intrinsics(内联函数函数)and VFPv3-D32 at the same time.
Not all ARMv7-based Android devices support NEON, but devices that do may benefit significantly有意义的,显著的 from its support for scalar/vector instructions. For x86 devices, the NDK can also translate NEON instructions into SSE, although with several restrictions. For more information, see x86 Support for ARM NEON Intrinsics.
Using LOCAL_ARM_NEON
To have the NDK build all its source files with NEON support, include the following line in your module definition:
LOCAL_ARM_NEON := true
It can be especially特别 useful to build all source files with NEON support if you want to build a static or shared library that specifically contains NEON code paths.
Using the .neon Suffix后缀
When listing source files for your LOCAL_SRC_FILES
variable, you have the option of using the .neon
suffix to indicate that you want to build binaries with NEON support. For example, the following example builds one file with .neon
support, and another without it:
LOCAL_SRC_FILES := foo.c.neon bar.c
You can combine the .neon
suffix with the .arm
suffix, which specifies the 32-bit ARM instruction set for non-NEON instructions. In such a definition, arm
must come before neon
. For example: foo.c.arm.neon
works, butfoo.c.neon.arm
does not.
Build Requirements
NEON support only works with the armeabi-v7a
and x86
ABIs. If the NDK build scripts encounter遭遇 other ABIs while attempting to build with NEON support, the NDK build scripts exit. x86 provides partial NEON support via经translation header. It is important to use checks like the following in your Android.mk
file:
# define a static library containing our NEON codeifeq ($(TARGET_ARCH_ABI),$(filter $(TARGET_ARCH_ABI), armeabi-v7a x86))include $(CLEAR_VARS)LOCAL_MODULE := mylib-neonLOCAL_SRC_FILES := mylib-neon.cLOCAL_ARM_NEON := trueinclude $(BUILD_STATIC_LIBRARY)endif # TARGET_ARCH_ABI == armeabi-v7a || x86
Runtime Detection检测
Your app must perform runtime detection to confirm that NEON-capable machine code can be run on the target device. This is because not all ARMv7-based Android devices support NEON. The app can perform this check using the cpufeatures
library that comes with this NDK.
You should explicitly明确的 check that android_getCpuFamily()
returns ANDROID_CPU_FAMILY_ARM
, and thatandroid_getCpuFeatures()
returns a value including the ANDROID_CPU_ARM_FEATURE_NEON flag
set. For example:
#include <cpu-features.h>......if (android_getCpuFamily() == ANDROID_CPU_FAMILY_ARM && (android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) != 0){ // use NEON-optimized routines ...}else{ // use non-NEON fallback routines instead ...}...
Sample Code
The source code for the NDK's hello-neon sample provides an example of how to use the cpufeatures
library and NEON intrinsics at the same time. This sample implements a tiny微小的 benchmark(基准;标准检查程序) for a FIR filter loop using a C version, and a NEON-optimized优化 one for devices that support it.
- android ndk NEON Support
- Android NDK 之NEON优化
- ffmpeg compile with neon support for android
- android ndk x86 Support
- android ndk MIPS Support
- Android NDK使用NEON优化,SIMD优化
- Android NDK开发之 Neon优化
- Android NDK开发之 NEON基础介绍
- Android NDK开发之 NEON使用介绍
- Android NDK开发之 NEON基础介绍
- android ndk not support pthread_cancel
- android ndk not support pthread_cancel
- Support NDK in Android studio.
- ARM cortex A8/9 - Android NDK - NEON介绍以及优化
- ARM cortex A8/9 - Android NDK - NEON介绍以及优化
- ANDROID NDK文档系列--(08)CPU ARM Neon
- Android NDK开发之 ARM与NEON指令说明
- Android NDK开发之 与NEON相关的库
- ormlite的一对多详解
- 适配器模式及SDK源码中的运用(附:分别面向接口、类、对象的适配器扩展)
- Spring中的<context:annotation-config/>
- JVM之我们需要掌握的
- MyBatis学习(二) - SQL语句映射文件(1)resultMap
- android ndk NEON Support
- effective c++学习笔记
- manual make usb installer for windows in ubuntu15.04
- 关于更改Zend Studio/Eclipse代码风格主题的介绍
- 黑马程序员——Java基础---API(下)
- 7_13:验证longjmp后变量的值
- 我对产品经理这个角色的认识
- 正确理解listView的listSelector
- docker1.8.2创建并运行karaf镜像