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;
int bitmask;
uint64_t key = 509;
avx_sreg = _mm256_castsi256_pd(_mm256_set1_epi64x(key));
alignas(32) uint64_t v[4];
_mm256_store_pd((double*)v, avx_sreg);
printf("v2_u64: %lld %lld %lld %lld\n", v[0], v[1],v[2],v[3]);
uint64_t b[4]= {500,505,510,515};
avx_creg = _mm256_castsi256_pd(
_mm256_loadu_si256((__m256i const *)&b));
//
alignas(32) uint64_t v1[4];
_mm256_store_pd((double*)v1, avx_creg);
printf("v2_u64: %lld %lld %lld %lld\n", v1[0], v1[1],v1[2],v1[3]);
//
res = _mm256_cmp_pd(avx_sreg, avx_creg, 30);
bitmask = _mm256_movemask_pd(res);
int mmask = __builtin_popcount(bitmask);
printf("mmask is %d\n",mmask);
}