SSE Type Container

I am trying to save an SSE type in a stl container. I tried this:

#include <iostream> #include <vector> int main() { typedef int v4sf __attribute__ (( vector_size(4*sizeof(float)) )); v4sf a; // compiles std::vector<v4sf> v1; // compiles, but nothing is actually allocated // std::vector<v4sf> v2(10); // compiler error: can't convert between vector values of different size std::vector<v4sf> v(10, a); // Compiles, but segfaults return 0; } 

but, as noted, the selection without providing the object for copying creates a compiler error, and the selection with the provision of compilation of the object, but segfaults. Can someone explain why I cannot store these SSE objects in an STL container like this (or, better, provide the correct way to do this)?

+4
source share
1 answer

To make it work, you must implement a custom Allocator. To use it, this is an argument next to the type: std :: vector <SSEType, CustomAlloc> container; Where CustomAlloc is an Allocator. You should use alligned_malloc or memalign to get the memory inside your Allocater, but this is the way to succeed here.

An example of this (not very simple implementation) can be found here: Implementation of the Allocator example

I've already done a lot with SSE, and I noticed that this is the easiest way to use alligned malloc and use it for my calculations.

+2
source

All Articles