arm 霓虹灯比较操作产生负一 [英] arm neon compare operations generate negative one

查看:36
本文介绍了arm 霓虹灯比较操作产生负一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试以下汇编代码:

I am trying the following assembly code:

vclt.f32 q9,q0,#0
vst1.i32 q9,[r2:128]

但如果条件为真,则q9中的对应元素设置为负一而不是正一.

But if the condition is true, the corresponding element in q9 is set to negative one instead of positive one.

我该怎么做才能得到一个积极的?

What can I do to get a positive one ?

推荐答案

这对于向量比较指令是正常的,因此您可以将比较结果用作带有 AND 或 XOR 指令或其他各种用例的掩码.

This is normal for vector compare instructions, so you can use the compare result as a mask with AND or XOR instructions, or various other use-cases.

p>

您通常不需要 +1.例如,如果要计算匹配的元素个数,只需使用减法指令从向量累加器中减去 0 或 -1.

You usually don't need a +1. If you want to count the number of elements that match, for example, just use a subtract instruction to subtract 0 or -1 from a vector accumulator.

要得到一个整数 +1,你可以从 0 中减去它,或者右移元素大小 -1.(例如,逻辑右移 31 只留下低位 0 或 1,其余位全为零).您还可以使用您之前创建的 +1 向量进行 AND.

To get an integer +1, you could subtract it from 0, or right-shift by element-size -1. (e.g. logical right-shift by 31 to leave just the low bit 0 or 1, and the rest of the bits all-zero). You could also AND with a vector of +1s that you created earlier.

我不知道其中哪一个最适合 ARM,或者这是否取决于微架构.(我真的只知道 x86 SSE/AVX 的 SIMD.)不过,我确信 NEON 至少可以完成我所描述的选项之一.

I don't know which of these would be best for ARM, or if that would depend on the microarchitecture. (I really only know SIMD for x86 SSE/AVX.) I'm sure NEON can do at least one of the options I described, though.

这篇关于arm 霓虹灯比较操作产生负一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆