如何使用NEON比较(大于或等于)指令?

发布于 2024-09-24 23:16:50 字数 318 浏览 1 评论 0原文

一般如何使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

素染倾城色 2024-10-01 23:16:50

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文