如何使用 NEON 比较(大于或等于)指令? [英] How to use NEON comparison (greater than or equal to) instruction?

查看:48
本文介绍了如何使用 NEON 比较(大于或等于)指令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一般如何使用NEON比较指令?

How to use the NEON comparison instructions in general?

这里有一个案例,我想使用大于或等于指令?

Here is a case, I want to use, Greater-than-or-equal-to instruction?

目前我有一个,

int x;
...
...
...
if(x >= 0)
{
....

}

在NEON中,我想以同样的方式使用x,只是这次x是一个向量.

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?
{
....

}

推荐答案

使用 SIMD,从单个标量 if/then 到对多个元素的测试并不简单.通常您想测试 any 元素是否大于或 所有 元素是否大于,并且通常对于每种情况都有不同的 SIMD 谓词,您可以将它们放入一个如果(...).不过我在 NEON 中没有看到类似的东西,所以你可能不走运.

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.

尽管您通常想采用不同的方法,因为在优化代码中通常不希望使用分支.理想情况下,您希望将 SIMD 比较的结果用作后续操作的掩码(例如,使用按位操作根据掩码选择不同的值).

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).

这篇关于如何使用 NEON 比较(大于或等于)指令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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