Loading a pair of floats into a vector type, as if it were double

I want to transfer the load vector __m256 with the same 4 pairs of floats that are adjacent in memory.

That is, if I have a pointer to the float x array specified by {a, b} , I want to end with __mm256 containing {a, b, a, b, a, b, a, b} .

My question is, are there any potential problems using _mm256_broadcast_sd to achieve this after casting x become a double array?

So:

 __m256 vect = (__m256)_mm256_broadcast_sd((double *)x); 
+4
source share
2 answers

Yes, you can do it safely; I have done this in the past. In my case, I did the math using complex numbers, where each component was drawn using float . Using mm256_broadcast_sd() can be used to insert a single complex number into each of the 4 positions in the resulting instance __m256d , which can then be passed to __m256 if you want to perform a float operation on it.

+3
source

This will work just fine.

There is a small detail regarding 8-byte alignment if alignment checking is turned on, however everyone works with alignment, so this is not a problem in practice.

+2
source

Source: https://habr.com/ru/post/1500565/


All Articles