Passing aligned types or structures with aligned types by value doesn't work with some implementations. This breaks STL containers, because some of the methods (such as resize) take their arguments by value.
I run some tests with Visual Studio 2008 and not entirely sure when and how pass by value fails. My main concern is function foo. It seems to work fine, but could it be a result of inlining or some other coincidence? What if I change its signature to void foo(const __m128&)?
Your input is greatly appreciated. Thank you.
struct A
{
__m128 x;
int n;
};
void foo(__m128);
void bar(A);
void f1()
{
// won't compile
// std::vector<A> vec1(3);
// compiles, but fails at runtime when elements are accessed
std::vector<__m128> vec2(3);
// this seems to work. WHY???
std::vector<__m128, some_16_byte_aligned_allocator<__m128> > vec3(3);
__m128 x;
A a;
// passed by value, is it OK?
foo(x);
// won't compile
//bar(a);
}
EDIT. STL fails even with aligned allocator, because pass by value problem remains.
Found this link pass __m128 by value