NEON包向量将比较结果转换为位图 [英] NEON pack vector compare result into bitmap

查看:73
本文介绍了NEON包向量将比较结果转换为位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到两个浮点操作数比较的比较结果,如下所示;我需要做的是基于比较的结果,需要执行以下操作:即:

I have a comparison result of comparison of two floating point operands as follows; What I need to do is based on the result of comparison need to perform the following: i.e:

neon_gt_res = vcgtq_f32(temp1, temp2);
if(neon_gt_res[0]) array[0] |= (unsigned char)0x01;
if(neon_gt_res[1]) array[0] |= (unsigned char)0x02;
if(neon_gt_res[2]) array[0] |= (unsigned char)0x04;
if(neon_gt_res[3]) array[0] |= (unsigned char)0x08;

但是这样写又等于多重比较.如何以霓虹C内部函数最佳地编写此代码.

But writing like this is again equivalent to multiple comparison. How do I optimally write this in neon C intrinsics.

在x86上,这将是array[0] |= _mm_movemask_ps(cmp_gt_res);

推荐答案

vmov.i32 qmask, #1
vand qres, qmask, qres
vsra.u64 qres, qres, #30
vsli.64 dres_bottom, dres_top, #2

在qres的四个最低有效位,您就有了所需的位.

And you have the bits you need at the four least significant bits of qres.

////////////////////////编辑

//////////////////////// edit

上述的改进版本:

vshr.u64 qres, qres, #31
vsli.64 dres_bot, dres_top, #2
// the four LSBs already contain the bitmap, the rest is optional:
vbic.i16 dres_bot, #0xf0
// you can now use byte 0 of dres_bot as the result.

这篇关于NEON包向量将比较结果转换为位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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