NEON中的L可以避免溢出
2024-10-09 03:15:34
在做加法时,比如两个255x255的数值相加,那么正确结果将是130050,对一个最大值为65565的unsigned short
是会溢出的,但是如果使用L命令时,则不会产生溢出。这说明L命令,不是先执行计算再简单使之long,而是对计算结果就直接针对更宽位。下面代码可以验证。
ushort data1[4] = {255*255};
uint16x4_t v0 = vld1_u16(data1);
uint16x4_t v1 = vld1_u16(data1);
uint16x4_t res = vadd_u16(v0, v1);
uint32x4_t res0 = vaddl_u16(v0, v1);
uint32x4_t res1 = vaddq_u32(vmovl_u16(v0), vmovl_u16(v1));
uint r0[4], r1[4];
short res3[4];
ushort res2[4];
vst1q_u32(r0, res0);
vst1q_u32(r1, res1);
vst1_u16(res2, res);
vst1_s16(res3, vreinterpret_s16_u16(res));
OLOGD("32: %d %d %d %d %d %d %d %d", res0[0], res0[1], res0[2], res0[3], res1[0], res1[1], res1[2], res1[3]);
OLOGD("32 c: %d %d %d %d %d %d %d %d", r0[0], r0[1], r0[2], r0[3], r1[0], r1[1], r1[2], r1[3]);
OLOGD("u:%d %d %d %d s:%d %d %d %d", res2[0], res2[1], res2[2], res2[3], res3[0], res3[1], res3[2], res3[3]);
输出为
D/OLOG:32: 130050 0 0 0 130050 0 0 0
D/OLOG:32 c: 130050 0 0 0 130050 0 0 0
D/OLOG:u:64514 0 0 0 s:-1022 0 0 0
而且这个代码说明,可以直接对NEON的vector进行打印,而没必要先保存到CPU内存。
最新文章
- (转)从0开始搭建SQL Server AlwaysOn 第二篇(配置故障转移集群)
- Ionic 常用插件
- 使用EmBitz开发STM32项目的环境配置
- HttpModule的认识
- Ladda – 把加载提示效果集成到按钮中,提升用户体验
- POi写入大批量数据
- CentOS镜像163更新源
- Deppon接口开发
- [SQL]LeetCode182. 查找重复的电子邮箱 | Duplicate Emails
- MyBatis集成到Spring时配置MapperScannerConfigurer出错
- python-opencv boundingRect使用注意
- python3 集合的常用方法
- 《TCP/IP 详解 卷1:协议》第 10 章:用户数据报协议
- android基础---->;音频和视频的使用
- 27.Remove Element(Array)
- 浅谈tcp_nodelay的作用
- JavaScript--3种函数调用的方法
- 《effective c++》读书笔记(上)
- create-react-native-app
- Go环境搭建(Windows)
热门文章
- 软件包管理rpm和yum
- B - Bash and a Tough Math Puzzle CodeForces - 914D (线段树的巧妙应用)
- PHP出现SSL certificate:unable to get local issuer certificate的解决办法
- web测试流程
- [V&;N2020 公开赛]TimeTravel 复现
- 【考试总结】欢乐模拟赛_Day1
- 基于 Python 的自动文本提取:抽象法和生成法的比较
- c++动态数组的使用
- /proc/[pid]/status
- C++ Windows - How to get process path from its PID