Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

STL unordered_map crashes with __m128 values

I tracked a bug to the use of a __m128 (SSE vector) as a value in a std::unordered_map. This causes a runtime segmentation fault with mingw32 g++4.7.2.

Please see the example below. Is there any reason why this should fail? Or, might there be a workaround? (I tried wrapping the value in a class but it did not help.) Thanks.

#include <unordered_map>
#include <xmmintrin.h>          // __m128
#include <iostream>

int main()
{
    std::unordered_map<int,__m128> m;
    std::cerr << "still ok\n";
    m[0] = __m128();
    std::cerr << "crash in previous statement\n";
    return 0;
}

Compilation settings: g++ -march=native -std=c++11

like image 468
Hugues Avatar asked Feb 02 '13 18:02

Hugues


1 Answers

There are 2 issues regarding alignment:

Does the ABI ensure that __m128 variables are always aligned on the stack?

Does the global new operator return memory suitably aligned for the __m128 type? i.e., returns memory with a 16-byte alignment.

like image 111
Brett Hale Avatar answered Sep 28 '22 10:09

Brett Hale