Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

c - NEON pack vector compare result into bitmap

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;

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

On x86, this would be array[0] |= _mm_movemask_ps(cmp_gt_res);

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
vmov.i32 qmask, #1
vand qres, qmask, qres
vsra.u64 qres, qres, #30
vsli.64 dres_bottom, dres_top, #2

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

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

An improved version of above:

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.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...