android ndk NEON Support

2023-11-08

NEON Support

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 viatranslation header. It is important to use checks like the following in your Android.mk file:

# define a static library containing our NEON code
ifeq ($(TARGET_ARCH_ABI),$(filter $(TARGET_ARCH_ABI), armeabi-v7a x86))
include $(CLEAR_VARS)
LOCAL_MODULE    := mylib-neon
LOCAL_SRC_FILES := mylib-neon.c
LOCAL_ARM_NEON  := true
include $(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.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

android ndk NEON Support 的相关文章

随机推荐

  • cmd命令查看笔记本电池状况

    1 以管理员身份运行 打开 命令提示符 exe 2 在命令提示符输入 powercfg batteryreport output D battery report html 其中 引号内的电池使用报告文件的保存路径可以自定义 你也可以保存到
  • linux根据进程的运行路径,停止进程

    公式 lsof grep 路径 awk print 2 xargs kill 比如我想停掉目录 home code python program 下的程序 可以使用 lsof grep home code python program aw
  • Python简介与安装

    一 windows下安装python 二 linux下安装python 三 mac系统安装python 四 学会配置不同操作系统的环境变量 windows配置环境变量 linux配置环境变量 五 写一个简单的helloworld小程序 学会
  • Python基于Zmail发送邮件

    目录 一 介绍 二 安装 三 使用须知 四 使用步骤 4 1 获得邮件授权码 以QQ邮箱为例 4 2 发送简单文本邮件 4 3 发送Html文件邮件 4 4 发送文本txt文件邮件 4 4 发送带附件邮件 4 5 验证SMTP和POP功能是
  • 了解GFS和HDFS后,要懂得分布式文件系统设计原理

    转自 https www jianshu com p fc0aa34606ce 一 概述 分布式文件系统是分布式领域的一个基础应用 其中最著名的毫无疑问是 HDFS GFS 如今该领域已经趋向于成熟 但了解它的设计要点和思想 对我们将来面临
  • 伸缩自如的ElasticSearch——通过bboss操作和访问elasticsearch模式

    文章目录 ClientUtil 加载配置文件中的dsl来实现对es的操作模式 所有不依赖dsl的功能 或直接接收dsl模式 基本功能 配置es查询dsl 文档批量创建或者修改 http api 查询dsl动态脚本语法规范 配置springb
  • C++11模板元编程—std::enable_if使用说明

    std enable if 顾名思义 满足条件时类型有效 作为选择类型的小工具 其广泛的应用在 C 的模板元编程中 它的定义也非常的简单 STRUCT TEMPLATE enable if template
  • linux硬盘安装器下载,通过硬盘安装Linux

    一 下载iso文件 下载后的文件可以保存在linux分区或windows分区 iso一般还有个md5sum的说明 用这个可以检验iso文件的正确性 以redhat7 3为例 linux下用 md5sum valhalla i386 disc
  • 接口测试和单元测试

    接口测试的本质 就是通过数据驱动 测试类里面的函数 单元测试的本质 通过代码级别 测试函数 单元测试的框架 unitest 接口 pytest WEB gt 接口 pytest jenkins allure requests 模块讲解和应用
  • 单链表逆转的2种方法。

    单链表逆转方法有很多 这里谈两种 1 再建一个链表然后 边遍历原来的链表 便是用头插法 完成新的单链表 这样子虽然内存损耗比较大 但是也是勉强可以完成的 2 使用3个指针 逐个节点的逆转 p q两个指针分别指向想要逆转关系的两个节点 p指向
  • iOS苹果开发者账号(公司账号)申请流程详解

    前言 近期由于公司项目的需要 全程参与了公司一款iOS原生应用的开发与上线 其中最让我印象深刻的还是申请苹果开发者账号以及app的上架审核 申请苹果开发者账号一波三折 又是邮件又是电话的 审核过程被拒多次 由于苹果审核时间大多是在凌晨或者第
  • JSP介绍

    目录 JSP简介 JSP脚本片段 JSP表达式 JSP声明片段 JSP的指令标识 page的属性 Include指令 Taglib指令 JSP标签 动态引入和静态引入的区别 JSP作用域 JSP的九大内置对象 内置 不需要创建 直接就能用
  • 立即放弃 TypeScript 的 17 个理由

    如果你和我一样 你可能会因为被迫而使用 Typescript 你的公司决定它会成为未来的语言 所以你被迫学习它 起初 您很高兴使用 Typescript 你知道它有很大的潜力 可以帮助你制作更强大的应用程序 但在使用了一段时间后 您开始意识
  • 微博登录和session恢复过程

    微博登录和session恢复过程 登录 预登录 获取验证码 登录 密码密文sp计算 登录请求 跨域广播登录 解决cookie设置不上的问题 跨域广播之后 恢复session 完整源码参考我的pixiv to weibo项目 只实现了核心部分
  • cygwin开发环境搭建与apt-cyg的应用

    1 Cygwin安装 http www cygwin com 下载安装工具 具体安装过程参照http jingyan baidu com article 6b97984d83dfe51ca2b0bf0e html 2 Cygwin一些设置
  • 使用Arduino开发板控制伺服电机

    大多数情况下 直流电机控制的控制方法都是非常简单的 只需要连接电源和地 伺服电机有一些不同 它使用3根线连接 电源 地和信号 将电机移动到某个旋转位置 该位置由信号线上发送的信号决定 一旦电机到达信号指定的位置 它将保持其位置 并抵抗试图将
  • 利用GPU预热以及同步执行正确计算卷积神经网络推理性能【附代码】

    我们在评价一个卷积神经网络模型性能好坏时 通常会用AP mAP来判断分类准确性 针对速度方面经常使用ms 毫秒 或者FPS 表示每秒处理多少张图像 或者说处理一张图像用多少秒 在看一些代码的时候 常常会看到是直接用python中的time函
  • docker 镜像的复制和导入

    1 复制 docker save o 要保存的文件名 要保存的镜像 docker save o d docker images fastdfs tar zl fastdfs 2 导入 docker load input 文件 docker
  • mysql数据库的安装和卸载(windows10)

    数据库安装 官网下载ZIP压缩包 解压到D MySQL mysql 5 6 40 winx64 打开刚刚解压的文件夹 D MySQL mysql 5 6 40 winx64 里面有一个系统自带的配置文件 my default ini 复制该
  • android ndk NEON Support

    NEON Support On this page Using LOCAL ARM NEON Using the neon Suffix Build Requirements Runtime Detection Sample Code Th