I have this AVX code - and it prints the value of the bitmask as 2 which is correct i.e. the second element of the array (counted from zero) is greater than the value of 509. Is there a way to get all elements of array that are greater than 509 with AVX intrinsics ? In this case two elements i.e. 510 and 515 are greater than 509 but the way I have implemented my test case only the first one is available. Is there a way to get the second element as well ?
Code:
```#include <stdint.h>
#include <immintrin.h>
#include <assert.h>
#include <limits.h>
#include <math.h>
#include <stdalign.h>

main()
{
__m256d avx_creg, res, avx_sreg;
uint64_t key = 509;

avx_sreg = _mm256_castsi256_pd(_mm256_set1_epi64x(key));
alignas(32) uint64_t v;
_mm256_store_pd((double*)v, avx_sreg);
printf("v2_u64: %lld %lld %lld %lld\n", v, v,v,v);
uint64_t b= {500,505,510,515};
avx_creg = _mm256_castsi256_pd(
//
alignas(32) uint64_t v1;
_mm256_store_pd((double*)v1, avx_creg);
printf("v2_u64: %lld %lld %lld %lld\n", v1, v1,v1,v1);
//
res      = _mm256_cmp_pd(avx_sreg, avx_creg, 30);
}``` 2. I'm assuming that the 2 bits that are set in bitmask represent either the two values that are greater than 509 or possibly the two values that are less than 509. You should run it again with a key of 503. What's the answer?

So assuming the 2 bits that are set in bitmask are in positions that correspond to the indices of the elements that are greater(/less?) than the key, you can extract the values by looking at the bits. Maybe something like:
Code:
```if (bitmask & 1) printf("%ull\n", b);
if (bitmask & 2) printf("%ull\n", b);
if (bitmask & 4) printf("%ull\n", b);
if (bitmask & 8) printf("%ull\n", b);``` 3. > and it prints the value of the bitmask as 2 which is correct
So why are you printing the population count of the bitmask?

Code:
```  bitmask  = _mm256_movemask_pd(res); Popular pages Recent additions #include, %lld, gcc, intrinsics, uint64_t 