Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide means for easy 16-alignment and std::vector embedding. #6

Closed
juj opened this issue May 9, 2012 · 0 comments
Closed

Provide means for easy 16-alignment and std::vector embedding. #6

juj opened this issue May 9, 2012 · 0 comments

Comments

@juj
Copy link
Owner

juj commented May 9, 2012

Data structures need to be aligned to 16 bytes for efficient SIMD loads and stores.
Also, data structures are often desired to be emdedded inside std::vectors.

If the data structure has declspec(align) members, it cannot be embedded into a std::vector.

As a workaround, provide something like the following scheme:

class float4_unaligned
{
float x,y,z,w;
__m128 sse;
};

typedef __declspec(align (16)) float4_unaligned float4;

// Use case 1 on the stack:
float4 x; // Will be aligned.

// Use case 2 in a vector:
vector<float4_unaligned, custom_16_aligned_allocator> vectorOfFloats; // Will be aligned. See aligned allocator here http://www.velocityreviews.com/forums/t646180-make-stl-containers-allocate-aligned-memory.html
vector<float4_unaligned> vectorOfFloats; // Wouldn't be aligned, and crash at runtime.
vector vectorOfFloats; // Wouldn't probably compile due to http://stackoverflow.com/questions/1281415/error-c2719-val-formal-parameter-with-declspecalign16-wont-be-alig

@juj juj closed this as completed in b82c000 Feb 13, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant