Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intel SIMD - How can I check if an __m256* contains any non-zero values

I am using the Microsoft Visual Studio compiler. I am trying to find out if a 256 bit vector contains any non-zero values. I have tried res_simd = ! _mm256_testz_ps(*pSrc1, *pSrc1); but it does not work.

like image 254
user1315172 Avatar asked Mar 08 '15 06:03

user1315172


1 Answers

_mm256_testz_ps just tests the sign bits - in order to test the values you'll need to compare against 0 and then extract the resulting mask, e.g.

__m256 vcmp = _mm256_cmp_ps(*pSrc1, _mm256_set1_ps(0.0f), _CMP_EQ_OQ);
int mask = _mm256_movemask_ps(vcmp);
bool any_nz = mask != 0xff;
like image 110
Paul R Avatar answered Nov 15 '22 09:11

Paul R