Search code examples
cvectorizationintrinsicsavxavx2

AVX2 set __mm256d variable to all ones


I am trying to make a constant all binary ones __m256d variable. I saw the post Fastest way to set __m256 value to all ONE bits but it only handles the case of __m256i and __m256, not __m256d. Thank you for your help


Solution

  • You should fill the bits to one as you did and then cast it to the __m256d register:

    __m256i a = _mm256_set1_epi64x(-1);
    __m256d b = _mm256_castsi256_pd(a);
    

    Or simply:

    __m256d b = _mm256_castsi256_pd(_mm256_set1_epi64x(-1));