c++ - Wrapper for __m256 producing segmentation fault with constructor -
i have union looks 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 aligned on 32 byte boundary used sse functions, , should automatically, within union.
and when this
barevec8f test = _mm256_set1_ps(1.0f);
i segmentation fault. code should work because of constructor made. however, when this
barevec8f test; test.m256 = _mm256_set1_ps(8.f);
i not segmentation fault.
so because works fine union aligned properly, there's segmentation fault being caused constructor seems
i'm using gcc 64bit windows compiler
---------------------------------edit matt managed produce simplest example of error seems happening here.
#include <immintrin.h> void foo(__m256 x) {} int main() { __m256 r = _mm256_set1_ps(0.0f); foo(r); }
i'm compiling -std=c++11 -mavx
this bug in g++ windows. not perform 32-byte stack alignment when should. bug 49001 bug 54412
on this thread made python script process assembly output g++ fix problem, 1 option.
otherwise, avoid in union make functions take __m256
value, take reference instead. shouldn't have performance penalty unless optimization low/off.
in case unaware - union aliasing causes undefined behaviour in c++, it's not permitted write m256
, read floats
or ints
example. perhaps there different solution problem.
Comments
Post a Comment