如何使用NEON比较(大于或等于)指令?
一般如何使用 NEON 比较指令?
这是一个案例,我想使用大于或等于指令?
目前我有一个,
int x;
...
...
...
if(x >= 0)
{
....
}
在NEON中,我想以同样的方式使用x,只是这次x是一个向量。
int32x4_t x;
...
...
...
if(vcgeq_s32(x, vdupq_n_s32(0))) // Whats the best way to achieve this effect?
{
....
}
How to use the NEON comparison instructions in general?
Here is a case, I want to use, Greater-than-or-equal-to instruction?
Currently I have a,
int x;
...
...
...
if(x >= 0)
{
....
}
In NEON, I would like to use x in the same way, just that x this time is a vector.
int32x4_t x;
...
...
...
if(vcgeq_s32(x, vdupq_n_s32(0))) // Whats the best way to achieve this effect?
{
....
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 SIMD,从单个标量 if/then 转变为对多个元素进行测试并不简单。通常,您想要测试任何元素是否大于或所有元素是否大于,并且每种情况通常会有不同的SIMD谓词,您可以将其放入
如果(...)
。不过我在 NEON 中没有看到类似的东西,所以你可能不走运。通常,您希望采用不同的方法,因为在优化代码中通常不需要分支。理想情况下,您会希望使用 SIMD 比较的结果作为后续操作的掩码(例如,使用按位运算根据掩码选择不同的值)。
With SIMD it's not straightforward to go from a single scalar if/then to a test on multiple elements. Usually you want to test if any element is greater than or if all elements are greater than, and there will usually be different SIMD predicates for each case which you can put inside an
if (...)
. I don't see anything like this in NEON though, so you may be out of luck.Often though you want to take a different approach, since branches are usually not desirable in optimised code. Ideally you will want to use the result of a SIMD comparison as a mask for subsequent operations (e.g. select different values based on mask using bitwise operations).