Fastest way to test a 128 bit NEON register for a value of 0 using intrinsics?

前端 未结 5 484
天命终不由人
天命终不由人 2021-01-12 13:58

I\'m looking for the fastest way to test if a 128 NEON register contains all zeros, using NEON intrinsics. I\'m currently using 3 OR operations, and 2 MOVs:

         


        
5条回答
  •  伪装坚强ぢ
    2021-01-12 14:52

    While this answer may be a bit late, there is a simple way to do the test with only 3 instructions and no extra registers:

    inline uint32_t is_not_zero(uint32x4_t v)
    {
        uint32x2_t tmp = vorr_u32(vget_low_u32(v), vget_high_u32(v));
        return vget_lane_u32(vpmax_u32(tmp, tmp), 0);
    }
    

    The return value will be nonzero if any bit in the 128-bit NEON register was set.

提交回复
热议问题