How to use NEON comparison (greater than or equal to) instruction?

荒凉一梦 提交于 2019-11-30 18:02:23

问题


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

}

回答1:


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



来源:https://stackoverflow.com/questions/3788380/how-to-use-neon-comparison-greater-than-or-equal-to-instruction

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!