I have a union that looks like this
union bareVec8f {
__m256 m256; //avx 8x float vector
float floats[8];
int ints[8];
inline bareVec8f(){
}
inline bareVec8f(__m256 vec){
this->m256 = vec;
}
inline bareVec8f &operator=(__m256 m256) {
this->m256 = m256;
return *this;
}
inline operator __m256 &() {
return m256;
}
}
the __m256 needs to be aligned on 32 byte boundary to be used with SSE functions, and should be automatically, even within the union.
And when I do this
bareVec8f test = _mm256_set1_ps(1.0f);
I get a segmentation fault. This code should work because of the constructor I made. However, when I do this
bareVec8f test;
test.m256 = _mm256_set1_ps(8.f);
I do not get a segmentation fault.
So because that works fine the union is probably aligned properly, there's just some segmentation fault being caused with the constructor it seems
I'm using gcc 64bit windows compiler
---------------------------------EDIT Matt managed to produce the simplest example of the error that seems to be happening here.
#include <immintrin.h>
void foo(__m256 x) {}
int main()
{
__m256 r = _mm256_set1_ps(0.0f);
foo(r);
}
I'm compiling with -std=c++11 -mavx
auto ptrvalue = (std::uintptr_t)this;
. – ProfanitybaseVec8f(__m256 vec)
is a constructor. The copy-constructor has signaturebaseVec8f(baseVec8f &)
possibly withconst
.bareVec8f test = _mm256_set1_ps(1.0f);
uses the compiler-generated copy constructor. (although it would probably be elided in this case) – Antliaavxintrin.h
toimmintrin.h
and adding a semicolon after the union definition (using mingw-w64 4.9.2), and compiling withg++ -o foo foo.cc -mavx
(error goes away for some other compiler switches) – Antlia