0

I was trying to initialise a C++ object with an SIMD member with a new keyword. Here is my code:

#include <immintrin.h>

class simd_obj {
protected:
    // float a;
    __m256 a;
public:
    simd_obj(float f) {
        // a = f;
        a = _mm256_set1_ps(f);
    }
};

int main() {
    simd_obj* a = new simd_obj(1.3);
    return 0;
}

It can be compiled with g++ 5.3.0 with -mavx flag in windows 7 (via mingw). However, when it runs, it crashes. When I changed the type of a into float and using a simple assignment (see the commented lines), it runs well, as expected. Also, when I change the initialisation to simd_obj a(1.3), it works, even with __m256 type of a.

Do you have any idea why the code above does not work?

Firman
  • 928
  • 7
  • 15

0 Answers0